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 23 import org.apache.cocoon.environment.Redirector; 24 import org.apache.cocoon.environment.SourceResolver; 25 import org.apache.cocoon.components.modules.input.InputModuleHelper; 26 27 import org.apache.commons.lang.BooleanUtils; 28 29 import java.util.HashMap ; 30 import java.util.Map ; 31 32 71 public class InputModuleAction extends ConfigurableServiceableAction implements ThreadSafe { 72 73 76 public Map act(Redirector redirector, SourceResolver resolver, 77 Map objectModel, String source, Parameters parameters) 78 throws Exception { 79 80 HashMap map = null; 81 Configuration conf = null; 82 String module = parameters.getParameter("module", (String ) this.settings.get("module")); 83 String attrib = 84 parameters.getParameter("attribute", (String ) this.settings.get("attribute")); 85 boolean single = 86 parameters.getParameterAsBoolean( 87 "single-value", 88 ((Boolean ) this.settings.get("single-value")).booleanValue()); 89 90 if (module != null && attrib != null) { 91 InputModuleHelper mhelper = new InputModuleHelper(); 92 mhelper.setup(manager); 93 Object [] result = null; 94 if (!single) { 95 result = mhelper.getAttributeValues(objectModel, conf, module, attrib, null); 96 } else { 97 Object tmp = mhelper.getAttribute(objectModel, conf, module, attrib, null); 98 if (tmp != null){ 99 result = new Object [1]; 100 result[0] = tmp; 101 } 102 } 103 mhelper.releaseAll(); 104 105 if (result != null && result.length != 0) { 106 map = new HashMap (); 107 for (int i = 0; i < result.length; i++) { 108 map.put(Integer.toString(i), result[i]); 109 } 110 } 111 } else { 112 if (getLogger().isErrorEnabled()) { 113 getLogger().error( 114 "Parameter is missing: module=" + module + " attribute=" + attrib); 115 } 116 } 117 return map; 118 } 119 120 123 public void configure(Configuration conf) throws ConfigurationException { 124 super.configure(conf); 125 String tmp = (String ) this.settings.get("single-value", "false"); 126 this.settings.put("single-value", BooleanUtils.toBooleanObject(tmp)); 127 } 128 129 } 130 | Popular Tags |