1 16 package org.apache.cocoon.portal.components.modules.input; 17 18 import java.util.Map ; 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 34 public class LayoutModule 35 extends AbstractModule { 36 37 40 public Object getAttribute(String name, Configuration modeConf, Map 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 path; 49 if ( pos == -1 ) { 50 path = null; 51 } else { 52 path = name.substring(pos + 1); 53 name = name.substring(0, pos); 54 } 55 pos = name.indexOf(':'); 57 String layoutKey = null; 58 String layoutId = name; 59 if ( pos != -1 ) { 60 layoutKey = name.substring(0, pos); 61 layoutId = name.substring(pos + 1); 62 } 63 64 final Object layout = portalService.getComponentManager().getProfileManager().getPortalLayout(layoutKey, layoutId); 66 Object 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 |