KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > portal > acting > CopletSetDataAction


1 /*
2  * Copyright 1999-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.acting;
17
18 import java.util.Map JavaDoc;
19
20 import org.apache.avalon.framework.configuration.ConfigurationException;
21 import org.apache.avalon.framework.parameters.Parameters;
22 import org.apache.avalon.framework.service.ServiceException;
23 import org.apache.cocoon.ProcessingException;
24 import org.apache.cocoon.acting.ServiceableAction;
25 import org.apache.cocoon.environment.ObjectModelHelper;
26 import org.apache.cocoon.environment.Redirector;
27 import org.apache.cocoon.environment.SourceResolver;
28 import org.apache.cocoon.portal.Constants;
29 import org.apache.cocoon.portal.PortalService;
30 import org.apache.cocoon.portal.event.Event;
31 import org.apache.cocoon.portal.event.EventManager;
32 import org.apache.cocoon.portal.event.impl.CopletJXPathEvent;
33
34 /**
35  * Using this action, you can set values in a coplet
36  *
37  * @author <a HREF="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
38  * @version CVS $Id: CopletSetDataAction.java 219049 2005-07-14 15:11:52Z cziegeler $
39  */

40 public class CopletSetDataAction
41 extends ServiceableAction {
42
43     /* (non-Javadoc)
44      * @see org.apache.cocoon.acting.Action#act(org.apache.cocoon.environment.Redirector, org.apache.cocoon.environment.SourceResolver, java.util.Map, java.lang.String, org.apache.avalon.framework.parameters.Parameters)
45      */

46     public Map JavaDoc act(Redirector redirector, SourceResolver resolver, Map JavaDoc objectModel, String JavaDoc source, Parameters parameters)
47     throws Exception JavaDoc {
48         PortalService portalService = null;
49         try {
50
51             portalService = (PortalService)this.manager.lookup(PortalService.ROLE);
52
53             // determine coplet id
54
String JavaDoc copletId = null;
55             Map JavaDoc context = (Map JavaDoc)objectModel.get(ObjectModelHelper.PARENT_CONTEXT);
56             if (context != null) {
57                 copletId = (String JavaDoc)context.get(Constants.COPLET_ID_KEY);
58             } else {
59                 copletId = (String JavaDoc)objectModel.get(Constants.COPLET_ID_KEY);
60             }
61         
62             if (copletId == null) {
63                 throw new ConfigurationException("copletId must be passed in the object model either directly (e.g. by using ObjectModelAction) or within the parent context.");
64             }
65         
66             // now traverse parameters:
67
// parameter name is path
68
// parameter value is value
69
// if the value is null or empty, the value is not set!
70
final String JavaDoc[] names = parameters.getNames();
71             if ( names != null ) {
72                 final EventManager publisher = portalService.getComponentManager().getEventManager();
73                 for(int i=0; i<names.length; i++) {
74                     final String JavaDoc path = names[i];
75                     final String JavaDoc value = parameters.getParameter(path, null );
76                     if ( value != null && value.trim().length() > 0 ) {
77                         final Event event = new CopletJXPathEvent(portalService.getComponentManager().getProfileManager().getCopletInstanceData(copletId),
78                                 path,
79                                 value);
80                         publisher.send(event);
81                     }
82                 }
83             }
84             
85             return EMPTY_MAP;
86         
87         } catch (ServiceException e) {
88             throw new ProcessingException("Unable to lookup component.", e);
89         } finally {
90             this.manager.release(portalService);
91         }
92     }
93 }
94
Popular Tags