1 16 17 package org.apache.cocoon.webapps.session.components; 18 19 import java.util.Iterator ; 20 import java.util.Map ; 21 22 import org.apache.avalon.framework.activity.Disposable; 23 import org.apache.avalon.framework.configuration.Configuration; 24 import org.apache.avalon.framework.configuration.ConfigurationException; 25 import org.apache.avalon.framework.service.ServiceException; 26 import org.apache.avalon.framework.service.ServiceManager; 27 import org.apache.avalon.framework.service.Serviceable; 28 import org.apache.avalon.framework.thread.ThreadSafe; 29 import org.apache.cocoon.ProcessingException; 30 import org.apache.cocoon.components.modules.input.InputModule; 31 import org.apache.cocoon.webapps.session.ContextManager; 32 import org.apache.cocoon.webapps.session.context.SessionContext; 33 import org.apache.cocoon.xml.dom.DOMUtil; 34 import org.w3c.dom.DocumentFragment ; 35 36 49 public class ContextInputModule 50 implements ThreadSafe, Serviceable, Disposable, InputModule { 51 52 protected ServiceManager manager; 53 54 protected ContextManager contextManager; 55 56 59 public Object getAttribute(String name, 60 Configuration modeConf, 61 Map objectModel) 62 throws ConfigurationException { 63 if ( name == null ) { 64 return null; 65 } 66 int pos = name.indexOf('/'); 67 if ( pos != -1 ) { 68 final String contextName = name.substring(0, pos); 69 final String path = name.substring(pos); 70 71 try { 72 SessionContext context = this.contextManager.getContext(contextName); 73 if ( context != null ) { 74 DocumentFragment frag = context.getXML(path); 75 return DOMUtil.getValueOfNode(frag); 76 } 77 } catch (ProcessingException pe) { 78 throw new ConfigurationException("Unable to get information from context.", pe); 79 } 80 81 } 82 return null; 83 } 84 85 88 public Iterator getAttributeNames(Configuration modeConf, Map objectModel) 89 throws ConfigurationException { 90 return null; 91 } 92 93 96 public Object [] getAttributeValues(String name, 97 Configuration modeConf, 98 Map objectModel) 99 throws ConfigurationException { 100 final Object value = this.getAttribute(name, modeConf, objectModel); 101 if ( value != null ) { 102 return new Object [] {value}; 103 } 104 return null; 105 } 106 107 110 public void service(ServiceManager manager) throws ServiceException { 111 this.manager = manager; 112 this.contextManager = (ContextManager) this.manager.lookup(ContextManager.ROLE); 113 } 114 115 118 public void dispose() { 119 if ( this.manager != null ) { 120 this.manager.release(this.contextManager); 121 this.contextManager = null; 122 this.manager = null; 123 } 124 125 } 126 127 } 128 | Popular Tags |