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);
}
if (staxInputSource == null) {
if (staxInputSource == null && fUseCatalog) {
if (fCatalogFeatures == null) {
fCatalogFeatures = JdkXmlUtils.getCatalogFeatures(fDefer, fCatalogFile, fPrefer, fResolve);
}
fCatalogFile = fCatalogFeatures.get(Feature.FILES);
if (fUseCatalog && fCatalogFile != null) {
if (fCatalogFile != null) {
try {
if (fCatalogResolver == null) {
fCatalogResolver = CatalogManager.catalogResolver(fCatalogFeatures);
@ -1133,12 +1133,12 @@ public class XMLEntityManager implements XMLComponent, XMLEntityResolver {
xmlInputSource = fEntityResolver.resolveEntity(resourceIdentifier);
}
if (xmlInputSource == null) {
if (xmlInputSource == null && fUseCatalog) {
if (fCatalogFeatures == null) {
fCatalogFeatures = JdkXmlUtils.getCatalogFeatures(fDefer, fCatalogFile, fPrefer, fResolve);
}
fCatalogFile = fCatalogFeatures.get(Feature.FILES);
if (fUseCatalog && fCatalogFile != null) {
if (fCatalogFile != null) {
/*
since the method can be called from various processors, both
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.io.MalformedByteSequenceException;
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.HTTPInputSource;
import com.sun.org.apache.xerces.internal.util.IntStack;
@ -129,8 +131,6 @@ import org.xml.sax.InputSource;
public class XIncludeHandler
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_LANGUAGE = "Accept-Language";
public final static String XPOINTER = "xpointer";
@ -1624,12 +1624,12 @@ public class XIncludeHandler
includedSource =
fEntityResolver.resolveEntity(resourceIdentifier);
if (includedSource == null) {
if (includedSource == null && fUseCatalog) {
if (fCatalogFeatures == null) {
fCatalogFeatures = JdkXmlUtils.getCatalogFeatures(fDefer, fCatalogFile, fPrefer, fResolve);
}
fCatalogFile = fCatalogFeatures.get(CatalogFeatures.Feature.FILES);
if (fUseCatalog && fCatalogFile != null) {
if (fCatalogFile != null) {
/*
Although URI entry is preferred for resolving XInclude, system entry
is allowed as well.
@ -1690,14 +1690,11 @@ public class XIncludeHandler
if ((xpointer != null && fXPointerChildConfig == null)
|| (xpointer == null && fXIncludeChildConfig == null) ) {
String parserName = XINCLUDE_DEFAULT_CONFIGURATION;
if (xpointer != null)
parserName = "com.sun.org.apache.xerces.internal.parsers.XPointerParserConfiguration";
fChildConfig =
(XMLParserConfiguration)ObjectFactory.newInstance(
parserName,
true);
if (xpointer == null) {
fChildConfig = new XIncludeParserConfiguration();
} else {
fChildConfig = new XPointerParserConfiguration();
}
// use the same symbol table, error reporter, entity resolver, security manager and buffer size.
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.stax.StAXSource;
import javax.xml.transform.stream.StreamSource;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Listeners;
@ -42,7 +41,7 @@ import org.xml.sax.InputSource;
/**
* @test
* @bug 8158084 8162438 8162442 8166220
* @bug 8158084 8162438 8162442 8166220 8166398
* @library /javax/xml/jaxp/libs /javax/xml/jaxp/unittest
* @run testng/othervm -DrunSecMngr=true 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 Catalog is used when there's no custom resolver, and the USE_CATALOG
* is true (which is the case by default).
*/
*/
/**
* Support Catalog:
@ -177,13 +176,13 @@ public class CatalogSupport extends CatalogSupportBase {
*/
@DataProvider(name = "data_SAXA")
public Object[][] getDataSAX() {
String[] systemIds = {"system.xsd"};
InputSource[] returnValues = {new InputSource(new StringReader(dtd_systemResolved))};
MyEntityHandler entityHandler = new MyEntityHandler(systemIds, returnValues, elementInSystem);
String[] systemIds = {"system.dtd"};
return new Object[][]{
{false, true, xml_catalog, xml_system, new MyHandler(elementInSystem), expectedWCatalog},
{false, true, xml_catalog, xml_system, entityHandler, expectedWResolver},
{true, true, xml_catalog, xml_system, entityHandler, expectedWResolver}
{false, true, xml_catalog, xml_system, getMyEntityHandler(elementInSystem, systemIds,
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")
public Object[][] getDataDOM() {
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[][]{
@ -230,8 +229,8 @@ public class CatalogSupport extends CatalogSupportBase {
return new Object[][]{
{false, true, xml_catalog, xml_system, null, expectedWCatalog},
{false, true, xml_catalog, xml_system, null, expectedWResolver},
{true, true, xml_catalog, xml_system, null, expectedWResolver}
{false, true, xml_catalog, xml_system, new MyStaxEntityResolver(), 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_utf8Catalog.xml" uri="XI_utf8Catalog.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"/>
<!-- 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);
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);
reader.setContentHandler(handler);
reader.setEntityResolver(handler);
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);
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);
String result = node.getFirstChild().getTextContent();
assertEquals(expected, result.trim(), "Catalog support for DOM");
Assert.assertEquals(result.trim(), expected);
}
/*
@ -327,7 +327,7 @@ public class CatalogSupportBase {
XMLStreamReader streamReader = getStreamReader(
setUseCatalog, useCatalog, catalog, xml, resolver);
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(
setUseCatalog, useCatalog, catalog, xml, resolver);
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
* @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
*/
String getText(XMLStreamReader streamReader, int type) throws XMLStreamException {
@ -662,24 +664,6 @@ public class CatalogSupportBase {
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) {
System.out.println("Test failed:");
System.out.println(msg);

View File

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