19f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson/* 29f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Licensed to the Apache Software Foundation (ASF) under one 39f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * or more contributor license agreements. See the NOTICE file 49f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * distributed with this work for additional information 59f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * regarding copyright ownership. The ASF licenses this file 69f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * to you under the Apache License, Version 2.0 (the "License"); 79f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * you may not use this file except in compliance with the License. 89f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * You may obtain a copy of the License at 99f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * http://www.apache.org/licenses/LICENSE-2.0 119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Unless required by applicable law or agreed to in writing, software 139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * distributed under the License is distributed on an "AS IS" BASIS, 149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * See the License for the specific language governing permissions and 169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * limitations under the License. 179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson// $Id: XPathExpressionImpl.java 524813 2007-04-02 15:52:07Z zongaro $ 199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonpackage org.apache.xpath.jaxp; 219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xpath.*; 239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport javax.xml.transform.TransformerException; 249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xpath.objects.XObject; 269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xml.utils.PrefixResolver; 279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xpath.res.XPATHErrorResources; 289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xalan.res.XSLMessages; 299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport javax.xml.namespace.NamespaceContext; 319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport javax.xml.namespace.QName; 329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport javax.xml.xpath.XPathExpressionException; 339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport javax.xml.xpath.XPathConstants; 349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport javax.xml.xpath.XPathFunctionResolver; 359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport javax.xml.xpath.XPathVariableResolver; 369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport javax.xml.xpath.XPathConstants; 379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.w3c.dom.Node; 399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.w3c.dom.Document; 409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.w3c.dom.DOMImplementation; 419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.w3c.dom.traversal.NodeIterator; 429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport javax.xml.parsers.DocumentBuilderFactory; 439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport javax.xml.parsers.DocumentBuilder; 449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.xml.sax.InputSource; 469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson/** 489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * The XPathExpression interface encapsulates a (compiled) XPath expression. 499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @version $Revision: 524813 $ 519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @author Ramesh Mandava 529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonpublic class XPathExpressionImpl implements javax.xml.xpath.XPathExpression{ 549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson private XPathFunctionResolver functionResolver; 569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson private XPathVariableResolver variableResolver; 579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson private JAXPPrefixResolver prefixResolver; 589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson private org.apache.xpath.XPath xpath; 599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // By default Extension Functions are allowed in XPath Expressions. If 619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // Secure Processing Feature is set on XPathFactory then the invocation of 629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // extensions function need to throw XPathFunctionException 639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson private boolean featureSecureProcessing = false; 649f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 659f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** Protected constructor to prevent direct instantiation; use compile() 669f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * from the context. 679f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 689f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson protected XPathExpressionImpl() { }; 699f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 709f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson protected XPathExpressionImpl(org.apache.xpath.XPath xpath, 719f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson JAXPPrefixResolver prefixResolver, 729f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson XPathFunctionResolver functionResolver, 739f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson XPathVariableResolver variableResolver ) { 749f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson this.xpath = xpath; 759f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson this.prefixResolver = prefixResolver; 769f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson this.functionResolver = functionResolver; 779f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson this.variableResolver = variableResolver; 789f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson this.featureSecureProcessing = false; 799f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson }; 809f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 819f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson protected XPathExpressionImpl(org.apache.xpath.XPath xpath, 829f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson JAXPPrefixResolver prefixResolver, 839f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson XPathFunctionResolver functionResolver, 849f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson XPathVariableResolver variableResolver, 859f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson boolean featureSecureProcessing ) { 869f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson this.xpath = xpath; 879f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson this.prefixResolver = prefixResolver; 889f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson this.functionResolver = functionResolver; 899f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson this.variableResolver = variableResolver; 909f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson this.featureSecureProcessing = featureSecureProcessing; 919f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson }; 929f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 939f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public void setXPath (org.apache.xpath.XPath xpath ) { 949f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson this.xpath = xpath; 959f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 969f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 979f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public Object eval(Object item, QName returnType) 989f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson throws javax.xml.transform.TransformerException { 999f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson XObject resultObject = eval ( item ); 1009f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return getResultAsType( resultObject, returnType ); 1019f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 1029f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1039f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson private XObject eval ( Object contextItem ) 1049f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson throws javax.xml.transform.TransformerException { 1059f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson org.apache.xpath.XPathContext xpathSupport = null; 1069f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1079f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // Create an XPathContext that doesn't support pushing and popping of 1089f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // variable resolution scopes. Sufficient for simple XPath 1.0 1099f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // expressions. 1109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if ( functionResolver != null ) { 1119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson JAXPExtensionsProvider jep = new JAXPExtensionsProvider( 1129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson functionResolver, featureSecureProcessing ); 1139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson xpathSupport = new org.apache.xpath.XPathContext(jep, false); 1149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } else { 1159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson xpathSupport = new org.apache.xpath.XPathContext(false); 1169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 1179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson xpathSupport.setVarStack(new JAXPVariableStack(variableResolver)); 1199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson XObject xobj = null; 1209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson Node contextNode = (Node)contextItem; 1229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // We always need to have a ContextNode with Xalan XPath implementation 1239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // To allow simple expression evaluation like 1+1 we are setting 1249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // dummy Document as Context Node 1259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if ( contextNode == null ) { 1269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson contextNode = getDummyDocument(); 1279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 1289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson xobj = xpath.execute(xpathSupport, contextNode, prefixResolver ); 1309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return xobj; 1319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 1329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 1359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <p>Evaluate the compiled XPath expression in the specified context and 1369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * return the result as the specified type.</p> 1379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 1389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <p>See "Evaluation of XPath Expressions" section of JAXP 1.3 spec 1399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * for context item evaluation, 1409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * variable, function and QName resolution and return type conversion.</p> 1419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 1429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <p>If <code>returnType</code> is not one of the types defined 1439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * in {@link XPathConstants}, 1449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * then an <code>IllegalArgumentException</code> is thrown.</p> 1459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 1469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <p>If a <code>null</code> value is provided for 1479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <code>item</code>, an empty document will be used for the 1489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * context. 1499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * If <code>returnType</code> is <code>null</code>, then a 1509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <code>NullPointerException</code> is thrown.</p> 1519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 1529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param item The starting context (node or node list, for example). 1539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param returnType The desired return type. 1549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 1559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return The <code>Object</code> that is the result of evaluating the 1569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * expression and converting the result to 1579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <code>returnType</code>. 1589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 1599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @throws XPathExpressionException If the expression cannot be evaluated. 1609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @throws IllegalArgumentException If <code>returnType</code> is not one 1619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * of the types defined in {@link XPathConstants}. 1629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @throws NullPointerException If <code>returnType</code> is 1639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <code>null</code>. 1649f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 1659f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public Object evaluate(Object item, QName returnType) 1669f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson throws XPathExpressionException { 1679f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson //Validating parameters to enforce constraints defined by JAXP spec 1689f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if ( returnType == null ) { 1699f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson //Throwing NullPointerException as defined in spec 1709f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson String fmsg = XSLMessages.createXPATHMessage( 1719f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson XPATHErrorResources.ER_ARG_CANNOT_BE_NULL, 1729f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson new Object[] {"returnType"} ); 1739f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson throw new NullPointerException( fmsg ); 1749f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 1759f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // Checking if requested returnType is supported. returnType need to be 1769f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // defined in XPathConstants 1779f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if ( !isSupported ( returnType ) ) { 1789f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson String fmsg = XSLMessages.createXPATHMessage( 1799f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson XPATHErrorResources.ER_UNSUPPORTED_RETURN_TYPE, 1809f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson new Object[] { returnType.toString() } ); 1819f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson throw new IllegalArgumentException ( fmsg ); 1829f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 1839f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson try { 1849f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return eval( item, returnType); 1859f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } catch ( java.lang.NullPointerException npe ) { 1869f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // If VariableResolver returns null Or if we get 1879f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // NullPointerException at this stage for some other reason 1889f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // then we have to reurn XPathException 1899f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson throw new XPathExpressionException ( npe ); 1909f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } catch ( javax.xml.transform.TransformerException te ) { 1919f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson Throwable nestedException = te.getException(); 1929f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if ( nestedException instanceof javax.xml.xpath.XPathFunctionException ) { 1939f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson throw (javax.xml.xpath.XPathFunctionException)nestedException; 1949f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } else { 1959f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // For any other exceptions we need to throw 1969f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // XPathExpressionException ( as per spec ) 1979f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson throw new XPathExpressionException( te); 1989f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 1999f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 2009f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2019f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 2029f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2039f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 2049f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <p>Evaluate the compiled XPath expression in the specified context and 2059f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * return the result as a <code>String</code>.</p> 2069f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 2079f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <p>This method calls {@link #evaluate(Object item, QName returnType)} 2089f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * with a <code>returnType</code> of 2099f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * {@link XPathConstants#STRING}.</p> 2109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 2119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <p>See "Evaluation of XPath Expressions" section of JAXP 1.3 spec 2129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * for context item evaluation, 2139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * variable, function and QName resolution and return type conversion.</p> 2149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 2159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <p>If a <code>null</code> value is provided for 2169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <code>item</code>, an empty document will be used for the 2179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * context. 2189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 2199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param item The starting context (node or node list, for example). 2209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 2219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return The <code>String</code> that is the result of evaluating the 2229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * expression and converting the result to a 2239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <code>String</code>. 2249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 2259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @throws XPathExpressionException If the expression cannot be evaluated. 2269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 2279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public String evaluate(Object item) 2289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson throws XPathExpressionException { 2299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return (String)this.evaluate( item, XPathConstants.STRING ); 2309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 2319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson static DocumentBuilderFactory dbf = null; 2359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson static DocumentBuilder db = null; 2369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson static Document d = null; 2379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 2399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <p>Evaluate the compiled XPath expression in the context of the 2409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * specified <code>InputSource</code> and return the result as the 2419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * specified type.</p> 2429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 2439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <p>This method builds a data model for the {@link InputSource} and calls 2449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * {@link #evaluate(Object item, QName returnType)} on the resulting 2459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * document object.</p> 2469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 2479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <p>See "Evaluation of XPath Expressions" section of JAXP 1.3 spec 2489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * for context item evaluation, 2499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * variable, function and QName resolution and return type conversion.</p> 2509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 2519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <p>If <code>returnType</code> is not one of the types defined in 2529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * {@link XPathConstants}, 2539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * then an <code>IllegalArgumentException</code> is thrown.</p> 2549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 2559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson *<p>If <code>source</code> or <code>returnType</code> is <code>null</code>, 2569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * then a <code>NullPointerException</code> is thrown.</p> 2579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 2589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param source The <code>InputSource</code> of the document to evaluate 2599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * over. 2609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param returnType The desired return type. 2619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 2629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return The <code>Object</code> that is the result of evaluating the 2639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * expression and converting the result to 2649f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <code>returnType</code>. 2659f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 2669f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @throws XPathExpressionException If the expression cannot be evaluated. 2679f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @throws IllegalArgumentException If <code>returnType</code> is not one 2689f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * of the types defined in {@link XPathConstants}. 2699f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @throws NullPointerException If <code>source</code> or 2709f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <code>returnType</code> is <code>null</code>. 2719f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 2729f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public Object evaluate(InputSource source, QName returnType) 2739f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson throws XPathExpressionException { 2749f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if ( ( source == null ) || ( returnType == null ) ) { 2759f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson String fmsg = XSLMessages.createXPATHMessage( 2769f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson XPATHErrorResources.ER_SOURCE_RETURN_TYPE_CANNOT_BE_NULL, 2779f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson null ); 2789f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson throw new NullPointerException ( fmsg ); 2799f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 2809f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // Checking if requested returnType is supported. returnType need to be 2819f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // defined in XPathConstants 2829f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if ( !isSupported ( returnType ) ) { 2839f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson String fmsg = XSLMessages.createXPATHMessage( 2849f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson XPATHErrorResources.ER_UNSUPPORTED_RETURN_TYPE, 2859f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson new Object[] { returnType.toString() } ); 2869f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson throw new IllegalArgumentException ( fmsg ); 2879f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 2889f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson try { 2899f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if ( dbf == null ) { 2909f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson dbf = DocumentBuilderFactory.newInstance(); 2919f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson dbf.setNamespaceAware( true ); 2929f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson dbf.setValidating( false ); 2939f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 2949f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson db = dbf.newDocumentBuilder(); 2959f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson Document document = db.parse( source ); 2969f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return eval( document, returnType ); 2979f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } catch ( Exception e ) { 2989f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson throw new XPathExpressionException ( e ); 2999f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 3009f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 3019f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 3029f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 3039f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <p>Evaluate the compiled XPath expression in the context of the specified <code>InputSource</code> and return the result as a 3049f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <code>String</code>.</p> 3059f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 3069f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <p>This method calls {@link #evaluate(InputSource source, QName returnType)} with a <code>returnType</code> of 3079f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * {@link XPathConstants#STRING}.</p> 3089f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 3099f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <p>See "Evaluation of XPath Expressions" section of JAXP 1.3 spec 3109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * for context item evaluation, 3119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * variable, function and QName resolution and return type conversion.</p> 3129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 3139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <p>If <code>source</code> is <code>null</code>, then a <code>NullPointerException</code> is thrown.</p> 3149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 3159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param source The <code>InputSource</code> of the document to evaluate over. 3169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 3179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return The <code>String</code> that is the result of evaluating the expression and converting the result to a 3189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <code>String</code>. 3199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 3209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @throws XPathExpressionException If the expression cannot be evaluated. 3219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @throws NullPointerException If <code>source</code> is <code>null</code>. 3229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 3239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public String evaluate(InputSource source) 3249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson throws XPathExpressionException { 3259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return (String)this.evaluate( source, XPathConstants.STRING ); 3269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 3279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 3289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson private boolean isSupported( QName returnType ) { 3299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // XPathConstants.STRING 3309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if ( ( returnType.equals( XPathConstants.STRING ) ) || 3319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson ( returnType.equals( XPathConstants.NUMBER ) ) || 3329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson ( returnType.equals( XPathConstants.BOOLEAN ) ) || 3339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson ( returnType.equals( XPathConstants.NODE ) ) || 3349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson ( returnType.equals( XPathConstants.NODESET ) ) ) { 3359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 3369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return true; 3379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 3389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return false; 3399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 3409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 3419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson private Object getResultAsType( XObject resultObject, QName returnType ) 3429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson throws javax.xml.transform.TransformerException { 3439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // XPathConstants.STRING 3449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if ( returnType.equals( XPathConstants.STRING ) ) { 3459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return resultObject.str(); 3469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 3479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // XPathConstants.NUMBER 3489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if ( returnType.equals( XPathConstants.NUMBER ) ) { 3499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return new Double ( resultObject.num()); 3509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 3519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // XPathConstants.BOOLEAN 3529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if ( returnType.equals( XPathConstants.BOOLEAN ) ) { 3539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return new Boolean( resultObject.bool()); 3549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 3559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // XPathConstants.NODESET ---ORdered, UNOrdered??? 3569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if ( returnType.equals( XPathConstants.NODESET ) ) { 3579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return resultObject.nodelist(); 3589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 3599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // XPathConstants.NODE 3609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if ( returnType.equals( XPathConstants.NODE ) ) { 3619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson NodeIterator ni = resultObject.nodeset(); 3629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson //Return the first node, or null 3639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return ni.nextNode(); 3649f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 3659f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // If isSupported check is already done then the execution path 3669f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // shouldn't come here. Being defensive 3679f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson String fmsg = XSLMessages.createXPATHMessage( 3689f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson XPATHErrorResources.ER_UNSUPPORTED_RETURN_TYPE, 3699f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson new Object[] { returnType.toString()}); 3709f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson throw new IllegalArgumentException ( fmsg ); 3719f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 3729f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 3739f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 3749f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson private static Document getDummyDocument( ) { 3759f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson try { 3769f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if ( dbf == null ) { 3779f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson dbf = DocumentBuilderFactory.newInstance(); 3789f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson dbf.setNamespaceAware( true ); 3799f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson dbf.setValidating( false ); 3809f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 3819f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson db = dbf.newDocumentBuilder(); 3829f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 3839f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson DOMImplementation dim = db.getDOMImplementation(); 3849f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson d = dim.createDocument("http://java.sun.com/jaxp/xpath", 3859f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson "dummyroot", null); 3869f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return d; 3879f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } catch ( Exception e ) { 3889f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson e.printStackTrace(); 3899f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 3909f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return null; 3919f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 3929f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 3939f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 3949f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 3959f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 3969f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson} 397