Author: julien(a)jboss.com
Date: 2007-06-11 07:31:36 -0400 (Mon, 11 Jun 2007)
New Revision: 7395
Added:
trunk/core/src/main/org/jboss/portal/core/aspects/controller/ControlInterceptor.java
trunk/core/src/main/org/jboss/portal/core/aspects/controller/ResourceAcquisitionInterceptor.java
trunk/core/src/main/org/jboss/portal/core/controller/AccessDeniedException.java
trunk/core/src/main/org/jboss/portal/core/controller/ControllerRequestDispatcher.java
trunk/core/src/main/org/jboss/portal/core/controller/NoSuchResourceException.java
trunk/core/src/main/org/jboss/portal/core/controller/SecurityException.java
trunk/core/src/main/org/jboss/portal/core/controller/classic/OtherResponseHandler.java
trunk/core/src/main/org/jboss/portal/core/controller/command/response/ErrorResponse.java
trunk/core/src/main/org/jboss/portal/core/controller/command/response/RedirectionResponse.java
trunk/core/src/main/org/jboss/portal/core/controller/command/response/SecurityErrorResponse.java
trunk/core/src/main/org/jboss/portal/core/controller/command/response/UnavailableResourceResponse.java
trunk/core/src/main/org/jboss/portal/core/controller/portlet/ControllerResponseFactory.java
trunk/core/src/main/org/jboss/portal/core/controller/portlet/PortletActionResponse.java
trunk/core/src/main/org/jboss/portal/core/model/instance/command/response/PortletInstanceActionResponse.java
trunk/core/src/main/org/jboss/portal/core/model/portal/command/response/MarkupResponse.java
trunk/core/src/main/org/jboss/portal/core/model/portal/command/response/PortletWindowActionResponse.java
trunk/core/src/main/org/jboss/portal/core/model/portal/content/WindowRendition.java
trunk/core/src/main/org/jboss/portal/core/model/portal/control/
trunk/core/src/main/org/jboss/portal/core/model/portal/control/ControlConstants.java
trunk/core/src/main/org/jboss/portal/core/model/portal/control/ControlContext.java
trunk/core/src/main/org/jboss/portal/core/model/portal/control/portal/
trunk/core/src/main/org/jboss/portal/core/model/portal/control/portal/DefaultPortalControlPolicy.java
trunk/core/src/main/org/jboss/portal/core/model/portal/control/portal/PortalControlContext.java
trunk/core/src/main/org/jboss/portal/core/model/portal/control/portal/PortalControlPolicy.java
trunk/core/src/main/org/jboss/portal/core/model/portal/control/window/
trunk/core/src/main/org/jboss/portal/core/model/portal/control/window/DefaultWindowControlPolicy.java
trunk/core/src/main/org/jboss/portal/core/model/portal/control/window/WindowControlContext.java
trunk/core/src/main/org/jboss/portal/core/model/portal/control/window/WindowControlPolicy.java
trunk/core/src/main/org/jboss/portal/core/theme/WindowContextFactory.java
trunk/core/src/main/org/jboss/portal/core/ui/portlet/
trunk/core/src/main/org/jboss/portal/core/ui/portlet/PortletHelper.java
trunk/core/src/main/org/jboss/portal/core/ui/portlet/catalog/
trunk/core/src/main/org/jboss/portal/core/ui/portlet/catalog/CatalogPortlet.java
trunk/core/src/main/org/jboss/portal/core/ui/portlet/role/
trunk/core/src/main/org/jboss/portal/core/ui/portlet/role/RolePortlet.java
trunk/core/src/main/org/jboss/portal/core/ui/portlet/user/
trunk/core/src/main/org/jboss/portal/core/ui/portlet/user/UserPortlet.java
trunk/core/src/main/org/jboss/portal/core/ui/portlet/user/UserPortletConstants.java
trunk/core/src/resources/portal-core-war/WEB-INF/jsp/control/
trunk/core/src/resources/portal-core-war/WEB-INF/jsp/control/aggregation_error.jsp
trunk/core/src/resources/portal-core-war/WEB-INF/jsp/control/error.jsp
Removed:
trunk/core/src/main/org/jboss/portal/core/controller/ControllerSecurityException.java
trunk/core/src/main/org/jboss/portal/core/controller/ResourceAccessDeniedException.java
trunk/core/src/main/org/jboss/portal/core/controller/ResourceNotFoundException.java
trunk/core/src/main/org/jboss/portal/core/controller/classic/ThrowableResponseHandler.java
trunk/core/src/main/org/jboss/portal/core/controller/portlet/PortletResponse.java
trunk/core/src/main/org/jboss/portal/core/controller/portlet/PortletResponseHandler.java
trunk/core/src/main/org/jboss/portal/core/model/instance/command/response/PortletInstanceResponse.java
trunk/core/src/main/org/jboss/portal/core/model/portal/command/response/PortletWindowResponse.java
trunk/core/src/main/org/jboss/portal/core/portlet/PortletHelper.java
trunk/core/src/main/org/jboss/portal/core/portlet/catalog/CatalogPortlet.java
trunk/core/src/main/org/jboss/portal/core/portlet/role/RolePortlet.java
trunk/core/src/main/org/jboss/portal/core/portlet/user/UserPortlet.java
trunk/core/src/main/org/jboss/portal/core/portlet/user/UserPortletConstants.java
trunk/core/src/main/org/jboss/portal/core/theme/WindowRendition.java
Modified:
trunk/common/src/main/org/jboss/portal/common/util/Exceptions.java
trunk/core-admin/src/main/org/jboss/portal/core/admin/ui/PropertiesInfo.java
trunk/core-admin/src/main/org/jboss/portal/core/admin/ui/PropertyInfo.java
trunk/core-cms/src/main/org/jboss/portal/core/cms/content/InternalCMSContentProvider.java
trunk/core/src/main/org/jboss/portal/core/aspects/controller/PageCustomizerInterceptor.java
trunk/core/src/main/org/jboss/portal/core/aspects/controller/PolicyEnforcementInterceptor.java
trunk/core/src/main/org/jboss/portal/core/aspects/controller/node/EventBroadcasterInterceptor.java
trunk/core/src/main/org/jboss/portal/core/controller/Controller.java
trunk/core/src/main/org/jboss/portal/core/controller/ControllerCommand.java
trunk/core/src/main/org/jboss/portal/core/controller/ControllerContext.java
trunk/core/src/main/org/jboss/portal/core/controller/ajax/AjaxResponseHandler.java
trunk/core/src/main/org/jboss/portal/core/controller/classic/ClassicResponseHandler.java
trunk/core/src/main/org/jboss/portal/core/controller/handler/HTTPResponse.java
trunk/core/src/main/org/jboss/portal/core/controller/handler/ResponseHandler.java
trunk/core/src/main/org/jboss/portal/core/impl/model/content/InternalContentProvider.java
trunk/core/src/main/org/jboss/portal/core/impl/model/content/generic/InternalGenericContentProvider.java
trunk/core/src/main/org/jboss/portal/core/model/instance/command/PortletInstanceCommand.java
trunk/core/src/main/org/jboss/portal/core/model/instance/command/action/InvokePortletInstanceActionCommand.java
trunk/core/src/main/org/jboss/portal/core/model/portal/DefaultPortalCommandFactory.java
trunk/core/src/main/org/jboss/portal/core/model/portal/PortalObjectContainer.java
trunk/core/src/main/org/jboss/portal/core/model/portal/PortalObjectResponseHandler.java
trunk/core/src/main/org/jboss/portal/core/model/portal/command/ContextCommand.java
trunk/core/src/main/org/jboss/portal/core/model/portal/command/PageCommand.java
trunk/core/src/main/org/jboss/portal/core/model/portal/command/PortalCommand.java
trunk/core/src/main/org/jboss/portal/core/model/portal/command/PortalObjectCommand.java
trunk/core/src/main/org/jboss/portal/core/model/portal/command/WindowCommand.java
trunk/core/src/main/org/jboss/portal/core/model/portal/command/action/ImportPageToDashboardCommand.java
trunk/core/src/main/org/jboss/portal/core/model/portal/command/action/InvokePortletWindowActionCommand.java
trunk/core/src/main/org/jboss/portal/core/model/portal/command/action/InvokePortletWindowRenderCommand.java
trunk/core/src/main/org/jboss/portal/core/model/portal/command/action/InvokeWindowCommand.java
trunk/core/src/main/org/jboss/portal/core/model/portal/command/action/MoveWindowCommand.java
trunk/core/src/main/org/jboss/portal/core/model/portal/command/render/RenderPageCommand.java
trunk/core/src/main/org/jboss/portal/core/model/portal/command/render/RenderWindowCommand.java
trunk/core/src/main/org/jboss/portal/core/model/portal/command/view/ViewContextCommand.java
trunk/core/src/main/org/jboss/portal/core/model/portal/command/view/ViewPageCommand.java
trunk/core/src/main/org/jboss/portal/core/model/portal/command/view/ViewPortalCommand.java
trunk/core/src/main/org/jboss/portal/core/model/portal/content/ContentRenderer.java
trunk/core/src/main/org/jboss/portal/core/model/portal/navstate/WindowNavigationalState.java
trunk/core/src/main/org/jboss/portal/core/theme/PageRendition.java
trunk/core/src/resources/portal-core-sar/META-INF/jboss-service.xml
trunk/core/src/resources/portal-core-sar/conf/data/default-object.xml
trunk/core/src/resources/portal-core-sar/conf/hibernate/user/setup.txt
trunk/core/src/resources/portal-core-war/WEB-INF/portlet.xml
trunk/portlet/src/main/org/jboss/portal/portlet/invocation/response/ErrorResponse.java
trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/InvocationHandler.java
trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/MarkupHandler.java
Log:
JBPORTAL-1466 : Provide customizable error handling
Modified: trunk/common/src/main/org/jboss/portal/common/util/Exceptions.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/common/util/Exceptions.java 2007-06-08 13:50:21
UTC (rev 7394)
+++ trunk/common/src/main/org/jboss/portal/common/util/Exceptions.java 2007-06-11 11:31:36
UTC (rev 7395)
@@ -50,19 +50,29 @@
public static String toHTML(Throwable throwable, boolean deep)
{
StringBuffer tmp = new StringBuffer();
- tmp.append("<div><pre
style=\"text-align:left;\"><code>");
+ appendHTMLTo(tmp, throwable, deep);
+ return tmp.toString();
+ }
+
+ public static void appendHTMLTo(StringBuffer buffer, Throwable throwable)
+ {
+ appendHTMLTo(buffer, throwable, false);
+ }
+
+ public static void appendHTMLTo(StringBuffer buffer, Throwable throwable, boolean
deep)
+ {
+ buffer.append("<div><pre
style=\"text-align:left;\"><code>");
while (throwable != null)
{
- tmp.append(throwable.toString()).append('\n');
+ buffer.append(throwable.toString()).append('\n');
StackTraceElement[] elts = throwable.getStackTrace();
for (int j = 0; j < elts.length; j++)
{
StackTraceElement elt = elts[j];
- tmp.append("\tat ").append(elt).append("\n");
+ buffer.append("\tat ").append(elt).append("\n");
}
throwable = throwable.getCause();
}
- tmp.append("</code></pre></div>");
- return tmp.toString();
+ buffer.append("</code></pre></div>");
}
}
Added:
trunk/core/src/main/org/jboss/portal/core/aspects/controller/ControlInterceptor.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/core/aspects/controller/ControlInterceptor.java
(rev 0)
+++
trunk/core/src/main/org/jboss/portal/core/aspects/controller/ControlInterceptor.java 2007-06-11
11:31:36 UTC (rev 7395)
@@ -0,0 +1,71 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.core.aspects.controller;
+
+import org.jboss.portal.core.controller.ControllerInterceptor;
+import org.jboss.portal.core.controller.ControllerResponse;
+import org.jboss.portal.core.controller.ControllerCommand;
+import org.jboss.portal.core.model.portal.command.PortalCommand;
+import org.jboss.portal.core.model.portal.control.portal.PortalControlContext;
+import org.jboss.portal.core.model.portal.control.portal.PortalControlPolicy;
+import org.jboss.portal.core.model.portal.control.portal.DefaultPortalControlPolicy;
+import org.jboss.portal.core.model.portal.PortalObjectId;
+import org.jboss.portal.common.invocation.InvocationException;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class ControlInterceptor extends ControllerInterceptor
+{
+
+ /** . */
+ private PortalControlPolicy portalControlPolicy;
+
+ public PortalControlPolicy getPortalControlPolicy()
+ {
+ return portalControlPolicy;
+ }
+
+ public void setPortalControlPolicy(PortalControlPolicy portalControlPolicy)
+ {
+ this.portalControlPolicy = portalControlPolicy;
+ }
+
+ public ControllerResponse invoke(ControllerCommand cmd) throws Exception,
InvocationException
+ {
+ ControllerResponse response = (ControllerResponse)cmd.invokeNext();
+
+ //
+ if (cmd instanceof PortalCommand && cmd.getControllerContext().getDepth()
== 1)
+ {
+ PortalObjectId portalId = ((PortalCommand)cmd).getTargetId();
+ PortalControlContext context = new
PortalControlContext(cmd.getControllerContext(), portalId, response);
+ portalControlPolicy.doControl(context);
+ response = context.getResponse();
+ }
+
+ //
+ return response;
+ }
+}
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-06-08
13:50:21 UTC (rev 7394)
+++
trunk/core/src/main/org/jboss/portal/core/aspects/controller/PageCustomizerInterceptor.java 2007-06-11
11:31:36 UTC (rev 7395)
@@ -22,26 +22,20 @@
******************************************************************************/
package org.jboss.portal.core.aspects.controller;
-import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
-import javax.servlet.RequestDispatcher;
-import javax.servlet.ServletContext;
-import javax.servlet.ServletException;
-
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;
import org.jboss.portal.core.controller.ControllerCommand;
import org.jboss.portal.core.controller.ControllerContext;
import org.jboss.portal.core.controller.ControllerInterceptor;
import org.jboss.portal.core.controller.ControllerResponse;
+import org.jboss.portal.core.controller.ControllerRequestDispatcher;
import org.jboss.portal.core.controller.command.SignOutCommand;
import org.jboss.portal.core.model.CustomizationManager;
import
org.jboss.portal.core.model.instance.command.action.InvokePortletInstanceRenderCommand;
@@ -62,7 +56,6 @@
import org.jboss.portal.portlet.PortletParametersStateString;
import org.jboss.portal.security.PortalSecurityException;
import org.jboss.portal.security.spi.auth.PortalAuthorizationManagerFactory;
-import org.jboss.portal.server.ServerInvocationContext;
import org.jboss.portal.server.config.ServerConfig;
import org.jboss.portal.server.request.URLContext;
import org.jboss.portal.server.request.URLFormat;
@@ -126,6 +119,7 @@
{
PageRendition rendition = (PageRendition)resp;
+ //
if (cmd instanceof RenderPageCommand)
{
RenderPageCommand rpc = (RenderPageCommand)cmd;
@@ -173,23 +167,15 @@
public String injectDashboardNav(ControllerCommand cc)
{
ControllerContext controllerCtx = cc.getControllerContext();
- ServerInvocationContext serverContext =
controllerCtx.getServerInvocation().getServerContext();
- ServletContext servletContext =
serverContext.getClientRequest().getSession().getServletContext().getContext(targetContextPath);
- RequestDispatcher rd = servletContext.getRequestDispatcher(headerPath);
+ ControllerRequestDispatcher rd =
controllerCtx.getRequestDispatcher(targetContextPath, headerPath);
//
if (rd != null)
{
- BufferingResponseWrapper response = new
BufferingResponseWrapper(serverContext.getClientResponse());
- BufferingRequestWrapper request = new BufferingRequestWrapper(
- serverContext.getClientRequest(),
- targetContextPath,
- cc.getControllerContext().getServerInvocation().getRequest().getLocales());
-
// Get user
Controller controller = controllerCtx.getController();
User user = controllerCtx.getUser();
- request.setAttribute("org.jboss.portal.header.USER", user);
+ rd.setAttribute("org.jboss.portal.header.USER", user);
if (user == null)
{
@@ -210,7 +196,7 @@
{
portalURL = new PortalURLImpl(cc, controllerCtx, Boolean.TRUE, null);
}
- request.setAttribute("org.jboss.portal.header.LOGIN_URL",
portalURL);
+ rd.setAttribute("org.jboss.portal.header.LOGIN_URL", portalURL);
}
// Edit dashboard page || Copy to dashboard link
@@ -229,7 +215,7 @@
PortletParametersStateString navState = new
PortletParametersStateString();
navState.setValue("editPageSelect", pageName);
InvokePortletInstanceRenderCommand command = new
InvokePortletInstanceRenderCommand("DashboardConfigPortletInstance", navState);
-
request.setAttribute("org.jboss.portal.header.EDIT_DASHBOARD_URL", new
PortalURLImpl(command, controllerCtx, null, null));
+ rd.setAttribute("org.jboss.portal.header.EDIT_DASHBOARD_URL",
new PortalURLImpl(command, controllerCtx, null, null));
}
else
{
@@ -241,7 +227,7 @@
if (dashboard.getChild(pageName) == null)
{
ImportPageToDashboardCommand iptdc = new
ImportPageToDashboardCommand(page.getId());
-
request.setAttribute("org.jboss.portal.header.COPY_TO_DASHBOARD_URL", new
PortalURLImpl(iptdc, controllerCtx, null, null));
+
rd.setAttribute("org.jboss.portal.header.COPY_TO_DASHBOARD_URL", new
PortalURLImpl(iptdc, controllerCtx, null, null));
}
}
@@ -255,7 +241,7 @@
if (dashboard != null)
{
ViewPortalCommand vdc = new ViewPortalCommand(dashboard.getId());
- request.setAttribute("org.jboss.portal.header.DASHBOARD_URL",
new PortalURLImpl(vdc, controllerCtx, null, null));
+ rd.setAttribute("org.jboss.portal.header.DASHBOARD_URL", new
PortalURLImpl(vdc, controllerCtx, null, null));
}
}
@@ -278,7 +264,7 @@
if
(controller.getPortalAuthorizationManagerFactory().getManager().checkPermission(perm))
{
ViewPageCommand showadmin = new ViewPageCommand(adminPortalId);
-
request.setAttribute("org.jboss.portal.header.ADMIN_PORTAL_URL", new
PortalURLImpl(showadmin, controllerCtx, null, null));
+ rd.setAttribute("org.jboss.portal.header.ADMIN_PORTAL_URL",
new PortalURLImpl(showadmin, controllerCtx, null, null));
}
}
catch (PortalSecurityException e)
@@ -292,27 +278,16 @@
{
// Link to default page of default portal
ViewPageCommand vpc = new ViewPageCommand(defaultPortalId);
- request.setAttribute("org.jboss.portal.header.DEFAULT_PORTAL_URL",
new PortalURLImpl(vpc, controllerCtx, null, null));
+ rd.setAttribute("org.jboss.portal.header.DEFAULT_PORTAL_URL", new
PortalURLImpl(vpc, controllerCtx, null, null));
}
//
SignOutCommand cmd = new SignOutCommand();
- request.setAttribute("org.jboss.portal.header.SIGN_OUT_URL", new
PortalURLImpl(cmd, controllerCtx, Boolean.FALSE, null));
+ rd.setAttribute("org.jboss.portal.header.SIGN_OUT_URL", new
PortalURLImpl(cmd, controllerCtx, Boolean.FALSE, null));
//
- try
- {
- rd.include(request, response);
- return response.getContent();
- }
- catch (ServletException e1)
- {
- e1.printStackTrace();
- }
- catch (IOException e1)
- {
- e1.printStackTrace();
- }
+ rd.include();
+ return rd.getMarkup();
}
//
@@ -322,44 +297,17 @@
public String injectTabbedNav(RenderPageCommand rpc)
{
ControllerContext controllerCtx = rpc.getControllerContext();
+ ControllerRequestDispatcher rd =
controllerCtx.getRequestDispatcher(targetContextPath, tabsPath);
//
- ServerInvocationContext serverContext =
controllerCtx.getServerInvocation().getServerContext();
-
- // Get the right servlet context
- ServletContext servletContext =
serverContext.getClientRequest().getSession().getServletContext().getContext(targetContextPath);
-
- // Get request dispatcher
- RequestDispatcher rd = servletContext.getRequestDispatcher(tabsPath);
-
- //
if (rd != null)
{
- // Wrap request and response safely
- BufferingResponseWrapper response = new
BufferingResponseWrapper(serverContext.getClientResponse());
- BufferingRequestWrapper request = new BufferingRequestWrapper(
- serverContext.getClientRequest(),
- targetContextPath,
- rpc.getControllerContext().getServerInvocation().getRequest().getLocales());
+ rd.setAttribute("org.jboss.portal.api.PORTAL_NODE",
Navigation.getCurrentNode());
+ rd.setAttribute("org.jboss.portal.api.PORTAL_RUNTIME_CONTEXT",
Navigation.getPortalRuntimeContext());
//
- request.setAttribute("org.jboss.portal.api.PORTAL_NODE",
Navigation.getCurrentNode());
- request.setAttribute("org.jboss.portal.api.PORTAL_RUNTIME_CONTEXT",
Navigation.getPortalRuntimeContext());
-
- //
- try
- {
- rd.include(request, response);
- return response.getContent();
- }
- catch (ServletException e)
- {
- e.printStackTrace();
- }
- catch (IOException e)
- {
- e.printStackTrace();
- }
+ rd.include();
+ return rd.getMarkup();
}
//
Modified:
trunk/core/src/main/org/jboss/portal/core/aspects/controller/PolicyEnforcementInterceptor.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/core/aspects/controller/PolicyEnforcementInterceptor.java 2007-06-08
13:50:21 UTC (rev 7394)
+++
trunk/core/src/main/org/jboss/portal/core/aspects/controller/PolicyEnforcementInterceptor.java 2007-06-11
11:31:36 UTC (rev 7395)
@@ -25,13 +25,12 @@
import org.jboss.logging.Logger;
import org.jboss.portal.common.invocation.InvocationException;
-import org.jboss.portal.core.controller.ControllerCommand;
-import org.jboss.portal.core.controller.ControllerInterceptor;
-import org.jboss.portal.core.controller.ControllerSecurityException;
-import org.jboss.portal.core.controller.ControllerResponse;
-import org.jboss.portal.security.PortalSecurityException;
+import org.jboss.portal.core.controller.*;
+import org.jboss.portal.core.controller.SecurityException;
+import org.jboss.portal.core.controller.command.response.SecurityErrorResponse;
import org.jboss.portal.security.spi.auth.PortalAuthorizationManager;
import org.jboss.portal.security.spi.auth.PortalAuthorizationManagerFactory;
+import org.jboss.portal.security.PortalSecurityException;
/**
* This aspect enforces security policy for all commands.
@@ -42,8 +41,6 @@
* @author <a href="mailto:mholzner@novell.com>Martin Holzner</a>
* @author julien(a)jboss.org
* @version $LastChangedRevision$, $LastChangedDate$
- * @see java.security.Permission
- * @see java.security.Policy
*/
public final class PolicyEnforcementInterceptor extends ControllerInterceptor
{
@@ -66,15 +63,17 @@
PortalAuthorizationManagerFactory pamf =
cmd.getControllerContext().getController().getPortalAuthorizationManagerFactory();
PortalAuthorizationManager pam = pamf.getManager();
cmd.enforceSecurity(pam);
- return (ControllerResponse)cmd.invokeNext();
}
catch (PortalSecurityException e)
{
- if (isTrace)
- {
- log.error("Security Exception", e);
- }
- throw new ControllerSecurityException(e);
+ return new SecurityErrorResponse(e, SecurityErrorResponse.NOT_AUTHORIZED,
true);
}
+ catch (SecurityException e)
+ {
+ return new SecurityErrorResponse(e, SecurityErrorResponse.NOT_AUTHORIZED,
false);
+ }
+
+ //
+ return (ControllerResponse)cmd.invokeNext();
}
}
\ No newline at end of file
Added:
trunk/core/src/main/org/jboss/portal/core/aspects/controller/ResourceAcquisitionInterceptor.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/core/aspects/controller/ResourceAcquisitionInterceptor.java
(rev 0)
+++
trunk/core/src/main/org/jboss/portal/core/aspects/controller/ResourceAcquisitionInterceptor.java 2007-06-11
11:31:36 UTC (rev 7395)
@@ -0,0 +1,52 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.core.aspects.controller;
+
+import org.jboss.portal.core.controller.ControllerInterceptor;
+import org.jboss.portal.core.controller.ControllerResponse;
+import org.jboss.portal.core.controller.ControllerCommand;
+import org.jboss.portal.core.controller.NoSuchResourceException;
+import org.jboss.portal.core.controller.command.response.UnavailableResourceResponse;
+import org.jboss.portal.common.invocation.InvocationException;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class ResourceAcquisitionInterceptor extends ControllerInterceptor
+{
+ public ControllerResponse invoke(ControllerCommand cmd) throws Exception,
InvocationException
+ {
+ try
+ {
+ cmd.acquireResources();
+ }
+ catch (NoSuchResourceException e)
+ {
+ return new UnavailableResourceResponse(e.getRef(), false);
+ }
+
+ //
+ return (ControllerResponse)cmd.invokeNext();
+ }
+}
Modified:
trunk/core/src/main/org/jboss/portal/core/aspects/controller/node/EventBroadcasterInterceptor.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/core/aspects/controller/node/EventBroadcasterInterceptor.java 2007-06-08
13:50:21 UTC (rev 7394)
+++
trunk/core/src/main/org/jboss/portal/core/aspects/controller/node/EventBroadcasterInterceptor.java 2007-06-11
11:31:36 UTC (rev 7395)
@@ -280,7 +280,7 @@
event.setMode(navstate.getMode());
event.setWindowState(navstate.getWindowState());
- StateString parametersState = navstate.getState();
+ StateString parametersState = navstate.getContentState();
if (parametersState instanceof PortletParametersStateString)
{
Map params =
((PortletParametersStateString)parametersState).getParameters();
Copied: trunk/core/src/main/org/jboss/portal/core/controller/AccessDeniedException.java
(from rev 7371,
trunk/core/src/main/org/jboss/portal/core/controller/ResourceAccessDeniedException.java)
===================================================================
--- trunk/core/src/main/org/jboss/portal/core/controller/AccessDeniedException.java
(rev 0)
+++
trunk/core/src/main/org/jboss/portal/core/controller/AccessDeniedException.java 2007-06-11
11:31:36 UTC (rev 7395)
@@ -0,0 +1,55 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.core.controller;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision$
+ */
+public class AccessDeniedException extends SecurityException
+{
+
+ /** The serialVersionUID */
+ private static final long serialVersionUID = 3506674156010581342L;
+
+ /** Object reference pointing to the not found object. */
+ private String ref;
+
+ public AccessDeniedException(String message, String ref)
+ {
+ super(ref + " has denied access: " + message);
+ this.ref = ref;
+ }
+
+ public AccessDeniedException(String ref)
+ {
+ super(ref + " has denied access");
+ this.ref = ref;
+ }
+
+ /** Return some kind of reference to the not found object. */
+ public String getRef()
+ {
+ return ref;
+ }
+}
Property changes on:
trunk/core/src/main/org/jboss/portal/core/controller/AccessDeniedException.java
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Modified: trunk/core/src/main/org/jboss/portal/core/controller/Controller.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/core/controller/Controller.java 2007-06-08
13:50:21 UTC (rev 7394)
+++ trunk/core/src/main/org/jboss/portal/core/controller/Controller.java 2007-06-11
11:31:36 UTC (rev 7395)
@@ -25,7 +25,7 @@
import org.jboss.portal.theme.PageService;
import org.jboss.portal.core.controller.command.mapper.CommandFactory;
import org.jboss.portal.core.controller.command.mapper.URLFactory;
-import org.jboss.portal.core.controller.command.response.ThrowableResponse;
+import org.jboss.portal.core.controller.command.response.ErrorResponse;
import org.jboss.portal.core.controller.handler.HandlerResponse;
import org.jboss.portal.core.controller.handler.ResponseForward;
import org.jboss.portal.core.controller.handler.HTTPResponse;
@@ -33,6 +33,8 @@
import org.jboss.portal.core.controller.handler.ResponseHandler;
import org.jboss.portal.core.controller.handler.AjaxResponse;
import org.jboss.portal.core.controller.handler.ResponseHandlerException;
+import org.jboss.portal.core.model.portal.control.portal.PortalControlPolicy;
+import org.jboss.portal.core.model.portal.control.window.WindowControlPolicy;
import org.jboss.portal.core.model.portal.PortalObjectContainer;
import org.jboss.portal.core.model.portal.content.ContentRendererRegistry;
import org.jboss.portal.core.model.instance.InstanceContainer;
@@ -89,6 +91,12 @@
/** . */
protected ServletContainerContext servletContainerContext;
+ /** . */
+ protected PortalControlPolicy portalControlPolicy;
+
+ /** . */
+ protected WindowControlPolicy windowControlPolicy;
+
public ContentRendererRegistry getContentRendererRegistry()
{
return contentRendererRegistry;
@@ -194,6 +202,26 @@
return servletContainerContext;
}
+ public WindowControlPolicy getWindowControlPolicy()
+ {
+ return windowControlPolicy;
+ }
+
+ public void setWindowControlPolicy(WindowControlPolicy windowControlPolicy)
+ {
+ this.windowControlPolicy = windowControlPolicy;
+ }
+
+ public PortalControlPolicy getPortalControlPolicy()
+ {
+ return portalControlPolicy;
+ }
+
+ public void setPortalControlPolicy(PortalControlPolicy portalControlPolicy)
+ {
+ this.portalControlPolicy = portalControlPolicy;
+ }
+
public final void handle(ServerInvocation invocation) throws ServerException
{
// Create controller context
@@ -202,10 +230,9 @@
// Invoke the chain that creates the initial command
ControllerCommand cmd = commandFactory.doMapping(controllerContext, invocation,
invocation.getServerContext().getPortalHost(),
invocation.getServerContext().getPortalContextPath(),
invocation.getServerContext().getPortalRequestPath());
- //
+ // Handle that case
if (cmd == null)
{
- // Handle that case
throw new ServerException("No command was produced by the command
factory");
}
@@ -222,30 +249,32 @@
*/
protected void processCommand(ControllerContext controllerContext, ControllerCommand
command) throws ServerException
{
- ControllerResponse response = executeCommand(controllerContext, command);
+ ControllerResponse response;
//
- if (response == null)
+ try
{
+ response = controllerContext.execute(command);
+ }
+ catch (CommandRedirectionException e)
+ {
+ processHandlerResponse(
+ controllerContext,
+ command,
+ new CommandForward(e.getRedirection(), null));
+
+ // We are done
return;
}
- if (response instanceof ThrowableResponse)
+ catch (ControllerException e)
{
- ThrowableResponse throwableResponse = (ThrowableResponse)response;
- Throwable t = throwableResponse.getThrowable();
+ response = new ErrorResponse(e, true);
+ }
- // Handle the special exception here
- if (t instanceof CommandRedirectionException)
- {
- CommandRedirectionException commandRedirection =
(CommandRedirectionException)t;
- processHandlerResponse(
- controllerContext,
- command,
- new CommandForward(commandRedirection.getRedirection(), null));
-
- // We are done
- return;
- }
+ //
+ if (response == null)
+ {
+ response = new ErrorResponse("No response was provided by the invocation of
" + command, true);
}
//
@@ -304,18 +333,6 @@
}
}
- protected ControllerResponse executeCommand(ControllerContext controllerContext,
ControllerCommand command)
- {
- try
- {
- return controllerContext.execute(command);
- }
- catch (Throwable t)
- {
- return new ThrowableResponse(t);
- }
- }
-
/**
* All http responses in the stack should be handled here.
*/
Modified: trunk/core/src/main/org/jboss/portal/core/controller/ControllerCommand.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/core/controller/ControllerCommand.java 2007-06-08
13:50:21 UTC (rev 7394)
+++ trunk/core/src/main/org/jboss/portal/core/controller/ControllerCommand.java 2007-06-11
11:31:36 UTC (rev 7395)
@@ -95,13 +95,21 @@
* Enforce the security on this command.
*
* @throws PortalSecurityException
- * @throws org.jboss.portal.core.controller.ControllerSecurityException
+ * @throws org.jboss.portal.core.controller.SecurityException
*
*/
- public void enforceSecurity(PortalAuthorizationManager pam) throws
ControllerSecurityException, PortalSecurityException
+ public void enforceSecurity(PortalAuthorizationManager pam) throws SecurityException
{
}
+ public void acquireResources() throws NoSuchResourceException
+ {
+ }
+
+ public void releaseResources()
+ {
+ }
+
/** Contextualize the command. */
public final void createContext(ControllerContext context) throws ControllerException
{
@@ -124,7 +132,7 @@
}
}
- protected void create() throws ControllerException
+ protected void create()
{
}
Modified: trunk/core/src/main/org/jboss/portal/core/controller/ControllerContext.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/core/controller/ControllerContext.java 2007-06-08
13:50:21 UTC (rev 7394)
+++ trunk/core/src/main/org/jboss/portal/core/controller/ControllerContext.java 2007-06-11
11:31:36 UTC (rev 7395)
@@ -25,8 +25,11 @@
import org.jboss.portal.common.invocation.AbstractInvocationContext;
import org.jboss.portal.common.invocation.InterceptorStack;
import org.jboss.portal.common.invocation.InvocationException;
+import org.jboss.portal.common.servlet.BufferingResponseWrapper;
+import org.jboss.portal.common.servlet.BufferingRequestWrapper;
import org.jboss.portal.server.ServerInvocation;
import org.jboss.portal.server.ServerURL;
+import org.jboss.portal.server.ServerInvocationContext;
import org.jboss.portal.server.request.URLContext;
import org.jboss.portal.server.request.URLFormat;
import org.jboss.portal.identity.User;
@@ -34,6 +37,8 @@
import org.jboss.portal.core.model.portal.navstate.PortalObjectNavigationalStateContext;
import javax.servlet.http.HttpServletRequest;
+import javax.servlet.ServletContext;
+import javax.servlet.RequestDispatcher;
import java.util.Map;
/**
@@ -189,4 +194,25 @@
{
return (Map)getAttribute(ServerInvocation.PRINCIPAL_SCOPE,
UserInterceptor.PROFILE_KEY);
}
+
+ public ControllerRequestDispatcher getRequestDispatcher(String contextPath, String
path)
+ {
+ ServerInvocationContext serverContext = serverInvocation.getServerContext();
+ ServletContext servletContext =
serverContext.getClientRequest().getSession().getServletContext().getContext(contextPath);
+ RequestDispatcher rd = servletContext.getRequestDispatcher(path);
+
+ //
+ if (rd != null)
+ {
+ BufferingRequestWrapper bufferReq = new BufferingRequestWrapper(
+ serverContext.getClientRequest(),
+ contextPath,
+ serverInvocation.getRequest().getLocales());
+ BufferingResponseWrapper bufferResp = new
BufferingResponseWrapper(serverContext.getClientResponse());
+ return new ControllerRequestDispatcher(rd, bufferReq, bufferResp);
+ }
+
+ //
+ return null;
+ }
}
Added:
trunk/core/src/main/org/jboss/portal/core/controller/ControllerRequestDispatcher.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/core/controller/ControllerRequestDispatcher.java
(rev 0)
+++
trunk/core/src/main/org/jboss/portal/core/controller/ControllerRequestDispatcher.java 2007-06-11
11:31:36 UTC (rev 7395)
@@ -0,0 +1,81 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.core.controller;
+
+import org.jboss.portal.common.servlet.BufferingResponseWrapper;
+import org.jboss.portal.common.servlet.BufferingRequestWrapper;
+
+import javax.servlet.RequestDispatcher;
+import javax.servlet.ServletException;
+import java.io.IOException;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class ControllerRequestDispatcher
+{
+
+ private final RequestDispatcher dispatcher;
+ private final BufferingRequestWrapper req;
+ private final BufferingResponseWrapper resp;
+
+ public ControllerRequestDispatcher(RequestDispatcher dispatcher,
BufferingRequestWrapper req, BufferingResponseWrapper resp)
+ {
+ this.dispatcher = dispatcher;
+ this.req = req;
+ this.resp = resp;
+ }
+
+ public String getMarkup()
+ {
+ return resp.getContent();
+ }
+
+ public void setAttribute(String name, Object value)
+ {
+ req.setAttribute(name, value);
+ }
+
+ public Object getAttribute(String name)
+ {
+ return req.getAttribute(name);
+ }
+
+ public void include()
+ {
+ try
+ {
+ dispatcher.include(req, resp);
+ }
+ catch (ServletException e)
+ {
+ e.printStackTrace();
+ }
+ catch (IOException e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+}
Deleted:
trunk/core/src/main/org/jboss/portal/core/controller/ControllerSecurityException.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/core/controller/ControllerSecurityException.java 2007-06-08
13:50:21 UTC (rev 7394)
+++
trunk/core/src/main/org/jboss/portal/core/controller/ControllerSecurityException.java 2007-06-11
11:31:36 UTC (rev 7395)
@@ -1,52 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, and individual *
- * contributors as indicated by the @authors tag. See the *
- * copyright.txt in the distribution for a full listing of *
- * individual contributors. *
- * *
- * This is free software; you can redistribute it and/or modify it *
- * under the terms of the GNU Lesser General Public License as *
- * published by the Free Software Foundation; either version 2.1 of *
- * the License, or (at your option) any later version. *
- * *
- * This software is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this software; if not, write to the Free *
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
- ******************************************************************************/
-package org.jboss.portal.core.controller;
-
-/**
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision$
- */
-public class ControllerSecurityException extends ControllerException
-{
- /** The serialVersionUID */
- private static final long serialVersionUID = -157650218749390553L;
-
- public ControllerSecurityException()
- {
- }
-
- public ControllerSecurityException(String message)
- {
- super(message);
- }
-
- public ControllerSecurityException(Throwable cause)
- {
- super(cause);
- }
-
- public ControllerSecurityException(String message, Throwable cause)
- {
- super(message, cause);
- }
-}
Copied: trunk/core/src/main/org/jboss/portal/core/controller/NoSuchResourceException.java
(from rev 7371,
trunk/core/src/main/org/jboss/portal/core/controller/ResourceNotFoundException.java)
===================================================================
--- trunk/core/src/main/org/jboss/portal/core/controller/NoSuchResourceException.java
(rev 0)
+++
trunk/core/src/main/org/jboss/portal/core/controller/NoSuchResourceException.java 2007-06-11
11:31:36 UTC (rev 7395)
@@ -0,0 +1,49 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.core.controller;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision$
+ */
+public class NoSuchResourceException extends ControllerException
+{
+
+ /** The serialVersionUID */
+ private static final long serialVersionUID = -1311521920998110717L;
+
+ /** Object reference pointing to the not found object. */
+ private String ref;
+
+ public NoSuchResourceException(String ref)
+ {
+ super("Resource not found " + ref);
+ this.ref = ref;
+ }
+
+ /** Return some kind of reference to the not found object. */
+ public String getRef()
+ {
+ return ref;
+ }
+}
Property changes on:
trunk/core/src/main/org/jboss/portal/core/controller/NoSuchResourceException.java
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Deleted:
trunk/core/src/main/org/jboss/portal/core/controller/ResourceAccessDeniedException.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/core/controller/ResourceAccessDeniedException.java 2007-06-08
13:50:21 UTC (rev 7394)
+++
trunk/core/src/main/org/jboss/portal/core/controller/ResourceAccessDeniedException.java 2007-06-11
11:31:36 UTC (rev 7395)
@@ -1,55 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, and individual *
- * contributors as indicated by the @authors tag. See the *
- * copyright.txt in the distribution for a full listing of *
- * individual contributors. *
- * *
- * This is free software; you can redistribute it and/or modify it *
- * under the terms of the GNU Lesser General Public License as *
- * published by the Free Software Foundation; either version 2.1 of *
- * the License, or (at your option) any later version. *
- * *
- * This software is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this software; if not, write to the Free *
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
- ******************************************************************************/
-package org.jboss.portal.core.controller;
-
-/**
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision$
- */
-public class ResourceAccessDeniedException extends ControllerSecurityException
-{
-
- /** The serialVersionUID */
- private static final long serialVersionUID = 3506674156010581342L;
-
- /** Object reference pointing to the not found object. */
- private String ref;
-
- public ResourceAccessDeniedException(String message, String ref)
- {
- super(ref + " has denied access: " + message);
- this.ref = ref;
- }
-
- public ResourceAccessDeniedException(String ref)
- {
- super(ref + " has denied access");
- this.ref = ref;
- }
-
- /** Return some kind of reference to the not found object. */
- public String getRef()
- {
- return ref;
- }
-}
Deleted:
trunk/core/src/main/org/jboss/portal/core/controller/ResourceNotFoundException.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/core/controller/ResourceNotFoundException.java 2007-06-08
13:50:21 UTC (rev 7394)
+++
trunk/core/src/main/org/jboss/portal/core/controller/ResourceNotFoundException.java 2007-06-11
11:31:36 UTC (rev 7395)
@@ -1,49 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, and individual *
- * contributors as indicated by the @authors tag. See the *
- * copyright.txt in the distribution for a full listing of *
- * individual contributors. *
- * *
- * This is free software; you can redistribute it and/or modify it *
- * under the terms of the GNU Lesser General Public License as *
- * published by the Free Software Foundation; either version 2.1 of *
- * the License, or (at your option) any later version. *
- * *
- * This software is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this software; if not, write to the Free *
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
- ******************************************************************************/
-package org.jboss.portal.core.controller;
-
-/**
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision$
- */
-public class ResourceNotFoundException extends ControllerException
-{
-
- /** The serialVersionUID */
- private static final long serialVersionUID = -1311521920998110717L;
-
- /** Object reference pointing to the not found object. */
- private String ref;
-
- public ResourceNotFoundException(String ref)
- {
- super("Resource not found " + ref);
- this.ref = ref;
- }
-
- /** Return some kind of reference to the not found object. */
- public String getRef()
- {
- return ref;
- }
-}
Copied: trunk/core/src/main/org/jboss/portal/core/controller/SecurityException.java (from
rev 7371,
trunk/core/src/main/org/jboss/portal/core/controller/ControllerSecurityException.java)
===================================================================
--- trunk/core/src/main/org/jboss/portal/core/controller/SecurityException.java
(rev 0)
+++ trunk/core/src/main/org/jboss/portal/core/controller/SecurityException.java 2007-06-11
11:31:36 UTC (rev 7395)
@@ -0,0 +1,52 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.core.controller;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision$
+ */
+public class SecurityException extends ControllerException
+{
+ /** The serialVersionUID */
+ private static final long serialVersionUID = -157650218749390553L;
+
+ public SecurityException()
+ {
+ }
+
+ public SecurityException(String message)
+ {
+ super(message);
+ }
+
+ public SecurityException(Throwable cause)
+ {
+ super(cause);
+ }
+
+ public SecurityException(String message, Throwable cause)
+ {
+ super(message, cause);
+ }
+}
Property changes on:
trunk/core/src/main/org/jboss/portal/core/controller/SecurityException.java
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Modified:
trunk/core/src/main/org/jboss/portal/core/controller/ajax/AjaxResponseHandler.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/core/controller/ajax/AjaxResponseHandler.java 2007-06-08
13:50:21 UTC (rev 7394)
+++
trunk/core/src/main/org/jboss/portal/core/controller/ajax/AjaxResponseHandler.java 2007-06-11
11:31:36 UTC (rev 7395)
@@ -30,28 +30,27 @@
import org.jboss.portal.core.controller.ControllerResponse;
import org.jboss.portal.core.controller.handler.ResponseHandlerException;
import org.jboss.portal.core.controller.handler.CommandForward;
-import org.jboss.portal.core.controller.portlet.PortletResponseHandler;
-import org.jboss.portal.core.model.portal.command.response.PortletWindowResponse;
+import org.jboss.portal.core.model.portal.command.response.PortletWindowActionResponse;
import org.jboss.portal.core.model.portal.command.response.UpdateWindowResponse;
import org.jboss.portal.core.model.portal.command.response.UpdatePageResponse;
+import org.jboss.portal.core.model.portal.command.response.MarkupResponse;
import org.jboss.portal.core.model.portal.command.render.RenderPageCommand;
import org.jboss.portal.core.model.portal.command.render.RenderWindowCommand;
import org.jboss.portal.core.model.portal.command.view.ViewPageCommand;
+import
org.jboss.portal.core.model.portal.command.action.InvokePortletWindowRenderCommand;
import org.jboss.portal.core.model.portal.Window;
import org.jboss.portal.core.model.portal.Page;
import org.jboss.portal.core.model.portal.PortalObject;
import org.jboss.portal.core.model.portal.PortalObjectId;
import org.jboss.portal.core.model.portal.PortalObjectContainer;
-import org.jboss.portal.core.model.portal.PortalObjectPath;
+import org.jboss.portal.core.model.portal.content.WindowRendition;
import org.jboss.portal.core.model.portal.navstate.PortalObjectNavigationalStateContext;
import org.jboss.portal.core.model.portal.navstate.WindowNavigationalState;
import org.jboss.portal.core.navstate.NavigationalStateChange;
import org.jboss.portal.core.navstate.NavigationalStateObjectChange;
import org.jboss.portal.core.navstate.NavigationalStateKey;
-import org.jboss.portal.core.theme.WindowRendition;
+import org.jboss.portal.core.theme.WindowContextFactory;
import org.jboss.portal.server.ServerInvocation;
-import org.jboss.portal.portlet.invocation.response.PortletInvocationResponse;
-import org.jboss.portal.portlet.invocation.response.RenderResponse;
import org.jboss.portal.portlet.StateString;
import org.jboss.portal.WindowState;
import org.jboss.portal.Mode;
@@ -62,11 +61,9 @@
import org.jboss.portal.theme.LayoutService;
import org.jboss.portal.theme.PortalLayout;
import org.jboss.portal.theme.PageService;
-import org.jboss.portal.theme.ThemeConstants;
import org.jboss.portal.theme.render.RendererContext;
import org.jboss.portal.theme.render.ThemeContext;
import org.jboss.portal.theme.page.PageResult;
-import org.jboss.portal.theme.page.WindowResult;
import org.jboss.portal.theme.page.WindowContext;
import org.jboss.portal.theme.page.Region;
import org.apache.log4j.Logger;
@@ -79,6 +76,7 @@
/**
* todo:
+ *
* 1/ interpret more responses types
*
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
@@ -150,29 +148,24 @@
ControllerCommand commeand,
ControllerResponse controllerResponse) throws ResponseHandlerException
{
- if (controllerResponse instanceof PortletWindowResponse)
+ if (controllerResponse instanceof PortletWindowActionResponse)
{
- PortletWindowResponse pwr = (PortletWindowResponse)controllerResponse;
- PortletInvocationResponse pir = pwr.getResult();
- if (pir instanceof RenderResponse)
+ PortletWindowActionResponse pwr =
(PortletWindowActionResponse)controllerResponse;
+ StateString contentState = pwr.getContentState();
+ WindowState windowState = pwr.getWindowState();
+ Mode mode = pwr.getMode();
+ ControllerCommand renderCmd = new InvokePortletWindowRenderCommand(
+ pwr.getWindowId(),
+ mode,
+ windowState,
+ contentState);
+ if (renderCmd != null)
{
- RenderResponse rr = (RenderResponse)pir;
- StateString navState = rr.getNavigationalState();
- WindowState windowState = rr.getWindowState();
- Mode mode = rr.getMode();
- ControllerCommand renderCmd =
PortletResponseHandler.createRenderCommand(mode, windowState, navState, pwr);
- if (renderCmd != null)
- {
- return new CommandForward(renderCmd, null);
- }
- else
- {
- return null;
- }
+ return new CommandForward(renderCmd, null);
}
else
{
- throw new Error("todo " + controllerResponse);
+ return null;
}
}
else if (controllerResponse instanceof UpdatePageResponse)
@@ -285,62 +278,81 @@
ServerInvocation invocation = controllerContext.getServerInvocation();
//
- for (Iterator i = windowToRefresh.iterator();i.hasNext();)
+ WindowContextFactory wcf = new WindowContextFactory(controllerContext);
+
+ //
+ for (Iterator i = windowToRefresh.iterator();i.hasNext() &&
!fullRefresh;)
{
- final PortalObject _window = (PortalObject)i.next();
- RenderWindowCommand rwc = new RenderWindowCommand(_window.getId());
try
{
- ControllerResponse wresp = controllerContext.execute(rwc);
- if (wresp instanceof WindowRendition)
+ PortalObject _window = (PortalObject)i.next();
+ RenderWindowCommand rwc = new RenderWindowCommand(_window.getId());
+ WindowRendition rendition = rwc.render(controllerContext);
+
+ //
+ if (rendition != null)
{
- WindowRendition rendition = (WindowRendition)wresp;
- final WindowResult windowResult = rendition.getWindow();
+ ControllerResponse resp = rendition.getControllerResponse();
//
- WindowContext wc = new WindowContext(
- _window.getId().toString(PortalObjectPath.LEGACY_BASE64_FORMAT),
- _window.getProperty(ThemeConstants.PORTAL_PROP_REGION),
- "0",
- windowResult);
+ if (resp instanceof MarkupResponse)
+ {
+ WindowContext wc = wcf.createWindowContext(window, rendition);
- //
- res.addWindowContext(wc);
+// WindowContext wc = new WindowContext(
+//
_window.getId().toString(PortalObjectPath.LEGACY_BASE64_FORMAT),
+// _window.getProperty(ThemeConstants.PORTAL_PROP_REGION),
+// "0",
+// windowResult);
- //
- MarkupInfo markupInfo =
(MarkupInfo)invocation.getResponse().getContentInfo();
+ //
+ res.addWindowContext(wc);
- // The buffer
- StringWriter buffer = new StringWriter();
+ //
+ MarkupInfo markupInfo =
(MarkupInfo)invocation.getResponse().getContentInfo();
- // Get a dispatcher
- ServletContextDispatcher dispatcher = new
ServletContextDispatcher(invocation.getServerContext().getClientRequest(),
invocation.getServerContext().getClientResponse(),
controllerContext.getController().getServletContainerContext());
+ // The buffer
+ StringWriter buffer = new StringWriter();
- // Not really used for now in that context, so we can pass null
(need to change that of course)
- ThemeContext themeContext = new ThemeContext(null, null);
+ // Get a dispatcher
+ ServletContextDispatcher dispatcher = new
ServletContextDispatcher(invocation.getServerContext().getClientRequest(),
invocation.getServerContext().getClientResponse(),
controllerContext.getController().getServletContainerContext());
- // get render context
- RendererContext rendererContext =
layout.getRenderContext(themeContext, markupInfo, dispatcher, buffer);
+ // Not really used for now in that context, so we can pass null
(need to change that of course)
+ ThemeContext themeContext = new ThemeContext(null, null);
- // Push page
- rendererContext.pushObjectRenderContext(res);
+ // get render context
+ RendererContext rendererContext =
layout.getRenderContext(themeContext, markupInfo, dispatcher, buffer);
- // Push region
- Region region = res.getRegion2(wc.getRegionName());
- rendererContext.pushObjectRenderContext(region);
+ // Push page
+ rendererContext.pushObjectRenderContext(res);
- // Render
- rendererContext.render(wc);
+ // Push region
+ Region region = res.getRegion2(wc.getRegionName());
+ rendererContext.pushObjectRenderContext(region);
- // Pop region
- rendererContext.popObjectRenderContext();
+ // Render
+ rendererContext.render(wc);
- // Pop page
- rendererContext.popObjectRenderContext();
+ // Pop region
+ rendererContext.popObjectRenderContext();
- // Add render to the page
- updatePage.addFragment(wc.getId(), buffer.toString());
+ // Pop page
+ rendererContext.popObjectRenderContext();
+
+ // Add render to the page
+ updatePage.addFragment(wc.getId(), buffer.toString());
+ }
+ else
+ {
+ fullRefresh = true;
+ }
}
+ else
+ {
+ // We'd better do a full refresh for now
+ // It could be handled as a portlet removal in the protocol between
the client side and server side
+ fullRefresh = true;
+ }
}
catch (Exception e)
{
Modified:
trunk/core/src/main/org/jboss/portal/core/controller/classic/ClassicResponseHandler.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/core/controller/classic/ClassicResponseHandler.java 2007-06-08
13:50:21 UTC (rev 7394)
+++
trunk/core/src/main/org/jboss/portal/core/controller/classic/ClassicResponseHandler.java 2007-06-11
11:31:36 UTC (rev 7395)
@@ -22,37 +22,22 @@
******************************************************************************/
package org.jboss.portal.core.controller.classic;
-import org.jboss.portal.server.ServerInvocation;
-import org.jboss.portal.server.ServerInvocationContext;
import org.jboss.portal.server.request.URLContext;
-import org.jboss.portal.core.theme.PageRendition;
-import org.jboss.portal.core.controller.command.response.SignOutResponse;
-import org.jboss.portal.core.controller.command.response.StreamContentResponse;
import org.jboss.portal.core.controller.command.info.CommandInfo;
import org.jboss.portal.core.controller.command.info.ActionCommandInfo;
import org.jboss.portal.core.controller.ControllerCommand;
import org.jboss.portal.core.controller.ControllerContext;
import org.jboss.portal.core.controller.handler.ResponseHandlerException;
import org.jboss.portal.core.controller.ControllerResponse;
+import org.jboss.portal.core.controller.portlet.PortletResponseHandler;
import org.jboss.portal.core.controller.handler.AbstractResponseHandler;
import org.jboss.portal.core.controller.handler.HTTPResponse;
import org.jboss.portal.core.controller.handler.HandlerResponse;
import org.jboss.portal.core.controller.handler.ResponseHandler;
import org.jboss.portal.core.controller.handler.CommandForward;
-import org.jboss.portal.core.controller.portlet.PortletResponseHandler;
-import org.jboss.portal.core.model.portal.Portal;
-import org.jboss.portal.core.model.portal.PortalObjectContainer;
-import org.jboss.portal.core.model.portal.PortalObjectId;
import org.jboss.portal.core.model.portal.PortalObjectResponseHandler;
-import org.jboss.portal.core.model.portal.PortalObjectPath;
-import org.jboss.portal.core.model.portal.command.view.ViewPageCommand;
import org.jboss.portal.core.model.instance.PortletInstanceResponseHandler;
-import org.jboss.portal.web.ServletContextDispatcher;
-import org.jboss.portal.common.util.MarkupInfo;
-import javax.servlet.ServletException;
-import java.io.IOException;
-
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision: 1.1 $
@@ -60,15 +45,11 @@
public class ClassicResponseHandler extends AbstractResponseHandler
{
- /** . */
- private static final PortalObjectId DEFAULT_PORTAL_PATH =
PortalObjectId.parse("/default", PortalObjectPath.CANONICAL_FORMAT);
-
public HandlerResponse processCommandResponse(
ControllerContext controllerContext,
ControllerCommand controllerCommand,
ControllerResponse commandResponse) throws ResponseHandlerException
{
-
HandlerResponse handlerResponse = processHandlers(controllerContext,
controllerCommand, commandResponse);
// Handle redirection here
@@ -79,7 +60,7 @@
if (requiresRedirect(controllerCommand, urlContext, forward))
{
String url = controllerContext.renderURL(forward.getCommand(),
forward.getURLContext(), null);
- return new HTTPResponse.SendRedirect(url);
+ return HTTPResponse.sendRedirect(url);
}
}
@@ -106,67 +87,13 @@
return null;
}
- private static class OtherResponseHandler implements ResponseHandler
- {
- public HandlerResponse processCommandResponse(ControllerContext controllerContext,
ControllerCommand cdmand, ControllerResponse controllerResponse) throws
ResponseHandlerException
- {
- final ServerInvocation invocation = controllerContext.getServerInvocation();
- if (controllerResponse instanceof PageRendition)
- {
- final PageRendition rendition = (PageRendition)controllerResponse;
-
- // Defer execution of rendition to the right place which is in the classic
controller send response
- return new HTTPResponse()
- {
- public void sendResponse(ServerInvocationContext ctx) throws IOException,
ServletException
- {
- ServletContextDispatcher dispatcher = new
ServletContextDispatcher(invocation.getServerContext().getClientRequest(),
invocation.getServerContext().getClientResponse(),
invocation.getRequest().getServer().getServletContainerContext());
- MarkupInfo markupInfo =
(MarkupInfo)invocation.getResponse().getContentInfo();
- rendition.render(markupInfo, dispatcher);
- }
- };
- }
- else if (controllerResponse instanceof SignOutResponse)
- {
- // Get the optional signout location
- String location = ((SignOutResponse)controllerResponse).getLocation();
-
- // Indicate that we want a sign out to be done
- invocation.getResponse().setWantSignOut(true);
-
- //
- if (location == null)
- {
- PortalObjectContainer portalObjectContainer =
controllerContext.getController().getPortalObjectContainer();
- Portal portal =
(Portal)portalObjectContainer.getObject(DEFAULT_PORTAL_PATH);
- ViewPageCommand renderCmd = new ViewPageCommand(portal.getId());
- URLContext urlContext = invocation.getServerContext().getURLContext();
- location = controllerContext.renderURL(renderCmd,
urlContext.asNonAuthenticated(), null);
- }
-
- //
- return new HTTPResponse.SendRedirect(location);
- }
- else if (controllerResponse instanceof StreamContentResponse)
- {
- StreamContentResponse scr = (StreamContentResponse)controllerResponse;
- return new HTTPResponse.SendBinary(scr.getContentType(),
scr.getInputStream());
- }
- else
- {
- return null;
- }
- }
- }
-
// Unhardcode this
private ResponseHandler[] handlers = new ResponseHandler[]
{
- new ThrowableResponseHandler(),
- new OtherResponseHandler(),
new PortletInstanceResponseHandler(),
new PortalObjectResponseHandler(),
- new PortletResponseHandler()
+ new PortletResponseHandler(),
+ new OtherResponseHandler()
};
/**
Added:
trunk/core/src/main/org/jboss/portal/core/controller/classic/OtherResponseHandler.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/core/controller/classic/OtherResponseHandler.java
(rev 0)
+++
trunk/core/src/main/org/jboss/portal/core/controller/classic/OtherResponseHandler.java 2007-06-11
11:31:36 UTC (rev 7395)
@@ -0,0 +1,166 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.core.controller.classic;
+
+import org.jboss.portal.core.controller.handler.ResponseHandler;
+import org.jboss.portal.core.controller.handler.HandlerResponse;
+import org.jboss.portal.core.controller.handler.ResponseHandlerException;
+import org.jboss.portal.core.controller.handler.HTTPResponse;
+import org.jboss.portal.core.controller.ControllerContext;
+import org.jboss.portal.core.controller.ControllerCommand;
+import org.jboss.portal.core.controller.ControllerResponse;
+import org.jboss.portal.core.controller.command.response.SignOutResponse;
+import org.jboss.portal.core.controller.command.response.StreamContentResponse;
+import org.jboss.portal.core.controller.command.response.ErrorResponse;
+import org.jboss.portal.core.controller.command.response.UnavailableResourceResponse;
+import org.jboss.portal.core.controller.command.response.SecurityErrorResponse;
+import org.jboss.portal.core.theme.PageRendition;
+import org.jboss.portal.core.model.portal.PortalObjectContainer;
+import org.jboss.portal.core.model.portal.Portal;
+import org.jboss.portal.core.model.portal.PortalObjectId;
+import org.jboss.portal.core.model.portal.PortalObjectPath;
+import org.jboss.portal.core.model.portal.command.view.ViewPageCommand;
+import org.jboss.portal.server.ServerInvocation;
+import org.jboss.portal.server.ServerInvocationContext;
+import org.jboss.portal.server.ServerURL;
+import org.jboss.portal.server.request.URLContext;
+import org.jboss.portal.web.ServletContextDispatcher;
+import org.jboss.portal.common.util.MarkupInfo;
+import org.apache.log4j.Logger;
+
+import javax.servlet.ServletException;
+import java.io.IOException;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class OtherResponseHandler implements ResponseHandler
+{
+
+ /** . */
+ private static final PortalObjectId DEFAULT_PORTAL_PATH =
PortalObjectId.parse("/default", PortalObjectPath.CANONICAL_FORMAT);
+
+ /** . */
+ private static final Logger log = Logger.getLogger(OtherResponseHandler.class);
+
+ public HandlerResponse processCommandResponse(ControllerContext controllerContext,
ControllerCommand controllerCommand, ControllerResponse controllerResponse) throws
ResponseHandlerException
+ {
+ final ServerInvocation invocation = controllerContext.getServerInvocation();
+
+ //
+ if (controllerResponse instanceof PageRendition)
+ {
+ final PageRendition rendition = (PageRendition)controllerResponse;
+
+ // Defer execution of rendition to the right place which is in the classic
controller send response
+ return new HTTPResponse()
+ {
+ public void sendResponse(ServerInvocationContext ctx) throws IOException,
ServletException
+ {
+ ServletContextDispatcher dispatcher = new
ServletContextDispatcher(invocation.getServerContext().getClientRequest(),
invocation.getServerContext().getClientResponse(),
invocation.getRequest().getServer().getServletContainerContext());
+ MarkupInfo markupInfo =
(MarkupInfo)invocation.getResponse().getContentInfo();
+ rendition.render(markupInfo, dispatcher);
+ }
+ };
+ }
+ else if (controllerResponse instanceof SignOutResponse)
+ {
+ // Get the optional signout location
+ String location = ((SignOutResponse)controllerResponse).getLocation();
+
+ // Indicate that we want a sign out to be done
+ invocation.getResponse().setWantSignOut(true);
+
+ //
+ if (location == null)
+ {
+ PortalObjectContainer portalObjectContainer =
controllerContext.getController().getPortalObjectContainer();
+ Portal portal =
(Portal)portalObjectContainer.getObject(DEFAULT_PORTAL_PATH);
+ ViewPageCommand renderCmd = new ViewPageCommand(portal.getId());
+ URLContext urlContext = invocation.getServerContext().getURLContext();
+ location = controllerContext.renderURL(renderCmd,
urlContext.asNonAuthenticated(), null);
+ }
+
+ //
+ return HTTPResponse.sendRedirect(location);
+ }
+ else if (controllerResponse instanceof StreamContentResponse)
+ {
+ StreamContentResponse scr = (StreamContentResponse)controllerResponse;
+ return HTTPResponse.sendBinary(scr.getContentType(), scr.getInputStream());
+ }
+ else if (controllerResponse instanceof SecurityErrorResponse)
+ {
+ SecurityErrorResponse ser = (SecurityErrorResponse)controllerResponse;
+ URLContext urlContext =
controllerContext.getServerInvocation().getServerContext().getURLContext();
+ if (ser.getStatus() == SecurityErrorResponse.NOT_AUTHORIZED)
+ {
+ if (controllerContext.getUser() != null)
+ {
+ return HTTPResponse.sendForbidden();
+ }
+ else
+ {
+ urlContext = URLContext.newInstance(urlContext.isSecure(), true);
+ ServerURL serverURL =
controllerContext.getController().getURLFactory().doMapping(controllerContext,
controllerContext.getServerInvocation(), controllerCommand);
+ String url =
controllerContext.getServerInvocation().getResponse().renderURL(serverURL, urlContext,
null);
+ return HTTPResponse.sendRedirect(url);
+ }
+ }
+ else
+ {
+ urlContext = URLContext.newInstance(true, urlContext.isAuthenticated());
+ ServerURL serverURL =
controllerContext.getController().getURLFactory().doMapping(controllerContext,
controllerContext.getServerInvocation(), controllerCommand);
+ String url =
controllerContext.getServerInvocation().getResponse().renderURL(serverURL, urlContext,
null);
+ return HTTPResponse.sendRedirect(url);
+ }
+ }
+ else if (controllerResponse instanceof ErrorResponse)
+ {
+ ErrorResponse errorResponse = (ErrorResponse)controllerResponse;
+
+ //
+ Throwable cause = errorResponse.getCause();
+
+ //
+ if (cause != null)
+ {
+ log.error("An error occured", cause);
+ }
+
+ return HTTPResponse.sendError();
+ }
+ else if (controllerResponse instanceof UnavailableResourceResponse)
+ {
+ UnavailableResourceResponse unavailable =
(UnavailableResourceResponse)controllerResponse;
+
+ //
+ return HTTPResponse.sendNotFound();
+ }
+ else
+ {
+ return null;
+ }
+ }
+}
Deleted:
trunk/core/src/main/org/jboss/portal/core/controller/classic/ThrowableResponseHandler.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/core/controller/classic/ThrowableResponseHandler.java 2007-06-08
13:50:21 UTC (rev 7394)
+++
trunk/core/src/main/org/jboss/portal/core/controller/classic/ThrowableResponseHandler.java 2007-06-11
11:31:36 UTC (rev 7395)
@@ -1,94 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, and individual *
- * contributors as indicated by the @authors tag. See the *
- * copyright.txt in the distribution for a full listing of *
- * individual contributors. *
- * *
- * This is free software; you can redistribute it and/or modify it *
- * under the terms of the GNU Lesser General Public License as *
- * published by the Free Software Foundation; either version 2.1 of *
- * the License, or (at your option) any later version. *
- * *
- * This software is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this software; if not, write to the Free *
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
- ******************************************************************************/
-package org.jboss.portal.core.controller.classic;
-
-import org.jboss.portal.core.controller.handler.ResponseHandler;
-import org.jboss.portal.core.controller.handler.HandlerResponse;
-import org.jboss.portal.core.controller.handler.HTTPResponse;
-import org.jboss.portal.core.controller.handler.ResponseHandlerException;
-import org.jboss.portal.core.controller.ControllerContext;
-import org.jboss.portal.core.controller.ControllerCommand;
-import org.jboss.portal.core.controller.ControllerSecurityException;
-import org.jboss.portal.core.controller.ResourceNotFoundException;
-import org.jboss.portal.core.controller.ControllerException;
-import org.jboss.portal.core.controller.ControllerResponse;
-import org.jboss.portal.core.controller.command.response.ThrowableResponse;
-import org.jboss.portal.server.ServerURL;
-import org.jboss.portal.server.request.URLContext;
-
-import javax.servlet.http.HttpServletResponse;
-
-/**
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision: 1.1 $
- */
-public class ThrowableResponseHandler implements ResponseHandler
-{
- public HandlerResponse processCommandResponse(ControllerContext controllerContext,
ControllerCommand controllerCommand, ControllerResponse controllerResponse) throws
ResponseHandlerException
- {
- if (controllerResponse instanceof ThrowableResponse)
- {
- ThrowableResponse tr = (ThrowableResponse)controllerResponse;
- Throwable t = tr.getThrowable();
- URLContext urlContext =
controllerContext.getServerInvocation().getServerContext().getURLContext();
-
- //
- if (t instanceof ControllerSecurityException)
- {
- if (urlContext.isAuthenticated())
- {
- return new
HTTPResponse.SetStatusCode(HttpServletResponse.SC_UNAUTHORIZED);
- }
- else
- {
- urlContext = URLContext.newInstance(urlContext.isSecure(), true);
- ServerURL serverURL =
controllerContext.getController().getURLFactory().doMapping(controllerContext,
controllerContext.getServerInvocation(), controllerCommand);
- String url =
controllerContext.getServerInvocation().getResponse().renderURL(serverURL, urlContext,
null);
- return new HTTPResponse.SendRedirect(url);
- }
- }
- else if (t instanceof ResourceNotFoundException)
- {
- ResourceNotFoundException rnfe = (ResourceNotFoundException)t;
- // log.error("Resource not found " + e.getRef(), e);
- return new HTTPResponse.SetStatusCode(HttpServletResponse.SC_NOT_FOUND);
- }
- else if (t instanceof ControllerException)
- {
- ControllerException ce = (ControllerException)t;
- throw new ResponseHandlerException(ce);
- }
- else if (t instanceof Exception)
- {
- Exception e = (Exception)t;
- throw new ResponseHandlerException(e);
- }
- else
- {
- // todo
- t.printStackTrace();
- }
- }
- return null;
- }
-}
Added:
trunk/core/src/main/org/jboss/portal/core/controller/command/response/ErrorResponse.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/core/controller/command/response/ErrorResponse.java
(rev 0)
+++
trunk/core/src/main/org/jboss/portal/core/controller/command/response/ErrorResponse.java 2007-06-11
11:31:36 UTC (rev 7395)
@@ -0,0 +1,98 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.core.controller.command.response;
+
+import org.jboss.portal.core.controller.ControllerResponse;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class ErrorResponse extends ControllerResponse
+{
+
+ /** The optional cause of the error. */
+ private final Throwable cause;
+
+ /** The optional error message. */
+ private final String message;
+
+ /** True if the error is considered as an internal error. */
+ private final boolean internal;
+
+ public ErrorResponse(Throwable cause, boolean internal)
+ {
+ this.cause = cause;
+ this.message = cause != null ? cause.getMessage() : null;
+ this.internal = internal;
+ }
+
+ public ErrorResponse(String message, boolean internal)
+ {
+ this.cause = null;
+ this.message = message;
+ this.internal = internal;
+ }
+
+ public ErrorResponse(boolean internal)
+ {
+ this.cause = null;
+ this.message = null;
+ this.internal = internal;
+ }
+
+ /**
+ * Returns the optional error.
+ *
+ * @return the error
+ */
+ public Throwable getCause()
+ {
+ return cause;
+ }
+
+ /**
+ * Returns the optional error message.
+ *
+ * @return the message
+ */
+ public String getMessage()
+ {
+ return message;
+ }
+
+ /**
+ * Returns true if the error is considered as internal.
+ *
+ * @return true if the error is internal
+ */
+ public boolean isInternal()
+ {
+ return internal;
+ }
+
+ public String toString()
+ {
+ return "ErrorResponse[internal=" + internal + "]";
+ }
+}
Added:
trunk/core/src/main/org/jboss/portal/core/controller/command/response/RedirectionResponse.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/core/controller/command/response/RedirectionResponse.java
(rev 0)
+++
trunk/core/src/main/org/jboss/portal/core/controller/command/response/RedirectionResponse.java 2007-06-11
11:31:36 UTC (rev 7395)
@@ -0,0 +1,46 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.core.controller.command.response;
+
+import org.jboss.portal.core.controller.ControllerResponse;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class RedirectionResponse extends ControllerResponse
+{
+
+ /** . */
+ private String location;
+
+ public RedirectionResponse(String location)
+ {
+ this.location = location;
+ }
+
+ public String getLocation()
+ {
+ return location;
+ }
+}
Added:
trunk/core/src/main/org/jboss/portal/core/controller/command/response/SecurityErrorResponse.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/core/controller/command/response/SecurityErrorResponse.java
(rev 0)
+++
trunk/core/src/main/org/jboss/portal/core/controller/command/response/SecurityErrorResponse.java 2007-06-11
11:31:36 UTC (rev 7395)
@@ -0,0 +1,74 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.core.controller.command.response;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class SecurityErrorResponse extends ErrorResponse
+{
+
+ /** . */
+ public static final int NOT_AUTHORIZED = 0;
+
+ /** . */
+ public static final int NOT_SECURE = 1;
+
+ /** . */
+ private int status;
+
+ public SecurityErrorResponse(int status, boolean internal)
+ {
+ super(internal);
+
+ //
+ this.status = status;
+ }
+
+ public SecurityErrorResponse(Throwable cause, int status, boolean internal)
+ {
+ super(cause, internal);
+
+ //
+ this.status = status;
+ }
+
+ public SecurityErrorResponse(String message, int status, boolean internal)
+ {
+ super(message, internal);
+
+ //
+ this.status = status;
+ }
+
+ public int getStatus()
+ {
+ return status;
+ }
+
+ public String toString()
+ {
+ return "SecurityErrorResponse[status=" + status + "]";
+ }
+}
Added:
trunk/core/src/main/org/jboss/portal/core/controller/command/response/UnavailableResourceResponse.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/core/controller/command/response/UnavailableResourceResponse.java
(rev 0)
+++
trunk/core/src/main/org/jboss/portal/core/controller/command/response/UnavailableResourceResponse.java 2007-06-11
11:31:36 UTC (rev 7395)
@@ -0,0 +1,63 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.core.controller.command.response;
+
+import org.jboss.portal.core.controller.ControllerResponse;
+
+/**
+ * A resource is not available either because the resource cannot be located or because
it is located
+ * but it is not serviceable.
+ *
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class UnavailableResourceResponse extends ControllerResponse
+{
+
+ /** The resource reference. */
+ private final String ref;
+
+ /** Indicates if the resource was located. */
+ private final boolean located;
+
+ public UnavailableResourceResponse(String ref, boolean located)
+ {
+ this.ref = ref;
+ this.located = located;
+ }
+
+ public String getRef()
+ {
+ return ref;
+ }
+
+ public boolean isLocated()
+ {
+ return located;
+ }
+
+ public String toString()
+ {
+ return "UnavailableResult[ref=" + ref + ",located=" + located +
"]";
+ }
+}
Modified: trunk/core/src/main/org/jboss/portal/core/controller/handler/HTTPResponse.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/core/controller/handler/HTTPResponse.java 2007-06-08
13:50:21 UTC (rev 7394)
+++
trunk/core/src/main/org/jboss/portal/core/controller/handler/HTTPResponse.java 2007-06-11
11:31:36 UTC (rev 7395)
@@ -32,7 +32,7 @@
import java.io.InputStream;
/**
- * Response that sends a response to the http stream.
+ * Response that sends a response to the http layer.
*
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision: 1.1 $
@@ -42,78 +42,71 @@
public abstract void sendResponse(ServerInvocationContext ctx) throws IOException,
ServletException;
- public static class SetStatusCode extends HTTPResponse
+ public static HTTPResponse sendRedirect(final String redirect)
{
-
- /** . */
- private final int statusCode;
-
- public SetStatusCode(int statusCode)
+ return new HTTPResponse()
{
- this.statusCode = statusCode;
- }
+ public void sendResponse(ServerInvocationContext ctx) throws IOException
+ {
+ HttpServletResponse resp = ctx.getClientResponse();
+ resp.sendRedirect(redirect);
+ }
+ };
+ }
- public void sendResponse(ServerInvocationContext ctx) throws IOException
+ public static HTTPResponse sendBinary(final String contentType, final InputStream in)
+ {
+ return new HTTPResponse()
{
- HttpServletResponse resp = ctx.getClientResponse();
- resp.sendError(statusCode);
- }
+ public void sendResponse(ServerInvocationContext ctx) throws IOException
+ {
+ HttpServletResponse resp = ctx.getClientResponse();
+ resp.setContentType(contentType);
+ ServletOutputStream sout = null;
+ try
+ {
+ sout = resp.getOutputStream();
+ byte[] buf = new byte[2048];
+ int len;
+ while ((len = in.read(buf)) > 0)
+ {
+ sout.write(buf, 0, len);
+ }
+ sout.flush();
+ }
+ finally
+ {
+ IOTools.safeClose(in);
+ IOTools.safeClose(sout);
+ }
+ }
+ };
}
- public static class SendRedirect extends HTTPResponse
+ public static HTTPResponse sendForbidden()
{
+ return sendStatus(HttpServletResponse.SC_FORBIDDEN);
+ }
- /** . */
- private final String redirect;
-
- public SendRedirect(String redirect)
- {
- this.redirect = redirect;
- }
-
- public void sendResponse(ServerInvocationContext ctx) throws IOException
- {
- HttpServletResponse resp = ctx.getClientResponse();
- resp.sendRedirect(redirect);
- }
+ public static HTTPResponse sendNotFound()
+ {
+ return sendStatus(HttpServletResponse.SC_NOT_FOUND);
}
- public static class SendBinary extends HTTPResponse
+ public static HTTPResponse sendError()
{
+ return sendStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+ }
- /** . */
- private final String contentType;
-
- /** . */
- private final InputStream in;
-
- public SendBinary(String contentType, InputStream inputStream)
+ private static HTTPResponse sendStatus(final int statusCode)
+ {
+ return new HTTPResponse()
{
- this.contentType = contentType;
- this.in = inputStream;
- }
-
- public void sendResponse(ServerInvocationContext ctx) throws IOException
- {
- HttpServletResponse resp = ctx.getClientResponse();
- resp.setContentType(contentType);
- ServletOutputStream sout = null;
- try
+ public void sendResponse(ServerInvocationContext ctx) throws IOException
{
- sout = resp.getOutputStream();
- byte[] buf = new byte[2048];
- int len;
- while ((len = in.read(buf)) > 0)
- {
- sout.write(buf, 0, len);
- }
- sout.flush();
+ HttpServletResponse resp = ctx.getClientResponse();
+ resp.sendError(statusCode);
}
- finally
- {
- IOTools.safeClose(in);
- IOTools.safeClose(sout);
- }
- }
+ };
}
}
Modified:
trunk/core/src/main/org/jboss/portal/core/controller/handler/ResponseHandler.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/core/controller/handler/ResponseHandler.java 2007-06-08
13:50:21 UTC (rev 7394)
+++
trunk/core/src/main/org/jboss/portal/core/controller/handler/ResponseHandler.java 2007-06-11
11:31:36 UTC (rev 7395)
@@ -29,7 +29,7 @@
/**
* The response handler interface defines the contract for translating the result of the
execution
- * of a command into a new type of result.
+ * of a command into a response adapated to the client side caller.
*
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision: 1.1 $
Added:
trunk/core/src/main/org/jboss/portal/core/controller/portlet/ControllerResponseFactory.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/core/controller/portlet/ControllerResponseFactory.java
(rev 0)
+++
trunk/core/src/main/org/jboss/portal/core/controller/portlet/ControllerResponseFactory.java 2007-06-11
11:31:36 UTC (rev 7395)
@@ -0,0 +1,117 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.core.controller.portlet;
+
+import org.jboss.portal.core.controller.ControllerResponse;
+import org.jboss.portal.core.controller.command.response.RedirectionResponse;
+import org.jboss.portal.core.controller.command.response.SecurityErrorResponse;
+import org.jboss.portal.core.controller.command.response.UnavailableResourceResponse;
+import org.jboss.portal.core.model.portal.PortalObjectId;
+import org.jboss.portal.core.model.portal.command.response.PortletWindowActionResponse;
+import
org.jboss.portal.core.model.instance.command.response.PortletInstanceActionResponse;
+import org.jboss.portal.portlet.invocation.response.PortletInvocationResponse;
+import org.jboss.portal.portlet.invocation.response.HTTPRedirectionResponse;
+import
org.jboss.portal.portlet.invocation.response.InsufficientTransportGuaranteeResponse;
+import org.jboss.portal.portlet.invocation.response.InsufficientPrivilegesResponse;
+import org.jboss.portal.portlet.invocation.response.ErrorResponse;
+import org.jboss.portal.portlet.invocation.response.RenderResponse;
+import org.jboss.portal.portlet.PortletInvokerException;
+import org.jboss.portal.portlet.NoSuchPortletException;
+import org.jboss.portal.common.FixMe;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class ControllerResponseFactory
+{
+
+ public static ControllerResponse createResponse(PortletInvokerException e)
+ {
+ if (e instanceof NoSuchPortletException)
+ {
+ return new
UnavailableResourceResponse(((NoSuchPortletException)e).getPortletId(), false);
+ }
+ else
+ {
+ return new org.jboss.portal.core.controller.command.response.ErrorResponse(e,
false);
+ }
+ }
+
+ public static ControllerResponse createActionResponse(PortalObjectId targetId,
PortletInvocationResponse response)
+ {
+ if (response instanceof RenderResponse)
+ {
+ RenderResponse renderResult = (RenderResponse)response;
+ return new PortletWindowActionResponse(targetId, renderResult.getWindowState(),
renderResult.getMode(), renderResult.getNavigationalState());
+ }
+ else
+ {
+ return createResponse(response);
+ }
+ }
+
+ public static ControllerResponse createActionResponse(String instanceId,
PortletInvocationResponse response)
+ {
+ if (response instanceof RenderResponse)
+ {
+ RenderResponse renderResult = (RenderResponse)response;
+ return new PortletInstanceActionResponse(instanceId,
renderResult.getWindowState(), renderResult.getMode(),
renderResult.getNavigationalState());
+ }
+ else
+ {
+ return createResponse(response);
+ }
+ }
+
+ private static ControllerResponse createResponse(PortletInvocationResponse response)
+ {
+ if (response instanceof HTTPRedirectionResponse)
+ {
+ HTTPRedirectionResponse redirection = (HTTPRedirectionResponse)response;
+ String location = redirection.getLocation();
+ return new RedirectionResponse(location);
+ }
+ else if (response instanceof InsufficientTransportGuaranteeResponse)
+ {
+ return new SecurityErrorResponse(SecurityErrorResponse.NOT_SECURE, false);
+ }
+ else if (response instanceof InsufficientPrivilegesResponse)
+ {
+ return new SecurityErrorResponse(SecurityErrorResponse.NOT_AUTHORIZED, false);
+ }
+ else if (response instanceof SignOutResponse)
+ {
+ return new org.jboss.portal.core.controller.command.response.SignOutResponse();
+ }
+ else if (response instanceof ErrorResponse)
+ {
+ return new
org.jboss.portal.core.controller.command.response.ErrorResponse(((ErrorResponse)response).getCause(),
false);
+ }
+ else
+ {
+ throw new FixMe();
+ }
+ }
+
+}
Copied:
trunk/core/src/main/org/jboss/portal/core/controller/portlet/PortletActionResponse.java
(from rev 7371,
trunk/core/src/main/org/jboss/portal/core/controller/portlet/PortletResponse.java)
===================================================================
---
trunk/core/src/main/org/jboss/portal/core/controller/portlet/PortletActionResponse.java
(rev 0)
+++
trunk/core/src/main/org/jboss/portal/core/controller/portlet/PortletActionResponse.java 2007-06-11
11:31:36 UTC (rev 7395)
@@ -0,0 +1,70 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.core.controller.portlet;
+
+import org.jboss.portal.portlet.invocation.response.PortletInvocationResponse;
+import org.jboss.portal.portlet.StateString;
+import org.jboss.portal.core.controller.ControllerResponse;
+import org.jboss.portal.Mode;
+import org.jboss.portal.WindowState;
+
+/**
+ * Controller response provided by a portlet.
+ *
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public abstract class PortletActionResponse extends ControllerResponse
+{
+
+ /** . */
+ private final WindowState windowState;
+
+ /** . */
+ private final Mode mode;
+
+ /** . */
+ private final StateString contentState;
+
+ protected PortletActionResponse(WindowState windowState, Mode mode, StateString
contentState)
+ {
+ this.windowState = windowState;
+ this.mode = mode;
+ this.contentState = contentState;
+ }
+
+ public WindowState getWindowState()
+ {
+ return windowState;
+ }
+
+ public Mode getMode()
+ {
+ return mode;
+ }
+
+ public StateString getContentState()
+ {
+ return contentState;
+ }
+}
Deleted:
trunk/core/src/main/org/jboss/portal/core/controller/portlet/PortletResponse.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/core/controller/portlet/PortletResponse.java 2007-06-08
13:50:21 UTC (rev 7394)
+++
trunk/core/src/main/org/jboss/portal/core/controller/portlet/PortletResponse.java 2007-06-11
11:31:36 UTC (rev 7395)
@@ -1,53 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, and individual *
- * contributors as indicated by the @authors tag. See the *
- * copyright.txt in the distribution for a full listing of *
- * individual contributors. *
- * *
- * This is free software; you can redistribute it and/or modify it *
- * under the terms of the GNU Lesser General Public License as *
- * published by the Free Software Foundation; either version 2.1 of *
- * the License, or (at your option) any later version. *
- * *
- * This software is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this software; if not, write to the Free *
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
- ******************************************************************************/
-package org.jboss.portal.core.controller.portlet;
-
-import org.jboss.portal.portlet.invocation.response.PortletInvocationResponse;
-import org.jboss.portal.core.controller.ControllerResponse;
-
-/**
- * Controller response provided by a portlet.
- *
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision: 1.1 $
- */
-public abstract class PortletResponse extends ControllerResponse
-{
-
- /** . */
- private PortletInvocationResponse response;
-
- public PortletResponse(PortletInvocationResponse response)
- {
- if (response == null)
- {
- throw new IllegalArgumentException();
- }
- this.response = response;
- }
-
- public PortletInvocationResponse getResult()
- {
- return response;
- }
-}
Deleted:
trunk/core/src/main/org/jboss/portal/core/controller/portlet/PortletResponseHandler.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/core/controller/portlet/PortletResponseHandler.java 2007-06-08
13:50:21 UTC (rev 7394)
+++
trunk/core/src/main/org/jboss/portal/core/controller/portlet/PortletResponseHandler.java 2007-06-11
11:31:36 UTC (rev 7395)
@@ -1,169 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, and individual *
- * contributors as indicated by the @authors tag. See the *
- * copyright.txt in the distribution for a full listing of *
- * individual contributors. *
- * *
- * This is free software; you can redistribute it and/or modify it *
- * under the terms of the GNU Lesser General Public License as *
- * published by the Free Software Foundation; either version 2.1 of *
- * the License, or (at your option) any later version. *
- * *
- * This software is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this software; if not, write to the Free *
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
- ******************************************************************************/
-package org.jboss.portal.core.controller.portlet;
-
-import org.jboss.portal.core.controller.ControllerCommand;
-import org.jboss.portal.core.controller.ControllerContext;
-import org.jboss.portal.core.controller.ControllerResponse;
-import org.jboss.portal.core.controller.handler.ResponseHandlerException;
-import org.jboss.portal.core.controller.handler.HTTPResponse;
-import org.jboss.portal.core.controller.handler.CommandForward;
-import org.jboss.portal.core.controller.handler.AbstractResponseHandler;
-import org.jboss.portal.core.controller.handler.HandlerResponse;
-import
org.jboss.portal.core.model.portal.command.action.InvokePortletWindowActionCommand;
-import
org.jboss.portal.core.model.portal.command.action.InvokePortletWindowRenderCommand;
-import org.jboss.portal.core.model.portal.command.view.ViewPageCommand;
-import org.jboss.portal.core.model.portal.command.response.PortletWindowResponse;
-import org.jboss.portal.core.model.portal.Page;
-import org.jboss.portal.core.model.instance.command.response.PortletInstanceResponse;
-import
org.jboss.portal.core.model.instance.command.action.InvokePortletInstanceRenderCommand;
-import org.jboss.portal.server.ServerInvocation;
-import org.jboss.portal.server.request.URLContext;
-import org.jboss.portal.portlet.invocation.response.PortletInvocationResponse;
-import org.jboss.portal.portlet.invocation.response.RenderResponse;
-import org.jboss.portal.portlet.invocation.response.HTTPRedirectionResponse;
-import
org.jboss.portal.portlet.invocation.response.InsufficientTransportGuaranteeResponse;
-import org.jboss.portal.portlet.invocation.response.InsufficientPrivilegesResponse;
-import org.jboss.portal.portlet.invocation.response.ErrorResponse;
-import org.jboss.portal.portlet.StateString;
-import org.jboss.portal.WindowState;
-import org.jboss.portal.Mode;
-
-import javax.servlet.http.HttpServletResponse;
-
-/**
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision: 1.1 $
- */
-public class PortletResponseHandler extends AbstractResponseHandler
-{
-
- public static ControllerCommand createRenderCommand(
- Mode mode,
- WindowState windowState,
- StateString navState,
- PortletResponse response)
- {
- if (response instanceof PortletInstanceResponse)
- {
- PortletInstanceResponse ir = (PortletInstanceResponse)response;
- return new InvokePortletInstanceRenderCommand(ir.getInstanceId(), navState);
- }
- else if (response instanceof PortletWindowResponse)
- {
- PortletWindowResponse pwr = (PortletWindowResponse)response;
- return new InvokePortletWindowRenderCommand(
- pwr.getWindowId(),
- mode,
- windowState,
- navState);
- }
- else
- {
- return null;
- }
- }
-
- public HandlerResponse processCommandResponse(ControllerContext controllerContext,
ControllerCommand controllerCommand, ControllerResponse controllerResponse) throws
ResponseHandlerException
- {
- if (controllerResponse instanceof PortletResponse)
- {
- ServerInvocation invocation = controllerContext.getServerInvocation();
- PortletResponse pr = (PortletResponse)controllerResponse;
- PortletInvocationResponse pir = pr.getResult();
-
- //
- if (pir instanceof RenderResponse)
- {
- RenderResponse renderResult = (RenderResponse)pir;
- StateString navState = renderResult.getNavigationalState();
- WindowState windowState = renderResult.getWindowState();
- Mode mode = renderResult.getMode();
- ControllerCommand renderCmd = createRenderCommand(mode, windowState,
navState, pr);
- if (renderCmd != null)
- {
- return new CommandForward(renderCmd, null);
- }
- else
- {
- return null;
- }
- }
- else if (pir instanceof HTTPRedirectionResponse)
- {
- HTTPRedirectionResponse redirectionResult = (HTTPRedirectionResponse)pir;
- String url = redirectionResult.getLocation();
- return new HTTPResponse.SendRedirect(url);
- }
- else if (pir instanceof InsufficientTransportGuaranteeResponse)
- {
- boolean authenticated =
invocation.getServerContext().getURLContext().isAuthenticated();
- return new CommandForward(controllerCommand, URLContext.newInstance(true,
authenticated));
- }
- else if (pir instanceof InsufficientPrivilegesResponse)
- {
- boolean authenticated =
invocation.getServerContext().getURLContext().isAuthenticated();
- return new CommandForward(controllerCommand, URLContext.newInstance(true,
authenticated));
- }
- else if (pir instanceof SignOutResponse)
- {
- SignOutResponse signOut = (SignOutResponse)pir;
-
- // Indicate that we want a sign out to be done
- invocation.getResponse().setWantSignOut(true);
-
- // Get the optional signout location
- String location = signOut.getLocation();
-
- //
- if (location == null)
- {
- // Redirect to the same page
- InvokePortletWindowActionCommand iwac =
(InvokePortletWindowActionCommand)controllerCommand;
- Page page = iwac.getPage();
- ViewPageCommand renderCmd = new ViewPageCommand(page.getId());
- boolean secure =
invocation.getServerContext().getURLContext().isSecure();
- URLContext urlContext = URLContext.newInstance(secure, false);
- location = controllerContext.renderURL(renderCmd, urlContext, null);
- }
-
- //
- return new HTTPResponse.SendRedirect(location);
- }
- else if (pir instanceof ErrorResponse)
- {
- ErrorResponse error = (ErrorResponse)pir;
- error.logErrorTo(log, "An portlet exception occured in portlet");
- return new
HTTPResponse.SetStatusCode(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
- }
- else
- {
- throw new IllegalStateException();
- }
- }
- else
- {
- return null;
- }
- }
-}
Modified:
trunk/core/src/main/org/jboss/portal/core/impl/model/content/InternalContentProvider.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/core/impl/model/content/InternalContentProvider.java 2007-06-08
13:50:21 UTC (rev 7394)
+++
trunk/core/src/main/org/jboss/portal/core/impl/model/content/InternalContentProvider.java 2007-06-11
11:31:36 UTC (rev 7395)
@@ -25,13 +25,11 @@
import org.jboss.logging.Logger;
import org.jboss.portal.Mode;
import org.jboss.portal.WindowState;
-import org.jboss.portal.common.util.Exceptions;
import org.jboss.portal.core.aspects.portlet.AjaxInterceptor;
import org.jboss.portal.core.controller.ControllerContext;
-import org.jboss.portal.core.controller.ControllerException;
import org.jboss.portal.core.controller.ControllerResponse;
-import org.jboss.portal.core.controller.ResourceAccessDeniedException;
-import org.jboss.portal.core.controller.ResourceNotFoundException;
+import org.jboss.portal.core.controller.command.response.UnavailableResourceResponse;
+import org.jboss.portal.core.controller.command.response.SecurityErrorResponse;
import org.jboss.portal.core.controller.portlet.PortletInvocationFactory;
import org.jboss.portal.core.model.content.Content;
import org.jboss.portal.core.model.content.ContentType;
@@ -40,13 +38,12 @@
import org.jboss.portal.core.model.portal.Portal;
import org.jboss.portal.core.model.portal.PortalObjectId;
import org.jboss.portal.core.model.portal.Window;
-import
org.jboss.portal.core.model.portal.command.action.InvokePortletWindowRenderCommand;
+import org.jboss.portal.core.model.portal.content.WindowRendition;
+import org.jboss.portal.core.model.portal.command.response.MarkupResponse;
import org.jboss.portal.core.model.portal.command.render.RenderWindowCommand;
-import org.jboss.portal.core.model.portal.command.response.PortletWindowResponse;
import org.jboss.portal.core.model.portal.content.ContentRenderer;
import org.jboss.portal.core.model.portal.navstate.WindowNavigationalState;
import org.jboss.portal.core.navstate.NavigationalStateKey;
-import org.jboss.portal.core.theme.WindowRendition;
import org.jboss.portal.portlet.NoSuchPortletException;
import org.jboss.portal.portlet.PortletInvokerException;
import org.jboss.portal.portlet.info.CapabilitiesInfo;
@@ -59,20 +56,16 @@
import org.jboss.portal.portlet.invocation.response.InsufficientPrivilegesResponse;
import org.jboss.portal.portlet.invocation.response.PortletInvocationResponse;
import org.jboss.portal.portlet.invocation.response.UnavailableResponse;
-import org.jboss.portal.server.ServerInvocationContext;
-import org.jboss.portal.server.config.ServerConfig;
-import org.jboss.portal.server.request.URLContext;
-import org.jboss.portal.server.request.URLFormat;
+import
org.jboss.portal.portlet.invocation.response.InsufficientTransportGuaranteeResponse;
import org.jboss.portal.theme.impl.render.dynamic.DynaRenderOptions;
-import org.jboss.portal.theme.page.WindowResult;
-import org.jboss.portal.theme.render.renderer.ActionRendererContext;
import java.util.ArrayList;
-import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.Collections;
+import java.util.Set;
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
@@ -150,12 +143,11 @@
*/
protected abstract Instance getPortletInstance(RenderWindowCommand command);
- public ControllerResponse renderWindow(RenderWindowCommand cmd) throws Exception
+ public WindowRendition renderWindow(RenderWindowCommand cmd)
{
Window window = cmd.getWindow();
Portal portal = cmd.getPortal();
ControllerContext context = cmd.getControllerContext();
- ServerConfig cfg =
context.getServerInvocation().getRequest().getServer().getConfig();
PortalObjectId windowId = window.getId();
NavigationalStateKey nsKey = new
NavigationalStateKey(WindowNavigationalState.class, windowId);
@@ -169,274 +161,163 @@
}
//
- String windowTitle;
- String contentChars;
- String headerChars = null;
- Map actionMap = new HashMap();
Map windowProps = new HashMap(window.getProperties());
+ Mode mode = windowNS.getMode();
+ WindowState windowState = windowNS.getWindowState();
+ // Obtain instance
+ Instance instance = getPortletInstance(cmd);
+
+ // No instance means we can't continue
+ if (instance == null)
+ {
+ String ref = null;
+ Content content = window.getContent();
+ if (content != null)
+ {
+ ref = content.getURI();
+ }
+ if (ref == null)
+ {
+ ref = window.getId().toString();
+ }
+ UnavailableResourceResponse cr = new UnavailableResourceResponse(ref, false);
+ return new WindowRendition(windowProps, windowState, mode,
Collections.singletonList(windowState), Collections.singletonList(mode), cr);
+ }
+
+ // Create invocation
+ RenderInvocation invocation = PortletInvocationFactory.createRender(
+ context,
+ mode,
+ windowState,
+ windowNS.getContentState(),
+ window,
+ portal);
+
//
+ List supportedWindowStates = Collections.EMPTY_LIST;
+ List supportedModes = Collections.EMPTY_LIST;
+ PortletInvocationResponse response;
+
+ //
try
{
- // Obtain instance
- Instance instance = getPortletInstance(cmd);
+ CapabilitiesInfo capabilitiesInfo =
instance.getPortlet().getInfo().getCapabilities();
- // No instance means we can't continue
- if (instance == null)
+ //
+ Set windowStatesInfo = capabilitiesInfo.getAllWindowStates();
+ supportedWindowStates = new ArrayList(windowStatesInfo.size());
+ for (Iterator i = windowStatesInfo.iterator(); i.hasNext();)
{
- String ref = null;
- Content content = window.getContent();
- if (content != null)
+ WindowStateInfo windowStateInfo = (WindowStateInfo)i.next();
+ WindowState tmp = windowStateInfo.getWindowState();
+ if (portal.getSupportedWindowStates().contains(tmp))
{
- ref = content.getURI();
+ supportedWindowStates.add(tmp);
}
- if (ref == null)
- {
- ref = window.getId().toString();
- }
- throw new ResourceNotFoundException(ref);
}
- // Create invocation
- RenderInvocation invocation = PortletInvocationFactory.createRender(
- context,
- windowNS.getMode(),
- windowNS.getWindowState(),
- windowNS.getState(),
- window,
- portal);
-
//
- PortletInvocationResponse response;
- try
+ Set modesInfo = capabilitiesInfo.getAllModes();
+ supportedModes = new ArrayList(modesInfo.size());
+ for (Iterator i = modesInfo.iterator(); i.hasNext();)
{
- response = instance.invoke(invocation);
- }
- catch (PortletInvokerException e)
- {
- if (e instanceof NoSuchPortletException)
+ ModeInfo modeInfo = (ModeInfo)i.next();
+ Mode tmp = modeInfo.getMode();
+ if (portal.getSupportedModes().contains(tmp))
{
- throw new
ResourceNotFoundException(((NoSuchPortletException)e).getPortletId());
+ supportedModes.add(tmp);
}
- else
- {
- log.error("Portlet invoker exception during portlet window
rendering", e);
+ }
- //
- throw new ControllerException(e);
- }
+ // Remove edit mode if the user is not logged it
+ if
(context.getServerInvocation().getServerContext().getClientRequest().getUserPrincipal() ==
null)
+ {
+ supportedModes.remove(Mode.EDIT);
}
//
- if (response instanceof FragmentResponse)
- {
- FragmentResponse fragment = (FragmentResponse)response;
- windowTitle = fragment.getTitle();
- if (windowTitle == null)
- {
- windowTitle = window.getName();
- }
- headerChars = fragment.getHeader();
+ response = instance.invoke(invocation);
+ }
+ catch (PortletInvokerException e)
+ {
+ ControllerResponse cr;
- //
- List supportedWindowStates = new ArrayList();
- CapabilitiesInfo capabilitiesInfo =
instance.getPortlet().getInfo().getCapabilities();
- for (Iterator i = capabilitiesInfo.getAllWindowStates().iterator();
i.hasNext();)
- {
- WindowStateInfo windowStateInfo = (WindowStateInfo)i.next();
- WindowState tmp = windowStateInfo.getWindowState();
- if (portal.getSupportedWindowStates().contains(tmp))
- {
- supportedWindowStates.add(tmp);
- }
- }
-
- //
- List supportedModes = new ArrayList();
- for (Iterator i = capabilitiesInfo.getAllModes().iterator(); i.hasNext();)
- {
- ModeInfo modeInfo = (ModeInfo)i.next();
- Mode tmp = modeInfo.getMode();
- if (portal.getSupportedModes().contains(tmp))
- {
- supportedModes.add(tmp);
- }
- }
-
- // Remove edit mode if the user is not logged it
- if
(context.getServerInvocation().getServerContext().getClientRequest().getUserPrincipal() ==
null)
- {
- supportedModes.remove(Mode.EDIT);
- }
-
- //
- addModeActions(context, window, actionMap, windowNS.getMode(),
supportedModes);
-
- //
- addStateActions(context, window, actionMap, windowNS.getWindowState(),
supportedWindowStates);
-
- // Handle minimized here
- if (WindowState.MINIMIZED == windowNS.getWindowState())
- {
- contentChars = "";
- }
- else
- {
- contentChars = fragment.getContent();
- }
-
- // Update window props after render if needed
- Boolean partialRefresh =
(Boolean)invocation.getAttribute(PortletInvocation.RESPONSE_PROPERTIES_SCOPE,
AjaxInterceptor.PARTIAL_REFRESH);
- if (partialRefresh != null && Boolean.FALSE.equals(partialRefresh))
- {
- DynaRenderOptions options = DynaRenderOptions.getOptions(null,
partialRefresh);
- options.setOptions(windowProps);
- }
-
- //
- return new WindowRendition(new WindowResult(
- windowTitle,
- contentChars,
- actionMap,
- windowProps,
- headerChars,
- windowNS.getWindowState(),
- windowNS.getMode()));
- }
- else if (response instanceof ErrorResponse)
+ //
+ if (e instanceof NoSuchPortletException)
{
- ErrorResponse errorResult = (ErrorResponse)response;
- String logMessage = "Rendering portlet window " + windowId + "
triggered the following error :";
- errorResult.logErrorTo(log, logMessage);
- String property = cfg.getProperty(RenderWindowCommand.WINDOW_ERROR);
- if (!RenderWindowCommand.HIDE.equals(property))
- {
- windowTitle = "An error occured while rendering window '" +
windowId + "'";
- contentChars = errorResult.getMessage();
- Throwable t = errorResult.getThrowable();
- if (t != null && RenderWindowCommand.SHOW.equals(property))
- {
- contentChars = Exceptions.toHTML(t, true);
- }
- return new WindowRendition(new WindowResult(windowTitle, contentChars,
actionMap, windowProps, headerChars, windowNS.getWindowState(), windowNS.getMode()));
- }
+ cr = new
UnavailableResourceResponse(((NoSuchPortletException)e).getPortletId(), false);
}
- else if (response instanceof UnavailableResponse)
- {
- if
(RenderWindowCommand.SHOW.equals(cfg.getProperty(RenderWindowCommand.WINDOW_UNAVAILABLE)))
- {
- windowTitle = "Portlet unavailable";
- contentChars = "Portlet unavailable";
- actionMap = new HashMap();
- actionMap.put(ActionRendererContext.MODES_KEY, Collections.EMPTY_LIST);
- actionMap.put(ActionRendererContext.WINDOWSTATES_KEY,
Collections.EMPTY_LIST);
- return new WindowRendition(new WindowResult(windowTitle, contentChars,
actionMap, windowProps, headerChars, windowNS.getWindowState(), windowNS.getMode()));
- }
- }
- else if (response instanceof InsufficientPrivilegesResponse)
- {
- // Julien : go to the section below, I know it is very ugly
- throw new ResourceAccessDeniedException(windowId.toString());
- }
else
{
- return new PortletWindowResponse(windowId, response);
+ log.error("Portlet invoker exception during portlet window
rendering", e);
+ cr = new org.jboss.portal.core.controller.command.response.ErrorResponse(e,
false);
}
+
+ //
+ return new WindowRendition(windowProps, windowState, mode,
supportedWindowStates, supportedModes, cr);
}
- catch (ResourceAccessDeniedException e)
+
+ //
+ ControllerResponse cr;
+ if (response instanceof FragmentResponse)
{
- if (log.isTraceEnabled())
+ FragmentResponse fragment = (FragmentResponse)response;
+
+ //
+ String windowTitle = fragment.getTitle();
+ if (windowTitle == null)
{
- log.trace("Window access denied", e);
+ windowTitle = window.getName();
}
- if
(RenderWindowCommand.SHOW.equals(cfg.getProperty(RenderWindowCommand.WINDOW_ACCESS_DENIED)))
+
+ //
+ String headerChars = fragment.getHeader();
+
+ // Handle minimized here
+ String contentChars;
+ if (WindowState.MINIMIZED == windowNS.getWindowState())
{
- actionMap.put(ActionRendererContext.MODES_KEY, Collections.EMPTY_LIST);
- actionMap.put(ActionRendererContext.WINDOWSTATES_KEY,
Collections.EMPTY_LIST);
- windowTitle = "Access denied";
- contentChars = "Access denied";
- return new WindowRendition(new WindowResult(windowTitle, contentChars,
actionMap, windowProps, headerChars, windowNS.getWindowState(), windowNS.getMode()));
+ contentChars = "";
}
- }
- catch (ResourceNotFoundException e)
- {
- if (log.isTraceEnabled())
+ else
{
- log.trace("Window not found", e);
+ contentChars = fragment.getContent();
}
- if
(RenderWindowCommand.SHOW.equals(cfg.getProperty(RenderWindowCommand.WINDOW_NOT_FOUND)))
+
+ // Update window props after render if needed
+ Boolean partialRefresh =
(Boolean)invocation.getAttribute(PortletInvocation.RESPONSE_PROPERTIES_SCOPE,
AjaxInterceptor.PARTIAL_REFRESH);
+ if (partialRefresh != null && Boolean.FALSE.equals(partialRefresh))
{
- actionMap.put(ActionRendererContext.MODES_KEY, Collections.EMPTY_LIST);
- actionMap.put(ActionRendererContext.WINDOWSTATES_KEY,
Collections.EMPTY_LIST);
- windowTitle = "Cannot render";
- contentChars = "Object not found " + e.getRef();
- return new WindowRendition(new WindowResult(windowTitle, contentChars,
actionMap, windowProps, headerChars, windowNS.getWindowState(), windowNS.getMode()));
+ DynaRenderOptions options = DynaRenderOptions.getOptions(null,
partialRefresh);
+ options.setOptions(windowProps);
}
+
+ //
+ cr = new MarkupResponse(windowTitle, contentChars, headerChars);
}
- catch (ControllerException e)
+ else if (response instanceof ErrorResponse)
{
- // It's a CommandException that we rethrow
- throw e;
+ cr = new
org.jboss.portal.core.controller.command.response.ErrorResponse(((ErrorResponse)response).getCause(),
false);
}
- catch (Exception e)
+ else if (response instanceof UnavailableResponse)
{
- log.error("Rendering portlet window " + windowId + " produced an
internal error", e);
- String property = cfg.getProperty(RenderWindowCommand.WINDOW_INTERNAL_ERROR);
- if (RenderWindowCommand.SHOW.equals(property))
- {
- windowTitle = "An internal error occured while rendering window
'" + window + "'";
- contentChars = Exceptions.toHTML(e, true);
- return new WindowRendition(new WindowResult(windowTitle, contentChars,
actionMap, windowProps, headerChars, windowNS.getWindowState(), windowNS.getMode()));
- }
+ cr = new UnavailableResourceResponse(instance.getId(), false);
}
-
- //
- return null;
- }
-
- /**
- * Create the action URLs for the allowed window states of the rendered portlet window
and add them to the provided
- * actionMap.
- */
- private void addStateActions(ControllerContext context, Window window, Map actionMap,
WindowState currentWindowState, List supportedWindowStates)
- {
- List windowStates = new ArrayList(supportedWindowStates.size());
- for (Iterator j = supportedWindowStates.iterator(); j.hasNext();)
+ else if (response instanceof InsufficientPrivilegesResponse)
{
- WindowState windowState = (WindowState)j.next();
- String url = createUpdateNavigationalStateURL(context, window, null,
windowState);
- boolean disabled = windowState.equals(currentWindowState);
- WindowResult.Action action = new WindowResult.Action(windowState.toString(),
url, !disabled);
- windowStates.add(action);
+ cr = new SecurityErrorResponse(SecurityErrorResponse.NOT_AUTHORIZED, false);
}
- actionMap.put(ActionRendererContext.WINDOWSTATES_KEY, windowStates);
- }
-
- /**
- * Create the action URLs for the allowed portlet modes of the rendered portlet window
and add them to the provided
- * actionMap.
- */
- private void addModeActions(ControllerContext context, Window window, Map actionMap,
Mode currentMode, List supportedModes)
- {
- List modes = new ArrayList(supportedModes.size());
- for (Iterator j = supportedModes.iterator(); j.hasNext();)
+ else if (response instanceof InsufficientTransportGuaranteeResponse)
{
- Mode mode = (Mode)j.next();
- String url = createUpdateNavigationalStateURL(context, window, mode, null);
- boolean disabled = mode.equals(currentMode);
- WindowResult.Action action = new WindowResult.Action(mode.toString(), url,
!disabled);
- modes.add(action);
+ cr = new SecurityErrorResponse(SecurityErrorResponse.NOT_SECURE, false);
}
- actionMap.put(ActionRendererContext.MODES_KEY, modes);
- }
+ else
+ {
+ return null;
+ }
- private String createUpdateNavigationalStateURL(ControllerContext context, Window
window, Mode mode, WindowState windowState)
- {
- InvokePortletWindowRenderCommand cmd = new
InvokePortletWindowRenderCommand(window.getId(), mode, windowState);
- ServerInvocationContext serverContext =
context.getServerInvocation().getServerContext();
- boolean secure = serverContext.getURLContext().isSecure();
- boolean authenticated = serverContext.getURLContext().isAuthenticated();
- URLContext urlContext = URLContext.newInstance(secure, authenticated);
- return context.renderURL(cmd, urlContext, URLFormat.newInstance(true, true));
+ //
+ return new WindowRendition(windowProps, windowState, mode, supportedWindowStates,
supportedModes, cr);
}
}
Modified:
trunk/core/src/main/org/jboss/portal/core/impl/model/content/generic/InternalGenericContentProvider.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/core/impl/model/content/generic/InternalGenericContentProvider.java 2007-06-08
13:50:21 UTC (rev 7394)
+++
trunk/core/src/main/org/jboss/portal/core/impl/model/content/generic/InternalGenericContentProvider.java 2007-06-11
11:31:36 UTC (rev 7395)
@@ -25,6 +25,7 @@
import org.jboss.portal.core.model.content.Content;
import org.jboss.portal.core.model.content.spi.ContentProvider;
import org.jboss.portal.core.model.content.ContentType;
+import org.jboss.portal.core.model.portal.content.WindowRendition;
import org.jboss.portal.core.model.content.spi.handler.ContentState;
import org.jboss.portal.core.model.content.spi.handler.ContentHandler;
import org.jboss.portal.core.model.content.spi.portlet.ContentPortlet;
@@ -33,14 +34,12 @@
import org.jboss.portal.core.model.portal.command.render.RenderWindowCommand;
import org.jboss.portal.core.model.portal.Window;
import org.jboss.portal.core.model.portal.PortalObjectId;
+import org.jboss.portal.core.model.portal.command.response.MarkupResponse;
import org.jboss.portal.core.model.portal.navstate.WindowNavigationalState;
import org.jboss.portal.core.controller.ControllerContext;
-import org.jboss.portal.core.controller.ControllerResponse;
import org.jboss.portal.core.impl.model.content.InternalContentProvider;
import org.jboss.portal.core.navstate.NavigationalStateKey;
-import org.jboss.portal.core.theme.WindowRendition;
import org.jboss.portal.portlet.PortletParametersStateString;
-import org.jboss.portal.theme.page.WindowResult;
import org.jboss.portal.Mode;
import org.jboss.portal.common.i18n.LocalizedString;
import org.jboss.portal.common.invocation.AttributeResolver;
@@ -155,7 +154,7 @@
{
}
- public ControllerResponse renderWindow(RenderWindowCommand cmd) throws Exception
+ public WindowRendition renderWindow(RenderWindowCommand cmd)
{
ControllerContext context = cmd.getControllerContext();
Window window = cmd.getWindow();
@@ -208,22 +207,18 @@
}
//
- ControllerResponse o = super.renderWindow(cmd);
+ WindowRendition rendition = super.renderWindow(cmd);
//
- if (o instanceof WindowRendition && getDecorateContent() == false)
+ if (rendition != null && rendition.getControllerResponse() instanceof
MarkupResponse && !getDecorateContent())
{
- WindowRendition rendition = (WindowRendition)o;
- WindowResult result = rendition.getWindow();
-
- //
- Map props = result.getProperties();
+ Map props = rendition.getProperties();
props.put("theme.windowRendererId", "emptyRenderer");
props.put("theme.decorationRendererId", "emptyRenderer");
props.put("theme.portletRendererId", "emptyRenderer");
}
//
- return o;
+ return rendition;
}
}
Modified:
trunk/core/src/main/org/jboss/portal/core/model/instance/command/PortletInstanceCommand.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/core/model/instance/command/PortletInstanceCommand.java 2007-06-08
13:50:21 UTC (rev 7394)
+++
trunk/core/src/main/org/jboss/portal/core/model/instance/command/PortletInstanceCommand.java 2007-06-11
11:31:36 UTC (rev 7395)
@@ -23,7 +23,7 @@
package org.jboss.portal.core.model.instance.command;
import org.jboss.portal.core.controller.ControllerCommand;
-import org.jboss.portal.core.controller.ControllerException;
+import org.jboss.portal.core.controller.NoSuchResourceException;
import org.jboss.portal.core.model.instance.Instance;
import org.jboss.portal.core.model.instance.InstanceContainer;
import org.jboss.portal.portlet.StateString;
@@ -62,15 +62,18 @@
return instanceId;
}
- protected void create() throws ControllerException
+
+ public void acquireResources() throws NoSuchResourceException
{
InstanceContainer container = context.getController().getInstanceContainer();
//
instance = container.getDefinition(instanceId);
+
+ //
if (instance == null)
{
- throw new ControllerException("Configurator portlet instance " +
instanceId + " not found");
+ throw new NoSuchResourceException("Configurator portlet instance " +
instanceId + " not found");
}
}
Modified:
trunk/core/src/main/org/jboss/portal/core/model/instance/command/action/InvokePortletInstanceActionCommand.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/core/model/instance/command/action/InvokePortletInstanceActionCommand.java 2007-06-08
13:50:21 UTC (rev 7394)
+++
trunk/core/src/main/org/jboss/portal/core/model/instance/command/action/InvokePortletInstanceActionCommand.java 2007-06-11
11:31:36 UTC (rev 7395)
@@ -27,9 +27,9 @@
import org.jboss.portal.core.controller.portlet.PortletContextFactory;
import org.jboss.portal.core.controller.portlet.InvokePortletCommandFactory;
import org.jboss.portal.core.controller.portlet.PortletInvocationFactory;
+import org.jboss.portal.core.controller.portlet.ControllerResponseFactory;
import org.jboss.portal.core.controller.command.info.CommandInfo;
import org.jboss.portal.core.model.instance.InvokePortletInstanceCommandFactory;
-import org.jboss.portal.core.model.instance.command.response.PortletInstanceResponse;
import org.jboss.portal.core.model.instance.command.PortletInstanceCommand;
import org.jboss.portal.portlet.StateString;
import org.jboss.portal.portlet.PortletParameters;
@@ -52,7 +52,11 @@
/** The nform. */
private PortletParameters form;
- public InvokePortletInstanceActionCommand(String instanceId, StateString
navigationalState, StateString interactionState, PortletParameters form)
+ public InvokePortletInstanceActionCommand(
+ String instanceId,
+ StateString navigationalState,
+ StateString interactionState,
+ PortletParameters form)
{
super(instanceId, navigationalState);
@@ -98,11 +102,11 @@
PortletInvocationResponse response = instance.invoke(action);
//
- return new PortletInstanceResponse(instanceId, response);
+ return ControllerResponseFactory.createActionResponse(instanceId, response);
}
catch (PortletInvokerException e)
{
- throw new ControllerException(e);
+ return ControllerResponseFactory.createResponse(e);
}
}
}
Copied:
trunk/core/src/main/org/jboss/portal/core/model/instance/command/response/PortletInstanceActionResponse.java
(from rev 7371,
trunk/core/src/main/org/jboss/portal/core/model/instance/command/response/PortletInstanceResponse.java)
===================================================================
---
trunk/core/src/main/org/jboss/portal/core/model/instance/command/response/PortletInstanceActionResponse.java
(rev 0)
+++
trunk/core/src/main/org/jboss/portal/core/model/instance/command/response/PortletInstanceActionResponse.java 2007-06-11
11:31:36 UTC (rev 7395)
@@ -0,0 +1,52 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.core.model.instance.command.response;
+
+import org.jboss.portal.core.controller.portlet.PortletActionResponse;
+import org.jboss.portal.portlet.StateString;
+import org.jboss.portal.WindowState;
+import org.jboss.portal.Mode;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class PortletInstanceActionResponse extends PortletActionResponse
+{
+
+ /** . */
+ private String instanceId;
+
+ public PortletInstanceActionResponse(String instanceId, WindowState windowState, Mode
mode, StateString contentState)
+ {
+ super(windowState, mode, contentState);
+
+ //
+ this.instanceId = instanceId;
+ }
+
+ public String getInstanceId()
+ {
+ return instanceId;
+ }
+}
Deleted:
trunk/core/src/main/org/jboss/portal/core/model/instance/command/response/PortletInstanceResponse.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/core/model/instance/command/response/PortletInstanceResponse.java 2007-06-08
13:50:21 UTC (rev 7394)
+++
trunk/core/src/main/org/jboss/portal/core/model/instance/command/response/PortletInstanceResponse.java 2007-06-11
11:31:36 UTC (rev 7395)
@@ -1,50 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, and individual *
- * contributors as indicated by the @authors tag. See the *
- * copyright.txt in the distribution for a full listing of *
- * individual contributors. *
- * *
- * This is free software; you can redistribute it and/or modify it *
- * under the terms of the GNU Lesser General Public License as *
- * published by the Free Software Foundation; either version 2.1 of *
- * the License, or (at your option) any later version. *
- * *
- * This software is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this software; if not, write to the Free *
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
- ******************************************************************************/
-package org.jboss.portal.core.model.instance.command.response;
-
-import org.jboss.portal.core.controller.portlet.PortletResponse;
-import org.jboss.portal.portlet.invocation.response.PortletInvocationResponse;
-
-/**
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision: 1.1 $
- */
-public class PortletInstanceResponse extends PortletResponse
-{
-
- /** . */
- private String instanceId;
-
- public PortletInstanceResponse(String instanceId, PortletInvocationResponse response)
- {
- super(response);
-
- //
- this.instanceId = instanceId;
- }
-
- public String getInstanceId()
- {
- return instanceId;
- }
-}
Modified:
trunk/core/src/main/org/jboss/portal/core/model/portal/DefaultPortalCommandFactory.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/core/model/portal/DefaultPortalCommandFactory.java 2007-06-08
13:50:21 UTC (rev 7394)
+++
trunk/core/src/main/org/jboss/portal/core/model/portal/DefaultPortalCommandFactory.java 2007-06-11
11:31:36 UTC (rev 7395)
@@ -38,10 +38,13 @@
public class DefaultPortalCommandFactory extends AbstractCommandFactory
{
+ /** . */
private PortalObjectId defaultPortalPath = PortalObjectId.parse("/default",
PortalObjectPath.CANONICAL_FORMAT);
+ /** . */
private CommandFactory nextFactory;
+ /** . */
private PortalObjectContainer container;
public PortalObjectContainer getContainer()
Modified:
trunk/core/src/main/org/jboss/portal/core/model/portal/PortalObjectContainer.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/core/model/portal/PortalObjectContainer.java 2007-06-08
13:50:21 UTC (rev 7394)
+++
trunk/core/src/main/org/jboss/portal/core/model/portal/PortalObjectContainer.java 2007-06-11
11:31:36 UTC (rev 7395)
@@ -33,7 +33,7 @@
public interface PortalObjectContainer
{
/**
- * Returns a container object.
+ * Returns a portal object or null if it cannot be found.
*
* @param id the portal object id
* @return the specified portal object
Modified:
trunk/core/src/main/org/jboss/portal/core/model/portal/PortalObjectResponseHandler.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/core/model/portal/PortalObjectResponseHandler.java 2007-06-08
13:50:21 UTC (rev 7394)
+++
trunk/core/src/main/org/jboss/portal/core/model/portal/PortalObjectResponseHandler.java 2007-06-11
11:31:36 UTC (rev 7395)
@@ -23,17 +23,17 @@
package org.jboss.portal.core.model.portal;
import org.jboss.portal.core.controller.handler.AbstractResponseHandler;
-import org.jboss.portal.core.controller.handler.CommandForward;
import org.jboss.portal.core.controller.handler.HandlerResponse;
import org.jboss.portal.core.controller.handler.HTTPResponse;
import org.jboss.portal.core.controller.ControllerCommand;
import org.jboss.portal.core.controller.ControllerContext;
import org.jboss.portal.core.controller.ControllerException;
import org.jboss.portal.core.controller.ControllerResponse;
+import org.jboss.portal.core.controller.command.response.ThrowableResponse;
import org.jboss.portal.core.controller.handler.ResponseHandlerException;
+import org.jboss.portal.core.controller.handler.ResponseForward;
import org.jboss.portal.core.model.portal.command.response.UpdatePageResponse;
import org.jboss.portal.core.model.portal.command.response.UpdateWindowResponse;
-import org.jboss.portal.core.model.portal.command.view.ViewPageCommand;
import org.jboss.portal.core.model.portal.command.render.RenderPageCommand;
import org.jboss.portal.core.theme.PageRendition;
import org.jboss.portal.server.ServerInvocationContext;
@@ -53,45 +53,54 @@
public HandlerResponse processCommandResponse(ControllerContext controllerContext,
ControllerCommand ceommand, ControllerResponse controllerResponse) throws
ResponseHandlerException
{
+ if (controllerResponse instanceof UpdateWindowResponse)
+ {
+ UpdateWindowResponse uwmr = (UpdateWindowResponse)controllerResponse;
+ PortalObjectContainer portalObjectContainer =
controllerContext.getController().getPortalObjectContainer();
+ PortalObject window = portalObjectContainer.getObject(uwmr.getWindowId());
+ Page page = (Page)window.getParent();
+
+ // We can do that safely as we know that only this class is responsible for
evaluating UpdatePageResponse objects
+ controllerResponse = new UpdatePageResponse(page.getId());
+ }
+
+ //
if (controllerResponse instanceof UpdatePageResponse)
{
- UpdatePageResponse uvr = (UpdatePageResponse)controllerResponse;
-
try
{
+ UpdatePageResponse uvr = (UpdatePageResponse)controllerResponse;
RenderPageCommand rpc = new RenderPageCommand(uvr.getPageId());
- final PageRendition rendition =
(PageRendition)controllerContext.execute(rpc);
- final ServerInvocation invocation = controllerContext.getServerInvocation();
- return new HTTPResponse()
+ ControllerResponse resp = controllerContext.execute(rpc);
+
+ //
+ if (resp instanceof PageRendition)
{
- public void sendResponse(ServerInvocationContext ctx) throws IOException,
ServletException
+ final PageRendition rendition = (PageRendition)resp;
+ final ServerInvocation invocation =
controllerContext.getServerInvocation();
+ return new HTTPResponse()
{
- ServletContextDispatcher dispatcher = new
ServletContextDispatcher(invocation.getServerContext().getClientRequest(),
invocation.getServerContext().getClientResponse(),
invocation.getRequest().getServer().getServletContainerContext());
- MarkupInfo markupInfo =
(MarkupInfo)invocation.getResponse().getContentInfo();
- rendition.render(markupInfo, dispatcher);
- }
- };
+ public void sendResponse(ServerInvocationContext ctx) throws
IOException, ServletException
+ {
+ ServletContextDispatcher dispatcher = new
ServletContextDispatcher(invocation.getServerContext().getClientRequest(),
invocation.getServerContext().getClientResponse(),
invocation.getRequest().getServer().getServletContainerContext());
+ MarkupInfo markupInfo =
(MarkupInfo)invocation.getResponse().getContentInfo();
+ rendition.render(markupInfo, dispatcher);
+ }
+ };
+ }
+ else
+ {
+ // Another kind of response is not interpretable
+ return new ResponseForward(resp);
+ }
}
catch (ControllerException e)
{
- e.printStackTrace();
-
- // todo
- return null;
+ return new ResponseForward(new ThrowableResponse(e));
}
}
- else if (controllerResponse instanceof UpdateWindowResponse)
- {
- UpdateWindowResponse uwmr = (UpdateWindowResponse)controllerResponse;
- PortalObjectContainer portalObjectContainer =
controllerContext.getController().getPortalObjectContainer();
- PortalObject window = portalObjectContainer.getObject(uwmr.getWindowId());
- Page page = (Page)window.getParent();
- ViewPageCommand rpc = new ViewPageCommand(page.getId());
- return new CommandForward(rpc, null);
- }
- else
- {
- return null;
- }
+
+ //
+ return null;
}
}
Modified:
trunk/core/src/main/org/jboss/portal/core/model/portal/command/ContextCommand.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/core/model/portal/command/ContextCommand.java 2007-06-08
13:50:21 UTC (rev 7394)
+++
trunk/core/src/main/org/jboss/portal/core/model/portal/command/ContextCommand.java 2007-06-11
11:31:36 UTC (rev 7395)
@@ -24,7 +24,7 @@
import org.jboss.portal.core.model.portal.PortalObjectId;
import org.jboss.portal.core.model.portal.Context;
-import org.jboss.portal.core.controller.ControllerException;
+import org.jboss.portal.core.controller.NoSuchResourceException;
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
@@ -51,15 +51,9 @@
return root;
}
- /**
- * Initialize the command.
- *
- * @throws org.jboss.portal.common.invocation.InvocationException
- *
- */
- public void create() throws ControllerException
+ public void acquireResources() throws NoSuchResourceException
{
- super.create();
+ super.acquireResources();
//
root = (Context)getTarget();
Modified: trunk/core/src/main/org/jboss/portal/core/model/portal/command/PageCommand.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/core/model/portal/command/PageCommand.java 2007-06-08
13:50:21 UTC (rev 7394)
+++
trunk/core/src/main/org/jboss/portal/core/model/portal/command/PageCommand.java 2007-06-11
11:31:36 UTC (rev 7395)
@@ -22,60 +22,42 @@
******************************************************************************/
package org.jboss.portal.core.model.portal.command;
-import org.jboss.portal.core.controller.ControllerException;
-import org.jboss.portal.core.controller.ResourceNotFoundException;
import org.jboss.portal.core.model.portal.Page;
-import org.jboss.portal.core.model.portal.Portal;
import org.jboss.portal.core.model.portal.PortalObjectId;
+import org.jboss.portal.core.model.portal.Portal;
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision: 1.1 $
*/
-public abstract class PageCommand extends PortalObjectCommand
+public abstract class PageCommand extends PortalCommand
{
/** . */
protected Page page;
- /** . */
- protected Portal portal;
-
public PageCommand(PortalObjectId pageId)
{
super(pageId);
}
+ protected abstract Page initPage();
+
+ protected final Portal initPortal()
+ {
+ page = initPage();
+
+ //
+ return page.getPortal();
+ }
+
/**
* Get the requested page
*
* @return the requested page
*/
- public Page getPage()
+ public final Page getPage()
{
return page;
}
-
- /**
- * Initialize the command
- *
- * @throws org.jboss.portal.common.invocation.InvocationException
- *
- */
- public void create() throws ControllerException
- {
- super.create();
-
- //
- page = (Page)getTarget();
-
- // Get nearest portal ancestor
- portal = page.getPortal();
-
- //
- if (portal == null)
- {
- throw new ResourceNotFoundException(targetId.toString());
- }
- }
}
Modified:
trunk/core/src/main/org/jboss/portal/core/model/portal/command/PortalCommand.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/core/model/portal/command/PortalCommand.java 2007-06-08
13:50:21 UTC (rev 7394)
+++
trunk/core/src/main/org/jboss/portal/core/model/portal/command/PortalCommand.java 2007-06-11
11:31:36 UTC (rev 7395)
@@ -22,7 +22,7 @@
******************************************************************************/
package org.jboss.portal.core.model.portal.command;
-import org.jboss.portal.core.controller.ControllerException;
+import org.jboss.portal.core.controller.NoSuchResourceException;
import org.jboss.portal.core.model.portal.Portal;
import org.jboss.portal.core.model.portal.PortalObjectId;
@@ -46,22 +46,19 @@
*
* @return the requested portal
*/
- public Portal getPortal()
+ public final Portal getPortal()
{
return portal;
}
- /**
- * Initialize the command
- *
- * @throws org.jboss.portal.common.invocation.InvocationException
- *
- */
- public void create() throws ControllerException
+ public void acquireResources() throws NoSuchResourceException
{
- super.create();
+ super.acquireResources();
//
- portal = (Portal)getTarget();
+ portal = initPortal();
}
+
+ protected abstract Portal initPortal();
+
}
Modified:
trunk/core/src/main/org/jboss/portal/core/model/portal/command/PortalObjectCommand.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/core/model/portal/command/PortalObjectCommand.java 2007-06-08
13:50:21 UTC (rev 7394)
+++
trunk/core/src/main/org/jboss/portal/core/model/portal/command/PortalObjectCommand.java 2007-06-11
11:31:36 UTC (rev 7395)
@@ -23,16 +23,13 @@
package org.jboss.portal.core.model.portal.command;
import org.jboss.portal.core.controller.ControllerCommand;
-import org.jboss.portal.core.controller.ControllerException;
-import org.jboss.portal.core.controller.ControllerSecurityException;
-import org.jboss.portal.core.controller.ResourceAccessDeniedException;
-import org.jboss.portal.core.controller.ResourceNotFoundException;
+import org.jboss.portal.core.controller.SecurityException;
+import org.jboss.portal.core.controller.NoSuchResourceException;
+import org.jboss.portal.core.controller.AccessDeniedException;
import org.jboss.portal.core.model.portal.PortalObject;
import org.jboss.portal.core.model.portal.PortalObjectPermission;
import org.jboss.portal.core.model.portal.PortalObjectId;
-import org.jboss.portal.security.PortalSecurityException;
import org.jboss.portal.security.spi.auth.PortalAuthorizationManager;
-import org.jboss.portal.identity.User;
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
@@ -60,20 +57,19 @@
this.dashboard = "dashboard".equals(targetId.getNamespace());
}
-
public final PortalObjectId getTargetId()
{
return targetId;
}
- public void create() throws ControllerException
+ public void acquireResources() throws NoSuchResourceException
{
// Get portal object
target = context.getController().getPortalObjectContainer().getObject(targetId);
if (target == null)
{
- throw new ResourceNotFoundException(targetId.toString());
+ throw new NoSuchResourceException(targetId.toString());
}
}
@@ -81,17 +77,17 @@
* Enforce the security on this command using the provided portal authorization
manager.
*
* @param pam the portal authorization manager
- * @throws org.jboss.portal.core.controller.ControllerSecurityException
+ * @throws org.jboss.portal.core.controller.SecurityException
* if the access is not granted
*/
- public void enforceSecurity(PortalAuthorizationManager pam) throws
ControllerSecurityException, PortalSecurityException
+ public void enforceSecurity(PortalAuthorizationManager pam) throws SecurityException
{
PortalObject target = getTarget();
PortalObjectId id = target.getId();
PortalObjectPermission perm = new PortalObjectPermission(id,
PortalObjectPermission.VIEW_MASK);
if (!pam.checkPermission(perm))
{
- throw new ResourceAccessDeniedException("Not Authorized");
+ throw new AccessDeniedException(id.toString(), "View permission not
granted");
}
}
Modified:
trunk/core/src/main/org/jboss/portal/core/model/portal/command/WindowCommand.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/core/model/portal/command/WindowCommand.java 2007-06-08
13:50:21 UTC (rev 7394)
+++
trunk/core/src/main/org/jboss/portal/core/model/portal/command/WindowCommand.java 2007-06-11
11:31:36 UTC (rev 7395)
@@ -22,14 +22,10 @@
******************************************************************************/
package org.jboss.portal.core.model.portal.command;
-import org.jboss.portal.core.controller.ControllerException;
-import org.jboss.portal.core.controller.ControllerSecurityException;
-import org.jboss.portal.core.controller.ResourceNotFoundException;
+import org.jboss.portal.core.controller.SecurityException;
import org.jboss.portal.core.model.portal.Page;
-import org.jboss.portal.core.model.portal.Portal;
import org.jboss.portal.core.model.portal.Window;
import org.jboss.portal.core.model.portal.PortalObjectId;
-import org.jboss.portal.security.PortalSecurityException;
import org.jboss.portal.security.spi.auth.PortalAuthorizationManager;
/**
@@ -38,15 +34,9 @@
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision$
*/
-public abstract class WindowCommand extends PortalObjectCommand
+public abstract class WindowCommand extends PageCommand
{
- /** The portal. */
- protected Portal portal;
-
- /** The portal. */
- protected Page page;
-
/** The window. */
protected Window window;
@@ -55,53 +45,29 @@
super(windowId);
}
- public Portal getPortal()
+ protected final Page initPage()
{
- return portal;
- }
+ window = (Window)getTarget();
- public Page getPage()
- {
- return page;
+ //
+ return window.getPage();
}
- public Window getWindow()
+ public final Window getWindow()
{
return window;
}
- public void create() throws ControllerException
- {
- super.create();
-
- // Retrieve the window
- window = (Window)getTarget();
-
- // First retrieve the target
- page = (Page)window.getParent();
- if (page == null)
- {
- throw new ResourceNotFoundException(targetId.toString());
- }
-
- // Get hardcoded portal for now
- portal = page.getPortal();
- if (portal == null)
- {
- throw new ResourceNotFoundException(targetId.toString());
- }
- }
-
/**
* We only enforce security at instance and component level.
*
* @param pam
- * @throws org.jboss.portal.core.controller.ControllerSecurityException
+ * @throws org.jboss.portal.core.controller.SecurityException
*
* @throws org.jboss.portal.security.PortalSecurityException
*
*/
- public void enforceSecurity(PortalAuthorizationManager pam) throws
ControllerSecurityException, PortalSecurityException
+ public void enforceSecurity(PortalAuthorizationManager pam) throws SecurityException
{
}
}
Modified:
trunk/core/src/main/org/jboss/portal/core/model/portal/command/action/ImportPageToDashboardCommand.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/core/model/portal/command/action/ImportPageToDashboardCommand.java 2007-06-08
13:50:21 UTC (rev 7394)
+++
trunk/core/src/main/org/jboss/portal/core/model/portal/command/action/ImportPageToDashboardCommand.java 2007-06-11
11:31:36 UTC (rev 7395)
@@ -26,10 +26,12 @@
import org.jboss.portal.core.controller.command.info.ActionCommandInfo;
import org.jboss.portal.core.controller.ControllerException;
import org.jboss.portal.core.controller.ControllerResponse;
+import org.jboss.portal.core.controller.NoSuchResourceException;
import org.jboss.portal.core.model.portal.PortalObjectId;
import org.jboss.portal.core.model.portal.Portal;
import org.jboss.portal.core.model.portal.DuplicatePortalObjectException;
import org.jboss.portal.core.model.portal.PortalObject;
+import org.jboss.portal.core.model.portal.Page;
import org.jboss.portal.core.model.portal.command.response.UpdatePageResponse;
import org.jboss.portal.core.model.portal.command.PageCommand;
import org.jboss.portal.core.model.CustomizationManager;
@@ -60,10 +62,15 @@
return info;
}
- public void create() throws ControllerException
+ protected Page initPage()
{
- super.create();
+ return (Page)getTarget();
+ }
+ public void acquireResources() throws NoSuchResourceException
+ {
+ super.acquireResources();
+
//
CustomizationManager manager =
getControllerContext().getController().getCustomizationManager();
Modified:
trunk/core/src/main/org/jboss/portal/core/model/portal/command/action/InvokePortletWindowActionCommand.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/core/model/portal/command/action/InvokePortletWindowActionCommand.java 2007-06-08
13:50:21 UTC (rev 7394)
+++
trunk/core/src/main/org/jboss/portal/core/model/portal/command/action/InvokePortletWindowActionCommand.java 2007-06-11
11:31:36 UTC (rev 7395)
@@ -27,16 +27,15 @@
import org.jboss.portal.WindowState;
import org.jboss.portal.identity.User;
import org.jboss.portal.core.controller.ControllerException;
-import org.jboss.portal.core.controller.ResourceNotFoundException;
import org.jboss.portal.core.controller.ControllerResponse;
+import org.jboss.portal.core.controller.NoSuchResourceException;
import org.jboss.portal.core.controller.command.info.ActionCommandInfo;
import org.jboss.portal.core.controller.command.info.CommandInfo;
import org.jboss.portal.core.controller.portlet.PortletInvocationFactory;
-import org.jboss.portal.core.model.portal.command.response.PortletWindowResponse;
+import org.jboss.portal.core.controller.portlet.ControllerResponseFactory;
import org.jboss.portal.core.model.portal.PortalObjectId;
import org.jboss.portal.core.model.instance.Instance;
import org.jboss.portal.core.model.content.Content;
-import org.jboss.portal.portlet.NoSuchPortletException;
import org.jboss.portal.portlet.PortletParameters;
import org.jboss.portal.portlet.PortletInvokerException;
import org.jboss.portal.portlet.StateString;
@@ -113,9 +112,9 @@
return info;
}
- public void create() throws ControllerException
+ public void acquireResources() throws NoSuchResourceException
{
- super.create();
+ super.acquireResources();
// We need the user id
User user = getControllerContext().getUser();
@@ -136,7 +135,7 @@
{
ref = window.getId().toString();
}
- throw new ResourceNotFoundException(ref);
+ throw new NoSuchResourceException(ref);
}
}
@@ -158,18 +157,11 @@
PortletInvocationResponse response = instance.invoke(invocation);
//
- return new PortletWindowResponse(targetId, response);
+ return ControllerResponseFactory.createActionResponse(targetId, response);
}
catch (PortletInvokerException e)
{
- if (e instanceof NoSuchPortletException)
- {
- throw new
ResourceNotFoundException(((NoSuchPortletException)e).getPortletId());
- }
- else
- {
- throw new ControllerException(e);
- }
+ return ControllerResponseFactory.createResponse(e);
}
}
}
Modified:
trunk/core/src/main/org/jboss/portal/core/model/portal/command/action/InvokePortletWindowRenderCommand.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/core/model/portal/command/action/InvokePortletWindowRenderCommand.java 2007-06-08
13:50:21 UTC (rev 7394)
+++
trunk/core/src/main/org/jboss/portal/core/model/portal/command/action/InvokePortletWindowRenderCommand.java 2007-06-11
11:31:36 UTC (rev 7395)
@@ -87,39 +87,15 @@
PortalObjectId windowId = window.getId();
NavigationalStateKey nsKey = new
NavigationalStateKey(WindowNavigationalState.class, windowId);
- //
+ // Get old NS
WindowNavigationalState oldNS =
(WindowNavigationalState)ctx.getAttribute(NAVIGATIONAL_STATE_SCOPE, nsKey);
- //
- StateString newState = oldNS != null ? oldNS.getState() : null;
- WindowState newWindowState = oldNS != null ? oldNS.getWindowState() :
WindowState.NORMAL;
- Mode newMode = oldNS != null ? oldNS.getMode() : Mode.VIEW;
-
- //
- if (navigationalState != null)
- {
- newState = navigationalState;
- }
-
- //
- if (this.mode != null)
- {
- newMode = this.mode;
- }
-
- //
- if (this.windowState != null)
- {
- newWindowState = this.windowState;
- }
-
// Create new NS
- WindowNavigationalState newNS = new WindowNavigationalState(newWindowState,
newMode, newState);
+ WindowNavigationalState newNS = WindowNavigationalState.bilto(oldNS,
this.windowState, this.mode, this.navigationalState);
// Update NS
ctx.setAttribute(NAVIGATIONAL_STATE_SCOPE, nsKey, newNS);
-
//
return new UpdateWindowResponse(windowId);
}
Modified:
trunk/core/src/main/org/jboss/portal/core/model/portal/command/action/InvokeWindowCommand.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/core/model/portal/command/action/InvokeWindowCommand.java 2007-06-08
13:50:21 UTC (rev 7394)
+++
trunk/core/src/main/org/jboss/portal/core/model/portal/command/action/InvokeWindowCommand.java 2007-06-11
11:31:36 UTC (rev 7395)
@@ -43,6 +43,8 @@
public InvokeWindowCommand(PortalObjectId windowId, Mode mode, WindowState
windowState) throws IllegalArgumentException
{
super(windowId);
+
+ //
this.mode = mode;
this.windowState = windowState;
}
Modified:
trunk/core/src/main/org/jboss/portal/core/model/portal/command/action/MoveWindowCommand.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/core/model/portal/command/action/MoveWindowCommand.java 2007-06-08
13:50:21 UTC (rev 7394)
+++
trunk/core/src/main/org/jboss/portal/core/model/portal/command/action/MoveWindowCommand.java 2007-06-11
11:31:36 UTC (rev 7395)
@@ -63,6 +63,8 @@
throws IllegalArgumentException
{
super(windowId);
+
+ //
this.fromPos = fromPos;
this.fromRegion = fromRegion;
this.toPos = toPos;
Modified:
trunk/core/src/main/org/jboss/portal/core/model/portal/command/render/RenderPageCommand.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/core/model/portal/command/render/RenderPageCommand.java 2007-06-08
13:50:21 UTC (rev 7394)
+++
trunk/core/src/main/org/jboss/portal/core/model/portal/command/render/RenderPageCommand.java 2007-06-11
11:31:36 UTC (rev 7395)
@@ -25,8 +25,9 @@
import org.jboss.portal.common.invocation.InvocationException;
import org.jboss.portal.core.controller.ControllerContext;
import org.jboss.portal.core.controller.ControllerException;
-import org.jboss.portal.core.controller.ControllerSecurityException;
+import org.jboss.portal.core.controller.SecurityException;
import org.jboss.portal.core.controller.ControllerResponse;
+import org.jboss.portal.core.controller.NoSuchResourceException;
import org.jboss.portal.core.controller.command.info.CommandInfo;
import org.jboss.portal.core.controller.command.info.ViewCommandInfo;
import org.jboss.portal.core.model.portal.Page;
@@ -34,23 +35,21 @@
import org.jboss.portal.core.model.portal.PortalObjectPermission;
import org.jboss.portal.core.model.portal.Window;
import org.jboss.portal.core.model.portal.PortalObjectId;
-import org.jboss.portal.core.model.portal.PortalObjectPath;
+import org.jboss.portal.core.model.portal.content.WindowRendition;
+import org.jboss.portal.core.model.portal.command.response.MarkupResponse;
import org.jboss.portal.core.model.portal.command.PageCommand;
import org.jboss.portal.identity.User;
import org.jboss.portal.identity.UserProfileModule;
-import org.jboss.portal.security.PortalSecurityException;
import org.jboss.portal.security.spi.auth.PortalAuthorizationManager;
import org.jboss.portal.theme.LayoutService;
import org.jboss.portal.core.theme.PageRendition;
-import org.jboss.portal.core.theme.WindowRendition;
+import org.jboss.portal.core.theme.WindowContextFactory;
import org.jboss.portal.theme.PortalLayout;
import org.jboss.portal.theme.PortalTheme;
import org.jboss.portal.theme.ThemeConstants;
import org.jboss.portal.theme.PageService;
import org.jboss.portal.theme.ThemeService;
import org.jboss.portal.theme.page.PageResult;
-import org.jboss.portal.theme.page.WindowResult;
-import org.jboss.portal.theme.page.WindowContext;
import javax.naming.InitialContext;
import javax.naming.NamingException;
@@ -102,21 +101,21 @@
return windows;
}
- /**
- * initialize the command
- *
- * @throws InvocationException
- */
- public void create() throws ControllerException
+ public void acquireResources() throws NoSuchResourceException
{
- super.create();
+ super.acquireResources();
// All windows on the page
windows = new ArrayList(getPage().getChildren(PortalObject.WINDOW_MASK));
}
- public void enforceSecurity(PortalAuthorizationManager pam) throws
ControllerSecurityException, PortalSecurityException
+ protected Page initPage()
{
+ return (Page)getTarget();
+ }
+
+ public void enforceSecurity(PortalAuthorizationManager pam) throws SecurityException
+ {
//
super.enforceSecurity(pam);
@@ -183,6 +182,9 @@
// Call the portlet container to create the markup fragment(s) for each portlet
that needs to render itself
PageResult pageResult = new PageResult(getPage().getName(), new
HashMap(getPage().getProperties()));
+ // The window context factory
+ WindowContextFactory wcFactory = new WindowContextFactory(context);
+
// Render the windows
for (Iterator i = windows.iterator(); i.hasNext();)
{
@@ -190,42 +192,37 @@
if (o instanceof Window)
{
Window window = (Window)o;
- boolean visible = true;
- if (visible)
+ RenderWindowCommand renderCmd = new RenderWindowCommand(window.getId());
+
+ //
+ WindowRendition rendition = null;
+
+ //
+ if (renderCmd != null)
{
- RenderWindowCommand renderCmd = new
RenderWindowCommand(window.getId());
+ rendition = renderCmd.render(context);
+ }
- //
- ControllerResponse res = null;
+ // We ignore null result objects
+ if (rendition != null)
+ {
+ // Get the controller response
+ ControllerResponse response = rendition.getControllerResponse();
- //
- if (renderCmd != null)
+ // Null means we skip the window
+ if (response != null)
{
- res = context.execute(renderCmd);
+ if (response instanceof MarkupResponse)
+ {
+ // If this is a markup response we aggregate it
+ pageResult.addWindowContext(wcFactory.createWindowContext(window,
rendition));
+ }
+ else if (response != null)
+ {
+ // Otherwise we return it
+ return response;
+ }
}
-
- //
- if (res == null)
- {
- // Skip
- }
- else if (res instanceof WindowRendition)
- {
- WindowRendition rendition = (WindowRendition)res;
- WindowResult result = rendition.getWindow();
- String region =
window.getDeclaredProperty(ThemeConstants.PORTAL_PROP_REGION);
- String order =
window.getDeclaredProperty(ThemeConstants.PORTAL_PROP_ORDER);
- WindowContext wc = new WindowContext(
- window.getId().toString(PortalObjectPath.LEGACY_BASE64_FORMAT),
- region,
- order,
- result);
- pageResult.addWindowContext(wc);
- }
- else
- {
- return res;
- }
}
}
}
Modified:
trunk/core/src/main/org/jboss/portal/core/model/portal/command/render/RenderWindowCommand.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/core/model/portal/command/render/RenderWindowCommand.java 2007-06-08
13:50:21 UTC (rev 7394)
+++
trunk/core/src/main/org/jboss/portal/core/model/portal/command/render/RenderWindowCommand.java 2007-06-11
11:31:36 UTC (rev 7395)
@@ -24,10 +24,13 @@
import org.jboss.portal.core.controller.ControllerException;
import org.jboss.portal.core.controller.ControllerResponse;
+import org.jboss.portal.core.controller.ControllerContext;
import org.jboss.portal.core.controller.command.info.CommandInfo;
import org.jboss.portal.core.controller.command.info.ViewCommandInfo;
import org.jboss.portal.core.model.content.ContentType;
+import org.jboss.portal.core.model.portal.content.WindowRendition;
import org.jboss.portal.core.model.portal.PortalObjectId;
+import org.jboss.portal.core.model.portal.control.window.WindowControlContext;
import org.jboss.portal.core.model.portal.command.WindowCommand;
import org.jboss.portal.core.model.portal.content.ContentRenderer;
import org.jboss.portal.core.model.portal.content.ContentRendererRegistry;
@@ -40,29 +43,11 @@
{
/** . */
- public static final String WINDOW_ACCESS_DENIED =
"core.render.window_access_denied";
+ private static final CommandInfo info = new ViewCommandInfo();
/** . */
- public static final String WINDOW_UNAVAILABLE =
"core.render.window_unavailable";
+ private WindowRendition rendition;
- /** . */
- public static final String WINDOW_ERROR = "core.render.window_error";
-
- /** . */
- public static final String WINDOW_INTERNAL_ERROR =
"core.render.window_internal_error";
-
- /** . */
- public static final String WINDOW_NOT_FOUND =
"core.render.window_not_found";
-
- /** . */
- public static final String HIDE = "hide";
-
- /** . */
- public static final String SHOW = "show";
-
- /** . */
- private static final CommandInfo info = new ViewCommandInfo();
-
public RenderWindowCommand(PortalObjectId windowId)
throws IllegalArgumentException
{
@@ -74,8 +59,21 @@
return info;
}
+ /**
+ * Hack the command system.
+ *
+ */
+ public WindowRendition render(ControllerContext ctx) throws ControllerException
+ {
+ ctx.execute(this);
+
+ //
+ return rendition;
+ }
+
public ControllerResponse execute() throws ControllerException
{
+ // Find the appropriate content renderer
ContentRendererRegistry registry =
context.getController().getContentRendererRegistry();
ContentType contentType = window.getContentType();
ContentRenderer renderer = registry.getRenderer(contentType);
@@ -83,18 +81,21 @@
//
if (renderer == null)
{
- return null;
+ // Return the appropriate result
}
else
{
- try
+ rendition = renderer.renderWindow(this);
+
+ // Apply policy behavior here
+ if (rendition != null)
{
- return renderer.renderWindow(this);
+ WindowControlContext wcc = new WindowControlContext(context, targetId,
rendition);
+ context.getController().getWindowControlPolicy().doControl(wcc);
}
- catch (Exception e)
- {
- throw new ControllerException(e);
- }
}
+
+ //
+ return null;
}
}
Added:
trunk/core/src/main/org/jboss/portal/core/model/portal/command/response/MarkupResponse.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/core/model/portal/command/response/MarkupResponse.java
(rev 0)
+++
trunk/core/src/main/org/jboss/portal/core/model/portal/command/response/MarkupResponse.java 2007-06-11
11:31:36 UTC (rev 7395)
@@ -0,0 +1,69 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.core.model.portal.command.response;
+
+import org.jboss.portal.core.controller.ControllerResponse;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class MarkupResponse extends ControllerResponse
+{
+
+ /** . */
+ private final String title;
+
+ /** . */
+ private final String content;
+
+ /** . */
+ private final String headerContent;
+
+ public MarkupResponse(String title, String content, String headerContent)
+ {
+ this.title = title;
+ this.content = content;
+ this.headerContent = headerContent;
+ }
+
+ public String getTitle()
+ {
+ return title;
+ }
+
+ public String getContent()
+ {
+ return content;
+ }
+
+ public String getHeaderContent()
+ {
+ return headerContent;
+ }
+
+ public String toString()
+ {
+ return "MarkupResponse[]";
+ }
+}
Copied:
trunk/core/src/main/org/jboss/portal/core/model/portal/command/response/PortletWindowActionResponse.java
(from rev 7371,
trunk/core/src/main/org/jboss/portal/core/model/portal/command/response/PortletWindowResponse.java)
===================================================================
---
trunk/core/src/main/org/jboss/portal/core/model/portal/command/response/PortletWindowActionResponse.java
(rev 0)
+++
trunk/core/src/main/org/jboss/portal/core/model/portal/command/response/PortletWindowActionResponse.java 2007-06-11
11:31:36 UTC (rev 7395)
@@ -0,0 +1,56 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.core.model.portal.command.response;
+
+import org.jboss.portal.core.controller.portlet.PortletActionResponse;
+import org.jboss.portal.core.model.portal.PortalObjectId;
+import org.jboss.portal.portlet.StateString;
+import org.jboss.portal.WindowState;
+import org.jboss.portal.Mode;
+
+/**
+ * A portlet response related to a portal object window.
+ *
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class PortletWindowActionResponse extends PortletActionResponse
+{
+
+ /** The window id targetting the portlet. */
+ private PortalObjectId windowId;
+
+
+ public PortletWindowActionResponse(PortalObjectId windowId, WindowState windowState,
Mode mode, StateString contentState)
+ {
+ super(windowState, mode, contentState);
+
+ //
+ this.windowId = windowId;
+ }
+
+ public PortalObjectId getWindowId()
+ {
+ return windowId;
+ }
+}
Deleted:
trunk/core/src/main/org/jboss/portal/core/model/portal/command/response/PortletWindowResponse.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/core/model/portal/command/response/PortletWindowResponse.java 2007-06-08
13:50:21 UTC (rev 7394)
+++
trunk/core/src/main/org/jboss/portal/core/model/portal/command/response/PortletWindowResponse.java 2007-06-11
11:31:36 UTC (rev 7395)
@@ -1,59 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, and individual *
- * contributors as indicated by the @authors tag. See the *
- * copyright.txt in the distribution for a full listing of *
- * individual contributors. *
- * *
- * This is free software; you can redistribute it and/or modify it *
- * under the terms of the GNU Lesser General Public License as *
- * published by the Free Software Foundation; either version 2.1 of *
- * the License, or (at your option) any later version. *
- * *
- * This software is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this software; if not, write to the Free *
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
- ******************************************************************************/
-package org.jboss.portal.core.model.portal.command.response;
-
-import org.jboss.portal.core.controller.portlet.PortletResponse;
-import org.jboss.portal.core.model.portal.PortalObjectId;
-import org.jboss.portal.portlet.invocation.response.PortletInvocationResponse;
-
-/**
- * A portlet response related to a portal object window.
- *
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision: 1.1 $
- */
-public class PortletWindowResponse extends PortletResponse
-{
-
- /** The window id targetting the portlet. */
- private PortalObjectId windowId;
-
- public PortletWindowResponse(PortalObjectId windowId, PortletInvocationResponse
response)
- {
- super(response);
-
- //
- if (windowId == null)
- {
- throw new IllegalArgumentException();
- }
-
- //
- this.windowId = windowId;
- }
-
- public PortalObjectId getWindowId()
- {
- return windowId;
- }
-}
Modified:
trunk/core/src/main/org/jboss/portal/core/model/portal/command/view/ViewContextCommand.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/core/model/portal/command/view/ViewContextCommand.java 2007-06-08
13:50:21 UTC (rev 7394)
+++
trunk/core/src/main/org/jboss/portal/core/model/portal/command/view/ViewContextCommand.java 2007-06-11
11:31:36 UTC (rev 7395)
@@ -22,7 +22,6 @@
******************************************************************************/
package org.jboss.portal.core.model.portal.command.view;
-import org.jboss.portal.core.model.portal.command.PageCommand;
import org.jboss.portal.core.model.portal.command.ContextCommand;
import org.jboss.portal.core.model.portal.command.response.UpdatePageResponse;
import org.jboss.portal.core.model.portal.PortalObjectId;
@@ -32,9 +31,6 @@
import org.jboss.portal.core.controller.command.info.ViewCommandInfo;
import org.jboss.portal.core.controller.ControllerResponse;
import org.jboss.portal.core.controller.ControllerException;
-import org.jboss.portal.core.controller.ControllerSecurityException;
-import org.jboss.portal.security.spi.auth.PortalAuthorizationManager;
-import org.jboss.portal.security.PortalSecurityException;
import org.jboss.portal.identity.User;
/**
@@ -57,11 +53,6 @@
return info;
}
- public void enforceSecurity(PortalAuthorizationManager pam) throws
ControllerSecurityException, PortalSecurityException
- {
- super.enforceSecurity(pam);
- }
-
public ControllerResponse execute() throws ControllerException
{
if (isDashboard())
Modified:
trunk/core/src/main/org/jboss/portal/core/model/portal/command/view/ViewPageCommand.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/core/model/portal/command/view/ViewPageCommand.java 2007-06-08
13:50:21 UTC (rev 7394)
+++
trunk/core/src/main/org/jboss/portal/core/model/portal/command/view/ViewPageCommand.java 2007-06-11
11:31:36 UTC (rev 7395)
@@ -23,6 +23,7 @@
package org.jboss.portal.core.model.portal.command.view;
import org.jboss.portal.core.model.portal.PortalObjectId;
+import org.jboss.portal.core.model.portal.Page;
import org.jboss.portal.core.model.portal.command.response.UpdatePageResponse;
import org.jboss.portal.core.model.portal.command.PageCommand;
import org.jboss.portal.core.controller.command.info.CommandInfo;
@@ -45,6 +46,11 @@
super(pageId);
}
+ protected Page initPage()
+ {
+ return (Page)getTarget();
+ }
+
public CommandInfo getInfo()
{
return info;
Modified:
trunk/core/src/main/org/jboss/portal/core/model/portal/command/view/ViewPortalCommand.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/core/model/portal/command/view/ViewPortalCommand.java 2007-06-08
13:50:21 UTC (rev 7394)
+++
trunk/core/src/main/org/jboss/portal/core/model/portal/command/view/ViewPortalCommand.java 2007-06-11
11:31:36 UTC (rev 7395)
@@ -27,6 +27,7 @@
import org.jboss.portal.core.controller.command.info.CommandInfo;
import org.jboss.portal.core.controller.command.info.ViewCommandInfo;
import org.jboss.portal.core.model.portal.PortalObjectId;
+import org.jboss.portal.core.model.portal.Portal;
import org.jboss.portal.core.model.portal.command.PortalCommand;
import org.jboss.portal.core.model.portal.command.response.UpdatePageResponse;
@@ -50,6 +51,11 @@
return info;
}
+ protected Portal initPortal()
+ {
+ return (Portal)getTarget();
+ }
+
public ControllerResponse execute() throws ControllerException
{
if (portal.getDefaultPage() != null)
Modified:
trunk/core/src/main/org/jboss/portal/core/model/portal/content/ContentRenderer.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/core/model/portal/content/ContentRenderer.java 2007-06-08
13:50:21 UTC (rev 7394)
+++
trunk/core/src/main/org/jboss/portal/core/model/portal/content/ContentRenderer.java 2007-06-11
11:31:36 UTC (rev 7395)
@@ -23,7 +23,7 @@
package org.jboss.portal.core.model.portal.content;
import org.jboss.portal.core.model.portal.command.render.RenderWindowCommand;
-import org.jboss.portal.core.controller.ControllerResponse;
+import org.jboss.portal.core.model.portal.content.WindowRendition;
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
@@ -31,5 +31,5 @@
*/
public interface ContentRenderer
{
- ControllerResponse renderWindow(RenderWindowCommand cmd) throws Exception;
+ WindowRendition renderWindow(RenderWindowCommand cmd);
}
Added:
trunk/core/src/main/org/jboss/portal/core/model/portal/content/WindowRendition.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/core/model/portal/content/WindowRendition.java
(rev 0)
+++
trunk/core/src/main/org/jboss/portal/core/model/portal/content/WindowRendition.java 2007-06-11
11:31:36 UTC (rev 7395)
@@ -0,0 +1,119 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.core.model.portal.content;
+
+import org.jboss.portal.core.controller.ControllerResponse;
+import org.jboss.portal.WindowState;
+import org.jboss.portal.Mode;
+
+import java.util.Map;
+import java.util.List;
+
+/**
+ * Aggregates window specific data and a controller response.
+ *
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class WindowRendition
+{
+
+ /** The window properties. */
+ private final Map properties;
+
+ /** The window state. */
+ private final WindowState windowState;
+
+ /** The window mode. */
+ private final Mode mode;
+
+ /** The supported window states. */
+ private List supportedWindowStates;
+
+ /** The supported modes. */
+ private List supportedModes;
+
+ /** The controller response. */
+ private ControllerResponse controllerResponse;
+
+ public WindowRendition(Map properties, WindowState windowState, Mode mode, List
supportedWindowStates, List supportedModes, ControllerResponse controllerResponse)
+ {
+ if (controllerResponse == null)
+ {
+ throw new IllegalArgumentException("Null controller response not
accepted");
+ }
+
+ //
+ this.properties = properties;
+ this.windowState = windowState;
+ this.mode = mode;
+ this.supportedWindowStates = supportedWindowStates;
+ this.supportedModes = supportedModes;
+ this.controllerResponse = controllerResponse;
+ }
+
+ public Map getProperties()
+ {
+ return properties;
+ }
+
+ public WindowState getWindowState()
+ {
+ return windowState;
+ }
+
+ public Mode getMode()
+ {
+ return mode;
+ }
+
+ public List getSupportedWindowStates()
+ {
+ return supportedWindowStates;
+ }
+
+ public void setSupportedWindowStates(List supportedWindowStates)
+ {
+ this.supportedWindowStates = supportedWindowStates;
+ }
+
+ public List getSupportedModes()
+ {
+ return supportedModes;
+ }
+
+ public void setSupportedModes(List supportedModes)
+ {
+ this.supportedModes = supportedModes;
+ }
+
+ public ControllerResponse getControllerResponse()
+ {
+ return controllerResponse;
+ }
+
+ public void setControllerResponse(ControllerResponse controllerResponse)
+ {
+ this.controllerResponse = controllerResponse;
+ }
+}
Added:
trunk/core/src/main/org/jboss/portal/core/model/portal/control/ControlConstants.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/core/model/portal/control/ControlConstants.java
(rev 0)
+++
trunk/core/src/main/org/jboss/portal/core/model/portal/control/ControlConstants.java 2007-06-11
11:31:36 UTC (rev 7395)
@@ -0,0 +1,105 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.core.model.portal.control;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class ControlConstants
+{
+
+ private ControlConstants()
+ {
+ }
+
+ /** . */
+ public static final String AGGREGATION_ACCESS_DENIED_CONTROL_KEY =
"control.aggregation.access_denied";
+
+ /** . */
+ public static final String AGGREGATION_UNAVAILABLE_CONTROL_KEY =
"control.aggregation.unavailable";
+
+ /** . */
+ public static final String AGGREGATION_ERROR_CONTROL_KEY =
"control.aggregation.error";
+
+ /** . */
+ public static final String AGGREGATION_INTERNAL_ERROR_CONTROL_KEY =
"control.aggregation.internal_error";
+
+ /** . */
+ public static final String AGGREGATION_NOT_FOUND_CONTROL_KEY =
"control.aggregation.not_found";
+
+ /** . */
+ public static final String AGGREGATION_RESOURCE_URI_CONTROL_KEY =
"control.aggregation.resource_uri";
+
+ /** . */
+ public static final String GLOBAL_ACCESS_DENIED_CONTROL_KEY =
"control.access_denied";
+
+ /** . */
+ public static final String GLOBAL_UNAVAILABLE_CONTROL_KEY =
"control.unavailable";
+
+ /** . */
+ public static final String GLOBAL_ERROR_CONTROL_KEY = "control.error";
+
+ /** . */
+ public static final String GLOBAL_INTERNAL_ERROR_CONTROL_KEY =
"control.internal_error";
+
+ /** . */
+ public static final String GLOBAL_NOT_FOUND_CONTROL_KEY =
"control.not_found";
+
+ /** . */
+ public static final String GLOBAL_RESOURCE_URI_CONTROL_KEY =
"control.resource_uri";
+
+ /** . */
+ public static final String HIDE_CONTROL_VALUE = "hide";
+
+ /** . */
+ public static final String SHOW_CONTROL_VALUE = "show";
+
+ /** . */
+ public static final String JSP_CONTROL_VALUE = "jsp";
+
+ /** . */
+ public static final String ERROR_TYPE_ATTRIBUTE =
"org.jboss.portal.control.ERROR_TYPE";
+
+ /** . */
+ public static final String CAUSE_ATTRIBUTE =
"org.jboss.portal.control.CAUSE";
+
+ /** . */
+ public static final String MESSAGE_ATTRIBUTE =
"org.jboss.portal.control.MESSAGE";
+
+ /** . */
+ public static final String ACCESS_DENIED_ERROR_TYPE = "ACCESS_DENIED";
+
+ /** . */
+ public static final String UNAVAILABLE_ERROR_TYPE = "UNAVAILABLE";
+
+ /** . */
+ public static final String ERROR_ERROR_TYPE = "ERROR";
+
+ /** . */
+ public static final String INTERNAL_ERROR_ERROR_TYPE = "INTERNAL_ERROR";
+
+ /** . */
+ public static final String NOT_FOUND_ERROR_TYPE = "NOT_FOUND";
+
+}
Added: trunk/core/src/main/org/jboss/portal/core/model/portal/control/ControlContext.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/core/model/portal/control/ControlContext.java
(rev 0)
+++
trunk/core/src/main/org/jboss/portal/core/model/portal/control/ControlContext.java 2007-06-11
11:31:36 UTC (rev 7395)
@@ -0,0 +1,46 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.core.model.portal.control;
+
+import org.jboss.portal.core.controller.ControllerContext;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class ControlContext
+{
+
+ /** . */
+ private final ControllerContext controllerContext;
+
+ public ControlContext(ControllerContext controllerContext)
+ {
+ this.controllerContext = controllerContext;
+ }
+
+ public ControllerContext getControllerContext()
+ {
+ return controllerContext;
+ }
+}
Added:
trunk/core/src/main/org/jboss/portal/core/model/portal/control/portal/DefaultPortalControlPolicy.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/core/model/portal/control/portal/DefaultPortalControlPolicy.java
(rev 0)
+++
trunk/core/src/main/org/jboss/portal/core/model/portal/control/portal/DefaultPortalControlPolicy.java 2007-06-11
11:31:36 UTC (rev 7395)
@@ -0,0 +1,189 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.core.model.portal.control.portal;
+
+import org.jboss.portal.core.model.portal.control.ControlConstants;
+import org.jboss.portal.core.model.portal.PortalObjectContainer;
+import org.jboss.portal.core.model.portal.PortalObject;
+import org.jboss.portal.core.controller.command.response.UnavailableResourceResponse;
+import org.jboss.portal.core.controller.command.response.SecurityErrorResponse;
+import org.jboss.portal.core.controller.command.response.ErrorResponse;
+import org.jboss.portal.core.controller.ControllerResponse;
+import org.jboss.portal.core.controller.ControllerContext;
+import org.jboss.portal.core.controller.ControllerRequestDispatcher;
+import org.jboss.portal.core.theme.PageRendition;
+import org.jboss.portal.theme.PageService;
+import org.jboss.portal.theme.LayoutService;
+import org.jboss.portal.theme.PortalLayout;
+import org.jboss.portal.theme.ThemeConstants;
+import org.jboss.portal.theme.page.PageResult;
+import org.jboss.portal.theme.page.WindowResult;
+import org.jboss.portal.theme.page.WindowContext;
+import org.jboss.portal.WindowState;
+import org.jboss.portal.Mode;
+import org.jboss.logging.Logger;
+
+import java.util.Map;
+import java.util.HashMap;
+import java.util.Collections;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class DefaultPortalControlPolicy implements PortalControlPolicy
+{
+
+ /** . */
+ private static final Logger log = Logger.getLogger(DefaultPortalControlPolicy.class);
+
+ /** . */
+ private static final Map errorTypeMapping = new HashMap();
+
+ static
+ {
+ errorTypeMapping.put(ControlConstants.GLOBAL_ACCESS_DENIED_CONTROL_KEY,
ControlConstants.ACCESS_DENIED_ERROR_TYPE);
+ errorTypeMapping.put(ControlConstants.GLOBAL_ERROR_CONTROL_KEY,
ControlConstants.ERROR_ERROR_TYPE);
+ errorTypeMapping.put(ControlConstants.GLOBAL_INTERNAL_ERROR_CONTROL_KEY,
ControlConstants.INTERNAL_ERROR_ERROR_TYPE);
+ errorTypeMapping.put(ControlConstants.GLOBAL_UNAVAILABLE_CONTROL_KEY,
ControlConstants.UNAVAILABLE_ERROR_TYPE);
+ errorTypeMapping.put(ControlConstants.GLOBAL_NOT_FOUND_CONTROL_KEY,
ControlConstants.NOT_FOUND_ERROR_TYPE);
+ }
+
+ /** . */
+ private PortalObjectContainer portalObjectContainer;
+
+ public PortalObjectContainer getPortalObjectContainer()
+ {
+ return portalObjectContainer;
+ }
+
+ public void setPortalObjectContainer(PortalObjectContainer portalObjectContainer)
+ {
+ this.portalObjectContainer = portalObjectContainer;
+ }
+
+ public void doControl(PortalControlContext controlContext)
+ {
+
+ ControllerResponse response = controlContext.getResponse();
+
+ //
+ String policyKey = null;
+ Throwable cause = null;
+ String message = null;
+
+ //
+ if (response instanceof ErrorResponse)
+ {
+ ErrorResponse error = (ErrorResponse)response;
+ cause = error.getCause();
+ message = error.getMessage();
+
+ //
+ if (response instanceof SecurityErrorResponse)
+ {
+ SecurityErrorResponse ser = (SecurityErrorResponse)response;
+
+ //
+ if (ser.getStatus() == SecurityErrorResponse.NOT_AUTHORIZED)
+ {
+ policyKey = ControlConstants.GLOBAL_ACCESS_DENIED_CONTROL_KEY;
+ }
+ }
+ else
+ {
+ policyKey = error.isInternal() ?
ControlConstants.GLOBAL_INTERNAL_ERROR_CONTROL_KEY :
ControlConstants.GLOBAL_ERROR_CONTROL_KEY;
+ }
+ }
+ else if (response instanceof UnavailableResourceResponse)
+ {
+ UnavailableResourceResponse unavailable =
(UnavailableResourceResponse)response;
+
+ //
+ policyKey = unavailable.isLocated() ?
ControlConstants.GLOBAL_UNAVAILABLE_CONTROL_KEY :
ControlConstants.GLOBAL_NOT_FOUND_CONTROL_KEY;
+ }
+
+ //
+ if (cause != null)
+ {
+ log.error("Rendering portlet window " + "" + " produced
an error", cause);
+ }
+
+ //
+ String policyValue;
+ if (policyKey != null)
+ {
+ PortalObject object =
portalObjectContainer.getObject(controlContext.getPortalId());
+ if (object != null)
+ {
+ policyValue = object.getProperty(policyKey);
+
+ if (policyValue != null)
+ {
+ if (ControlConstants.JSP_CONTROL_VALUE.equals(policyValue))
+ {
+ String resourceURI =
object.getProperty(ControlConstants.AGGREGATION_RESOURCE_URI_CONTROL_KEY);
+ if (resourceURI != null)
+ {
+ ControllerContext controllerCtx =
controlContext.getControllerContext();
+ ControllerRequestDispatcher rd =
controllerCtx.getRequestDispatcher("/portal-core", resourceURI);
+ if (rd != null)
+ {
+ String errorType = (String)errorTypeMapping.get(policyKey);
+ rd.setAttribute(ControlConstants.ERROR_TYPE_ATTRIBUTE,
errorType);
+ rd.setAttribute(ControlConstants.CAUSE_ATTRIBUTE, cause);
+ rd.setAttribute(ControlConstants.MESSAGE_ATTRIBUTE, message);
+
+ //
+ rd.include();
+
+ //
+ PageService ps =
controlContext.getControllerContext().getController().getPageService();
+ LayoutService ls = ps.getLayoutService();
+ PortalLayout layout = ls.getLayout("generic", true);
+ Map pageProperties = new HashMap();
+ pageProperties.put("theme.renderSetId",
"divRenderer");
+ pageProperties.put("theme.id",
"renaissance");
+ PageResult result = new PageResult("BILTO",
pageProperties);
+
+ //
+ Map windowProps = new HashMap();
+ windowProps.put(ThemeConstants.PORTAL_PROP_WINDOW_RENDERER,
"emptyRenderer");
+ windowProps.put(ThemeConstants.PORTAL_PROP_DECORATION_RENDERER,
"emptyRenderer");
+ windowProps.put(ThemeConstants.PORTAL_PROP_PORTLET_RENDERER,
"emptyRenderer");
+
+ //
+ WindowResult res = new WindowResult("", rd.getMarkup(),
Collections.EMPTY_MAP, windowProps, "", WindowState.MAXIMIZED, Mode.VIEW);
+ WindowContext blah = new WindowContext("BILTO",
"maximized", "0", res);
+ result.addWindowContext(blah);
+
+ //
+ controlContext.setResponse(new PageRendition(layout, null,
result, ps));
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+}
Added:
trunk/core/src/main/org/jboss/portal/core/model/portal/control/portal/PortalControlContext.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/core/model/portal/control/portal/PortalControlContext.java
(rev 0)
+++
trunk/core/src/main/org/jboss/portal/core/model/portal/control/portal/PortalControlContext.java 2007-06-11
11:31:36 UTC (rev 7395)
@@ -0,0 +1,66 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.core.model.portal.control.portal;
+
+import org.jboss.portal.core.model.portal.PortalObjectId;
+import org.jboss.portal.core.model.portal.control.ControlContext;
+import org.jboss.portal.core.controller.ControllerResponse;
+import org.jboss.portal.core.controller.ControllerContext;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class PortalControlContext extends ControlContext
+{
+
+ /** The active portal id. */
+ private PortalObjectId portalId;
+
+ /** The controller response. */
+ private ControllerResponse response;
+
+ public PortalControlContext(ControllerContext controllerContext, PortalObjectId
portalId, ControllerResponse response)
+ {
+ super(controllerContext);
+
+ //
+ this.portalId = portalId;
+ this.response = response;
+ }
+
+ public PortalObjectId getPortalId()
+ {
+ return portalId;
+ }
+
+ public ControllerResponse getResponse()
+ {
+ return response;
+ }
+
+ public void setResponse(ControllerResponse response)
+ {
+ this.response = response;
+ }
+}
Added:
trunk/core/src/main/org/jboss/portal/core/model/portal/control/portal/PortalControlPolicy.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/core/model/portal/control/portal/PortalControlPolicy.java
(rev 0)
+++
trunk/core/src/main/org/jboss/portal/core/model/portal/control/portal/PortalControlPolicy.java 2007-06-11
11:31:36 UTC (rev 7395)
@@ -0,0 +1,32 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.core.model.portal.control.portal;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public interface PortalControlPolicy
+{
+ void doControl(PortalControlContext controlContext);
+}
Added:
trunk/core/src/main/org/jboss/portal/core/model/portal/control/window/DefaultWindowControlPolicy.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/core/model/portal/control/window/DefaultWindowControlPolicy.java
(rev 0)
+++
trunk/core/src/main/org/jboss/portal/core/model/portal/control/window/DefaultWindowControlPolicy.java 2007-06-11
11:31:36 UTC (rev 7395)
@@ -0,0 +1,194 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.core.model.portal.control.window;
+
+import org.jboss.logging.Logger;
+import org.jboss.portal.server.config.ServerConfig;
+import org.jboss.portal.core.controller.ControllerResponse;
+import org.jboss.portal.core.controller.ControllerContext;
+import org.jboss.portal.core.controller.ControllerRequestDispatcher;
+import org.jboss.portal.core.controller.command.response.ErrorResponse;
+import org.jboss.portal.core.controller.command.response.SecurityErrorResponse;
+import org.jboss.portal.core.controller.command.response.UnavailableResourceResponse;
+import org.jboss.portal.core.model.portal.command.response.MarkupResponse;
+import org.jboss.portal.core.model.portal.content.WindowRendition;
+import org.jboss.portal.core.model.portal.control.ControlConstants;
+import org.jboss.portal.core.model.portal.PortalObjectContainer;
+
+import java.util.Collections;
+import java.util.Map;
+import java.util.HashMap;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class DefaultWindowControlPolicy implements WindowControlPolicy
+{
+
+ /** . */
+ private static final Logger log = Logger.getLogger(DefaultWindowControlPolicy.class);
+
+ /** . */
+ private static final Map errorTypeMapping = new HashMap();
+
+ static
+ {
+ errorTypeMapping.put(ControlConstants.AGGREGATION_ACCESS_DENIED_CONTROL_KEY,
ControlConstants.ACCESS_DENIED_ERROR_TYPE);
+ errorTypeMapping.put(ControlConstants.AGGREGATION_ERROR_CONTROL_KEY,
ControlConstants.ERROR_ERROR_TYPE);
+ errorTypeMapping.put(ControlConstants.AGGREGATION_INTERNAL_ERROR_CONTROL_KEY,
ControlConstants.INTERNAL_ERROR_ERROR_TYPE);
+ errorTypeMapping.put(ControlConstants.AGGREGATION_UNAVAILABLE_CONTROL_KEY,
ControlConstants.UNAVAILABLE_ERROR_TYPE);
+ errorTypeMapping.put(ControlConstants.AGGREGATION_NOT_FOUND_CONTROL_KEY,
ControlConstants.NOT_FOUND_ERROR_TYPE);
+ }
+
+ /** . */
+ private ServerConfig serverConfig;
+
+ /** . */
+ private PortalObjectContainer portalObjectContainer;
+
+ public ServerConfig getServerConfig()
+ {
+ return serverConfig;
+ }
+
+ public void setServerConfig(ServerConfig serverConfig)
+ {
+ this.serverConfig = serverConfig;
+ }
+
+ public PortalObjectContainer getPortalObjectContainer()
+ {
+ return portalObjectContainer;
+ }
+
+ public void setPortalObjectContainer(PortalObjectContainer portalObjectContainer)
+ {
+ this.portalObjectContainer = portalObjectContainer;
+ }
+
+ public void doControl(WindowControlContext controlContext)
+ {
+ WindowRendition rendition = controlContext.getRendition();
+
+ //
+ ControllerResponse response = rendition.getControllerResponse();
+
+ //
+ String policyKey = null;
+ Throwable cause = null;
+ String message = null;
+
+ //
+ if (response instanceof ErrorResponse)
+ {
+ ErrorResponse error = (ErrorResponse)response;
+ cause = error.getCause();
+ message = error.getMessage();
+
+ //
+ if (response instanceof SecurityErrorResponse)
+ {
+ SecurityErrorResponse ser = (SecurityErrorResponse)response;
+
+ //
+ if (ser.getStatus() == SecurityErrorResponse.NOT_AUTHORIZED)
+ {
+ policyKey = ControlConstants.AGGREGATION_ACCESS_DENIED_CONTROL_KEY;
+ }
+ }
+ else
+ {
+ policyKey = error.isInternal() ?
ControlConstants.AGGREGATION_INTERNAL_ERROR_CONTROL_KEY :
ControlConstants.AGGREGATION_ERROR_CONTROL_KEY;
+ }
+ }
+ else if (response instanceof UnavailableResourceResponse)
+ {
+ UnavailableResourceResponse unavailable =
(UnavailableResourceResponse)response;
+
+ //
+ if (log.isTraceEnabled())
+ {
+ log.trace("Window not found " + unavailable.getRef());
+ }
+
+ policyKey = unavailable.isLocated() ?
ControlConstants.AGGREGATION_UNAVAILABLE_CONTROL_KEY :
ControlConstants.AGGREGATION_NOT_FOUND_CONTROL_KEY;
+ }
+
+ //
+ if (cause != null)
+ {
+ log.error("Rendering portlet window " + "" + " produced
an error", cause);
+ }
+
+ //
+ if (policyKey != null)
+ {
+ Map properties = controlContext.getRendition().getProperties();
+
+ //
+ String policyValue = (String)properties.get(policyKey);
+
+ //
+ if (policyValue != null)
+ {
+ if (ControlConstants.HIDE_CONTROL_VALUE.equals(policyValue))
+ {
+ rendition.setControllerResponse(null);
+ }
+ else if (ControlConstants.SHOW_CONTROL_VALUE.equals(policyValue))
+ {
+ rendition.setSupportedWindowStates(Collections.EMPTY_LIST);
+ rendition.setSupportedModes(Collections.EMPTY_LIST);
+ rendition.setControllerResponse(new MarkupResponse(response.toString(),
response.toString(), null));
+ }
+ else if (ControlConstants.JSP_CONTROL_VALUE.equals(policyValue))
+ {
+ String resourceURI =
(String)properties.get(ControlConstants.GLOBAL_RESOURCE_URI_CONTROL_KEY);
+ if (resourceURI != null)
+ {
+ ControllerContext controllerCtx =
controlContext.getControllerContext();
+ ControllerRequestDispatcher rd =
controllerCtx.getRequestDispatcher("/portal-core", resourceURI);
+ if (rd != null)
+ {
+ String errorType = (String)errorTypeMapping.get(policyKey);
+ rd.setAttribute(ControlConstants.ERROR_TYPE_ATTRIBUTE, errorType);
+ rd.setAttribute(ControlConstants.CAUSE_ATTRIBUTE, cause);
+ rd.setAttribute(ControlConstants.MESSAGE_ATTRIBUTE, message);
+
+ //
+ rd.include();
+
+ //
+ String markup = rd.getMarkup();
+ rendition.setSupportedWindowStates(Collections.EMPTY_LIST);
+ rendition.setSupportedModes(Collections.EMPTY_LIST);
+ rendition.setControllerResponse(new MarkupResponse("An error
occured", markup, null));
+ }
+ }
+ }
+ }
+ }
+ }
+
+}
Added:
trunk/core/src/main/org/jboss/portal/core/model/portal/control/window/WindowControlContext.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/core/model/portal/control/window/WindowControlContext.java
(rev 0)
+++
trunk/core/src/main/org/jboss/portal/core/model/portal/control/window/WindowControlContext.java 2007-06-11
11:31:36 UTC (rev 7395)
@@ -0,0 +1,60 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.core.model.portal.control.window;
+
+import org.jboss.portal.core.model.portal.PortalObjectId;
+import org.jboss.portal.core.model.portal.control.ControlContext;
+import org.jboss.portal.core.model.portal.content.WindowRendition;
+import org.jboss.portal.core.controller.ControllerContext;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class WindowControlContext extends ControlContext
+{
+
+ /** . */
+ private final PortalObjectId windowId;
+
+ /** . */
+ private final WindowRendition rendition;
+
+
+ public WindowControlContext(ControllerContext controllerContext, PortalObjectId
windowId, WindowRendition rendition)
+ {
+ super(controllerContext);
+ this.windowId = windowId;
+ this.rendition = rendition;
+ }
+
+ public PortalObjectId getWindowId()
+ {
+ return windowId;
+ }
+
+ public WindowRendition getRendition()
+ {
+ return rendition;
+ }
+}
Added:
trunk/core/src/main/org/jboss/portal/core/model/portal/control/window/WindowControlPolicy.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/core/model/portal/control/window/WindowControlPolicy.java
(rev 0)
+++
trunk/core/src/main/org/jboss/portal/core/model/portal/control/window/WindowControlPolicy.java 2007-06-11
11:31:36 UTC (rev 7395)
@@ -0,0 +1,34 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.core.model.portal.control.window;
+
+/**
+ * Policy that controls the behavior of a portal window.
+ *
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public interface WindowControlPolicy
+{
+ void doControl(WindowControlContext controlContext);
+}
Modified:
trunk/core/src/main/org/jboss/portal/core/model/portal/navstate/WindowNavigationalState.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/core/model/portal/navstate/WindowNavigationalState.java 2007-06-08
13:50:21 UTC (rev 7394)
+++
trunk/core/src/main/org/jboss/portal/core/model/portal/navstate/WindowNavigationalState.java 2007-06-11
11:31:36 UTC (rev 7395)
@@ -47,26 +47,26 @@
private final Mode mode;
/** . */
- private final StateString state;
+ private final StateString contentState;
public static WindowNavigationalState create()
{
return DEFAULT;
}
- public WindowNavigationalState(WindowState windowState, Mode mode, StateString
navigationalState)
+ public WindowNavigationalState(WindowState windowState, Mode mode, StateString
contentState)
{
if (windowState == null)
{
- throw new IllegalArgumentException();
+ throw new IllegalArgumentException("No null window state accepted");
}
- if (windowState == null)
+ if (mode == null)
{
- throw new IllegalArgumentException();
+ throw new IllegalArgumentException("No null mode accepted");
}
this.windowState = windowState;
this.mode = mode;
- this.state = navigationalState;
+ this.contentState = contentState;
}
private WindowNavigationalState()
@@ -84,9 +84,9 @@
return mode;
}
- public StateString getState()
+ public StateString getContentState()
{
- return state;
+ return contentState;
}
public static WindowState getWindowState(AttributeResolver resolver, Object id)
@@ -130,7 +130,7 @@
}
else
{
- wns = new WindowNavigationalState(windowState, wns.getMode(), wns.getState());
+ wns = new WindowNavigationalState(windowState, wns.getMode(),
wns.getContentState());
}
//
@@ -178,7 +178,7 @@
}
else
{
- wns = new WindowNavigationalState(wns.getWindowState(), mode, wns.getState());
+ wns = new WindowNavigationalState(wns.getWindowState(), mode,
wns.getContentState());
}
//
@@ -193,7 +193,7 @@
WindowNavigationalState wns = (WindowNavigationalState)resolver.getAttribute(key);
//
- return wns != null ? wns.getState() : null;
+ return wns != null ? wns.getContentState() : null;
}
public static void setState(AttributeResolver resolver, Object id, StateString state)
@@ -232,4 +232,32 @@
//
resolver.setAttribute(key, wns);
}
+
+ public static WindowNavigationalState bilto(WindowNavigationalState oldNS, WindowState
windowState, Mode mode, StateString contentState)
+ {
+ StateString newState = oldNS != null ? oldNS.getContentState() : null;
+ WindowState newWindowState = oldNS != null ? oldNS.getWindowState() :
WindowState.NORMAL;
+ Mode newMode = oldNS != null ? oldNS.getMode() : Mode.VIEW;
+
+ //
+ if (contentState != null)
+ {
+ newState = contentState;
+ }
+
+ //
+ if (mode != null)
+ {
+ newMode = mode;
+ }
+
+ //
+ if (windowState != null)
+ {
+ newWindowState = windowState;
+ }
+
+ // Create new NS
+ return new WindowNavigationalState(newWindowState, newMode, newState);
+ }
}
Deleted: trunk/core/src/main/org/jboss/portal/core/portlet/PortletHelper.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/core/portlet/PortletHelper.java 2007-06-08
13:50:21 UTC (rev 7394)
+++ trunk/core/src/main/org/jboss/portal/core/portlet/PortletHelper.java 2007-06-11
11:31:36 UTC (rev 7395)
@@ -1,71 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, and individual *
- * contributors as indicated by the @authors tag. See the *
- * copyright.txt in the distribution for a full listing of *
- * individual contributors. *
- * *
- * This is free software; you can redistribute it and/or modify it *
- * under the terms of the GNU Lesser General Public License as *
- * published by the Free Software Foundation; either version 2.1 of *
- * the License, or (at your option) any later version. *
- * *
- * This software is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this software; if not, write to the Free *
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
- ******************************************************************************/
-package org.jboss.portal.core.portlet;
-
-import org.jboss.logging.Logger;
-import org.jboss.portal.core.servlet.jsp.PortalJsp;
-import org.jboss.portlet.JBossActionRequest;
-import org.jboss.portlet.JBossActionResponse;
-import org.jboss.portlet.JBossPortlet;
-
-import java.util.Locale;
-import java.util.ResourceBundle;
-
-/** @author <a href="theute(a)jboss.org">Thomas Heute </a> $Revision$
*/
-public class PortletHelper
-{
- private Logger log = Logger.getLogger(PortalJsp.class);
-
- private JBossPortlet portlet;
-
- public PortletHelper(JBossPortlet portlet)
- {
- this.portlet = portlet;
- }
-
- public void setRenderParameter(JBossActionResponse resp, String key, String value)
- {
- if (value != null)
- {
- resp.setRenderParameter(key, value);
- }
- }
-
- public void setI18nRenderParameter(JBossActionRequest req, JBossActionResponse resp,
String key, String value)
- {
- if (value != null)
- {
- Locale locale = req.getLocale();
- ResourceBundle bundle = portlet.getResourceBundle(locale);
- try
- {
- resp.setRenderParameter(key, bundle.getString(value));
- }
- catch (Exception e)
- {
- log.error("Cannot find language key: " + key);
- resp.setRenderParameter(key, value);
- }
- }
- }
-}
\ No newline at end of file
Deleted: trunk/core/src/main/org/jboss/portal/core/portlet/catalog/CatalogPortlet.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/core/portlet/catalog/CatalogPortlet.java 2007-06-08
13:50:21 UTC (rev 7394)
+++
trunk/core/src/main/org/jboss/portal/core/portlet/catalog/CatalogPortlet.java 2007-06-11
11:31:36 UTC (rev 7395)
@@ -1,201 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, and individual *
- * contributors as indicated by the @authors tag. See the *
- * copyright.txt in the distribution for a full listing of *
- * individual contributors. *
- * *
- * This is free software; you can redistribute it and/or modify it *
- * under the terms of the GNU Lesser General Public License as *
- * published by the Free Software Foundation; either version 2.1 of *
- * the License, or (at your option) any later version. *
- * *
- * This software is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this software; if not, write to the Free *
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
- ******************************************************************************/
-package org.jboss.portal.core.portlet.catalog;
-
-import org.jboss.portal.api.node.PortalNode;
-import org.jboss.portal.api.node.PortalNodeURL;
-import org.jboss.portal.core.impl.api.node.PortalNodeImpl;
-import org.jboss.portal.core.model.portal.PortalObjectPermission;
-import org.jboss.portal.security.spi.auth.PortalAuthorizationManagerFactory;
-import org.jboss.portlet.JBossPortlet;
-import org.jboss.portlet.JBossRenderRequest;
-import org.jboss.portlet.JBossRenderResponse;
-
-import javax.portlet.PortletException;
-import javax.portlet.PortletRequestDispatcher;
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Locale;
-import java.util.MissingResourceException;
-import java.util.ResourceBundle;
-
-/**
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @author <a href="mailto:theute@jboss.org">Thomas Heute</a>
- * @version $Revision$
- */
-public class CatalogPortlet
- extends JBossPortlet
-{
- /** . */
- private static final String RESOURCE_PREFIX = "PAGENAME_";
-
- private PortalAuthorizationManagerFactory portalAuthorizationManagerFactory;
-
- public void init() throws PortletException
- {
- portalAuthorizationManagerFactory = (PortalAuthorizationManagerFactory)
getPortletContext().getAttribute("PortalAuthorizationManagerFactory");
-
- if(portalAuthorizationManagerFactory == null)
- {
- throw new PortletException("No portal authorization manager
factory");
- }
- }
-
- public void destroy()
- {
- super.destroy();
-
- portalAuthorizationManagerFactory = null;
- }
-
- public void render(JBossRenderRequest req, JBossRenderResponse resp) throws
IOException
- {
- resp.setContentType("text/html");
-
- PortalNode current = req.getPortalNode();
-// WindowState ws = req.getWindowState();
-// if(WindowState.MAXIMIZED.equals(ws))
-// {
-// resp.setTitle("Sitemap");
-// PortalNode parent = current.getParent();
-// req.setAttribute("parentNode", parent);
-// try
-// {
-// PortletRequestDispatcher prd =
getPortletContext().getRequestDispatcher("/WEB-INF/jsp/catalog/sitemap.jsp");
-// prd.include(req, resp);
-// }
-// catch(Exception e)
-// {
-// e.printStackTrace();
-// }
-// }
-// else
-// {
- resp.setTitle("Pages");
- PortalNode parent = current.getParent();
-
- HashMap parentsMap = new HashMap();
- PortalNode node = parent.getParent();
- while (node.getType() != PortalNode.TYPE_PORTAL)
- {
- parentsMap.put(localize(req.getLocale(), node.getName()),
resp.createRenderURL(node));
- node = node.getParent();
- }
- req.setAttribute("parents", parentsMap);
-
- try
- {
- req.setAttribute("parentNode", localize(req.getLocale(),
parent.getName()));
-
- HashMap parentChildMap = new HashMap();
- HashMap parentSiblingMap = new HashMap();
- for (Iterator i = parent.getParent().getChildren().iterator(); i.hasNext();)
- {
- PortalNode parentSibling = (PortalNode)i.next();
-
- // Display only sibling pages
- if (parentSibling.getType() == PortalNode.TYPE_PAGE)
- {
- if (parentSibling.equals(parent))
- {
- for (Iterator j = parent.getChildren().iterator(); j.hasNext();)
- {
- PortalNode child = (PortalNode)j.next();
- if (child.getType() == PortalNode.TYPE_PAGE)
- {
- boolean allowed = false;
- // check if the current user is allowed to access this page
- if (child instanceof PortalNodeImpl)
- {
- PortalNodeImpl pn = (PortalNodeImpl)child;
- PortalObjectPermission perm = new
PortalObjectPermission(pn.getObjectId(), PortalObjectPermission.VIEW_MASK);
- if
(portalAuthorizationManagerFactory.getManager().checkPermission(perm))
- {
- allowed = true;
- }
- else
- {
- allowed = false;
- }
- }
- if (allowed)
- {
- PortalNodeURL childURL = resp.createRenderURL(child);
- parentChildMap.put(localize(req.getLocale(), child.getName()),
childURL);
- }
- }
- }
- }
- else
- {
- boolean allowed = false;
- // check if the current user is allowed to access this page
- if (parentSibling instanceof PortalNodeImpl)
- {
- PortalNodeImpl pn = (PortalNodeImpl)parentSibling;
- PortalObjectPermission perm = new
PortalObjectPermission(pn.getObjectId(), PortalObjectPermission.VIEW_MASK);
- if
(portalAuthorizationManagerFactory.getManager().checkPermission(perm))
- {
- allowed = true;
- }
- else
- {
- allowed = false;
- }
- }
- if (allowed)
- {
- PortalNodeURL parentSiblingURL =
resp.createRenderURL(parentSibling);
- parentSiblingMap.put(localize(req.getLocale(),
parentSibling.getName()), parentSiblingURL);
- }
- }
- }
- }
- req.setAttribute("pchild", parentChildMap);
- req.setAttribute("psib", parentSiblingMap);
-
- PortletRequestDispatcher prd =
getPortletContext().getRequestDispatcher("/WEB-INF/jsp/catalog/index.jsp");
- prd.include(req, resp);
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
-// }
- }
-
- private String localize(Locale locale, String name)
- {
- try
- {
- ResourceBundle rb = ResourceBundle.getBundle("conf.bundles.Resource",
locale, Thread.currentThread().getContextClassLoader());
- name = rb.getString(RESOURCE_PREFIX + name);
- }
- catch (MissingResourceException e)
- {
- }
- return name;
- }
-}
Deleted: trunk/core/src/main/org/jboss/portal/core/portlet/role/RolePortlet.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/core/portlet/role/RolePortlet.java 2007-06-08
13:50:21 UTC (rev 7394)
+++ trunk/core/src/main/org/jboss/portal/core/portlet/role/RolePortlet.java 2007-06-11
11:31:36 UTC (rev 7395)
@@ -1,959 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, and individual *
- * contributors as indicated by the @authors tag. See the *
- * copyright.txt in the distribution for a full listing of *
- * individual contributors. *
- * *
- * This is free software; you can redistribute it and/or modify it *
- * under the terms of the GNU Lesser General Public License as *
- * published by the Free Software Foundation; either version 2.1 of *
- * the License, or (at your option) any later version. *
- * *
- * This software is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this software; if not, write to the Free *
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
- ******************************************************************************/
-package org.jboss.portal.core.portlet.role;
-
-import org.jboss.logging.Logger;
-import org.jboss.portal.core.portlet.PortletHelper;
-import org.jboss.portal.core.portlet.user.UserPortletConstants;
-import org.jboss.portal.core.servlet.jsp.PortalJsp;
-import org.jboss.portal.core.servlet.jsp.taglib.context.DelegateContext;
-import org.jboss.portal.identity.IdentityException;
-import org.jboss.portal.identity.Role;
-import org.jboss.portal.identity.RoleModule;
-import org.jboss.portal.identity.User;
-import org.jboss.portal.identity.UserModule;
-import org.jboss.portal.identity.MembershipModule;
-import org.jboss.portal.identity.UserProfileModule;
-import org.jboss.portlet.JBossActionRequest;
-import org.jboss.portlet.JBossActionResponse;
-import org.jboss.portlet.JBossPortlet;
-import org.jboss.portlet.JBossRenderRequest;
-import org.jboss.portlet.JBossRenderResponse;
-
-import javax.portlet.PortletException;
-import javax.portlet.PortletRequestDispatcher;
-import javax.portlet.PortletSecurityException;
-import javax.portlet.PortletURL;
-import javax.portlet.WindowState;
-import javax.portlet.WindowStateException;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.util.Iterator;
-import java.util.Locale;
-import java.util.ResourceBundle;
-import java.util.Set;
-import java.util.Map;
-import java.util.HashSet;
-import java.util.Arrays;
-import java.util.List;
-
-/**
- * This portlet aims at managing roles of users.
- *
- * @author <a href="mailto:noel.rocher@free.fr">Noel Rocher</a>
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @author <a href="mailto:theute@jboss.org">Thomas Heute </a>
- * @author Roy Russo : roy at jboss dot org
- * @version $Revision$
- */
-public class RolePortlet
- extends JBossPortlet
-{
- /** the class logger */
- public static final Logger log = Logger.getLogger(JBossPortlet.class);
-
- private PortletHelper portletHelper;
-
- // Render op
- public static final String OP_SHOWSUMMARY = "showSummary";
-
- public static final String OP_SHOWCREATEROLE = "showCreateRole";
-
- public static final String OP_SHOWEDITROLE = "showEditRole";
-
- /** Main Edit role page where admins can filter */
- public static final String OP_SHOWMAINROLEMEMBERS =
"showMainEditRoleMembers";
-
- /** Edit role page where admins can edit the members individually. */
- public static final String OP_SHOWLISTROLEMEMBERS =
"showListEditRoleMembers";
-
- /** Render operation to show the screen to assign roles to a user */
- public static final String OP_SHOWADDROLESTOUSER = "showAddRolesToUser";
-
- private RoleModule roleModule;
-
- private UserModule userModule;
-
- private MembershipModule membershipModule;
-
- private UserProfileModule userProfileModule;
-
- private static final String ADMIN_ROLE = "Admin";
-
- public void init() throws PortletException
- {
- super.init();
- userModule = (UserModule)getPortletContext().getAttribute("UserModule");
- roleModule = (RoleModule)getPortletContext().getAttribute("RoleModule");
- portletHelper = new PortletHelper(this);
- membershipModule =
(MembershipModule)getPortletContext().getAttribute("MembershipModule");
- userProfileModule =
(UserProfileModule)getPortletContext().getAttribute("UserProfileModule");
-
- //
- if (userModule == null)
- {
- throw new PortletException("No user module");
- }
- if (roleModule == null)
- {
- throw new PortletException("No role module");
- }
- if (membershipModule == null)
- {
- throw new PortletException("No membership module");
- }
- if (userProfileModule == null)
- {
- throw new PortletException("No user profile module");
- }
-
-
- }
-
- public void destroy()
- {
- super.destroy();
-
- //
- userModule = null;
- roleModule = null;
- portletHelper = null;
- }
-
- public String getDefaultOperation()
- {
- return OP_SHOWSUMMARY;
- }
-
- protected void doView(JBossRenderRequest req, JBossRenderResponse resp)
- throws PortletException, PortletSecurityException, IOException
- {
-
- if (req.isUserInRole(ADMIN_ROLE))
- {
- resp.setContentType("text/html");
- PrintWriter writer = resp.getWriter();
-
- String op;
- if (req.getWindowState() != WindowState.MAXIMIZED)
- {
- op = getDefaultOperation();
- }
- else
- {
- op = req.getParameters().get(getOperationName(),
- getDefaultOperation());
- }
-
- Locale locale = req.getLocale();
- ResourceBundle bundle = getResourceBundle(locale);
- if (OP_SHOWSUMMARY.equals(op))
- {
- if (req.isUserInRole(ADMIN_ROLE))
- {
- DelegateContext ctx = new DelegateContext();
- ctx.put("nbRoles", getNbRolesString(bundle));
-
- DelegateContext roleCtx = null;
- try
- {
- Set roles = roleModule.findRoles();
- Iterator i = roles.iterator();
- while (i.hasNext())
- {
- Role role = (Role)i.next();
- roleCtx = ctx.next("role");
- String roleId = role.getId().toString();
- roleCtx.put("id", roleId);
- roleCtx.put("displayname", role.getDisplayName());
- }
- }
- catch (IdentityException e)
- {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- req.setAttribute(PortalJsp.CTX_REQUEST, ctx);
- PortletRequestDispatcher rd = getPortletContext()
- .getRequestDispatcher("/WEB-INF/jsp/role/menu.jsp");
- rd.include(req, resp);
- }
- }
- else if (OP_SHOWCREATEROLE.equals(op))
- {
- if (req.isUserInRole(ADMIN_ROLE))
- {
- PortletRequestDispatcher rd = getPortletContext()
- .getRequestDispatcher("/WEB-INF/jsp/role/createRole.jsp");
- rd.include(req, resp);
- }
- }
- else if (OP_SHOWEDITROLE.equals(op))
- {
- if (req.isUserInRole(ADMIN_ROLE))
- {
- try
- {
- Set roles = roleModule.findRoles();
- DelegateContext ctx = new DelegateContext();
- ctx.put("editroleid", req.getParameter("roleid"));
- ctx.put("editroledisplayname",
req.getParameter("roledisplayname"));
- Iterator i = roles.iterator();
- DelegateContext roleCtx = null;
- while (i.hasNext())
- {
- Role role = (Role)i.next();
- roleCtx = ctx.next("role");
- String roleId = role.getId().toString();
- roleCtx.put("id", roleId);
- roleCtx.put("displayname", role.getDisplayName());
- String selectedRoleId = req.getParameter("roleid");
- if (roleId.equals(selectedRoleId))
- {
- roleCtx.put("selected", "selected");
- }
- }
- req.setAttribute(PortalJsp.CTX_REQUEST, ctx);
- }
- catch (IdentityException e)
- {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- PortletRequestDispatcher rd = getPortletContext()
- .getRequestDispatcher("/WEB-INF/jsp/role/editRole.jsp");
- rd.include(req, resp);
- }
- }
- else if (OP_SHOWMAINROLEMEMBERS.equals(op))
- {
- if (req.isUserInRole(ADMIN_ROLE))
- {
- try
- {
- Set roles = roleModule.findRoles();
- DelegateContext ctx = new DelegateContext();
- Iterator i = roles.iterator();
- DelegateContext roleCtx = null;
- while (i.hasNext())
- {
- Role role = (Role)i.next();
- roleCtx = ctx.next("role");
- String roleId = role.getId().toString();
- roleCtx.put("id", roleId);
- roleCtx.put("displayname", role.getDisplayName());
- String selectedRoleId = req.getParameter("roleid");
- if (roleId.equals(selectedRoleId))
- {
- roleCtx.put("selected", "selected");
- }
- }
- req.setAttribute(PortalJsp.CTX_REQUEST, ctx);
- }
- catch (IdentityException e)
- {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- PortletRequestDispatcher rd = getPortletContext()
-
.getRequestDispatcher("/WEB-INF/jsp/role/editRoleMembers.jsp");
- rd.include(req, resp);
- }
- }
- else if (OP_SHOWLISTROLEMEMBERS.equals(op))
- {
- if (req.isUserInRole(ADMIN_ROLE))
- {
- try
- {
- String roleID = req.getParameters().getParameter("roleid");
- Role role = roleModule.findRoleById(roleID);
-
- DelegateContext ctx = new DelegateContext();
- DelegateContext roleCtx = null;
- roleCtx = ctx.next("role");
- ctx.put("displayname", role.getDisplayName());
-
- int offset = req.getParameters().getInt("offset", 0);
- int usersPerPage = req.getParameters().getInt("usersperpage",
UserPortletConstants.DEFAULT_USERSPERPAGE);
- String usernameFilter =
req.getParameters().get("usernamefilter", "");
- ctx.put("usernameFilter", usernameFilter);
-
- Set users = null;
- users = membershipModule.findRoleMembers(role.getName(), offset,
usersPerPage + 1, usernameFilter.trim());
-
- User[] usersArray = new User[users.size()];
- usersArray = (User[])users.toArray(usersArray);
-
- DelegateContext rowCtx = null;
- for (int i = 0; i < Math.min(usersArray.length, usersPerPage); i++)
- {
- User user = usersArray[i];
- rowCtx = ctx.next("row");
- rowCtx.put("fullname", getFullName(bundle, user));
- rowCtx.put("username", user.getUserName());
-
- //
- Iterator itRoles = membershipModule.getRoles(user).iterator();
- while (itRoles.hasNext())
- {
- DelegateContext rolesCtx = rowCtx.next("roles");
- rolesCtx.put("name",
((Role)itRoles.next()).getDisplayName());
- }
-
- PortletURL editURL = resp.createRenderURL();
- editURL.setParameter(getOperationName(), OP_SHOWADDROLESTOUSER);
- editURL.setParameter("userid", "" +
user.getId());
- editURL.setParameter("roleid", "" +
role.getId());
- editURL.setParameter("usernamefilter", usernameFilter);
- editURL.setParameter("offset", "" + offset);
- editURL.setParameter("usersperpage", "" +
usersPerPage);
-
- rowCtx.put("editURL", editURL.toString());
- }
-
- if (offset != 0)
- {
- PortletURL previousPageLink = resp.createRenderURL();
- previousPageLink.setParameter(getOperationName(),
OP_SHOWLISTROLEMEMBERS);
- previousPageLink.setParameter("offset", "" +
Math.max(0, offset - usersPerPage));
- previousPageLink.setParameter("usersperpage", ""
+ usersPerPage);
- previousPageLink.setParameter("usernamefilter",
usernameFilter);
- previousPageLink.setParameter("roleid", "" +
roleID);
- DelegateContext previousCtx = ctx.next("previouspage");
- previousCtx.put("link", previousPageLink.toString());
- }
-
- if (usersArray.length > usersPerPage)
- {
- PortletURL nextPageLink = resp.createRenderURL();
- nextPageLink.setParameter(getOperationName(),
OP_SHOWLISTROLEMEMBERS);
- nextPageLink.setParameter("offset", "" + (offset
+ usersPerPage));
- nextPageLink.setParameter("usersperpage", "" +
usersPerPage);
- nextPageLink.setParameter("usernamefilter",
usernameFilter);
- nextPageLink.setParameter("roleid", "" +
roleID);
- DelegateContext nextCtx = ctx.next("nextpage");
- nextCtx.put("link", nextPageLink.toString());
- }
-
- try
- {
- Set roles = roleModule.findRoles();
- Iterator i = roles.iterator();
- DelegateContext roleCtxs = null;
- while (i.hasNext())
- {
- Role arole = (Role)i.next();
- roleCtxs = ctx.next("rolelist");
- String aroleId = arole.getId().toString();
- roleCtxs.put("id", aroleId);
- roleCtxs.put("displayname", arole.getDisplayName());
- if (aroleId.equals(roleID))
- {
- roleCtxs.put("selected", "selected");
- }
- }
- }
- catch (IdentityException e)
- {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- ctx.put("usernamefilter", usernameFilter);
- req.setAttribute(PortalJsp.CTX_REQUEST, ctx);
- }
- catch (IdentityException e)
- {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- PortletRequestDispatcher rd = getPortletContext()
-
.getRequestDispatcher("/WEB-INF/jsp/role/editListRoleMembers.jsp");
- rd.include(req, resp);
- }
- }
- else if (OP_SHOWADDROLESTOUSER.equals(op))
- {
- if (req.isUserInRole(ADMIN_ROLE))
- {
- DelegateContext ctx = new DelegateContext();
-
- try
- {
- ctx.put("usernamefilter",
req.getParameter("usernamefilter"));
- ctx.put("offset", req.getParameter("offset"));
- ctx.put("usersperpage",
req.getParameter("usersperpage"));
- ctx.put("roleid", req.getParameter("roleid"));
-
-
- User user =
userModule.findUserById(req.getParameter("userid"));
-
- ctx.put("userid", user.getId().toString());
- ctx.put("username", user.getUserName());
- ctx.put("userfullname", getFullName(bundle, user));
- Set userRoles = membershipModule.getRoles(user);
-
- //old stuff
- Set roles = roleModule.findRoles();
- Role[] rolesArray = new Role[roles.size()];
- //rolesArray = (Role[])roles.toArray(rolesArray);
- Role role = null;
-
- DelegateContext allRolesCtx = null;
- for (Iterator it = roles.iterator(); it.hasNext();)
- {
- role = (Role)it.next();
- allRolesCtx = ctx.next("allRoles");
-
- allRolesCtx.put("name", role.getName());
- allRolesCtx.put("displayname", role.getDisplayName());
- }
-
- DelegateContext userRolesCtx = null;
-
- if
(!req.getParameterMap().keySet().contains("selectedRoles"))
- {
- for (Iterator it = userRoles.iterator(); it.hasNext();)
- {
- role = (Role)it.next();
- userRolesCtx = ctx.next("userRoles");
-
- userRolesCtx.put("name", role.getName());
- userRolesCtx.put("displayname",
role.getDisplayName());
- }
- }
- else
- {
- String[] selectedRoles =
req.getParameterValues("selectedRoles");
- for (int i = 0; i < selectedRoles.length; i++)
- {
- String selectedRole = selectedRoles[i];
- role = roleModule.findRoleByName(selectedRole);
-
- userRolesCtx = ctx.next("userRoles");
-
- userRolesCtx.put("name", role.getName());
- userRolesCtx.put("displayname",
role.getDisplayName());
- }
- }
-
- }
- catch (IllegalArgumentException e)
- {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- catch (IdentityException e)
- {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- req.setAttribute(PortalJsp.CTX_REQUEST, ctx);
- PortletRequestDispatcher rd =
getPortletContext().getRequestDispatcher("/WEB-INF/jsp/role/editUserRoles.jsp");
- rd.include(req, resp);
- }
- }
- else
- {
- log.error("This operation does not exist when user is logged in:"
- + op);
- }
- writer.close();
- }
- else
- {
- forbidden(req, resp);
- }
- }
-
- public void showListEditRoleMembers(JBossActionRequest req, JBossActionResponse resp)
throws WindowStateException
- {
- resp.setRenderParameter(getOperationName(), OP_SHOWLISTROLEMEMBERS);
- resp.setRenderParameter("roleid", req.getParameter("roleid"));
- resp.setRenderParameter("usersperpage",
req.getParameter("usersperpage"));
- resp.setRenderParameter("usernamefilter",
req.getParameter("usernamefilter"));
- resp.setWindowState(WindowState.MAXIMIZED);
- }
-
- /**
- * Handles permissions errors on doView.
- *
- * @param rReq
- * @param rRes
- * @throws javax.portlet.PortletException
- * @throws IOException
- */
- private void forbidden(javax.portlet.RenderRequest rReq, javax.portlet.RenderResponse
rRes) throws javax.portlet.PortletException, IOException
- {
- rRes.setContentType("text/html");
- javax.portlet.PortletRequestDispatcher prd =
getPortletContext().getRequestDispatcher("/WEB-INF/jsp/permission/forbidden.jsp");
- prd.include(rReq, rRes);
- }
-
- public void createRole(JBossActionRequest req, JBossActionResponse resp)
- {
- if (req.isUserInRole(ADMIN_ROLE))
- {
-
- String roleName = req.getParameter("rolename");
- String roleDisplayName = req.getParameter("roledisplayname");
- if ((roleName != null) && (roleDisplayName != null)
- && (roleName.length() != 0) && (roleDisplayName.length() !=
0))
- {
- if (roleByDisplayNameAvailable(roleDisplayName)
- && roleByNameAvailable(roleName))
- {
- try
- {
- roleModule.createRole(roleName, roleDisplayName);
-/*
- try
- {
-*/
- resp.setRenderParameter(getOperationName(),
- getDefaultOperation());
-/*
- resp.setWindowState(WindowState.NORMAL);
- }
- catch (WindowStateException e1)
- {
- log.error("Couldn't put the window in normal state");
- }
-*/
- }
- catch (IllegalArgumentException e)
- {
- log.error("Cannot create role, rolename is null");
- e.printStackTrace();
- }
- catch (IdentityException e)
- {
- log.error("Cannot create role \"" + roleName
- + "\", unexpected error");
- e.printStackTrace();
- }
- }
- else
- {
- if (!roleByDisplayNameAvailable(roleDisplayName))
- {
- // Role with that display name already exists !
- portletHelper.setRenderParameter(resp, "rolename",
roleName);
- portletHelper.setRenderParameter(resp, "roledisplayname",
- roleDisplayName);
- resp.setRenderParameter("roledisplayname_error",
- "ROLE_ERROR_DISPLAYNAMEALREADYEXISTS");
- resp.setRenderParameter(getOperationName(),
- getDefaultOperation());
- }
- else if (!roleByNameAvailable(roleName))
- {
- // Role with that name already exists !
- portletHelper.setRenderParameter(resp, "rolename",
roleName);
- portletHelper.setRenderParameter(resp, "roledisplayname",
- roleDisplayName);
- resp.setRenderParameter("rolename_error",
- "ROLE_ERROR_NAMEALREADYEXISTS");
- resp.setRenderParameter(getOperationName(),
- getDefaultOperation());
- }
- }
- }
- else
- {
- // Role name or displayname empty
- portletHelper.setRenderParameter(resp, "rolename", roleName);
- portletHelper.setRenderParameter(resp, "roledisplayname",
- roleDisplayName);
- if (roleName == null || roleName.length() == 0)
- {
- resp
- .setRenderParameter("rolename_error",
- "ROLE_ERROR_NAMEEMPTY");
- }
- if (roleDisplayName == null || roleDisplayName.length() == 0)
- {
- resp.setRenderParameter("roledisplayname_error",
- "ROLE_ERROR_DISPLAYNAMEEMPTY");
- }
- resp.setRenderParameter(getOperationName(),
- getDefaultOperation());
- }
- }
- }
-
- /**
- * Action to edit a role
- *
- * @param req
- * @param resp
- */
- public void editRole(JBossActionRequest req, JBossActionResponse resp) throws
WindowStateException
- {
- if (req.isUserInRole(ADMIN_ROLE))
- {
- String roleID = req.getParameters().getParameter("roleid");
- String newDisplayName = req.getParameter("roledisplayname");
- Role role = null;
- try
- {
- role = roleModule.findRoleById(roleID);
- // Check that the new display name is available
- if (!"".equals(newDisplayName))
- {
- if (roleByDisplayNameAvailable(newDisplayName))
- {
- role.setDisplayName(newDisplayName);
- }
- else
- // The display name is not available, go back to the prefilled form
- {
- portletHelper.setRenderParameter(resp, "roledisplayname",
- newDisplayName);
- portletHelper.setRenderParameter(resp, "roleid", roleID);
- resp.setRenderParameter("roledisplayname_error",
- "ROLE_ERROR_DISPLAYNAMEALREADYEXISTS");
- resp.setRenderParameter(getOperationName(), OP_SHOWEDITROLE);
- }
- }
- else
- {
- portletHelper.setRenderParameter(resp, "roledisplayname",
- newDisplayName);
- portletHelper.setRenderParameter(resp, "roleid", roleID);
- resp.setRenderParameter("roledisplayname_error",
- "ROLE_ERROR_NAMEEMPTY");
- resp.setRenderParameter(getOperationName(), OP_SHOWEDITROLE);
- }
- }
- catch (IllegalArgumentException e)
- {
- log.error("Cannot update role: roleID is null");
- e.printStackTrace();
- }
- catch (IdentityException e)
- {
- log.error("Cannot update role, unexpected error");
- e.printStackTrace();
- }
- }
- }
-
- /**
- * Adds or Removes roles from a user.
- *
- * @param request
- * @param response
- */
- public void addRolesToUser(JBossActionRequest request, JBossActionResponse response)
- {
-
- if (request.isUserInRole(ADMIN_ROLE))
- {
- String userId = request.getParameters().getParameter("userid");
-
- response.setRenderParameter("usernamefilter",
request.getParameter("usernamefilter"));
- response.setRenderParameter("offset",
request.getParameter("offset"));
- response.setRenderParameter("roleid",
request.getParameter("roleid"));
- response.setRenderParameter("usersperpage",
request.getParameter("usersperpage"));
-
- if (request.getParameterMap().keySet().contains("addRoles"))
- {
- String[] selectedRoles =
request.getParameterValues("assignedRoles");
- String[] rolesToAdd = request.getParameterValues("rolesToAdd");
-
- if (selectedRoles == null)
- {
- selectedRoles = new String[]{};
- }
- if (rolesToAdd == null)
- {
-
- if (selectedRoles.length != 0)
- {
- response.setRenderParameter("selectedRoles", selectedRoles);
- }
-
- response.setRenderParameter("op", OP_SHOWADDROLESTOUSER );
- response.setRenderParameter("userid", userId);
- return;
- }
-
-
- Set roles = new HashSet();
- List l1 = Arrays.asList(selectedRoles);
- List l2 = Arrays.asList(rolesToAdd);
- roles.addAll(l1);
- roles.addAll(l2);
-
- String[] roleNames = new String[roles.size()];
- roleNames = (String[])roles.toArray(roleNames);
-
- response.setRenderParameter("selectedRoles", roleNames);
- response.setRenderParameter("op", OP_SHOWADDROLESTOUSER );
- response.setRenderParameter("userid", userId);
- }
- else if (request.getParameterMap().keySet().contains("removeRoles"))
- {
-
- String[] selectedRoles =
request.getParameterValues("assignedRoles");
- String[] rolesToRemove =
request.getParameterValues("selectedRoles");
-
- if (selectedRoles == null)
- {
- selectedRoles = new String[]{};
- }
-
- if (rolesToRemove == null)
- {
- if (selectedRoles.length != 0)
- {
- response.setRenderParameter("selectedRoles", selectedRoles);
- }
-
- response.setRenderParameter("op", OP_SHOWADDROLESTOUSER );
- response.setRenderParameter("userid", userId);
- return;
- }
-
- List toRemove = Arrays.asList(rolesToRemove);
-
- Set roles = new HashSet();
-
- for (int i = 0; i < selectedRoles.length; i++)
- {
- String selectedRole = selectedRoles[i];
-
- if (!toRemove.contains(selectedRole))
- {
- roles.add(selectedRole);
- }
- }
-
- String[] roleNames = new String[roles.size()];
- roleNames = (String[])roles.toArray(roleNames);
-
- if (roleNames.length != 0)
- {
- response.setRenderParameter("selectedRoles", roleNames);
- }
-
- response.setRenderParameter("op", OP_SHOWADDROLESTOUSER );
- response.setRenderParameter("userid", userId);
- }
- else
- {
-
- String[] selectedRoles =
request.getParameterValues("assignedRoles");
-
- try
- {
- User user = userModule.findUserById(userId);
- Set roles = roleModule.findRolesByNames(selectedRoles);
- membershipModule.assignRoles(user, roles);
-
- response.setRenderParameter("op", OP_SHOWLISTROLEMEMBERS );
- response.setRenderParameter("userid", userId);
- }
- catch (IllegalArgumentException e)
- {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- catch (IdentityException e)
- {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
- }
-
- /**
- * Action to delete a role
- *
- * @param req
- * @param resp
- */
- public void removeRole(JBossActionRequest req, JBossActionResponse resp)
- {
-
-
- if (req.isUserInRole(ADMIN_ROLE))
- {
- String roleId = req.getParameters().getParameter("roleid");
- try
- {
- Role role = roleModule.findRoleById(roleId);
- roleModule.removeRole(role.getId());
- resp.setRenderParameter("roledelete_error",
"ROLE_DELETED");
- resp.setRenderParameter(getOperationName(), OP_SHOWEDITROLE);
- }
- catch (IdentityException e)
- {
- log.error("Cannot remove role, unexpected error", e);
- portletHelper.setRenderParameter(resp, "roleid", roleId);
- resp.setRenderParameter("roledelete_error",
"ROLE_ERROR_DELETE_FAILED");
- resp.setRenderParameter(getOperationName(), OP_SHOWEDITROLE);
- }
- }
- }
-
- /**
- * Returns true if the role with display name in argument is available
- *
- * @param name Display name of the role to check
- * @return true if the display name is available
- */
- private boolean roleByDisplayNameAvailable(String name)
- {
- try
- {
- for (Iterator i = roleModule.findRoles().iterator(); i.hasNext();)
- {
- Role role = (Role)i.next();
- if (role.getDisplayName() != null &&
role.getDisplayName().equals(name))
- {
- return false;
- }
- }
- }
- catch (IdentityException e)
- {
- return false;
- }
- return true;
- }
-
- /** Returns true if the role with name in argument is available */
- private boolean roleByNameAvailable(String name)
- {
- Role role = null;
- try
- {
- role = roleModule.findRoleByName(name);
- //in case that exception was not thrown
- if (role == null)
- {
- return true;
- }
- }
- catch (IllegalArgumentException e)
- {
- e.printStackTrace();
- }
- catch (IdentityException e)
- {
- return true;
- }
- return false;
- }
-
- /** Return a localized sentence stating the number of existing roles */
- private String getNbRolesString(ResourceBundle bundle)
- {
- StringBuffer buffer = new StringBuffer();
- int nbRoles = 0;
- try
- {
- nbRoles = roleModule.getRolesCount();
- }
- catch (IllegalArgumentException e)
- {
- e.printStackTrace();
- }
- catch (IdentityException e)
- {
- e.printStackTrace();
- }
- if (nbRoles <= 1)
- {
- buffer.append(bundle.getString("ROLE_THEREIS")).append("
");
- if (nbRoles == 0)
- {
- buffer.append("no");
- }
- else
- {
- buffer.append("1");
- }
- buffer.append("
").append(bundle.getString("ROLE_ROLEDEFINED"));
- }
- else
- {
- buffer.append(bundle.getString("ROLE_THEREARE")).append("
");
- buffer.append(nbRoles);
- buffer.append("
").append(bundle.getString("ROLE_ROLESDEFINED"));
- }
- return buffer.toString();
- }
-
- /**
- * This is a helper method extracted from the userPortlet that returns the user's
fullname.
- *
- * @param bundle
- * @param user
- */
- private String getFullName(ResourceBundle bundle,
- User user)
- {
- String givenName = null;
- String familyName = null;
-
- try
- {
- givenName = (String)userProfileModule.getProperty(user,
User.INFO_USER_NAME_GIVEN);
- familyName = (String)userProfileModule.getProperty(user,
User.INFO_USER_NAME_FAMILY);
- }
- catch (IdentityException e)
- {
- log.error("cannot obtain user profile information: ", e);
- }
-
- if ((givenName != null) && (givenName.trim().length() != 0))
- {
- if ((familyName != null) && (familyName.trim().length() != 0))
- {
- return givenName + " " + familyName;
- }
- else
- {
- return givenName.trim();
- }
- }
- else
- {
- if ((familyName != null) && (familyName.trim().length() != 0))
- {
- return familyName.trim();
- }
- else
- {
- return bundle.getString("NAMENOTAVAILABLE");
- }
- }
- }
-}
\ No newline at end of file
Deleted: trunk/core/src/main/org/jboss/portal/core/portlet/user/UserPortlet.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/core/portlet/user/UserPortlet.java 2007-06-08
13:50:21 UTC (rev 7394)
+++ trunk/core/src/main/org/jboss/portal/core/portlet/user/UserPortlet.java 2007-06-11
11:31:36 UTC (rev 7395)
@@ -1,1484 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, and individual *
- * contributors as indicated by the @authors tag. See the *
- * copyright.txt in the distribution for a full listing of *
- * individual contributors. *
- * *
- * This is free software; you can redistribute it and/or modify it *
- * under the terms of the GNU Lesser General Public License as *
- * published by the Free Software Foundation; either version 2.1 of *
- * the License, or (at your option) any later version. *
- * *
- * This software is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this software; if not, write to the Free *
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
- ******************************************************************************/
-package org.jboss.portal.core.portlet.user;
-
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.PrintWriter;
-import java.io.StringWriter;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Locale;
-import java.util.Map;
-import java.util.ResourceBundle;
-import java.util.Set;
-import java.util.List;
-import java.util.Arrays;
-
-import javax.portlet.PortletException;
-import javax.portlet.PortletRequestDispatcher;
-import javax.portlet.PortletSecurityException;
-import javax.portlet.PortletURL;
-import javax.portlet.WindowState;
-import javax.portlet.WindowStateException;
-
-import org.jboss.logging.Logger;
-import org.jboss.portal.api.node.PortalNode;
-import org.jboss.portal.api.node.PortalNodeURL;
-import org.jboss.portal.common.p3p.P3PConstants;
-import org.jboss.portal.common.util.Tools;
-import org.jboss.portal.common.net.URLTools;
-import org.jboss.portal.common.util.ConversionException;
-import org.jboss.portal.common.i18n.LocaleFormat;
-import org.jboss.portal.common.i18n.LocaleManager;
-import org.jboss.portal.core.aspects.controller.node.Navigation;
-import org.jboss.portal.core.modules.MailModule;
-import org.jboss.portal.core.portlet.PortletHelper;
-import org.jboss.portal.core.servlet.jsp.PortalJsp;
-import org.jboss.portal.core.servlet.jsp.taglib.context.DelegateContext;
-import org.jboss.portal.identity.IdentityException;
-import org.jboss.portal.identity.MembershipModule;
-import org.jboss.portal.identity.Role;
-import org.jboss.portal.identity.RoleModule;
-import org.jboss.portal.identity.User;
-import org.jboss.portal.identity.UserModule;
-import org.jboss.portal.identity.UserProfileModule;
-import org.jboss.portal.theme.PortalTheme;
-import org.jboss.portal.theme.ThemeInfo;
-import org.jboss.portal.theme.ThemeService;
-import org.jboss.portlet.JBossActionRequest;
-import org.jboss.portlet.JBossActionResponse;
-import org.jboss.portlet.JBossPortlet;
-import org.jboss.portlet.JBossRenderRequest;
-import org.jboss.portlet.JBossRenderResponse;
-
-import freemarker.template.Configuration;
-import freemarker.template.Template;
-import freemarker.template.TemplateException;
-
-/**
- * This portlet aims at managing users
- *
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @author <a href="mailto:theute@jboss.org">Thomas Heute </a>
- * @author <a href="mailto:mageshbk@jboss.com">Magesh Kumar
Bojan</a>
- * @version $Revision$
- */
-public class UserPortlet
- extends JBossPortlet
-{
-
- /** The class logger. */
- public static final Logger log = Logger.getLogger(JBossPortlet.class);
-
- /** Render operation to show the login screen. */
- public static final String OP_SHOWLOGIN = "showLogin";
-
- /** Render operation to show the register screen. */
- public static final String OP_SHOWREGISTER = "showRegister";
-
- /** Render operation to show the register thankyou screen. */
- public static final String OP_SHOWREGISTER_TY = "showRegisterty";
-
- /** Render operation to show the user menu screen. */
- public static final String OP_SHOWMENU = "showMenu";
-
- /** Render operation to show the user profile to edit. */
- public static final String OP_SHOWPROFILE = "showProfile";
-
- /** Render operation to show the screen to assign roles to a user. */
- public static final String OP_SHOWADDROLESTOUSER = "showAddRolesToUser";
-
- /** Render operation to show the list of users. */
- public static final String OP_SHOWLISTUSERS = "showListUsers";
-
- /** Logout the user. */
- public static final String OP_USERLOGOUT = "userLogout";
-
- /** Deletes the user */
- public static final String OP_DELETEUSER = "deleteUser";
-
- /** Activate the user via email link */
- public static final String OP_ACTIVATEUSER = "activate";
-
- private UserModule userModule;
- private RoleModule roleModule;
- private MembershipModule membershipModule;
- private UserProfileModule userProfileModule;
- private MailModule mailModule;
- private PortletHelper portletHelper;
- public static final short UNDEFINED_TIMEZONE = (short)0;
-
- /**
- * init method of the portlet, Setting up the diffrent modules used.
- *
- * @throws PortletException If a module cannot be looked up.
- */
- public void init()
- throws PortletException
- {
- super.init();
-
- //
- userModule = (UserModule)getPortletContext().getAttribute("UserModule");
- roleModule = (RoleModule)getPortletContext().getAttribute("RoleModule");
- membershipModule =
(MembershipModule)getPortletContext().getAttribute("MembershipModule");
- userProfileModule =
(UserProfileModule)getPortletContext().getAttribute("UserProfileModule");
- mailModule = (MailModule)getPortletContext().getAttribute("MailModule");
- portletHelper = new PortletHelper(this);
-
- //
- if (userModule == null)
- {
- throw new PortletException("No user module");
- }
- if (roleModule == null)
- {
- throw new PortletException("No role module");
- }
- if (mailModule == null)
- {
- throw new PortletException("No mail module");
- }
- if (membershipModule == null)
- {
- throw new PortletException("No membership module");
- }
- if (userProfileModule == null)
- {
- throw new PortletException("No user profile module");
- }
- }
-
- public void destroy()
- {
- super.destroy();
-
- //
- userModule = null;
- roleModule = null;
- mailModule = null;
- portletHelper = null;
- }
-
- public String getDefaultOperation()
- {
- return OP_SHOWLOGIN;
- }
-
- /**
- * doView method
- *
- * @param req Render request
- * @param resp render response
- * @throws PortletException DOCUMENT_ME
- * @throws PortletSecurityException DOCUMENT_ME
- * @throws IOException DOCUMENT_ME
- */
- protected void doView(JBossRenderRequest req, JBossRenderResponse resp)
- throws PortletException,
- PortletSecurityException,
- IOException
- {
- String op;
- resp.setContentType("text/html");
- PrintWriter writer = resp.getWriter();
-/*
- if (req.getRemoteUser() == null)
- {
- req.getPortletSession().invalidate();
- PortletRequestDispatcher rd =
getPortletContext().getRequestDispatcher("/WEB-INF/jsp/user/login.jsp");
- PortalNode currentNode = req.getPortalNode();
- PortalNodeURL url = resp.createRenderURL(currentNode);
- url.setAuthenticated(Boolean.TRUE);
- if
("1".equals(getPortletConfig().getInitParameter("useSSL")))
- {
- url.setSecure(Boolean.TRUE);
- req.setAttribute("secureURL", url.toString());
- }
- url.setSecure(null);
- req.setAttribute("URL", url.toString());
- rd.include(req, resp);
- return;
- }
-*/
- if (req.getRemoteUser() != null)
- {
- if (req.getWindowState() != WindowState.MAXIMIZED)
- {
- op = OP_SHOWMENU;
- }
- else
- {
- op = req.getParameters().get(getOperationName(),
- OP_SHOWMENU);
- // Because of the automatic redirection
- if (op.equals(OP_SHOWLOGIN))
- {
- op = OP_SHOWMENU;
- }
- }
-
- Locale requestLocale = req.getLocale();
- ResourceBundle bundle = getResourceBundle(requestLocale);
- if (OP_SHOWPROFILE.equals(op))
- {
- String userid = req.getParameters().getParameter("userid");
- User user = null;
- if (userid != null)
- {
- try
- {
- user = userModule.findUserById(userid);
- }
- catch (Exception e)
- {
- log.error("Cannot retrive user", e);
- }
- }
- else
- {
- user = req.getUser();
- try
- {
- user = userModule.findUserById(user.getId());
- }
- catch (IdentityException e)
- {
- log.error("Cannot retrive user", e);
- }
- }
-
- // Validate we have a user object
- if (user == null)
- {
- throw new PortletException("Not user object found");
- }
-
- //
- DelegateContext ctx = new DelegateContext();
-
- //
- ctx.put("userid", user.getId().toString());
- fillContextWithUserProfile(user, ctx);
-
- //
- //String selectedTimeZone =
(String)user.getProfile().get(User.INFO_USER_TIME_ZONE_OFFSET);
- String selectedTimeZone = (String)getProperty(user,
User.INFO_USER_TIME_ZONE_OFFSET);
- for (int i = 0; i < UserPortletConstants.TIME_ZONE_OFFSETS.length; i++)
- {
- if (UserPortletConstants.TIME_ZONE_OFFSETS[i] != null)
- {
- DelegateContext timeZoneCtx = ctx.next("timezone");
- timeZoneCtx.put("name",
UserPortletConstants.TIME_ZONE_OFFSETS[i]);
- timeZoneCtx.put("id", "" + i);
- if (selectedTimeZone != null &&
selectedTimeZone.equals("" + i))
- {
- timeZoneCtx.put("selected", "selected");
- }
- }
- }
-
- //
- //String selectedLocale =
(String)user.getProfile().get(User.INFO_USER_LOCALE);
- String selectedLocale = (String)getProperty(user, User.INFO_USER_LOCALE);
-
- ArrayList locales = new ArrayList(LocaleManager.getLocales());
- Collections.sort(locales, new LocaleComparator());
-
- for (Iterator i = locales.iterator(); i.hasNext();)
- {
- Locale locale = (Locale)i.next();
- DelegateContext localeCtx = ctx.next("locale");
- localeCtx.put("name", locale.getDisplayName(requestLocale));
- String localeString = locale.toString();
- localeCtx.put("id", localeString);
- if (selectedLocale != null &&
selectedLocale.equals(localeString))
- {
- localeCtx.put("selected", "selected");
- }
- }
-
- //
- //String selectedTheme =
(String)user.getProfile().get(User.INFO_USER_THEME);
- String selectedTheme = (String)getProperty(user,User.INFO_USER_THEME);
- ThemeService themeService =
(ThemeService)getPortletContext().getAttribute("ThemeService");
- for (Iterator i = themeService.getThemes().iterator(); i.hasNext();)
- {
- PortalTheme theme = (PortalTheme)i.next();
- ThemeInfo info = theme.getThemeInfo();
- DelegateContext themeCtx = ctx.next("theme");
- themeCtx.put("name", info.getAppId() + "." +
info.getName());
- themeCtx.put("id", info.getRegistrationId().toString());
- if ((selectedTheme != null) &&
selectedTheme.equals(info.getRegistrationId().toString()))
- {
- themeCtx.put("selected", "selected");
- }
- }
-
- //
- req.setAttribute(PortalJsp.CTX_REQUEST, ctx);
- resp.setTitle(bundle.getString("REGISTER_PERSONALINFO"));
- PortletRequestDispatcher rd =
getPortletContext().getRequestDispatcher("/WEB-INF/jsp/user/editProfile.jsp");
- rd.include(req, resp);
- }
- else if (OP_SHOWMENU.equals(op))
- {
- DelegateContext ctx = new DelegateContext();
- if (req.isUserInRole("Admin"))
- {
- ctx.next("admin");
- }
- if (req.getParameter("modifiedProfile") != null)
- {
- ctx.next("modifiedProfile");
- }
- req.setAttribute(PortalJsp.CTX_REQUEST, ctx);
- PortletRequestDispatcher rd =
getPortletContext().getRequestDispatcher("/WEB-INF/jsp/user/menu.jsp");
- rd.include(req, resp);
-
- }
- else if (OP_SHOWLISTUSERS.equals(op))
- {
- if (req.isUserInRole("Admin"))
- {
- try
- {
- int offset = req.getParameters().getInt("offset", 0);
- int usersPerPage = req.getParameters().getInt("usersperpage",
UserPortletConstants.DEFAULT_USERSPERPAGE);
- String usernameFilter =
req.getParameters().get("usernamefilter", "");
-
- // We get usersPerPage + 1 entries so we can know if there is
- // a next page
- // It's tricky but it avoids to make 2 queries.
- Set users;
- if (usernameFilter.trim().length() == 0)
- {
- users = userModule.findUsers(offset, usersPerPage + 1);
- }
- else
- {
- users = userModule.findUsersFilteredByUserName(usernameFilter,
offset, usersPerPage + 1);
- }
-
- User[] usersArray = new User[users.size()];
- usersArray = (User[])users.toArray(usersArray);
- DelegateContext ctx = new DelegateContext();
-
- DelegateContext rowCtx = null;
- for (int i = 0; i < Math.min(usersArray.length, usersPerPage); i++)
- {
- User user = usersArray[i];
- rowCtx = ctx.next("row");
- rowCtx.put("firstname", getFirstName(bundle, user));
- rowCtx.put("lastname", getLastName(bundle, user));
- rowCtx.put("username", user.getUserName());
- if (i % 2 == 0)
- {
- rowCtx.put("css-class",
"portlet-table-text");
- }
- else
- {
- rowCtx.put("cssClass",
"portlet-table-alternate");
- }
-
- //
- Iterator itRoles = membershipModule.getRoles(user).iterator();
- while (itRoles.hasNext())
- {
- DelegateContext rolesCtx = rowCtx.next("roles");
- rolesCtx.put("name",
((Role)itRoles.next()).getDisplayName());
- }
-
- PortletURL editURL = resp.createRenderURL();
- editURL.setParameter(getOperationName(), OP_SHOWPROFILE);
- editURL.setParameter("userid", "" +
user.getId());
-
- PortletURL rolesURL = resp.createRenderURL();
- rolesURL.setParameter(getOperationName(), OP_SHOWADDROLESTOUSER);
- rolesURL.setParameter("userid", "" +
user.getId());
- rolesURL.setParameter("usernamefilter", usernameFilter);
- rolesURL.setParameter("offset", "" + offset);
- rolesURL.setParameter("usersperpage", "" +
usersPerPage);
-
- PortletURL deleteUrl = resp.createActionURL();
- deleteUrl.setParameter(getOperationName(), OP_DELETEUSER);
- deleteUrl.setParameter("userid", "" +
user.getId());
-
- rowCtx.put("editURL", editURL.toString());
- rowCtx.put("rolesURL", rolesURL.toString());
- rowCtx.put("deleteURL", deleteUrl.toString());
- }
-
- if (offset != 0)
- {
- PortletURL previousPageLink = resp.createRenderURL();
- previousPageLink.setParameter(getOperationName(),
OP_SHOWLISTUSERS);
- previousPageLink.setParameter("offset", "" +
Math.max(0, offset - usersPerPage));
- previousPageLink.setParameter("usersperpage", ""
+ usersPerPage);
- previousPageLink.setParameter("usernamefilter",
usernameFilter);
- DelegateContext previousCtx = ctx.next("previouspage");
- previousCtx.put("link", previousPageLink.toString());
- }
-
- if (usersArray.length > usersPerPage)
- {
- PortletURL nextPageLink = resp.createRenderURL();
- nextPageLink.setParameter(getOperationName(), OP_SHOWLISTUSERS);
- nextPageLink.setParameter("offset", "" + (offset
+ usersPerPage));
- nextPageLink.setParameter("usersperpage", "" +
usersPerPage);
- nextPageLink.setParameter("usernamefilter",
usernameFilter);
- DelegateContext nextCtx = ctx.next("nextpage");
- nextCtx.put("link", nextPageLink.toString());
- }
-
- ctx.put("usernamefilter", usernameFilter);
- ctx.put("results", users.size() + "");
- req.setAttribute(PortalJsp.CTX_REQUEST, ctx);
- }
- catch (IllegalArgumentException e)
- {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- catch (IdentityException e)
- {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- PortletRequestDispatcher rd =
getPortletContext().getRequestDispatcher("/WEB-INF/jsp/user/listUsers.jsp");
- rd.include(req, resp);
- }
- }
- else if (OP_SHOWADDROLESTOUSER.equals(op))
- {
- if (req.isUserInRole("Admin"))
- {
- DelegateContext ctx = new DelegateContext();
-
- ctx.put("usernamefilter",
req.getParameter("usernamefilter"));
- ctx.put("offset", req.getParameter("offset"));
- ctx.put("usersperpage",
req.getParameter("usersperpage"));
-
- try
- {
- User user =
userModule.findUserById(req.getParameter("userid"));
- ctx.put("userid", user.getId().toString());
- ctx.put("username", user.getUserName());
- ctx.put("userfullname", getFullName(bundle, user));
- Set userRoles = membershipModule.getRoles(user);
-
- Set roles = roleModule.findRoles();
-
-
- Role role = null;
-
-
-
- DelegateContext allRolesCtx = null;
- for (Iterator it = roles.iterator(); it.hasNext();)
- {
- role = (Role)it.next();
- allRolesCtx = ctx.next("allRoles");
-
- allRolesCtx.put("name", role.getName());
- allRolesCtx.put("displayname", role.getDisplayName());
- }
-
- DelegateContext userRolesCtx = null;
-
- if
(!req.getParameterMap().keySet().contains("selectedRoles"))
- {
- for (Iterator it = userRoles.iterator(); it.hasNext();)
- {
- role = (Role)it.next();
- userRolesCtx = ctx.next("userRoles");
-
- userRolesCtx.put("name", role.getName());
- userRolesCtx.put("displayname",
role.getDisplayName());
- }
- }
- else
- {
- String[] selectedRoles =
req.getParameterValues("selectedRoles");
- for (int i = 0; i < selectedRoles.length; i++)
- {
- String selectedRole = selectedRoles[i];
- role = roleModule.findRoleByName(selectedRole);
-
- userRolesCtx = ctx.next("userRoles");
-
- userRolesCtx.put("name", role.getName());
- userRolesCtx.put("displayname",
role.getDisplayName());
- }
- }
- }
- catch (IllegalArgumentException e)
- {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- catch (IdentityException e)
- {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- req.setAttribute(PortalJsp.CTX_REQUEST, ctx);
- PortletRequestDispatcher rd =
getPortletContext().getRequestDispatcher("/WEB-INF/jsp/user/editUserRoles.jsp");
- rd.include(req, resp);
- }
- }
- else if (OP_SHOWREGISTER.equals(op))
- {
- if (req.isUserInRole("Admin"))
- {
- DelegateContext ctx = new DelegateContext();
- ctx.put("lastView",
req.getParameters().get("lastView", "showMenu"));
- req.setAttribute(PortalJsp.CTX_REQUEST, ctx);
-
- PortletRequestDispatcher rd =
getPortletContext().getRequestDispatcher("/WEB-INF/jsp/user/registerUser.jsp");
- rd.include(req, resp);
- }
- }
- else if (OP_SHOWREGISTER_TY.equals(op))
- {
- if (req.isUserInRole("Admin"))
- {
- PortletRequestDispatcher rd =
getPortletContext().getRequestDispatcher("/WEB-INF/jsp/user/registerUser_admin.jsp");
- rd.include(req, resp);
- }
- }
- else
- {
- log.error("This operation does not exist when user is logged in:" +
op);
- }
- }
- else
- {
- // User is not logged in
- op = req.getParameters().get(getOperationName(), OP_SHOWLOGIN);
-
- if (req.getWindowState() != WindowState.MAXIMIZED && !
OP_SHOWREGISTER_TY.equals(op) && ! OP_ACTIVATEUSER.equals(op))
- {
- op = OP_SHOWLOGIN;
- }
-
- if (OP_SHOWREGISTER.equals(op))
- {
- PortletRequestDispatcher rd =
getPortletContext().getRequestDispatcher("/WEB-INF/jsp/user/register.jsp");
- rd.include(req, resp);
- }
- else if (OP_SHOWREGISTER_TY.equals(op))
- {
- PortletRequestDispatcher rd =
getPortletContext().getRequestDispatcher("/WEB-INF/jsp/user/register_ty.jsp");
- rd.include(req, resp);
- }
- else if (OP_SHOWLOGIN.equals(op))
- {
- PortletRequestDispatcher rd =
getPortletContext().getRequestDispatcher("/WEB-INF/jsp/user/login.jsp");
- rd.include(req, resp);
- }
- else if (OP_ACTIVATEUSER.equals(op))
- {
- String hash = req.getParameter(UserPortletConstants.HASH);
- String userId =
req.getParameters().getParameter(UserPortletConstants.USERID);
-
- User user;
- PortletRequestDispatcher rd;
- try
- {
- user = userModule.findUserById(userId);
- String hexCompare = Tools.md5AsHexString(user.getUserName() +
getProperty(user,User.INFO_USER_REGISTRATION_DATE).toString() +
UserPortletConstants.SALT);
- if (hash.equals(hexCompare))
- {
- setProperty(user, User.INFO_USER_ENABLED, Boolean.TRUE);
- rd =
getPortletContext().getRequestDispatcher("/WEB-INF/jsp/user/register_ty.jsp");
- PortalNode currentNode = Navigation.getCurrentNode();
- PortalNodeURL url = resp.createRenderURL(currentNode);
- url.setAuthenticated(Boolean.TRUE);
- if
("1".equals(getPortletConfig().getInitParameter("useSSL")))
- {
- url.setSecure(Boolean.TRUE);
- req.setAttribute("secureURL", url.toString());
- }
- url.setSecure(null);
- req.setAttribute("URL", url.toString());
- }
- else
- {
- rd =
getPortletContext().getRequestDispatcher("/WEB-INF/jsp/user/login.jsp");
- }
- }
- catch (Exception e)
- {
- rd =
getPortletContext().getRequestDispatcher("/WEB-INF/jsp/user/login.jsp");
- }
- rd.include(req, resp);
- }
- else
- {
- log.error("This operation does not exist when user is not logged
in:" + op);
- }
- }
-
- writer.close();
- }
-
-
- /**
- *
- */
- public void showListUsers(JBossActionRequest actionRequest, JBossActionResponse
actionResponse) throws IOException, WindowStateException
- {
- if (actionRequest.isUserInRole("Admin"))
- {
- actionResponse.setRenderParameter("usernamefilter",
actionRequest.getParameter("usernamefilter"));
- actionResponse.setRenderParameter("usersperpage",
actionRequest.getParameter("usersperpage"));
- actionResponse.setRenderParameter("op", OP_SHOWLISTUSERS);
- actionResponse.setWindowState(WindowState.MAXIMIZED);
- }
- }
-
-
- /** Performs a log out. */
- public void userLogout(JBossActionRequest req, JBossActionResponse resp) throws
IOException
- {
- String locationURL = req.getParameter("locationURL");
- if (locationURL != null)
- {
- resp.signOut(locationURL);
- }
- else
- {
- resp.signOut();
- }
- }
-
- /**
- * Action when a user register
- *
- * @param req JBoss action request
- * @param resp JBoss action response
- */
- public void userRegister(JBossActionRequest req, JBossActionResponse resp)
- {
- // TODO: Check that a bot is not creating many accounts
- String uname = req.getParameter("uname");
- resp.setRenderParameter("op",
req.getParameters().get("lastView",OP_SHOWMENU));
-
- int nbErrors = 0;
- if ((uname == null) || (uname.length() == 0))
- {
- nbErrors++;
- resp.setRenderParameter("uname_error",
"REGISTER_ERROR_INVALIDUSERNAME");
- }
- else
- {
- try
- {
- User user = userModule.findUserByUserName(uname);
- if (user != null)
- {
- nbErrors++;
- resp.setRenderParameter("uname_error",
"REGISTER_ERROR_EXISTINGUSERNAME");
- }
- }
- catch (IllegalArgumentException e)
- {
- log.error("", e);
- }
- catch (IdentityException e)
- {
- // Ok the user does not exist yet
- }
- }
-
- String pass1 = req.getParameter("pass1");
- if ((pass1 == null) || (pass1.length() == 0))
- {
- nbErrors++;
- resp.setRenderParameter("pass1_error",
"REGISTER_ERROR_INVALIDPASSWORD1");
- }
-
- String pass2 = req.getParameter("pass2");
- if ((pass2 == null) || (pass2.length() == 0))
- {
- nbErrors++;
- resp.setRenderParameter("pass2_error",
"REGISTER_ERROR_INVALIDPASSWORD2");
- }
- else if (!pass1.equals(pass2))
- {
- nbErrors++;
- resp.setRenderParameter("pass2_error",
"REGISTER_ERROR_PASSWORDMISMATCH");
- }
-
- String realEmail = req.getParameter("realemail");
- if (!URLTools.isEmailValid(realEmail))
- {
- nbErrors++;
- resp.setRenderParameter("realemail_error",
"REGISTER_ERROR_INVALIDREALEMAIL");
- }
-
- String fakeEmail = req.getParameter("fakeemail");
- String question = req.getParameter("question");
- String answer = req.getParameter("answer");
- User user;
- if (nbErrors == 0)
- {
- try
- {
-
- user = userModule.createUser(uname, pass1);
-
- setProperty(user, P3PConstants.INFO_USER_BUSINESS_INFO_ONLINE_EMAIL,
realEmail);
- //user.setFakeEmail(fakeEmail);
- setProperty(user,User.INFO_USER_EMAIL_FAKE, fakeEmail);
-
- //TODO: set registration date
-
- String type =
userProfileModule.getProfileInfo().getPropertyInfo(User.INFO_USER_REGISTRATION_DATE).getType();
- if (type.equals("java.util.Date"))
- {
- putNonEmptyProperty(user, User.INFO_USER_REGISTRATION_DATE, new Date());
- }
- else if (type.equals("java.lang.String"))
- {
- putNonEmptyProperty(user, User.INFO_USER_REGISTRATION_DATE, new
Date().toString());
- }
- else
- {
- log.warn(User.INFO_USER_REGISTRATION_DATE + " property is mapped in
not supported type: " + type);
- }
-
- String subscriptionMode =
getPortletConfig().getInitParameter(UserPortletConstants.SUBSCRIPTIONMODE);
- if (subscriptionMode == null)
- {
- subscriptionMode = UserPortletConstants.SUBSCRIPTIONMODE_AUTOMATIC;
- }
-
- setProperty(user, User.INFO_USER_LOCALE, req.getLocale().toString());
-
- if (UserPortletConstants.SUBSCRIPTIONMODE_AUTOMATIC.equals(subscriptionMode)
|| req.isUserInRole("Admin"))
- {
- setProperty(user, User.INFO_USER_ENABLED, Boolean.TRUE);
- }
- else if
(UserPortletConstants.SUBSCRIPTIONMODE_EMAILVERIFICATION.equals(subscriptionMode))
- {
- setProperty(user, User.INFO_USER_ENABLED, Boolean.FALSE);
- String emailText = generateValidationEmail(req, resp, user, pass1);
- String from =
getPortletConfig().getInitParameter(UserPortletConstants.EMAILFROM);
- Locale locale = req.getLocale();
- ResourceBundle bundle = getResourceBundle(locale);
- String subject =
bundle.getString("REGISTER_CONFIRMATIONEMAIL");
- mailModule.send(from,
(String)getProperty(user,P3PConstants.INFO_USER_BUSINESS_INFO_ONLINE_EMAIL), subject,
emailText);
- }
-
- /*
- * Have to define the link to /login Have to redirect after the
- * login try { resp.sendRedirect("/portal/login?username=" + uname
+
- * "&password=" + pass1); } catch (IOException e1) { // TODO
- * Auto-generated catch block e1.printStackTrace(); }
- */
-
- // Add the user to the default user role
- String defaultRole =
getPortletConfig().getInitParameter(UserPortletConstants.DEFAULT_ROLE);
- if (defaultRole != null)
- {
- Set roleSet = new HashSet();
- Role role = roleModule.findRoleByName(defaultRole);
- if (role != null)
- {
- roleSet.add(role);
- membershipModule.assignRoles(user, roleSet);
- }
- else
- {
- log.error("The role you specified as default role does not exist,
check your portlet configuration");
- }
- }
- else
- {
- log.info("You didn't specify a default role in the portlet init
configuration, please refer to the documentation");
- }
- //resp.setRenderParameter("op", OP_SHOWREGISTER_TY);
- if
(req.getParameters().get("lastView",OP_SHOWMENU).equals(OP_SHOWLISTUSERS))
- {
- resp.setWindowState(WindowState.MAXIMIZED);
- }
- else
- {
- resp.setWindowState(WindowState.NORMAL);
- }
- }
- catch (IllegalArgumentException e)
- {
- log.error("Cannot create user " + uname, e);
- }
- catch (IdentityException e)
- {
- log.error("Cannot create user " + uname, e);
- }
- catch (WindowStateException e)
- {
- log.error("Normal window state not supported...");
- }
- }
- else
- {
- portletHelper.setRenderParameter(resp, "USERNAME", uname);
- portletHelper.setRenderParameter(resp, "REALEMAIL", realEmail);
- portletHelper.setRenderParameter(resp, "FAKEEMAIL", fakeEmail);
- portletHelper.setRenderParameter(resp, "QUESTION", question);
- portletHelper.setRenderParameter(resp, "ANSWER", answer);
- portletHelper.setRenderParameter(resp, getOperationName(), OP_SHOWREGISTER);
- }
- }
-
- private void fillContextWithUserProfile(User user, DelegateContext ctx)
- {
- ctx.put("GIVENNAME", (String)getProperty(user,
P3PConstants.INFO_USER_NAME_GIVEN));
- ctx.put("FAMILYNAME", (String)getProperty(user,
P3PConstants.INFO_USER_NAME_FAMILY));
- ctx.put("REALEMAIL", (String)getProperty(user,
P3PConstants.INFO_USER_BUSINESS_INFO_ONLINE_EMAIL));
- ctx.put("FAKEEMAIL", (String)getProperty(user,
User.INFO_USER_EMAIL_FAKE));
- ctx.put("THEME", (String)getProperty(user, User.INFO_USER_THEME));
- ctx.put("VIEWREALEMAIL", ((String)getProperty(user,
User.INFO_USER_VIEW_EMAIL_VIEW_REAL)).equals("true") ?
"checked=\"checked\"" : "");
- ctx.put("HOMEPAGE", (String)getProperty(user,User.INFO_USER_HOMEPAGE));
- ctx.put("ICQ", (String)getProperty(user,User.INFO_USER_IM_ICQ));
- ctx.put("AIM", (String)getProperty(user,User.INFO_USER_IM_AIM));
- ctx.put("YIM", (String)getProperty(user,User.INFO_USER_IM_YIM));
- ctx.put("MSNM", (String)getProperty(user,User.INFO_USER_IM_MSNM));
- ctx.put("SKYPE", (String)getProperty(user,User.INFO_USER_IM_SKYPE));
- ctx.put("SIGNATURE",
(String)getProperty(user,User.INFO_USER_SIGNATURE));
- ctx.put("LOCATION", (String)getProperty(user,User.INFO_USER_LOCATION));
- ctx.put("OCCUPATION",
(String)getProperty(user,User.INFO_USER_OCCUPATION));
- ctx.put("INTERESTS",
(String)getProperty(user,User.INFO_USER_INTERESTS));
- ctx.put("EXTRA", (String)getProperty(user,User.INFO_USER_EXTRA));
- ctx.put("QUESTION",
(String)getProperty(user,User.INFO_USER_SECURITY_QUESTION));
- ctx.put("ANSWER",
(String)getProperty(user,User.INFO_USER_SECURITY_ANSWER));
- }
-
- /**
- * DOCUMENT_ME
- *
- * @param req DOCUMENT_ME
- * @param resp DOCUMENT_ME
- */
- public void storeProfile(JBossActionRequest req, JBossActionResponse resp) throws
PortletException
- {
- User currentUser = req.getUser();
- try
- {
- currentUser = userModule.findUserById(currentUser.getId());
- }
- catch (IdentityException e)
- {
- log.error("Cannot retrive user", e);
- }
-
- if (currentUser == null)
- {
- throw new PortletException("No user");
- }
-
- // Get the user
- User user = null;
- try
- {
- String userid = req.getParameters().getParameter("userid");
- user = userModule.findUserById(userid);
- }
- catch (Exception e)
- {
- throw new PortletException("blah", e);
- }
-
- // Are we editing ourself ?
- boolean self = currentUser.getId().equals(user.getId());
- if (!self && !req.isUserInRole("Admin"))
- {
- throw new PortletException();
- }
-
-
- int nbErrors = 0;
- boolean changePassword = false;
- String givenName = req.getParameter("givenname");
- String familyName = req.getParameter("familyname");
- String pass1 = req.getParameter("pass1");
- String pass2 = req.getParameter("pass2");
- if (!(((pass2 == null) || (pass2.length() == 0)) && ((pass1 == null) ||
(pass1.length() == 0))))
- {
- changePassword = true;
- if ((pass1 == null) || (pass1.length() == 0))
- {
- nbErrors++;
- resp.setRenderParameter("pass1_error",
"REGISTER_ERROR_INVALIDPASSWORD1");
- }
-
- if ((pass2 == null) || (pass2.length() == 0))
- {
- nbErrors++;
- resp.setRenderParameter("pass2_error",
"REGISTER_ERROR_INVALIDPASSWORD2");
- }
- else if (!pass1.equals(pass2))
- {
- nbErrors++;
- resp.setRenderParameter("pass2_error",
"REGISTER_ERROR_PASSWORDMISMATCH");
- }
- }
-
- String realEmail = req.getParameter("realemail");
- if (!URLTools.isEmailValid(realEmail))
- {
- nbErrors++;
- resp.setRenderParameter("realemail_error",
"REGISTER_ERROR_INVALIDREALEMAIL");
- }
-
- String fakeEmail = req.getParameter("fakeemail");
- boolean viewRealEmail = req.getParameters().getBoolean("viewrealemail",
false);
- String homepage = req.getParameter("homepage");
- Short timezoneoffset =
req.getParameters().getShortObject("timezoneoffset", UNDEFINED_TIMEZONE);
- String question = req.getParameter("question");
- String answer = req.getParameter("answer");
- String icq = req.getParameter("icq");
- String msnm = req.getParameter("msnm");
- String yim = req.getParameter("yim");
- String aim = req.getParameter("aim");
- String skype = req.getParameter("skype");
- String location = req.getParameter("location");
- String occupation = req.getParameter("occupation");
- String interests = req.getParameter("interests");
- String signature = req.getParameter("signature");
- String extra = req.getParameter("extra");
- String localeParam = req.getParameter("locale");
- String theme = req.getParameter("theme");
-
- if (nbErrors == 0)
- {
- //
- if (givenName.trim().length() != 0)
- {
- setProperty(user, P3PConstants.INFO_USER_NAME_GIVEN, givenName);
- }
-
- if (familyName.trim().length() != 0)
- {
- setProperty(user, P3PConstants.INFO_USER_NAME_FAMILY, familyName);
- }
-
- if (realEmail.trim().length() != 0)
- {
- setProperty(user, P3PConstants.INFO_USER_BUSINESS_INFO_ONLINE_EMAIL,
realEmail);
- }
-
- if (fakeEmail.trim().length() != 0)
- {
- setProperty(user, User.INFO_USER_EMAIL_FAKE, fakeEmail);
- }
-
- setProperty(user, User.INFO_USER_VIEW_EMAIL_VIEW_REAL,
Boolean.valueOf(viewRealEmail));
-
- if (changePassword)
- {
- user.updatePassword(pass1);
- }
-
- if (timezoneoffset.shortValue() != UNDEFINED_TIMEZONE)
- {
- setProperty(user, User.INFO_USER_TIME_ZONE_OFFSET,
timezoneoffset.toString());
- }
-
- try
- {
- Locale locale = LocaleFormat.DEFAULT.getLocale(localeParam);
- //setProperty(user, User.INFO_USER_LOCALE, localeInfo.getLocale());
- setProperty(user, User.INFO_USER_LOCALE,
LocaleFormat.DEFAULT.toString(locale));
- }
- catch (ConversionException e)
- {
- log.error("Cannot convert locale format", e);
- }
-
- putNonEmptyProperty(user, User.INFO_USER_THEME, theme);
- putNonEmptyProperty(user, User.INFO_USER_HOMEPAGE, homepage);
- putNonEmptyProperty(user, User.INFO_USER_SECURITY_QUESTION, question);
- putNonEmptyProperty(user, User.INFO_USER_SECURITY_ANSWER, answer);
- putNonEmptyProperty(user, User.INFO_USER_IM_ICQ, icq);
- putNonEmptyProperty(user, User.INFO_USER_IM_MSNM, msnm);
- putNonEmptyProperty(user, User.INFO_USER_IM_YIM, yim);
- putNonEmptyProperty(user, User.INFO_USER_IM_AIM, aim);
- putNonEmptyProperty(user, User.INFO_USER_IM_SKYPE, skype);
- putNonEmptyProperty(user, User.INFO_USER_SIGNATURE, signature);
- putNonEmptyProperty(user, User.INFO_USER_LOCATION, location);
- putNonEmptyProperty(user, User.INFO_USER_OCCUPATION, occupation);
- putNonEmptyProperty(user, User.INFO_USER_INTERESTS, interests);
- putNonEmptyProperty(user, User.INFO_USER_EXTRA, extra);
-
- // Set back to normal window state
- resp.setWindowState(WindowState.NORMAL);
- portletHelper.setRenderParameter(resp, "modifiedProfile",
"true");
- portletHelper.setRenderParameter(resp, getOperationName(), OP_SHOWMENU);
- }
- else
- {
- portletHelper.setRenderParameter(resp, "GIVENNAME", givenName);
- portletHelper.setRenderParameter(resp, "FAMILYNAME", familyName);
- portletHelper.setRenderParameter(resp, "REALEMAIL", realEmail);
- portletHelper.setRenderParameter(resp, "FAKEEMAIL", fakeEmail);
- if (getProperty(user,
User.INFO_USER_VIEW_EMAIL_VIEW_REAL).toString().equals("true"))
- {
- portletHelper.setRenderParameter(resp, "VIEWREALEMAIL",
"checked=\"checked\"");
- }
- else
- {
- portletHelper.setRenderParameter(resp, "VIEWREALEMAIL",
"");
- }
-
- portletHelper.setRenderParameter(resp, "HOMEPAGE", homepage);
- portletHelper.setRenderParameter(resp, "SELECTEDTIMEZONE",
"" + timezoneoffset);
- portletHelper.setRenderParameter(resp, "SELECTEDLOCALE",
localeParam);
- portletHelper.setRenderParameter(resp, "THEME", theme);
- portletHelper.setRenderParameter(resp, "ICQ", icq);
- portletHelper.setRenderParameter(resp, "AIM", aim);
- portletHelper.setRenderParameter(resp, "YIM", yim);
- portletHelper.setRenderParameter(resp, "MSNM", msnm);
- portletHelper.setRenderParameter(resp, "SKYPE", skype);
- portletHelper.setRenderParameter(resp, "SIGNATURE", signature);
- portletHelper.setRenderParameter(resp, "LOCATION", location);
- portletHelper.setRenderParameter(resp, "OCCUPATION", occupation);
- portletHelper.setRenderParameter(resp, "INTERESTS", interests);
- portletHelper.setRenderParameter(resp, "EXTRA", extra);
- portletHelper.setRenderParameter(resp, getOperationName(), OP_SHOWPROFILE);
- }
-
- }
-
- /**
- * DOCUMENT_ME
- *
- * @param request DOCUMENT_ME
- * @param response DOCUMENT_ME
- */
- public void addRolesToUser(JBossActionRequest request, JBossActionResponse response)
- {
- if (request.isUserInRole("Admin"))
- {
-
- String userId = request.getParameters().getParameter("userid");
- response.setRenderParameter("usernamefilter",
request.getParameter("usernamefilter"));
- response.setRenderParameter("offset",
request.getParameter("offset"));
- response.setRenderParameter("usersperpage",
request.getParameter("usersperpage"));
-
- if (request.getParameterMap().keySet().contains("addRoles"))
- {
- String[] selectedRoles =
request.getParameterValues("assignedRoles");
- String[] rolesToAdd = request.getParameterValues("rolesToAdd");
-
- if (selectedRoles == null)
- {
- selectedRoles = new String[]{};
- }
- if (rolesToAdd == null)
- {
-
- if (selectedRoles.length != 0)
- {
- response.setRenderParameter("selectedRoles", selectedRoles);
- }
-
- response.setRenderParameter("op", OP_SHOWADDROLESTOUSER );
- response.setRenderParameter("userid", userId);
- return;
- }
-
-
- Set roles = new HashSet();
- List l1 = Arrays.asList(selectedRoles);
- List l2 = Arrays.asList(rolesToAdd);
- roles.addAll(l1);
- roles.addAll(l2);
-
- String[] roleNames = new String[roles.size()];
- roleNames = (String[])roles.toArray(roleNames);
-
- response.setRenderParameter("selectedRoles", roleNames);
- response.setRenderParameter("op", OP_SHOWADDROLESTOUSER );
- response.setRenderParameter("userid", userId);
- }
- else if (request.getParameterMap().keySet().contains("removeRoles"))
- {
-
- String[] selectedRoles =
request.getParameterValues("assignedRoles");
- String[] rolesToRemove =
request.getParameterValues("selectedRoles");
-
- if (selectedRoles == null)
- {
- selectedRoles = new String[]{};
- }
-
- if (rolesToRemove == null)
- {
- if (selectedRoles.length != 0)
- {
- response.setRenderParameter("selectedRoles", selectedRoles);
- }
-
- response.setRenderParameter("op", OP_SHOWADDROLESTOUSER );
- response.setRenderParameter("userid", userId);
- return;
- }
-
- List toRemove = Arrays.asList(rolesToRemove);
-
- Set roles = new HashSet();
-
- for (int i = 0; i < selectedRoles.length; i++)
- {
- String selectedRole = selectedRoles[i];
-
- if (!toRemove.contains(selectedRole))
- {
- roles.add(selectedRole);
- }
- }
-
- String[] roleNames = new String[roles.size()];
- roleNames = (String[])roles.toArray(roleNames);
-
- if (roleNames.length != 0)
- {
- response.setRenderParameter("selectedRoles", roleNames);
- }
-
- response.setRenderParameter("op", OP_SHOWADDROLESTOUSER );
- response.setRenderParameter("userid", userId);
- }
- else
- {
- try
- {
- String[] selectedRoles =
request.getParameterValues("assignedRoles");
- User user = userModule.findUserById(userId);
- Set roles = roleModule.findRolesByNames(selectedRoles);
- membershipModule.assignRoles(user, roles);
- response.setRenderParameter(getOperationName(), OP_SHOWLISTUSERS);
- response.setRenderParameter("usernamefilter",
request.getParameter("usernamefilter"));
- response.setRenderParameter("offset",
request.getParameter("offset"));
- response.setRenderParameter("usersperpage",
request.getParameter("usersperpage"));
- }
- catch (IllegalArgumentException e)
- {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- catch (IdentityException e)
- {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
- }
-
- /*
- * TODO: The email verification needs an email service. This is not done yet.
- * It also needs a way to generate portlet URL or some kind of URL. Once all
- * of this made, it will be quick to implement.
- */
- /*
- * * Generates the body of the email sent for user activation.
- *
- * @param user user @param password unencrypted password @return email body
- *
- */
- private String generateValidationEmail(JBossActionRequest req,
- JBossActionResponse resp,
- User user,
- String clearPassword)
- {
- // gen link using username, encrypted pw, and a salt.
- String hash = Tools.md5AsHexString(user.getUserName() + getProperty(user,
User.INFO_USER_REGISTRATION_DATE).toString() + UserPortletConstants.SALT);
-
- PortalNode node = req.getPortalNode();
-
- //PortalNodeURL link = resp.createActionURL(node);
- PortalNodeURL link = resp.createRenderURL(node);
- link.setParameter("op", OP_ACTIVATEUSER);
- link.setParameter(UserPortletConstants.USERID, "" + user.getId());
- link.setParameter(UserPortletConstants.HASH, hash);
- link.setRelative(false);
-
- // Fill data to share with the template
- Map modelRoot = new HashMap();
- modelRoot.put("emailDomain",
getPortletConfig().getInitParameter("emailDomain"));
- modelRoot.put("id", user.getId());
- modelRoot.put("username", user.getUserName());
- modelRoot.put("password", clearPassword);
- modelRoot.put("activationLink", link);
-
- ClassLoader tcl = Thread.currentThread().getContextClassLoader();
- String message = null;
- try
- {
- Locale locale = req.getLocale();
- URL config = tcl.getResource("templates/user/emailTemplate_" +
locale.getLanguage() + "_" + locale.getCountry()+ ".tpl");
- if (config == null)
- {
- config = tcl.getResource("templates/user/emailTemplate_" +
locale.getLanguage() + ".tpl");
- }
- if (config == null)
- {
- config = tcl.getResource("templates/user/emailTemplate.tpl");
- }
- if (config == null)
- {
- throw new FileNotFoundException("Cannot load a suitable
emailTemplate.tpl in templates/user");
- }
- InputStream in = config.openStream();
- Template tpl = new Template("emailTemplate", new
InputStreamReader(in), new Configuration());
- StringWriter out = new StringWriter();
- tpl.process(modelRoot, out);
- out.close();
- message = out.toString();
- }
- catch (IOException e1)
- {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
- catch (TemplateException e)
- {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- return message;
- }
-
- private String getFirstName(ResourceBundle bundle, User user)
- {
- String givenName = null;
-
- try
- {
- givenName = (String)userProfileModule.getProperty(user,
P3PConstants.INFO_USER_NAME_GIVEN);
- }
- catch (IdentityException e)
- {
- log.error("cannot obtain user profile information: ", e);
- }
-
- if ((givenName != null) && (givenName.trim().length() != 0))
- {
- return givenName.trim();
- }
- else
- {
- return bundle.getString("NAMENOTAVAILABLE");
- }
- }
-
- private String getLastName(ResourceBundle bundle, User user)
- {
- String familyName = null;
-
- try
- {
- familyName = (String)userProfileModule.getProperty(user,
P3PConstants.INFO_USER_NAME_FAMILY);
- }
- catch (IdentityException e)
- {
- log.error("cannot obtain user profile information: ", e);
- }
-
-
- if ((familyName != null) && (familyName.trim().length() != 0))
- {
- return familyName.trim();
- }
- else
- {
- return bundle.getString("NAMENOTAVAILABLE");
- }
- }
-
- private String getFullName(ResourceBundle bundle,
- User user)
- {
- String givenName = null;
- String familyName = null;
-
- try
- {
- givenName = (String)userProfileModule.getProperty(user,
P3PConstants.INFO_USER_NAME_GIVEN);
- familyName = (String)userProfileModule.getProperty(user,
P3PConstants.INFO_USER_NAME_FAMILY);
- }
- catch (IdentityException e)
- {
- log.error("cannot obtain user profile information: ", e);
- }
-
- if ((givenName != null) && (givenName.trim().length() != 0))
- {
- if ((familyName != null) && (familyName.trim().length() != 0))
- {
- return givenName + " " + familyName;
- }
- else
- {
- return givenName.trim();
- }
- }
- else
- {
- if ((familyName != null) && (familyName.trim().length() != 0))
- {
- return familyName.trim();
- }
- else
- {
- return bundle.getString("NAMENOTAVAILABLE");
- }
- }
- }
-
- private void putNonEmptyProperty(User user, String key, Object value)
- {
-
-
- if (value != null)
- {
- if (value instanceof String && !(((String)value).trim().length() != 0)
)
- {
- return;
- }
- //user.getProfile().put(key, value);
- try
- {
- userProfileModule.setProperty(user, key, value);
- }
- catch (IdentityException e)
- {
- //TODO: change to error
- log.info("Cannot set profile property: ", e);
- }
- }
- }
-
- public void deleteUser(JBossActionRequest request, JBossActionResponse response)
- {
- if (request.isUserInRole("Admin"))
- {
- try
- {
- User user =
userModule.findUserById(request.getParameter("userid"));
- userModule.removeUser(user.getId());
- }
- catch (IdentityException e)
- {
- e.printStackTrace();
- }
- }
- portletHelper.setRenderParameter(response, getOperationName(), OP_SHOWLISTUSERS);
- }
-
- private void setProperty(User user, String key, Object value)
- {
- try
- {
- userProfileModule.setProperty(user, key, value);
- }
- catch (IdentityException e)
- {
- //TODO: change to error
- log.info("Cannot set profile property: ", e);
- }
- }
-
- //Some temp solution to make this portlet not break with new stuff
- private Object getProperty(User user, String key)
- {
- try
- {
- Object o = userProfileModule.getProperty(user, key);
- if (o == null)
- {
- return "";
- }
- else
- {
- return o.toString();
- }
- }
- catch (IdentityException e)
- {
- log.error("Cannot get profile property: ", e);
- }
- return null;
- }
-
- private class LocaleComparator implements Comparator
- {
-
- public int compare(Object arg0, Object arg1)
- {
- Locale locale1 = (Locale)arg0;
- Locale locale2 = (Locale)arg1;
- int compare =
locale1.getDisplayLanguage().compareTo(locale2.getDisplayLanguage());
- if (compare == 0)
- {
- compare =
locale1.getDisplayCountry().compareTo(locale2.getDisplayCountry());
- }
- return compare;
- }
-
- }
-
- /*
- * private String getTimezoneOffsetString(short timezoneOffset) {
- * StringBuffer timeZone = new StringBuffer(); for (int i = 0; i <
- * UserPortletConstants.TIME_ZONE_OFFSETS.length; i++) { if
- * (UserPortletConstants.TIME_ZONE_OFFSETS[i] != null) { timeZone.append("
- * <option value=\"").append(i); if (timezoneOffset == i) {
- * timeZone.append("\" selected>"); } else {
timeZone.append("\">"); }
- * timeZone.append(UserPortletConstants.TIME_ZONE_OFFSETS[i]).append("
- * </option>"); } } return timeZone.toString(); }
- *
- * private String getTimezoneOffsetString() { return
- * getTimezoneOffsetString((short)0); }
- *
- * private String getTimezoneOffsetString(String timezoneOffset) { short
- * offset = Short.parseShort(timezoneOffset); return
- * getTimezoneOffsetString(offset); }
- */
-}
\ No newline at end of file
Deleted: trunk/core/src/main/org/jboss/portal/core/portlet/user/UserPortletConstants.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/core/portlet/user/UserPortletConstants.java 2007-06-08
13:50:21 UTC (rev 7394)
+++
trunk/core/src/main/org/jboss/portal/core/portlet/user/UserPortletConstants.java 2007-06-11
11:31:36 UTC (rev 7395)
@@ -1,119 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, and individual *
- * contributors as indicated by the @authors tag. See the *
- * copyright.txt in the distribution for a full listing of *
- * individual contributors. *
- * *
- * This is free software; you can redistribute it and/or modify it *
- * under the terms of the GNU Lesser General Public License as *
- * published by the Free Software Foundation; either version 2.1 of *
- * the License, or (at your option) any later version. *
- * *
- * This software is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this software; if not, write to the Free *
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
- ******************************************************************************/
-package org.jboss.portal.core.portlet.user;
-
-/** @author <a href="theute(a)jboss.org">Thomas Heute</a> $Revision$
*/
-public class UserPortletConstants
-{
-
- public static final String SALT = "14m1r0nm4n";
-
- public static final String INFOMESSAGE = "infomessage";
- public static final String ERRORMESSAGE = "errormessage";
-
- // Cookie names
- public static String CK_USERNAME = "username";
- public static String CK_PASS = "password";
-
- // Default values
- public static int DEFAULT_USERSPERPAGE = 10;
-
- // Status return codes for the login.
- public static final int LOGIN_STATUS_OK = 0;
- public static final int LOGIN_STATUS_BAD_PASSWORD = 1;
- public static final int LOGIN_STATUS_NO_SUCH_USER = 2;
- public static final int LOGIN_STATUS_USER_DISABLED = 3;
- public static final int LOGIN_STATUS_INVALID_NAME = 4;
- public static final int LOGIN_STATUS_UNEXPECTED_ERROR = 5;
-
- public static final int PERMANENT_USER_MAX_INACTIVE = 60 * 60 * 24 * 5 * 1000; // 5
days in ms
- public static final int TRANSIENT_USER_MAX_INACTIVE = 60 * 60; // 1 hours in seconds
-
- public static final String HASH = "hash";
- public static final String USERID = "userid";
-
- // Portlet configuration
-
- public static final String EMAILFROM = "emailFrom";
- public static final String SUBSCRIPTIONMODE = "subscriptionMode";
- public static final String SUBSCRIPTIONMODE_AUTOMATIC = "automatic";
- public static final String SUBSCRIPTIONMODE_EMAILVERIFICATION =
"emailVerification";
- public static final String DEFAULT_ROLE = "defaultRole";
-
- /** Timezone information : ((value + 1) * 2) - 1 = 2 * value + 1 */
- public static final String[] TIME_ZONE_OFFSETS =
- {
- "(GMT -12:00 hours) Eniwetok, Kwajalein",
- null,
- "(GMT -11:00 hours) Midway Island, Samoa",
- null,
- "(GMT -10:00 hours) Hawaii",
- null,
- "(GMT -9:00 hours) Alaska",
- null,
- "(GMT -8:00 hours) Pacific Time (US & Canada)",
- null,
- "(GMT -7:00 hours) Mountain Time (US & Canada)",
- null,
- "(GMT -6:00 hours) Central Time (US & Canada), Mexico City",
- null,
- "(GMT -5:00 hours) Eastern Time (US & Canada), Bogota, Lima,
Quito",
- null,
- "(GMT -4:00 hours) Atlantic Time (Canada), Caracas, La Paz",
- "(GMT -3:30 hours) Newfoundland",
- "(GMT -3:00 hours) Brazil, Buenos Aires, Georgetown",
- null,
- "(GMT -2:00 hours) Mid-Atlantic",
- null,
- "(GMT -1:00 hours) Azores, Cape Verde Islands",
- null,
- "(GMT) Western Europe Time, London, Lisbon, Casablanca, Monrovia",
- null,
- "(GMT +1:00 hours) CET(Central Europe Time), Brussels, Copenhagen, Madrid,
Paris",
- null,
- "(GMT +2:00 hours) EET(Eastern Europe Time), Kaliningrad, South
Africa",
- null,
- "(GMT +3:00 hours) Baghdad, Kuwait, Riyadh, Moscow, St. Petersburg",
- "(GMT +3:30 hours) Tehran",
- "(GMT +4:00 hours) Abu Dhabi, Muscat, Baku, Tbilisi",
- "(GMT +4:30 hours) Kabul",
- "(GMT +5:00 hours) Ekaterinburg, Islamabad, Karachi, Tashkent",
- "(GMT +5:30 hours) Bombay, Calcutta, Madras, New Delhi",
- "(GMT +6:00 hours) Almaty, Dhaka, Colombo",
- null,
- "(GMT +7:00 hours) Bangkok, Hanoi, Jakarta",
- null,
- "(GMT +8:00 hours) Beijing, Perth, Singapore, Hong Kong, Chongqing, Urumqi,
Taipei",
- null,
- "(GMT +9:00 hours) Tokyo, Seoul, Osaka, Sapporo, Yakutsk",
- "(GMT +9:30 hours) Adelaide, Darwin",
- "(GMT +10:00 hours) EAST(East Australian Standard)",
- null,
- "(GMT +11:00 hours) Magadan, Solomon Islands, New Caledonia",
- null,
- "(GMT +12:00 hours) Auckland, Wellington, Fiji, Kamchatka, Marshall
Island",
- null
- };
-
- public static final String DEFAULT_IMAGES_PATH = "images/user";
-}
Modified: trunk/core/src/main/org/jboss/portal/core/theme/PageRendition.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/core/theme/PageRendition.java 2007-06-08 13:50:21
UTC (rev 7394)
+++ trunk/core/src/main/org/jboss/portal/core/theme/PageRendition.java 2007-06-11 11:31:36
UTC (rev 7395)
@@ -37,6 +37,8 @@
import java.io.IOException;
/**
+ * Should not be a controller response, but it comes from legacy design.
+ *
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision: 1.1 $
*/
Added: trunk/core/src/main/org/jboss/portal/core/theme/WindowContextFactory.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/core/theme/WindowContextFactory.java
(rev 0)
+++ trunk/core/src/main/org/jboss/portal/core/theme/WindowContextFactory.java 2007-06-11
11:31:36 UTC (rev 7395)
@@ -0,0 +1,138 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.core.theme;
+
+import org.jboss.portal.theme.page.WindowContext;
+import org.jboss.portal.theme.page.WindowResult;
+import org.jboss.portal.theme.render.renderer.ActionRendererContext;
+import org.jboss.portal.theme.ThemeConstants;
+import
org.jboss.portal.core.model.portal.command.action.InvokePortletWindowRenderCommand;
+import org.jboss.portal.core.model.portal.command.response.MarkupResponse;
+import org.jboss.portal.core.model.portal.PortalObjectPath;
+import org.jboss.portal.core.model.portal.Window;
+import org.jboss.portal.core.model.portal.content.WindowRendition;
+import org.jboss.portal.core.controller.ControllerContext;
+import org.jboss.portal.WindowState;
+import org.jboss.portal.Mode;
+import org.jboss.portal.server.ServerInvocationContext;
+import org.jboss.portal.server.request.URLContext;
+import org.jboss.portal.server.request.URLFormat;
+
+import java.util.Map;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.HashMap;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class WindowContextFactory
+{
+
+ /** . */
+ private final ControllerContext context;
+
+ public WindowContextFactory(ControllerContext context)
+ {
+ this.context = context;
+ }
+
+ public WindowContext createWindowContext(Window window, WindowRendition context)
+ {
+ Map actionMap = new HashMap();
+ addModeActions(window, actionMap, context.getMode(), context.getSupportedModes());
+ addWindowStateActions(window, actionMap, context.getWindowState(),
context.getSupportedWindowStates());
+
+ //
+ MarkupResponse markup = (MarkupResponse)context.getControllerResponse();
+
+ //
+ String region = window.getDeclaredProperty(ThemeConstants.PORTAL_PROP_REGION);
+ String order = window.getDeclaredProperty(ThemeConstants.PORTAL_PROP_ORDER);
+
+ //
+ WindowResult windowResult = new WindowResult(
+ markup.getTitle(),
+ markup.getContent(),
+ actionMap,
+ context.getProperties(),
+ markup.getHeaderContent(),
+ context.getWindowState(),
+ context.getMode());
+
+ //
+ return new WindowContext(
+ window.getId().toString(PortalObjectPath.LEGACY_BASE64_FORMAT),
+ region,
+ order,
+ windowResult);
+ }
+
+ /**
+ * Create the action URLs for the allowed window states of the rendered portlet window
and add them to the provided
+ * actionMap.
+ */
+ protected final void addWindowStateActions(Window window, Map actionMap, WindowState
currentWindowState, List supportedWindowStates)
+ {
+ List windowStates = new ArrayList(supportedWindowStates.size());
+ for (Iterator j = supportedWindowStates.iterator(); j.hasNext();)
+ {
+ WindowState windowState = (WindowState)j.next();
+ String url = createUpdateNavigationalStateURL(window, null, windowState);
+ boolean disabled = windowState.equals(currentWindowState);
+ WindowResult.Action action = new WindowResult.Action(windowState.toString(),
url, !disabled);
+ windowStates.add(action);
+ }
+ actionMap.put(ActionRendererContext.WINDOWSTATES_KEY, windowStates);
+ }
+
+ /**
+ * Create the action URLs for the allowed portlet modes of the rendered portlet window
and add them to the provided
+ * actionMap.
+ */
+ protected final void addModeActions(Window window, Map actionMap, Mode currentMode,
List supportedModes)
+ {
+ List modes = new ArrayList(supportedModes.size());
+ for (Iterator j = supportedModes.iterator(); j.hasNext();)
+ {
+ Mode mode = (Mode)j.next();
+ String url = createUpdateNavigationalStateURL(window, mode, null);
+ boolean disabled = mode.equals(currentMode);
+ WindowResult.Action action = new WindowResult.Action(mode.toString(), url,
!disabled);
+ modes.add(action);
+ }
+ actionMap.put(ActionRendererContext.MODES_KEY, modes);
+ }
+
+ protected final String createUpdateNavigationalStateURL(Window window, Mode mode,
WindowState windowState)
+ {
+ InvokePortletWindowRenderCommand cmd = new
InvokePortletWindowRenderCommand(window.getId(), mode, windowState);
+ ServerInvocationContext serverContext =
context.getServerInvocation().getServerContext();
+ boolean secure = serverContext.getURLContext().isSecure();
+ boolean authenticated = serverContext.getURLContext().isAuthenticated();
+ URLContext urlContext = URLContext.newInstance(secure, authenticated);
+ return context.renderURL(cmd, urlContext, URLFormat.newInstance(true, true));
+ }
+}
Deleted: trunk/core/src/main/org/jboss/portal/core/theme/WindowRendition.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/core/theme/WindowRendition.java 2007-06-08
13:50:21 UTC (rev 7394)
+++ trunk/core/src/main/org/jboss/portal/core/theme/WindowRendition.java 2007-06-11
11:31:36 UTC (rev 7395)
@@ -1,47 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, and individual *
- * contributors as indicated by the @authors tag. See the *
- * copyright.txt in the distribution for a full listing of *
- * individual contributors. *
- * *
- * This is free software; you can redistribute it and/or modify it *
- * under the terms of the GNU Lesser General Public License as *
- * published by the Free Software Foundation; either version 2.1 of *
- * the License, or (at your option) any later version. *
- * *
- * This software is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this software; if not, write to the Free *
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
- ******************************************************************************/
-package org.jboss.portal.core.theme;
-
-import org.jboss.portal.theme.page.WindowResult;
-import org.jboss.portal.core.controller.ControllerResponse;
-
-/**
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision: 1.1 $
- */
-public class WindowRendition extends ControllerResponse
-{
-
- /** . */
- private final WindowResult window;
-
- public WindowRendition(WindowResult window)
- {
- this.window = window;
- }
-
- public WindowResult getWindow()
- {
- return window;
- }
-}
Added: trunk/core/src/main/org/jboss/portal/core/ui/portlet/PortletHelper.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/core/ui/portlet/PortletHelper.java
(rev 0)
+++ trunk/core/src/main/org/jboss/portal/core/ui/portlet/PortletHelper.java 2007-06-11
11:31:36 UTC (rev 7395)
@@ -0,0 +1,71 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.core.ui.portlet;
+
+import org.jboss.logging.Logger;
+import org.jboss.portal.core.servlet.jsp.PortalJsp;
+import org.jboss.portlet.JBossActionRequest;
+import org.jboss.portlet.JBossActionResponse;
+import org.jboss.portlet.JBossPortlet;
+
+import java.util.Locale;
+import java.util.ResourceBundle;
+
+/** @author <a href="theute(a)jboss.org">Thomas Heute </a> $Revision:
5448 $ */
+public class PortletHelper
+{
+ private Logger log = Logger.getLogger(PortalJsp.class);
+
+ private JBossPortlet portlet;
+
+ public PortletHelper(JBossPortlet portlet)
+ {
+ this.portlet = portlet;
+ }
+
+ public void setRenderParameter(JBossActionResponse resp, String key, String value)
+ {
+ if (value != null)
+ {
+ resp.setRenderParameter(key, value);
+ }
+ }
+
+ public void setI18nRenderParameter(JBossActionRequest req, JBossActionResponse resp,
String key, String value)
+ {
+ if (value != null)
+ {
+ Locale locale = req.getLocale();
+ ResourceBundle bundle = portlet.getResourceBundle(locale);
+ try
+ {
+ resp.setRenderParameter(key, bundle.getString(value));
+ }
+ catch (Exception e)
+ {
+ log.error("Cannot find language key: " + key);
+ resp.setRenderParameter(key, value);
+ }
+ }
+ }
+}
\ No newline at end of file
Property changes on:
trunk/core/src/main/org/jboss/portal/core/ui/portlet/PortletHelper.java
___________________________________________________________________
Name: svn:executable
+ *
Added: trunk/core/src/main/org/jboss/portal/core/ui/portlet/catalog/CatalogPortlet.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/core/ui/portlet/catalog/CatalogPortlet.java
(rev 0)
+++
trunk/core/src/main/org/jboss/portal/core/ui/portlet/catalog/CatalogPortlet.java 2007-06-11
11:31:36 UTC (rev 7395)
@@ -0,0 +1,201 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.core.ui.portlet.catalog;
+
+import org.jboss.portal.api.node.PortalNode;
+import org.jboss.portal.api.node.PortalNodeURL;
+import org.jboss.portal.core.impl.api.node.PortalNodeImpl;
+import org.jboss.portal.core.model.portal.PortalObjectPermission;
+import org.jboss.portal.security.spi.auth.PortalAuthorizationManagerFactory;
+import org.jboss.portlet.JBossPortlet;
+import org.jboss.portlet.JBossRenderRequest;
+import org.jboss.portlet.JBossRenderResponse;
+
+import javax.portlet.PortletException;
+import javax.portlet.PortletRequestDispatcher;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Locale;
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @author <a href="mailto:theute@jboss.org">Thomas Heute</a>
+ * @version $Revision: 7134 $
+ */
+public class CatalogPortlet
+ extends JBossPortlet
+{
+ /** . */
+ private static final String RESOURCE_PREFIX = "PAGENAME_";
+
+ private PortalAuthorizationManagerFactory portalAuthorizationManagerFactory;
+
+ public void init() throws PortletException
+ {
+ portalAuthorizationManagerFactory = (PortalAuthorizationManagerFactory)
getPortletContext().getAttribute("PortalAuthorizationManagerFactory");
+
+ if(portalAuthorizationManagerFactory == null)
+ {
+ throw new PortletException("No portal authorization manager
factory");
+ }
+ }
+
+ public void destroy()
+ {
+ super.destroy();
+
+ portalAuthorizationManagerFactory = null;
+ }
+
+ public void render(JBossRenderRequest req, JBossRenderResponse resp) throws
IOException
+ {
+ resp.setContentType("text/html");
+
+ PortalNode current = req.getPortalNode();
+// WindowState ws = req.getWindowState();
+// if(WindowState.MAXIMIZED.equals(ws))
+// {
+// resp.setTitle("Sitemap");
+// PortalNode parent = current.getParent();
+// req.setAttribute("parentNode", parent);
+// try
+// {
+// PortletRequestDispatcher prd =
getPortletContext().getRequestDispatcher("/WEB-INF/jsp/catalog/sitemap.jsp");
+// prd.include(req, resp);
+// }
+// catch(Exception e)
+// {
+// e.printStackTrace();
+// }
+// }
+// else
+// {
+ resp.setTitle("Pages");
+ PortalNode parent = current.getParent();
+
+ HashMap parentsMap = new HashMap();
+ PortalNode node = parent.getParent();
+ while (node.getType() != PortalNode.TYPE_PORTAL)
+ {
+ parentsMap.put(localize(req.getLocale(), node.getName()),
resp.createRenderURL(node));
+ node = node.getParent();
+ }
+ req.setAttribute("parents", parentsMap);
+
+ try
+ {
+ req.setAttribute("parentNode", localize(req.getLocale(),
parent.getName()));
+
+ HashMap parentChildMap = new HashMap();
+ HashMap parentSiblingMap = new HashMap();
+ for (Iterator i = parent.getParent().getChildren().iterator(); i.hasNext();)
+ {
+ PortalNode parentSibling = (PortalNode)i.next();
+
+ // Display only sibling pages
+ if (parentSibling.getType() == PortalNode.TYPE_PAGE)
+ {
+ if (parentSibling.equals(parent))
+ {
+ for (Iterator j = parent.getChildren().iterator(); j.hasNext();)
+ {
+ PortalNode child = (PortalNode)j.next();
+ if (child.getType() == PortalNode.TYPE_PAGE)
+ {
+ boolean allowed = false;
+ // check if the current user is allowed to access this page
+ if (child instanceof PortalNodeImpl)
+ {
+ PortalNodeImpl pn = (PortalNodeImpl)child;
+ PortalObjectPermission perm = new
PortalObjectPermission(pn.getObjectId(), PortalObjectPermission.VIEW_MASK);
+ if
(portalAuthorizationManagerFactory.getManager().checkPermission(perm))
+ {
+ allowed = true;
+ }
+ else
+ {
+ allowed = false;
+ }
+ }
+ if (allowed)
+ {
+ PortalNodeURL childURL = resp.createRenderURL(child);
+ parentChildMap.put(localize(req.getLocale(), child.getName()),
childURL);
+ }
+ }
+ }
+ }
+ else
+ {
+ boolean allowed = false;
+ // check if the current user is allowed to access this page
+ if (parentSibling instanceof PortalNodeImpl)
+ {
+ PortalNodeImpl pn = (PortalNodeImpl)parentSibling;
+ PortalObjectPermission perm = new
PortalObjectPermission(pn.getObjectId(), PortalObjectPermission.VIEW_MASK);
+ if
(portalAuthorizationManagerFactory.getManager().checkPermission(perm))
+ {
+ allowed = true;
+ }
+ else
+ {
+ allowed = false;
+ }
+ }
+ if (allowed)
+ {
+ PortalNodeURL parentSiblingURL =
resp.createRenderURL(parentSibling);
+ parentSiblingMap.put(localize(req.getLocale(),
parentSibling.getName()), parentSiblingURL);
+ }
+ }
+ }
+ }
+ req.setAttribute("pchild", parentChildMap);
+ req.setAttribute("psib", parentSiblingMap);
+
+ PortletRequestDispatcher prd =
getPortletContext().getRequestDispatcher("/WEB-INF/jsp/catalog/index.jsp");
+ prd.include(req, resp);
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+// }
+ }
+
+ private String localize(Locale locale, String name)
+ {
+ try
+ {
+ ResourceBundle rb = ResourceBundle.getBundle("conf.bundles.Resource",
locale, Thread.currentThread().getContextClassLoader());
+ name = rb.getString(RESOURCE_PREFIX + name);
+ }
+ catch (MissingResourceException e)
+ {
+ }
+ return name;
+ }
+}
Property changes on:
trunk/core/src/main/org/jboss/portal/core/ui/portlet/catalog/CatalogPortlet.java
___________________________________________________________________
Name: svn:executable
+ *
Added: trunk/core/src/main/org/jboss/portal/core/ui/portlet/role/RolePortlet.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/core/ui/portlet/role/RolePortlet.java
(rev 0)
+++ trunk/core/src/main/org/jboss/portal/core/ui/portlet/role/RolePortlet.java 2007-06-11
11:31:36 UTC (rev 7395)
@@ -0,0 +1,958 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.core.ui.portlet.role;
+
+import org.jboss.logging.Logger;
+import org.jboss.portal.core.ui.portlet.PortletHelper;
+import org.jboss.portal.core.ui.portlet.user.UserPortletConstants;
+import org.jboss.portal.core.servlet.jsp.PortalJsp;
+import org.jboss.portal.core.servlet.jsp.taglib.context.DelegateContext;
+import org.jboss.portal.identity.IdentityException;
+import org.jboss.portal.identity.Role;
+import org.jboss.portal.identity.RoleModule;
+import org.jboss.portal.identity.User;
+import org.jboss.portal.identity.UserModule;
+import org.jboss.portal.identity.MembershipModule;
+import org.jboss.portal.identity.UserProfileModule;
+import org.jboss.portlet.JBossActionRequest;
+import org.jboss.portlet.JBossActionResponse;
+import org.jboss.portlet.JBossPortlet;
+import org.jboss.portlet.JBossRenderRequest;
+import org.jboss.portlet.JBossRenderResponse;
+
+import javax.portlet.PortletException;
+import javax.portlet.PortletRequestDispatcher;
+import javax.portlet.PortletSecurityException;
+import javax.portlet.PortletURL;
+import javax.portlet.WindowState;
+import javax.portlet.WindowStateException;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.Iterator;
+import java.util.Locale;
+import java.util.ResourceBundle;
+import java.util.Set;
+import java.util.HashSet;
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * This portlet aims at managing roles of users.
+ *
+ * @author <a href="mailto:noel.rocher@free.fr">Noel Rocher</a>
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @author <a href="mailto:theute@jboss.org">Thomas Heute </a>
+ * @author Roy Russo : roy at jboss dot org
+ * @version $Revision: 7343 $
+ */
+public class RolePortlet
+ extends JBossPortlet
+{
+ /** the class logger */
+ public static final Logger log = Logger.getLogger(JBossPortlet.class);
+
+ private PortletHelper portletHelper;
+
+ // Render op
+ public static final String OP_SHOWSUMMARY = "showSummary";
+
+ public static final String OP_SHOWCREATEROLE = "showCreateRole";
+
+ public static final String OP_SHOWEDITROLE = "showEditRole";
+
+ /** Main Edit role page where admins can filter */
+ public static final String OP_SHOWMAINROLEMEMBERS =
"showMainEditRoleMembers";
+
+ /** Edit role page where admins can edit the members individually. */
+ public static final String OP_SHOWLISTROLEMEMBERS =
"showListEditRoleMembers";
+
+ /** Render operation to show the screen to assign roles to a user */
+ public static final String OP_SHOWADDROLESTOUSER = "showAddRolesToUser";
+
+ private RoleModule roleModule;
+
+ private UserModule userModule;
+
+ private MembershipModule membershipModule;
+
+ private UserProfileModule userProfileModule;
+
+ private static final String ADMIN_ROLE = "Admin";
+
+ public void init() throws PortletException
+ {
+ super.init();
+ userModule = (UserModule)getPortletContext().getAttribute("UserModule");
+ roleModule = (RoleModule)getPortletContext().getAttribute("RoleModule");
+ portletHelper = new PortletHelper(this);
+ membershipModule =
(MembershipModule)getPortletContext().getAttribute("MembershipModule");
+ userProfileModule =
(UserProfileModule)getPortletContext().getAttribute("UserProfileModule");
+
+ //
+ if (userModule == null)
+ {
+ throw new PortletException("No user module");
+ }
+ if (roleModule == null)
+ {
+ throw new PortletException("No role module");
+ }
+ if (membershipModule == null)
+ {
+ throw new PortletException("No membership module");
+ }
+ if (userProfileModule == null)
+ {
+ throw new PortletException("No user profile module");
+ }
+
+
+ }
+
+ public void destroy()
+ {
+ super.destroy();
+
+ //
+ userModule = null;
+ roleModule = null;
+ portletHelper = null;
+ }
+
+ public String getDefaultOperation()
+ {
+ return OP_SHOWSUMMARY;
+ }
+
+ protected void doView(JBossRenderRequest req, JBossRenderResponse resp)
+ throws PortletException, PortletSecurityException, IOException
+ {
+
+ if (req.isUserInRole(ADMIN_ROLE))
+ {
+ resp.setContentType("text/html");
+ PrintWriter writer = resp.getWriter();
+
+ String op;
+ if (req.getWindowState() != WindowState.MAXIMIZED)
+ {
+ op = getDefaultOperation();
+ }
+ else
+ {
+ op = req.getParameters().get(getOperationName(),
+ getDefaultOperation());
+ }
+
+ Locale locale = req.getLocale();
+ ResourceBundle bundle = getResourceBundle(locale);
+ if (OP_SHOWSUMMARY.equals(op))
+ {
+ if (req.isUserInRole(ADMIN_ROLE))
+ {
+ DelegateContext ctx = new DelegateContext();
+ ctx.put("nbRoles", getNbRolesString(bundle));
+
+ DelegateContext roleCtx = null;
+ try
+ {
+ Set roles = roleModule.findRoles();
+ Iterator i = roles.iterator();
+ while (i.hasNext())
+ {
+ Role role = (Role)i.next();
+ roleCtx = ctx.next("role");
+ String roleId = role.getId().toString();
+ roleCtx.put("id", roleId);
+ roleCtx.put("displayname", role.getDisplayName());
+ }
+ }
+ catch (IdentityException e)
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ req.setAttribute(PortalJsp.CTX_REQUEST, ctx);
+ PortletRequestDispatcher rd = getPortletContext()
+ .getRequestDispatcher("/WEB-INF/jsp/role/menu.jsp");
+ rd.include(req, resp);
+ }
+ }
+ else if (OP_SHOWCREATEROLE.equals(op))
+ {
+ if (req.isUserInRole(ADMIN_ROLE))
+ {
+ PortletRequestDispatcher rd = getPortletContext()
+ .getRequestDispatcher("/WEB-INF/jsp/role/createRole.jsp");
+ rd.include(req, resp);
+ }
+ }
+ else if (OP_SHOWEDITROLE.equals(op))
+ {
+ if (req.isUserInRole(ADMIN_ROLE))
+ {
+ try
+ {
+ Set roles = roleModule.findRoles();
+ DelegateContext ctx = new DelegateContext();
+ ctx.put("editroleid", req.getParameter("roleid"));
+ ctx.put("editroledisplayname",
req.getParameter("roledisplayname"));
+ Iterator i = roles.iterator();
+ DelegateContext roleCtx = null;
+ while (i.hasNext())
+ {
+ Role role = (Role)i.next();
+ roleCtx = ctx.next("role");
+ String roleId = role.getId().toString();
+ roleCtx.put("id", roleId);
+ roleCtx.put("displayname", role.getDisplayName());
+ String selectedRoleId = req.getParameter("roleid");
+ if (roleId.equals(selectedRoleId))
+ {
+ roleCtx.put("selected", "selected");
+ }
+ }
+ req.setAttribute(PortalJsp.CTX_REQUEST, ctx);
+ }
+ catch (IdentityException e)
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ PortletRequestDispatcher rd = getPortletContext()
+ .getRequestDispatcher("/WEB-INF/jsp/role/editRole.jsp");
+ rd.include(req, resp);
+ }
+ }
+ else if (OP_SHOWMAINROLEMEMBERS.equals(op))
+ {
+ if (req.isUserInRole(ADMIN_ROLE))
+ {
+ try
+ {
+ Set roles = roleModule.findRoles();
+ DelegateContext ctx = new DelegateContext();
+ Iterator i = roles.iterator();
+ DelegateContext roleCtx = null;
+ while (i.hasNext())
+ {
+ Role role = (Role)i.next();
+ roleCtx = ctx.next("role");
+ String roleId = role.getId().toString();
+ roleCtx.put("id", roleId);
+ roleCtx.put("displayname", role.getDisplayName());
+ String selectedRoleId = req.getParameter("roleid");
+ if (roleId.equals(selectedRoleId))
+ {
+ roleCtx.put("selected", "selected");
+ }
+ }
+ req.setAttribute(PortalJsp.CTX_REQUEST, ctx);
+ }
+ catch (IdentityException e)
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ PortletRequestDispatcher rd = getPortletContext()
+
.getRequestDispatcher("/WEB-INF/jsp/role/editRoleMembers.jsp");
+ rd.include(req, resp);
+ }
+ }
+ else if (OP_SHOWLISTROLEMEMBERS.equals(op))
+ {
+ if (req.isUserInRole(ADMIN_ROLE))
+ {
+ try
+ {
+ String roleID = req.getParameters().getParameter("roleid");
+ Role role = roleModule.findRoleById(roleID);
+
+ DelegateContext ctx = new DelegateContext();
+ DelegateContext roleCtx = null;
+ roleCtx = ctx.next("role");
+ ctx.put("displayname", role.getDisplayName());
+
+ int offset = req.getParameters().getInt("offset", 0);
+ int usersPerPage = req.getParameters().getInt("usersperpage",
UserPortletConstants.DEFAULT_USERSPERPAGE);
+ String usernameFilter =
req.getParameters().get("usernamefilter", "");
+ ctx.put("usernameFilter", usernameFilter);
+
+ Set users = null;
+ users = membershipModule.findRoleMembers(role.getName(), offset,
usersPerPage + 1, usernameFilter.trim());
+
+ User[] usersArray = new User[users.size()];
+ usersArray = (User[])users.toArray(usersArray);
+
+ DelegateContext rowCtx = null;
+ for (int i = 0; i < Math.min(usersArray.length, usersPerPage); i++)
+ {
+ User user = usersArray[i];
+ rowCtx = ctx.next("row");
+ rowCtx.put("fullname", getFullName(bundle, user));
+ rowCtx.put("username", user.getUserName());
+
+ //
+ Iterator itRoles = membershipModule.getRoles(user).iterator();
+ while (itRoles.hasNext())
+ {
+ DelegateContext rolesCtx = rowCtx.next("roles");
+ rolesCtx.put("name",
((Role)itRoles.next()).getDisplayName());
+ }
+
+ PortletURL editURL = resp.createRenderURL();
+ editURL.setParameter(getOperationName(), OP_SHOWADDROLESTOUSER);
+ editURL.setParameter("userid", "" +
user.getId());
+ editURL.setParameter("roleid", "" +
role.getId());
+ editURL.setParameter("usernamefilter", usernameFilter);
+ editURL.setParameter("offset", "" + offset);
+ editURL.setParameter("usersperpage", "" +
usersPerPage);
+
+ rowCtx.put("editURL", editURL.toString());
+ }
+
+ if (offset != 0)
+ {
+ PortletURL previousPageLink = resp.createRenderURL();
+ previousPageLink.setParameter(getOperationName(),
OP_SHOWLISTROLEMEMBERS);
+ previousPageLink.setParameter("offset", "" +
Math.max(0, offset - usersPerPage));
+ previousPageLink.setParameter("usersperpage", ""
+ usersPerPage);
+ previousPageLink.setParameter("usernamefilter",
usernameFilter);
+ previousPageLink.setParameter("roleid", "" +
roleID);
+ DelegateContext previousCtx = ctx.next("previouspage");
+ previousCtx.put("link", previousPageLink.toString());
+ }
+
+ if (usersArray.length > usersPerPage)
+ {
+ PortletURL nextPageLink = resp.createRenderURL();
+ nextPageLink.setParameter(getOperationName(),
OP_SHOWLISTROLEMEMBERS);
+ nextPageLink.setParameter("offset", "" + (offset
+ usersPerPage));
+ nextPageLink.setParameter("usersperpage", "" +
usersPerPage);
+ nextPageLink.setParameter("usernamefilter",
usernameFilter);
+ nextPageLink.setParameter("roleid", "" +
roleID);
+ DelegateContext nextCtx = ctx.next("nextpage");
+ nextCtx.put("link", nextPageLink.toString());
+ }
+
+ try
+ {
+ Set roles = roleModule.findRoles();
+ Iterator i = roles.iterator();
+ DelegateContext roleCtxs = null;
+ while (i.hasNext())
+ {
+ Role arole = (Role)i.next();
+ roleCtxs = ctx.next("rolelist");
+ String aroleId = arole.getId().toString();
+ roleCtxs.put("id", aroleId);
+ roleCtxs.put("displayname", arole.getDisplayName());
+ if (aroleId.equals(roleID))
+ {
+ roleCtxs.put("selected", "selected");
+ }
+ }
+ }
+ catch (IdentityException e)
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ ctx.put("usernamefilter", usernameFilter);
+ req.setAttribute(PortalJsp.CTX_REQUEST, ctx);
+ }
+ catch (IdentityException e)
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ PortletRequestDispatcher rd = getPortletContext()
+
.getRequestDispatcher("/WEB-INF/jsp/role/editListRoleMembers.jsp");
+ rd.include(req, resp);
+ }
+ }
+ else if (OP_SHOWADDROLESTOUSER.equals(op))
+ {
+ if (req.isUserInRole(ADMIN_ROLE))
+ {
+ DelegateContext ctx = new DelegateContext();
+
+ try
+ {
+ ctx.put("usernamefilter",
req.getParameter("usernamefilter"));
+ ctx.put("offset", req.getParameter("offset"));
+ ctx.put("usersperpage",
req.getParameter("usersperpage"));
+ ctx.put("roleid", req.getParameter("roleid"));
+
+
+ User user =
userModule.findUserById(req.getParameter("userid"));
+
+ ctx.put("userid", user.getId().toString());
+ ctx.put("username", user.getUserName());
+ ctx.put("userfullname", getFullName(bundle, user));
+ Set userRoles = membershipModule.getRoles(user);
+
+ //old stuff
+ Set roles = roleModule.findRoles();
+ Role[] rolesArray = new Role[roles.size()];
+ //rolesArray = (Role[])roles.toArray(rolesArray);
+ Role role = null;
+
+ DelegateContext allRolesCtx = null;
+ for (Iterator it = roles.iterator(); it.hasNext();)
+ {
+ role = (Role)it.next();
+ allRolesCtx = ctx.next("allRoles");
+
+ allRolesCtx.put("name", role.getName());
+ allRolesCtx.put("displayname", role.getDisplayName());
+ }
+
+ DelegateContext userRolesCtx = null;
+
+ if
(!req.getParameterMap().keySet().contains("selectedRoles"))
+ {
+ for (Iterator it = userRoles.iterator(); it.hasNext();)
+ {
+ role = (Role)it.next();
+ userRolesCtx = ctx.next("userRoles");
+
+ userRolesCtx.put("name", role.getName());
+ userRolesCtx.put("displayname",
role.getDisplayName());
+ }
+ }
+ else
+ {
+ String[] selectedRoles =
req.getParameterValues("selectedRoles");
+ for (int i = 0; i < selectedRoles.length; i++)
+ {
+ String selectedRole = selectedRoles[i];
+ role = roleModule.findRoleByName(selectedRole);
+
+ userRolesCtx = ctx.next("userRoles");
+
+ userRolesCtx.put("name", role.getName());
+ userRolesCtx.put("displayname",
role.getDisplayName());
+ }
+ }
+
+ }
+ catch (IllegalArgumentException e)
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ catch (IdentityException e)
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ req.setAttribute(PortalJsp.CTX_REQUEST, ctx);
+ PortletRequestDispatcher rd =
getPortletContext().getRequestDispatcher("/WEB-INF/jsp/role/editUserRoles.jsp");
+ rd.include(req, resp);
+ }
+ }
+ else
+ {
+ log.error("This operation does not exist when user is logged in:"
+ + op);
+ }
+ writer.close();
+ }
+ else
+ {
+ forbidden(req, resp);
+ }
+ }
+
+ public void showListEditRoleMembers(JBossActionRequest req, JBossActionResponse resp)
throws WindowStateException
+ {
+ resp.setRenderParameter(getOperationName(), OP_SHOWLISTROLEMEMBERS);
+ resp.setRenderParameter("roleid", req.getParameter("roleid"));
+ resp.setRenderParameter("usersperpage",
req.getParameter("usersperpage"));
+ resp.setRenderParameter("usernamefilter",
req.getParameter("usernamefilter"));
+ resp.setWindowState(WindowState.MAXIMIZED);
+ }
+
+ /**
+ * Handles permissions errors on doView.
+ *
+ * @param rReq
+ * @param rRes
+ * @throws javax.portlet.PortletException
+ * @throws IOException
+ */
+ private void forbidden(javax.portlet.RenderRequest rReq, javax.portlet.RenderResponse
rRes) throws javax.portlet.PortletException, IOException
+ {
+ rRes.setContentType("text/html");
+ javax.portlet.PortletRequestDispatcher prd =
getPortletContext().getRequestDispatcher("/WEB-INF/jsp/permission/forbidden.jsp");
+ prd.include(rReq, rRes);
+ }
+
+ public void createRole(JBossActionRequest req, JBossActionResponse resp)
+ {
+ if (req.isUserInRole(ADMIN_ROLE))
+ {
+
+ String roleName = req.getParameter("rolename");
+ String roleDisplayName = req.getParameter("roledisplayname");
+ if ((roleName != null) && (roleDisplayName != null)
+ && (roleName.length() != 0) && (roleDisplayName.length() !=
0))
+ {
+ if (roleByDisplayNameAvailable(roleDisplayName)
+ && roleByNameAvailable(roleName))
+ {
+ try
+ {
+ roleModule.createRole(roleName, roleDisplayName);
+/*
+ try
+ {
+*/
+ resp.setRenderParameter(getOperationName(),
+ getDefaultOperation());
+/*
+ resp.setWindowState(WindowState.NORMAL);
+ }
+ catch (WindowStateException e1)
+ {
+ log.error("Couldn't put the window in normal state");
+ }
+*/
+ }
+ catch (IllegalArgumentException e)
+ {
+ log.error("Cannot create role, rolename is null");
+ e.printStackTrace();
+ }
+ catch (IdentityException e)
+ {
+ log.error("Cannot create role \"" + roleName
+ + "\", unexpected error");
+ e.printStackTrace();
+ }
+ }
+ else
+ {
+ if (!roleByDisplayNameAvailable(roleDisplayName))
+ {
+ // Role with that display name already exists !
+ portletHelper.setRenderParameter(resp, "rolename",
roleName);
+ portletHelper.setRenderParameter(resp, "roledisplayname",
+ roleDisplayName);
+ resp.setRenderParameter("roledisplayname_error",
+ "ROLE_ERROR_DISPLAYNAMEALREADYEXISTS");
+ resp.setRenderParameter(getOperationName(),
+ getDefaultOperation());
+ }
+ else if (!roleByNameAvailable(roleName))
+ {
+ // Role with that name already exists !
+ portletHelper.setRenderParameter(resp, "rolename",
roleName);
+ portletHelper.setRenderParameter(resp, "roledisplayname",
+ roleDisplayName);
+ resp.setRenderParameter("rolename_error",
+ "ROLE_ERROR_NAMEALREADYEXISTS");
+ resp.setRenderParameter(getOperationName(),
+ getDefaultOperation());
+ }
+ }
+ }
+ else
+ {
+ // Role name or displayname empty
+ portletHelper.setRenderParameter(resp, "rolename", roleName);
+ portletHelper.setRenderParameter(resp, "roledisplayname",
+ roleDisplayName);
+ if (roleName == null || roleName.length() == 0)
+ {
+ resp
+ .setRenderParameter("rolename_error",
+ "ROLE_ERROR_NAMEEMPTY");
+ }
+ if (roleDisplayName == null || roleDisplayName.length() == 0)
+ {
+ resp.setRenderParameter("roledisplayname_error",
+ "ROLE_ERROR_DISPLAYNAMEEMPTY");
+ }
+ resp.setRenderParameter(getOperationName(),
+ getDefaultOperation());
+ }
+ }
+ }
+
+ /**
+ * Action to edit a role
+ *
+ * @param req
+ * @param resp
+ */
+ public void editRole(JBossActionRequest req, JBossActionResponse resp) throws
WindowStateException
+ {
+ if (req.isUserInRole(ADMIN_ROLE))
+ {
+ String roleID = req.getParameters().getParameter("roleid");
+ String newDisplayName = req.getParameter("roledisplayname");
+ Role role = null;
+ try
+ {
+ role = roleModule.findRoleById(roleID);
+ // Check that the new display name is available
+ if (!"".equals(newDisplayName))
+ {
+ if (roleByDisplayNameAvailable(newDisplayName))
+ {
+ role.setDisplayName(newDisplayName);
+ }
+ else
+ // The display name is not available, go back to the prefilled form
+ {
+ portletHelper.setRenderParameter(resp, "roledisplayname",
+ newDisplayName);
+ portletHelper.setRenderParameter(resp, "roleid", roleID);
+ resp.setRenderParameter("roledisplayname_error",
+ "ROLE_ERROR_DISPLAYNAMEALREADYEXISTS");
+ resp.setRenderParameter(getOperationName(), OP_SHOWEDITROLE);
+ }
+ }
+ else
+ {
+ portletHelper.setRenderParameter(resp, "roledisplayname",
+ newDisplayName);
+ portletHelper.setRenderParameter(resp, "roleid", roleID);
+ resp.setRenderParameter("roledisplayname_error",
+ "ROLE_ERROR_NAMEEMPTY");
+ resp.setRenderParameter(getOperationName(), OP_SHOWEDITROLE);
+ }
+ }
+ catch (IllegalArgumentException e)
+ {
+ log.error("Cannot update role: roleID is null");
+ e.printStackTrace();
+ }
+ catch (IdentityException e)
+ {
+ log.error("Cannot update role, unexpected error");
+ e.printStackTrace();
+ }
+ }
+ }
+
+ /**
+ * Adds or Removes roles from a user.
+ *
+ * @param request
+ * @param response
+ */
+ public void addRolesToUser(JBossActionRequest request, JBossActionResponse response)
+ {
+
+ if (request.isUserInRole(ADMIN_ROLE))
+ {
+ String userId = request.getParameters().getParameter("userid");
+
+ response.setRenderParameter("usernamefilter",
request.getParameter("usernamefilter"));
+ response.setRenderParameter("offset",
request.getParameter("offset"));
+ response.setRenderParameter("roleid",
request.getParameter("roleid"));
+ response.setRenderParameter("usersperpage",
request.getParameter("usersperpage"));
+
+ if (request.getParameterMap().keySet().contains("addRoles"))
+ {
+ String[] selectedRoles =
request.getParameterValues("assignedRoles");
+ String[] rolesToAdd = request.getParameterValues("rolesToAdd");
+
+ if (selectedRoles == null)
+ {
+ selectedRoles = new String[]{};
+ }
+ if (rolesToAdd == null)
+ {
+
+ if (selectedRoles.length != 0)
+ {
+ response.setRenderParameter("selectedRoles", selectedRoles);
+ }
+
+ response.setRenderParameter("op", OP_SHOWADDROLESTOUSER );
+ response.setRenderParameter("userid", userId);
+ return;
+ }
+
+
+ Set roles = new HashSet();
+ List l1 = Arrays.asList(selectedRoles);
+ List l2 = Arrays.asList(rolesToAdd);
+ roles.addAll(l1);
+ roles.addAll(l2);
+
+ String[] roleNames = new String[roles.size()];
+ roleNames = (String[])roles.toArray(roleNames);
+
+ response.setRenderParameter("selectedRoles", roleNames);
+ response.setRenderParameter("op", OP_SHOWADDROLESTOUSER );
+ response.setRenderParameter("userid", userId);
+ }
+ else if (request.getParameterMap().keySet().contains("removeRoles"))
+ {
+
+ String[] selectedRoles =
request.getParameterValues("assignedRoles");
+ String[] rolesToRemove =
request.getParameterValues("selectedRoles");
+
+ if (selectedRoles == null)
+ {
+ selectedRoles = new String[]{};
+ }
+
+ if (rolesToRemove == null)
+ {
+ if (selectedRoles.length != 0)
+ {
+ response.setRenderParameter("selectedRoles", selectedRoles);
+ }
+
+ response.setRenderParameter("op", OP_SHOWADDROLESTOUSER );
+ response.setRenderParameter("userid", userId);
+ return;
+ }
+
+ List toRemove = Arrays.asList(rolesToRemove);
+
+ Set roles = new HashSet();
+
+ for (int i = 0; i < selectedRoles.length; i++)
+ {
+ String selectedRole = selectedRoles[i];
+
+ if (!toRemove.contains(selectedRole))
+ {
+ roles.add(selectedRole);
+ }
+ }
+
+ String[] roleNames = new String[roles.size()];
+ roleNames = (String[])roles.toArray(roleNames);
+
+ if (roleNames.length != 0)
+ {
+ response.setRenderParameter("selectedRoles", roleNames);
+ }
+
+ response.setRenderParameter("op", OP_SHOWADDROLESTOUSER );
+ response.setRenderParameter("userid", userId);
+ }
+ else
+ {
+
+ String[] selectedRoles =
request.getParameterValues("assignedRoles");
+
+ try
+ {
+ User user = userModule.findUserById(userId);
+ Set roles = roleModule.findRolesByNames(selectedRoles);
+ membershipModule.assignRoles(user, roles);
+
+ response.setRenderParameter("op", OP_SHOWLISTROLEMEMBERS );
+ response.setRenderParameter("userid", userId);
+ }
+ catch (IllegalArgumentException e)
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ catch (IdentityException e)
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+
+ /**
+ * Action to delete a role
+ *
+ * @param req
+ * @param resp
+ */
+ public void removeRole(JBossActionRequest req, JBossActionResponse resp)
+ {
+
+
+ if (req.isUserInRole(ADMIN_ROLE))
+ {
+ String roleId = req.getParameters().getParameter("roleid");
+ try
+ {
+ Role role = roleModule.findRoleById(roleId);
+ roleModule.removeRole(role.getId());
+ resp.setRenderParameter("roledelete_error",
"ROLE_DELETED");
+ resp.setRenderParameter(getOperationName(), OP_SHOWEDITROLE);
+ }
+ catch (IdentityException e)
+ {
+ log.error("Cannot remove role, unexpected error", e);
+ portletHelper.setRenderParameter(resp, "roleid", roleId);
+ resp.setRenderParameter("roledelete_error",
"ROLE_ERROR_DELETE_FAILED");
+ resp.setRenderParameter(getOperationName(), OP_SHOWEDITROLE);
+ }
+ }
+ }
+
+ /**
+ * Returns true if the role with display name in argument is available
+ *
+ * @param name Display name of the role to check
+ * @return true if the display name is available
+ */
+ private boolean roleByDisplayNameAvailable(String name)
+ {
+ try
+ {
+ for (Iterator i = roleModule.findRoles().iterator(); i.hasNext();)
+ {
+ Role role = (Role)i.next();
+ if (role.getDisplayName() != null &&
role.getDisplayName().equals(name))
+ {
+ return false;
+ }
+ }
+ }
+ catch (IdentityException e)
+ {
+ return false;
+ }
+ return true;
+ }
+
+ /** Returns true if the role with name in argument is available */
+ private boolean roleByNameAvailable(String name)
+ {
+ Role role = null;
+ try
+ {
+ role = roleModule.findRoleByName(name);
+ //in case that exception was not thrown
+ if (role == null)
+ {
+ return true;
+ }
+ }
+ catch (IllegalArgumentException e)
+ {
+ e.printStackTrace();
+ }
+ catch (IdentityException e)
+ {
+ return true;
+ }
+ return false;
+ }
+
+ /** Return a localized sentence stating the number of existing roles */
+ private String getNbRolesString(ResourceBundle bundle)
+ {
+ StringBuffer buffer = new StringBuffer();
+ int nbRoles = 0;
+ try
+ {
+ nbRoles = roleModule.getRolesCount();
+ }
+ catch (IllegalArgumentException e)
+ {
+ e.printStackTrace();
+ }
+ catch (IdentityException e)
+ {
+ e.printStackTrace();
+ }
+ if (nbRoles <= 1)
+ {
+ buffer.append(bundle.getString("ROLE_THEREIS")).append("
");
+ if (nbRoles == 0)
+ {
+ buffer.append("no");
+ }
+ else
+ {
+ buffer.append("1");
+ }
+ buffer.append("
").append(bundle.getString("ROLE_ROLEDEFINED"));
+ }
+ else
+ {
+ buffer.append(bundle.getString("ROLE_THEREARE")).append("
");
+ buffer.append(nbRoles);
+ buffer.append("
").append(bundle.getString("ROLE_ROLESDEFINED"));
+ }
+ return buffer.toString();
+ }
+
+ /**
+ * This is a helper method extracted from the userPortlet that returns the user's
fullname.
+ *
+ * @param bundle
+ * @param user
+ */
+ private String getFullName(ResourceBundle bundle,
+ User user)
+ {
+ String givenName = null;
+ String familyName = null;
+
+ try
+ {
+ givenName = (String)userProfileModule.getProperty(user,
User.INFO_USER_NAME_GIVEN);
+ familyName = (String)userProfileModule.getProperty(user,
User.INFO_USER_NAME_FAMILY);
+ }
+ catch (IdentityException e)
+ {
+ log.error("cannot obtain user profile information: ", e);
+ }
+
+ if ((givenName != null) && (givenName.trim().length() != 0))
+ {
+ if ((familyName != null) && (familyName.trim().length() != 0))
+ {
+ return givenName + " " + familyName;
+ }
+ else
+ {
+ return givenName.trim();
+ }
+ }
+ else
+ {
+ if ((familyName != null) && (familyName.trim().length() != 0))
+ {
+ return familyName.trim();
+ }
+ else
+ {
+ return bundle.getString("NAMENOTAVAILABLE");
+ }
+ }
+ }
+}
\ No newline at end of file
Property changes on:
trunk/core/src/main/org/jboss/portal/core/ui/portlet/role/RolePortlet.java
___________________________________________________________________
Name: svn:executable
+ *
Added: trunk/core/src/main/org/jboss/portal/core/ui/portlet/user/UserPortlet.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/core/ui/portlet/user/UserPortlet.java
(rev 0)
+++ trunk/core/src/main/org/jboss/portal/core/ui/portlet/user/UserPortlet.java 2007-06-11
11:31:36 UTC (rev 7395)
@@ -0,0 +1,1484 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.core.ui.portlet.user;
+
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Locale;
+import java.util.Map;
+import java.util.ResourceBundle;
+import java.util.Set;
+import java.util.List;
+import java.util.Arrays;
+
+import javax.portlet.PortletException;
+import javax.portlet.PortletRequestDispatcher;
+import javax.portlet.PortletSecurityException;
+import javax.portlet.PortletURL;
+import javax.portlet.WindowState;
+import javax.portlet.WindowStateException;
+
+import org.jboss.logging.Logger;
+import org.jboss.portal.api.node.PortalNode;
+import org.jboss.portal.api.node.PortalNodeURL;
+import org.jboss.portal.common.p3p.P3PConstants;
+import org.jboss.portal.common.util.Tools;
+import org.jboss.portal.common.net.URLTools;
+import org.jboss.portal.common.util.ConversionException;
+import org.jboss.portal.common.i18n.LocaleFormat;
+import org.jboss.portal.common.i18n.LocaleManager;
+import org.jboss.portal.core.aspects.controller.node.Navigation;
+import org.jboss.portal.core.modules.MailModule;
+import org.jboss.portal.core.ui.portlet.PortletHelper;
+import org.jboss.portal.core.servlet.jsp.PortalJsp;
+import org.jboss.portal.core.servlet.jsp.taglib.context.DelegateContext;
+import org.jboss.portal.identity.IdentityException;
+import org.jboss.portal.identity.MembershipModule;
+import org.jboss.portal.identity.Role;
+import org.jboss.portal.identity.RoleModule;
+import org.jboss.portal.identity.User;
+import org.jboss.portal.identity.UserModule;
+import org.jboss.portal.identity.UserProfileModule;
+import org.jboss.portal.theme.PortalTheme;
+import org.jboss.portal.theme.ThemeInfo;
+import org.jboss.portal.theme.ThemeService;
+import org.jboss.portlet.JBossActionRequest;
+import org.jboss.portlet.JBossActionResponse;
+import org.jboss.portlet.JBossPortlet;
+import org.jboss.portlet.JBossRenderRequest;
+import org.jboss.portlet.JBossRenderResponse;
+
+import freemarker.template.Configuration;
+import freemarker.template.Template;
+import freemarker.template.TemplateException;
+
+/**
+ * This portlet aims at managing users
+ *
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @author <a href="mailto:theute@jboss.org">Thomas Heute </a>
+ * @author <a href="mailto:mageshbk@jboss.com">Magesh Kumar
Bojan</a>
+ * @version $Revision: 7379 $
+ */
+public class UserPortlet
+ extends JBossPortlet
+{
+
+ /** The class logger. */
+ public static final Logger log = Logger.getLogger(JBossPortlet.class);
+
+ /** Render operation to show the login screen. */
+ public static final String OP_SHOWLOGIN = "showLogin";
+
+ /** Render operation to show the register screen. */
+ public static final String OP_SHOWREGISTER = "showRegister";
+
+ /** Render operation to show the register thankyou screen. */
+ public static final String OP_SHOWREGISTER_TY = "showRegisterty";
+
+ /** Render operation to show the user menu screen. */
+ public static final String OP_SHOWMENU = "showMenu";
+
+ /** Render operation to show the user profile to edit. */
+ public static final String OP_SHOWPROFILE = "showProfile";
+
+ /** Render operation to show the screen to assign roles to a user. */
+ public static final String OP_SHOWADDROLESTOUSER = "showAddRolesToUser";
+
+ /** Render operation to show the list of users. */
+ public static final String OP_SHOWLISTUSERS = "showListUsers";
+
+ /** Logout the user. */
+ public static final String OP_USERLOGOUT = "userLogout";
+
+ /** Deletes the user */
+ public static final String OP_DELETEUSER = "deleteUser";
+
+ /** Activate the user via email link */
+ public static final String OP_ACTIVATEUSER = "activate";
+
+ private UserModule userModule;
+ private RoleModule roleModule;
+ private MembershipModule membershipModule;
+ private UserProfileModule userProfileModule;
+ private MailModule mailModule;
+ private PortletHelper portletHelper;
+ public static final short UNDEFINED_TIMEZONE = (short)0;
+
+ /**
+ * init method of the portlet, Setting up the diffrent modules used.
+ *
+ * @throws PortletException If a module cannot be looked up.
+ */
+ public void init()
+ throws PortletException
+ {
+ super.init();
+
+ //
+ userModule = (UserModule)getPortletContext().getAttribute("UserModule");
+ roleModule = (RoleModule)getPortletContext().getAttribute("RoleModule");
+ membershipModule =
(MembershipModule)getPortletContext().getAttribute("MembershipModule");
+ userProfileModule =
(UserProfileModule)getPortletContext().getAttribute("UserProfileModule");
+ mailModule = (MailModule)getPortletContext().getAttribute("MailModule");
+ portletHelper = new PortletHelper(this);
+
+ //
+ if (userModule == null)
+ {
+ throw new PortletException("No user module");
+ }
+ if (roleModule == null)
+ {
+ throw new PortletException("No role module");
+ }
+ if (mailModule == null)
+ {
+ throw new PortletException("No mail module");
+ }
+ if (membershipModule == null)
+ {
+ throw new PortletException("No membership module");
+ }
+ if (userProfileModule == null)
+ {
+ throw new PortletException("No user profile module");
+ }
+ }
+
+ public void destroy()
+ {
+ super.destroy();
+
+ //
+ userModule = null;
+ roleModule = null;
+ mailModule = null;
+ portletHelper = null;
+ }
+
+ public String getDefaultOperation()
+ {
+ return OP_SHOWLOGIN;
+ }
+
+ /**
+ * doView method
+ *
+ * @param req Render request
+ * @param resp render response
+ * @throws PortletException DOCUMENT_ME
+ * @throws PortletSecurityException DOCUMENT_ME
+ * @throws IOException DOCUMENT_ME
+ */
+ protected void doView(JBossRenderRequest req, JBossRenderResponse resp)
+ throws PortletException,
+ PortletSecurityException,
+ IOException
+ {
+ String op;
+ resp.setContentType("text/html");
+ PrintWriter writer = resp.getWriter();
+/*
+ if (req.getRemoteUser() == null)
+ {
+ req.getPortletSession().invalidate();
+ PortletRequestDispatcher rd =
getPortletContext().getRequestDispatcher("/WEB-INF/jsp/user/login.jsp");
+ PortalNode currentNode = req.getPortalNode();
+ PortalNodeURL url = resp.createRenderURL(currentNode);
+ url.setAuthenticated(Boolean.TRUE);
+ if
("1".equals(getPortletConfig().getInitParameter("useSSL")))
+ {
+ url.setSecure(Boolean.TRUE);
+ req.setAttribute("secureURL", url.toString());
+ }
+ url.setSecure(null);
+ req.setAttribute("URL", url.toString());
+ rd.include(req, resp);
+ return;
+ }
+*/
+ if (req.getRemoteUser() != null)
+ {
+ if (req.getWindowState() != WindowState.MAXIMIZED)
+ {
+ op = OP_SHOWMENU;
+ }
+ else
+ {
+ op = req.getParameters().get(getOperationName(),
+ OP_SHOWMENU);
+ // Because of the automatic redirection
+ if (op.equals(OP_SHOWLOGIN))
+ {
+ op = OP_SHOWMENU;
+ }
+ }
+
+ Locale requestLocale = req.getLocale();
+ ResourceBundle bundle = getResourceBundle(requestLocale);
+ if (OP_SHOWPROFILE.equals(op))
+ {
+ String userid = req.getParameters().getParameter("userid");
+ User user = null;
+ if (userid != null)
+ {
+ try
+ {
+ user = userModule.findUserById(userid);
+ }
+ catch (Exception e)
+ {
+ log.error("Cannot retrive user", e);
+ }
+ }
+ else
+ {
+ user = req.getUser();
+ try
+ {
+ user = userModule.findUserById(user.getId());
+ }
+ catch (IdentityException e)
+ {
+ log.error("Cannot retrive user", e);
+ }
+ }
+
+ // Validate we have a user object
+ if (user == null)
+ {
+ throw new PortletException("Not user object found");
+ }
+
+ //
+ DelegateContext ctx = new DelegateContext();
+
+ //
+ ctx.put("userid", user.getId().toString());
+ fillContextWithUserProfile(user, ctx);
+
+ //
+ //String selectedTimeZone =
(String)user.getProfile().get(User.INFO_USER_TIME_ZONE_OFFSET);
+ String selectedTimeZone = (String)getProperty(user,
User.INFO_USER_TIME_ZONE_OFFSET);
+ for (int i = 0; i < UserPortletConstants.TIME_ZONE_OFFSETS.length; i++)
+ {
+ if (UserPortletConstants.TIME_ZONE_OFFSETS[i] != null)
+ {
+ DelegateContext timeZoneCtx = ctx.next("timezone");
+ timeZoneCtx.put("name",
UserPortletConstants.TIME_ZONE_OFFSETS[i]);
+ timeZoneCtx.put("id", "" + i);
+ if (selectedTimeZone != null &&
selectedTimeZone.equals("" + i))
+ {
+ timeZoneCtx.put("selected", "selected");
+ }
+ }
+ }
+
+ //
+ //String selectedLocale =
(String)user.getProfile().get(User.INFO_USER_LOCALE);
+ String selectedLocale = (String)getProperty(user, User.INFO_USER_LOCALE);
+
+ ArrayList locales = new ArrayList(LocaleManager.getLocales());
+ Collections.sort(locales, new LocaleComparator());
+
+ for (Iterator i = locales.iterator(); i.hasNext();)
+ {
+ Locale locale = (Locale)i.next();
+ DelegateContext localeCtx = ctx.next("locale");
+ localeCtx.put("name", locale.getDisplayName(requestLocale));
+ String localeString = locale.toString();
+ localeCtx.put("id", localeString);
+ if (selectedLocale != null &&
selectedLocale.equals(localeString))
+ {
+ localeCtx.put("selected", "selected");
+ }
+ }
+
+ //
+ //String selectedTheme =
(String)user.getProfile().get(User.INFO_USER_THEME);
+ String selectedTheme = (String)getProperty(user,User.INFO_USER_THEME);
+ ThemeService themeService =
(ThemeService)getPortletContext().getAttribute("ThemeService");
+ for (Iterator i = themeService.getThemes().iterator(); i.hasNext();)
+ {
+ PortalTheme theme = (PortalTheme)i.next();
+ ThemeInfo info = theme.getThemeInfo();
+ DelegateContext themeCtx = ctx.next("theme");
+ themeCtx.put("name", info.getAppId() + "." +
info.getName());
+ themeCtx.put("id", info.getRegistrationId().toString());
+ if ((selectedTheme != null) &&
selectedTheme.equals(info.getRegistrationId().toString()))
+ {
+ themeCtx.put("selected", "selected");
+ }
+ }
+
+ //
+ req.setAttribute(PortalJsp.CTX_REQUEST, ctx);
+ resp.setTitle(bundle.getString("REGISTER_PERSONALINFO"));
+ PortletRequestDispatcher rd =
getPortletContext().getRequestDispatcher("/WEB-INF/jsp/user/editProfile.jsp");
+ rd.include(req, resp);
+ }
+ else if (OP_SHOWMENU.equals(op))
+ {
+ DelegateContext ctx = new DelegateContext();
+ if (req.isUserInRole("Admin"))
+ {
+ ctx.next("admin");
+ }
+ if (req.getParameter("modifiedProfile") != null)
+ {
+ ctx.next("modifiedProfile");
+ }
+ req.setAttribute(PortalJsp.CTX_REQUEST, ctx);
+ PortletRequestDispatcher rd =
getPortletContext().getRequestDispatcher("/WEB-INF/jsp/user/menu.jsp");
+ rd.include(req, resp);
+
+ }
+ else if (OP_SHOWLISTUSERS.equals(op))
+ {
+ if (req.isUserInRole("Admin"))
+ {
+ try
+ {
+ int offset = req.getParameters().getInt("offset", 0);
+ int usersPerPage = req.getParameters().getInt("usersperpage",
UserPortletConstants.DEFAULT_USERSPERPAGE);
+ String usernameFilter =
req.getParameters().get("usernamefilter", "");
+
+ // We get usersPerPage + 1 entries so we can know if there is
+ // a next page
+ // It's tricky but it avoids to make 2 queries.
+ Set users;
+ if (usernameFilter.trim().length() == 0)
+ {
+ users = userModule.findUsers(offset, usersPerPage + 1);
+ }
+ else
+ {
+ users = userModule.findUsersFilteredByUserName(usernameFilter,
offset, usersPerPage + 1);
+ }
+
+ User[] usersArray = new User[users.size()];
+ usersArray = (User[])users.toArray(usersArray);
+ DelegateContext ctx = new DelegateContext();
+
+ DelegateContext rowCtx = null;
+ for (int i = 0; i < Math.min(usersArray.length, usersPerPage); i++)
+ {
+ User user = usersArray[i];
+ rowCtx = ctx.next("row");
+ rowCtx.put("firstname", getFirstName(bundle, user));
+ rowCtx.put("lastname", getLastName(bundle, user));
+ rowCtx.put("username", user.getUserName());
+ if (i % 2 == 0)
+ {
+ rowCtx.put("css-class",
"portlet-table-text");
+ }
+ else
+ {
+ rowCtx.put("cssClass",
"portlet-table-alternate");
+ }
+
+ //
+ Iterator itRoles = membershipModule.getRoles(user).iterator();
+ while (itRoles.hasNext())
+ {
+ DelegateContext rolesCtx = rowCtx.next("roles");
+ rolesCtx.put("name",
((Role)itRoles.next()).getDisplayName());
+ }
+
+ PortletURL editURL = resp.createRenderURL();
+ editURL.setParameter(getOperationName(), OP_SHOWPROFILE);
+ editURL.setParameter("userid", "" +
user.getId());
+
+ PortletURL rolesURL = resp.createRenderURL();
+ rolesURL.setParameter(getOperationName(), OP_SHOWADDROLESTOUSER);
+ rolesURL.setParameter("userid", "" +
user.getId());
+ rolesURL.setParameter("usernamefilter", usernameFilter);
+ rolesURL.setParameter("offset", "" + offset);
+ rolesURL.setParameter("usersperpage", "" +
usersPerPage);
+
+ PortletURL deleteUrl = resp.createActionURL();
+ deleteUrl.setParameter(getOperationName(), OP_DELETEUSER);
+ deleteUrl.setParameter("userid", "" +
user.getId());
+
+ rowCtx.put("editURL", editURL.toString());
+ rowCtx.put("rolesURL", rolesURL.toString());
+ rowCtx.put("deleteURL", deleteUrl.toString());
+ }
+
+ if (offset != 0)
+ {
+ PortletURL previousPageLink = resp.createRenderURL();
+ previousPageLink.setParameter(getOperationName(),
OP_SHOWLISTUSERS);
+ previousPageLink.setParameter("offset", "" +
Math.max(0, offset - usersPerPage));
+ previousPageLink.setParameter("usersperpage", ""
+ usersPerPage);
+ previousPageLink.setParameter("usernamefilter",
usernameFilter);
+ DelegateContext previousCtx = ctx.next("previouspage");
+ previousCtx.put("link", previousPageLink.toString());
+ }
+
+ if (usersArray.length > usersPerPage)
+ {
+ PortletURL nextPageLink = resp.createRenderURL();
+ nextPageLink.setParameter(getOperationName(), OP_SHOWLISTUSERS);
+ nextPageLink.setParameter("offset", "" + (offset
+ usersPerPage));
+ nextPageLink.setParameter("usersperpage", "" +
usersPerPage);
+ nextPageLink.setParameter("usernamefilter",
usernameFilter);
+ DelegateContext nextCtx = ctx.next("nextpage");
+ nextCtx.put("link", nextPageLink.toString());
+ }
+
+ ctx.put("usernamefilter", usernameFilter);
+ ctx.put("results", users.size() + "");
+ req.setAttribute(PortalJsp.CTX_REQUEST, ctx);
+ }
+ catch (IllegalArgumentException e)
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ catch (IdentityException e)
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ PortletRequestDispatcher rd =
getPortletContext().getRequestDispatcher("/WEB-INF/jsp/user/listUsers.jsp");
+ rd.include(req, resp);
+ }
+ }
+ else if (OP_SHOWADDROLESTOUSER.equals(op))
+ {
+ if (req.isUserInRole("Admin"))
+ {
+ DelegateContext ctx = new DelegateContext();
+
+ ctx.put("usernamefilter",
req.getParameter("usernamefilter"));
+ ctx.put("offset", req.getParameter("offset"));
+ ctx.put("usersperpage",
req.getParameter("usersperpage"));
+
+ try
+ {
+ User user =
userModule.findUserById(req.getParameter("userid"));
+ ctx.put("userid", user.getId().toString());
+ ctx.put("username", user.getUserName());
+ ctx.put("userfullname", getFullName(bundle, user));
+ Set userRoles = membershipModule.getRoles(user);
+
+ Set roles = roleModule.findRoles();
+
+
+ Role role = null;
+
+
+
+ DelegateContext allRolesCtx = null;
+ for (Iterator it = roles.iterator(); it.hasNext();)
+ {
+ role = (Role)it.next();
+ allRolesCtx = ctx.next("allRoles");
+
+ allRolesCtx.put("name", role.getName());
+ allRolesCtx.put("displayname", role.getDisplayName());
+ }
+
+ DelegateContext userRolesCtx = null;
+
+ if
(!req.getParameterMap().keySet().contains("selectedRoles"))
+ {
+ for (Iterator it = userRoles.iterator(); it.hasNext();)
+ {
+ role = (Role)it.next();
+ userRolesCtx = ctx.next("userRoles");
+
+ userRolesCtx.put("name", role.getName());
+ userRolesCtx.put("displayname",
role.getDisplayName());
+ }
+ }
+ else
+ {
+ String[] selectedRoles =
req.getParameterValues("selectedRoles");
+ for (int i = 0; i < selectedRoles.length; i++)
+ {
+ String selectedRole = selectedRoles[i];
+ role = roleModule.findRoleByName(selectedRole);
+
+ userRolesCtx = ctx.next("userRoles");
+
+ userRolesCtx.put("name", role.getName());
+ userRolesCtx.put("displayname",
role.getDisplayName());
+ }
+ }
+ }
+ catch (IllegalArgumentException e)
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ catch (IdentityException e)
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ req.setAttribute(PortalJsp.CTX_REQUEST, ctx);
+ PortletRequestDispatcher rd =
getPortletContext().getRequestDispatcher("/WEB-INF/jsp/user/editUserRoles.jsp");
+ rd.include(req, resp);
+ }
+ }
+ else if (OP_SHOWREGISTER.equals(op))
+ {
+ if (req.isUserInRole("Admin"))
+ {
+ DelegateContext ctx = new DelegateContext();
+ ctx.put("lastView",
req.getParameters().get("lastView", "showMenu"));
+ req.setAttribute(PortalJsp.CTX_REQUEST, ctx);
+
+ PortletRequestDispatcher rd =
getPortletContext().getRequestDispatcher("/WEB-INF/jsp/user/registerUser.jsp");
+ rd.include(req, resp);
+ }
+ }
+ else if (OP_SHOWREGISTER_TY.equals(op))
+ {
+ if (req.isUserInRole("Admin"))
+ {
+ PortletRequestDispatcher rd =
getPortletContext().getRequestDispatcher("/WEB-INF/jsp/user/registerUser_admin.jsp");
+ rd.include(req, resp);
+ }
+ }
+ else
+ {
+ log.error("This operation does not exist when user is logged in:" +
op);
+ }
+ }
+ else
+ {
+ // User is not logged in
+ op = req.getParameters().get(getOperationName(), OP_SHOWLOGIN);
+
+ if (req.getWindowState() != WindowState.MAXIMIZED && !
OP_SHOWREGISTER_TY.equals(op) && ! OP_ACTIVATEUSER.equals(op))
+ {
+ op = OP_SHOWLOGIN;
+ }
+
+ if (OP_SHOWREGISTER.equals(op))
+ {
+ PortletRequestDispatcher rd =
getPortletContext().getRequestDispatcher("/WEB-INF/jsp/user/register.jsp");
+ rd.include(req, resp);
+ }
+ else if (OP_SHOWREGISTER_TY.equals(op))
+ {
+ PortletRequestDispatcher rd =
getPortletContext().getRequestDispatcher("/WEB-INF/jsp/user/register_ty.jsp");
+ rd.include(req, resp);
+ }
+ else if (OP_SHOWLOGIN.equals(op))
+ {
+ PortletRequestDispatcher rd =
getPortletContext().getRequestDispatcher("/WEB-INF/jsp/user/login.jsp");
+ rd.include(req, resp);
+ }
+ else if (OP_ACTIVATEUSER.equals(op))
+ {
+ String hash = req.getParameter(UserPortletConstants.HASH);
+ String userId =
req.getParameters().getParameter(UserPortletConstants.USERID);
+
+ User user;
+ PortletRequestDispatcher rd;
+ try
+ {
+ user = userModule.findUserById(userId);
+ String hexCompare = Tools.md5AsHexString(user.getUserName() +
getProperty(user,User.INFO_USER_REGISTRATION_DATE).toString() +
UserPortletConstants.SALT);
+ if (hash.equals(hexCompare))
+ {
+ setProperty(user, User.INFO_USER_ENABLED, Boolean.TRUE);
+ rd =
getPortletContext().getRequestDispatcher("/WEB-INF/jsp/user/register_ty.jsp");
+ PortalNode currentNode = Navigation.getCurrentNode();
+ PortalNodeURL url = resp.createRenderURL(currentNode);
+ url.setAuthenticated(Boolean.TRUE);
+ if
("1".equals(getPortletConfig().getInitParameter("useSSL")))
+ {
+ url.setSecure(Boolean.TRUE);
+ req.setAttribute("secureURL", url.toString());
+ }
+ url.setSecure(null);
+ req.setAttribute("URL", url.toString());
+ }
+ else
+ {
+ rd =
getPortletContext().getRequestDispatcher("/WEB-INF/jsp/user/login.jsp");
+ }
+ }
+ catch (Exception e)
+ {
+ rd =
getPortletContext().getRequestDispatcher("/WEB-INF/jsp/user/login.jsp");
+ }
+ rd.include(req, resp);
+ }
+ else
+ {
+ log.error("This operation does not exist when user is not logged
in:" + op);
+ }
+ }
+
+ writer.close();
+ }
+
+
+ /**
+ *
+ */
+ public void showListUsers(JBossActionRequest actionRequest, JBossActionResponse
actionResponse) throws IOException, WindowStateException
+ {
+ if (actionRequest.isUserInRole("Admin"))
+ {
+ actionResponse.setRenderParameter("usernamefilter",
actionRequest.getParameter("usernamefilter"));
+ actionResponse.setRenderParameter("usersperpage",
actionRequest.getParameter("usersperpage"));
+ actionResponse.setRenderParameter("op", OP_SHOWLISTUSERS);
+ actionResponse.setWindowState(WindowState.MAXIMIZED);
+ }
+ }
+
+
+ /** Performs a log out. */
+ public void userLogout(JBossActionRequest req, JBossActionResponse resp) throws
IOException
+ {
+ String locationURL = req.getParameter("locationURL");
+ if (locationURL != null)
+ {
+ resp.signOut(locationURL);
+ }
+ else
+ {
+ resp.signOut();
+ }
+ }
+
+ /**
+ * Action when a user register
+ *
+ * @param req JBoss action request
+ * @param resp JBoss action response
+ */
+ public void userRegister(JBossActionRequest req, JBossActionResponse resp)
+ {
+ // TODO: Check that a bot is not creating many accounts
+ String uname = req.getParameter("uname");
+ resp.setRenderParameter("op",
req.getParameters().get("lastView",OP_SHOWMENU));
+
+ int nbErrors = 0;
+ if ((uname == null) || (uname.length() == 0))
+ {
+ nbErrors++;
+ resp.setRenderParameter("uname_error",
"REGISTER_ERROR_INVALIDUSERNAME");
+ }
+ else
+ {
+ try
+ {
+ User user = userModule.findUserByUserName(uname);
+ if (user != null)
+ {
+ nbErrors++;
+ resp.setRenderParameter("uname_error",
"REGISTER_ERROR_EXISTINGUSERNAME");
+ }
+ }
+ catch (IllegalArgumentException e)
+ {
+ log.error("", e);
+ }
+ catch (IdentityException e)
+ {
+ // Ok the user does not exist yet
+ }
+ }
+
+ String pass1 = req.getParameter("pass1");
+ if ((pass1 == null) || (pass1.length() == 0))
+ {
+ nbErrors++;
+ resp.setRenderParameter("pass1_error",
"REGISTER_ERROR_INVALIDPASSWORD1");
+ }
+
+ String pass2 = req.getParameter("pass2");
+ if ((pass2 == null) || (pass2.length() == 0))
+ {
+ nbErrors++;
+ resp.setRenderParameter("pass2_error",
"REGISTER_ERROR_INVALIDPASSWORD2");
+ }
+ else if (!pass1.equals(pass2))
+ {
+ nbErrors++;
+ resp.setRenderParameter("pass2_error",
"REGISTER_ERROR_PASSWORDMISMATCH");
+ }
+
+ String realEmail = req.getParameter("realemail");
+ if (!URLTools.isEmailValid(realEmail))
+ {
+ nbErrors++;
+ resp.setRenderParameter("realemail_error",
"REGISTER_ERROR_INVALIDREALEMAIL");
+ }
+
+ String fakeEmail = req.getParameter("fakeemail");
+ String question = req.getParameter("question");
+ String answer = req.getParameter("answer");
+ User user;
+ if (nbErrors == 0)
+ {
+ try
+ {
+
+ user = userModule.createUser(uname, pass1);
+
+ setProperty(user, P3PConstants.INFO_USER_BUSINESS_INFO_ONLINE_EMAIL,
realEmail);
+ //user.setFakeEmail(fakeEmail);
+ setProperty(user,User.INFO_USER_EMAIL_FAKE, fakeEmail);
+
+ //TODO: set registration date
+
+ String type =
userProfileModule.getProfileInfo().getPropertyInfo(User.INFO_USER_REGISTRATION_DATE).getType();
+ if (type.equals("java.util.Date"))
+ {
+ putNonEmptyProperty(user, User.INFO_USER_REGISTRATION_DATE, new Date());
+ }
+ else if (type.equals("java.lang.String"))
+ {
+ putNonEmptyProperty(user, User.INFO_USER_REGISTRATION_DATE, new
Date().toString());
+ }
+ else
+ {
+ log.warn(User.INFO_USER_REGISTRATION_DATE + " property is mapped in
not supported type: " + type);
+ }
+
+ String subscriptionMode =
getPortletConfig().getInitParameter(UserPortletConstants.SUBSCRIPTIONMODE);
+ if (subscriptionMode == null)
+ {
+ subscriptionMode = UserPortletConstants.SUBSCRIPTIONMODE_AUTOMATIC;
+ }
+
+ setProperty(user, User.INFO_USER_LOCALE, req.getLocale().toString());
+
+ if (UserPortletConstants.SUBSCRIPTIONMODE_AUTOMATIC.equals(subscriptionMode)
|| req.isUserInRole("Admin"))
+ {
+ setProperty(user, User.INFO_USER_ENABLED, Boolean.TRUE);
+ }
+ else if
(UserPortletConstants.SUBSCRIPTIONMODE_EMAILVERIFICATION.equals(subscriptionMode))
+ {
+ setProperty(user, User.INFO_USER_ENABLED, Boolean.FALSE);
+ String emailText = generateValidationEmail(req, resp, user, pass1);
+ String from =
getPortletConfig().getInitParameter(UserPortletConstants.EMAILFROM);
+ Locale locale = req.getLocale();
+ ResourceBundle bundle = getResourceBundle(locale);
+ String subject =
bundle.getString("REGISTER_CONFIRMATIONEMAIL");
+ mailModule.send(from,
(String)getProperty(user,P3PConstants.INFO_USER_BUSINESS_INFO_ONLINE_EMAIL), subject,
emailText);
+ }
+
+ /*
+ * Have to define the link to /login Have to redirect after the
+ * login try { resp.sendRedirect("/portal/login?username=" + uname
+
+ * "&password=" + pass1); } catch (IOException e1) { // TODO
+ * Auto-generated catch block e1.printStackTrace(); }
+ */
+
+ // Add the user to the default user role
+ String defaultRole =
getPortletConfig().getInitParameter(UserPortletConstants.DEFAULT_ROLE);
+ if (defaultRole != null)
+ {
+ Set roleSet = new HashSet();
+ Role role = roleModule.findRoleByName(defaultRole);
+ if (role != null)
+ {
+ roleSet.add(role);
+ membershipModule.assignRoles(user, roleSet);
+ }
+ else
+ {
+ log.error("The role you specified as default role does not exist,
check your portlet configuration");
+ }
+ }
+ else
+ {
+ log.info("You didn't specify a default role in the portlet init
configuration, please refer to the documentation");
+ }
+ //resp.setRenderParameter("op", OP_SHOWREGISTER_TY);
+ if
(req.getParameters().get("lastView",OP_SHOWMENU).equals(OP_SHOWLISTUSERS))
+ {
+ resp.setWindowState(WindowState.MAXIMIZED);
+ }
+ else
+ {
+ resp.setWindowState(WindowState.NORMAL);
+ }
+ }
+ catch (IllegalArgumentException e)
+ {
+ log.error("Cannot create user " + uname, e);
+ }
+ catch (IdentityException e)
+ {
+ log.error("Cannot create user " + uname, e);
+ }
+ catch (WindowStateException e)
+ {
+ log.error("Normal window state not supported...");
+ }
+ }
+ else
+ {
+ portletHelper.setRenderParameter(resp, "USERNAME", uname);
+ portletHelper.setRenderParameter(resp, "REALEMAIL", realEmail);
+ portletHelper.setRenderParameter(resp, "FAKEEMAIL", fakeEmail);
+ portletHelper.setRenderParameter(resp, "QUESTION", question);
+ portletHelper.setRenderParameter(resp, "ANSWER", answer);
+ portletHelper.setRenderParameter(resp, getOperationName(), OP_SHOWREGISTER);
+ }
+ }
+
+ private void fillContextWithUserProfile(User user, DelegateContext ctx)
+ {
+ ctx.put("GIVENNAME", (String)getProperty(user,
P3PConstants.INFO_USER_NAME_GIVEN));
+ ctx.put("FAMILYNAME", (String)getProperty(user,
P3PConstants.INFO_USER_NAME_FAMILY));
+ ctx.put("REALEMAIL", (String)getProperty(user,
P3PConstants.INFO_USER_BUSINESS_INFO_ONLINE_EMAIL));
+ ctx.put("FAKEEMAIL", (String)getProperty(user,
User.INFO_USER_EMAIL_FAKE));
+ ctx.put("THEME", (String)getProperty(user, User.INFO_USER_THEME));
+ ctx.put("VIEWREALEMAIL", ((String)getProperty(user,
User.INFO_USER_VIEW_EMAIL_VIEW_REAL)).equals("true") ?
"checked=\"checked\"" : "");
+ ctx.put("HOMEPAGE", (String)getProperty(user,User.INFO_USER_HOMEPAGE));
+ ctx.put("ICQ", (String)getProperty(user,User.INFO_USER_IM_ICQ));
+ ctx.put("AIM", (String)getProperty(user,User.INFO_USER_IM_AIM));
+ ctx.put("YIM", (String)getProperty(user,User.INFO_USER_IM_YIM));
+ ctx.put("MSNM", (String)getProperty(user,User.INFO_USER_IM_MSNM));
+ ctx.put("SKYPE", (String)getProperty(user,User.INFO_USER_IM_SKYPE));
+ ctx.put("SIGNATURE",
(String)getProperty(user,User.INFO_USER_SIGNATURE));
+ ctx.put("LOCATION", (String)getProperty(user,User.INFO_USER_LOCATION));
+ ctx.put("OCCUPATION",
(String)getProperty(user,User.INFO_USER_OCCUPATION));
+ ctx.put("INTERESTS",
(String)getProperty(user,User.INFO_USER_INTERESTS));
+ ctx.put("EXTRA", (String)getProperty(user,User.INFO_USER_EXTRA));
+ ctx.put("QUESTION",
(String)getProperty(user,User.INFO_USER_SECURITY_QUESTION));
+ ctx.put("ANSWER",
(String)getProperty(user,User.INFO_USER_SECURITY_ANSWER));
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param req DOCUMENT_ME
+ * @param resp DOCUMENT_ME
+ */
+ public void storeProfile(JBossActionRequest req, JBossActionResponse resp) throws
PortletException
+ {
+ User currentUser = req.getUser();
+ try
+ {
+ currentUser = userModule.findUserById(currentUser.getId());
+ }
+ catch (IdentityException e)
+ {
+ log.error("Cannot retrive user", e);
+ }
+
+ if (currentUser == null)
+ {
+ throw new PortletException("No user");
+ }
+
+ // Get the user
+ User user = null;
+ try
+ {
+ String userid = req.getParameters().getParameter("userid");
+ user = userModule.findUserById(userid);
+ }
+ catch (Exception e)
+ {
+ throw new PortletException("blah", e);
+ }
+
+ // Are we editing ourself ?
+ boolean self = currentUser.getId().equals(user.getId());
+ if (!self && !req.isUserInRole("Admin"))
+ {
+ throw new PortletException();
+ }
+
+
+ int nbErrors = 0;
+ boolean changePassword = false;
+ String givenName = req.getParameter("givenname");
+ String familyName = req.getParameter("familyname");
+ String pass1 = req.getParameter("pass1");
+ String pass2 = req.getParameter("pass2");
+ if (!(((pass2 == null) || (pass2.length() == 0)) && ((pass1 == null) ||
(pass1.length() == 0))))
+ {
+ changePassword = true;
+ if ((pass1 == null) || (pass1.length() == 0))
+ {
+ nbErrors++;
+ resp.setRenderParameter("pass1_error",
"REGISTER_ERROR_INVALIDPASSWORD1");
+ }
+
+ if ((pass2 == null) || (pass2.length() == 0))
+ {
+ nbErrors++;
+ resp.setRenderParameter("pass2_error",
"REGISTER_ERROR_INVALIDPASSWORD2");
+ }
+ else if (!pass1.equals(pass2))
+ {
+ nbErrors++;
+ resp.setRenderParameter("pass2_error",
"REGISTER_ERROR_PASSWORDMISMATCH");
+ }
+ }
+
+ String realEmail = req.getParameter("realemail");
+ if (!URLTools.isEmailValid(realEmail))
+ {
+ nbErrors++;
+ resp.setRenderParameter("realemail_error",
"REGISTER_ERROR_INVALIDREALEMAIL");
+ }
+
+ String fakeEmail = req.getParameter("fakeemail");
+ boolean viewRealEmail = req.getParameters().getBoolean("viewrealemail",
false);
+ String homepage = req.getParameter("homepage");
+ Short timezoneoffset =
req.getParameters().getShortObject("timezoneoffset", UNDEFINED_TIMEZONE);
+ String question = req.getParameter("question");
+ String answer = req.getParameter("answer");
+ String icq = req.getParameter("icq");
+ String msnm = req.getParameter("msnm");
+ String yim = req.getParameter("yim");
+ String aim = req.getParameter("aim");
+ String skype = req.getParameter("skype");
+ String location = req.getParameter("location");
+ String occupation = req.getParameter("occupation");
+ String interests = req.getParameter("interests");
+ String signature = req.getParameter("signature");
+ String extra = req.getParameter("extra");
+ String localeParam = req.getParameter("locale");
+ String theme = req.getParameter("theme");
+
+ if (nbErrors == 0)
+ {
+ //
+ if (givenName.trim().length() != 0)
+ {
+ setProperty(user, P3PConstants.INFO_USER_NAME_GIVEN, givenName);
+ }
+
+ if (familyName.trim().length() != 0)
+ {
+ setProperty(user, P3PConstants.INFO_USER_NAME_FAMILY, familyName);
+ }
+
+ if (realEmail.trim().length() != 0)
+ {
+ setProperty(user, P3PConstants.INFO_USER_BUSINESS_INFO_ONLINE_EMAIL,
realEmail);
+ }
+
+ if (fakeEmail.trim().length() != 0)
+ {
+ setProperty(user, User.INFO_USER_EMAIL_FAKE, fakeEmail);
+ }
+
+ setProperty(user, User.INFO_USER_VIEW_EMAIL_VIEW_REAL,
Boolean.valueOf(viewRealEmail));
+
+ if (changePassword)
+ {
+ user.updatePassword(pass1);
+ }
+
+ if (timezoneoffset.shortValue() != UNDEFINED_TIMEZONE)
+ {
+ setProperty(user, User.INFO_USER_TIME_ZONE_OFFSET,
timezoneoffset.toString());
+ }
+
+ try
+ {
+ Locale locale = LocaleFormat.DEFAULT.getLocale(localeParam);
+ //setProperty(user, User.INFO_USER_LOCALE, localeInfo.getLocale());
+ setProperty(user, User.INFO_USER_LOCALE,
LocaleFormat.DEFAULT.toString(locale));
+ }
+ catch (ConversionException e)
+ {
+ log.error("Cannot convert locale format", e);
+ }
+
+ putNonEmptyProperty(user, User.INFO_USER_THEME, theme);
+ putNonEmptyProperty(user, User.INFO_USER_HOMEPAGE, homepage);
+ putNonEmptyProperty(user, User.INFO_USER_SECURITY_QUESTION, question);
+ putNonEmptyProperty(user, User.INFO_USER_SECURITY_ANSWER, answer);
+ putNonEmptyProperty(user, User.INFO_USER_IM_ICQ, icq);
+ putNonEmptyProperty(user, User.INFO_USER_IM_MSNM, msnm);
+ putNonEmptyProperty(user, User.INFO_USER_IM_YIM, yim);
+ putNonEmptyProperty(user, User.INFO_USER_IM_AIM, aim);
+ putNonEmptyProperty(user, User.INFO_USER_IM_SKYPE, skype);
+ putNonEmptyProperty(user, User.INFO_USER_SIGNATURE, signature);
+ putNonEmptyProperty(user, User.INFO_USER_LOCATION, location);
+ putNonEmptyProperty(user, User.INFO_USER_OCCUPATION, occupation);
+ putNonEmptyProperty(user, User.INFO_USER_INTERESTS, interests);
+ putNonEmptyProperty(user, User.INFO_USER_EXTRA, extra);
+
+ // Set back to normal window state
+ resp.setWindowState(WindowState.NORMAL);
+ portletHelper.setRenderParameter(resp, "modifiedProfile",
"true");
+ portletHelper.setRenderParameter(resp, getOperationName(), OP_SHOWMENU);
+ }
+ else
+ {
+ portletHelper.setRenderParameter(resp, "GIVENNAME", givenName);
+ portletHelper.setRenderParameter(resp, "FAMILYNAME", familyName);
+ portletHelper.setRenderParameter(resp, "REALEMAIL", realEmail);
+ portletHelper.setRenderParameter(resp, "FAKEEMAIL", fakeEmail);
+ if (getProperty(user,
User.INFO_USER_VIEW_EMAIL_VIEW_REAL).toString().equals("true"))
+ {
+ portletHelper.setRenderParameter(resp, "VIEWREALEMAIL",
"checked=\"checked\"");
+ }
+ else
+ {
+ portletHelper.setRenderParameter(resp, "VIEWREALEMAIL",
"");
+ }
+
+ portletHelper.setRenderParameter(resp, "HOMEPAGE", homepage);
+ portletHelper.setRenderParameter(resp, "SELECTEDTIMEZONE",
"" + timezoneoffset);
+ portletHelper.setRenderParameter(resp, "SELECTEDLOCALE",
localeParam);
+ portletHelper.setRenderParameter(resp, "THEME", theme);
+ portletHelper.setRenderParameter(resp, "ICQ", icq);
+ portletHelper.setRenderParameter(resp, "AIM", aim);
+ portletHelper.setRenderParameter(resp, "YIM", yim);
+ portletHelper.setRenderParameter(resp, "MSNM", msnm);
+ portletHelper.setRenderParameter(resp, "SKYPE", skype);
+ portletHelper.setRenderParameter(resp, "SIGNATURE", signature);
+ portletHelper.setRenderParameter(resp, "LOCATION", location);
+ portletHelper.setRenderParameter(resp, "OCCUPATION", occupation);
+ portletHelper.setRenderParameter(resp, "INTERESTS", interests);
+ portletHelper.setRenderParameter(resp, "EXTRA", extra);
+ portletHelper.setRenderParameter(resp, getOperationName(), OP_SHOWPROFILE);
+ }
+
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param request DOCUMENT_ME
+ * @param response DOCUMENT_ME
+ */
+ public void addRolesToUser(JBossActionRequest request, JBossActionResponse response)
+ {
+ if (request.isUserInRole("Admin"))
+ {
+
+ String userId = request.getParameters().getParameter("userid");
+ response.setRenderParameter("usernamefilter",
request.getParameter("usernamefilter"));
+ response.setRenderParameter("offset",
request.getParameter("offset"));
+ response.setRenderParameter("usersperpage",
request.getParameter("usersperpage"));
+
+ if (request.getParameterMap().keySet().contains("addRoles"))
+ {
+ String[] selectedRoles =
request.getParameterValues("assignedRoles");
+ String[] rolesToAdd = request.getParameterValues("rolesToAdd");
+
+ if (selectedRoles == null)
+ {
+ selectedRoles = new String[]{};
+ }
+ if (rolesToAdd == null)
+ {
+
+ if (selectedRoles.length != 0)
+ {
+ response.setRenderParameter("selectedRoles", selectedRoles);
+ }
+
+ response.setRenderParameter("op", OP_SHOWADDROLESTOUSER );
+ response.setRenderParameter("userid", userId);
+ return;
+ }
+
+
+ Set roles = new HashSet();
+ List l1 = Arrays.asList(selectedRoles);
+ List l2 = Arrays.asList(rolesToAdd);
+ roles.addAll(l1);
+ roles.addAll(l2);
+
+ String[] roleNames = new String[roles.size()];
+ roleNames = (String[])roles.toArray(roleNames);
+
+ response.setRenderParameter("selectedRoles", roleNames);
+ response.setRenderParameter("op", OP_SHOWADDROLESTOUSER );
+ response.setRenderParameter("userid", userId);
+ }
+ else if (request.getParameterMap().keySet().contains("removeRoles"))
+ {
+
+ String[] selectedRoles =
request.getParameterValues("assignedRoles");
+ String[] rolesToRemove =
request.getParameterValues("selectedRoles");
+
+ if (selectedRoles == null)
+ {
+ selectedRoles = new String[]{};
+ }
+
+ if (rolesToRemove == null)
+ {
+ if (selectedRoles.length != 0)
+ {
+ response.setRenderParameter("selectedRoles", selectedRoles);
+ }
+
+ response.setRenderParameter("op", OP_SHOWADDROLESTOUSER );
+ response.setRenderParameter("userid", userId);
+ return;
+ }
+
+ List toRemove = Arrays.asList(rolesToRemove);
+
+ Set roles = new HashSet();
+
+ for (int i = 0; i < selectedRoles.length; i++)
+ {
+ String selectedRole = selectedRoles[i];
+
+ if (!toRemove.contains(selectedRole))
+ {
+ roles.add(selectedRole);
+ }
+ }
+
+ String[] roleNames = new String[roles.size()];
+ roleNames = (String[])roles.toArray(roleNames);
+
+ if (roleNames.length != 0)
+ {
+ response.setRenderParameter("selectedRoles", roleNames);
+ }
+
+ response.setRenderParameter("op", OP_SHOWADDROLESTOUSER );
+ response.setRenderParameter("userid", userId);
+ }
+ else
+ {
+ try
+ {
+ String[] selectedRoles =
request.getParameterValues("assignedRoles");
+ User user = userModule.findUserById(userId);
+ Set roles = roleModule.findRolesByNames(selectedRoles);
+ membershipModule.assignRoles(user, roles);
+ response.setRenderParameter(getOperationName(), OP_SHOWLISTUSERS);
+ response.setRenderParameter("usernamefilter",
request.getParameter("usernamefilter"));
+ response.setRenderParameter("offset",
request.getParameter("offset"));
+ response.setRenderParameter("usersperpage",
request.getParameter("usersperpage"));
+ }
+ catch (IllegalArgumentException e)
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ catch (IdentityException e)
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+
+ /*
+ * TODO: The email verification needs an email service. This is not done yet.
+ * It also needs a way to generate portlet URL or some kind of URL. Once all
+ * of this made, it will be quick to implement.
+ */
+ /*
+ * * Generates the body of the email sent for user activation.
+ *
+ * @param user user @param password unencrypted password @return email body
+ *
+ */
+ private String generateValidationEmail(JBossActionRequest req,
+ JBossActionResponse resp,
+ User user,
+ String clearPassword)
+ {
+ // gen link using username, encrypted pw, and a salt.
+ String hash = Tools.md5AsHexString(user.getUserName() + getProperty(user,
User.INFO_USER_REGISTRATION_DATE).toString() + UserPortletConstants.SALT);
+
+ PortalNode node = req.getPortalNode();
+
+ //PortalNodeURL link = resp.createActionURL(node);
+ PortalNodeURL link = resp.createRenderURL(node);
+ link.setParameter("op", OP_ACTIVATEUSER);
+ link.setParameter(UserPortletConstants.USERID, "" + user.getId());
+ link.setParameter(UserPortletConstants.HASH, hash);
+ link.setRelative(false);
+
+ // Fill data to share with the template
+ Map modelRoot = new HashMap();
+ modelRoot.put("emailDomain",
getPortletConfig().getInitParameter("emailDomain"));
+ modelRoot.put("id", user.getId());
+ modelRoot.put("username", user.getUserName());
+ modelRoot.put("password", clearPassword);
+ modelRoot.put("activationLink", link);
+
+ ClassLoader tcl = Thread.currentThread().getContextClassLoader();
+ String message = null;
+ try
+ {
+ Locale locale = req.getLocale();
+ URL config = tcl.getResource("templates/user/emailTemplate_" +
locale.getLanguage() + "_" + locale.getCountry()+ ".tpl");
+ if (config == null)
+ {
+ config = tcl.getResource("templates/user/emailTemplate_" +
locale.getLanguage() + ".tpl");
+ }
+ if (config == null)
+ {
+ config = tcl.getResource("templates/user/emailTemplate.tpl");
+ }
+ if (config == null)
+ {
+ throw new FileNotFoundException("Cannot load a suitable
emailTemplate.tpl in templates/user");
+ }
+ InputStream in = config.openStream();
+ Template tpl = new Template("emailTemplate", new
InputStreamReader(in), new Configuration());
+ StringWriter out = new StringWriter();
+ tpl.process(modelRoot, out);
+ out.close();
+ message = out.toString();
+ }
+ catch (IOException e1)
+ {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ }
+ catch (TemplateException e)
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ return message;
+ }
+
+ private String getFirstName(ResourceBundle bundle, User user)
+ {
+ String givenName = null;
+
+ try
+ {
+ givenName = (String)userProfileModule.getProperty(user,
P3PConstants.INFO_USER_NAME_GIVEN);
+ }
+ catch (IdentityException e)
+ {
+ log.error("cannot obtain user profile information: ", e);
+ }
+
+ if ((givenName != null) && (givenName.trim().length() != 0))
+ {
+ return givenName.trim();
+ }
+ else
+ {
+ return bundle.getString("NAMENOTAVAILABLE");
+ }
+ }
+
+ private String getLastName(ResourceBundle bundle, User user)
+ {
+ String familyName = null;
+
+ try
+ {
+ familyName = (String)userProfileModule.getProperty(user,
P3PConstants.INFO_USER_NAME_FAMILY);
+ }
+ catch (IdentityException e)
+ {
+ log.error("cannot obtain user profile information: ", e);
+ }
+
+
+ if ((familyName != null) && (familyName.trim().length() != 0))
+ {
+ return familyName.trim();
+ }
+ else
+ {
+ return bundle.getString("NAMENOTAVAILABLE");
+ }
+ }
+
+ private String getFullName(ResourceBundle bundle,
+ User user)
+ {
+ String givenName = null;
+ String familyName = null;
+
+ try
+ {
+ givenName = (String)userProfileModule.getProperty(user,
P3PConstants.INFO_USER_NAME_GIVEN);
+ familyName = (String)userProfileModule.getProperty(user,
P3PConstants.INFO_USER_NAME_FAMILY);
+ }
+ catch (IdentityException e)
+ {
+ log.error("cannot obtain user profile information: ", e);
+ }
+
+ if ((givenName != null) && (givenName.trim().length() != 0))
+ {
+ if ((familyName != null) && (familyName.trim().length() != 0))
+ {
+ return givenName + " " + familyName;
+ }
+ else
+ {
+ return givenName.trim();
+ }
+ }
+ else
+ {
+ if ((familyName != null) && (familyName.trim().length() != 0))
+ {
+ return familyName.trim();
+ }
+ else
+ {
+ return bundle.getString("NAMENOTAVAILABLE");
+ }
+ }
+ }
+
+ private void putNonEmptyProperty(User user, String key, Object value)
+ {
+
+
+ if (value != null)
+ {
+ if (value instanceof String && !(((String)value).trim().length() != 0)
)
+ {
+ return;
+ }
+ //user.getProfile().put(key, value);
+ try
+ {
+ userProfileModule.setProperty(user, key, value);
+ }
+ catch (IdentityException e)
+ {
+ //TODO: change to error
+ log.info("Cannot set profile property: ", e);
+ }
+ }
+ }
+
+ public void deleteUser(JBossActionRequest request, JBossActionResponse response)
+ {
+ if (request.isUserInRole("Admin"))
+ {
+ try
+ {
+ User user =
userModule.findUserById(request.getParameter("userid"));
+ userModule.removeUser(user.getId());
+ }
+ catch (IdentityException e)
+ {
+ e.printStackTrace();
+ }
+ }
+ portletHelper.setRenderParameter(response, getOperationName(), OP_SHOWLISTUSERS);
+ }
+
+ private void setProperty(User user, String key, Object value)
+ {
+ try
+ {
+ userProfileModule.setProperty(user, key, value);
+ }
+ catch (IdentityException e)
+ {
+ //TODO: change to error
+ log.info("Cannot set profile property: ", e);
+ }
+ }
+
+ //Some temp solution to make this portlet not break with new stuff
+ private Object getProperty(User user, String key)
+ {
+ try
+ {
+ Object o = userProfileModule.getProperty(user, key);
+ if (o == null)
+ {
+ return "";
+ }
+ else
+ {
+ return o.toString();
+ }
+ }
+ catch (IdentityException e)
+ {
+ log.error("Cannot get profile property: ", e);
+ }
+ return null;
+ }
+
+ private class LocaleComparator implements Comparator
+ {
+
+ public int compare(Object arg0, Object arg1)
+ {
+ Locale locale1 = (Locale)arg0;
+ Locale locale2 = (Locale)arg1;
+ int compare =
locale1.getDisplayLanguage().compareTo(locale2.getDisplayLanguage());
+ if (compare == 0)
+ {
+ compare =
locale1.getDisplayCountry().compareTo(locale2.getDisplayCountry());
+ }
+ return compare;
+ }
+
+ }
+
+ /*
+ * private String getTimezoneOffsetString(short timezoneOffset) {
+ * StringBuffer timeZone = new StringBuffer(); for (int i = 0; i <
+ * UserPortletConstants.TIME_ZONE_OFFSETS.length; i++) { if
+ * (UserPortletConstants.TIME_ZONE_OFFSETS[i] != null) { timeZone.append("
+ * <option value=\"").append(i); if (timezoneOffset == i) {
+ * timeZone.append("\" selected>"); } else {
timeZone.append("\">"); }
+ * timeZone.append(UserPortletConstants.TIME_ZONE_OFFSETS[i]).append("
+ * </option>"); } } return timeZone.toString(); }
+ *
+ * private String getTimezoneOffsetString() { return
+ * getTimezoneOffsetString((short)0); }
+ *
+ * private String getTimezoneOffsetString(String timezoneOffset) { short
+ * offset = Short.parseShort(timezoneOffset); return
+ * getTimezoneOffsetString(offset); }
+ */
+}
\ No newline at end of file
Property changes on:
trunk/core/src/main/org/jboss/portal/core/ui/portlet/user/UserPortlet.java
___________________________________________________________________
Name: svn:executable
+ *
Added:
trunk/core/src/main/org/jboss/portal/core/ui/portlet/user/UserPortletConstants.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/core/ui/portlet/user/UserPortletConstants.java
(rev 0)
+++
trunk/core/src/main/org/jboss/portal/core/ui/portlet/user/UserPortletConstants.java 2007-06-11
11:31:36 UTC (rev 7395)
@@ -0,0 +1,119 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.core.ui.portlet.user;
+
+/** @author <a href="theute(a)jboss.org">Thomas Heute</a> $Revision:
5448 $ */
+public class UserPortletConstants
+{
+
+ public static final String SALT = "14m1r0nm4n";
+
+ public static final String INFOMESSAGE = "infomessage";
+ public static final String ERRORMESSAGE = "errormessage";
+
+ // Cookie names
+ public static String CK_USERNAME = "username";
+ public static String CK_PASS = "password";
+
+ // Default values
+ public static int DEFAULT_USERSPERPAGE = 10;
+
+ // Status return codes for the login.
+ public static final int LOGIN_STATUS_OK = 0;
+ public static final int LOGIN_STATUS_BAD_PASSWORD = 1;
+ public static final int LOGIN_STATUS_NO_SUCH_USER = 2;
+ public static final int LOGIN_STATUS_USER_DISABLED = 3;
+ public static final int LOGIN_STATUS_INVALID_NAME = 4;
+ public static final int LOGIN_STATUS_UNEXPECTED_ERROR = 5;
+
+ public static final int PERMANENT_USER_MAX_INACTIVE = 60 * 60 * 24 * 5 * 1000; // 5
days in ms
+ public static final int TRANSIENT_USER_MAX_INACTIVE = 60 * 60; // 1 hours in seconds
+
+ public static final String HASH = "hash";
+ public static final String USERID = "userid";
+
+ // Portlet configuration
+
+ public static final String EMAILFROM = "emailFrom";
+ public static final String SUBSCRIPTIONMODE = "subscriptionMode";
+ public static final String SUBSCRIPTIONMODE_AUTOMATIC = "automatic";
+ public static final String SUBSCRIPTIONMODE_EMAILVERIFICATION =
"emailVerification";
+ public static final String DEFAULT_ROLE = "defaultRole";
+
+ /** Timezone information : ((value + 1) * 2) - 1 = 2 * value + 1 */
+ public static final String[] TIME_ZONE_OFFSETS =
+ {
+ "(GMT -12:00 hours) Eniwetok, Kwajalein",
+ null,
+ "(GMT -11:00 hours) Midway Island, Samoa",
+ null,
+ "(GMT -10:00 hours) Hawaii",
+ null,
+ "(GMT -9:00 hours) Alaska",
+ null,
+ "(GMT -8:00 hours) Pacific Time (US & Canada)",
+ null,
+ "(GMT -7:00 hours) Mountain Time (US & Canada)",
+ null,
+ "(GMT -6:00 hours) Central Time (US & Canada), Mexico City",
+ null,
+ "(GMT -5:00 hours) Eastern Time (US & Canada), Bogota, Lima,
Quito",
+ null,
+ "(GMT -4:00 hours) Atlantic Time (Canada), Caracas, La Paz",
+ "(GMT -3:30 hours) Newfoundland",
+ "(GMT -3:00 hours) Brazil, Buenos Aires, Georgetown",
+ null,
+ "(GMT -2:00 hours) Mid-Atlantic",
+ null,
+ "(GMT -1:00 hours) Azores, Cape Verde Islands",
+ null,
+ "(GMT) Western Europe Time, London, Lisbon, Casablanca, Monrovia",
+ null,
+ "(GMT +1:00 hours) CET(Central Europe Time), Brussels, Copenhagen, Madrid,
Paris",
+ null,
+ "(GMT +2:00 hours) EET(Eastern Europe Time), Kaliningrad, South
Africa",
+ null,
+ "(GMT +3:00 hours) Baghdad, Kuwait, Riyadh, Moscow, St. Petersburg",
+ "(GMT +3:30 hours) Tehran",
+ "(GMT +4:00 hours) Abu Dhabi, Muscat, Baku, Tbilisi",
+ "(GMT +4:30 hours) Kabul",
+ "(GMT +5:00 hours) Ekaterinburg, Islamabad, Karachi, Tashkent",
+ "(GMT +5:30 hours) Bombay, Calcutta, Madras, New Delhi",
+ "(GMT +6:00 hours) Almaty, Dhaka, Colombo",
+ null,
+ "(GMT +7:00 hours) Bangkok, Hanoi, Jakarta",
+ null,
+ "(GMT +8:00 hours) Beijing, Perth, Singapore, Hong Kong, Chongqing, Urumqi,
Taipei",
+ null,
+ "(GMT +9:00 hours) Tokyo, Seoul, Osaka, Sapporo, Yakutsk",
+ "(GMT +9:30 hours) Adelaide, Darwin",
+ "(GMT +10:00 hours) EAST(East Australian Standard)",
+ null,
+ "(GMT +11:00 hours) Magadan, Solomon Islands, New Caledonia",
+ null,
+ "(GMT +12:00 hours) Auckland, Wellington, Fiji, Kamchatka, Marshall
Island",
+ null
+ };
+
+ public static final String DEFAULT_IMAGES_PATH = "images/user";
+}
Property changes on:
trunk/core/src/main/org/jboss/portal/core/ui/portlet/user/UserPortletConstants.java
___________________________________________________________________
Name: svn:executable
+ *
Modified: trunk/core/src/resources/portal-core-sar/META-INF/jboss-service.xml
===================================================================
--- trunk/core/src/resources/portal-core-sar/META-INF/jboss-service.xml 2007-06-08
13:50:21 UTC (rev 7394)
+++ trunk/core/src/resources/portal-core-sar/META-INF/jboss-service.xml 2007-06-11
11:31:36 UTC (rev 7395)
@@ -163,6 +163,23 @@
<!-- Command stack -->
<mbean
+ code="org.jboss.portal.core.aspects.controller.ControlInterceptor"
+ name="portal:service=Interceptor,type=Command,name=Control"
+ xmbean-dd=""
+ xmbean-code="org.jboss.portal.jems.as.system.JBossServiceModelMBean">
+ <xmbean/>
+ <depends
+ optional-attribute-name="PortalControlPolicy"
+
proxy-type="attribute">portal:service=ControlPolicy,type=Portal</depends>
+ </mbean>
+ <mbean
+
code="org.jboss.portal.core.aspects.controller.ResourceAcquisitionInterceptor"
+ name="portal:service=Interceptor,type=Command,name=ResourceAcquisition"
+ xmbean-dd=""
+ xmbean-code="org.jboss.portal.jems.as.system.JBossServiceModelMBean">
+ <xmbean/>
+ </mbean>
+ <mbean
code="org.jboss.portal.core.controller.ajax.AjaxInterceptor"
name="portal:service=Interceptor,type=Command,name=Ajax"
xmbean-dd=""
@@ -228,6 +245,8 @@
xmbean-code="org.jboss.portal.jems.as.system.JBossServiceModelMBean">
<xmbean/>
<depends-list optional-attribute-name="InterceptorNames">
+
<depends-list-element>portal:service=Interceptor,type=Command,name=Control</depends-list-element>
+
<depends-list-element>portal:service=Interceptor,type=Command,name=ResourceAcquisition</depends-list-element>
<depends-list-element>portal:service=Interceptor,type=Command,name=Ajax</depends-list-element>
<depends-list-element>portal:service=Interceptor,type=Command,name=NavigationalState</depends-list-element>
<depends-list-element>portal:service=Interceptor,type=Command,name=PortalNode</depends-list-element>
@@ -1009,6 +1028,28 @@
proxy-type="attribute">portal:service=ResponseHandler,type=Ajax</depends>
</mbean>
+ <!-- -->
+ <mbean
+
code="org.jboss.portal.core.model.portal.control.window.DefaultWindowControlPolicy"
+ name="portal:service=ControlPolicy,type=Window"
+ xmbean-dd=""
+ xmbean-code="org.jboss.portal.jems.as.system.JBossServiceModelMBean">
+ <xmbean/>
+ <depends
+ optional-attribute-name="PortalObjectContainer"
+
proxy-type="attribute">portal:container=PortalObject</depends>
+ </mbean>
+ <mbean
+
code="org.jboss.portal.core.model.portal.control.portal.DefaultPortalControlPolicy"
+ name="portal:service=ControlPolicy,type=Portal"
+ xmbean-dd=""
+ xmbean-code="org.jboss.portal.jems.as.system.JBossServiceModelMBean">
+ <xmbean/>
+ <depends
+ optional-attribute-name="PortalObjectContainer"
+
proxy-type="attribute">portal:container=PortalObject</depends>
+ </mbean>
+
<!-- The controller -->
<mbean
code="org.jboss.portal.core.controller.Controller"
@@ -1046,6 +1087,14 @@
<depends
optional-attribute-name="ResponseHandler"
proxy-type="attribute">portal:service=ResponseHandler,type=Selector</depends>
+ <depends
+ optional-attribute-name="WindowControlPolicy"
+
proxy-type="attribute">portal:service=ControlPolicy,type=Window</depends>
+<!--
+ <depends
+ optional-attribute-name="PortalControlPolicy"
+
proxy-type="attribute">portal:service=ControlPolicy,type=Window</depends>
+-->
</mbean>
<!-- The controller factory -->
Modified: trunk/core/src/resources/portal-core-sar/conf/data/default-object.xml
===================================================================
--- trunk/core/src/resources/portal-core-sar/conf/data/default-object.xml 2007-06-08
13:50:21 UTC (rev 7394)
+++ trunk/core/src/resources/portal-core-sar/conf/data/default-object.xml 2007-06-11
11:31:36 UTC (rev 7395)
@@ -30,6 +30,56 @@
<deployment>
<context>
<context-name/>
+ <properties>
+ <property>
+ <name>control.access_denied</name>
+ <value>hide</value>
+ </property>
+ <property>
+ <name>control.unavailable</name>
+ <value>hide</value>
+ </property>
+ <property>
+ <name>control.not_found</name>
+ <value>hide</value>
+ </property>
+ <property>
+ <name>control.internal_error</name>
+ <value>jsp</value>
+ </property>
+ <property>
+ <name>control.error</name>
+ <value>jsp</value>
+ </property>
+ <property>
+ <name>control.resource_uri</name>
+ <value>/WEB-INF/jsp/control/error.jsp</value>
+ </property>
+ <property>
+ <name>control.aggregation.access_denied</name>
+ <value>hide</value>
+ </property>
+ <property>
+ <name>control.aggregation.unavailable</name>
+ <value>hide</value>
+ </property>
+ <property>
+ <name>control.aggregation.not_found</name>
+ <value>hide</value>
+ </property>
+ <property>
+ <name>control.aggregation.internal_error</name>
+ <value>jsp</value>
+ </property>
+ <property>
+ <name>control.aggregation.error</name>
+ <value>jsp</value>
+ </property>
+ <property>
+ <name>control.aggregation.resource_uri</name>
+ <value>/WEB-INF/jsp/control/aggregation_error.jsp</value>
+ </property>
+ </properties>
</context>
</deployment>
<deployment>
Modified: trunk/core/src/resources/portal-core-sar/conf/hibernate/user/setup.txt
===================================================================
--- trunk/core/src/resources/portal-core-sar/conf/hibernate/user/setup.txt 2007-06-08
13:50:21 UTC (rev 7394)
+++ trunk/core/src/resources/portal-core-sar/conf/hibernate/user/setup.txt 2007-06-11
11:31:36 UTC (rev 7395)
@@ -1,5 +1,6 @@
// This bsh script setup the default content of the portal.
// It is called when the SessionFactoryBinder service has created a schema and needs to
populate it
+import org.jboss.portal.common.io.IOTools;
import org.jboss.portal.common.util.Tools;
import org.jboss.portal.identity.db.HibernateUserImpl;
import org.jboss.portal.identity.db.HibernateRoleImpl;
@@ -44,5 +45,5 @@
}
finally
{
- Tools.safeClose(session);
+ IOTools.safeClose(session);
}
Added: trunk/core/src/resources/portal-core-war/WEB-INF/jsp/control/aggregation_error.jsp
===================================================================
--- trunk/core/src/resources/portal-core-war/WEB-INF/jsp/control/aggregation_error.jsp
(rev 0)
+++
trunk/core/src/resources/portal-core-war/WEB-INF/jsp/control/aggregation_error.jsp 2007-06-11
11:31:36 UTC (rev 7395)
@@ -0,0 +1,3 @@
+Error type: <%= request.getAttribute("org.jboss.portal.control.ERROR_TYPE")
%><br/>
+Cause: <%= request.getAttribute("org.jboss.portal.control.CAUSE")
%><br/>
+Message: <%= request.getAttribute("org.jboss.portal.control.MESSAGE")
%><br/>
Added: trunk/core/src/resources/portal-core-war/WEB-INF/jsp/control/error.jsp
===================================================================
--- trunk/core/src/resources/portal-core-war/WEB-INF/jsp/control/error.jsp
(rev 0)
+++ trunk/core/src/resources/portal-core-war/WEB-INF/jsp/control/error.jsp 2007-06-11
11:31:36 UTC (rev 7395)
@@ -0,0 +1,3 @@
+Error type: <%= request.getAttribute("org.jboss.portal.control.ERROR_TYPE")
%><br/>
+Cause: <%= request.getAttribute("org.jboss.portal.control.CAUSE")
%><br/>
+Message: <%= request.getAttribute("org.jboss.portal.control.MESSAGE")
%><br/>
Modified: trunk/core/src/resources/portal-core-war/WEB-INF/portlet.xml
===================================================================
--- trunk/core/src/resources/portal-core-war/WEB-INF/portlet.xml 2007-06-08 13:50:21 UTC
(rev 7394)
+++ trunk/core/src/resources/portal-core-war/WEB-INF/portlet.xml 2007-06-11 11:31:36 UTC
(rev 7395)
@@ -31,7 +31,7 @@
<description>Portlet providing user login/logout and profile
management</description>
<portlet-name>UserPortlet</portlet-name>
<display-name>User Portlet</display-name>
-
<portlet-class>org.jboss.portal.core.portlet.user.UserPortlet</portlet-class>
+
<portlet-class>org.jboss.portal.core.ui.portlet.user.UserPortlet</portlet-class>
<init-param>
<description>Whether we should use ssl on login and throughout the Portal.
1=yes;0=no</description>
<name>useSSL</name>
@@ -80,7 +80,7 @@
<description>Portlet for managing user roles</description>
<portlet-name>RolePortlet</portlet-name>
<display-name>User Roles Portlet</display-name>
-
<portlet-class>org.jboss.portal.core.portlet.role.RolePortlet</portlet-class>
+
<portlet-class>org.jboss.portal.core.ui.portlet.role.RolePortlet</portlet-class>
<supports>
<mime-type>text/html</mime-type>
<portlet-mode>VIEW</portlet-mode>
@@ -101,7 +101,7 @@
<description>Portlet providing navigable list of portal
pages</description>
<portlet-name>CatalogPortlet</portlet-name>
<display-name>Portal Pages Catalog Portlet</display-name>
-
<portlet-class>org.jboss.portal.core.portlet.catalog.CatalogPortlet</portlet-class>
+
<portlet-class>org.jboss.portal.core.ui.portlet.catalog.CatalogPortlet</portlet-class>
<supports>
<mime-type>text/html</mime-type>
<portlet-mode>VIEW</portlet-mode>
Modified: trunk/core-admin/src/main/org/jboss/portal/core/admin/ui/PropertiesInfo.java
===================================================================
---
trunk/core-admin/src/main/org/jboss/portal/core/admin/ui/PropertiesInfo.java 2007-06-08
13:50:21 UTC (rev 7394)
+++
trunk/core-admin/src/main/org/jboss/portal/core/admin/ui/PropertiesInfo.java 2007-06-11
11:31:36 UTC (rev 7395)
@@ -23,6 +23,7 @@
package org.jboss.portal.core.admin.ui;
import org.jboss.portal.core.model.portal.PortalObject;
+import org.jboss.portal.core.model.portal.control.ControlConstants;
import org.jboss.portal.core.impl.model.portal.WindowImpl;
import org.jboss.portal.common.i18n.LocalizedString;
import org.jboss.portal.theme.ThemeConstants;
@@ -58,6 +59,14 @@
public static final PropertyInfo DEFAULT_CHILD_NAME = new
PropertyInfo(WindowImpl.PORTAL_PROP_DEFAULT_OBJECT_NAME, new LocalizedString("Default
child name"), new LocalizedString("The child name used when no specific child
name is explicited"), "java.lang.String",
PropertyInfo.READ_WRITE_ACCESS_MODE, PropertyInfo.PUBLIC_SCOPE);
public static final PropertyInfo PAGE_ORDER = new PropertyInfo("order", new
LocalizedString("Tab order"), new LocalizedString("The order value to
display pages in tabs"), "java.lang.String",
PropertyInfo.READ_WRITE_ACCESS_MODE, PropertyInfo.PUBLIC_SCOPE);
+ //
+
+ public static final PropertyInfo CONTROL_POLICY_ACCESS_DENIED = new
PropertyInfo(ControlConstants.AGGREGATION_ACCESS_DENIED_CONTROL_KEY, new
LocalizedString("On window access denied"), new LocalizedString("On window
access denied"), "java.lang.String", PropertyInfo.READ_WRITE_ACCESS_MODE,
PropertyInfo.PUBLIC_SCOPE);
+ public static final PropertyInfo CONTROL_POLICY_UNAVAILABLE = new
PropertyInfo(ControlConstants.AGGREGATION_UNAVAILABLE_CONTROL_KEY, new
LocalizedString("On window unavailable"), new LocalizedString("On window
unavailable"), "java.lang.String", PropertyInfo.READ_WRITE_ACCESS_MODE,
PropertyInfo.PUBLIC_SCOPE);
+ public static final PropertyInfo CONTROL_POLICY_ERROR = new
PropertyInfo(ControlConstants.AGGREGATION_ERROR_CONTROL_KEY, new LocalizedString("On
window error"), new LocalizedString("On window error"),
"java.lang.String", PropertyInfo.READ_WRITE_ACCESS_MODE,
PropertyInfo.PUBLIC_SCOPE);
+ public static final PropertyInfo CONTROL_POLICY_INTERNAL_ERROR = new
PropertyInfo(ControlConstants.AGGREGATION_INTERNAL_ERROR_CONTROL_KEY, new
LocalizedString("On window internal error"), new LocalizedString("On window
internal error"), "java.lang.String", PropertyInfo.READ_WRITE_ACCESS_MODE,
PropertyInfo.PUBLIC_SCOPE);
+ public static final PropertyInfo CONTROL_POLICY_NOT_FOUND = new
PropertyInfo(ControlConstants.AGGREGATION_NOT_FOUND_CONTROL_KEY, new
LocalizedString("On window not found"), new LocalizedString("On window not
found"), "java.lang.String", PropertyInfo.READ_WRITE_ACCESS_MODE,
PropertyInfo.PUBLIC_SCOPE);
+
/** . */
private static final Map CONTEXT_PROPERTIES = new HashMap();
@@ -80,6 +89,11 @@
PORTAL_PROPERTIES.put(THEME_RENDER_SET_ID.getName(), THEME_RENDER_SET_ID);
PORTAL_PROPERTIES.put(DEFAULT_CHILD_NAME.getName(), DEFAULT_CHILD_NAME);
PORTAL_PROPERTIES.put(AJAX_PARTIAL_REFRESH.getName(), AJAX_PARTIAL_REFRESH);
+ PORTAL_PROPERTIES.put(CONTROL_POLICY_ACCESS_DENIED.getName(),
CONTROL_POLICY_ACCESS_DENIED);
+ PORTAL_PROPERTIES.put(CONTROL_POLICY_UNAVAILABLE.getName(),
CONTROL_POLICY_UNAVAILABLE);
+ PORTAL_PROPERTIES.put(CONTROL_POLICY_ERROR.getName(), CONTROL_POLICY_ERROR);
+ PORTAL_PROPERTIES.put(CONTROL_POLICY_INTERNAL_ERROR.getName(),
CONTROL_POLICY_INTERNAL_ERROR);
+ PORTAL_PROPERTIES.put(CONTROL_POLICY_NOT_FOUND.getName(),
CONTROL_POLICY_NOT_FOUND);
//
PAGE_PROPERTIES.put(THEME_LAYOUT_ID.getName(), THEME_LAYOUT_ID);
@@ -88,6 +102,11 @@
PAGE_PROPERTIES.put(DEFAULT_CHILD_NAME.getName(), DEFAULT_CHILD_NAME);
PAGE_PROPERTIES.put(PAGE_ORDER.getName(), PAGE_ORDER);
PAGE_PROPERTIES.put(AJAX_PARTIAL_REFRESH.getName(), AJAX_PARTIAL_REFRESH);
+ PAGE_PROPERTIES.put(CONTROL_POLICY_ACCESS_DENIED.getName(),
CONTROL_POLICY_ACCESS_DENIED);
+ PAGE_PROPERTIES.put(CONTROL_POLICY_UNAVAILABLE.getName(),
CONTROL_POLICY_UNAVAILABLE);
+ PAGE_PROPERTIES.put(CONTROL_POLICY_ERROR.getName(), CONTROL_POLICY_ERROR);
+ PAGE_PROPERTIES.put(CONTROL_POLICY_INTERNAL_ERROR.getName(),
CONTROL_POLICY_INTERNAL_ERROR);
+ PAGE_PROPERTIES.put(CONTROL_POLICY_NOT_FOUND.getName(), CONTROL_POLICY_NOT_FOUND);
//
WINDOW_PROPERTIES.put(AJAX_PARTIAL_REFRESH.getName(), AJAX_PARTIAL_REFRESH);
Modified: trunk/core-admin/src/main/org/jboss/portal/core/admin/ui/PropertyInfo.java
===================================================================
--- trunk/core-admin/src/main/org/jboss/portal/core/admin/ui/PropertyInfo.java 2007-06-08
13:50:21 UTC (rev 7394)
+++ trunk/core-admin/src/main/org/jboss/portal/core/admin/ui/PropertyInfo.java 2007-06-11
11:31:36 UTC (rev 7395)
@@ -38,6 +38,9 @@
public static final int PRIVATE_SCOPE = 1;
/** . */
+ public static final int EXPERIMENTAL_SCOPE = 2;
+
+ /** . */
public static final int READ_ONLY_ACCESS_MODE = 0;
/** . */
Modified:
trunk/core-cms/src/main/org/jboss/portal/core/cms/content/InternalCMSContentProvider.java
===================================================================
---
trunk/core-cms/src/main/org/jboss/portal/core/cms/content/InternalCMSContentProvider.java 2007-06-08
13:50:21 UTC (rev 7394)
+++
trunk/core-cms/src/main/org/jboss/portal/core/cms/content/InternalCMSContentProvider.java 2007-06-11
11:31:36 UTC (rev 7395)
@@ -25,9 +25,9 @@
import org.jboss.portal.core.impl.model.content.generic.InternalGenericContentProvider;
import org.jboss.portal.core.model.portal.command.render.RenderWindowCommand;
import org.jboss.portal.core.model.portal.PortalObjectId;
+import org.jboss.portal.core.model.portal.content.WindowRendition;
import org.jboss.portal.core.model.content.spi.portlet.ContentPortlet;
import org.jboss.portal.core.cms.CMSObjectCommandFactory;
-import org.jboss.portal.core.controller.ControllerResponse;
import org.jboss.portal.Mode;
/**
@@ -89,7 +89,7 @@
super.start();
}
- public ControllerResponse renderWindow(RenderWindowCommand cmd) throws Exception
+ public WindowRendition renderWindow(RenderWindowCommand cmd) throws Exception
{
try
{
Modified:
trunk/portlet/src/main/org/jboss/portal/portlet/invocation/response/ErrorResponse.java
===================================================================
---
trunk/portlet/src/main/org/jboss/portal/portlet/invocation/response/ErrorResponse.java 2007-06-08
13:50:21 UTC (rev 7394)
+++
trunk/portlet/src/main/org/jboss/portal/portlet/invocation/response/ErrorResponse.java 2007-06-11
11:31:36 UTC (rev 7395)
@@ -34,19 +34,19 @@
public class ErrorResponse extends PortletInvocationResponse
{
/** The logged throwable if any. */
- private final Throwable throwable;
+ private final Throwable cause;
/** There must be one error message. */
private final String message;
- public ErrorResponse(Throwable throwable)
+ public ErrorResponse(Throwable cause)
{
- if (throwable == null)
+ if (cause == null)
{
- throw new IllegalArgumentException("There must be a throwable");
+ throw new IllegalArgumentException("There must be a cause");
}
- this.throwable = throwable;
- this.message = throwable.getMessage();
+ this.cause = cause;
+ this.message = cause.getMessage();
}
public ErrorResponse(String message)
@@ -56,13 +56,13 @@
throw new IllegalArgumentException("Message cannot be null.");
}
this.message = message;
- this.throwable = null;
+ this.cause = null;
}
/** The throwable. Can be a null object. */
- public Throwable getThrowable()
+ public Throwable getCause()
{
- return throwable;
+ return cause;
}
/** The logged message. */
@@ -70,7 +70,7 @@
{
if (message == null)
{
- return throwable.getClass().getName();
+ return cause.getClass().getName();
}
return message;
@@ -85,9 +85,9 @@
*/
public void logErrorTo(Logger log, String logMessage)
{
- if (throwable != null)
+ if (cause != null)
{
- log.error(logMessage, throwable);
+ log.error(logMessage, cause);
}
else
{
@@ -102,9 +102,9 @@
*/
public String toHTML()
{
- if (throwable != null)
+ if (cause != null)
{
- return Exceptions.toHTML(throwable);
+ return Exceptions.toHTML(cause);
}
else
{
Modified: trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/InvocationHandler.java
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/InvocationHandler.java 2007-06-08
13:50:21 UTC (rev 7394)
+++ trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/InvocationHandler.java 2007-06-11
11:31:36 UTC (rev 7395)
@@ -228,7 +228,7 @@
protected ErrorResponse unwrapWSRPError(ErrorResponse errorResponse)
{
- Throwable cause = errorResponse.getThrowable();
+ Throwable cause = errorResponse.getCause();
if (cause != null)
{
// unwrap original exception...
Modified: trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/MarkupHandler.java
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/MarkupHandler.java 2007-06-08
13:50:21 UTC (rev 7394)
+++ trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/MarkupHandler.java 2007-06-11
11:31:36 UTC (rev 7395)
@@ -180,7 +180,7 @@
if (response instanceof ErrorResponse)
{
ErrorResponse errorResult = (ErrorResponse)response;
- Throwable throwable = errorResult.getThrowable();
+ Throwable throwable = errorResult.getCause();
if (throwable instanceof PortletModeException)
{
throw
(UnsupportedModeFault)WSRPExceptionFactory.createFaultFrom(UnsupportedModeFault.class,