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 java.util.Collection;
020: import java.util.Collections;
021: import java.util.HashMap;
022: import java.util.Iterator;
023: import java.util.Map;
024:
025: import javax.portlet.PortletMode;
026: import javax.portlet.WindowState;
027:
028: import org.apache.pluto.driver.url.PortalURL;
029: import org.apache.pluto.driver.url.PortalURLParameter;
030: import org.apache.pluto.driver.url.PortalURLParser;
031:
032: /**
033: * The portal URL.
034: * @since 1.0
035: * @deprecated replaced by {@link RelativePortalURLImpl}
036: */
037: public class PortalURLImpl implements PortalURL {
038:
039: /** Server URI contains protocol, host name, and (optional) port. */
040: private String serverURI;
041:
042: private String servletPath;
043: private String renderPath;
044: private String actionWindow;
045:
046: /**
047: * PortalURLParser used to construct the string
048: * representation of this portal url.
049: */
050: private PortalURLParser urlParser;
051:
052: /** The window states: key is the window ID, value is WindowState. */
053: private Map windowStates = new HashMap();
054:
055: private Map portletModes = new HashMap();
056:
057: /** Parameters of the portlet windows. */
058: private Map parameters = new HashMap();
059:
060: // Constructors ------------------------------------------------------------
061:
062: /**
063: * Constructs a PortalURLImpl instance using default port.
064: * @param protocol the protocol.
065: * @param hostName the host name.
066: * @param contextPath the servlet context path.
067: * @param servletName the servlet name.
068: */
069: public PortalURLImpl(String protocol, String hostName,
070: String contextPath, String servletName,
071: PortalURLParser urlParser) {
072: this (protocol, hostName, -1, contextPath, servletName,
073: urlParser);
074: }
075:
076: /**
077: * Constructs a PortalURLImpl instance using customized port.
078: * @param protocol the protocol.
079: * @param hostName the host name.
080: * @param port the port number: 0 or negative means using default port.
081: * @param contextPath the servlet context path.
082: * @param servletName the servlet name.
083: */
084: public PortalURLImpl(String protocol, String hostName, int port,
085: String contextPath, String servletName,
086: PortalURLParser urlParser) {
087: StringBuffer buffer = new StringBuffer();
088: buffer.append(protocol);
089: buffer.append(hostName);
090: if (port > 0) {
091: buffer.append(":").append(port);
092: }
093: serverURI = buffer.toString();
094:
095: buffer = new StringBuffer();
096: buffer.append(contextPath);
097: buffer.append(servletName);
098: servletPath = buffer.toString();
099: this .urlParser = urlParser;
100: }
101:
102: /**
103: * Internal private constructor used by method <code>clone()</code>.
104: * @see #clone()
105: */
106: private PortalURLImpl() {
107: // Do nothing.
108: }
109:
110: // Public Methods ----------------------------------------------------------
111:
112: public void setRenderPath(String renderPath) {
113: this .renderPath = renderPath;
114: }
115:
116: public String getRenderPath() {
117: return renderPath;
118: }
119:
120: public void addParameter(PortalURLParameter param) {
121: parameters.put(param.getWindowId() + param.getName(), param);
122: }
123:
124: public Collection getParameters() {
125: return parameters.values();
126: }
127:
128: public void setActionWindow(String actionWindow) {
129: this .actionWindow = actionWindow;
130: }
131:
132: public String getActionWindow() {
133: return actionWindow;
134: }
135:
136: public Map getPortletModes() {
137: return Collections.unmodifiableMap(portletModes);
138: }
139:
140: public PortletMode getPortletMode(String windowId) {
141: PortletMode mode = (PortletMode) portletModes.get(windowId);
142: if (mode == null) {
143: mode = PortletMode.VIEW;
144: }
145: return mode;
146: }
147:
148: public void setPortletMode(String windowId, PortletMode portletMode) {
149: portletModes.put(windowId, portletMode);
150: }
151:
152: public Map getWindowStates() {
153: return Collections.unmodifiableMap(windowStates);
154: }
155:
156: /**
157: * Returns the window state of the specified window.
158: * @param windowId the window ID.
159: * @return the window state. Default to NORMAL.
160: */
161: public WindowState getWindowState(String windowId) {
162: WindowState state = (WindowState) windowStates.get(windowId);
163: if (state == null) {
164: state = WindowState.NORMAL;
165: }
166: return state;
167: }
168:
169: /**
170: * Sets the window state of the specified window.
171: * @param windowId the window ID.
172: * @param windowState the window state.
173: */
174: public void setWindowState(String windowId, WindowState windowState) {
175: this .windowStates.put(windowId, windowState);
176: }
177:
178: /**
179: * Clear parameters of the specified window.
180: * @param windowId the window ID.
181: */
182: public void clearParameters(String windowId) {
183: for (Iterator it = parameters.entrySet().iterator(); it
184: .hasNext();) {
185: Map.Entry entry = (Map.Entry) it.next();
186: PortalURLParameter param = (PortalURLParameter) entry
187: .getValue();
188: if (param.getWindowId().equals(windowId)) {
189: it.remove();
190: }
191: }
192: }
193:
194: /**
195: * Converts to a string representing the portal URL.
196: * @return a string representing the portal URL.
197: * @see org.apache.pluto.driver.url.impl.PortalURLParserImpl#toString(PortalURL)
198: */
199: public String toString() {
200: return urlParser.toString(this );
201: }
202:
203: /**
204: * Returns the server URI (protocol, name, port).
205: * @return the server URI portion of the portal URL.
206: */
207: public String getServerURI() {
208: return serverURI;
209: }
210:
211: /**
212: * Returns the servlet path (context path + servlet name).
213: * @return the servlet path.
214: */
215: public String getServletPath() {
216: return servletPath;
217: }
218:
219: /**
220: * Clone a copy of itself.
221: * @return a copy of itself.
222: */
223: public Object clone() {
224: PortalURLImpl portalURL = new PortalURLImpl();
225: portalURL.serverURI = this .serverURI;
226: portalURL.servletPath = this .servletPath;
227: portalURL.parameters = new HashMap(parameters);
228: portalURL.portletModes = new HashMap(portletModes);
229: portalURL.windowStates = new HashMap(windowStates);
230: portalURL.renderPath = renderPath;
231: portalURL.actionWindow = actionWindow;
232: return portalURL;
233: }
234: }
|