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 2006/04/14 14:52:12 UTC

svn commit: r394077 - in /xml/commons/trunk/java: ./ etc/ src/org/apache/xml/resolver/ src/org/apache/xml/resolver/helpers/ src/org/apache/xml/resolver/readers/

Author: ndw
Date: Fri Apr 14 05:52:10 2006
New Revision: 394077

URL: http://svn.apache.org/viewcvs?rev=394077&view=rev
Log:
Apply Jacob Kjome's patches to fix ASF Bugzilla Bug 38562: [resolver] patch making XCatalog support actually functional plus other minor cleanup

Added:
    xml/commons/trunk/java/etc/xcatalog.dtd
Modified:
    xml/commons/trunk/java/resolver.xml
    xml/commons/trunk/java/src/org/apache/xml/resolver/Catalog.java
    xml/commons/trunk/java/src/org/apache/xml/resolver/Resolver.java
    xml/commons/trunk/java/src/org/apache/xml/resolver/helpers/BootstrapResolver.java
    xml/commons/trunk/java/src/org/apache/xml/resolver/readers/OASISXMLCatalogReader.java
    xml/commons/trunk/java/src/org/apache/xml/resolver/readers/SAXCatalogReader.java
    xml/commons/trunk/java/src/org/apache/xml/resolver/readers/XCatalogReader.java

Added: xml/commons/trunk/java/etc/xcatalog.dtd
URL: http://svn.apache.org/viewcvs/xml/commons/trunk/java/etc/xcatalog.dtd?rev=394077&view=auto
==============================================================================
--- xml/commons/trunk/java/etc/xcatalog.dtd (added)
+++ xml/commons/trunk/java/etc/xcatalog.dtd Fri Apr 14 05:52:10 2006
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="US-ASCII"?>
+<!ELEMENT XCatalog ANY>
+<!ATTLIST XCatalog
+  Version (0.1|0.2) "0.2"
+  >
+
+<!ELEMENT Map EMPTY>
+<!ATTLIST Map
+  PublicID CDATA #REQUIRED
+  HRef     CDATA #REQUIRED
+  >
+
+<!ELEMENT Remap EMPTY>
+<!ATTLIST Remap
+  SystemID CDATA #REQUIRED
+  HRef     CDATA #REQUIRED
+  >
+
+<!ELEMENT Delegate EMPTY>
+<!ATTLIST Delegate
+  PublicID CDATA #REQUIRED
+  HRef     CDATA #REQUIRED
+  >
+
+<!ELEMENT Extend EMPTY>
+<!ATTLIST Extend
+  HRef CDATA #REQUIRED
+  >
+
+<!ELEMENT Base EMPTY>
+<!ATTLIST Base
+  HRef CDATA #REQUIRED
+  >
+

Modified: xml/commons/trunk/java/resolver.xml
URL: http://svn.apache.org/viewcvs/xml/commons/trunk/java/resolver.xml?rev=394077&r1=394076&r2=394077&view=diff
==============================================================================
--- xml/commons/trunk/java/resolver.xml (original)
+++ xml/commons/trunk/java/resolver.xml Fri Apr 14 05:52:10 2006
@@ -88,7 +88,7 @@
 
    <echo message="Compiling..." />
 
-   <javac srcdir="${src.dir}" destdir="${build.classes.dir}">
+   <javac srcdir="${src.dir}" destdir="${build.classes.dir}" debug="true" optimize="true" deprecation="true" verbose="false">
      <!-- <classpath> not needed since Ant already supplies these Sep-03 -sc -->
      <include name="${resolver.subdir}/*.java"/>
      <include name="${resolver.subdir}/helpers/*.java"/>
@@ -108,7 +108,7 @@
       <fileset dir="${etc.dir}"/>
     </copy>
 
-    <jar jarfile="${resolver.jar}" manifest="${build.dir}/manifest.resolver" basedir="${build.classes.dir}" />
+    <jar jarfile="${resolver.jar}" manifest="${build.dir}/manifest.resolver" basedir="${build.classes.dir}" index="true" />
   </target>
 
   <target name="install">

