Merge
This commit is contained in:
commit
e06c8dd069
jaxp
src/java.xml/share/classes
com/sun/org/apache
xerces/internal/dom
xml/internal/serialize
xpath/internal
javax/xml/xpath
module-info.javatest/javax/xml/jaxp/unittest/xpath
36
jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/dom/AbortException.java
Normal file
36
jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/dom/AbortException.java
Normal file
@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.org.apache.xerces.internal.dom;
|
||||
|
||||
public class AbortException extends RuntimeException {
|
||||
|
||||
private static final long serialVersionUID = 2608302175475740417L;
|
||||
|
||||
/**
|
||||
* Constructor AbortException
|
||||
*/
|
||||
public AbortException() { super(null, null, false, false); }
|
||||
}
|
@ -26,6 +26,7 @@ import java.util.ArrayList;
|
||||
import java.io.StringReader;
|
||||
import java.util.Vector;
|
||||
|
||||
import com.sun.org.apache.xerces.internal.dom.AbortException;
|
||||
import com.sun.org.apache.xerces.internal.impl.Constants;
|
||||
import com.sun.org.apache.xerces.internal.impl.RevalidationHandler;
|
||||
import com.sun.org.apache.xerces.internal.impl.dtd.DTDGrammar;
|
||||
@ -157,11 +158,6 @@ public class DOMNormalizer implements XMLDocumentHandler {
|
||||
// attribute value normalization
|
||||
final XMLString fNormalizedValue = new XMLString(new char[16], 0, 0);
|
||||
|
||||
/**
|
||||
* If the user stops the process, this exception will be thrown.
|
||||
*/
|
||||
public static final RuntimeException abort = new RuntimeException();
|
||||
|
||||
//DTD validator
|
||||
private XMLDTDValidator fDTDValidator;
|
||||
|
||||
@ -242,11 +238,8 @@ public class DOMNormalizer implements XMLDocumentHandler {
|
||||
XMLGrammarDescription.XML_SCHEMA, fValidationHandler);
|
||||
fValidationHandler = null;
|
||||
}
|
||||
}
|
||||
catch (RuntimeException e) {
|
||||
if( e==abort )
|
||||
return; // processing aborted by the user
|
||||
throw e; // otherwise re-throw.
|
||||
} catch (AbortException e) {
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
@ -1371,10 +1364,10 @@ public class DOMNormalizer implements XMLDocumentHandler {
|
||||
error.fRelatedData = locator.fRelatedNode;
|
||||
|
||||
if(!errorHandler.handleError(error))
|
||||
throw abort;
|
||||
throw new AbortException();
|
||||
}
|
||||
if( severity==DOMError.SEVERITY_FATAL_ERROR )
|
||||
throw abort;
|
||||
throw new AbortException();
|
||||
}
|
||||
|
||||
protected final void updateQName (Node node, QName qname){
|
||||
@ -2043,5 +2036,4 @@ public class DOMNormalizer implements XMLDocumentHandler {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
} // DOMNormalizer class
|
||||
|
@ -28,6 +28,7 @@ import java.io.Writer;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.sun.org.apache.xerces.internal.dom.AbortException;
|
||||
import com.sun.org.apache.xerces.internal.dom.CoreDocumentImpl;
|
||||
import com.sun.org.apache.xerces.internal.dom.DOMErrorImpl;
|
||||
import com.sun.org.apache.xerces.internal.dom.DOMLocatorImpl;
|
||||
@ -501,11 +502,9 @@ public class DOMSerializerImpl implements LSSerializer, DOMConfiguration {
|
||||
} catch (LSException lse) {
|
||||
// Rethrow LSException.
|
||||
throw lse;
|
||||
} catch (AbortException e) {
|
||||
return null;
|
||||
} catch (RuntimeException e) {
|
||||
if (e == DOMNormalizer.abort) {
|
||||
// stopped at user request
|
||||
return null;
|
||||
}
|
||||
throw (LSException) DOMUtil.createLSException(LSException.SERIALIZE_ERR, e).fillInStackTrace();
|
||||
} catch (IOException ioe) {
|
||||
// REVISIT: A generic IOException doesn't provide enough information
|
||||
@ -733,11 +732,9 @@ public class DOMSerializerImpl implements LSSerializer, DOMConfiguration {
|
||||
} catch (LSException lse) {
|
||||
// Rethrow LSException.
|
||||
throw lse;
|
||||
} catch (AbortException e) {
|
||||
return false;
|
||||
} catch (RuntimeException e) {
|
||||
if (e == DOMNormalizer.abort) {
|
||||
// stopped at user request
|
||||
return false;
|
||||
}
|
||||
throw (LSException) DOMUtil.createLSException(LSException.SERIALIZE_ERR, e).fillInStackTrace();
|
||||
} catch (Exception e) {
|
||||
if (ser.fDOMErrorHandler != null) {
|
||||
@ -833,11 +830,9 @@ public class DOMSerializerImpl implements LSSerializer, DOMConfiguration {
|
||||
} catch (LSException lse) {
|
||||
// Rethrow LSException.
|
||||
throw lse;
|
||||
} catch (AbortException e) {
|
||||
return false;
|
||||
} catch (RuntimeException e) {
|
||||
if (e == DOMNormalizer.abort) {
|
||||
// stopped at user request
|
||||
return false;
|
||||
}
|
||||
throw (LSException) DOMUtil.createLSException(LSException.SERIALIZE_ERR, e).fillInStackTrace();
|
||||
} catch (Exception e) {
|
||||
if (ser.fDOMErrorHandler != null) {
|
||||
|
@ -28,6 +28,7 @@ package com.sun.org.apache.xpath.internal.jaxp;
|
||||
import com.sun.org.apache.xalan.internal.res.XSLMessages;
|
||||
import com.sun.org.apache.xalan.internal.utils.FactoryImpl;
|
||||
import com.sun.org.apache.xml.internal.dtm.DTM;
|
||||
import com.sun.org.apache.xpath.internal.axes.LocPathIterator;
|
||||
import com.sun.org.apache.xpath.internal.objects.XObject;
|
||||
import com.sun.org.apache.xpath.internal.res.XPATHErrorResources;
|
||||
import java.io.IOException;
|
||||
@ -73,6 +74,12 @@ class XPathImplUtil {
|
||||
XObject eval(Object contextItem, com.sun.org.apache.xpath.internal.XPath xpath)
|
||||
throws javax.xml.transform.TransformerException {
|
||||
com.sun.org.apache.xpath.internal.XPathContext xpathSupport;
|
||||
if (contextItem == null && xpath.getExpression() instanceof LocPathIterator) {
|
||||
// the operation must have no dependency on the context that is null
|
||||
throw new TransformerException(XSLMessages.createXPATHMessage(
|
||||
XPATHErrorResources.ER_CONTEXT_CAN_NOT_BE_NULL,
|
||||
new Object[] {}));
|
||||
}
|
||||
if (functionResolver != null) {
|
||||
JAXPExtensionsProvider jep = new JAXPExtensionsProvider(
|
||||
functionResolver, featureSecureProcessing, featureManager);
|
||||
|
@ -93,6 +93,7 @@ public class XPATHErrorResources extends ListResourceBundle
|
||||
public static final String ER_CURRENT_TAKES_NO_ARGS =
|
||||
"ER_CURRENT_TAKES_NO_ARGS";
|
||||
public static final String ER_DOCUMENT_REPLACED = "ER_DOCUMENT_REPLACED";
|
||||
public static final String ER_CONTEXT_CAN_NOT_BE_NULL = "ER_CONTEXT_CAN_NOT_BE_NULL";
|
||||
public static final String ER_CONTEXT_HAS_NO_OWNERDOC =
|
||||
"ER_CONTEXT_HAS_NO_OWNERDOC";
|
||||
public static final String ER_LOCALNAME_HAS_TOO_MANY_ARGS =
|
||||
@ -368,6 +369,9 @@ public static final String ER_IGNORABLE_WHITESPACE_NOT_HANDLED =
|
||||
{ ER_DOCUMENT_REPLACED,
|
||||
"document() function implementation has been replaced by com.sun.org.apache.xalan.internal.xslt.FuncDocument!"},
|
||||
|
||||
{ ER_CONTEXT_CAN_NOT_BE_NULL,
|
||||
"The context can not be null when the operation is context-dependent."},
|
||||
|
||||
{ ER_CONTEXT_HAS_NO_OWNERDOC,
|
||||
"context does not have an owner document!"},
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -34,18 +34,20 @@ import org.xml.sax.InputSource;
|
||||
*
|
||||
* <a name="XPath-evaluation"></a>
|
||||
* <table border="1" cellpadding="2">
|
||||
* <thead>
|
||||
* <tr>
|
||||
* <th colspan="2">Evaluation of XPath Expressions.</th>
|
||||
* </tr>
|
||||
* </thead>
|
||||
* <tr>
|
||||
* <td>context</td>
|
||||
* <td>
|
||||
* If a request is made to evaluate the expression in the absence
|
||||
* of a context item, an empty document node will be used for the context.
|
||||
* For the purposes of evaluating XPath expressions, a DocumentFragment
|
||||
* is treated like a Document node.
|
||||
* <thead>
|
||||
* <tr>
|
||||
* <th colspan="2">Evaluation of XPath Expressions.</th>
|
||||
* </tr>
|
||||
* </thead>
|
||||
* <tr>
|
||||
* <td>context</td>
|
||||
* <td>
|
||||
* The type of the context is implementation-dependent. If the value is
|
||||
* null, the operation must have no dependency on the context, otherwise
|
||||
* an XPathExpressionException will be thrown.
|
||||
*
|
||||
* For the purposes of evaluating XPath expressions, a DocumentFragment
|
||||
* is treated like a Document node.
|
||||
* </td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -33,19 +33,20 @@ import org.xml.sax.InputSource;
|
||||
*
|
||||
* <a name="XPathExpression-evaluation"></a>
|
||||
* <table border="1" cellpadding="2">
|
||||
* <thead>
|
||||
* <tr>
|
||||
* <th colspan="2">Evaluation of XPath Expressions.</th>
|
||||
* </tr>
|
||||
* </thead>
|
||||
* <tbody>
|
||||
* <tr>
|
||||
* <td>context</td>
|
||||
* <td>
|
||||
* If a request is made to evaluate the expression in the absence
|
||||
* of a context item, an empty document node will be used for the context.
|
||||
* For the purposes of evaluating XPath expressions, a DocumentFragment
|
||||
* is treated like a Document node.
|
||||
* <thead>
|
||||
* <tr>
|
||||
* <th colspan="2">Evaluation of XPath Expressions.</th>
|
||||
* </tr>
|
||||
* </thead>
|
||||
* <tr>
|
||||
* <td>context</td>
|
||||
* <td>
|
||||
* The type of the context is implementation-dependent. If the value is
|
||||
* null, the operation must have no dependency on the context, otherwise
|
||||
* an XPathExpressionException will be thrown.
|
||||
*
|
||||
* For the purposes of evaluating XPath expressions, a DocumentFragment
|
||||
* is treated like a Document node.
|
||||
* </td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
|
@ -23,6 +23,10 @@
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Defines the Java API for XML Processing (JAXP), the Streaming API for XML (StAX),
|
||||
* the Simple API for XML (SAX), and the W3C Document Object Model (DOM) API.
|
||||
*/
|
||||
module java.xml {
|
||||
exports javax.xml;
|
||||
exports javax.xml.catalog;
|
||||
|
@ -24,11 +24,17 @@
|
||||
package xpath;
|
||||
|
||||
import javax.xml.namespace.NamespaceContext;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import javax.xml.xpath.XPath;
|
||||
import javax.xml.xpath.XPathConstants;
|
||||
import javax.xml.xpath.XPathExpressionException;
|
||||
import javax.xml.xpath.XPathFactory;
|
||||
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Listeners;
|
||||
import org.testng.annotations.Test;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Node;
|
||||
|
||||
/*
|
||||
* @test
|
||||
@ -36,19 +42,105 @@ import org.testng.annotations.Test;
|
||||
* @library /javax/xml/jaxp/libs /javax/xml/jaxp/unittest
|
||||
* @run testng/othervm -DrunSecMngr=true xpath.XPathTest
|
||||
* @run testng/othervm xpath.XPathTest
|
||||
* @summary Test XPath.getNamespaceContext() is supported.
|
||||
* @summary Test XPath functions. See details for each test.
|
||||
*/
|
||||
@Listeners({jaxp.library.BasePolicy.class})
|
||||
public class XPathTest {
|
||||
|
||||
/*
|
||||
@bug 6211561
|
||||
* Verifies the specification for XPath and XPathExpression:
|
||||
* If a null value is provided for item (the context),
|
||||
* the expression must have no dependency on the context.
|
||||
*/
|
||||
@Test(dataProvider = "noContextDependency")
|
||||
public void testNoContextDependency1(String expression, Object item) throws XPathExpressionException {
|
||||
XPath xPath = XPathFactory.newInstance().newXPath();
|
||||
xPath.evaluate(expression, item, XPathConstants.STRING);
|
||||
}
|
||||
|
||||
@Test(dataProvider = "noContextDependency")
|
||||
public void testNoContextDependency2(String expression, Object item) throws XPathExpressionException {
|
||||
XPath xPath = XPathFactory.newInstance().newXPath();
|
||||
xPath.evaluateExpression(expression, item, String.class);
|
||||
}
|
||||
|
||||
/*
|
||||
@bug 6211561
|
||||
* Verifies the specification for XPath and XPathExpression:
|
||||
* If a null value is provided for item (the context) that the operation
|
||||
* depends on, XPathExpressionException will be thrown
|
||||
*/
|
||||
@Test(dataProvider = "hasContextDependency", expectedExceptions = XPathExpressionException.class)
|
||||
public void testHasContextDependency1(String expression, Object item) throws XPathExpressionException {
|
||||
XPath xPath = XPathFactory.newInstance().newXPath();
|
||||
xPath.evaluate(expression, item, XPathConstants.STRING);
|
||||
}
|
||||
|
||||
@Test(dataProvider = "hasContextDependency", expectedExceptions = XPathExpressionException.class)
|
||||
public void testHasContextDependency2(String expression, Object item) throws XPathExpressionException {
|
||||
XPath xPath = XPathFactory.newInstance().newXPath();
|
||||
xPath.evaluateExpression(expression, item, String.class);
|
||||
}
|
||||
|
||||
/*
|
||||
@bug 6376058
|
||||
Verifies that XPath.getNamespaceContext() is supported.
|
||||
*/
|
||||
@Test
|
||||
public void testNamespaceContext() {
|
||||
|
||||
XPathFactory xPathFactory = XPathFactory.newInstance();
|
||||
XPath xPath = xPathFactory.newXPath();
|
||||
|
||||
NamespaceContext namespaceContext = xPath.getNamespaceContext();
|
||||
}
|
||||
|
||||
/*
|
||||
* DataProvider: the expression has no dependency on the context
|
||||
*/
|
||||
@DataProvider(name = "noContextDependency")
|
||||
public Object[][] getExpressionContext() throws Exception {
|
||||
return new Object[][]{
|
||||
{"1+1", (Node)null},
|
||||
{"5 mod 2", (Node)null},
|
||||
{"8 div 2", (Node)null},
|
||||
{"/node", getEmptyDocument()}
|
||||
};
|
||||
}
|
||||
|
||||
/*
|
||||
* DataProvider: the expression has dependency on the context, but the context
|
||||
* is null.
|
||||
*/
|
||||
@DataProvider(name = "hasContextDependency")
|
||||
public Object[][] getExpressionContext1() throws Exception {
|
||||
return new Object[][]{
|
||||
{"/node", (Node)null},
|
||||
{"//@lang", (Node)null},
|
||||
{"bookstore//book", (Node)null},
|
||||
{"/bookstore/book[last()]", (Node)null},
|
||||
{"//title[@lang='en']", (Node)null},
|
||||
{"/bookstore/book[price>9.99]", (Node)null},
|
||||
{"/bookstore/book[price>8.99 and price<9.99]", (Node)null},
|
||||
{"/bookstore/*", (Node)null},
|
||||
{"//title[@*]", (Node)null},
|
||||
{"//title | //price", (Node)null},
|
||||
{"//book/title | //book/price", (Node)null},
|
||||
{"/bookstore/book/title | //price", (Node)null},
|
||||
{"child::book", (Node)null},
|
||||
{"child::text()", (Node)null},
|
||||
{"child::*/child::price", (Node)null}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an empty {@link org.w3c.dom.Document}.
|
||||
* @return a DOM Document, null in case of Exception
|
||||
*/
|
||||
public Document getEmptyDocument() {
|
||||
try {
|
||||
return DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
|
||||
} catch (ParserConfigurationException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user