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.HashSet;
020: import java.util.Iterator;
021:
022: import javax.portlet.PortletMode;
023: import javax.portlet.WindowState;
024:
025: import org.apache.avalon.framework.service.ServiceManager;
026: import org.apache.cocoon.portal.coplet.CopletInstanceData;
027: import org.apache.cocoon.portal.pluto.om.PortletEntityImpl;
028: import org.apache.pluto.om.window.PortletWindow;
029: import org.apache.pluto.services.information.DynamicInformationProvider;
030: import org.apache.pluto.services.information.PortletActionProvider;
031: import org.apache.pluto.services.information.PortletURLProvider;
032: import org.apache.pluto.services.information.ResourceURLProvider;
033:
034: /**
035: * Our own dynamic information provider
036: *
037: * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
038: *
039: * @version CVS $Id: DynamicInformationProviderImpl.java 433543 2006-08-22 06:22:54Z crossley $
040: */
041: public class DynamicInformationProviderImpl implements
042: DynamicInformationProvider {
043:
044: /** Service manager */
045: protected final ServiceManager manager;
046:
047: /** The portal context provider */
048: protected final PortalContextProviderImpl provider;
049:
050: /**
051: * Constructor
052: */
053: public DynamicInformationProviderImpl(ServiceManager manager,
054: PortalContextProviderImpl provider) {
055: this .manager = manager;
056: this .provider = provider;
057: }
058:
059: /* (non-Javadoc)
060: * @see org.apache.pluto.services.information.DynamicInformationProvider#getPortletURLProvider(org.apache.pluto.om.window.PortletWindow)
061: */
062: public PortletURLProvider getPortletURLProvider(
063: PortletWindow portletWindow) {
064: return new PortletURLProviderImpl(portletWindow, this .manager);
065: }
066:
067: /* (non-Javadoc)
068: * @see org.apache.pluto.services.information.DynamicInformationProvider#getResourceURLProvider(org.apache.pluto.om.window.PortletWindow)
069: */
070: public ResourceURLProvider getResourceURLProvider(
071: PortletWindow portletWindow) {
072: return new ResourceURLProviderImpl(this .provider);
073: }
074:
075: /**
076: * @see org.apache.pluto.services.information.DynamicInformationProvider#getPortletActionProvider(org.apache.pluto.om.window.PortletWindow)
077: */
078: public PortletActionProvider getPortletActionProvider(
079: PortletWindow portletWindow) {
080: return new PortletActionProviderImpl(portletWindow);
081: }
082:
083: /**
084: * @see org.apache.pluto.services.information.DynamicInformationProvider#getPortletMode(org.apache.pluto.om.window.PortletWindow)
085: */
086: public PortletMode getPortletMode(PortletWindow portletWindow) {
087: final CopletInstanceData cid = ((PortletEntityImpl) portletWindow
088: .getPortletEntity()).getCopletInstanceData();
089: final String pmString = (String) cid
090: .getTemporaryAttribute("portlet-mode");
091: if (pmString == null) {
092: return PortletMode.VIEW;
093: }
094: return new PortletMode(pmString);
095: }
096:
097: /**
098: * @see org.apache.pluto.services.information.DynamicInformationProvider#getWindowState(org.apache.pluto.om.window.PortletWindow)
099: */
100: public WindowState getWindowState(PortletWindow portletWindow) {
101: final CopletInstanceData cid = ((PortletEntityImpl) portletWindow
102: .getPortletEntity()).getCopletInstanceData();
103: final String wsString = (String) cid
104: .getTemporaryAttribute("window-state");
105: if (wsString != null) {
106: return new WindowState(wsString);
107: }
108: return WindowState.NORMAL;
109: }
110:
111: /**
112: * @see org.apache.pluto.services.information.DynamicInformationProvider#getResponseContentType()
113: */
114: public String getResponseContentType() {
115: return "text/html";
116: }
117:
118: static protected final HashSet responseMimeTypes = new HashSet();
119:
120: static {
121: responseMimeTypes.add("text/html");
122: }
123:
124: /* (non-Javadoc)
125: * @see org.apache.pluto.services.information.DynamicInformationProvider#getResponseContentTypes()
126: */
127: public Iterator getResponseContentTypes() {
128: return responseMimeTypes.iterator();
129: }
130:
131: /* (non-Javadoc)
132: * @see org.apache.pluto.services.information.DynamicInformationProvider#isPortletModeAllowed(javax.portlet.PortletMode)
133: */
134: public boolean isPortletModeAllowed(PortletMode mode) {
135: return this .provider.getSupportedPortletModes().contains(mode);
136: }
137:
138: /* (non-Javadoc)
139: * @see org.apache.pluto.services.information.DynamicInformationProvider#isWindowStateAllowed(javax.portlet.WindowState)
140: */
141: public boolean isWindowStateAllowed(WindowState state) {
142: return this.provider.getSupportedWindowStates().contains(state);
143: }
144:
145: }
|