Modified: xml/commons/trunk/java/src/org/apache/xml/resolver/Catalog.java
URL: http://svn.apache.org/viewcvs/xml/commons/trunk/java/src/org/apache/xml/resolver/Catalog.java?rev=394077&r1=394076&r2=394077&view=diff
==============================================================================
--- xml/commons/trunk/java/src/org/apache/xml/resolver/Catalog.java (original)
+++ xml/commons/trunk/java/src/org/apache/xml/resolver/Catalog.java Fri Apr 14 05:52:10 2006
@@ -405,7 +405,7 @@
 
     SAXCatalogReader saxReader = new SAXCatalogReader(spf);
 
-    saxReader.setCatalogParser(null, "XMLCatalog",
+    saxReader.setCatalogParser(null, "XCatalog",
 			       "org.apache.xml.resolver.readers.XCatalogReader");
 
     saxReader.setCatalogParser(OASISXMLCatalogReader.namespaceName,

Modified: xml/commons/trunk/java/src/org/apache/xml/resolver/Resolver.java
URL: http://svn.apache.org/viewcvs/xml/commons/trunk/java/src/org/apache/xml/resolver/Resolver.java?rev=394077&r1=394076&r2=394077&view=diff
==============================================================================
--- xml/commons/trunk/java/src/org/apache/xml/resolver/Resolver.java (original)
+++ xml/commons/trunk/java/src/org/apache/xml/resolver/Resolver.java Fri Apr 14 05:52:10 2006
@@ -87,7 +87,7 @@
 
     SAXCatalogReader saxReader = new SAXCatalogReader(spf);
 
-    saxReader.setCatalogParser(null, "XMLCatalog",
+    saxReader.setCatalogParser(null, "XCatalog",
 			       "org.apache.xml.resolver.readers.XCatalogReader");
 
     saxReader.setCatalogParser(OASISXMLCatalogReader.namespaceName,

Modified: xml/commons/trunk/java/src/org/apache/xml/resolver/helpers/BootstrapResolver.java
URL: http://svn.apache.org/viewcvs/xml/commons/trunk/java/src/org/apache/xml/resolver/helpers/BootstrapResolver.java?rev=394077&r1=394076&r2=394077&view=diff
==============================================================================
--- xml/commons/trunk/java/src/org/apache/xml/resolver/helpers/BootstrapResolver.java (original)
+++ xml/commons/trunk/java/src/org/apache/xml/resolver/helpers/BootstrapResolver.java Fri Apr 14 05:52:10 2006
@@ -62,6 +62,9 @@
   /** System identifier for OASIS XML Catalog files. */
   public static final String xmlCatalogSysId = "http://www.oasis-open.org/committees/entity/release/1.0/catalog.dtd";
 
+  /** Public identifier for legacy Apache XCatalog files.  There is no official system identifier for XCatalog files. */
+  public static final String xCatalogPubId = "-//DTD XCatalog//EN";
+
   /** Private hash used for public identifiers. */
   private Hashtable publicMap = new Hashtable();
 
@@ -87,6 +90,11 @@
     url = this.getClass().getResource("/org/apache/xml/resolver/etc/catalog.xsd");
     if (url != null) {
       uriMap.put(xmlCatalogXSD, url.toString());
+    }
+
+    url = this.getClass().getResource("/org/apache/xml/resolver/etc/xcatalog.dtd");
+    if (url != null) {
+      publicMap.put(xCatalogPubId, url.toString());
     }
   }
 

Modified: xml/commons/trunk/java/src/org/apache/xml/resolver/readers/OASISXMLCatalogReader.java
URL: http://svn.apache.org/viewcvs/xml/commons/trunk/java/src/org/apache/xml/resolver/readers/OASISXMLCatalogReader.java?rev=394077&r1=394076&r2=394077&view=diff
==============================================================================
--- xml/commons/trunk/java/src/org/apache/xml/resolver/readers/OASISXMLCatalogReader.java (original)
+++ xml/commons/trunk/java/src/org/apache/xml/resolver/readers/OASISXMLCatalogReader.java Fri Apr 14 05:52:10 2006
@@ -28,7 +28,8 @@
 import org.apache.xml.resolver.helpers.PublicId;
 
 import org.xml.sax.*;
-import org.w3c.dom.*;
+
+import javax.xml.parsers.*;
 
 /**
  * Parse OASIS Entity Resolution Technical Committee 
@@ -68,6 +69,17 @@
     return catalog;
   }
 
+  /** Default constructor */
+  public OASISXMLCatalogReader() {
+    super();
+  }
+
+  /** Constructor allowing for providing custom SAX parser factory */
+  public OASISXMLCatalogReader(SAXParserFactory parserFactory, Catalog catalog) {
+    super(parserFactory);
+    setCatalog(catalog);
+  }
+
   /**
    * Are we in an extension namespace?
    *
@@ -99,7 +111,7 @@
     return;
   }
 
-  /** The SAX <code>startDocument</code> method does nothing. */
+  /** The SAX <code>startDocument</code> */
   public void startDocument ()
     throws SAXException {
     baseURIStack.push(catalog.getCurrentBase());
@@ -429,7 +441,7 @@
       && checkAttributes(atts, attName2);
   }
 
-  /** The SAX <code>endElement</code> method does nothing. */
+  /** The SAX <code>endElement</code> */
   public void endElement (String namespaceURI,
 			  String localName,
 			  String qName)

Modified: xml/commons/trunk/java/src/org/apache/xml/resolver/readers/SAXCatalogReader.java
URL: http://svn.apache.org/viewcvs/xml/commons/trunk/java/src/org/apache/xml/resolver/readers/SAXCatalogReader.java?rev=394077&r1=394076&r2=394077&view=diff
==============================================================================
--- xml/commons/trunk/java/src/org/apache/xml/resolver/readers/SAXCatalogReader.java (original)
+++ xml/commons/trunk/java/src/org/apache/xml/resolver/readers/SAXCatalogReader.java Fri Apr 14 05:52:10 2006
@@ -100,6 +100,9 @@
      */
   private boolean abandonHope = false;
 
+  /** If set, used for loading classes by reflection */
+  private ClassLoader loader = null;
+
   /** The Catalog that we're working for. */
   private Catalog catalog;
 
@@ -125,6 +128,14 @@
     return parserClass;
   }
 
+  /**
+   * Set the class loader to use when loading class by reflection.  If not set,
+   * the the class loader used to load this class is used.
+   */
+  public void setClassLoader(ClassLoader loader) {
+    this.loader = loader;
+  }
+
   /** The debug class to use for this reader.
    *
    * This is a bit of a hack. Anyway, whenever we read for a catalog,
@@ -152,29 +163,25 @@
     this.parserClass = parserClass;
   }
 
-  /** Set the SAXCatalogParser class for the given namespace/root
-     * element type.
-     */
+  /**
+   * Set the SAXCatalogParser class for the given namespace/root
+   * element type.
+   */
   public void setCatalogParser(String namespaceURI,
 			       String rootElement,
 			       String parserClass) {
-    if (namespaceURI == null) {
-      namespaceMap.put(rootElement, parserClass);
-    } else {
-      namespaceMap.put("{"+namespaceURI+"}"+rootElement, parserClass);
-    }
+    namespaceURI = namespaceURI != null ? namespaceURI.trim() : "";
+    namespaceMap.put("{"+namespaceURI+"}"+rootElement, parserClass);
   }
 
-  /** Get the SAXCatalogParser class for the given namespace/root
-     * element type.
-     */
+  /**
+   * Get the SAXCatalogParser class for the given namespace/root
+   * element type.
+   */
   public String getCatalogParser(String namespaceURI,
 				 String rootElement) {
-    if (namespaceURI == null) {
-      return (String) namespaceMap.get(rootElement);
-    } else {
-      return (String) namespaceMap.get("{"+namespaceURI+"}"+rootElement);
-    }
+    namespaceURI = namespaceURI != null ? namespaceURI.trim() : "";
+    return (String) namespaceMap.get("{"+namespaceURI+"}"+rootElement);
   }
 
   /**
@@ -243,7 +250,7 @@
 	}
 	parser.parse(new InputSource(is), spHandler);
       } else {
-	Parser parser = (Parser) Class.forName(parserClass).newInstance();
+	Parser parser = (Parser) Class.forName(parserClass, true, loader != null ? loader : this.getClass().getClassLoader()).newInstance();
 	parser.setDocumentHandler(this);
 	if (bResolver != null) {
 	  parser.setEntityResolver(bResolver);
@@ -349,7 +356,7 @@
 
       try {
 	saxParser = (SAXCatalogParser)
-	  Class.forName(saxParserClass).newInstance();
+	  Class.forName(saxParserClass, true, loader != null ? loader : this.getClass().getClassLoader()).newInstance();
 
 	saxParser.setCatalog(catalog);
 	saxParser.startDocument();
@@ -410,7 +417,7 @@
 
       try {
 	saxParser = (SAXCatalogParser)
-	  Class.forName(saxParserClass).newInstance();
+	  Class.forName(saxParserClass, true, loader != null ? loader : this.getClass().getClassLoader()).newInstance();
 
 	saxParser.setCatalog(catalog);
 	saxParser.startDocument();

Modified: xml/commons/trunk/java/src/org/apache/xml/resolver/readers/XCatalogReader.java
URL: http://svn.apache.org/viewcvs/xml/commons/trunk/java/src/org/apache/xml/resolver/readers/XCatalogReader.java?rev=394077&r1=394076&r2=394077&view=diff
==============================================================================
--- xml/commons/trunk/java/src/org/apache/xml/resolver/readers/XCatalogReader.java (original)
+++ xml/commons/trunk/java/src/org/apache/xml/resolver/readers/XCatalogReader.java Fri Apr 14 05:52:10 2006
@@ -30,7 +30,7 @@
 import javax.xml.parsers.*;
 
 /**
- * Parse "xcatalog" XML Catalog files, this is the XML Catalog format
+ * Parse "XCatalog" XML Catalog files, this is the XML Catalog format
  * developed by John Cowan and supported by Apache.
  *
  * @see Catalog
@@ -49,6 +49,7 @@
   /** Set the current catalog. */
   public void setCatalog (Catalog catalog) {
     this.catalog = catalog;
+    debug = catalog.getCatalogManager().debug;
   }
 
   /** Get the current catalog. */
@@ -56,13 +57,19 @@
     return catalog;
   }
 
-  /** The constructor */
-  public XCatalogReader(SAXParserFactory parserFactory) {
+  /** Default constructor */
+  public XCatalogReader() {
+    super();
+  }
+
+  /** Constructor allowing for providing custom SAX parser factory */
+  public XCatalogReader(SAXParserFactory parserFactory, Catalog catalog) {
     super(parserFactory);
+    setCatalog(catalog);
   }
 
   // ----------------------------------------------------------------------
-  // Implement the SAX DocumentHandler interface
+  // Implement the SAX ContentHandler interface
 
   /** The SAX <code>setDocumentLocator</code> method does nothing. */
   public void setDocumentLocator (Locator locator) {
@@ -106,41 +113,41 @@
       entryType = catalog.BASE;
       entryArgs.add(atts.getValue("HRef"));
 
-      catalog.getCatalogManager().debug.message(4, "Base", atts.getValue("HRef"));
+      debug.message(4, "Base", atts.getValue("HRef"));
     } else if (localName.equals("Delegate")) {
       entryType = catalog.DELEGATE_PUBLIC;
-      entryArgs.add(atts.getValue("PublicId"));
+      entryArgs.add(atts.getValue("PublicID"));
       entryArgs.add(atts.getValue("HRef"));
 
-      catalog.getCatalogManager().debug.message(4, "Delegate",
-		    PublicId.normalize(atts.getValue("PublicId")),
+      debug.message(4, "Delegate",
+		    PublicId.normalize(atts.getValue("PublicID")),
 		    atts.getValue("HRef"));
     } else if (localName.equals("Extend")) {
       entryType = catalog.CATALOG;
       entryArgs.add(atts.getValue("HRef"));
 
-      catalog.getCatalogManager().debug.message(4, "Extend", atts.getValue("HRef"));
+      debug.message(4, "Extend", atts.getValue("HRef"));
     } else if (localName.equals("Map")) {
       entryType = catalog.PUBLIC;
-      entryArgs.add(atts.getValue("PublicId"));
+      entryArgs.add(atts.getValue("PublicID"));
       entryArgs.add(atts.getValue("HRef"));
 
-      catalog.getCatalogManager().debug.message(4, "Map",
-		    PublicId.normalize(atts.getValue("PublicId")),
+      debug.message(4, "Map",
+		    PublicId.normalize(atts.getValue("PublicID")),
 		    atts.getValue("HRef"));
     } else if (localName.equals("Remap")) {
       entryType = catalog.SYSTEM;
-      entryArgs.add(atts.getValue("SystemId"));
+      entryArgs.add(atts.getValue("SystemID"));
       entryArgs.add(atts.getValue("HRef"));
 
-      catalog.getCatalogManager().debug.message(4, "Remap",
-		    atts.getValue("SystemId"),
+      debug.message(4, "Remap",
+		    atts.getValue("SystemID"),
 		    atts.getValue("HRef"));
-    } else if (localName.equals("XMLCatalog")) {
+    } else if (localName.equals("XCatalog")) {
       // nop, start of catalog
     } else {
       // This is equivalent to an invalid catalog entry type
-      catalog.getCatalogManager().debug.message(1, "Invalid catalog entry type", localName);
+      debug.message(1, "Invalid catalog entry type", localName);
     }
 
     if (entryType >= 0) {
@@ -149,21 +156,21 @@
 	catalog.addEntry(ce);
       } catch (CatalogException cex) {
 	if (cex.getExceptionType() == CatalogException.INVALID_ENTRY_TYPE) {
-	  catalog.getCatalogManager().debug.message(1, "Invalid catalog entry type", localName);
+	  debug.message(1, "Invalid catalog entry type", localName);
 	} else if (cex.getExceptionType() == CatalogException.INVALID_ENTRY) {
-	  catalog.getCatalogManager().debug.message(1, "Invalid catalog entry", localName);
+	  debug.message(1, "Invalid catalog entry", localName);
 	}
       }
     }
-    }
+  }
 
-    /** The SAX <code>endElement</code> method does nothing. */
-    public void endElement (String namespaceURI,
-			    String localName,
-			    String qName)
-      throws SAXException {
-      return;
-    }
+  /** The SAX <code>endElement</code> method does nothing. */
+  public void endElement (String namespaceURI,
+			  String localName,
+			  String qName)
+    throws SAXException {
+    return;
+  }
 
   /** The SAX <code>characters</code> method does nothing. */
   public void characters (char ch[], int start, int length)
@@ -182,4 +189,23 @@
     throws SAXException {
     return;
   }
+
+  /** The SAX <code>skippedEntity</code> method does nothing. */
+  public void skippedEntity (String name)
+    throws SAXException {
+    return;
+  }
+
+  /** The SAX <code>startPrefixMapping</code> method does nothing. */
+  public void startPrefixMapping(String prefix, String uri)
+    throws SAXException {
+    return;
+  }
+
+  /** The SAX <code>endPrefixMapping</code> method does nothing. */
+  public void endPrefixMapping(String prefix)
+    throws SAXException {
+    return;
+  }
+
 }