1 16 package org.apache.cocoon.components.modules.input; 17 18 import java.util.Iterator ; 19 import java.util.Map ; 20 21 import org.apache.avalon.framework.configuration.Configurable; 22 import org.apache.avalon.framework.configuration.Configuration; 23 import org.apache.avalon.framework.configuration.ConfigurationException; 24 import org.apache.avalon.framework.thread.ThreadSafe; 25 26 87 public class JXPathMetaModule extends AbstractMetaModule 88 implements Configurable, ThreadSafe { 89 90 95 protected JXPathHelperConfiguration configuration; 96 97 100 protected String parameter = ""; 101 102 103 public JXPathMetaModule() { 104 super.defaultInput = "request-attr"; 106 } 107 108 109 116 public void configure(Configuration config) throws ConfigurationException { 117 118 this.inputConf = config.getChild("input-module"); 119 this.defaultInput = this.inputConf.getAttribute("name",this.defaultInput); 120 this.parameter = config.getChild("parameter").getValue(this.parameter); 121 122 this.configuration = JXPathHelper.setup(config); 123 } 124 125 126 public Object getAttribute(String name, Configuration modeConf, Map objectModel) 127 throws ConfigurationException { 128 129 Object contextObj = getContextObject(modeConf, objectModel); 130 if (modeConf != null) { 131 name = modeConf.getChild("parameter").getValue(!this.parameter.equals("") ? this.parameter : name); 132 } 133 return JXPathHelper.getAttribute(name, modeConf, this.configuration, contextObj); 134 } 135 136 137 public Iterator getAttributeNames(Configuration modeConf, Map objectModel) 138 throws ConfigurationException { 139 140 Object contextObj = getContextObject(modeConf, objectModel); 141 return JXPathHelper.getAttributeNames(this.configuration, contextObj); 142 } 143 144 145 public Object [] getAttributeValues(String name, Configuration modeConf, Map objectModel) 146 throws ConfigurationException { 147 148 Object contextObj = getContextObject(modeConf, objectModel); 149 if (modeConf != null) { 150 name = modeConf.getChild("parameter").getValue(!this.parameter.equals("") ? this.parameter : name); 151 } 152 return JXPathHelper.getAttributeValues(name, modeConf, this.configuration, contextObj); 153 } 154 155 156 163 protected Object getContextObject(Configuration modeConf, Map objectModel) 164 throws ConfigurationException { 165 166 if (!this.initialized) { 167 lazy_initialize(); 168 } 169 170 Configuration mConf = null; 171 String inputName = null; 172 String parameter = this.parameter; 173 if (modeConf != null) { 174 mConf = modeConf.getChild("input-module"); 175 inputName = mConf.getAttribute("name", null); 176 parameter = modeConf.getChild("from-parameter").getValue(parameter); 177 } 178 179 if (getLogger().isDebugEnabled()) { 180 getLogger().debug("modeConf is " + modeConf + " this.inputConf is " + this.inputConf 181 + " mConf is " + mConf + " this.input is " + this.input 182 + " this.defaultInput is " + this.defaultInput 183 + " inputName is " + inputName + " parameter is " + parameter); 184 } 185 186 Object obj = getValue(parameter, objectModel, 187 this.input, this.defaultInput, this.inputConf, 188 null, inputName, mConf); 189 190 if (getLogger().isDebugEnabled()) { 191 getLogger().debug("returning an " + (obj == null ? "null" : obj.getClass().getName()) + 192 " as " + obj); 193 } 194 195 return obj; 196 } 197 } 198 | Popular Tags |