KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > portal > pluto > PortalContextProviderImpl


1 /*
2  * Copyright 2004,2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.cocoon.portal.pluto;
17
18 import java.util.Collection JavaDoc;
19 import java.util.HashMap JavaDoc;
20 import java.util.Map JavaDoc;
21 import java.util.Vector JavaDoc;
22
23 import javax.portlet.PortletMode;
24 import javax.portlet.WindowState;
25
26 import org.apache.cocoon.Constants;
27 import org.apache.cocoon.environment.ObjectModelHelper;
28 import org.apache.cocoon.environment.Request;
29 import org.apache.pluto.services.information.PortalContextProvider;
30
31 /**
32  * Information about the portal
33  *
34  * @author <a HREF="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
35  *
36  * @version CVS $Id: PortalContextProviderImpl.java 30932 2004-07-29 17:35:38Z vgritsenko $
37  */

38 public class PortalContextProviderImpl
39 implements PortalContextProvider {
40
41     /** Portal information */
42     protected String JavaDoc info;
43
44     /** supported portlet modes by this portal */
45     protected Vector JavaDoc modes;
46
47     /** supported window states by this portal */
48     protected Vector JavaDoc states;
49
50     /** portal properties */
51     protected HashMap JavaDoc properties;
52
53     /** The host name */
54     protected String JavaDoc hostNameHTTP;
55     
56     /** The host name */
57     protected String JavaDoc hostNameHTTPS;
58     
59     /** The host name */
60     protected String JavaDoc contextHTTP;
61     
62     /** The host name */
63     protected String JavaDoc contextHTTPS;
64
65     /**
66      * Constructor
67      */

68     public PortalContextProviderImpl(Map JavaDoc objectModel) {
69         // these are the minimum modes that the portal needs to support
70
this.modes = this.getDefaultModes();
71         // these are the minimum states that the portal needs to support
72
this.states = this.getDefaultStates();
73         // set info
74
this.info = "Apache Cocoon/" + Constants.VERSION;
75         this.properties = new HashMap JavaDoc();
76         this.init(objectModel);
77     }
78
79     /* (non-Javadoc)
80      * @see org.apache.pluto.services.information.PortalContextProvider#getProperty(java.lang.String)
81      */

82     public String JavaDoc getProperty(String JavaDoc name) {
83         if (name == null) {
84             throw new IllegalArgumentException JavaDoc("Property name == null");
85         }
86
87         return(String JavaDoc) properties.get(name);
88     }
89
90
91     /* (non-Javadoc)
92      * @see org.apache.pluto.services.information.PortalContextProvider#getPropertyNames()
93      */

94     public Collection JavaDoc getPropertyNames() {
95         return properties.keySet();
96     }
97
98
99     /* (non-Javadoc)
100      * @see org.apache.pluto.services.information.PortalContextProvider#getSupportedPortletModes()
101      */

102     public Collection JavaDoc getSupportedPortletModes() {
103         return this.modes;
104     }
105
106
107     /* (non-Javadoc)
108      * @see org.apache.pluto.services.information.PortalContextProvider#getSupportedWindowStates()
109      */

110     public Collection JavaDoc getSupportedWindowStates() {
111         return this.states;
112     }
113
114
115     /* (non-Javadoc)
116      * @see org.apache.pluto.services.information.PortalContextProvider#getPortalInfo()
117      */

118     public String JavaDoc getPortalInfo() {
119         return this.info;
120     }
121
122     /**
123      * Return all default modes
124      */

125     protected Vector JavaDoc getDefaultModes() {
126         Vector JavaDoc m = new Vector JavaDoc();
127
128         m.add(new PortletMode("view"));
129         m.add(new PortletMode("edit"));
130         m.add(new PortletMode("help"));
131         m.add(new PortletMode("config"));
132         
133         return m;
134     }
135
136     /**
137      * Return all default states
138      */

139     protected Vector JavaDoc getDefaultStates() {
140         Vector JavaDoc s = new Vector JavaDoc();
141
142         s.add(new WindowState("normal"));
143         s.add(new WindowState("minimized"));
144         s.add(new WindowState("maximized"));
145         
146         return s;
147     }
148
149     /**
150      * Initialize some infos
151      */

152     protected void init(Map JavaDoc objectModel) {
153         final Request request = ObjectModelHelper.getRequest(objectModel);
154         final String JavaDoc hostName = request.getServerName();
155         final String JavaDoc contextRoot = request.getContextPath();
156         final int hostPortHTTP = request.getServerPort();
157         final int hostPortHTTPS = 443;
158         
159         StringBuffer JavaDoc hostHTTP = new StringBuffer JavaDoc("http://");
160         hostHTTP.append(hostName);
161         if (hostPortHTTP != 80) {
162             hostHTTP.append(":");
163             hostHTTP.append(hostPortHTTP);
164         }
165         this.hostNameHTTP = hostHTTP.toString();
166         hostHTTP.append('/');
167         hostHTTP.append(contextRoot);
168         this.contextHTTP = hostHTTP.toString();
169         
170         StringBuffer JavaDoc hostHTTPS = new StringBuffer JavaDoc("https://");
171         hostHTTPS.append(hostName);
172         if (hostPortHTTPS != 443) {
173             hostHTTPS.append(":");
174             hostHTTPS.append(hostPortHTTPS);
175         }
176         this.hostNameHTTPS = hostHTTPS.toString();
177         hostHTTPS.append('/');
178         hostHTTPS.append(contextRoot);
179         this.contextHTTPS = hostHTTPS.toString();
180     }
181     
182     public String JavaDoc getBaseURLexcludeContext(boolean secure) {
183         return (secure?this.hostNameHTTPS : this.hostNameHTTP);
184     }
185
186     public String JavaDoc getBaseURL(boolean secure) {
187         return (secure?this.contextHTTPS : this.contextHTTP);
188     }
189     
190 }
191
Popular Tags