diff --git a/java/src/org/apache/xml/resolver/Catalog.java b/java/src/org/apache/xml/resolver/Catalog.java
index ab1d5fd..2ac9b06 100644
--- a/java/src/org/apache/xml/resolver/Catalog.java
+++ b/java/src/org/apache/xml/resolver/Catalog.java
@@ -130,6 +130,11 @@ import org.apache.xml.resolver.helpers.FileURL;
* specifies alternate prefix for a system identifier.
*
REWRITE_URI
* specifies alternate prefix for a URI.
+ * SYSTEM_SUFFIX
+ * maps any system identifier that ends with a particular suffix to another
+ * system identifier.
+ * URI_SUFFIX
+ * maps any URI that ends with a particular suffix to another URI.
* DOCTYPE
* 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 @@ public class Catalog {
/** 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.
@@ -1054,6 +1063,26 @@ public class Catalog {
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)));
@@ -1758,6 +1787,32 @@ public class Catalog {
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 @@ public class Catalog {
}
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();
diff --git a/java/src/org/apache/xml/resolver/CatalogManager.java b/java/src/org/apache/xml/resolver/CatalogManager.java
index fcfdc04..52863b9 100644
--- a/java/src/org/apache/xml/resolver/CatalogManager.java
+++ b/java/src/org/apache/xml/resolver/CatalogManager.java
@@ -193,7 +193,7 @@ public class CatalogManager {
/** 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. */
diff --git a/java/src/org/apache/xml/resolver/readers/OASISXMLCatalogReader.java b/java/src/org/apache/xml/resolver/readers/OASISXMLCatalogReader.java
index 289cf3e..21e70ca 100644
--- a/java/src/org/apache/xml/resolver/readers/OASISXMLCatalogReader.java
+++ b/java/src/org/apache/xml/resolver/readers/OASISXMLCatalogReader.java
@@ -284,6 +284,16 @@ public class OASISXMLCatalogReader extends SAXCatalogReader implements SAXCatalo
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 @@ public class OASISXMLCatalogReader extends SAXCatalogReader implements SAXCatalo
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;
diff --git a/java/src/org/apache/xml/resolver/tests/BasicResolverTests.java b/java/src/org/apache/xml/resolver/tests/BasicResolverTests.java
index 1d8d0b7..82ac6ae 100644
--- a/java/src/org/apache/xml/resolver/tests/BasicResolverTests.java
+++ b/java/src/org/apache/xml/resolver/tests/BasicResolverTests.java
@@ -122,4 +122,31 @@ public class BasicResolverTests extends TestCase {
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));
+ }
+
}
diff --git a/java/src/org/apache/xml/resolver/tests/catalog.xml b/java/src/org/apache/xml/resolver/tests/catalog.xml
index ac07027..85048a9 100644
--- a/java/src/org/apache/xml/resolver/tests/catalog.xml
+++ b/java/src/org/apache/xml/resolver/tests/catalog.xml
@@ -8,13 +8,13 @@
uri="file:///local/system-resolver.dtd"/>
+ rewritePrefix="file:///short/"/>
+ rewritePrefix="file:///longest/"/>
+ rewritePrefix="file:///long/"/>
@@ -29,4 +29,10 @@
+
+
+
+