KickJava   Java API By Example, From Geeks To Geeks.

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


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.intf.WSRP_v1_Markup_PortType;
19 import oasis.names.tc.wsrp.v1.intf.WSRP_v1_PortletManagement_PortType;
20 import oasis.names.tc.wsrp.v1.types.BlockingInteractionResponse;
21 import oasis.names.tc.wsrp.v1.types.ClientData;
22 import oasis.names.tc.wsrp.v1.types.CookieProtocol;
23 import oasis.names.tc.wsrp.v1.types.DestroyPortletsResponse;
24 import oasis.names.tc.wsrp.v1.types.Extension;
25 import oasis.names.tc.wsrp.v1.types.InteractionParams;
26 import oasis.names.tc.wsrp.v1.types.InvalidCookieFault;
27 import oasis.names.tc.wsrp.v1.types.MarkupContext;
28 import oasis.names.tc.wsrp.v1.types.MarkupParams;
29 import oasis.names.tc.wsrp.v1.types.MarkupResponse;
30 import oasis.names.tc.wsrp.v1.types.MarkupType;
31 import oasis.names.tc.wsrp.v1.types.PortletContext;
32 import oasis.names.tc.wsrp.v1.types.PortletDescription;
33 import oasis.names.tc.wsrp.v1.types.PortletDescriptionResponse;
34 import oasis.names.tc.wsrp.v1.types.PortletPropertyDescriptionResponse;
35 import oasis.names.tc.wsrp.v1.types.PropertyList;
36 import oasis.names.tc.wsrp.v1.types.RegistrationContext;
37 import oasis.names.tc.wsrp.v1.types.ReturnAny;
38 import oasis.names.tc.wsrp.v1.types.RuntimeContext;
39 import oasis.names.tc.wsrp.v1.types.ServiceDescription;
40 import oasis.names.tc.wsrp.v1.types.StateChange;
41 import oasis.names.tc.wsrp.v1.types.Templates;
42 import oasis.names.tc.wsrp.v1.types.UserContext;
43 import oasis.names.tc.wsrp.v1.types.ClonePortlet;
44 import oasis.names.tc.wsrp.v1.types.DestroyPortlets;
45 import oasis.names.tc.wsrp.v1.types.GetMarkup;
46 import oasis.names.tc.wsrp.v1.types.GetPortletDescription;
47 import oasis.names.tc.wsrp.v1.types.GetPortletProperties;
48 import oasis.names.tc.wsrp.v1.types.GetPortletPropertyDescription;
49 import oasis.names.tc.wsrp.v1.types.InitCookie;
50 import oasis.names.tc.wsrp.v1.types.PerformBlockingInteraction;
51 import oasis.names.tc.wsrp.v1.types.ReleaseSessions;
52 import oasis.names.tc.wsrp.v1.types.SetPortletProperties;
53
54 import org.apache.avalon.framework.logger.AbstractLogEnabled;
55 import org.apache.cocoon.portal.PortalService;
56 import org.apache.cocoon.portal.wsrp.logging.WSRPLogger;
57 import org.apache.commons.lang.ArrayUtils;
58 import org.apache.wsrp4j.consumer.ConsumerEnvironment;
59 import org.apache.wsrp4j.consumer.GroupSessionMgr;
60 import org.apache.wsrp4j.consumer.InteractionRequest;
61 import org.apache.wsrp4j.consumer.MarkupRequest;
62 import org.apache.wsrp4j.consumer.PortletDriver;
63 import org.apache.wsrp4j.consumer.Producer;
64 import org.apache.wsrp4j.consumer.URLRewriter;
65 import org.apache.wsrp4j.consumer.URLTemplateComposer;
66 import org.apache.wsrp4j.consumer.User;
67 import org.apache.wsrp4j.consumer.UserSessionMgr;
68 import org.apache.wsrp4j.consumer.WSRPBaseRequest;
69 import org.apache.wsrp4j.consumer.WSRPPortlet;
70 import org.apache.wsrp4j.exception.WSRPException;
71 import org.apache.wsrp4j.exception.WSRPXHelper;
72 import org.apache.wsrp4j.log.Logger;
73 import org.apache.wsrp4j.util.Constants;
74 import org.apache.wsrp4j.util.ParameterChecker;
75
76 /**
77  * This class implements a portlet driver.
78  * @version $Id: PortletDriverImpl.java 264755 2005-08-30 10:29:21Z cziegeler $
79  **/

