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.jetspeed.container;
018:
019: import java.io.IOException;
020: import java.util.Properties;
021:
022: import javax.portlet.PortletException;
023: import javax.servlet.ServletConfig;
024: import javax.servlet.http.HttpServletRequest;
025: import javax.servlet.http.HttpServletResponse;
026:
027: import org.apache.commons.logging.Log;
028: import org.apache.commons.logging.LogFactory;
029: import org.apache.jetspeed.engine.servlet.ServletRequestFactory;
030: import org.apache.jetspeed.engine.servlet.ServletResponseFactory;
031: import org.apache.pluto.PortletContainer;
032: import org.apache.pluto.PortletContainerException;
033: import org.apache.pluto.om.window.PortletWindow;
034: import org.apache.pluto.services.PortletContainerEnvironment;
035:
036: /**
037: * Portlet Container Wrapper to secure access to portlet container.
038: *
039: * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
040: * @version $Id: JetspeedPortletContainerWrapper.java 516448 2007-03-09 16:25:47Z ate $
041: */
042: public class JetspeedPortletContainerWrapper implements
043: PortletContainerWrapper {
044: private boolean initialized = false;
045: private static final Log log = LogFactory
046: .getLog(JetspeedPortletContainerWrapper.class);
047: private final PortletContainer pluto;
048: private final String containerId;
049: private final Properties properties;
050: private final PortletContainerEnvironment environment;
051: private final ServletConfig servletConfig;
052:
053: private ServletRequestFactory requestFactory;
054: private ServletResponseFactory responseFactory;
055:
056: public JetspeedPortletContainerWrapper(PortletContainer pluto,
057: String containerId, ServletConfig servletConfig,
058: PortletContainerEnvironment env, Properties properties) {
059: this .pluto = pluto;
060: this .containerId = containerId;
061: this .environment = env;
062: this .properties = properties;
063: this .servletConfig = servletConfig;
064: }
065:
066: public JetspeedPortletContainerWrapper(PortletContainer pluto,
067: String containerId, ServletConfig servletConfig,
068: PortletContainerEnvironment env) {
069: this (pluto, containerId, servletConfig, env, new Properties());
070: }
071:
072: /**
073: * Allows starting of the container without providing calling the
074: * <code>init()</code> method without all of the arguments as the
075: * arguments have already been provided in the constructor.
076: *
077: * @throws PortletContainerException
078: */
079: public void start() throws PortletContainerException {
080: log.info("Attmepting to start Pluto portal container...");
081: this .init(containerId, servletConfig, environment, properties);
082: log.info("Pluto portlet container successfully started.");
083: }
084:
085: /**
086: * initialization is still handled outside component architecture, since Pluto is not a component
087: */
088: public synchronized void init(String uniqueContainerId,
089: ServletConfig servletConfig,
090: PortletContainerEnvironment environment, Properties props)
091: throws PortletContainerException {
092:
093: pluto
094: .init(uniqueContainerId, servletConfig, environment,
095: props);
096: initialized = true;
097: }
098:
099: public synchronized void shutdown()
100: throws PortletContainerException {
101: initialized = false;
102: pluto.shutdown();
103: }
104:
105: public void renderPortlet(PortletWindow portletWindow,
106: HttpServletRequest servletRequest,
107: HttpServletResponse servletResponse)
108: throws PortletException, IOException,
109: PortletContainerException {
110:
111: if (portletWindow.getPortletEntity() == null) {
112: log.warn("Could not render PortletWindow "
113: + portletWindow.getId()
114: + " as it has no PortletEntity defined.");
115: return;
116: }
117:
118: if (portletWindow.getPortletEntity().getPortletDefinition() == null) {
119: log.warn("Could not render PortletWindow"
120: + portletWindow.getId()
121: + " as it has no PortletDefintion defined.");
122: return;
123: }
124: pluto.renderPortlet(portletWindow, servletRequest,
125: servletResponse);
126: // TODO: figure out how to access pluto-services before container kicks in
127: // ServletObjectAccess.getServletRequest(servletRequest),
128: // ServletObjectAccess.getServletResponse(servletResponse));
129: }
130:
131: public void processPortletAction(PortletWindow portletWindow,
132: HttpServletRequest servletRequest,
133: HttpServletResponse servletResponse)
134: throws PortletException, IOException,
135: PortletContainerException {
136: pluto.processPortletAction(portletWindow, servletRequest,
137: servletResponse);
138: // ServletObjectAccess.getServletRequest(servletRequest),
139: // ServletObjectAccess.getServletResponse(servletResponse));
140: }
141:
142: public void portletLoad(PortletWindow portletWindow,
143: HttpServletRequest servletRequest,
144: HttpServletResponse servletResponse)
145: throws PortletException, PortletContainerException {
146: pluto.portletLoad(portletWindow, requestFactory
147: .getServletRequest(servletRequest, portletWindow),
148: responseFactory.getServletResponse(servletResponse));
149: }
150:
151: /**
152: * <p>
153: * isInitialized
154: * </p>
155: *
156: * @see org.apache.pluto.PortletContainer#isInitialized()
157: * @return
158: */
159: public boolean isInitialized() {
160: return initialized;
161: }
162:
163: public void setRequestFactory(ServletRequestFactory requestFactory) {
164: this .requestFactory = requestFactory;
165: }
166:
167: public void setResponseFactory(
168: ServletResponseFactory responseFactory) {
169: this.responseFactory = responseFactory;
170: }
171:
172: }
|