1 16 package org.apache.cocoon.acting; 17 18 import org.apache.avalon.framework.configuration.Configuration; 19 import org.apache.avalon.framework.configuration.ConfigurationException; 20 import org.apache.avalon.framework.parameters.Parameters; 21 import org.apache.avalon.framework.thread.ThreadSafe; 22 import org.apache.cocoon.environment.ObjectModelHelper; 23 import org.apache.cocoon.environment.Redirector; 24 import org.apache.cocoon.environment.Response; 25 import org.apache.cocoon.environment.SourceResolver; 26 27 import java.util.Collections ; 28 import java.util.HashMap ; 29 import java.util.Map ; 30 31 37 public class HttpHeaderAction 38 extends AbstractConfigurableAction 39 implements ThreadSafe { 40 41 44 private Object [] defaults = {}; 45 46 public void configure(Configuration conf) throws ConfigurationException { 47 super.configure(conf); 48 this.defaults = super.settings.keySet().toArray(); 49 } 50 51 public Map act(Redirector redirector, SourceResolver resolver, 52 Map objectModel, String source, Parameters parameters) 53 throws Exception { 54 final Map results = new HashMap (); 55 56 final Response response = ObjectModelHelper.getResponse(objectModel); 57 58 final String [] names = parameters.getNames(); 60 for (int i = 0; i < names.length; i++) { 61 response.setHeader(names[i],parameters.getParameter(names[i])); 62 results.put(names[i], parameters.getParameter(names[i])); 63 } 64 65 for (int i = 0; i < defaults.length; i++) { 67 if (!results.containsKey(this.defaults[i])) { 68 response.setHeader((String ) this.defaults[i], (String ) this.settings.get(defaults[i])); 69 results.put(this.defaults[i], this.settings.get(defaults[i])); 70 } 71 } 72 73 return Collections.unmodifiableMap(results); 74 } 75 } 76 | Popular Tags |