1 16 17 package org.apache.cocoon.components.modules.input; 18 19 import java.util.Iterator ; 20 import java.util.Map ; 21 import java.util.Vector ; 22 23 import org.apache.avalon.framework.configuration.Configuration; 24 import org.apache.avalon.framework.configuration.ConfigurationException; 25 import org.apache.avalon.framework.thread.ThreadSafe; 26 import org.apache.cocoon.environment.ObjectModelHelper; 27 28 38 public class BaseLinkModule extends AbstractInputModule implements ThreadSafe { 39 40 final static Vector returnNames = new Vector () { 41 { 42 add("RequestBaseLink"); 43 add("SitemapBaseLink"); 44 } 45 }; 46 47 public Object getAttribute( 48 final String name, 49 final Configuration modeConf, 50 final Map objectModel) 51 throws ConfigurationException { 52 53 String uri; 54 if (name.equals("SitemapBaseLink")) 55 uri = ObjectModelHelper.getRequest(objectModel).getSitemapURI(); 56 else if (name.equals("RequestBaseLink")) 57 uri = ObjectModelHelper.getRequest(objectModel).getRequestURI(); 58 else 59 uri = ""; 60 61 if (uri.startsWith("/")) { 62 uri = uri.substring(1); 63 } 64 65 StringBuffer result = new StringBuffer (uri.length()); 66 67 int nextIndex = 0; 68 while ((nextIndex = uri.indexOf('/', nextIndex) + 1) > 0) { 69 result.append("../"); 70 } 71 72 if (getLogger().isDebugEnabled()) 73 getLogger().debug("Returns " + result + " for uri " + uri + " and attribute " + name); 74 75 return result.toString(); 76 } 77 78 public Iterator getAttributeNames(final Configuration modeConf, final Map objectModel) 79 throws ConfigurationException { 80 81 return RequestURIModule.returnNames.iterator(); 82 } 83 84 public Object [] getAttributeValues( 85 final String name, 86 final Configuration modeConf, 87 final Map objectModel) 88 throws ConfigurationException { 89 90 Object result = new Object [1]; 91 result = getAttribute(name, modeConf, objectModel); 92 return (result == null? null : new Object []{result}); 93 } 94 95 } 96 | Popular Tags |