1 17 package org.apache.excalibur.xml.xpath; 18 19 import java.util.HashMap ; 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.logger.AbstractLogEnabled; 25 26 import org.w3c.dom.Node ; 27 import org.w3c.dom.NodeList ; 28 29 38 public abstract class AbstractProcessorImpl 39 extends AbstractLogEnabled 40 implements XPathProcessor, Configurable, PrefixResolver 41 { 42 private final HashMap m_mappings = new HashMap (); 43 44 public void configure( Configuration configuration ) throws ConfigurationException 45 { 46 final Configuration namespaceMappings = configuration.getChild( "namespace-mappings", true ); 47 final Configuration[] namespaces = namespaceMappings.getChildren( "namespace" ); 48 for( int i = 0; i < namespaces.length; i++ ) 49 { 50 final String prefix = namespaces[ i ].getAttribute( "prefix" ); 51 final String uri = namespaces[ i ].getAttribute( "uri" ); 52 m_mappings.put( prefix, uri ); 53 } 54 } 55 56 65 public Node selectSingleNode( final Node contextNode, 66 final String str ) 67 { 68 return selectSingleNode(contextNode, str, this); 69 } 70 71 79 public NodeList selectNodeList( final Node contextNode, 80 final String str ) 81 { 82 return selectNodeList(contextNode, str, this); 83 } 84 85 92 public boolean evaluateAsBoolean( Node contextNode, String str ) 93 { 94 return evaluateAsBoolean(contextNode, str, this); 95 } 96 97 104 public Number evaluateAsNumber( Node contextNode, String str ) 105 { 106 return evaluateAsNumber(contextNode, str, this); 107 } 108 109 116 public String evaluateAsString( Node contextNode, String str ) 117 { 118 return evaluateAsString(contextNode, str, this); 119 } 120 121 129 public abstract boolean evaluateAsBoolean(Node contextNode, String str, PrefixResolver resolver); 130 131 139 public abstract Number evaluateAsNumber(Node contextNode, String str, PrefixResolver resolver); 140 141 149 public abstract String evaluateAsString(Node contextNode, String str, PrefixResolver resolver); 150 151 159 public abstract Node selectSingleNode(Node contextNode, String str, PrefixResolver resolver); 160 161 169 public abstract NodeList selectNodeList(Node contextNode, String str, PrefixResolver resolver); 170 171 public String prefixToNamespace(String prefix) 172 { 173 return (String )m_mappings.get( prefix ); 174 } 175 } 176 | Popular Tags |