1/*2 * Licensed to the Apache Software Foundation (ASF) under one or more3 * contributor license agreements. See the NOTICE file distributed with4 * this work for additional information regarding copyright ownership.5 * The ASF licenses this file to You under the Apache License, Version 2.06 * (the "License"); you may not use this file except in compliance with7 * the License. You may obtain a copy of the License at8 * 9 * http://www.apache.org/licenses/LICENSE-2.010 * 11 * Unless required by applicable law or agreed to in writing, software12 * distributed under the License is distributed on an "AS IS" BASIS,13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.14 * See the License for the specific language governing permissions and15 * limitations under the License.16 */17packageorg.apache.jetspeed;
1819import java.util.Collection;
20import java.util.Enumeration;
21import java.util.HashMap;
2223import javax.portlet.PortletMode;
24import javax.portlet.WindowState;
2526import org.apache.jetspeed.administration.PortalConfiguration;
27import org.apache.jetspeed.container.PortletRequestContext;
28import org.apache.jetspeed.engine.Engine;
29import org.apache.jetspeed.om.common.portlet.PortletApplication;
30import org.apache.pluto.util.Enumerator;
3132/***33 * Implementation of Portal Context associated with running thread of the engine34 *35 * @author <a href="mailto:david@bluesunrise.com">David Sean Taylor</a>36 * @version $Id: JetspeedPortalContext.java 553375 2007-07-05 05:37:00Z taylor $37 */38publicclassJetspeedPortalContext implements PortalContext
39 {
40privatestaticfinal String SUPPORTED_WINDOWSTATE_ATTR = "supported.windowstate";
41privatestaticfinal String SUPPORTED_PORTLETMODE_ATTR = "supported.portletmode";
42privatestaticfinal String PORTAL_VERSION_ATTR = "portal.version";
43privatestaticfinal String PORTAL_NAME_ATTR = "portal.name";
4445/***46 * The engine associated with this context.47 */48private Engine engine = null;
4950/***51 * Runtime attributes.52 */53private HashMap attributes = new HashMap();
5455/***56 * Configuration state57 */58private PortalConfiguration configuration = null;
5960/***61 * The base from which the Jetspped application will operate.62 */63private String applicationRoot;
6465privatefinal String portalInfo;
6667publicJetspeedPortalContext(Engine engine, PortalConfiguration configuration, String applicationRoot)
68 {
69this.engine = engine;
70this.configuration = configuration;
71this.applicationRoot = applicationRoot;
7273 portalInfo = configuration.getString(PORTAL_NAME_ATTR) + "/" + configuration.getString(PORTAL_VERSION_ATTR);
7475// Inititalize supported portlet modes and window states76 String[] supportedModes = configuration.getStringArray(SUPPORTED_PORTLETMODE_ATTR);
77 String[] supportedStates = configuration.getStringArray(SUPPORTED_WINDOWSTATE_ATTR);
78new JetspeedActions(supportedModes, supportedStates);
79 }
8081// ------------------------------------------------------------------------82// A C C E S S O R S83// ------------------------------------------------------------------------8485/***86 * Returns the configuration properties for this Jetspeed engine context.87 *88 * @return a <code>Configuration</code> containing the configuration properties for this Jetspeed context.89 */90public PortalConfiguration getConfiguration()
91 {
92return configuration;
93 }
9495public String getConfigurationProperty(String key)
96 {
97return configuration.getString(key);
98 }
99100public String getConfigurationProperty(String key, String defaultValue)
101 {
102return configuration.getString(key, defaultValue);
103 }
104105/***106 * Set the configuration properties for this Jetspeed engine context.107 *108 * @param configuration - the configuration properties109 */110publicvoid setConfiguration(PortalConfiguration configuration)
111 {
112this.configuration = configuration;
113 }
114115/***116 * Returns the application root for this Jetspeed engine context.117 *118 * @return a <code>String</code> containing the application root path for this Jetspeed context.119 */120public String getApplicationRoot()
121 {
122return applicationRoot;
123 }
124125/***126 * Sets the application root path for this Jetspeed engine context.127 *128 * @param applicationRoot - the applicationRoot path on the file system.129 */130publicvoid setApplicationRoot(String applicationRoot)
131 {
132this.applicationRoot = applicationRoot;
133 }
134135/***136 * Returns the engine associated with this context.137 *138 * @return an <code>Engine</code> associated with this context139 */140public Engine getEngine()
141 {
142returnthis.engine;
143 }
144145/***146 * Returns the engine attribute with the given name, or null if there is no attribute by that name.147 *148 * @return an <code>Object</code> containing the value of the attribute, or null if no attribute exists matching the given name149 */150public Object getAttribute(String name)
151 {
152return attributes.get(name);
153 }
154155156/***157 * Binds an object to a given attribute name in this servlet context.158 *159 * @param name - a <code>String</code> specifying the name of the attribute160 * @param value - an <code>Object</code> representing the attribute to be bound161 */162publicvoid setAttribute(String name, Object value)
163 {
164 attributes.put(name, value);
165 }
166167/* (non-Javadoc)168 * @see javax.portlet.PortalContext#getProperty(java.lang.String)169 */170public String getProperty(String name)
171 {
172if (name == null)
173 {
174thrownew IllegalArgumentException("Property name == null");
175 }
176return(String) configuration.getString(name);
177 }
178179/* (non-Javadoc)180 * @see javax.portlet.PortalContext#getPropertyNames()181 */182public Enumeration getPropertyNames()
183 {
184returnnew Enumerator(configuration.getKeys());
185 }
186187private Collection getSupportedModes()
188 {
189 PortletRequestContext ctx = PortletRequestContext.getContext();
190if ( ctx != null )
191 {
192 PortletApplication pa = ((PortletApplication)ctx.getPortletDefinition().getPortletApplicationDefinition());
193return pa.getSupportedPortletModes();
194 }
195return JetspeedActions.getStandardPortletModes();
196 }
197198/* (non-Javadoc)199 * @see javax.portlet.PortalContext#getSupportedPortletModes()200 */201public Enumeration getSupportedPortletModes()
202 {
203returnnew Enumerator(getSupportedModes());
204 }
205206publicboolean isPortletModeAllowed(PortletMode mode)
207 {
208return getSupportedModes().contains(mode);
209 }
210211private Collection getSupportedStates()
212 {
213 PortletRequestContext ctx = PortletRequestContext.getContext();
214if ( ctx != null )
215 {
216 PortletApplication pa = ((PortletApplication)ctx.getPortletDefinition().getPortletApplicationDefinition());
217return pa.getSupportedWindowStates();
218 }
219return JetspeedActions.getStandardWindowStates();
220 }
221222/* (non-Javadoc)223 * @see javax.portlet.PortalContext#getSupportedWindowStates()224 */225public Enumeration getSupportedWindowStates()
226 {
227returnnew Enumerator(getSupportedStates());
228 }
229230publicboolean isWindowStateAllowed(WindowState state)
231 {
232return getSupportedStates().contains(state);
233 }
234235/* (non-Javadoc)236 * @see javax.portlet.PortalContext#getPortalInfo()237 */238public String getPortalInfo()
239 {
240return portalInfo;
241 }
242 }