You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commons-cvs@xml.apache.org by nd...@apache.org on 2005/04/13 16:16:13 UTC
cvs commit: xml-commons/java/src/org/apache/xml/resolver/tests BasicResolverTests.java catalog.xml
ndw 2005/04/13 07:16:13
Modified: java/src/org/apache/xml/resolver Catalog.java
CatalogManager.java
java/src/org/apache/xml/resolver/readers
OASISXMLCatalogReader.java
java/src/org/apache/xml/resolver/tests
BasicResolverTests.java catalog.xml
Log:
Support uriSuffix and systemIdSuffix per XML Catalogs V1.1
Revision Changes Path
1.13 +82 -1 xml-commons/java/src/org/apache/xml/resolver/Catalog.java
Index: Catalog.java
===================================================================
RCS file: /home/cvs/xml-commons/java/src/org/apache/xml/resolver/Catalog.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- Catalog.java 13 Apr 2005 13:30:58 -0000 1.12
+++ Catalog.java 13 Apr 2005 14:16:13 -0000 1.13
@@ -130,6 +130,11 @@
* specifies alternate prefix for a system identifier.</li>
* <li><b>REWRITE_URI</b>
* specifies alternate prefix for a URI.</li>
+ * <li><b>SYSTEM_SUFFIX</b>
+ * maps any system identifier that ends with a particular suffix to another
+ * system identifier.</li>
+ * <li><b>URI_SUFFIX</b>
+ * maps any URI that ends with a particular suffix to another URI.</li>
* <li><b>DOCTYPE</b>
* associates the names of root elements with URIs. (In other words, an XML
* processor might infer the doctype of an XML document that does not include
@@ -275,6 +280,10 @@
/** The REWRITE_URI Catalog Entry type. */
public static final int REWRITE_URI = CatalogEntry.addEntryType("REWRITE_URI", 2);
+ /** The SYSTEM_SUFFIX Catalog Entry type. */
+ public static final int SYSTEM_SUFFIX = CatalogEntry.addEntryType("SYSTEM_SUFFIX", 2);
+ /** The URI_SUFFIX Catalog Entry type. */
+ public static final int URI_SUFFIX = CatalogEntry.addEntryType("URI_SUFFIX", 2);
/**
* The base URI for relative system identifiers in the catalog.
@@ -1055,6 +1064,26 @@
catalogManager.debug.message(4, "REWRITE_URI", pui, upx);
catalogEntries.addElement(entry);
+ } else if (type == SYSTEM_SUFFIX) {
+ String pui = normalizeURI(entry.getEntryArg(0));
+ String upx = makeAbsolute(normalizeURI(entry.getEntryArg(1)));
+
+ entry.setEntryArg(0, pui);
+ entry.setEntryArg(1, upx);
+
+ catalogManager.debug.message(4, "SYSTEM_SUFFIX", pui, upx);
+
+ catalogEntries.addElement(entry);
+ } else if (type == URI_SUFFIX) {
+ String pui = normalizeURI(entry.getEntryArg(0));
+ String upx = makeAbsolute(normalizeURI(entry.getEntryArg(1)));
+
+ entry.setEntryArg(0, pui);
+ entry.setEntryArg(1, upx);
+
+ catalogManager.debug.message(4, "URI_SUFFIX", pui, upx);
+
+ catalogEntries.addElement(entry);
} else if (type == DOCTYPE) {
String fsi = makeAbsolute(normalizeURI(entry.getEntryArg(1)));
entry.setEntryArg(1, fsi);
@@ -1758,6 +1787,32 @@
return prefix + systemId.substring(startString.length());
}
+ // If there's a SYSTEM_SUFFIX entry in this catalog, use it
+ en = catalogEntries.elements();
+ String suffixString = null;
+ String suffixURI = null;
+ while (en.hasMoreElements()) {
+ CatalogEntry e = (CatalogEntry) en.nextElement();
+
+ if (e.getEntryType() == SYSTEM_SUFFIX) {
+ String p = (String) e.getEntryArg(0);
+ if (p.length() <= systemId.length()
+ && systemId.endsWith(p)) {
+ // Is this the longest prefix?
+ if (suffixString == null
+ || p.length() > suffixString.length()) {
+ suffixString = p;
+ suffixURI = e.getEntryArg(1);
+ }
+ }
+ }
+ }
+
+ if (suffixURI != null) {
+ // return the systemId for the suffix
+ return suffixURI;
+ }
+
// If there's a DELEGATE_SYSTEM entry in this catalog, use it
en = catalogEntries.elements();
Vector delCats = new Vector();
@@ -1886,10 +1941,36 @@
}
if (prefix != null) {
- // return the systemId with the new prefix
+ // return the uri with the new prefix
return prefix + uri.substring(startString.length());
}
+ // If there's a URI_SUFFIX entry in this catalog, use it
+ en = catalogEntries.elements();
+ String suffixString = null;
+ String suffixURI = null;
+ while (en.hasMoreElements()) {
+ CatalogEntry e = (CatalogEntry) en.nextElement();
+
+ if (e.getEntryType() == URI_SUFFIX) {
+ String p = (String) e.getEntryArg(0);
+ if (p.length() <= uri.length()
+ && uri.endsWith(p)) {
+ // Is this the longest prefix?
+ if (suffixString == null
+ || p.length() > suffixString.length()) {
+ suffixString = p;
+ suffixURI = e.getEntryArg(1);
+ }
+ }
+ }
+ }
+
+ if (suffixURI != null) {
+ // return the uri for the suffix
+ return suffixURI;
+ }
+
// If there's a DELEGATE_URI entry in this catalog, use it
en = catalogEntries.elements();
Vector delCats = new Vector();
1.10 +1 -1 xml-commons/java/src/org/apache/xml/resolver/CatalogManager.java
Index: CatalogManager.java
===================================================================
RCS file: /home/cvs/xml-commons/java/src/org/apache/xml/resolver/CatalogManager.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- CatalogManager.java 13 Apr 2005 13:30:58 -0000 1.9
+++ CatalogManager.java 13 Apr 2005 14:16:13 -0000 1.10
@@ -193,7 +193,7 @@
/** Current catalog files list. */
private String catalogFiles = null;
- /** Did the catalgoFiles come from the properties file? */
+ /** Did the catalogFiles come from the properties file? */
private boolean fromPropertiesFile = false;
/** Default verbosity level if there is no property setting for it. */
1.6 +20 -0 xml-commons/java/src/org/apache/xml/resolver/readers/OASISXMLCatalogReader.java
Index: OASISXMLCatalogReader.java
===================================================================
RCS file: /home/cvs/xml-commons/java/src/org/apache/xml/resolver/readers/OASISXMLCatalogReader.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- OASISXMLCatalogReader.java 2 Sep 2003 07:05:08 -0000 1.5
+++ OASISXMLCatalogReader.java 13 Apr 2005 14:16:13 -0000 1.6
@@ -284,6 +284,16 @@
atts.getValue("systemIdStartString"),
atts.getValue("rewritePrefix"));
}
+ } else if (localName.equals("systemSuffix")) {
+ if (checkAttributes(atts, "systemIdSuffix", "uri")) {
+ entryType = Catalog.SYSTEM_SUFFIX;
+ entryArgs.add(atts.getValue("systemIdSuffix"));
+ entryArgs.add(atts.getValue("uri"));
+
+ debug.message(4, "systemSuffix",
+ atts.getValue("systemIdSuffix"),
+ atts.getValue("uri"));
+ }
} else if (localName.equals("rewriteURI")) {
if (checkAttributes(atts, "uriStartString", "rewritePrefix")) {
entryType = Catalog.REWRITE_URI;
@@ -294,6 +304,16 @@
atts.getValue("uriStartString"),
atts.getValue("rewritePrefix"));
}
+ } else if (localName.equals("uriSuffix")) {
+ if (checkAttributes(atts, "uriSuffix", "uri")) {
+ entryType = Catalog.URI_SUFFIX;
+ entryArgs.add(atts.getValue("uriSuffix"));
+ entryArgs.add(atts.getValue("uri"));
+
+ debug.message(4, "uriSuffix",
+ atts.getValue("uriSuffix"),
+ atts.getValue("uri"));
+ }
} else if (localName.equals("nextCatalog")) {
if (checkAttributes(atts, "catalog")) {
entryType = Catalog.CATALOG;
1.2 +27 -0 xml-commons/java/src/org/apache/xml/resolver/tests/BasicResolverTests.java
Index: BasicResolverTests.java
===================================================================
RCS file: /home/cvs/xml-commons/java/src/org/apache/xml/resolver/tests/BasicResolverTests.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- BasicResolverTests.java 13 Apr 2005 13:29:02 -0000 1.1
+++ BasicResolverTests.java 13 Apr 2005 14:16:13 -0000 1.2
@@ -122,4 +122,31 @@
assertTrue(local.equals(resolved));
}
+
+ public void testSystemSuffix() {
+ String resolved = null;
+ String local = "file:/usr/local/xml/docbook/4.4/docbookx.dtd";
+
+ try {
+ resolved = catalog.resolveSystem("http://any/random/path/to/docbookx.dtd");
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ assertTrue(local.equals(resolved));
+ }
+
+ public void testUriSuffix() {
+ String resolved = null;
+ String local = "file:/usr/local/xsl/docbook/html/docbook.xsl";
+
+ try {
+ resolved = catalog.resolveURI("http://any/path/to/html/docbook.xsl");
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ assertTrue(local.equals(resolved));
+ }
+
}
1.2 +9 -3 xml-commons/java/src/org/apache/xml/resolver/tests/catalog.xml
Index: catalog.xml
===================================================================
RCS file: /home/cvs/xml-commons/java/src/org/apache/xml/resolver/tests/catalog.xml,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- catalog.xml 13 Apr 2005 13:29:02 -0000 1.1
+++ catalog.xml 13 Apr 2005 14:16:13 -0000 1.2
@@ -8,13 +8,13 @@
uri="file:///local/system-resolver.dtd"/>
<rewriteSystem systemIdStartString="http://rewrite.example.org/"
- rewritePrefix="/short/"/>
+ rewritePrefix="file:///short/"/>
<rewriteSystem systemIdStartString="http://rewrite.example.org/longest/"
- rewritePrefix="/longest/"/>
+ rewritePrefix="file:///longest/"/>
<rewriteSystem systemIdStartString="http://rewrite.example.org/long"
- rewritePrefix="/long/"/>
+ rewritePrefix="file:///long/"/>
<uri name="http://example.org/someURI"
uri="file:///local/uri"/>
@@ -29,4 +29,10 @@
<nextCatalog catalog="tr9401.xml"/>
+ <systemSuffix systemIdSuffix="/docbookx.dtd"
+ uri="file:///usr/local/xml/docbook/4.4/docbookx.dtd"/>
+
+ <uriSuffix uriSuffix="/html/docbook.xsl"
+ uri="file:///usr/local/xsl/docbook/html/docbook.xsl"/>
+
</catalog>