1 package net.sf.saxon.xpath; 2 3 import net.sf.saxon.Configuration; 4 import net.sf.saxon.om.NamespaceConstant; 5 6 import javax.xml.XMLConstants ; 7 import javax.xml.xpath.*; 8 9 12 public class XPathFactoryImpl extends XPathFactory { 13 14 private Configuration config = new Configuration(); 15 private XPathVariableResolver variableResolver; 16 private XPathFunctionResolver functionResolver; 17 18 28 public boolean isObjectModelSupported(String model) { 29 if (model.equals(NamespaceConstant.OBJECT_MODEL_SAXON)) return true; 30 if (model.equals(XPathConstants.DOM_OBJECT_MODEL)) return true; 31 if (model.equals(NamespaceConstant.OBJECT_MODEL_JDOM)) return true; 32 if (model.equals(NamespaceConstant.OBJECT_MODEL_XOM)) return true; 33 return false; 34 } 35 36 43 44 public void setFeature(String feature, boolean b) throws XPathFactoryConfigurationException { 45 if (feature.equals(XMLConstants.FEATURE_SECURE_PROCESSING)) { 46 config.setAllowExternalFunctions(!b); 47 } else { 48 throw new XPathFactoryConfigurationException("Unknown feature: " + feature); 49 } 50 } 51 52 59 60 public boolean getFeature(String feature) throws XPathFactoryConfigurationException { 61 if (feature.equals(XMLConstants.FEATURE_SECURE_PROCESSING)) { 62 return !config.isAllowExternalFunctions(); 63 } else { 64 throw new XPathFactoryConfigurationException("Unknown feature: " + feature); 65 } 66 } 67 68 75 public void setXPathVariableResolver(XPathVariableResolver xPathVariableResolver) { 76 variableResolver = xPathVariableResolver; 77 } 78 79 86 87 public void setXPathFunctionResolver(XPathFunctionResolver xPathFunctionResolver) { 88 functionResolver = xPathFunctionResolver; 89 } 90 91 95 public XPath newXPath() { 96 XPathEvaluator xpath = new XPathEvaluator(config); 97 xpath.setXPathFunctionResolver(functionResolver); 98 xpath.setXPathVariableResolver(variableResolver); 99 return xpath; 101 } 102 103 104 105 } 106 107 | Popular Tags |