001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.cocoon.portal.components.modules.input;
018:
019: import java.util.Map;
020:
021: import org.apache.avalon.framework.configuration.Configuration;
022: import org.apache.avalon.framework.configuration.ConfigurationException;
023: import org.apache.avalon.framework.service.ServiceException;
024: import org.apache.cocoon.environment.ObjectModelHelper;
025: import org.apache.cocoon.portal.Constants;
026: import org.apache.cocoon.portal.PortalService;
027: import org.apache.commons.jxpath.JXPathContext;
028:
029: /**
030: * Makes accessible coplet instance data by using JXPath expressions.<br><br>
031: *
032: * Example:<br><br>
033: *
034: * <pre><map:action type="foo">
035: * <map:parameter name="maxpageable" value="{coplet:copletData/maxpageable}"/>
036: * </map:action><br></pre>
037: *
038: * The module will insert the boolean value specifying whether the coplet is
039: * maxpageable or not as value of attribute "value" in <map:parameter>.
040: * There are two possibilities how the module obtains the information required for
041: * getting the coplet instance data:<br><br>
042: * 1) If it is used within a coplet pipeline and this pipeline is called using the "cocoon:" protocol,
043: * all required information are passed automatically.<br>
044: * 2) Otherwise the portal name and the coplet id must be passed in the object model
045: * which can be done by using the ObjectModelAction:
046: *
047: * <pre><map:action type="objectModel">
048: * <map:parameter name="portalName" value="exampleportal"/>
049: * <map:parameter name="copletId" value="examplecoplet"/>
050: * <map:action type="foo">
051: * <map:parameter name="maxpageable" value="{coplet:copletData/maxpageable}"/>
052: * </map:action>
053: * </map:action></pre>
054: *
055: * Using the path '#' you get the current copletId: {coplet:#}
056: *
057: * @author <a href="mailto:bluetkemeier@s-und-n.de">Björn Lütkemeier</a>
058: * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
059: * @version CVS $Id: CopletModule.java 433543 2006-08-22 06:22:54Z crossley $
060: */
061: public class CopletModule extends AbstractModule {
062:
063: /* (non-Javadoc)
064: * @see org.apache.cocoon.components.modules.input.InputModule#getAttribute(java.lang.String, org.apache.avalon.framework.configuration.Configuration, java.util.Map)
065: */
066: public Object getAttribute(String name, Configuration modeConf,
067: Map objectModel) throws ConfigurationException {
068: PortalService portalService = null;
069: try {
070:
071: portalService = (PortalService) this .manager
072: .lookup(PortalService.ROLE);
073:
074: // determine coplet id
075: String copletId = null;
076: Map context = (Map) objectModel
077: .get(ObjectModelHelper.PARENT_CONTEXT);
078: if (context != null) {
079: copletId = (String) context
080: .get(Constants.COPLET_ID_KEY);
081: } else {
082: copletId = (String) objectModel
083: .get(Constants.COPLET_ID_KEY);
084: }
085:
086: if (copletId == null) {
087: return null;
088: }
089:
090: // return the coplet id
091: if (name.equals("#")) {
092: return copletId;
093: }
094: JXPathContext jxpathContext = JXPathContext
095: .newContext(portalService.getComponentManager()
096: .getProfileManager().getCopletInstanceData(
097: copletId));
098: return jxpathContext.getValue(name);
099: } catch (ServiceException e) {
100: throw new ConfigurationException(
101: "Unable to lookup portal service.", e);
102: } finally {
103: this.manager.release(portalService);
104: }
105: }
106:
107: }
|