1 16 package org.apache.cocoon.matching.modular; 17 18 import org.apache.avalon.framework.configuration.Configurable; 19 import org.apache.avalon.framework.configuration.Configuration; 20 import org.apache.avalon.framework.configuration.ConfigurationException; 21 import org.apache.avalon.framework.parameters.Parameters; 22 import org.apache.avalon.framework.component.ComponentSelector; 23 import org.apache.avalon.framework.component.ComponentException; 24 import org.apache.avalon.framework.component.ComponentManager; 25 import org.apache.avalon.framework.component.Composable; 26 27 import org.apache.cocoon.components.modules.input.InputModule; 28 29 import org.apache.cocoon.matching.AbstractWildcardMatcher; 30 31 import java.util.Map ; 32 33 48 public class WildcardMatcher extends AbstractWildcardMatcher 49 implements Configurable, Composable 50 { 51 52 53 protected ComponentManager manager; 54 55 private String defaultParam; 56 private String defaultInput = "request-param"; private Configuration inputConf = null; String INPUT_MODULE_ROLE = InputModule.ROLE; 60 String INPUT_MODULE_SELECTOR = INPUT_MODULE_ROLE+"Selector"; 61 62 66 public void compose(ComponentManager manager) throws ComponentException { 67 this.manager=manager; 68 } 69 70 public void configure(Configuration config) throws ConfigurationException { 71 this.defaultParam = config.getChild("parameter-name").getValue(null); 72 this.inputConf = config.getChild("input-module"); 73 this.defaultInput = this.inputConf.getAttribute("name",this.defaultInput); 74 } 75 76 protected String getMatchString(Map objectModel, Parameters parameters) { 77 78 String paramName = parameters.getParameter("parameter-name", this.defaultParam); 79 String inputName = parameters.getParameter("input-module", this.defaultInput); 80 81 if (paramName == null) { 82 if (getLogger().isWarnEnabled()) 83 getLogger().warn("No parameter name given. Trying to continue"); 84 } 85 if (inputName == null) { 86 if (getLogger().isWarnEnabled()) 87 getLogger().warn("No input module given. FAILING"); 88 return null; 89 } 90 91 InputModule input = null; 92 ComponentSelector inputSelector = null; 93 Object result = null; 94 95 102 try { 103 inputSelector=(ComponentSelector) this.manager.lookup(INPUT_MODULE_SELECTOR); 105 if (inputName != null && inputSelector != null && inputSelector.hasComponent(inputName)){ 106 input = (InputModule) inputSelector.select(inputName); 107 } 108 if (input != null) { 109 result = input.getAttribute(paramName, this.inputConf, objectModel); 110 } 111 } catch (Exception e) { 112 if (getLogger().isWarnEnabled()) 113 getLogger().warn("A problem occurred acquiring Parameter '" + paramName 114 + "' from '" + inputName + "': " + e.getMessage()); 115 } finally { 116 if (inputSelector != null) { 118 if (input != null) 119 inputSelector.release(input); 120 this.manager.release(inputSelector); 121 } 122 } 123 124 if (getLogger().isDebugEnabled()) 125 getLogger().debug(" using "+inputName+" obtained value "+result); 126 127 if (result instanceof String ) { 128 return (String ) result; 129 } else { 130 return result.toString(); 131 } 132 } 133 } 134 | Popular Tags |