Author: julien(a)jboss.com
Date: 2007-05-15 17:01:36 -0400 (Tue, 15 May 2007)
New Revision: 7256
Modified:
trunk/core/src/main/org/jboss/portal/core/aspects/controller/PageCustomizerInterceptor.java
trunk/core/src/resources/portal-core-war/WEB-INF/jsp/header/header.jsp
trunk/server/src/main/org/jboss/portal/server/request/URLContext.java
Log:
replace page customization String URL by a simple impl?\195?\169mentation of PortalURL
which allow to lazy create URLs and also provide more programmatic control over the
generated URL
Modified:
trunk/core/src/main/org/jboss/portal/core/aspects/controller/PageCustomizerInterceptor.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/core/aspects/controller/PageCustomizerInterceptor.java 2007-05-15
20:27:55 UTC (rev 7255)
+++
trunk/core/src/main/org/jboss/portal/core/aspects/controller/PageCustomizerInterceptor.java 2007-05-15
21:01:36 UTC (rev 7256)
@@ -34,6 +34,7 @@
import org.apache.log4j.Logger;
import org.jboss.portal.Mode;
import org.jboss.portal.WindowState;
+import org.jboss.portal.api.PortalURL;
import org.jboss.portal.common.servlet.BufferingRequestWrapper;
import org.jboss.portal.common.servlet.BufferingResponseWrapper;
import org.jboss.portal.core.controller.Controller;
@@ -62,6 +63,7 @@
import org.jboss.portal.security.spi.auth.PortalAuthorizationManagerFactory;
import org.jboss.portal.server.ServerInvocationContext;
import org.jboss.portal.server.request.URLContext;
+import org.jboss.portal.server.request.URLFormat;
import org.jboss.portal.theme.ThemeConstants;
import org.jboss.portal.theme.impl.render.dynamic.DynaRenderOptions;
import org.jboss.portal.theme.page.Region;
@@ -183,10 +185,7 @@
if (user == null)
{
- URLContext ctx =
controllerCtx.getServerInvocation().getServerContext().getURLContext();
- ctx = URLContext.newInstance(ctx.isSecure(), true);
- String loginURL = controllerCtx.renderURL(cc, ctx, null);
- request.setAttribute("org.jboss.portal.header.LOGIN_URL",
loginURL);
+ request.setAttribute("org.jboss.portal.header.LOGIN_URL", new
PortalURLImpl(cc, controllerCtx, Boolean.TRUE, null));
}
// Edit dashboard page || Copy to dashboard link
@@ -205,7 +204,7 @@
PortletParametersStateString navState = new
PortletParametersStateString();
navState.setValue("editPageSelect", pageName);
InvokePortletInstanceRenderCommand command = new
InvokePortletInstanceRenderCommand("DashboardConfigPortletInstance", navState);
-
request.setAttribute("org.jboss.portal.header.EDIT_DASHBOARD_URL",
controllerCtx.renderURL(command, null, null));
+
request.setAttribute("org.jboss.portal.header.EDIT_DASHBOARD_URL", new
PortalURLImpl(command, controllerCtx, null, null));
}
else
{
@@ -217,7 +216,7 @@
if (dashboard.getChild(pageName) == null)
{
ImportPageToDashboardCommand iptdc = new
ImportPageToDashboardCommand(page.getId());
-
request.setAttribute("org.jboss.portal.header.COPY_TO_DASHBOARD_URL",
controllerCtx.renderURL(iptdc, null, null));
+
request.setAttribute("org.jboss.portal.header.COPY_TO_DASHBOARD_URL", new
PortalURLImpl(iptdc, controllerCtx, null, null));
}
}
@@ -231,7 +230,7 @@
if (dashboard != null)
{
ViewPortalCommand vdc = new ViewPortalCommand(dashboard.getId());
- request.setAttribute("org.jboss.portal.header.DASHBOARD_URL",
controllerCtx.renderURL(vdc, null, null));
+ request.setAttribute("org.jboss.portal.header.DASHBOARD_URL",
new PortalURLImpl(vdc, controllerCtx, null, null));
}
}
@@ -254,7 +253,7 @@
if
(controller.getPortalAuthorizationManagerFactory().getManager().checkPermission(perm))
{
ViewPageCommand showadmin = new ViewPageCommand(adminPortalId);
-
request.setAttribute("org.jboss.portal.header.ADMIN_PORTAL_URL",
controllerCtx.renderURL(showadmin, null, null));
+
request.setAttribute("org.jboss.portal.header.ADMIN_PORTAL_URL", new
PortalURLImpl(showadmin, controllerCtx, null, null));
}
}
catch (PortalSecurityException e)
@@ -267,15 +266,13 @@
if (admin || isDashboard)
{
// Link to default page of default portal
- ViewPageCommand _rpc = new ViewPageCommand(defaultPortalId);
- request.setAttribute("org.jboss.portal.header.DEFAULT_PORTAL_URL",
controllerCtx.renderURL(_rpc, null, null));
+ ViewPageCommand vpc = new ViewPageCommand(defaultPortalId);
+ request.setAttribute("org.jboss.portal.header.DEFAULT_PORTAL_URL",
new PortalURLImpl(vpc, controllerCtx, null, null));
}
//
SignOutCommand cmd = new SignOutCommand();
- URLContext urlContext =
controllerCtx.getServerInvocation().getServerContext().getURLContext();
- String logoutURL = controllerCtx.renderURL(cmd, urlContext.asNonAuthenticated(),
null);
- request.setAttribute("org.jboss.portal.header.SIGN_OUT_URL",
logoutURL);
+ request.setAttribute("org.jboss.portal.header.SIGN_OUT_URL", new
PortalURLImpl(cmd, controllerCtx, Boolean.FALSE, null));
//
try
@@ -373,4 +370,66 @@
{
this.tabsPath = tabsPath;
}
+
+ private static class PortalURLImpl implements PortalURL
+ {
+
+ /** . */
+ private ControllerCommand command;
+
+ /** . */
+ private ControllerContext context;
+
+ /** . */
+ private Boolean wantAuthenticated;
+
+ /** . */
+ private Boolean wantSecure;
+
+ /** . */
+ private boolean relative;
+
+ /** . */
+ private String value;
+
+
+ public PortalURLImpl(ControllerCommand command, ControllerContext context, Boolean
wantAuthenticated, Boolean wantSecure)
+ {
+ this.command = command;
+ this.context = context;
+ this.wantAuthenticated = wantAuthenticated;
+ this.wantSecure = wantSecure;
+ this.relative = false;
+ this.value = null;
+ }
+
+ public void setAuthenticated(Boolean wantAuthenticated)
+ {
+ this.wantAuthenticated = wantAuthenticated;
+ this.value = null;
+ }
+
+ public void setSecure(Boolean wantSecure)
+ {
+ this.wantSecure = wantSecure;
+ this.value = null;
+ }
+
+ public void setRelative(boolean relative)
+ {
+ this.relative = relative;
+ this.value = null;
+ }
+
+ public String toString()
+ {
+ if (value == null)
+ {
+ URLContext urlContext =
context.getServerInvocation().getServerContext().getURLContext();
+ urlContext =
urlContext.withAuthenticated(wantAuthenticated).withSecured(wantSecure);
+ value = context.renderURL(command, urlContext,
URLFormat.newInstance(relative, true));
+ }
+ return value;
+ }
+ }
}
Modified: trunk/core/src/resources/portal-core-war/WEB-INF/jsp/header/header.jsp
===================================================================
--- trunk/core/src/resources/portal-core-war/WEB-INF/jsp/header/header.jsp 2007-05-15
20:27:55 UTC (rev 7255)
+++ trunk/core/src/resources/portal-core-war/WEB-INF/jsp/header/header.jsp 2007-05-15
21:01:36 UTC (rev 7256)
@@ -1,14 +1,15 @@
<%@ page import="org.jboss.portal.identity.User" %>
+<%@ page import="org.jboss.portal.api.PortalURL" %>
<%
- User user = (User) request.getAttribute("org.jboss.portal.header.USER");
- String dashboardURL = (String)
request.getAttribute("org.jboss.portal.header.DASHBOARD_URL");
- String loginURL = (String)
request.getAttribute("org.jboss.portal.header.LOGIN_URL");
- String defaultPortalURL = (String)
request.getAttribute("org.jboss.portal.header.DEFAULT_PORTAL_URL");
- String adminPortalURL = (String)
request.getAttribute("org.jboss.portal.header.ADMIN_PORTAL_URL");
- String editDashboardURL = (String)
request.getAttribute("org.jboss.portal.header.EDIT_DASHBOARD_URL");
- String copyToDashboardURL = (String)
request.getAttribute("org.jboss.portal.header.COPY_TO_DASHBOARD_URL");
- String signOutURL = (String)
request.getAttribute("org.jboss.portal.header.SIGN_OUT_URL");
+ User user = (User)request.getAttribute("org.jboss.portal.header.USER");
+ PortalURL dashboardURL =
(PortalURL)request.getAttribute("org.jboss.portal.header.DASHBOARD_URL");
+ PortalURL loginURL =
(PortalURL)request.getAttribute("org.jboss.portal.header.LOGIN_URL");
+ PortalURL defaultPortalURL =
(PortalURL)request.getAttribute("org.jboss.portal.header.DEFAULT_PORTAL_URL");
+ PortalURL adminPortalURL =
(PortalURL)request.getAttribute("org.jboss.portal.header.ADMIN_PORTAL_URL");
+ PortalURL editDashboardURL =
(PortalURL)request.getAttribute("org.jboss.portal.header.EDIT_DASHBOARD_URL");
+ PortalURL copyToDashboardURL =
(PortalURL)request.getAttribute("org.jboss.portal.header.COPY_TO_DASHBOARD_URL");
+ PortalURL signOutURL =
(PortalURL)request.getAttribute("org.jboss.portal.header.SIGN_OUT_URL");
%>
<%
Modified: trunk/server/src/main/org/jboss/portal/server/request/URLContext.java
===================================================================
--- trunk/server/src/main/org/jboss/portal/server/request/URLContext.java 2007-05-15
20:27:55 UTC (rev 7255)
+++ trunk/server/src/main/org/jboss/portal/server/request/URLContext.java 2007-05-15
21:01:36 UTC (rev 7256)
@@ -72,6 +72,22 @@
return authenticated;
}
+ public URLContext withSecured(Boolean wantSecure)
+ {
+ if (wantSecure == null)
+ {
+ return this;
+ }
+ else if (Boolean.TRUE == wantSecure)
+ {
+ return asSecured();
+ }
+ else
+ {
+ return asNonSecured();
+ }
+ }
+
public URLContext asSecured()
{
int newMask = mask | SEC_MASK;
@@ -84,6 +100,22 @@
return contexts[newMask];
}
+ public URLContext withAuthenticated(Boolean wantAuthenticated)
+ {
+ if (wantAuthenticated == null)
+ {
+ return this;
+ }
+ else if (Boolean.TRUE == wantAuthenticated)
+ {
+ return asAuthenticated();
+ }
+ else
+ {
+ return asNonAuthenticated();
+ }
+ }
+
public URLContext asAuthenticated()
{
int newMask = mask | AUTH_MASK;