You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pluto-scm@portals.apache.org by zh...@apache.org on 2006/01/25 19:38:11 UTC
svn commit: r372281 - in
/portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver:
./ core/ services/container/ tags/ url/
Author: zheng
Date: Wed Jan 25 10:37:59 2006
New Revision: 372281
URL: http://svn.apache.org/viewcvs?rev=372281&view=rev
Log:
Moved portal URL related classes to package org.apache.pluto.driver.url
Added:
portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/url/
portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/url/PortalURL.java
portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/url/PortalURLFactory.java
portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/url/PortalURLParameter.java
portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/url/PortalURLParser.java
Removed:
portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/core/PortalURL.java
portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/core/PortalUrlFactory.java
portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/core/PortalUrlParameter.java
portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/core/PortalUrlParser.java
Modified:
portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/PortalDriverServlet.java
portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/PortalStartupListener.java
portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/core/PortalEnvironment.java
portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/core/PortalServletRequest.java
portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/core/PortletWindowImpl.java
portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/core/ResourceURLProviderImpl.java
portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/container/PortletURLProviderImpl.java
portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/tags/PortletTag.java
portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/tags/PortletWindowControlTag.java
Modified: portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/PortalDriverServlet.java
URL: http://svn.apache.org/viewcvs/portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/PortalDriverServlet.java?rev=372281&r1=372280&r2=372281&view=diff
==============================================================================
--- portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/PortalDriverServlet.java (original)
+++ portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/PortalDriverServlet.java Wed Jan 25 10:37:59 2006
@@ -21,10 +21,10 @@
import org.apache.pluto.PortletContainerException;
import org.apache.pluto.driver.config.DriverConfiguration;
import org.apache.pluto.driver.core.PortalEnvironment;
-import org.apache.pluto.driver.core.PortalURL;
import org.apache.pluto.driver.core.PortletWindowImpl;
import org.apache.pluto.driver.services.portal.PageConfig;
import org.apache.pluto.driver.services.portal.PortletWindowConfig;
+import org.apache.pluto.driver.url.PortalURL;
import javax.portlet.PortletException;
import javax.servlet.RequestDispatcher;
@@ -130,6 +130,11 @@
// Private Methods ---------------------------------------------------------
+ /**
+ * Returns the config of the portal page to be rendered.
+ * @param currentURL the current portal URL.
+ * @return the config of the portal page to be rendered.
+ */
private PageConfig getPageConfig(PortalURL currentURL) {
String currentPage = currentURL.getRenderPath();
if (LOG.isDebugEnabled()) {
Modified: portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/PortalStartupListener.java
URL: http://svn.apache.org/viewcvs/portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/PortalStartupListener.java?rev=372281&r1=372280&r2=372281&view=diff
==============================================================================
--- portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/PortalStartupListener.java (original)
+++ portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/PortalStartupListener.java Wed Jan 25 10:37:59 2006
@@ -82,6 +82,9 @@
initDriverConfiguration(servletContext);
initAdminConfiguration(servletContext);
initContainer(servletContext);
+ if (LOG.isInfoEnabled()) {
+ LOG.info("********** Pluto Portal Driver Started **********");
+ }
}
/**
@@ -92,10 +95,15 @@
*/
public void contextDestroyed(ServletContextEvent event) {
ServletContext servletContext = event.getServletContext();
+ if (LOG.isInfoEnabled()) {
+ LOG.info("Shutting down Pluto Portal Driver...");
+ }
destroyContainer(servletContext);
destroyAdminConfiguration(servletContext);
destroyDriverConfiguration(servletContext);
-
+ if (LOG.isInfoEnabled()) {
+ LOG.info("********** Pluto Portal Driver Shut Down **********");
+ }
}
@@ -197,7 +205,7 @@
// Save portlet container to the servlet context scope.
servletContext.setAttribute(CONTAINER_KEY, container);
if (LOG.isInfoEnabled()) {
- LOG.info("Pluto Portal Driver started.");
+ LOG.info("Pluto portlet container started.");
}
} catch (DriverConfigurationException ex) {
Modified: portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/core/PortalEnvironment.java
URL: http://svn.apache.org/viewcvs/portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/core/PortalEnvironment.java?rev=372281&r1=372280&r2=372281&view=diff
==============================================================================
--- portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/core/PortalEnvironment.java (original)
+++ portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/core/PortalEnvironment.java Wed Jan 25 10:37:59 2006
@@ -22,6 +22,9 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import org.apache.pluto.driver.url.PortalURL;
+import org.apache.pluto.driver.url.PortalURLFactory;
+
/**
* The portal environment of the incoming servlet request and response.
*
@@ -56,8 +59,8 @@
this.request = request;
this.response = response;
// Parse servlet request and construct portal URL.
- this.requestedPortalURL = PortalUrlFactory.getFactory()
- .createPortalUrl(request);
+ this.requestedPortalURL = PortalURLFactory.getFactory()
+ .createPortalURL(request);
// Set Environment in servlet request scope for later use.
request.setAttribute(REQUEST_PORTALENV, this);
}
Modified: portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/core/PortalServletRequest.java
URL: http://svn.apache.org/viewcvs/portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/core/PortalServletRequest.java?rev=372281&r1=372280&r2=372281&view=diff
==============================================================================
--- portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/core/PortalServletRequest.java (original)
+++ portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/core/PortalServletRequest.java Wed Jan 25 10:37:59 2006
@@ -25,6 +25,8 @@
import javax.servlet.http.HttpServletRequestWrapper;
import org.apache.pluto.PortletWindow;
+import org.apache.pluto.driver.url.PortalURL;
+import org.apache.pluto.driver.url.PortalURLParameter;
public class PortalServletRequest extends HttpServletRequestWrapper {
@@ -82,7 +84,7 @@
Iterator iterator = url.getParameters().iterator();
while (iterator.hasNext()) {
- PortalUrlParameter param = (PortalUrlParameter) iterator.next();
+ PortalURLParameter param = (PortalURLParameter) iterator.next();
String name = param.getName();
String[] values = param.getValues();
if (param.getWindowId().equals(portletWindow.getId().toString())) {
Modified: portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/core/PortletWindowImpl.java
URL: http://svn.apache.org/viewcvs/portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/core/PortletWindowImpl.java?rev=372281&r1=372280&r2=372281&view=diff
==============================================================================
--- portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/core/PortletWindowImpl.java (original)
+++ portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/core/PortletWindowImpl.java Wed Jan 25 10:37:59 2006
@@ -24,11 +24,14 @@
import org.apache.pluto.PortletWindow;
import org.apache.pluto.driver.services.portal.PortletWindowConfig;
+import org.apache.pluto.driver.url.PortalURL;
import org.apache.pluto.driver.util.ObjectIdImpl;
import org.apache.pluto.om.ObjectID;
/**
- * Implementation of javax.portlet.PortletWindow interface.
+ * Implementation of <code>javax.portlet.PortletWindow</code> interface.
+ * @author <a href="mailto:zheng@apache.org">ZHENG Zhong</a>
+ * @author <a href="mailto:ddewolf@apache.org">David H. DeWolf</a>
*/
public class PortletWindowImpl implements PortletWindow {
Modified: portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/core/ResourceURLProviderImpl.java
URL: http://svn.apache.org/viewcvs/portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/core/ResourceURLProviderImpl.java?rev=372281&r1=372280&r2=372281&view=diff
==============================================================================
--- portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/core/ResourceURLProviderImpl.java (original)
+++ portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/core/ResourceURLProviderImpl.java Wed Jan 25 10:37:59 2006
@@ -24,6 +24,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.pluto.PortletWindow;
+import org.apache.pluto.driver.url.PortalURLFactory;
import org.apache.pluto.services.ResourceURLProvider;
public class ResourceURLProviderImpl implements ResourceURLProvider {
@@ -37,7 +38,7 @@
public ResourceURLProviderImpl(HttpServletRequest req,
PortletWindow internalPortletWindow) {
this.base =
- PortalUrlFactory.getFactory().createPortalUrl(req).getServerUri();
+ PortalURLFactory.getFactory().createPortalURL(req).getServerURI();
if (LOG.isDebugEnabled()) {
LOG.debug("Resource URL Created with base: " + base);
}
Modified: portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/container/PortletURLProviderImpl.java
URL: http://svn.apache.org/viewcvs/portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/container/PortletURLProviderImpl.java?rev=372281&r1=372280&r2=372281&view=diff
==============================================================================
--- portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/container/PortletURLProviderImpl.java (original)
+++ portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/container/PortletURLProviderImpl.java Wed Jan 25 10:37:59 2006
@@ -29,22 +29,26 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.pluto.PortletWindow;
-import org.apache.pluto.driver.core.PortalURL;
-import org.apache.pluto.driver.core.PortalUrlFactory;
-import org.apache.pluto.driver.core.PortalUrlParameter;
+import org.apache.pluto.driver.url.PortalURL;
+import org.apache.pluto.driver.url.PortalURLFactory;
+import org.apache.pluto.driver.url.PortalURLParameter;
import org.apache.pluto.services.PortletURLProvider;
+/**
+ *
+ * @author <a href="mailto:zheng@apache.org">ZHENG Zhong</a>
+ * @author <a href="mailto:ddewolf@apache.org">David H. DeWolf</a>
+ */
public class PortletURLProviderImpl implements PortletURLProvider {
- private static final Log LOG =
- LogFactory.getLog(PortletURLProviderImpl.class);
+ private static final Log LOG = LogFactory.getLog(PortletURLProviderImpl.class);
private PortalURL url;
private String window;
public PortletURLProviderImpl(HttpServletRequest request,
PortletWindow internalPortletWindow) {
- url = PortalUrlFactory.getFactory().createPortalUrl(request);
+ url = PortalURLFactory.getFactory().createPortalURL(request);
this.window = internalPortletWindow.getId().toString();
}
@@ -76,9 +80,10 @@
Iterator it = parameters.entrySet().iterator();
while (it.hasNext()) {
Map.Entry entry = (Map.Entry) it.next();
- PortalUrlParameter param = new PortalUrlParameter(window,
- (String) entry.getKey(),
- (String[]) entry.getValue());
+ PortalURLParameter param = new PortalURLParameter(
+ window,
+ (String) entry.getKey(),
+ (String[]) entry.getValue());
url.addParameter(param);
}
}
Modified: portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/tags/PortletTag.java
URL: http://svn.apache.org/viewcvs/portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/tags/PortletTag.java?rev=372281&r1=372280&r2=372281&view=diff
==============================================================================
--- portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/tags/PortletTag.java (original)
+++ portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/tags/PortletTag.java Wed Jan 25 10:37:59 2006
@@ -16,11 +16,11 @@
import org.apache.pluto.PortletWindow;
import org.apache.pluto.driver.AttributeKeys;
import org.apache.pluto.driver.services.portal.PortletWindowConfig;
+import org.apache.pluto.driver.url.PortalURL;
import org.apache.pluto.driver.config.DriverConfiguration;
import org.apache.pluto.driver.core.PortalEnvironment;
import org.apache.pluto.driver.core.PortalServletRequest;
import org.apache.pluto.driver.core.PortalServletResponse;
-import org.apache.pluto.driver.core.PortalURL;
import org.apache.pluto.driver.core.PortletWindowImpl;
import org.apache.taglibs.standard.lang.support.ExpressionEvaluatorManager;
Modified: portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/tags/PortletWindowControlTag.java
URL: http://svn.apache.org/viewcvs/portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/tags/PortletWindowControlTag.java?rev=372281&r1=372280&r2=372281&view=diff
==============================================================================
--- portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/tags/PortletWindowControlTag.java (original)
+++ portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/tags/PortletWindowControlTag.java Wed Jan 25 10:37:59 2006
@@ -24,8 +24,8 @@
import javax.servlet.jsp.tagext.BodyTagSupport;
import javax.servlet.jsp.tagext.TagSupport;
-import org.apache.pluto.driver.core.PortalURL;
-import org.apache.pluto.driver.core.PortalUrlFactory;
+import org.apache.pluto.driver.url.PortalURL;
+import org.apache.pluto.driver.url.PortalURLFactory;
/**
* @author <a href="ddewolf@apache.org">David H. DeWolf</a>
@@ -50,7 +50,7 @@
String id = parent.getEvaluatedPortletId();
HttpServletRequest req = (HttpServletRequest) pageContext.getRequest();
- PortalURL url = PortalUrlFactory.getFactory().createPortalUrl(req);
+ PortalURL url = PortalURLFactory.getFactory().createPortalURL(req);
if (windowState != null) {
WindowState state = new WindowState(windowState);
Added: portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/url/PortalURL.java
URL: http://svn.apache.org/viewcvs/portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/url/PortalURL.java?rev=372281&view=auto
==============================================================================
--- portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/url/PortalURL.java (added)
+++ portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/url/PortalURL.java Wed Jan 25 10:37:59 2006
@@ -0,0 +1,227 @@
+/*
+ * Copyright 2003,2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/*
+
+ */
+
+package org.apache.pluto.driver.url;
+
+import javax.portlet.PortletMode;
+import javax.portlet.WindowState;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+/**
+ * The portal URL.
+ * @author <a href="mailto:zheng@apache.org">ZHENG Zhong</a>
+ * @author <a href="mailto:ddewolf@apache.org">David H. DeWolf</a>
+ * @since 1.0
+ */
+public class PortalURL implements Cloneable {
+
+ /** Server URI contains protocol, host name, and (optional) port. */
+ private String serverURI = null;
+
+ private String servletPath = null;
+ private String renderPath = null;
+ private String actionWindow = null;
+
+ private Map windowStates = new HashMap();
+ private Map portletModes = new HashMap();
+
+ /** Parameters of the portlet windows. */
+ private Map parameters = new HashMap();
+
+
+ // Constructors ------------------------------------------------------------
+
+ /**
+ * Constructs a PortalURL instance using default port.
+ * @param protocol the protocol.
+ * @param hostName the host name.
+ * @param contextPath the servlet context path.
+ * @param servletName the servlet name.
+ */
+ public PortalURL(String protocol,
+ String hostName,
+ String contextPath,
+ String servletName) {
+ this(protocol, hostName, -1, contextPath, servletName);
+ }
+
+ /**
+ * Constructs a PortalURL instance using customized port.
+ * @param protocol the protocol.
+ * @param hostName the host name.
+ * @param port the port number: 0 or negative means using default port.
+ * @param contextPath the servlet context path.
+ * @param servletName the servlet name.
+ */
+ public PortalURL(String protocol,
+ String hostName,
+ int port,
+ String contextPath,
+ String servletName) {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append(protocol);
+ buffer.append(hostName);
+ if (port > 0) {
+ buffer.append(":").append(port);
+ }
+ serverURI = buffer.toString();
+
+ buffer = new StringBuffer();
+ buffer.append(contextPath);
+ buffer.append(servletName);
+ servletPath = buffer.toString();
+ }
+
+ /**
+ * Internal private constructor used by method <code>clone()</code>.
+ * @see #clone()
+ */
+ private PortalURL() {
+ // Do nothing.
+ }
+
+ // Public Methods ----------------------------------------------------------
+
+ public void setRenderPath(String renderPath) {
+ this.renderPath = renderPath;
+ }
+
+ public String getRenderPath() {
+ return renderPath;
+ }
+
+ public void addParameter(PortalURLParameter param) {
+ parameters.put(param.getWindowId() + param.getName(), param);
+ }
+
+ public Collection getParameters() {
+ return parameters.values();
+ }
+
+ public void setActionWindow(String actionWindow) {
+ this.actionWindow = actionWindow;
+ }
+
+ public String getActionWindow() {
+ return actionWindow;
+ }
+
+ public Map getPortletModes() {
+ return Collections.unmodifiableMap(portletModes);
+ }
+
+ public PortletMode getPortletMode(String windowId) {
+ PortletMode mode = (PortletMode) portletModes.get(windowId);
+ if (mode == null) {
+ mode = PortletMode.VIEW;
+ }
+ return mode;
+ }
+
+ public void setPortletMode(String windowId, PortletMode portletMode) {
+ portletModes.put(windowId, portletMode);
+ }
+
+ public Map getWindowStates() {
+ return Collections.unmodifiableMap(windowStates);
+ }
+
+ /**
+ * Returns the window state of the specified window.
+ * @param windowId the window ID.
+ * @return the window state. Default to NORMAL.
+ */
+ public WindowState getWindowState(String windowId) {
+ WindowState state = (WindowState) windowStates.get(windowId);
+ if (state == null) {
+ state = WindowState.NORMAL;
+ }
+ return state;
+ }
+
+ /**
+ * Sets the window state of the specified window.
+ * @param windowId the window ID.
+ * @param windowState the window state.
+ */
+ public void setWindowState(String windowId, WindowState windowState) {
+ this.windowStates.put(windowId, windowState);
+ }
+
+ /**
+ * Clear parameters of the specified window.
+ * @param windowId the window ID.
+ */
+ public void clearParameters(String windowId) {
+ for (Iterator it = parameters.entrySet().iterator(); it.hasNext(); ) {
+ Map.Entry entry = (Map.Entry) it.next();
+ PortalURLParameter param = (PortalURLParameter) entry.getValue();
+ if (param.getWindowId().equals(windowId)) {
+ it.remove();
+ }
+ }
+ }
+
+ /**
+ * Converts to a string representing the portal URL.
+ * @return a string representing the portal URL.
+ * @see org.apache.pluto.driver.url.PortalURLParser#toString(PortalURL)
+ */
+ public String toString() {
+ return PortalURLParser.getParser().toString(this);
+ }
+
+
+ /**
+ * Returns the server URI (protocol, name, port).
+ * @return the server URI portion of the portal URL.
+ */
+ public String getServerURI() {
+ return serverURI;
+ }
+
+ /**
+ * Returns the servlet path (context path + servlet name).
+ * @return the servlet path.
+ */
+ public String getServletPath() {
+ return servletPath;
+ }
+
+ /**
+ * Clone a copy of itself.
+ * @return a copy of itself.
+ */
+ public Object clone() {
+ PortalURL portalURL = new PortalURL();
+ portalURL.serverURI = this.serverURI;
+ portalURL.servletPath = this.servletPath;
+ portalURL.parameters = new HashMap(parameters);
+ portalURL.portletModes = new HashMap(portletModes);
+ portalURL.windowStates = new HashMap(windowStates);
+ portalURL.renderPath = renderPath;
+ portalURL.actionWindow = actionWindow;
+ return portalURL;
+ }
+}
Added: portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/url/PortalURLFactory.java
URL: http://svn.apache.org/viewcvs/portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/url/PortalURLFactory.java?rev=372281&view=auto
==============================================================================
--- portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/url/PortalURLFactory.java (added)
+++ portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/url/PortalURLFactory.java Wed Jan 25 10:37:59 2006
@@ -0,0 +1,53 @@
+package org.apache.pluto.driver.url;
+
+import javax.servlet.http.HttpServletRequest;
+
+/**
+ * @author <a href="mailto:ddewolf@apache.org">David H. DeWolf</a>
+ * @author <a href="mailto:zheng@apache.org">ZHENG Zhong</a>
+ */
+public class PortalURLFactory {
+
+ private static final String KEY = PortalURL.class.getName();
+
+ /** The singleton factory instance. */
+ private static final PortalURLFactory FACTORY = new PortalURLFactory();
+
+
+ // Constructor -------------------------------------------------------------
+
+ /**
+ * Private constructor that prevents external instantiation.
+ */
+ private PortalURLFactory() {
+ // Do nothing.
+ }
+
+ /**
+ * Returns the singleton factory instance.
+ * @return the singleton factory instance.
+ */
+ public static PortalURLFactory getFactory() {
+ return FACTORY;
+ }
+
+
+ // Public Methods ----------------------------------------------------------
+
+ /**
+ * Creates a portal URL from the servlet request. If the servlet request
+ * does not contain a portal URL (in request scope), the method creates a
+ * portal URL and saves it into the request scope.
+ * @param request the servlet request.
+ * @return a portal URL created from the servlet request.
+ */
+ public PortalURL createPortalURL(HttpServletRequest request) {
+ PortalURL portalURL = (PortalURL) request.getAttribute(KEY);
+ if (portalURL == null) {
+ portalURL = PortalURLParser.getParser().parse(request);
+ request.setAttribute(KEY, portalURL);
+ }
+ return (PortalURL) portalURL.clone();
+ }
+
+}
Added: portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/url/PortalURLParameter.java
URL: http://svn.apache.org/viewcvs/portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/url/PortalURLParameter.java?rev=372281&view=auto
==============================================================================
--- portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/url/PortalURLParameter.java (added)
+++ portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/url/PortalURLParameter.java Wed Jan 25 10:37:59 2006
@@ -0,0 +1,65 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pluto.driver.url;
+
+/**
+ * The portal URL parameter.
+ * @author <a href="mailto:ddewolf@apache.org">David H. DeWolf</a>
+ * @author <a href="mailto:zheng@apache.org">ZHENG Zhong</a>
+ * @version 1.0
+ * @since Sep 30, 2004
+ */
+public class PortalURLParameter {
+
+
+ private String window;
+ private String name;
+ private String[] values;
+
+ public PortalURLParameter(String window, String name, String value) {
+ this.window = window;
+ this.name = name;
+ this.values = new String[]{value};
+ }
+
+ public PortalURLParameter(String window, String name, String[] values) {
+ this.window = window;
+ this.name = name;
+ this.values = values;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String[] getValues() {
+ return values;
+ }
+
+ public void setValues(String[] values) {
+ this.values = values;
+ }
+
+ public String getWindowId() {
+ return window;
+ }
+
+}
+
Added: portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/url/PortalURLParser.java
URL: http://svn.apache.org/viewcvs/portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/url/PortalURLParser.java?rev=372281&view=auto
==============================================================================
--- portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/url/PortalURLParser.java (added)
+++ portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/url/PortalURLParser.java Wed Jan 25 10:37:59 2006
@@ -0,0 +1,361 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pluto.driver.url;
+
+import java.util.Iterator;
+import java.util.Map;
+import java.util.StringTokenizer;
+
+import javax.portlet.PortletMode;
+import javax.portlet.WindowState;
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.pluto.util.StringUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * @author <a href="mailto:zheng@apache.org">ZHENG Zhong</a>
+ * @author <a href="mailto:ddewolf@apache.org">David H. DeWolf</a>
+ * @version 1.0
+ * @since Sep 30, 2004
+ */
+class PortalURLParser {
+
+ /** Logger. */
+ private static final Log LOG = LogFactory.getLog(PortalURLParser.class);
+
+ /** The singleton parser instance. */
+ private static final PortalURLParser PARSER = new PortalURLParser();
+
+
+ // Constants used for Encoding/Decoding ------------------------------------
+
+ private static final String PREFIX = "__";
+ private static final String DELIM = "_";
+ private static final String PORTLET_ID = "pd";
+ private static final String ACTION = "ac";
+ private static final String RENDER_PARAM = "rp";
+ private static final String WINDOW_STATE = "ws";
+ private static final String PORTLET_MODE = "pm";
+ private static final String VALUE_DELIM = "0x0";
+
+ private static final String[][] ENCODINGS = new String[][] {
+ new String[] { "_", "0x1" },
+ new String[] { ".", "0x2" },
+ new String[] { "/", "0x3" },
+ new String[] { "\r", "0x4" },
+ new String[] { "\n", "0x5" },
+ new String[] { "<", "0x6" },
+ new String[] { ">", "0x7" },
+ new String[] { " ", "0x8" },
+ };
+
+ // Constructor -------------------------------------------------------------
+
+ /**
+ * Private constructor that prevents external instantiation.
+ */
+ private PortalURLParser() {
+ // Do nothing.
+ }
+
+ /**
+ * Returns the singleton parser instance.
+ * @return the singleton parser instance.
+ */
+ public static PortalURLParser getParser() {
+ return PARSER;
+ }
+
+
+ // Public Methods ----------------------------------------------------------
+
+ /**
+ * Parse a servlet request to a portal URL.
+ * @param request the servlet request to parse.
+ * @return the portal URL.
+ */
+ public PortalURL parse(HttpServletRequest request) {
+
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Parsing URL: " + request.getRequestURI());
+ }
+
+ String protocol = request.isSecure() ? "https://" : "http://";
+ String server = request.getServerName();
+ int port = request.getServerPort();
+ String contextPath = request.getContextPath();
+ String servletName = request.getServletPath();
+
+ // Construct portal URL using info retrieved from servlet request.
+ PortalURL portalURL = null;
+ if ((request.isSecure() && port != 443)
+ || (!request.isSecure() && port != 80)) {
+ portalURL = new PortalURL(protocol, server, port, contextPath, servletName);
+ } else {
+ portalURL = new PortalURL(protocol, server, contextPath, servletName);
+ }
+
+ String pathInfo = request.getPathInfo();
+ if (pathInfo == null) {
+ return portalURL;
+ }
+
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Parsing request pathInfo: " + pathInfo);
+ }
+ StringBuffer renderPath = new StringBuffer();
+ StringTokenizer st = new StringTokenizer(pathInfo, "/", false);
+ while (st.hasMoreTokens()) {
+
+ String token = st.nextToken();
+
+ // Part of the render path: append to renderPath.
+ if (!token.startsWith(PREFIX)) {
+ renderPath.append(token);
+ }
+ // Action window definition: portalURL.setActionWindow().
+ else if (token.startsWith(PREFIX + ACTION)) {
+ portalURL.setActionWindow(decodeControlParameter(token)[0]);
+ }
+ // Window state definition: portalURL.setWindowState().
+ else if (token.startsWith(PREFIX + WINDOW_STATE)) {
+ String[] decoded = decodeControlParameter(token);
+ portalURL.setWindowState(decoded[0], new WindowState(decoded[1]));
+ }
+ // Portlet mode definition: portalURL.setPortletMode().
+ else if (token.startsWith(PREFIX + PORTLET_MODE)) {
+ String[] decoded = decodeControlParameter(token);
+ portalURL.setPortletMode(decoded[0], new PortletMode(decoded[1]));
+ }
+ // Portal URL parameter: portalURL.addParameter().
+ else {
+ String value = null;
+ if (st.hasMoreTokens()) {
+ value = st.nextToken();
+ }
+ portalURL.addParameter(decodeParameter(token, value));
+ }
+ }
+ if (renderPath.length() > 0) {
+ portalURL.setRenderPath(renderPath.toString());
+ }
+
+ // Return the portal URL.
+ return portalURL;
+ }
+
+
+ /**
+ * Converts a portal URL to a URL string.
+ * @param portalURL the portal URL to convert.
+ * @return a URL string representing the portal URL.
+ */
+ public String toString(PortalURL portalURL) {
+
+ StringBuffer buffer = new StringBuffer();
+
+ // Append the server URI and the servlet path.
+ buffer.append(portalURL.getServerURI())
+ .append(portalURL.getServletPath());
+
+ // Start the pathInfo with the path to the render URL (page).
+ if (portalURL.getRenderPath() != null) {
+ buffer.append("/").append(portalURL.getRenderPath());
+ }
+
+ // Append the action window definition, if it exists.
+ if (portalURL.getActionWindow() != null) {
+ buffer.append("/");
+ buffer.append(PREFIX).append(ACTION)
+ .append(encodeCharacters(portalURL.getActionWindow()));
+ }
+
+ // Append portlet mode definitions.
+ for (Iterator it = portalURL.getPortletModes().entrySet().iterator();
+ it.hasNext(); ) {
+ Map.Entry entry = (Map.Entry) it.next();
+ buffer.append("/").append(
+ encodeControlParameter(PORTLET_MODE, entry.getKey().toString(),
+ entry.getValue().toString()));
+ }
+
+ // Append window state definitions.
+ for (Iterator it = portalURL.getWindowStates().entrySet().iterator();
+ it.hasNext(); ) {
+ Map.Entry entry = (Map.Entry) it.next();
+ buffer.append("/").append(
+ encodeControlParameter(WINDOW_STATE, entry.getKey().toString(),
+ entry.getValue().toString()));
+ }
+
+ // Append action and render parameters.
+ StringBuffer query = new StringBuffer("?");
+ for (Iterator it = portalURL.getParameters().iterator();
+ it.hasNext(); ) {
+
+ PortalURLParameter param = (PortalURLParameter) it.next();
+
+ // Encode action params in the query appended at the end of the URL.
+ if (portalURL.getActionWindow() != null
+ && portalURL.getActionWindow().equals(param.getWindowId())) {
+ for (int i = 0; i < param.getValues().length; i++) {
+ query.append("&").append(param.getName()).append("=")
+ .append(param.getValues()[i]);
+ }
+ }
+
+ // Encode render params as a part of the URL.
+ else if (param.getValues() != null
+ && param.getValues().length > 0) {
+ String valueString = encodeMultiValues(param.getValues());
+ if (valueString.length() > 0) {
+ buffer.append("/").append(
+ encodeControlParameter(RENDER_PARAM, param.getWindowId(),
+ param.getName()));
+ buffer.append("/").append(valueString);
+ }
+ }
+ }
+
+ // Construct the string representing the portal URL.
+ return buffer.append(query).toString();
+ }
+
+
+ // Private Encoding/Decoding Methods ---------------------------------------
+
+ /**
+ * Encode a control parameter.
+ * @param type the type of the control parameter, which may be:
+ * portlet mode, window state, or render parameter.
+ * @param windowId the portlet window ID.
+ * @param name the name to encode.
+ */
+ private String encodeControlParameter(String type,
+ String windowId,
+ String name) {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append(PREFIX).append(type)
+ .append(encodeCharacters(windowId))
+ .append(DELIM).append(name);
+ return buffer.toString();
+ }
+
+ /**
+ * Encode a string array containing multiple values into a single string.
+ * This method is used to encode multiple render parameter values.
+ * @param values the string array to encode.
+ * @return a single string containing all the values.
+ */
+ private String encodeMultiValues(String[] values) {
+ StringBuffer buffer = new StringBuffer();
+ for (int i = 0; i < values.length; i++) {
+ buffer.append(values[i] != null ? values[i] : "");
+ if (i + 1 < values.length) {
+ buffer.append(VALUE_DELIM);
+ }
+ }
+ return encodeCharacters(buffer.toString());
+ }
+
+ /**
+ * Encode special characters contained in the string value.
+ * @param string the string value to encode.
+ * @return the encoded string.
+ */
+ private String encodeCharacters(String string) {
+ for (int i = 0; i < ENCODINGS.length; i++) {
+ string = StringUtils.replace(string,
+ ENCODINGS[i][0],
+ ENCODINGS[i][1]);
+ }
+ return string;
+ }
+
+
+ /**
+ * Decode a control parameter.
+ * @param control the control parameter to decode.
+ * @return values a pair of decoded values.
+ */
+ private String[] decodeControlParameter(String control) {
+ String[] valuePair = new String[2];
+ control = control.substring((PREFIX + PORTLET_ID).length());
+ int index = control.indexOf(DELIM);
+ if (index >= 0) {
+ valuePair[0] = control.substring(0, index);
+ valuePair[0] = decodeCharacters(valuePair[0]);
+ if (index + 1 <= control.length()) {
+ valuePair[1] = control.substring(index + 1);
+ valuePair[1] = decodeCharacters(valuePair[1]);
+ } else {
+ valuePair[1] = "";
+ }
+ } else {
+ valuePair[0] = decodeCharacters(control);
+ }
+ return valuePair;
+ }
+
+ /**
+ * Decode a name-value pair into a portal URL parameter.
+ * @param name the parameter name.
+ * @param value the parameter value.
+ * @return the decoded portal URL parameter.
+ */
+ private PortalURLParameter decodeParameter(String name, String value) {
+
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Decoding parameter: name=" + name
+ + ", value=" + value);
+ }
+
+ // Decode the name into window ID and parameter name.
+ String noPrefix = name.substring((PREFIX + PORTLET_ID).length());
+ String windowId = noPrefix.substring(0, noPrefix.indexOf(DELIM));
+ String paramName = noPrefix.substring(noPrefix.indexOf(DELIM) + 1);
+
+ // Decode special characters in window ID and parameter value.
+ windowId = decodeCharacters(windowId);
+ if (value != null) {
+ value = decodeCharacters(value);
+ }
+
+ // Split multiple values into a value array.
+ String[] paramValues = value.split(VALUE_DELIM);
+
+ // Construct portal URL parameter and return.
+ return new PortalURLParameter(windowId, paramName, paramValues);
+ }
+
+ /**
+ * Decode special characters contained in the string value.
+ * @param string the string value to decode.
+ * @return the decoded string.
+ */
+ private String decodeCharacters(String string) {
+ for (int i = 0; i < ENCODINGS.length; i++) {
+ string = StringUtils.replace(string,
+ ENCODINGS[i][1],
+ ENCODINGS[i][0]);
+ }
+ return string;
+ }
+
+}
+