1 16 package org.apache.cocoon.acting; 17 18 import java.util.Enumeration ; 19 import java.util.HashMap ; 20 import java.util.Map ; 21 22 import org.apache.avalon.framework.parameters.Parameters; 23 import org.apache.avalon.framework.thread.ThreadSafe; 24 25 import org.apache.cocoon.environment.ObjectModelHelper; 26 import org.apache.cocoon.environment.Redirector; 27 import org.apache.cocoon.environment.Request; 28 import org.apache.cocoon.environment.SourceResolver; 29 30 85 public class RequestParamAction extends ServiceableAction implements ThreadSafe { 86 87 public final static String MAP_URI = "requestURI"; 88 public final static String MAP_QUERY = "requestQuery"; 89 public final static String MAP_CONTEXTPATH = "context"; 90 91 public final static String PARAM_PARAMETERS = "parameters"; 92 public final static String PARAM_DEFAULT_PREFIX = "default."; 93 94 public Map act(Redirector redirector, SourceResolver resolver, Map objectModel, 95 String source, Parameters param) throws Exception { 96 97 Request request = ObjectModelHelper.getRequest(objectModel); 98 99 Map map = new HashMap (); 100 101 map.put(MAP_URI, request.getRequestURI()); 102 103 String query = request.getQueryString(); 104 if (query != null && query.length() > 0) { 105 map.put(MAP_QUERY, "?" + query); 106 } else { 107 map.put(MAP_QUERY, ""); 108 } 109 110 map.put(MAP_CONTEXTPATH, request.getContextPath()); 111 112 if ("true".equalsIgnoreCase(param.getParameter(PARAM_PARAMETERS, null))) { 113 Enumeration e = request.getParameterNames(); 114 while (e.hasMoreElements()) { 115 String name = (String )e.nextElement(); 116 String value = request.getParameter(name); 117 118 if (value != null && !map.containsKey(name)) { 119 map.put(name, value); 120 } 121 } 122 123 String [] paramNames = param.getNames(); 124 for (int i = 0; i < paramNames.length; i++) { 125 if (paramNames[i].startsWith(PARAM_DEFAULT_PREFIX) 126 && (request.getParameter(paramNames[i].substring(PARAM_DEFAULT_PREFIX.length())) == null)) { 127 map.put(paramNames[i].substring(PARAM_DEFAULT_PREFIX.length()), 128 param.getParameter(paramNames[i])); 129 } 130 } 131 } 132 return (map); 133 } 134 135 } 136 | Popular Tags |