This commit is contained in:
Lana Steuck 2016-09-22 18:32:15 +00:00
commit d664e7b6c2
7 changed files with 46 additions and 55 deletions

View File

@ -1033,12 +1033,12 @@ public class XMLEntityManager implements XMLComponent, XMLEntityResolver {
staxInputSource = new StaxXMLInputSource(xmlInputSource, fISCreatedByResolver); staxInputSource = new StaxXMLInputSource(xmlInputSource, fISCreatedByResolver);
} }
if (staxInputSource == null) { if (staxInputSource == null && fUseCatalog) {
if (fCatalogFeatures == null) { if (fCatalogFeatures == null) {
fCatalogFeatures = JdkXmlUtils.getCatalogFeatures(fDefer, fCatalogFile, fPrefer, fResolve); fCatalogFeatures = JdkXmlUtils.getCatalogFeatures(fDefer, fCatalogFile, fPrefer, fResolve);
} }
fCatalogFile = fCatalogFeatures.get(Feature.FILES); fCatalogFile = fCatalogFeatures.get(Feature.FILES);
if (fUseCatalog && fCatalogFile != null) { if (fCatalogFile != null) {
try { try {
if (fCatalogResolver == null) { if (fCatalogResolver == null) {
fCatalogResolver = CatalogManager.catalogResolver(fCatalogFeatures); fCatalogResolver = CatalogManager.catalogResolver(fCatalogFeatures);
@ -1133,12 +1133,12 @@ public class XMLEntityManager implements XMLComponent, XMLEntityResolver {
xmlInputSource = fEntityResolver.resolveEntity(resourceIdentifier); xmlInputSource = fEntityResolver.resolveEntity(resourceIdentifier);
} }
if (xmlInputSource == null) { if (xmlInputSource == null && fUseCatalog) {
if (fCatalogFeatures == null) { if (fCatalogFeatures == null) {
fCatalogFeatures = JdkXmlUtils.getCatalogFeatures(fDefer, fCatalogFile, fPrefer, fResolve); fCatalogFeatures = JdkXmlUtils.getCatalogFeatures(fDefer, fCatalogFile, fPrefer, fResolve);
} }
fCatalogFile = fCatalogFeatures.get(Feature.FILES); fCatalogFile = fCatalogFeatures.get(Feature.FILES);
if (fUseCatalog && fCatalogFile != null) { if (fCatalogFile != null) {
/* /*
since the method can be called from various processors, both since the method can be called from various processors, both
EntityResolver and URIResolver are used to attempt to find EntityResolver and URIResolver are used to attempt to find

View File

@ -34,6 +34,8 @@ import com.sun.org.apache.xerces.internal.impl.XMLEntityManager;
import com.sun.org.apache.xerces.internal.impl.XMLErrorReporter; import com.sun.org.apache.xerces.internal.impl.XMLErrorReporter;
import com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException; import com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException;
import com.sun.org.apache.xerces.internal.impl.msg.XMLMessageFormatter; import com.sun.org.apache.xerces.internal.impl.msg.XMLMessageFormatter;
import com.sun.org.apache.xerces.internal.parsers.XIncludeParserConfiguration;
import com.sun.org.apache.xerces.internal.parsers.XPointerParserConfiguration;
import com.sun.org.apache.xerces.internal.util.AugmentationsImpl; import com.sun.org.apache.xerces.internal.util.AugmentationsImpl;
import com.sun.org.apache.xerces.internal.util.HTTPInputSource; import com.sun.org.apache.xerces.internal.util.HTTPInputSource;
import com.sun.org.apache.xerces.internal.util.IntStack; import com.sun.org.apache.xerces.internal.util.IntStack;
@ -129,8 +131,6 @@ import org.xml.sax.InputSource;
public class XIncludeHandler public class XIncludeHandler
implements XMLComponent, XMLDocumentFilter, XMLDTDFilter { implements XMLComponent, XMLDocumentFilter, XMLDTDFilter {
public final static String XINCLUDE_DEFAULT_CONFIGURATION =
"com.sun.org.apache.xerces.internal.parsers.XIncludeParserConfiguration";
public final static String HTTP_ACCEPT = "Accept"; public final static String HTTP_ACCEPT = "Accept";
public final static String HTTP_ACCEPT_LANGUAGE = "Accept-Language"; public final static String HTTP_ACCEPT_LANGUAGE = "Accept-Language";
public final static String XPOINTER = "xpointer"; public final static String XPOINTER = "xpointer";
@ -1624,12 +1624,12 @@ public class XIncludeHandler
includedSource = includedSource =
fEntityResolver.resolveEntity(resourceIdentifier); fEntityResolver.resolveEntity(resourceIdentifier);
if (includedSource == null) { if (includedSource == null && fUseCatalog) {
if (fCatalogFeatures == null) { if (fCatalogFeatures == null) {
fCatalogFeatures = JdkXmlUtils.getCatalogFeatures(fDefer, fCatalogFile, fPrefer, fResolve); fCatalogFeatures = JdkXmlUtils.getCatalogFeatures(fDefer, fCatalogFile, fPrefer, fResolve);
} }
fCatalogFile = fCatalogFeatures.get(CatalogFeatures.Feature.FILES); fCatalogFile = fCatalogFeatures.get(CatalogFeatures.Feature.FILES);
if (fUseCatalog && fCatalogFile != null) { if (fCatalogFile != null) {
/* /*
Although URI entry is preferred for resolving XInclude, system entry Although URI entry is preferred for resolving XInclude, system entry
is allowed as well. is allowed as well.
@ -1690,14 +1690,11 @@ public class XIncludeHandler
if ((xpointer != null && fXPointerChildConfig == null) if ((xpointer != null && fXPointerChildConfig == null)
|| (xpointer == null && fXIncludeChildConfig == null) ) { || (xpointer == null && fXIncludeChildConfig == null) ) {
String parserName = XINCLUDE_DEFAULT_CONFIGURATION; if (xpointer == null) {
if (xpointer != null) fChildConfig = new XIncludeParserConfiguration();
parserName = "com.sun.org.apache.xerces.internal.parsers.XPointerParserConfiguration"; } else {
fChildConfig = new XPointerParserConfiguration();
fChildConfig = }
(XMLParserConfiguration)ObjectFactory.newInstance(
parserName,
true);
// use the same symbol table, error reporter, entity resolver, security manager and buffer size. // use the same symbol table, error reporter, entity resolver, security manager and buffer size.
if (fSymbolTable != null) fChildConfig.setProperty(SYMBOL_TABLE, fSymbolTable); if (fSymbolTable != null) fChildConfig.setProperty(SYMBOL_TABLE, fSymbolTable);

View File

@ -32,7 +32,6 @@ import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.sax.SAXSource; import javax.xml.transform.sax.SAXSource;
import javax.xml.transform.stax.StAXSource; import javax.xml.transform.stax.StAXSource;
import javax.xml.transform.stream.StreamSource; import javax.xml.transform.stream.StreamSource;
import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider; import org.testng.annotations.DataProvider;
import org.testng.annotations.Listeners; import org.testng.annotations.Listeners;
@ -42,7 +41,7 @@ import org.xml.sax.InputSource;
/** /**
* @test * @test
* @bug 8158084 8162438 8162442 8166220 * @bug 8158084 8162438 8162442 8166220 8166398
* @library /javax/xml/jaxp/libs /javax/xml/jaxp/unittest * @library /javax/xml/jaxp/libs /javax/xml/jaxp/unittest
* @run testng/othervm -DrunSecMngr=true catalog.CatalogSupport * @run testng/othervm -DrunSecMngr=true catalog.CatalogSupport
* @run testng/othervm catalog.CatalogSupport * @run testng/othervm catalog.CatalogSupport
@ -51,7 +50,7 @@ import org.xml.sax.InputSource;
* A custom resolver is used whether or not there's a Catalog; * A custom resolver is used whether or not there's a Catalog;
* A Catalog is used when there's no custom resolver, and the USE_CATALOG * A Catalog is used when there's no custom resolver, and the USE_CATALOG
* is true (which is the case by default). * is true (which is the case by default).
*/ */
/** /**
* Support Catalog: * Support Catalog:
@ -177,13 +176,13 @@ public class CatalogSupport extends CatalogSupportBase {
*/ */
@DataProvider(name = "data_SAXA") @DataProvider(name = "data_SAXA")
public Object[][] getDataSAX() { public Object[][] getDataSAX() {
String[] systemIds = {"system.xsd"}; String[] systemIds = {"system.dtd"};
InputSource[] returnValues = {new InputSource(new StringReader(dtd_systemResolved))};
MyEntityHandler entityHandler = new MyEntityHandler(systemIds, returnValues, elementInSystem);
return new Object[][]{ return new Object[][]{
{false, true, xml_catalog, xml_system, new MyHandler(elementInSystem), expectedWCatalog}, {false, true, xml_catalog, xml_system, new MyHandler(elementInSystem), expectedWCatalog},
{false, true, xml_catalog, xml_system, entityHandler, expectedWResolver}, {false, true, xml_catalog, xml_system, getMyEntityHandler(elementInSystem, systemIds,
{true, true, xml_catalog, xml_system, entityHandler, expectedWResolver} new InputSource(new StringReader(dtd_systemResolved))), expectedWResolver},
{true, true, xml_catalog, xml_system, getMyEntityHandler(elementInSystem, systemIds,
new InputSource(new StringReader(dtd_systemResolved))), expectedWResolver}
}; };
} }
@ -209,7 +208,7 @@ public class CatalogSupport extends CatalogSupportBase {
*/ */
@DataProvider(name = "data_DOMA") @DataProvider(name = "data_DOMA")
public Object[][] getDataDOM() { public Object[][] getDataDOM() {
String[] systemIds = {"system.xsd"}; String[] systemIds = {"system.dtd"};
InputSource[] returnValues = {new InputSource(new StringReader(dtd_systemResolved))}; InputSource[] returnValues = {new InputSource(new StringReader(dtd_systemResolved))};
MyEntityHandler entityHandler = new MyEntityHandler(systemIds, returnValues, elementInSystem); MyEntityHandler entityHandler = new MyEntityHandler(systemIds, returnValues, elementInSystem);
return new Object[][]{ return new Object[][]{
@ -230,8 +229,8 @@ public class CatalogSupport extends CatalogSupportBase {
return new Object[][]{ return new Object[][]{
{false, true, xml_catalog, xml_system, null, expectedWCatalog}, {false, true, xml_catalog, xml_system, null, expectedWCatalog},
{false, true, xml_catalog, xml_system, null, expectedWResolver}, {false, true, xml_catalog, xml_system, new MyStaxEntityResolver(), expectedWResolver},
{true, true, xml_catalog, xml_system, null, expectedWResolver} {true, true, xml_catalog, xml_system, new MyStaxEntityResolver(), expectedWResolver}
}; };
} }

View File

@ -15,6 +15,7 @@
<system systemId="XI_utf8.xml" uri="XI_utf8.xml"/> <system systemId="XI_utf8.xml" uri="XI_utf8.xml"/>
<system systemId="XI_utf8Catalog.xml" uri="XI_utf8Catalog.xml"/> <system systemId="XI_utf8Catalog.xml" uri="XI_utf8Catalog.xml"/>
<system systemId="XI_test2.xml" uri="XI_test2.xml"/> <system systemId="XI_test2.xml" uri="XI_test2.xml"/>
<system systemId="XI_test2Catalog.xml" uri="XI_test2Catalog.xml"/>
<system systemId="XI_red.dtd" uri="XI_red.dtd"/> <system systemId="XI_red.dtd" uri="XI_red.dtd"/>
<!-- xsd import can be mapped using the namespace or systemId --> <!-- xsd import can be mapped using the namespace or systemId -->

View File

@ -276,7 +276,7 @@ public class CatalogSupportBase {
SAXParser parser = getSAXParser(setUseCatalog, useCatalog, catalog); SAXParser parser = getSAXParser(setUseCatalog, useCatalog, catalog);
parser.parse(xml, handler); parser.parse(xml, handler);
assertEquals(expected, handler.getResult().trim(), ""); Assert.assertEquals(handler.getResult().trim(), expected);
} }
/* /*
@ -287,8 +287,9 @@ public class CatalogSupportBase {
XMLReader reader = getXMLReader(setUseCatalog, useCatalog, catalog); XMLReader reader = getXMLReader(setUseCatalog, useCatalog, catalog);
reader.setContentHandler(handler); reader.setContentHandler(handler);
reader.setEntityResolver(handler);
reader.parse(xml); reader.parse(xml);
assertEquals(expected, handler.getResult().trim(), ""); Assert.assertEquals(handler.getResult().trim(), expected);
} }
/* /*
@ -300,7 +301,7 @@ public class CatalogSupportBase {
parser.parse(new InputSource(new StringReader(xml)), handler); parser.parse(new InputSource(new StringReader(xml)), handler);
debugPrint("handler.result:" + handler.getResult()); debugPrint("handler.result:" + handler.getResult());
assertEquals(expected, handler.getResult(), "Catalog support for XInclude"); Assert.assertEquals(handler.getResult().trim(), expected);
} }
/* /*
@ -314,8 +315,7 @@ public class CatalogSupportBase {
Node node = doc.getElementsByTagName(elementInSystem).item(0); Node node = doc.getElementsByTagName(elementInSystem).item(0);
String result = node.getFirstChild().getTextContent(); String result = node.getFirstChild().getTextContent();
Assert.assertEquals(result.trim(), expected);
assertEquals(expected, result.trim(), "Catalog support for DOM");
} }
/* /*
@ -327,7 +327,7 @@ public class CatalogSupportBase {
XMLStreamReader streamReader = getStreamReader( XMLStreamReader streamReader = getStreamReader(
setUseCatalog, useCatalog, catalog, xml, resolver); setUseCatalog, useCatalog, catalog, xml, resolver);
String text = getText(streamReader, XMLStreamConstants.CHARACTERS); String text = getText(streamReader, XMLStreamConstants.CHARACTERS);
assertEquals(expected, text.trim(), "Catalog support for StAX"); Assert.assertEquals(text.trim(), expected);
} }
/* /*
@ -340,7 +340,7 @@ public class CatalogSupportBase {
XMLStreamReader streamReader = getStreamReader( XMLStreamReader streamReader = getStreamReader(
setUseCatalog, useCatalog, catalog, xml, resolver); setUseCatalog, useCatalog, catalog, xml, resolver);
String text = getText(streamReader, XMLStreamConstants.ENTITY_REFERENCE); String text = getText(streamReader, XMLStreamConstants.ENTITY_REFERENCE);
assertEquals(expected, text.trim(), "Catalog support for StAX"); Assert.assertEquals(text.trim(), expected);
} }
/* /*
@ -601,9 +601,11 @@ public class CatalogSupportBase {
} }
/** /**
* Returns the text of the first element found by the reader. * Returns the accumulated text of an event type.
*
* @param streamReader the XMLStreamReader * @param streamReader the XMLStreamReader
* @return the text of the first element * @param type the type of event requested
* @return the text of the accumulated text for the request type
* @throws XMLStreamException * @throws XMLStreamException
*/ */
String getText(XMLStreamReader streamReader, int type) throws XMLStreamException { String getText(XMLStreamReader streamReader, int type) throws XMLStreamException {
@ -662,24 +664,6 @@ public class CatalogSupportBase {
return factory; return factory;
} }
void assertNotNull(Object obj, String msg) {
if (obj == null) {
debugPrint("Test failed: " + msg);
} else {
debugPrint("Test passed: " + obj + " is not null");
}
}
void assertEquals(String expected, String actual, String msg) {
if (!expected.equals(actual)) {
debugPrint("Test failed: " + msg);
} else {
debugPrint("Test passed: ");
}
debugPrint("Expected: " + expected);
debugPrint("Actual: " + actual);
}
void fail(String msg) { void fail(String msg) {
System.out.println("Test failed:"); System.out.println("Test failed:");
System.out.println(msg); System.out.println(msg);

View File

@ -9,7 +9,7 @@
</another> </another>
</latin1> </latin1>
<test2> <test2>
<xinclude:include href="XI_test2.xml"/> <xinclude:include href="XI_test2Catalog.xml"/>
</test2> </test2>
<test3> <test3>
<!-- <xinclude:include href="XI_roottest.xml"/> --> <!-- <xinclude:include href="XI_roottest.xml"/> -->

View File

@ -0,0 +1,10 @@
<?xml version="1.0"?>
<!-- comment before root -->
<!DOCTYPE red SYSTEM "XI_red.dtd">
<red xmlns:xinclude="http://www.w3.org/2001/XInclude">
<blue>
<xinclude:include href="XI_utf8Catalog.xml" parse="text"/>
</blue>
</red>
<!-- comment after root -->