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.cocoon.portal.pluto;
018:
019: import java.util.Collection;
020: import java.util.HashMap;
021: import java.util.Map;
022: import java.util.Vector;
023:
024: import javax.portlet.PortletMode;
025: import javax.portlet.WindowState;
026:
027: import org.apache.cocoon.Constants;
028: import org.apache.cocoon.environment.ObjectModelHelper;
029: import org.apache.cocoon.environment.Request;
030: import org.apache.pluto.services.information.PortalContextProvider;
031:
032: /**
033: * Information about the portal
034: *
035: * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
036: *
037: * @version CVS $Id: PortalContextProviderImpl.java 433543 2006-08-22 06:22:54Z crossley $
038: */
039: public class PortalContextProviderImpl implements PortalContextProvider {
040:
041: /** Portal information */
042: protected String info;
043:
044: /** supported portlet modes by this portal */
045: protected Vector modes;
046:
047: /** supported window states by this portal */
048: protected Vector states;
049:
050: /** portal properties */
051: protected HashMap properties;
052:
053: /** The host name */
054: protected String hostNameHTTP;
055:
056: /** The host name */
057: protected String hostNameHTTPS;
058:
059: /** The host name */
060: protected String contextHTTP;
061:
062: /** The host name */
063: protected String contextHTTPS;
064:
065: /**
066: * Constructor
067: */
068: public PortalContextProviderImpl(Map objectModel) {
069: // these are the minimum modes that the portal needs to support
070: this .modes = this .getDefaultModes();
071: // these are the minimum states that the portal needs to support
072: this .states = this .getDefaultStates();
073: // set info
074: this .info = "Apache Cocoon/" + Constants.VERSION;
075: this .properties = new HashMap();
076: this .init(objectModel);
077: }
078:
079: /* (non-Javadoc)
080: * @see org.apache.pluto.services.information.PortalContextProvider#getProperty(java.lang.String)
081: */
082: public String getProperty(String name) {
083: if (name == null) {
084: throw new IllegalArgumentException("Property name == null");
085: }
086:
087: return (String) properties.get(name);
088: }
089:
090: /* (non-Javadoc)
091: * @see org.apache.pluto.services.information.PortalContextProvider#getPropertyNames()
092: */
093: public Collection getPropertyNames() {
094: return properties.keySet();
095: }
096:
097: /* (non-Javadoc)
098: * @see org.apache.pluto.services.information.PortalContextProvider#getSupportedPortletModes()
099: */
100: public Collection getSupportedPortletModes() {
101: return this .modes;
102: }
103:
104: /* (non-Javadoc)
105: * @see org.apache.pluto.services.information.PortalContextProvider#getSupportedWindowStates()
106: */
107: public Collection getSupportedWindowStates() {
108: return this .states;
109: }
110:
111: /* (non-Javadoc)
112: * @see org.apache.pluto.services.information.PortalContextProvider#getPortalInfo()
113: */
114: public String getPortalInfo() {
115: return this .info;
116: }
117:
118: /**
119: * Return all default modes
120: */
121: protected Vector getDefaultModes() {
122: Vector m = new Vector();
123:
124: m.add(new PortletMode("view"));
125: m.add(new PortletMode("edit"));
126: m.add(new PortletMode("help"));
127: m.add(new PortletMode("config"));
128:
129: return m;
130: }
131:
132: /**
133: * Return all default states
134: */
135: protected Vector getDefaultStates() {
136: Vector s = new Vector();
137:
138: s.add(new WindowState("normal"));
139: s.add(new WindowState("minimized"));
140: s.add(new WindowState("maximized"));
141:
142: return s;
143: }
144:
145: /**
146: * Initialize some infos
147: */
148: protected void init(Map objectModel) {
149: final Request request = ObjectModelHelper
150: .getRequest(objectModel);
151: final String hostName = request.getServerName();
152: final String contextRoot = request.getContextPath();
153: final int hostPortHTTP = request.getServerPort();
154: final int hostPortHTTPS = 443;
155:
156: StringBuffer hostHTTP = new StringBuffer("http://");
157: hostHTTP.append(hostName);
158: if (hostPortHTTP != 80) {
159: hostHTTP.append(":");
160: hostHTTP.append(hostPortHTTP);
161: }
162: this .hostNameHTTP = hostHTTP.toString();
163: hostHTTP.append('/');
164: hostHTTP.append(contextRoot);
165: this .contextHTTP = hostHTTP.toString();
166:
167: StringBuffer hostHTTPS = new StringBuffer("https://");
168: hostHTTPS.append(hostName);
169: if (hostPortHTTPS != 443) {
170: hostHTTPS.append(":");
171: hostHTTPS.append(hostPortHTTPS);
172: }
173: this .hostNameHTTPS = hostHTTPS.toString();
174: hostHTTPS.append('/');
175: hostHTTPS.append(contextRoot);
176: this .contextHTTPS = hostHTTPS.toString();
177: }
178:
179: public String getBaseURLexcludeContext(boolean secure) {
180: return (secure ? this .hostNameHTTPS : this .hostNameHTTP);
181: }
182:
183: public String getBaseURL(boolean secure) {
184: return (secure ? this.contextHTTPS : this.contextHTTP);
185: }
186:
187: }
|