8152527: Relative rewriteSystem with xml:base at group level failed
Reviewed-by: lancea
--- a/jaxp/src/java.xml/share/classes/javax/xml/catalog/GroupEntry.java Thu Apr 14 09:33:48 2016 -0700
+++ b/jaxp/src/java.xml/share/classes/javax/xml/catalog/GroupEntry.java Thu Apr 14 16:36:04 2016 -0700
@@ -249,8 +249,10 @@
//use it if there is a match of the system type
return match;
} else if (grpEntry.longestRewriteMatch > longestRewriteMatch) {
+ longestRewriteMatch = grpEntry.longestRewriteMatch;
rewriteMatch = match;
} else if (grpEntry.longestSuffixMatch > longestSuffixMatch) {
+ longestSuffixMatch = grpEntry.longestSuffixMatch;
suffixMatch = match;
}
break;
--- a/jaxp/test/javax/xml/jaxp/unittest/catalog/CatalogTest.java Thu Apr 14 09:33:48 2016 -0700
+++ b/jaxp/test/javax/xml/jaxp/unittest/catalog/CatalogTest.java Thu Apr 14 16:36:04 2016 -0700
@@ -38,16 +38,34 @@
import org.testng.annotations.Test;
import org.xml.sax.Attributes;
import org.xml.sax.ErrorHandler;
+import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
import org.xml.sax.ext.DefaultHandler2;
/*
- * @bug 8081248, 8144966, 8146606, 8146237, 8151154, 8150969, 8151162
+ * @bug 8081248, 8144966, 8146606, 8146237, 8151154, 8150969, 8151162, 8152527
* @summary Tests basic Catalog functions.
*/
public class CatalogTest {
/*
+ * @bug 8152527
+ * This test is the same as the JDK test ResolveEntityTests:testMatch1.
+ * Verifies that the CatalogResolver resolves a publicId and/or systemId as
+ * expected.
+ */
+ @Test(dataProvider = "resolveEntity")
+ public void testMatch1(String cfile, String prefer, String sysId, String pubId, String expectedUri, String expectedFile, String msg) {
+ String catalogFile = getClass().getResource(cfile).getFile();
+ CatalogFeatures features = CatalogFeatures.builder().with(CatalogFeatures.Feature.PREFER, prefer).build();
+ CatalogResolver catalogResolver = CatalogManager.catalogResolver(features, catalogFile);
+ InputSource is = catalogResolver.resolveEntity(pubId, sysId);
+ Assert.assertNotNull(is, msg);
+ String expected = (expectedUri == null) ? expectedFile : expectedUri;
+ Assert.assertEquals(expected, is.getSystemId(), msg);
+ }
+
+ /*
* @bug 8151162
* Verifies that the Catalog matches specified publicId or systemId and returns
* results as expected.
@@ -270,6 +288,18 @@
}
}
+ /*
+ DataProvider: used to verify CatalogResolver's resolveEntity function.
+ Data columns:
+ catalog, prefer, systemId, publicId, expectedUri, expectedFile, msg
+ */
+ @DataProvider(name = "resolveEntity")
+ Object[][] getDataForMatchingBothIds() {
+ String expected = "http://www.groupxmlbase.com/dtds/rewrite.dtd";
+ return new Object[][]{
+ {"rewriteSystem_id.xml", "system", "http://www.sys00test.com/rewrite.dtd", "PUB-404", expected, expected, "Relative rewriteSystem with xml:base at group level failed"},
+ };
+ }
static String id = "http://openjdk.java.net/xml/catalog/dtd/system.dtd";
/*
DataProvider: used to verify how prefer settings affect the result of the
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jaxp/test/javax/xml/jaxp/unittest/catalog/rewriteSystem_id.xml Thu Apr 14 16:36:04 2016 -0700
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog" xml:base="http://local/base/dtd/">
+ <rewriteSystem systemIdStartString="http://remote/dtd/alice/" rewritePrefix="http://local/dtd/alice/rs/" />
+
+ <rewriteSystem systemIdStartString="http://remote/dtd/bob/" rewritePrefix="bob/rs/" />
+
+ <rewriteSystem systemIdStartString="http://remote/dtd/carl/" rewritePrefix="carl/rs/"
+ xml:base="http://local/carlBase/dtd/" />
+
+ <rewriteSystem systemIdStartString="http://remote/dtd/david/" rewritePrefix="david1/rs/" />
+ <rewriteSystem systemIdStartString="http://remote/dtd/david/" rewritePrefix="david2/rs/" />
+
+ <rewriteSystem systemIdStartString="http://remote/dtd/" rewritePrefix="ella/" />
+ <rewriteSystem systemIdStartString="http://remote/dtd/ella/" rewritePrefix="ella/rs/" />
+
+ <rewriteSystem systemIdStartString="http://remote.com/"
+ rewritePrefix="file:///share/doctypes/dtd/fail/"/>
+ <rewriteSystem systemIdStartString="http://remote.com/dtd"
+ rewritePrefix="file:///share/docbook/docbook/pass"/>
+
+ <group xml:base="http://www.groupxmlbase.com/">
+ <rewriteSystem systemIdStartString="http://www.sys00test.com" rewritePrefix="dtds"/>
+ </group>
+</catalog>