KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > portal > components > modules > input > CopletModule


1 /*
2  * Copyright 1999-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.components.modules.input;
17
18 import java.util.Map JavaDoc;
19
20 import org.apache.avalon.framework.configuration.Configuration;
21 import org.apache.avalon.framework.configuration.ConfigurationException;
22 import org.apache.avalon.framework.service.ServiceException;
23 import org.apache.cocoon.environment.ObjectModelHelper;
24 import org.apache.cocoon.portal.Constants;
25 import org.apache.cocoon.portal.PortalService;
26 import org.apache.commons.jxpath.JXPathContext;
27
28 /**
29  * Makes accessible coplet instance data by using JXPath expressions.<br><br>
30  *
31  * Example:<br><br>
32  *
33  * <pre>&lt;map:action type="foo"&gt;
34  * &lt;map:parameter name="maxpageable" value="{coplet:copletData/maxpageable}"/&gt;
35  * &lt;/map:action&gt;<br></pre>
36  *
37  * The module will insert the boolean value specifying whether the coplet is
38  * maxpageable or not as value of attribute "value" in &lt;map:parameter&gt;.
39  * There are two possibilities how the module obtains the information required for
40  * getting the coplet instance data:<br><br>
41  * 1) If it is used within a coplet pipeline and this pipeline is called using the "cocoon:" protocol,
42  * all required information are passed automatically.<br>
43  * 2) Otherwise the portal name and the coplet id must be passed in the object model
44  * which can be done by using the ObjectModelAction:
45  *
46  * <pre>&lt;map:action type="objectModel"&gt;
47  * &lt;map:parameter name="portalName" value="exampleportal"/&gt;
48  * &lt;map:parameter name="copletId" value="examplecoplet"/&gt;
49  * &lt;map:action type="foo"&gt;
50  * &lt;map:parameter name="maxpageable" value="{coplet:copletData/maxpageable}"/&gt;
51  * &lt;/map:action&gt;
52  * &lt;/map:action&gt;</pre>
53  *
54  * Using the path '#' you get the current copletId: {coplet:#}
55  *
56  * @author <a HREF="mailto:bluetkemeier@s-und-n.de">Bj&ouml;rn L&uuml;tkemeier</a>
57  * @author <a HREF="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
58  * @version CVS $Id: CopletModule.java 289415 2005-09-16 07:40:04Z cziegeler $
59  */

60 public class CopletModule
61 extends AbstractModule {
62     
63     /* (non-Javadoc)
64      * @see org.apache.cocoon.components.modules.input.InputModule#getAttribute(java.lang.String, org.apache.avalon.framework.configuration.Configuration, java.util.Map)
65      */

66     public Object JavaDoc getAttribute(String JavaDoc name, Configuration modeConf, Map JavaDoc objectModel)
67     throws ConfigurationException {
68         PortalService portalService = null;
69         try {
70
71             portalService = (PortalService)this.manager.lookup(PortalService.ROLE);
72
73             // determine coplet id
74
String JavaDoc copletId = null;
75             Map JavaDoc context = (Map JavaDoc)objectModel.get(ObjectModelHelper.PARENT_CONTEXT);
76             if (context != null) {
77                 copletId = (String JavaDoc)context.get(Constants.COPLET_ID_KEY);
78             } else {
79                 copletId = (String JavaDoc)objectModel.get(Constants.COPLET_ID_KEY);
80             }
81             
82             if (copletId == null) {
83                 return null;
84             }
85             
86             // return the coplet id
87
if ( name.equals("#") ) {
88                 return copletId;
89             }
90             JXPathContext jxpathContext = JXPathContext.newContext(portalService.getComponentManager().getProfileManager().getCopletInstanceData(copletId));
91             return jxpathContext.getValue(name);
92         } catch (ServiceException e) {
93             throw new ConfigurationException("Unable to lookup portal service.", e);
94         } finally {
95             this.manager.release(portalService);
96         }
97     }
98
99 }
100
Popular Tags