KickJava   Java API By Example, From Geeks To Geeks.

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


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.HashSet JavaDoc;
19 import java.util.Iterator JavaDoc;
20
21 import javax.portlet.PortletMode;
22 import javax.portlet.WindowState;
23
24 import org.apache.avalon.framework.service.ServiceManager;
25 import org.apache.cocoon.portal.coplet.CopletInstanceData;
26 import org.apache.cocoon.portal.pluto.om.PortletEntityImpl;
27 import org.apache.pluto.om.window.PortletWindow;
28 import org.apache.pluto.services.information.DynamicInformationProvider;
29 import org.apache.pluto.services.information.PortletActionProvider;
30 import org.apache.pluto.services.information.PortletURLProvider;
31 import org.apache.pluto.services.information.ResourceURLProvider;
32
33 /**
34  * Our own dynamic information provider
35  *
36  * @author <a HREF="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
37  *
38  * @version CVS $Id: DynamicInformationProviderImpl.java 123903 2005-01-02 21:26:59Z antonio $
39  */

40 public class DynamicInformationProviderImpl
41 implements DynamicInformationProvider {
42
43     /** Service manager */
44     protected final ServiceManager manager;
45     
46     /** The portal context provider */
47     protected final PortalContextProviderImpl provider;
48     
49     /**
50      * Constructor
51      */

52     public DynamicInformationProviderImpl(ServiceManager manager,
53                                           PortalContextProviderImpl provider) {
54         this.manager = manager;
55         this.provider = provider;
56     }
57
58     /* (non-Javadoc)
59      * @see org.apache.pluto.services.information.DynamicInformationProvider#getPortletURLProvider(org.apache.pluto.om.window.PortletWindow)
60      */

61     public PortletURLProvider getPortletURLProvider(PortletWindow portletWindow) {
62         return new PortletURLProviderImpl(portletWindow, this.manager);
63     }
64     
65     /* (non-Javadoc)
66      * @see org.apache.pluto.services.information.DynamicInformationProvider#getResourceURLProvider(org.apache.pluto.om.window.PortletWindow)
67      */

68     public ResourceURLProvider getResourceURLProvider(PortletWindow portletWindow) {
69         return new ResourceURLProviderImpl(this.provider);
70     }
71
72     /* (non-Javadoc)
73      * @see org.apache.pluto.services.information.DynamicInformationProvider#getPortletActionProvider(org.apache.pluto.om.window.PortletWindow)
74      */

75     public PortletActionProvider getPortletActionProvider(PortletWindow portletWindow) {
76         return new PortletActionProviderImpl(portletWindow);
77     }
78
79     /* (non-Javadoc)
80      * @see org.apache.pluto.services.information.DynamicInformationProvider#getPortletMode(org.apache.pluto.om.window.PortletWindow)
81      */

82     public PortletMode getPortletMode(PortletWindow portletWindow) {
83         final CopletInstanceData cid = ((PortletEntityImpl)portletWindow.getPortletEntity()).getCopletInstanceData();
84         PortletMode pm = (PortletMode) cid.getTemporaryAttribute("portlet-mode");
85         if ( pm == null ) {
86             pm = PortletMode.VIEW;
87         }
88         return pm;
89     }
90
91     /* (non-Javadoc)
92      * @see org.apache.pluto.services.information.DynamicInformationProvider#getPreviousPortletMode(org.apache.pluto.om.window.PortletWindow)
93      */

94     public PortletMode getPreviousPortletMode(PortletWindow portletWindow) {
95         final CopletInstanceData cid = ((PortletEntityImpl)portletWindow.getPortletEntity()).getCopletInstanceData();
96         PortletMode pm = (PortletMode) cid.getTemporaryAttribute("previous-portlet-mode");
97         return pm;
98     }
99
100     /* (non-Javadoc)
101      * @see org.apache.pluto.services.information.DynamicInformationProvider#getWindowState(org.apache.pluto.om.window.PortletWindow)
102      */

103     public WindowState getWindowState(PortletWindow portletWindow) {
104         final CopletInstanceData cid = ((PortletEntityImpl)portletWindow.getPortletEntity()).getCopletInstanceData();
105         WindowState ws = (WindowState) cid.getTemporaryAttribute("window-state");
106         if ( ws == null ) {
107             ws = WindowState.NORMAL;
108         }
109         return ws;
110     }
111
112     /* (non-Javadoc)
113      * @see org.apache.pluto.services.information.DynamicInformationProvider#getPreviousWindowState(org.apache.pluto.om.window.PortletWindow)
114      */

115     public WindowState getPreviousWindowState(PortletWindow portletWindow) {
116         final CopletInstanceData cid = ((PortletEntityImpl)portletWindow.getPortletEntity()).getCopletInstanceData();
117         WindowState ws = (WindowState) cid.getTemporaryAttribute("previous-window-state");
118         return ws;
119     }
120
121     /* (non-Javadoc)
122      * @see org.apache.pluto.services.information.DynamicInformationProvider#getResponseContentType()
123      */

124     public String JavaDoc getResponseContentType() {
125         return "text/html";
126     }
127
128     static protected final HashSet JavaDoc responseMimeTypes = new HashSet JavaDoc();
129     
130     static {
131         responseMimeTypes.add("text/html");
132     }
133     
134     /* (non-Javadoc)
135      * @see org.apache.pluto.services.information.DynamicInformationProvider#getResponseContentTypes()
136      */

137     public Iterator JavaDoc getResponseContentTypes() {
138         return responseMimeTypes.iterator();
139     }
140
141     /* (non-Javadoc)
142      * @see org.apache.pluto.services.information.DynamicInformationProvider#isPortletModeAllowed(javax.portlet.PortletMode)
143      */

144     public boolean isPortletModeAllowed(PortletMode mode) {
145         return this.provider.getSupportedPortletModes().contains(mode);
146     }
147
148     /* (non-Javadoc)
149      * @see org.apache.pluto.services.information.DynamicInformationProvider#isWindowStateAllowed(javax.portlet.WindowState)
150      */

151     public boolean isWindowStateAllowed(WindowState state) {
152         return this.provider.getSupportedWindowStates().contains(state);
153     }
154     
155 }
156
Popular Tags