001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.pluto.driver.url.impl;
018:
019: import org.apache.pluto.driver.url.PortalURL;
020: import org.apache.pluto.driver.url.PortalURLParameter;
021: import org.apache.commons.logging.Log;
022: import org.apache.commons.logging.LogFactory;
023:
024: import javax.portlet.PortletMode;
025: import javax.portlet.WindowState;
026: import java.util.Map;
027: import java.util.HashMap;
028: import java.util.Collection;
029: import java.util.Collections;
030: import java.util.Iterator;
031:
032: /**
033: * The portal URL.
034: * @since 1.0
035: */
036: public class RelativePortalURLImpl implements PortalURL {
037:
038: private static final Log LOG = LogFactory
039: .getLog(RelativePortalURLImpl.class);
040:
041: private String servletPath;
042: private String renderPath;
043: private String actionWindow;
044:
045: /** The window states: key is the window ID, value is WindowState. */
046: private Map windowStates = new HashMap();
047:
048: private Map portletModes = new HashMap();
049:
050: /** Parameters of the portlet windows. */
051: private Map parameters = new HashMap();
052:
053: /**
054: * Constructs a PortalURLImpl instance using customized port.
055: * @param contextPath the servlet context path.
056: * @param servletName the servlet name.
057: */
058: public RelativePortalURLImpl(String contextPath, String servletName) {
059: StringBuffer buffer = new StringBuffer();
060: buffer.append(contextPath);
061: buffer.append(servletName);
062: servletPath = buffer.toString();
063: }
064:
065: /**
066: * Internal private constructor used by method <code>clone()</code>.
067: * @see #clone()
068: */
069: private RelativePortalURLImpl() {
070: // Do nothing.
071: }
072:
073: // Public Methods ----------------------------------------------------------
074:
075: public void setRenderPath(String renderPath) {
076: this .renderPath = renderPath;
077: }
078:
079: public String getRenderPath() {
080: return renderPath;
081: }
082:
083: public void addParameter(PortalURLParameter param) {
084: parameters.put(param.getWindowId() + param.getName(), param);
085: }
086:
087: public Collection getParameters() {
088: return parameters.values();
089: }
090:
091: public void setActionWindow(String actionWindow) {
092: this .actionWindow = actionWindow;
093: }
094:
095: public String getActionWindow() {
096: return actionWindow;
097: }
098:
099: public Map getPortletModes() {
100: return Collections.unmodifiableMap(portletModes);
101: }
102:
103: public PortletMode getPortletMode(String windowId) {
104: PortletMode mode = (PortletMode) portletModes.get(windowId);
105: if (mode == null) {
106: mode = PortletMode.VIEW;
107: }
108: return mode;
109: }
110:
111: public void setPortletMode(String windowId, PortletMode portletMode) {
112: portletModes.put(windowId, portletMode);
113: }
114:
115: public Map getWindowStates() {
116: return Collections.unmodifiableMap(windowStates);
117: }
118:
119: /**
120: * Returns the window state of the specified window.
121: * @param windowId the window ID.
122: * @return the window state. Default to NORMAL.
123: */
124: public WindowState getWindowState(String windowId) {
125: WindowState state = (WindowState) windowStates.get(windowId);
126: if (state == null) {
127: state = WindowState.NORMAL;
128: }
129: return state;
130: }
131:
132: /**
133: * Sets the window state of the specified window.
134: * @param windowId the window ID.
135: * @param windowState the window state.
136: */
137: public void setWindowState(String windowId, WindowState windowState) {
138: this .windowStates.put(windowId, windowState);
139: }
140:
141: /**
142: * Clear parameters of the specified window.
143: * @param windowId the window ID.
144: */
145: public void clearParameters(String windowId) {
146: for (Iterator it = parameters.entrySet().iterator(); it
147: .hasNext();) {
148: Map.Entry entry = (Map.Entry) it.next();
149: PortalURLParameter param = (PortalURLParameter) entry
150: .getValue();
151: if (param.getWindowId().equals(windowId)) {
152: it.remove();
153: }
154: }
155: }
156:
157: /**
158: * Converts to a string representing the portal URL.
159: * @return a string representing the portal URL.
160: * @see PortalURLParserImpl#toString(org.apache.pluto.driver.url.PortalURL)
161: */
162: public String toString() {
163: return PortalURLParserImpl.getParser().toString(this );
164: }
165:
166: /**
167: * Returns the server URI (protocol, name, port).
168: * @return the server URI portion of the portal URL.
169: * @deprecated
170: */
171: public String getServerURI() {
172: return null;
173: }
174:
175: /**
176: * Returns the servlet path (context path + servlet name).
177: * @return the servlet path.
178: */
179: public String getServletPath() {
180: return servletPath;
181: }
182:
183: /**
184: * Clone a copy of itself.
185: * @return a copy of itself.
186: */
187: public Object clone() {
188: RelativePortalURLImpl portalURL = new RelativePortalURLImpl();
189: portalURL.servletPath = this .servletPath;
190: portalURL.parameters = new HashMap(parameters);
191: portalURL.portletModes = new HashMap(portletModes);
192: portalURL.windowStates = new HashMap(windowStates);
193: portalURL.renderPath = renderPath;
194: portalURL.actionWindow = actionWindow;
195: return portalURL;
196: }
197: }
|