1 16 17 package org.apache.cocoon.components.modules.input; 18 import org.apache.avalon.framework.service.ServiceException; 19 import org.apache.avalon.framework.service.ServiceManager; 20 import org.apache.avalon.framework.service.Serviceable; 21 22 import org.apache.avalon.framework.configuration.Configuration; 23 import org.apache.avalon.framework.configuration.ConfigurationException; 24 import org.apache.avalon.framework.thread.ThreadSafe; 25 import org.apache.excalibur.source.SourceResolver; 26 27 import java.io.IOException ; 28 import java.util.Iterator ; 29 import java.util.LinkedList ; 30 import java.util.List ; 31 import java.util.Map ; 32 import java.util.Vector ; 33 34 76 public class ContextPathModule extends AbstractInputModule implements Serviceable, ThreadSafe { 77 78 private ServiceManager m_manager; 79 private SourceResolver m_resolver; 80 81 final static Vector returnNames; 82 static { 83 Vector tmp = new Vector (); 84 tmp.add("contextPath"); 85 returnNames = tmp; 86 } 87 88 91 public void service(ServiceManager manager) throws ServiceException { 92 m_manager = manager; 93 m_resolver = (SourceResolver) m_manager.lookup(SourceResolver.ROLE); 94 } 95 96 101 public void dispose() { 102 super.dispose(); 103 if ( this.m_manager != null ) { 104 this.m_manager.release( this.m_resolver ); 105 this.m_manager = null; 106 this.m_resolver = null; 107 } 108 } 109 110 public Object getAttribute( String name, Configuration modeConf, Map objectModel ) throws ConfigurationException { 111 try { 112 if(name.startsWith("/")) { 113 return m_resolver.resolveURI("context:/"+name).getURI().substring("file:".length()); 114 } 115 return m_resolver.resolveURI(name).getURI().substring("file:".length()); 116 } catch( final IOException mue ) { 117 throw new ConfigurationException( "Cannot resolve realpath", mue); 118 } 119 } 120 121 public Iterator getAttributeNames( Configuration modeConf, Map objectModel ) throws ConfigurationException { 122 123 return ContextPathModule.returnNames.iterator(); 124 } 125 126 127 public Object [] getAttributeValues( String name, Configuration modeConf, Map objectModel ) 128 throws ConfigurationException { 129 130 List values = new LinkedList (); 131 values.add( this.getAttribute(name, modeConf, objectModel) ); 132 133 return values.toArray(); 134 } 135 } 136 | Popular Tags |