80 public class PortletDriverImpl
81     extends AbstractLogEnabled
82     implements PortletDriver, RequiresConsumerEnvironment, RequiresPortalService {
83
84     protected WSRPPortlet portlet;
85     protected WSRP_v1_Markup_PortType markupPort;
86     protected WSRP_v1_PortletManagement_PortType portletPort;
87     protected ConsumerEnvironment consumerEnv;
88     protected Producer producer;
89     protected ParameterChecker parameterChecker;
90     protected CookieProtocol initCookie = CookieProtocol.none;
91     protected PortletDescription desc;
92
93     /** Our logger. */
94     protected Logger logger;
95
96     /** The portal service. */
97     protected PortalService service;
98
99     /**
100      * @see org.apache.avalon.framework.logger.LogEnabled#enableLogging(org.apache.avalon.framework.logger.Logger)
101      */

102     public void enableLogging(org.apache.avalon.framework.logger.Logger arg0) {
103         super.enableLogging(arg0);
104         this.logger = new WSRPLogger(arg0);
105     }
106
107     /**
108      * @see org.apache.cocoon.portal.wsrp.consumer.RequiresConsumerEnvironment#setConsumerEnvironment(org.apache.wsrp4j.consumer.ConsumerEnvironment)
109      */

110     public void setConsumerEnvironment(ConsumerEnvironment env) {
111         this.consumerEnv = env;
112     }
113
114     /**
115      * @see org.apache.cocoon.portal.wsrp.consumer.RequiresPortalService#setPortalService(org.apache.cocoon.portal.PortalService)
116      */

117     public void setPortalService(PortalService service) {
118        this.service = service;
119     }
120
121     /**
122      * Set the wsrp portlet and initialize this component.
123      * @param portlet
124      * @throws WSRPException
125      */

126     public void init(WSRPPortlet portlet)
127     throws WSRPException {
128         this.parameterChecker = new ParameterChecker();
129
130         this.portlet = portlet;
131         this.producer = consumerEnv.getProducerRegistry().getProducer(portlet.getPortletKey().getProducerId());
132         
133         this.portletPort = this.producer.getPortletManagementInterface();
134         this.desc = this.producer.getPortletDescription(this.portlet.getPortletKey().getPortletHandle());
135
136         ServiceDescription serviceDescription = this.producer.getServiceDescription(false);
137         if (serviceDescription != null) {
138             this.initCookie = serviceDescription.getRequiresInitCookie();
139             if (initCookie == null) {
140                 initCookie = CookieProtocol.none; // TODO - get from config
141
}
142         }
143     }
144
145     /**
146      * Get the portlet this driver is bind to.
147      *
148      * @return The enity
149      **/

150     public WSRPPortlet getPortlet() {
151         return this.portlet;
152     }
153
154     protected void resetInitCookie(String JavaDoc userID) throws WSRPException {
155
156         UserSessionMgr userSession =
157             this.consumerEnv.getSessionHandler().getUserSession(
158                 getPortlet().getPortletKey().getProducerId(),
159                 userID);
160
161         if (initCookie.getValue().equalsIgnoreCase(CookieProtocol._none)) {
162
163             userSession.setInitCookieDone(false);
164
165         } else if (initCookie.getValue().equalsIgnoreCase(CookieProtocol._perGroup)) {
166
167             PortletDescription portletDescription = null;
168             try {
169
170                 portletDescription = producer.getPortletDescription(getPortlet().getParent());
171
172             } catch (WSRPException e) {
173
174                 // do nothing since exception has been logged already
175

176             }
177
178             String JavaDoc groupID = null;
179             if (portletDescription != null) {
180                 groupID = portletDescription.getGroupID();
181             }
182
183             if (groupID != null) {
184                 GroupSessionMgr groupSession = userSession.getGroupSession(groupID);
185                 groupSession.setInitCookieDone(false);
186             }
187         }
188     }
189
190     protected void checkInitCookie(String JavaDoc userID) throws WSRPException {
191         UserSessionMgr userSession =
192             this.consumerEnv.getSessionHandler().getUserSession(
193                 getPortlet().getPortletKey().getProducerId(),
194                 userID);
195
196         if (initCookie.getValue().equalsIgnoreCase(CookieProtocol._perUser)) {
197
198             this.markupPort = userSession.getWSRPBaseService();
199
200             if (!userSession.isInitCookieDone()) {
201
202                 userSession.setInitCookieRequired(true);
203                 initCookie();
204                 userSession.setInitCookieDone(true);
205             }
206
207         } else if (initCookie.getValue().equalsIgnoreCase(CookieProtocol._perGroup)) {
208
209             PortletDescription portletDescription = producer.getPortletDescription(getPortlet().getParent());
210             String JavaDoc groupID = null;
211             if (portletDescription != null) {
212                 groupID = portletDescription.getGroupID();
213             }
214
215             if (groupID != null) {
216                 GroupSessionMgr groupSession = userSession.getGroupSession(groupID);
217
218                 this.markupPort = groupSession.getWSRPBaseService();
219
220                 if (!groupSession.isInitCookieDone()) {
221                     groupSession.setInitCookieRequired(true);
222                     initCookie();
223                     groupSession.setInitCookieDone(true);
224                 }
225
226             } else {
227                 // means either we have no service description from the producer containg the portlet
228
// or the producer specified initCookieRequired perGroup but didn't provide
229
// a groupID in the portlet description
230
}
231         } else {
232             this.markupPort = userSession.getWSRPBaseService();
233         }
234         
235     }
236
237     protected MarkupParams getMarkupParams(WSRPBaseRequest request) {
238
239         MarkupParams markupParams = new MarkupParams();
240         ClientData clientData = null;
241
242         // lets just set this to the consumer agent for now
243
if (producer.getRegistrationData() != null) {
244             clientData = new ClientData();
245             clientData.setUserAgent(producer.getRegistrationData().getConsumerAgent());
246         }
247         markupParams.setClientData(clientData);
248         markupParams.setSecureClientCommunication(this.service.getComponentManager().getLinkService().isSecure());
249         markupParams.setLocales(consumerEnv.getSupportedLocales());
250
251         markupParams.setMimeTypes(consumerEnv.getMimeTypes());
252
253         markupParams.setMode(request.getMode());
254         markupParams.setWindowState(request.getWindowState());
255         markupParams.setNavigationalState(request.getNavigationalState());
256         markupParams.setMarkupCharacterSets(consumerEnv.getCharacterEncodingSet());
257         markupParams.setValidateTag(null); // TODO ValidateTag
258

259         // TODO we could cache the modes and window states
260
final MarkupType markupType = this.desc.getMarkupTypes(0);
261         markupParams.setValidNewModes(this.getValidValues(consumerEnv.getSupportedModes(), markupType.getModes()));
262         markupParams.setValidNewWindowStates(this.getValidValues(consumerEnv.getSupportedWindowStates(), markupType.getWindowStates()));
263
264         markupParams.setExtensions(this.getMarkupParamsExtensions());
265
266         return markupParams;
267     }
268
269     /**
270      * Calculate the valid values for modes and window states.
271      * @param supported The values supported by the consumer.
272      * @param allowed The values allowed by the producer.
273      * @return The valid values.
274      */

275     protected String JavaDoc[] getValidValues(String JavaDoc[] supported, String JavaDoc[] allowed) {
276         String JavaDoc[] validModes = new String JavaDoc[0];
277         for(int i=0; i < supported.length; i++ ) {
278             if ( ArrayUtils.contains(allowed, supported[i]) ) {
279                 String JavaDoc[] newValidModes = new String JavaDoc[validModes.length+1];
280                 System.arraycopy(validModes, 0, newValidModes, 0, validModes.length);
281                 newValidModes[validModes.length] = supported[i];
282                 validModes = newValidModes;
283             }
284         }
285         return validModes;
286     }
287
288     /**
289      * Create the runtime context for the current request.
290      */

291     protected RuntimeContext getRuntimeContext(WSRPBaseRequest request) {
292         RuntimeContext runtimeContext = new RuntimeContext();
293         runtimeContext.setUserAuthentication(consumerEnv.getUserAuthentication());
294         runtimeContext.setPortletInstanceKey(request.getPortletInstanceKey());
295
296         URLTemplateComposer templateComposer = consumerEnv.getTemplateComposer();
297         if (templateComposer != null) {
298             runtimeContext.setNamespacePrefix(templateComposer.getNamespacePrefix());
299         }
300
301         Boolean JavaDoc doesUrlTemplateProcess = null;
302         try {
303
304             PortletDescription desc = producer.getPortletDescription(getPortlet().getParent());
305
306             if (desc != null) {
307
308                 doesUrlTemplateProcess = desc.getDoesUrlTemplateProcessing();
309             }
310
311         } catch (WSRPException e) {
312
313             // do nothing since exception has been logged already
314
// continue with assumption that portlet does not support template processing
315
}
316
317         if (doesUrlTemplateProcess != null && templateComposer != null && doesUrlTemplateProcess.booleanValue()) {
318             Templates templates = new Templates();
319             templates.setBlockingActionTemplate(templateComposer.createBlockingActionTemplate(true, true, true, true));
320             templates.setRenderTemplate(templateComposer.createRenderTemplate(true, true, true, true));
321             templates.setDefaultTemplate(templateComposer.createDefaultTemplate(true, true, true, true));
322             templates.setResourceTemplate(templateComposer.createResourceTemplate(true, true, true, true));
323             templates.setSecureBlockingActionTemplate(
324                 templateComposer.createSecureBlockingActionTemplate(true, true, true, true));
325             templates.setSecureRenderTemplate(templateComposer.createSecureRenderTemplate(true, true, true, true));
326             templates.setSecureDefaultTemplate(templateComposer.createSecureDefaultTemplate(true, true, true, true));
327             templates.setSecureResourceTemplate(templateComposer.createSecureResourceTemplate(true, true, true, true));
328             runtimeContext.setTemplates(templates);
329         }
330
331         runtimeContext.setSessionID(request.getSessionID());
332         runtimeContext.setExtensions(null);
333
334         return runtimeContext;
335     }
336
337     protected UserContext getUserContext(String JavaDoc userID) {
338         UserContext userContext = null;
339
340         if (userID != null) {
341             User user = consumerEnv.getUserRegistry().getUser(userID);
342
343             if (user != null) {
344                 userContext = user.getUserContext();
345             }
346         }
347         
348         // workaround for Oracle bug, always send a userContext with dummy value
349
// if none was provided
350

351         if (userContext == null) {
352             userContext = new UserContext();
353             userContext.setUserContextKey("dummyUserContextKey");
354         }
355
356         return userContext;
357     }
358
359     protected InteractionParams getInteractionParams(InteractionRequest actionRequest) {
360         InteractionParams interactionParams = new InteractionParams();
361
362         interactionParams.setPortletStateChange(consumerEnv.getPortletStateChange());
363         
364         // access POPs with cloneBeforeWrite
365
// however keep the default behaviour from ConsEnv
366
// this means that if readWrite is set and we access a POP then set to cloneBeforeWrite
367
if (!portlet.isConsumerConfigured() &&
368              interactionParams.getPortletStateChange().toString().equalsIgnoreCase(StateChange._readWrite)) {
369                 interactionParams.setPortletStateChange(StateChange.cloneBeforeWrite);
370         }
371         
372         interactionParams.setInteractionState(actionRequest.getInteractionState());
373         interactionParams.setFormParameters(actionRequest.getFormParameters());
374         interactionParams.setUploadContexts(null);
375         interactionParams.setExtensions(null);
376
377         return interactionParams;
378     }
379
380     /**
381       * This method is used to retrieve the markup generated by the portlet instance.
382       *
383       * @param markupRequest
384       * @param userID
385       * @return The markup response generated by the portlet
386       **/

387     public MarkupResponse getMarkup(MarkupRequest markupRequest,
388                                     String JavaDoc userID)
389     throws WSRPException {
390         checkInitCookie(userID);
391
392         MarkupResponse response = null;
393
394         try {
395
396             MarkupContext markupContext = null;
397             if ((markupContext = markupRequest.getCachedMarkup()) == null) {
398
399                 // getMarkup request
400
GetMarkup request = new GetMarkup();
401
402                 request.setPortletContext(getPortlet().getPortletContext());
403                 request.setMarkupParams(getMarkupParams(markupRequest));
404                 request.setRuntimeContext(getRuntimeContext(markupRequest));
405
406                 RegistrationContext regCtx = producer.getRegistrationContext();
407                 if (regCtx != null)
408                     request.setRegistrationContext(regCtx);
409
410                 UserContext userCtx = getUserContext(userID);
411                 if (userCtx != null) {
412                     request.setUserContext(getUserContext(userID));
413                 }
414
415                 response = markupPort.getMarkup(request);
416
417                 parameterChecker.check(response);
418
419             } else {
420
421                 response = new MarkupResponse();
422                 response.setMarkupContext(markupContext);
423             }
424             
425             Boolean JavaDoc requiresRewriting = response.getMarkupContext().getRequiresUrlRewriting();
426             requiresRewriting = requiresRewriting == null ? Boolean.FALSE : requiresRewriting;
427
428             if (requiresRewriting.booleanValue()) {
429                 // rewrite url's
430

431                 URLRewriter urlRewriter = consumerEnv.getURLRewriter();
432                 String JavaDoc rewrittenMarkup = urlRewriter.rewriteURLs(response.getMarkupContext().getMarkupString());
433
434                 if (rewrittenMarkup != null) {
435                     response.getMarkupContext().setMarkupString(rewrittenMarkup);
436                 }
437             }
438
439         } catch (InvalidCookieFault cookieFault) {
440
441             // lets reset the init cookie settings
442
resetInitCookie(userID);
443
444             // and try it again
445
response = getMarkup(markupRequest, userID);
446
447         } catch (java.rmi.RemoteException JavaDoc wsrpFault) {
448
449             WSRPXHelper.handleWSRPFault(logger, wsrpFault);
450
451         }
452
453         return response;
454     }
455
456     /**
457      * This method is used to perform a blocking interaction on the portlet instance.
458      *
459      * @param actionRequest
460      **/

461     public BlockingInteractionResponse performBlockingInteraction(InteractionRequest actionRequest,
462                                                                   String JavaDoc userID)
463     throws WSRPException {
464
465         checkInitCookie(userID);
466
467         BlockingInteractionResponse response = null;
468
469         try {
470             PerformBlockingInteraction request = new PerformBlockingInteraction();
471
472             request.setPortletContext(getPortlet().getPortletContext());
473             request.setInteractionParams(getInteractionParams(actionRequest));
474             request.setMarkupParams(getMarkupParams(actionRequest));
475             request.setRuntimeContext(getRuntimeContext(actionRequest));
476
477             RegistrationContext regCtx = producer.getRegistrationContext();
478             if (regCtx != null)
479                 request.setRegistrationContext(regCtx);
480
481             UserContext userCtx = getUserContext(userID);
482             if (userCtx != null)
483                 request.setUserContext(userCtx);
484
485             response = markupPort.performBlockingInteraction(request);
486
487             parameterChecker.check(response);
488
489         } catch (InvalidCookieFault cookieFault) {
490
491             // lets reset the init cookie settings
492
resetInitCookie(userID);
493
494             // and try it again
495
response = performBlockingInteraction(actionRequest, userID);
496
497         } catch (java.rmi.RemoteException JavaDoc wsrpFault) {
498
499             WSRPXHelper.handleWSRPFault(logger, wsrpFault);
500         }
501
502         return response;
503     }
504
505     /**
506      * Clone the portlet
507      *
508      * @return The new portlet context
509      **/

510     public PortletContext clonePortlet(String JavaDoc userID) throws WSRPException {
511         ClonePortlet request = new ClonePortlet();
512
513         request.setPortletContext(getPortlet().getPortletContext());
514
515         RegistrationContext regCtx = producer.getRegistrationContext();
516         if (regCtx != null)
517             request.setRegistrationContext(regCtx);
518
519         UserContext userCtx = getUserContext(userID);
520         if (userCtx != null)
521             request.setUserContext(userCtx);
522
523         PortletContext response = null;
524
525         try {
526
527             response = portletPort.clonePortlet(request);
528             parameterChecker.check(response, Constants.NILLABLE_FALSE);
529
530         } catch (java.rmi.RemoteException JavaDoc wsrpFault) {
531
532             WSRPXHelper.handleWSRPFault(logger, wsrpFault);
533         }
534
535         return response;
536     }
537
538     /**
539      * Destroy the producer portlets specified in the entiyHandles array.
540      **/

541     public DestroyPortletsResponse destroyPortlets(String JavaDoc[] portletHandles,
542                                                    String JavaDoc userID)
543     throws WSRPException {
544         DestroyPortlets request = new DestroyPortlets();
545
546         RegistrationContext regCtx = producer.getRegistrationContext();
547         if (regCtx != null)
548             request.setRegistrationContext(regCtx);
549
550         request.setPortletHandles(portletHandles);
551
552         DestroyPortletsResponse response = null;
553         try {
554
555             response = portletPort.destroyPortlets(request);
556             parameterChecker.check(response);
557
558         } catch (java.rmi.RemoteException JavaDoc wsrpFault) {
559
560             WSRPXHelper.handleWSRPFault(logger, wsrpFault);
561         }
562
563         return response;
564     }
565
566     /**
567      * Inform the producer that the sessions specified in the sessionIDs array
568      * will no longer be used by the consumer and can therefor be released.
569      **/

570     public ReturnAny releaseSessions(String JavaDoc[] sessionIDs,
571                                      String JavaDoc userID)
572     throws WSRPException {
573
574         checkInitCookie(userID);
575
576         ReleaseSessions request = new ReleaseSessions();
577
578         RegistrationContext regCtx = producer.getRegistrationContext();
579         if (regCtx != null)
580             request.setRegistrationContext(regCtx);
581
582         request.setSessionIDs(sessionIDs);
583
584         ReturnAny response = null;
585         try {
586
587             response = markupPort.releaseSessions(request);
588
589         } catch (java.rmi.RemoteException JavaDoc wsrpFault) {
590
591             WSRPXHelper.handleWSRPFault(logger, wsrpFault);
592         }
593
594         return response;
595     }
596
597     /**
598      * Actual WSRP initCookie() call
599      **/

600     public void initCookie() throws WSRPException {
601         InitCookie request = new InitCookie();
602
603         RegistrationContext regCtx = producer.getRegistrationContext();
604         if (regCtx != null)
605             request.setRegistrationContext(regCtx);
606
607         try {
608
609             markupPort.initCookie(request);
610
611         } catch (java.rmi.RemoteException JavaDoc wsrpFault) {
612             WSRPXHelper.handleWSRPFault(logger, wsrpFault);
613         }
614     }
615
616     /**
617      * Fetches information about the portlet from the producer.
618      *
619      * @param userID is used to get the user context of the user from the user registry
620      * @param desiredLocales Array of locales the description should be provided
621      *
622      * @return The response to the getPortletDescription call.
623      **/

624     public PortletDescriptionResponse getPortletDescription(String JavaDoc userID,
625                                                             String JavaDoc[] desiredLocales)
626     throws WSRPException {
627         GetPortletDescription request = new GetPortletDescription();
628
629         RegistrationContext regCtx = producer.getRegistrationContext();
630         if (regCtx != null)
631             request.setRegistrationContext(regCtx);
632
633         request.setPortletContext(getPortlet().getPortletContext());
634
635         UserContext userCtx = getUserContext(userID);
636         if (userCtx != null)
637             request.setUserContext(userCtx);
638
639         request.setDesiredLocales(desiredLocales);
640
641         PortletDescriptionResponse response = null;
642
643         try {
644
645             response = portletPort.getPortletDescription(request);
646             parameterChecker.check(response);
647
648         } catch (java.rmi.RemoteException JavaDoc wsrpFault) {
649
650             WSRPXHelper.handleWSRPFault(logger, wsrpFault);
651         }
652
653         return response;
654     }
655
656     /**
657      * Fetches all published properties of an remote portlet.
658      *
659      * @param userID The ID of the user this request is done for
660      *
661      * @return The portlet property description response from the producer
662      **/

663     public PortletPropertyDescriptionResponse getPortletPropertyDescription(String JavaDoc userID)
664     throws WSRPException {
665         GetPortletPropertyDescription request = new GetPortletPropertyDescription();
666         request.setPortletContext(getPortlet().getPortletContext());
667
668         RegistrationContext regCtx = producer.getRegistrationContext();
669         if (regCtx != null)
670             request.setRegistrationContext(regCtx);
671
672         UserContext userCtx = getUserContext(userID);
673         if (userCtx != null)
674             request.setUserContext(userCtx);
675
676         request.setDesiredLocales(consumerEnv.getSupportedLocales());
677
678         PortletPropertyDescriptionResponse response = null;
679
680         try {
681
682             response = portletPort.getPortletPropertyDescription(request);
683             parameterChecker.check(response);
684
685         } catch (java.rmi.RemoteException JavaDoc wsrpFault) {
686
687             WSRPXHelper.handleWSRPFault(logger, wsrpFault);
688         }
689
690         return response;
691     }
692
693     /**
694      * Get the current values of the properties with the given names.
695      *
696      * @param names The names of the properties
697      * @param userID The ID of the user is used to get the user context
698      *
699      * @return A list of properties containing the values and names of the properties.
700      **/

701     public PropertyList getPortletProperties(String JavaDoc[] names, String JavaDoc userID)
702     throws WSRPException {
703         GetPortletProperties request = new GetPortletProperties();
704         request.setPortletContext(getPortlet().getPortletContext());
705         request.setNames(names);
706
707         RegistrationContext regCtx = producer.getRegistrationContext();
708         if (regCtx != null)
709             request.setRegistrationContext(regCtx);
710
711         UserContext userCtx = getUserContext(userID);
712         if (userCtx != null)
713             request.setUserContext(userCtx);
714
715         PropertyList response = null;
716
717         try {
718
719             response = portletPort.getPortletProperties(request);
720             parameterChecker.check(response, Constants.NILLABLE_FALSE);
721
722         } catch (java.rmi.RemoteException JavaDoc wsrpFault) {
723
724             WSRPXHelper.handleWSRPFault(logger, wsrpFault);
725         }
726
727         return response;
728     }
729
730     /**
731      * Set the portlet properties specified in the property list
732      *
733      * @param properties List of properties to be set.
734      * @param userID The ID of the user is used to get the user context
735      **/

736     public PortletContext setPortletProperties(PropertyList properties, String JavaDoc userID)
737     throws WSRPException {
738         SetPortletProperties request = new SetPortletProperties();
739         request.setPortletContext(getPortlet().getPortletContext());
740
741         RegistrationContext regCtx = producer.getRegistrationContext();
742         if (regCtx != null)
743             request.setRegistrationContext(regCtx);
744
745         UserContext userCtx = getUserContext(userID);
746         if (userCtx != null)
747             request.setUserContext(userCtx);
748         request.setPropertyList(properties);
749
750         PortletContext response = null;
751
752         try {
753
754             response = portletPort.setPortletProperties(request);
755             parameterChecker.check(response, Constants.NILLABLE_FALSE);
756
757         } catch (java.rmi.RemoteException JavaDoc wsrpFault) {
758
759             WSRPXHelper.handleWSRPFault(logger, wsrpFault);
760         }
761
762         return response;
763     }
764
765     /**
766      * Get the extensions for the MarkupContext.
767      */

768     protected Extension[] getMarkupParamsExtensions() {
769         // this can be overwritten in sub classes
770
return null;
771     }
772 }
773
Popular Tags