KickJava   Java API By Example, From Geeks To Geeks.

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


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.portal.PortalService;
24 import org.apache.commons.jxpath.JXPathContext;
25
26 /**
27  * This input module gives access to information stored in a layout object
28  * by using JXPathExpressions.
29  * The syntax to use is LAYOUT_ID/PATH or LAYOUT_KEY:LAYOUT_ID/PATH
30  *
31  * @author <a HREF="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
32  * @version CVS $Id: LayoutModule.java 289415 2005-09-16 07:40:04Z cziegeler $
33  */

34 public class LayoutModule
35 extends AbstractModule {
36     
37     /* (non-Javadoc)
38      * @see org.apache.cocoon.components.modules.input.InputModule#getAttribute(java.lang.String, org.apache.avalon.framework.configuration.Configuration, java.util.Map)
39      */

40     public Object JavaDoc getAttribute(String JavaDoc name, Configuration modeConf, Map JavaDoc objectModel)
41     throws ConfigurationException {
42         PortalService portalService = null;
43         try {
44
45             portalService = (PortalService)this.manager.lookup(PortalService.ROLE);
46
47             int pos = name.indexOf('/');
48             String JavaDoc path;
49             if ( pos == -1 ) {
50                 path = null;
51             } else {
52                 path = name.substring(pos + 1);
53                 name = name.substring(0, pos);
54             }
55             // is the layout key specified?
56
pos = name.indexOf(':');
57             String JavaDoc layoutKey = null;
58             String JavaDoc layoutId = name;
59             if ( pos != -1 ) {
60                 layoutKey = name.substring(0, pos);
61                 layoutId = name.substring(pos + 1);
62             }
63
64             // get the layout
65
final Object JavaDoc layout = portalService.getComponentManager().getProfileManager().getPortalLayout(layoutKey, layoutId);
66             Object JavaDoc value = layout;
67             if ( layout != null && path != null ) {
68                 final JXPathContext jxpathContext = JXPathContext.newContext(layout);
69                 value = jxpathContext.getValue(path);
70             }
71             return value;
72         } catch (ServiceException e) {
73             throw new ConfigurationException("Unable to lookup portal service.", e);
74         } finally {
75             this.manager.release(portalService);
76         }
77     }
78 }
79
Popular Tags