X-Git-Url: http://wamblee.org/gitweb/?a=blobdiff_plain;f=support%2Fgeneral%2Fsrc%2Fmain%2Fjava%2Forg%2Fwamblee%2Fxml%2FXPathContext.java;fp=support%2Fgeneral%2Fsrc%2Fmain%2Fjava%2Forg%2Fwamblee%2Fxml%2FXPathContext.java;h=42fa99d436acd95c98864fbde859e808eb87a191;hb=02d312f6ce5642cbb4fa6c883e0ece2b30c1f029;hp=0000000000000000000000000000000000000000;hpb=3205980513232d44b49681aced7cd7f124a4d1a0;p=utils diff --git a/support/general/src/main/java/org/wamblee/xml/XPathContext.java b/support/general/src/main/java/org/wamblee/xml/XPathContext.java new file mode 100644 index 00000000..42fa99d4 --- /dev/null +++ b/support/general/src/main/java/org/wamblee/xml/XPathContext.java @@ -0,0 +1,59 @@ +/* + * Copyright 2005-2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.wamblee.xml; + +import javax.xml.namespace.NamespaceContext; +import javax.xml.xpath.XPath; +import javax.xml.xpath.XPathFactory; + +/** + * Represents a namespace context and is a factory for creating xpath expressions. + * @author Erik Brakkee + */ +public class XPathContext { + private XPath xpath; + + /** + * Constructs the context. + * @param aContext Namespaces. + */ + public XPathContext(NamespaceContext aContext) { + xpath = XPathFactory.newInstance().newXPath(); + xpath.setNamespaceContext(aContext); + } + + public static XPathContext xpathcontext(NamespaceContext aContext) { + return new XPathContext(aContext); + } + + /** + * Creates the expression. + * @param aExpression XPath expression. + * @return Xpath expression. + * @throws XMLException + */ + public XPathExpression createExpression(String aExpression) throws XMLException { + return new XPathExpression(xpath, aExpression); + } + + /** + * To get access to the lower level API. + * @return Lower level API. + */ + public XPath getXpath() { + return xpath; + } +}