001: /******************************************************************************
002: * JBoss, a division of Red Hat *
003: * Copyright 2006, Red Hat Middleware, LLC, and individual *
004: * contributors as indicated by the @authors tag. See the *
005: * copyright.txt in the distribution for a full listing of *
006: * individual contributors. *
007: * *
008: * This is free software; you can redistribute it and/or modify it *
009: * under the terms of the GNU Lesser General Public License as *
010: * published by the Free Software Foundation; either version 2.1 of *
011: * the License, or (at your option) any later version. *
012: * *
013: * This software is distributed in the hope that it will be useful, *
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of *
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
016: * Lesser General Public License for more details. *
017: * *
018: * You should have received a copy of the GNU Lesser General Public *
019: * License along with this software; if not, write to the Free *
020: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
021: * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
022: ******************************************************************************/package org.jboss.portal.core.controller.portlet;
023:
024: import org.jboss.portal.Mode;
025: import org.jboss.portal.WindowState;
026: import org.jboss.portal.common.util.CollectionBuilder;
027: import org.jboss.portal.core.controller.ControllerContext;
028: import org.jboss.portal.core.model.portal.Portal;
029: import org.jboss.portal.core.model.portal.Window;
030: import org.jboss.portal.portlet.impl.spi.AbstractRequestContext;
031: import org.jboss.portal.portlet.impl.spi.AbstractSecurityContext;
032: import org.jboss.portal.portlet.spi.PortalContext;
033: import org.jboss.portal.portlet.spi.RequestContext;
034: import org.jboss.portal.portlet.spi.SecurityContext;
035: import org.jboss.portal.portlet.spi.UserContext;
036: import org.jboss.portal.portlet.spi.WindowContext;
037: import org.jboss.portal.server.PortalConstants;
038:
039: import java.util.Collections;
040: import java.util.Map;
041: import java.util.Set;
042:
043: /**
044: * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
045: * @version $Revision: 8883 $
046: */
047: public class PortletContextFactory {
048:
049: /** . */
050: private PortalContext portalContext;
051:
052: /** . */
053: private RequestContext requestContext;
054:
055: /** . */
056: private SecurityContext securityContext;
057:
058: /** . */
059: private UserContext userContext;
060:
061: /** . */
062: private WindowContext windowContext;
063:
064: public PortletContextFactory(ControllerContext controllerContext,
065: Portal portal, Window window) {
066: this .requestContext = new AbstractRequestContext(
067: controllerContext.getServerInvocation()
068: .getServerContext().getClientRequest(),
069: controllerContext.getServerInvocation()
070: .getServerContext().getClientResponse());
071: this .securityContext = new AbstractSecurityContext(
072: controllerContext.getServerInvocation()
073: .getServerContext().getClientRequest());
074: this .userContext = new ControllerUserContext(controllerContext);
075: this .portalContext = new org.jboss.portal.core.model.portal.portlet.PortalContextImpl(
076: portal);
077: this .windowContext = new org.jboss.portal.core.model.portal.portlet.WindowContextImpl(
078: window);
079: }
080:
081: public PortletContextFactory(ControllerContext controllerContext) {
082: this .requestContext = new AbstractRequestContext(
083: controllerContext.getServerInvocation()
084: .getServerContext().getClientRequest(),
085: controllerContext.getServerInvocation()
086: .getServerContext().getClientResponse());
087: this .securityContext = new AbstractSecurityContext(
088: controllerContext.getServerInvocation()
089: .getServerContext().getClientRequest());
090: this .userContext = new ControllerUserContext(controllerContext);
091: this .portalContext = portalContextImpl;
092: this .windowContext = new WindowContextImpl("abc"); // Well ????
093: }
094:
095: public PortalContext createPortalContext() {
096: return portalContext;
097: }
098:
099: public RequestContext createRequestContext() {
100: return requestContext;
101: }
102:
103: public SecurityContext createSecurityContext() {
104: return securityContext;
105: }
106:
107: public UserContext createUserContext() {
108: return userContext;
109: }
110:
111: public WindowContext createWindowContext() {
112: return windowContext;
113: }
114:
115: /** . */
116: private static final PortalContextImpl portalContextImpl = new PortalContextImpl();
117:
118: private static class PortalContextImpl implements PortalContext {
119:
120: /** . */
121: private final Set windowStates;
122:
123: /** . */
124: private final Set modes;
125:
126: /** . */
127: private final Map props;
128:
129: public PortalContextImpl() {
130: windowStates = Collections
131: .unmodifiableSet((Set) CollectionBuilder.hashSet()
132: .add(WindowState.MAXIMIZED).add(
133: WindowState.MINIMIZED).add(
134: WindowState.NORMAL).get());
135: modes = Collections.unmodifiableSet((Set) CollectionBuilder
136: .hashSet().add(Mode.EDIT).add(Mode.HELP).add(
137: Mode.VIEW).get());
138: props = Collections.EMPTY_MAP;
139: }
140:
141: public String getInfo() {
142: return PortalConstants.VERSION.toString();
143: }
144:
145: public Set getWindowStates() {
146: return windowStates;
147: }
148:
149: public Set getModes() {
150: return modes;
151: }
152:
153: public Map getProperties() {
154: return props;
155: }
156: }
157:
158: private static class WindowContextImpl implements WindowContext {
159:
160: /** . */
161: private String id;
162:
163: public WindowContextImpl(String id) {
164: this .id = id;
165: }
166:
167: public String getId() {
168: return id;
169: }
170: }
171: }
|