[jboss-svn-commits] JBL Code SVN: r8579 - in labs/jbosslabs/trunk/portal-extensions-2.6: . forge-mapper/src/java/org/jboss/labs/mapper
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Fri Dec 22 18:12:16 EST 2006
Author: adamw
Date: 2006-12-22 18:12:14 -0500 (Fri, 22 Dec 2006)
New Revision: 8579
Removed:
labs/jbosslabs/trunk/portal-extensions-2.6/forge-map/
labs/jbosslabs/trunk/portal-extensions-2.6/forge-mapper/src/java/org/jboss/labs/mapper/LabsCommandFactory.java
Log:
http://jira.jboss.com/jira/browse/JBLAB-817
Deleted: labs/jbosslabs/trunk/portal-extensions-2.6/forge-mapper/src/java/org/jboss/labs/mapper/LabsCommandFactory.java
===================================================================
--- labs/jbosslabs/trunk/portal-extensions-2.6/forge-mapper/src/java/org/jboss/labs/mapper/LabsCommandFactory.java 2006-12-22 23:11:49 UTC (rev 8578)
+++ labs/jbosslabs/trunk/portal-extensions-2.6/forge-mapper/src/java/org/jboss/labs/mapper/LabsCommandFactory.java 2006-12-22 23:12:14 UTC (rev 8579)
@@ -1,311 +0,0 @@
-package org.jboss.labs.mapper;
-
-import org.jboss.portal.core.model.portal.PortalObjectContainer;
-import org.jboss.portal.core.model.portal.Page;
-import org.jboss.portal.core.command.mapper.AbstractCommandFactory;
-import org.jboss.portal.core.command.mapper.CommandFactory;
-import org.jboss.portal.core.command.ControllerCommand;
-import org.jboss.portal.core.command.InvokeWindowActionCommand;
-import org.jboss.portal.core.command.RenderPageCommand;
-import org.jboss.portal.server.ServerInvocation;
-import org.jboss.portal.portlet.Parameters;
-import org.jboss.portal.portlet.PortletRequestDecoder;
-import org.jboss.portal.common.invocation.InvocationException;
-import org.jboss.shotoku.ContentManager;
-import org.jboss.shotoku.tools.Tools;
-import org.jboss.forge.common.projects.ProjectsHelper;
-import org.jboss.forge.common.projects.Projects;
-import org.jboss.forge.common.Constants;
-import org.jboss.forge.common.ForgeHelper;
-
-import java.io.IOException;
-
-/**
- * Command factory for labs. Uses following rules for URLs:
- * - / -> default page
- * - /projectId/pageName -> sets projectId as the selected project, goes to
- * page pageName
- * - /projectId/otherPath -> sets projectId as the selected project, invokes
- * freezone with otherPath
- * - /pageName -> goes to page pageName
- * - /otherPath -> invokes freezone with otherPath
- *
- * Currently, this supports only 1 portal (as set in
- * org.jboss.forge.common.Constants).
- *
- * @author Adam Warski (adamw at aster.pl)
- */
-public class LabsCommandFactory extends AbstractCommandFactory {
- private PortalObjectContainer container;
- private CommandFactory nextFactory;
- private ContentManager cm;
-
- /*
- * Getters and setters.
- */
-
- public PortalObjectContainer getContainer() {
- return container;
- }
-
- public void setContainer(PortalObjectContainer container) {
- this.container = container;
- }
-
- public CommandFactory getNextFactory() {
- return nextFactory;
- }
-
- public void setNextFactory(CommandFactory nextFactory) {
- this.nextFactory = nextFactory;
- }
-
- /*
- * Helper methods.
- */
-
- private void setParamIfNotNull(Parameters params, String name, String value) {
- if (value != null) {
- params.setValue(name, value);
- }
- }
-
- /**
- * Gets a command to render a page with the given name.
- */
- private ControllerCommand getPageCommand(ServerInvocation invocation, String name) {
- Page p = container.getContext().getDefaultPortal().getPage(name);
-
- if (p == null) {
- return null;
- }
-
- /*if ("wiki".equals(name)) {
-
- Parameters params = new Parameters();
- setParamIfNotNull(params, "page", getParameter(invocation, "page"));
- setParamIfNotNull(params, "language", getParameter(invocation, "language"));
-
- return new InvokeWindowActionCommand("default.wiki.WikiPortletWindow", null,
- null, null, null, params);
- }*/
-
- return new RenderPageCommand(p.getId());
- }
-
- /**
- * Gets path to the resource definied by the given parameters in the CMS.
- */
- private String getCmsPath(String portalName, String projectId, String path) {
- /*
- * If the requested path references a project, getting the page from
- * the project's freezone dir. Otherwise, getting the page from the
- * default directory.
- */
- String cmsPath = portalName + "/" + ProjectsHelper.MEMBERS_DIR + "/" +
- projectId + "/" + ProjectsHelper.FREEZONE_DIR + "/" + path;
-
- /*
- * Checking if we don't have to add a default page to the constructed
- * path.
- */
- if (!cmsPath.contains(".")) {
- if (!cmsPath.endsWith("/"))
- cmsPath += "/";
-
- cmsPath += Constants.DEFAULT_FREEZONE_PAGE;
- }
-
- return cmsPath;
- }
-
- /**
- * Gets a request attribute of the given name.
- */
- private String getParameter(ServerInvocation invocation, String name) {
- return invocation.getRequest().getContext().getClientRequest().getParameter(name);
- }
-
- /**
- * Sets an attribute of the given and value both in session and request.
- */
- private void setAttribute(ServerInvocation invocation, String name, String value) {
- invocation.getRequest().getContext().getClientRequest().setAttribute(name, value);
- invocation.getRequest().getContext().getClientRequest().getSession().setAttribute(name, value);
- }
-
- /**
- * Sets the response to be a redirect to the given location/
- */
- private void sendRedirect(ServerInvocation invocation, String where) throws IOException {
- invocation.getResponse().getContext().getClientResponse().sendRedirect(where);
- }
-
- /**
- * Gets the appropriate command basing on the given path and the selected
- * project. Path must not be empty.
- */
- private ControllerCommand getCommand(ServerInvocation invocation, String path,
- String projectId) {
- String[] tokens = path.split("[/]", 2);
-
- ControllerCommand c = getPageCommand(invocation, tokens[0]);
- if (c == null) {
- /*
- * No such page. In this case, we have to invoke freezone. There
- * are two possibilities:
- * - the requested resource has an appropriate mime type to display
- * it (typically text/html) - then we call the freezone portlet.
- * - the requested resource is of another mime type - in this case,
- * we send a redirect to the file-access servlet.
- */
- String cmsPath = getCmsPath(ForgeHelper.LABS_PORTAL, projectId, path);
-
- try {
- if (!Constants.PAGES_MIME_TYPE.equalsIgnoreCase(cm.getNode(cmsPath).getMimeType())) {
- sendRedirect(invocation, "/" + ForgeHelper.FILE_ACCESS_DIR + "/" + cmsPath);
- return getPageCommand(invocation, Constants.DEFAULT_PORTAL_PAGE);
- }
- } catch (Exception e) {
- return getPageCommand(invocation, Constants.DEFAULT_PORTAL_PAGE);
- }
-
- setAttribute(invocation, Constants.ATTR_REQ_PATH, cmsPath);
-
- return getPageCommand(invocation, Constants.FREEZONE_PAGE);
- } else {
- if (tokens.length == 2) {
- /*
- * Setting the rest of the path as an attribute so the portlets
- * can use it.
- */
- setAttribute(invocation, Constants.ATTR_REQ_PATH, tokens[1]);
- }
-
- return c;
- }
- }
-
- /**
- * Gets a command that should be executed, given the request path, if no
- * project is selected.
- */
- private ControllerCommand getNormalCommand(ServerInvocation invocation, String path) {
- if (Tools.isEmpty(path)) {
- return getPageCommand(invocation, Constants.DEFAULT_PORTAL_PAGE);
- }
-
- return getCommand(invocation, path, Constants.GLOBAL_FREEZONE_PRJ);
- }
-
- /**
- * Gets a command that should be executed, given the request path, if a
- * project is selected.
- */
- private ControllerCommand getProjectCommand(ServerInvocation invocation, String path,
- String projectId, Projects projects)
- throws IOException {
- if (Tools.isEmpty(path)) {
- /*
- * If the path is empty, we have to show the project's default
- * page. This can be:
- * - a normal info page
- * - a freezone page - in this case we just redirect to a
- * freezone
- * - an outside page - in this case, we redirect to this
- * outside page.
- */
- String freezonePage = projects.getProjectPageFreezone(projectId);
- if (!Tools.isEmpty(freezonePage)) {
- String redirect;
- if (Tools.isOutsideLink(freezonePage)) {
- redirect = freezonePage;
- } else {
- redirect = ProjectsHelper.createFreezonePageLink(
- ForgeHelper.LABS_PORTAL, projectId, freezonePage);
- }
-
- sendRedirect(invocation, redirect);
- }
-
- return getPageCommand(invocation, Constants.DEFAULT_PROJECT_PAGE);
- }
-
- return getCommand(invocation, path, projectId);
- }
-
- public ControllerCommand doMapping(ServerInvocation invocation, String portalContextPath,
- String portalRequestPath) {
- // TODO temporary for freezone
- String projectParam = invocation.getRequest().getContext().getClientRequest()
- .getParameter(Constants.PROJECT_PARAM);
- if (projectParam != null) {
- setAttribute(invocation, Constants.PROJECT_PARAM, projectParam);
- }
-
- // Removing unnecessary /.
- while (portalRequestPath.indexOf("//") != -1) {
- portalRequestPath = portalRequestPath.replace("//", "/");
- }
-
- /*
- * If this is an action/ nav etc request (in canonical form), path
- * parsing is not only not appropriate, it is not possible. So passing
- * it higher.
- */
- if (invocation.getRequest().getContext().getParameterMap().get(
- PortletRequestDecoder.META_PARAMETER) != null) {
- return nextFactory.doMapping(invocation, portalContextPath, portalRequestPath);
- }
-
- /*
- * If the user just logged in, showing the default page.
- */
- if (portalRequestPath.startsWith("/portal")) {
- portalRequestPath = portalRequestPath.substring(7);
- try {
- sendRedirect(invocation, portalRequestPath);
- } catch (IOException e) {
- throw new InvocationException(e);
- }
- return nextFactory.doMapping(invocation, portalContextPath, portalRequestPath);
- }
-
- ControllerCommand c;
- String[] tokens = portalRequestPath.split("[/]", 3);
- Projects projects = ProjectsHelper.getProjects(ForgeHelper.LABS_PORTAL);
- if ((tokens.length > 1) && (projects.projectExists(tokens[1]))) {
- /*
- * The user requested a project page (/projectId). It will be
- * unset, if necessary, in the AttributesFilter.
- */
- setAttribute(invocation, Constants.PROJECT_PARAM, tokens[1]);
-
- try {
- c = getProjectCommand(invocation, tokens.length > 2 ? tokens[2] : null,
- tokens[1], projects);
- } catch (IOException e) {
- throw new InvocationException(e);
- }
- } else {
- tokens = portalRequestPath.split("[/]", 2);
- // The user requested a non-project page - default, portlet page or
- // global freezone.
- c = getNormalCommand(invocation, tokens.length > 1 ? tokens[1] : null);
- }
-
- return c;
- }
-
- /*
- * Service management methods
- */
-
- protected void startService() throws Exception {
- cm = ContentManager.getContentManager();
- }
-
- protected void stopService() throws Exception {
-
- }
-}
More information about the jboss-svn-commits
mailing list