KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > portal > wsrp > consumer > ConsumerEnvironmentImpl


1 /*
2  * Copyright 2005 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.wsrp.consumer;
17
18 import oasis.names.tc.wsrp.v1.types.StateChange;
19
20 import org.apache.avalon.framework.parameters.Parameters;
21 import org.apache.cocoon.portal.PortalService;
22 import org.apache.cocoon.portal.coplet.CopletInstanceData;
23 import org.apache.cocoon.portal.wsrp.adapter.WSRPAdapter;
24 import org.apache.wsrp4j.consumer.PortletDriverRegistry;
25 import org.apache.wsrp4j.consumer.PortletRegistry;
26 import org.apache.wsrp4j.consumer.ProducerRegistry;
27 import org.apache.wsrp4j.consumer.SessionHandler;
28 import org.apache.wsrp4j.consumer.URLGenerator;
29 import org.apache.wsrp4j.consumer.URLRewriter;
30 import org.apache.wsrp4j.consumer.URLTemplateComposer;
31 import org.apache.wsrp4j.consumer.User;
32 import org.apache.wsrp4j.consumer.UserRegistry;
33 import org.apache.wsrp4j.consumer.driver.GenericConsumerEnvironment;
34 import org.apache.wsrp4j.consumer.util.ConsumerConstants;
35 import org.apache.wsrp4j.util.Constants;
36 import org.apache.wsrp4j.util.Modes;
37 import org.apache.wsrp4j.util.WindowStates;
38
39 /**
40  * Implements the consumer environment interface. <br/>
41  *
42  * @author <a HREF="mailto:cziegeler@s-und-n.de">Carsten Ziegeler</a>
43  * @author <a HREF="mailto:malessandrini@s-und-n.de">Michel Alessandrini</a>
44  *
45  * @version $Id: ConsumerEnvironmentImpl.java 264755 2005-08-30 10:29:21Z cziegeler $
46  **/

47 public class ConsumerEnvironmentImpl
48     extends GenericConsumerEnvironment {
49
50     /** The generator used to rewrite the urls. */
51     protected URLGenerator urlGenerator;
52
53     /** The wsrp adapter. */
54     protected WSRPAdapter adapter;
55
56     /**
57      * Initialize the consumer
58      *
59      * @param service
60      * @param adapter
61      * @throws Exception
62      */

63     public void init(PortalService service,
64                      WSRPAdapter adapter)
65     throws Exception JavaDoc {
66         this.adapter = adapter;
67         Parameters params = adapter.getAdapterConfiguration();
68         this.setConsumerAgent("not set");
69
70         // To define the locales per end-user
71
// the configuration must be set within UserContextProviderImpl
72
// the following lines define the global locales
73
String JavaDoc[] supportedLocales = new String JavaDoc[1];
74         supportedLocales[0] = Constants.LOCALE_EN_US;
75         this.setSupportedLocales(supportedLocales);
76
77         // define the modes the consumer supports
78
String JavaDoc[] supportedModes = new String JavaDoc[3];
79         supportedModes[0] = Modes._view;
80         supportedModes[1] = Modes._help;
81         supportedModes[2] = Modes._edit;
82         this.setSupportedModes(supportedModes);
83
84         // define the window states the consumer supports
85
String JavaDoc[] supportedWindowStates = new String JavaDoc[3];
86         supportedWindowStates[0] = WindowStates._normal;
87         supportedWindowStates[1] = WindowStates._maximized;
88         supportedWindowStates[2] = WindowStates._minimized;
89         this.setSupportedWindowStates(supportedWindowStates);
90
91         // define portlet state change behaviour
92
this.setPortletStateChange(StateChange.readWrite);
93
94         // define the mime types the consumer supports
95
this.setMimeTypes(new String JavaDoc[] { Constants.MIME_TYPE_HTML });
96
97         // define the character sets the consumer supports
98
this.setCharacterEncodingSet(new String JavaDoc[] { Constants.UTF_8 });
99
100         // set the authentication method the consumer uses
101
this.setUserAuthentication(ConsumerConstants.NONE);
102
103         // THE ORDER IN WHICH THE FOLLOWING OBJECTS ARE INSTANCIATED IS IMPORTANT
104
this.setUserRegistry((UserRegistry)adapter.createObject(params.getParameter("user-registry-class", UserRegistryImpl.class.getName())));
105         this.setSessionHandler((SessionHandler)adapter.createObject(params.getParameter("session-handler-class", SessionHandlerImpl.class.getName())));
106         this.setProducerRegistry((ProducerRegistry)adapter.createObject(params.getParameter("producer-registry-class", ProducerRegistryImpl.class.getName())));
107         this.setPortletRegistry((PortletRegistry)adapter.createObject(params.getParameter("portlet-registry-class", PortletRegistryImpl.class.getName())));
108
109         this.setTemplateComposer((URLTemplateComposer)adapter.createObject(params.getParameter("url-template-composer-class", URLTemplateComposerImpl.class.getName())));
110         this.setURLRewriter((URLRewriter)adapter.createObject(params.getParameter("url-rewriter-class", URLRewriterImpl.class.getName())));
111
112         this.setPortletDriverRegistry((PortletDriverRegistry)adapter.createObject(params.getParameter("portlet-driver-registry-class", PortletDriverRegistryImpl.class.getName())));
113
114         this.urlGenerator = (URLGenerator)adapter.createObject(params.getParameter("url-generator-class", URLGeneratorImpl.class.getName()));
115         this.getTemplateComposer().setURLGenerator(this.urlGenerator);
116         this.getURLRewriter().setURLGenerator(this.urlGenerator);
117     }
118
119     /**
120      * @return URLGenerator the used url generator.
121      */

122     public URLGenerator getURLGenerator() {
123         return this.urlGenerator;
124     }
125     
126     /**
127      * @see org.apache.wsrp4j.consumer.driver.GenericConsumerEnvironment#getSupportedLocales()
128      */

129     public String JavaDoc[] getSupportedLocales() {
130         CopletInstanceData coplet = this.adapter.getCurrentCopletInstanceData();
131         User user = (User)coplet.getTemporaryAttribute(WSRPAdapter.ATTRIBUTE_NAME_USER);
132         
133         return ((UserContextExtension)user.getUserContext()).getSupportedLocales();
134     }
135
136     /**
137      * @see org.apache.wsrp4j.consumer.ConsumerCapabilities#getUserAuthentication()
138      */

139     public String JavaDoc getUserAuthentication() {
140         CopletInstanceData coplet = this.adapter.getCurrentCopletInstanceData();
141         User user = (User)coplet.getTemporaryAttribute(WSRPAdapter.ATTRIBUTE_NAME_USER);
142         
143         return ((UserContextExtension)user.getUserContext()).getUserAuthentication();
144     }
145 }
146
Popular Tags