1 16 17 package org.apache.cocoon.components.modules.input; 18 19 import org.apache.avalon.framework.configuration.Configuration; 20 import org.apache.avalon.framework.configuration.ConfigurationException; 21 import org.apache.avalon.framework.thread.ThreadSafe; 22 import org.apache.cocoon.environment.ObjectModelHelper; 23 import org.apache.cocoon.environment.Request; 24 25 import java.util.Enumeration ; 26 import java.util.Iterator ; 27 import java.util.LinkedList ; 28 import java.util.List ; 29 import java.util.Map ; 30 import java.util.SortedSet ; 31 import java.util.TreeSet ; 32 33 45 public class RequestParameterModule extends AbstractInputModule implements ThreadSafe { 46 47 public Object getAttribute( String name, Configuration modeConf, Map objectModel ) throws ConfigurationException { 48 49 String pname = (String ) this.settings.get("parameter", name); 50 if ( modeConf != null ) { 51 pname = modeConf.getAttribute( "parameter", pname ); 52 pname = modeConf.getChild("parameter").getValue(pname); 54 } 55 return ObjectModelHelper.getRequest(objectModel).getParameter( pname ); 56 } 57 58 59 public Iterator getAttributeNames( Configuration modeConf, Map objectModel ) throws ConfigurationException { 60 61 return new IteratorHelper(ObjectModelHelper.getRequest(objectModel).getParameterNames()); 62 } 63 64 65 public Object [] getAttributeValues( String name, Configuration modeConf, Map objectModel ) 66 throws ConfigurationException { 67 68 Request request = ObjectModelHelper.getRequest(objectModel); 69 String wildcard = (String ) this.settings.get("parameter", name); 70 if ( modeConf != null ) { 71 wildcard = modeConf.getAttribute( "parameter", wildcard ); 72 wildcard = modeConf.getChild("parameter").getValue(wildcard); 74 } 75 int wildcardIndex = wildcard.indexOf( "*" ); 76 if ( wildcardIndex != -1 ) { 77 80 String prefix = wildcard.substring( 0, wildcardIndex ); 85 String suffix; 86 if ( wildcard.length() >= wildcardIndex + 1 ) { 87 suffix = wildcard.substring( wildcardIndex + 1 ); 88 } else { 89 suffix = ""; 90 } 91 SortedSet names = new TreeSet (); 92 Enumeration allNames = request.getParameterNames(); 93 94 while (allNames.hasMoreElements()) { 95 String pname = (String ) allNames.nextElement(); 96 if ( pname.startsWith( prefix ) && pname.endsWith( suffix ) ) { 97 names.add(pname); 98 } 99 } 100 101 List values = new LinkedList (); 102 Iterator j = names.iterator(); 103 while (j.hasNext()){ 104 String pname = (String ) j.next(); 105 values.add( request.getParameter( pname ) ); 106 } 107 108 return values.toArray(); 109 110 } else { 111 114 return request.getParameterValues( wildcard ); 115 116 } 117 118 } 119 120 } 121 | Popular Tags |