You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by co...@locus.apache.org on 2000/11/16 04:15:41 UTC
cvs commit: xml-xalan/java/src/javax/xml/parsers DocumentBuilder.java DocumentBuilderFactory.java FactoryConfigurationError.java ParserConfigurationException.java SAXParser.java SAXParserFactory.java
costin 00/11/15 19:15:41
Modified: java/src/javax/xml/parsers DocumentBuilder.java
DocumentBuilderFactory.java
FactoryConfigurationError.java
ParserConfigurationException.java SAXParser.java
SAXParserFactory.java
Log:
Replaced javax.xml.parsers ( wich used to represent JAXP1.0 ) with the
latest JAXP1.1.
Now both javax.xml.transform and javax.xml.parsers correspond with the
latest spec.
Revision Changes Path
1.2 +130 -80 xml-xalan/java/src/javax/xml/parsers/DocumentBuilder.java
Index: DocumentBuilder.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/javax/xml/parsers/DocumentBuilder.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- DocumentBuilder.java 2000/10/02 02:43:02 1.1
+++ DocumentBuilder.java 2000/11/16 03:15:40 1.2
@@ -90,8 +90,8 @@
* http://java.sun.com/aboutJava/communityprocess/jsr/jsr_005_xml.html
* </a><br>
* THIS IMPLEMENTATION IS CONFORMANT TO THE "JAVA API FOR XML PARSING"
- * SPECIFICATION VERSION 1.0 PUBLIC RELEASE 1 BY JAMES DUNCAN DAVIDSON
- * PUBLISHED BY SUN MICROSYSTEMS ON FEB. 18, 2000 AND FOUND AT
+ * SPECIFICATION VERSION 1.1 PUBLIC REVIEW 1 BY JAMES DUNCAN DAVIDSON
+ * PUBLISHED BY SUN MICROSYSTEMS ON NOV. 2, 2000 AND FOUND AT
* <a href="http://java.sun.com/xml">http://java.sun.com/xml</a>
* <br>
* <br>
@@ -108,119 +108,169 @@
*
* @author <a href="pier@betaversion.org">Pierpaolo Fumagalli</a>
* @author Copyright © 2000 The Apache Software Foundation.
- * @version 1.0 CVS $Revision: 1.1 $ $Date: 2000/10/02 02:43:02 $
+ * @version 1.0 CVS $Revision: 1.2 $ $Date: 2000/11/16 03:15:40 $
*/
public abstract class DocumentBuilder {
+ protected DocumentBuilder () {
+ }
+
/**
- * Implementors of this abstract class are not required to provide a
- * public no-argument constructor, since instantiation is taken care
- * by <code>DocumentBuilderFactory</code> implementations.
- */
- protected DocumentBuilder() {
- super();
+ * Parse the content of the given InputStream as an XML document
+ * and return a new DOM Document object.
+ *
+ * @param is InputStream containing the content to be parsed.
+ * @exception IOException If any IO errors occur.
+ * @exception SAXException If any parse errors occur.
+ * @exception IllegalArgumentException If the InputStream is null
+ * @see org.xml.sax.DocumentHandler
+ */
+
+ public Document parse(InputStream is)
+ throws SAXException, IOException
+ {
+ if (is == null) {
+ throw new IllegalArgumentException("InputStream cannot be null");
+ }
+
+ InputSource in = new InputSource(is);
+ return parse(in);
}
/**
- * Parses the contents of the given <code>InputStream</code> and returns
- * a <code>Document</code> object.
+ * Parse the content of the given InputStream as an XML document
+ * and return a new DOM Document object.
*
- * @exception SAXException If there is a problem parsing the given XML
- * content.
- * @exception IOException If any IO errors occur reading the given
- * <code>InputStream</code>.
- * @exception IllegalArgumentException If the given
- * <code>InputStream</code> is <b>null</b>.
- */
- public Document parse(InputStream stream)
- throws SAXException, IOException, IllegalArgumentException {
- if (stream==null) throw new IllegalArgumentException();
- return(this.parse(new InputSource(stream)));
+ * @param is InputStream containing the content to be parsed.
+ * @param systemId Provide a base for resolving relative URIs.
+ * @exception IOException If any IO errors occur.
+ * @exception SAXException If any parse errors occur.
+ * @exception IllegalArgumentException If the InputStream is null
+ * @see org.xml.sax.DocumentHandler
+ */
+
+ public Document parse(InputStream is, String systemId)
+ throws SAXException, IOException
+ {
+ if (is == null) {
+ throw new IllegalArgumentException("InputStream cannot be null");
+ }
+
+ InputSource in = new InputSource(is);
+ in.setSystemId(systemId);
+ return parse(in);
}
/**
- * Parses the content of the given URI and returns a <code>Document</code>
- * object.
+ * Parse the content of the given URI as an XML document
+ * and return a new DOM Document object.
*
- * @exception SAXException If there is a problem parsing the given XML
- * content.
- * @exception IOException If any IO errors occur while reading content
- * located by the given URI.
- * @exception IllegalArgumentException If the given URI is <b>null</b>.
+ * @param uri The location of the content to be parsed.
+ * @exception IOException If any IO errors occur.
+ * @exception SAXException If any parse errors occur.
+ * @exception IllegalArgumentException If the URI is null
+ * @see org.xml.sax.DocumentHandler
*/
+
public Document parse(String uri)
- throws SAXException, IOException, IllegalArgumentException {
- if (uri==null) throw new IllegalArgumentException();
- return(this.parse(new InputSource(uri)));
+ throws SAXException, IOException
+ {
+ if (uri == null) {
+ throw new IllegalArgumentException("URI cannot be null");
+ }
+
+ InputSource in = new InputSource(uri);
+ return parse(in);
}
/**
- * Parses the content of the given <code>File</code> and returns a
- * <code>Document</code> object.
+ * Parse the content of the given file as an XML document
+ * and return a new DOM Document object.
*
- * @exception SAXException If there is a problem parsing the given XML
- * content.
- * @exception IOException if any IO errors occur while reading content
- * from the given <code>File</code>.
- * @exception IllegalArgumentException if the given <code>File</code> is
- * <b>null</b>.
- */
- public Document parse(File file)
- throws SAXException, IOException, IllegalArgumentException {
- if (file==null) throw new IllegalArgumentException();
- // Thanks to Kevin Kress <Ke...@oracle.com> for pointing
- // out this bug.
- return(this.parse(new InputSource(file.getAbsolutePath())));
+ * @param f The file containing the XML to parse
+ * @exception IOException If any IO errors occur.
+ * @exception SAXException If any parse errors occur.
+ * @exception IllegalArgumentException If the file is null
+ * @see org.xml.sax.DocumentHandler
+ */
+
+ public Document parse(File f)
+ throws SAXException, IOException
+ {
+ if (f == null) {
+ throw new IllegalArgumentException("File cannot be null");
+ }
+
+ String uri = "file:" + f.getAbsolutePath();
+ if (File.separatorChar == '\\') {
+ uri = uri.replace('\\', '/');
+ }
+ InputSource in = new InputSource(uri);
+ return parse(in);
}
/**
- * Parses the content of the given <code>InputSource</code> and returns
- * a <code>Document</code> object.
+ * Parse the content of the given input source as an XML document
+ * and return a new DOM Document object.
*
- * @exception SAXException If there is a problem parsing the given XML
- * content.
- * @exception IOException if any IO Errors occur while reading content
- * from the given <code>InputSource</code>.
- * @exception IllegalArgumentException if the given
- * <code>InputSource</code> is <b>null</b>.
- */
- public abstract Document parse(InputSource source)
- throws SAXException, IOException, IllegalArgumentException;
+ * @param is InputSource containing the content to be parsed.
+ * @exception IOException If any IO errors occur.
+ * @exception SAXException If any parse errors occur.
+ * @exception IllegalArgumentException If the InputSource is null
+ * @see org.xml.sax.DocumentHandler
+ */
+
+ public abstract Document parse(InputSource is)
+ throws SAXException, IOException;
+
/**
- * Creates an new <code>Document</code> instance from the underlying DOM
- * implementation.
+ * Indicates whether or not this parser is configured to
+ * understand namespaces.
*/
- public abstract Document newDocument();
- /**
- * Returns whether or not this parser supports XML namespaces.
- */
public abstract boolean isNamespaceAware();
/**
- * Returns whether or not this parser supports validating XML content.
+ * Indicates whether or not this parser is configured to
+ * validate XML documents.
*/
+
public abstract boolean isValidating();
/**
- * Specifies the <code>EntityResolver</code> to be used by this
- * <code>DocumentBuilder</code>.
- * <br>
- * Setting the <code>EntityResolver</code> to <b>null</b>, or not
- * calling this method, will cause the underlying implementation to
- * use its own default implementation and behavior.
+ * Specify the <code>EntityResolver</code> to be used to resolve
+ * entities present in the XML document to be parsed. Setting
+ * this to <code>null</code> will result in the underlying
+ * implementation using it's own default implementation and
+ * behavior.
*/
- public abstract void setEntityResolver(EntityResolver er);
+
+ // XXX
+ // Add that the underlying impl doesn't have to use SAX, but
+ // must understand how to resolve entities from this object.
+
+ public abstract void setEntityResolver(org.xml.sax.EntityResolver er);
/**
- * Specifies the <code>ErrorHandler</code> to be used by this
- * <code>DocumentBuilder</code>.
- *
- * Setting the <code>ErrorHandler</code> to <b>null</b>, or not
- * calling this method, will cause the underlying implementation to
- * use its own default implementation and behavior.
+ * Specify the <code>ErrorHandler</code> to be used to resolve
+ * entities present in the XML document to be parsed. Setting
+ * this to <code>null</code> will result in the underlying
+ * implementation using it's own default implementation and
+ * behavior.
*/
- public abstract void setErrorHandler(ErrorHandler eh);
-}
+ // XXX
+ // Add that the underlying impl doesn't have to use SAX, but
+ // must understand how to handle errors using this object.
+
+ public abstract void setErrorHandler(org.xml.sax.ErrorHandler eh);
+
+ /**
+ * Obtain a new instance of a DOM Document object to build a DOM
+ * tree with.
+ */
+
+ public abstract Document newDocument();
+
+}
1.2 +284 -105 xml-xalan/java/src/javax/xml/parsers/DocumentBuilderFactory.java
Index: DocumentBuilderFactory.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/javax/xml/parsers/DocumentBuilderFactory.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- DocumentBuilderFactory.java 2000/10/02 02:43:03 1.1
+++ DocumentBuilderFactory.java 2000/11/16 03:15:40 1.2
@@ -57,6 +57,15 @@
package javax.xml.parsers;
+import java.io.InputStream;
+import java.io.IOException;
+import java.io.File;
+import java.io.FileInputStream;
+
+import java.util.Properties;
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+
/**
* The <code>DocumentBuilderFactory</code> defines a factory API that enables
* applications to configure and obtain a parser to parse XML documents into
@@ -70,8 +79,8 @@
* http://java.sun.com/aboutJava/communityprocess/jsr/jsr_005_xml.html
* </a><br>
* THIS IMPLEMENTATION IS CONFORMANT TO THE "JAVA API FOR XML PARSING"
- * SPECIFICATION VERSION 1.0 PUBLIC RELEASE 1 BY JAMES DUNCAN DAVIDSON
- * PUBLISHED BY SUN MICROSYSTEMS ON FEB. 18, 2000 AND FOUND AT
+ * SPECIFICATION VERSION 1.1 PUBLIC REVIEW 1 BY JAMES DUNCAN DAVIDSON
+ * PUBLISHED BY SUN MICROSYSTEMS ON NOV. 2, 2000 AND FOUND AT
* <a href="http://java.sun.com/xml">http://java.sun.com/xml</a>
* <br>
* <br>
@@ -88,140 +97,310 @@
*
* @author <a href="pier@betaversion.org">Pierpaolo Fumagalli</a>
* @author Copyright © 2000 The Apache Software Foundation.
- * @version 1.0 CVS $Revision: 1.1 $ $Date: 2000/10/02 02:43:03 $
+ * @version 1.0 CVS $Revision: 1.2 $ $Date: 2000/11/16 03:15:40 $
*/
public abstract class DocumentBuilderFactory {
-
- /** Wether the DocumentBuilder to be generated must support namespaces. */
- private boolean namespaces=false;
- /** Wether the DocumentBuilder to be generated must support validataion. */
- private boolean validation=false;
- /** The system property to check for DocumentBuilderFactory class name. */
- private static String property="javax.xml.parsers.DocumentBuilderFactory";
- /** The default DocumentBuilderFactory implementation class name. */
- private static String factory=
- "org.apache.xerces.jaxp.DocumentBuilderFactoryImpl";
-
- /**
- * Implementors of this abstract class <b>must</b> provide their own
- * public no-argument constructor in order for the static
- * <code>newInstance()</code> method to work correctly.
- * <br>
- * Application programmers should be able to instantiate an implementation
- * of this abstract class directly if they want to use a specfic
- * implementation of this API without using the static newInstance method
- * to obtain the configured or platform default implementation.
- */
- protected DocumentBuilderFactory() {
- super();
+ /** The default property name according to the JAXP spec */
+ private static final String defaultPropName =
+ "javax.xml.parsers.DocumentBuilderFactory";
+
+ private boolean validating = false;
+ private boolean namespaceAware = false;
+ private boolean whitespace = false;
+ private boolean expandEntityRef = false;
+ private boolean ignoreComments = false;
+ private boolean coalescing = false;
+
+ protected DocumentBuilderFactory () {
+
}
/**
+ * Obtain a new instance of a
+ * <code>DocumentBuilderFactory</code>. This static method creates
+ * a new factory instance based on a System property setting or
+ * uses the platform default if no property has been defined.<p>
*
- * Returns a new instance of a <code>DocumentBuilderFactory</code>.
- * <br>
- * The implementation of the <code>DocumentBuilderFactory</code>
- * returned depends on the setting of the
- * <code>javax.xml.parsers.DocumentBuilderFactory</code> property or,
- * if the property is not set, a platform specific default.
+ * The system property that controls which Factory implementation
+ * to create is named
+ * "javax.xml.parsers.DocumentBuilderFactory". This
+ * property names a class that is a concrete subclass of this
+ * abstract class. If no property is defined, a platform default
+ * will be used.<p>
*
- * @exception FactoryConfigurationError If the class implementing the
- * factory cannot be found or instantiated.
- * An <code>Error</code> is thrown instead of an exception
- * because the application is not expected to handle or
- * recover from such events.
- */
+ * Once an application has obtained a reference to a
+ * <code>DocumentBuilderFactory</code> it can use the factory to
+ * configure and obtain parser instances.
+ *
+ * @exception FactoryConfigurationError if the implementation is not
+ * available or cannot be instantiated.
+ */
+
public static DocumentBuilderFactory newInstance() {
-
- // Retrieve the javax.xml.parsers.DocumentBuilderFactory system property
- String n=factory;
- try {
- n=System.getProperty(property, factory);
- } catch (SecurityException e) {
- // In applets System.getProperty throws a SecurityException.
- // Thanks to Aaron Buchanan <ab...@inovacorp.com> and to
- // James Duncan Davidson <ja...@eng.sun.com> for this
- n=factory;
+ String factoryImplName = findFactory(defaultPropName,
+ "org.apache.xerces.jaxp.DocumentBuilderFactoryImpl");
+ // the default can be removed after services are tested well enough
+
+ if (factoryImplName == null) {
+ throw new FactoryConfigurationError(
+ "No default implementation found");
}
+ DocumentBuilderFactory factoryImpl;
try {
- // Attempt to load, instantiate and return the factory class
- return (DocumentBuilderFactory)Class.forName(n).newInstance();
-
- } catch (ClassNotFoundException e) {
- // The factory class was not found
- throw new FactoryConfigurationError("Cannot load class "+
- "DocumentBuilderFactory class \""+n+"\"");
-
- } catch (InstantiationException e) {
- // The factory class wasn't instantiated
- throw new FactoryConfigurationError("Cannot instantiate the "+
- "specified DocumentBuilderFactory class \""+n+"\"");
-
- } catch (IllegalAccessException e) {
- // The factory class couldn't have been accessed
- throw new FactoryConfigurationError("Cannot access the specified "+
- "DocumentBuilderFactory class \""+n+"\"");
-
- } catch (ClassCastException e) {
- // The factory class was not a DocumentBuilderFactory
- throw new FactoryConfigurationError("The specified class \""+n+
- "\" is not instance of \""+
- "javax.xml.parsers.DocumentBuilderFactory\"");
- }
+ Class clazz = Class.forName(factoryImplName);
+ factoryImpl = (DocumentBuilderFactory)clazz.newInstance();
+ } catch (ClassNotFoundException cnfe) {
+ throw new FactoryConfigurationError(cnfe);
+ } catch (IllegalAccessException iae) {
+ throw new FactoryConfigurationError(iae);
+ } catch (InstantiationException ie) {
+ throw new FactoryConfigurationError(ie);
+ }
+ return factoryImpl;
}
-
+
/**
- * Returns a new configured instance of type <code>DocumentBuilder</code>.
+ * Creates a new instance of a DocumentBuilder using the
+ * currently configured parameters.
*
- * @exception ParserConfigurationException If the
- * <code>DocumentBuilder</code> instance cannot be created
- * with the requested configuration.
+ * @exception ParserConfigurationException if a DocumentBuilder
+ * cannot be created which satisfies the configuration requested
*/
+
public abstract DocumentBuilder newDocumentBuilder()
- throws ParserConfigurationException;
-
+ throws ParserConfigurationException;
+
+
/**
- * Configuration method that specifies whether the parsers created by this
- * factory are required to provide XML namespace support or not.
- * <br>
- * <b>NOTE:</b> if a parser cannot be created by this factory that
- * satisfies the requested namespace awareness value, a
- * <code>ParserConfigurationException</code> will be thrown when the
- * program attempts to aquire the parser calling the
- * <code>newDocumentBuilder()</code> method.
- */
- public void setNamespaceAware(boolean aware) {
- this.namespaces=aware;
+ * Specifies that the parser produced by this code will
+ * provide support for XML namespaces.
+ */
+
+ public void setNamespaceAware(boolean awareness) {
+ this.namespaceAware = awareness;
}
/**
- * Configuration method whether specifies if the parsers created by this
- * factory are required to validate the XML documents that they parse.
- * <br>
- * <b>NOTE:</b> if a parser cannot be created by this factory that
- * satisfies the requested validation capacity, a
- * <code>ParserConfigurationException</code> will be thrown when
- * the application attempts to aquire the parser via the
- * <code>newDocumentBuilder()</code> method.
+ * Specifies that the parser produced by this code will
+ * validate documents as they are parsed.
*/
+
public void setValidating(boolean validating) {
- this.validation=validating;
+ this.validating = validating;
+ }
+
+ /**
+ * Specifies that the parser produced by this code will
+ * ignore "ignorable whitespace" ONLY when the document is validated as
+ * they are parsed.
+ */
+
+ public void setIgnoreElementContentWhitespace(boolean whitespace) {
+ this.whitespace = whitespace;
+ }
+
+ /**
+ * Specifies that the parser produced by this code will
+ * expand entity reference nodes.
+ */
+
+ public void setExpandEntityReferences(boolean expandEntityRef) {
+ this.expandEntityRef = expandEntityRef;
+ }
+
+ /**
+ * Specifies that the parser produced by this code will
+ * ignore comments.
+ */
+
+ public void setIgnoringComments(boolean ignoreComments) {
+ this.ignoreComments = ignoreComments;
+ }
+
+ /**
+ * Specifies that the parser produced by this code will
+ * convert CDATA nodes to Text nodes and append it to the
+ * adjacent (if any) text node.
+ */
+
+ public void setCoalescing(boolean coalescing) {
+ this.coalescing = coalescing;
}
/**
- * Indicates if this <code>DocumentBuilderFactory</code> is configured to
- * produce parsers that are namespace aware or not.
+ * Indicates whether or not the factory is configured to produce
+ * parsers which are namespace aware.
*/
+
public boolean isNamespaceAware() {
- return(this.namespaces);
+ return namespaceAware;
}
/**
- * Indicates if this <code>DocumentBuilderFactory</code> is configured to
- * produce parsers that validate XML documents as they are parsed.
+ * Indicates whether or not the factory is configured to produce
+ * parsers which validate the XML content during parse.
*/
+
public boolean isValidating() {
- return(this.validation);
+ return validating;
}
+
+ /**
+ * Indicates whether or not the factory is configured to produce
+ * parsers which ignore "ignorable whitespace" when validated in the XML
+ * content during parse.
+ */
+
+ public boolean isIgnoreElementContentWhitespace() {
+ return whitespace;
+ }
+
+ /**
+ * Indicates whether or not the factory is configured to produce
+ * parsers which expand entity reference nodes.
+ */
+
+ public boolean isExpandEntityReferences() {
+ return expandEntityRef;
+ }
+
+ /**
+ * Indicates whether or not the factory is configured to produce
+ * parsers which ignores comments.
+ */
+
+ public boolean isIgnoringComments() {
+ return ignoreComments;
+ }
+
+ /**
+ * Indicates whether or not the factory is configured to produce
+ * parsers which converts CDATA nodes to Text nodes and appends it to
+ * the adjacent (if any) Text node.
+ */
+
+ public boolean isCoalescing() {
+ return coalescing;
+ }
+
+ /**
+ * Allows the user to set specific attributes on the underlying
+ * implementation.
+ * @param name The name of the attribute.
+ * @param value The value of the attribute.
+ * @exception IllegalArgumentException thrown if the underlying
+ * implementation doesn't recognize the attribute.
+ */
+ public abstract void setAttribute(String name, Object value)
+ throws IllegalArgumentException;
+
+ /**
+ * Allows the user to retrieve specific attributes on the underlying
+ * implementation.
+ * @param name The name of the attribute.
+ * @return value The value of the attribute.
+ * @exception IllegalArgumentException thrown if the underlying
+ * implementation doesn't recognize the attribute.
+ */
+ public abstract Object getAttribute(String name)
+ throws IllegalArgumentException;
+
+ // -------------------- private methods --------------------
+ // This code is duplicated in all factories.
+ // Keep it in sync or move it to a common place
+ // Because it's small probably it's easier to keep it here
+ /** Avoid reading all the files when the findFactory
+ method is called the second time ( cache the result of
+ finding the default impl )
+ */
+ private static String foundFactory=null;
+
+ /** Temp debug code - this will be removed after we test everything
+ */
+ private static final boolean debug=
+ System.getProperty( "jaxp.debug" ) != null;
+
+ /** Private implementation method - will find the implementation
+ class in the specified order.
+ @param factoryId Name of the factory interface
+ @param xmlProperties Name of the properties file based on JAVA/lib
+ @param defaultFactory Default implementation, if nothing else is found
+ */
+ private static String findFactory(String factoryId,
+ String defaultFactory)
+ {
+ // Use the system property first
+ try {
+ String systemProp =
+ System.getProperty( factoryId );
+ if( systemProp!=null) {
+ if( debug )
+ System.err.println("JAXP: found system property" +
+ systemProp );
+ return systemProp;
+ }
+
+ }catch (SecurityException se) {
+ }
+
+ if( foundFactory!=null)
+ return foundFactory;
+
+ // try to read from $java.home/lib/xml.properties
+ try {
+ String javah=System.getProperty( "java.home" );
+ String configFile = javah + File.separator +
+ "lib" + File.separator + "jaxp.properties";
+ File f=new File( configFile );
+ if( f.exists()) {
+ Properties props=new Properties();
+ props.load( new FileInputStream(f));
+ foundFactory=props.getProperty( factoryId );
+ if( debug )
+ System.err.println("JAXP: found java.home property " +
+ foundFactory );
+ if(foundFactory!=null )
+ return foundFactory;
+ }
+ } catch(Exception ex ) {
+ if( debug ) ex.printStackTrace();
+ }
+
+ String serviceId = "META-INF/services/" + factoryId;
+ // try to find services in CLASSPATH
+ try {
+ ClassLoader cl=DocumentBuilderFactory.class.getClassLoader();
+ InputStream is=null;
+ if( cl == null ) {
+ is=ClassLoader.getSystemResourceAsStream( serviceId );
+ } else {
+ is=cl.getResourceAsStream( serviceId );
+ }
+
+ if( is!=null ) {
+ if( debug )
+ System.err.println("JAXP: found " +
+ serviceId);
+ BufferedReader rd=new BufferedReader( new
+ InputStreamReader(is));
+
+ foundFactory=rd.readLine();
+ rd.close();
+
+ if( debug )
+ System.err.println("JAXP: loaded from services: " +
+ foundFactory );
+ if( foundFactory != null &&
+ ! "".equals( foundFactory) ) {
+ return foundFactory;
+ }
+ }
+ } catch( Exception ex ) {
+ if( debug ) ex.printStackTrace();
+ }
+
+ return defaultFactory;
+ }
+
}
1.2 +63 -24 xml-xalan/java/src/javax/xml/parsers/FactoryConfigurationError.java
Index: FactoryConfigurationError.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/javax/xml/parsers/FactoryConfigurationError.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- FactoryConfigurationError.java 2000/10/02 02:43:03 1.1
+++ FactoryConfigurationError.java 2000/11/16 03:15:40 1.2
@@ -76,8 +76,8 @@
* http://java.sun.com/aboutJava/communityprocess/jsr/jsr_005_xml.html
* </a><br>
* THIS IMPLEMENTATION IS CONFORMANT TO THE "JAVA API FOR XML PARSING"
- * SPECIFICATION VERSION 1.0 PUBLIC RELEASE 1 BY JAMES DUNCAN DAVIDSON
- * PUBLISHED BY SUN MICROSYSTEMS ON FEB. 18, 2000 AND FOUND AT
+ * SPECIFICATION VERSION 1.1 PUBLIC REVIEW 1 BY JAMES DUNCAN DAVIDSON
+ * PUBLISHED BY SUN MICROSYSTEMS ON NOV. 2, 2000 AND FOUND AT
* <a href="http://java.sun.com/xml">http://java.sun.com/xml</a>
* <br>
* <br>
@@ -94,52 +94,91 @@
*
* @author <a href="pier@betaversion.org">Pierpaolo Fumagalli</a>
* @author Copyright © 2000 The Apache Software Foundation.
- * @version 1.0 CVS $Revision: 1.1 $ $Date: 2000/10/02 02:43:03 $
+ * @version 1.0 CVS $Revision: 1.2 $ $Date: 2000/11/16 03:15:40 $
*/
public class FactoryConfigurationError extends Error {
- /** The root cause of this <code>FactoryConfigurationError</code>. */
- private Exception exception=null;
+ private Exception exception;
/**
- * Constructs a new <code>FactoryConfigurationError</code> with no
- * detail message.
+ * Create a new <code>FactoryConfigurationError</code> with no
+ * detail mesage.
*/
- public FactoryConfigurationError() {
- this(null,null);
- }
+
+ public FactoryConfigurationError() {
+ super();
+ this.exception = null;
+ }
/**
- * Constructs a new <code>FactoryConfigurationError</code> with the
- * given detail message.
+ * Create a new <code>FactoryConfigurationError</code> with
+ * the <code>String </code> specified as an error message.
+ *
+ * @param msg The error message for the exception.
*/
+
public FactoryConfigurationError(String msg) {
- this(null,msg);
+ super(msg);
+ this.exception = null;
}
+
/**
- * Constructs a new <code>FactoryConfigurationError</code> with the
- * given <code>Exception</code> as a root cause.
+ * Create a new <code>FactoryConfigurationError</code> with a
+ * given <code>Exception</code> base cause of the error.
+ *
+ * @param e The exception to be encapsulated in a
+ * FactoryConfigurationError.
*/
+
public FactoryConfigurationError(Exception e) {
- this(e,null);
+ super();
+ this.exception = e;
}
/**
- * Constructs a new <code>FactoryConfigurationError</code> with the
- * given <code>Exception</code> as a root cause and the given detail
- * message.
+ * Create a new <code>FactoryConfigurationError</code> with the
+ * given <code>Exception</code> base cause and detail message.
+ *
+ * @param e The exception to be encapsulated in a
+ * FactoryConfigurationError
+ * @param msg The detail message.
+ * @param e The exception to be wrapped in a FactoryConfigurationError
*/
+
public FactoryConfigurationError(Exception e, String msg) {
super(msg);
- this.exception=e;
+ this.exception = e;
}
+
/**
- * Returns the root cause of this <code>FactoryConfigurationError</code>
- * or <b>null</b> if there is none.
+ * Return the message (if any) for this error . If there is no
+ * message for the exception and there is an encapsulated
+ * exception then the message of that exception will be returned.
+ *
+ * @return The error message.
*/
- public Exception getException() {
- return(this.exception);
+
+ public String getMessage () {
+ String message = super.getMessage ();
+
+ if (message == null && exception != null) {
+ return exception.getMessage();
+ }
+
+ return message;
}
+
+ /**
+ * Return the actual exception (if any) that caused this exception to
+ * be raised.
+ *
+ * @return The encapsulated exception, or null if there is none.
+ */
+
+ public Exception getException () {
+ return exception;
+ }
}
+
1.2 +3 -3 xml-xalan/java/src/javax/xml/parsers/ParserConfigurationException.java
Index: ParserConfigurationException.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/javax/xml/parsers/ParserConfigurationException.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ParserConfigurationException.java 2000/10/02 02:43:03 1.1
+++ ParserConfigurationException.java 2000/11/16 03:15:40 1.2
@@ -77,8 +77,8 @@
* http://java.sun.com/aboutJava/communityprocess/jsr/jsr_005_xml.html
* </a><br>
* THIS IMPLEMENTATION IS CONFORMANT TO THE "JAVA API FOR XML PARSING"
- * SPECIFICATION VERSION 1.0 PUBLIC RELEASE 1 BY JAMES DUNCAN DAVIDSON
- * PUBLISHED BY SUN MICROSYSTEMS ON FEB. 18, 2000 AND FOUND AT
+ * SPECIFICATION VERSION 1.1 PUBLIC REVIEW 1 BY JAMES DUNCAN DAVIDSON
+ * PUBLISHED BY SUN MICROSYSTEMS ON NOV. 2, 2000 AND FOUND AT
* <a href="http://java.sun.com/xml">http://java.sun.com/xml</a>
* <br>
* <br>
@@ -95,7 +95,7 @@
*
* @author <a href="pier@betaversion.org">Pierpaolo Fumagalli</a>
* @author Copyright © 2000 The Apache Software Foundation.
- * @version 1.0 CVS $Revision: 1.1 $ $Date: 2000/10/02 02:43:03 $
+ * @version 1.0 CVS $Revision: 1.2 $ $Date: 2000/11/16 03:15:40 $
*/
public class ParserConfigurationException extends Exception {
1.2 +304 -94 xml-xalan/java/src/javax/xml/parsers/SAXParser.java
Index: SAXParser.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/javax/xml/parsers/SAXParser.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- SAXParser.java 2000/10/02 02:43:03 1.1
+++ SAXParser.java 2000/11/16 03:15:40 1.2
@@ -60,10 +60,20 @@
import java.io.File;
import java.io.InputStream;
import java.io.IOException;
+import java.io.FileInputStream;
+import java.util.Locale;
+import java.util.Properties;
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+
+import org.xml.sax.Parser;
+import org.xml.sax.XMLReader;
import org.xml.sax.HandlerBase;
+import org.xml.sax.helpers.DefaultHandler;
import org.xml.sax.InputSource;
-import org.xml.sax.Parser;
import org.xml.sax.SAXException;
+import org.xml.sax.SAXNotRecognizedException;
+import org.xml.sax.SAXNotSupportedException;
/**
* Implementation instances of the <code>SAXParser</code> abstract class
@@ -83,8 +93,8 @@
* http://java.sun.com/aboutJava/communityprocess/jsr/jsr_005_xml.html
* </a><br>
* THIS IMPLEMENTATION IS CONFORMANT TO THE "JAVA API FOR XML PARSING"
- * SPECIFICATION VERSION 1.0 PUBLIC RELEASE 1 BY JAMES DUNCAN DAVIDSON
- * PUBLISHED BY SUN MICROSYSTEMS ON FEB. 18, 2000 AND FOUND AT
+ * SPECIFICATION VERSION 1.1 PUBLIC REVIEW 1 BY JAMES DUNCAN DAVIDSON
+ * PUBLISHED BY SUN MICROSYSTEMS ON NOV. 2, 2000 AND FOUND AT
* <a href="http://java.sun.com/xml">http://java.sun.com/xml</a>
* <br>
* <br>
@@ -101,135 +111,335 @@
*
* @author <a href="pier@betaversion.org">Pierpaolo Fumagalli</a>
* @author Copyright © 2000 The Apache Software Foundation.
- * @version 1.0 CVS $Revision: 1.1 $ $Date: 2000/10/02 02:43:03 $
+ * @version 1.0 CVS $Revision: 1.2 $ $Date: 2000/11/16 03:15:40 $
*/
+
public abstract class SAXParser {
- /**
- * Implementations should provide a protected constructor so that
- * their factory implementation can instantiate instances of the
- * implementation class.
- * <br>
- * Application programmers should not be able to directly construct
- * implementation subclasses of this abstract subclass. The only way a
- * application should be able to obtain a reference to a SAXParser
- * implementation instance is by using the appropriate methods of the
- * <code>SAXParserFactory</code>.
- */
- protected SAXParser() {
- super();
+ protected SAXParser () {
+
}
/**
- * Parses the contents of the given <code>InputStream</code> as an XML
- * document using the specified <code>HandlerBase</code> object.
+ * Parse the content of the given <code>java.io.InputStream</code>
+ * instance as XML using the specified
+ * <code>org.xml.sax.HandlerBase</code>.
*
- * @exception SAXException If there is a problem parsing the given XML
- * content.
- * @exception IOException If any IO errors occur reading the given
- * <code>InputStream</code>.
- * @exception IllegalArgumentException If the given
- * <code>InputStream</code> is <b>null</b>.
+ * @param is InputStream containing the content to be parsed.
+ * @param hb The SAX HandlerBase to use.
+ * @exception IOException If any IO errors occur.
+ * @exception IllegalArgumentException If the given InputStream is null.
+ * @see org.xml.sax.DocumentHandler
*/
- public void parse(InputStream stream, HandlerBase base)
- throws SAXException, IOException, IllegalArgumentException {
- if (stream==null) throw new IllegalArgumentException();
- this.parse(new InputSource(stream),base);
+
+ public void parse(InputStream is, HandlerBase hb)
+ throws SAXException, IOException
+ {
+ if (is == null) {
+ throw new IllegalArgumentException("InputStream cannot be null");
+ }
+
+ InputSource input = new InputSource(is);
+ this.parse(input, hb);
}
/**
- * Parses the content of the given URI as an XML document using the
- * specified <code>HandlerBase</code> object.
+ * Parse the content of the given <code>java.io.InputStream</code>
+ * instance as XML using the specified
+ * <code>org.xml.sax.HandlerBase</code>.
*
- * @exception SAXException If there is a problem parsing the given XML
- * content.
- * @exception IOException If any IO errors occur while reading content
- * located by the given URI.
- * @exception IllegalArgumentException If the given URI is <b>null</b>.
+ * @param is InputStream containing the content to be parsed.
+ * @param hb The SAX HandlerBase to use.
+ * @param systemId The systemId which is needed for resolving relative URIs.
+ * @exception IOException If any IO errors occur.
+ * @exception IllegalArgumentException If the given InputStream is null.
+ * @see org.xml.sax.DocumentHandler
+ * version of this method instead.
*/
- public void parse(String uri, HandlerBase base)
- throws SAXException, IOException, IllegalArgumentException {
- if (uri==null) throw new IllegalArgumentException();
- this.parse(new InputSource(uri),base);
+
+ public void parse(InputStream is, HandlerBase hb, String systemId)
+ throws SAXException, IOException
+ {
+ if (is == null) {
+ throw new IllegalArgumentException("InputStream cannot be null");
+ }
+
+ InputSource input = new InputSource(is);
+ input.setSystemId(systemId);
+ this.parse(input, hb);
}
+
+ /**
+ * Parse the content of the given <code>java.io.InputStream</code>
+ * instance as XML using the specified
+ * <code>org.xml.sax.helpers.DefaultHandler</code>.
+ *
+ * @param is InputStream containing the content to be parsed.
+ * @param hb The SAX HandlerBase to use.
+ * @exception IOException If any IO errors occur.
+ * @exception IllegalArgumentException If the given InputStream is null.
+ * @see org.xml.sax.DocumentHandler
+ */
+
+ public void parse(InputStream is, DefaultHandler dh)
+ throws SAXException, IOException
+ {
+ if (is == null) {
+ throw new IllegalArgumentException("InputStream cannot be null");
+ }
+
+ InputSource input = new InputSource(is);
+ this.parse(input, dh);
+ }
/**
- * Parses the content of the given <code>File</code> as an XML document
- * using the specified <code>HandlerBase</code> object.
+ * Parse the content of the given <code>java.io.InputStream</code>
+ * instance as XML using the specified
+ * <code>org.xml.sax.helpers.DefaultHandler</code>.
*
- * @exception SAXException If there is a problem parsing the given XML
- * content.
- * @exception IOException if any IO errors occur while reading content
- * from the given <code>File</code>.
- * @exception IllegalArgumentException if the given <code>File</code> is
- * <b>null</b>.
+ * @param is InputStream containing the content to be parsed.
+ * @param hb The SAX HandlerBase to use.
+ * @param systemId The systemId which is needed for resolving relative URIs.
+ * @exception IOException If any IO errors occur.
+ * @exception IllegalArgumentException If the given InputStream is null.
+ * @see org.xml.sax.DocumentHandler
+ * version of this method instead.
*/
- public void parse(File file, HandlerBase base)
- throws SAXException, IOException, IllegalArgumentException {
- if (file==null) throw new IllegalArgumentException();
- String path = file.getAbsolutePath();
- if (File.separatorChar != '/') {
- path = path.replace(File.separatorChar, '/');
+
+ public void parse(InputStream is, DefaultHandler dh, String systemId)
+ throws SAXException, IOException
+ {
+ if (is == null) {
+ throw new IllegalArgumentException("InputStream cannot be null");
}
- if (!path.startsWith("/")) {
- path = "/" + path;
+
+ InputSource input = new InputSource(is);
+ input.setSystemId(systemId);
+ this.parse(input, dh);
+ }
+
+ /**
+ * Parse the content described by the giving Uniform Resource
+ * Identifier (URI) as XML using the specified
+ * <code>org.xml.sax.HandlerBase</code>.
+ *
+ * @param uri The location of the content to be parsed.
+ * @param hb The SAX HandlerBase to use.
+ * @exception IOException If any IO errors occur.
+ * @exception IllegalArgumentException If the uri is null.
+ * @see org.xml.sax.DocumentHandler
+ */
+
+ public void parse(String uri, HandlerBase hb)
+ throws SAXException, IOException
+ {
+ if (uri == null) {
+ throw new IllegalArgumentException("uri cannot be null");
}
- if (!path.endsWith("/") && file.isDirectory()) {
- path = path + "/";
+
+ InputSource input = new InputSource(uri);
+ this.parse(input, hb);
+ }
+
+ /**
+ * Parse the content described by the giving Uniform Resource
+ * Identifier (URI) as XML using the specified
+ * <code>org.xml.sax.helpers.DefaultHandler</code>.
+ *
+ * @param uri The location of the content to be parsed.
+ * @param hb The SAX HandlerBase to use.
+ * @exception IOException If any IO errors occur.
+ * @exception IllegalArgumentException If the uri is null.
+ * @see org.xml.sax.DocumentHandler
+ */
+
+ public void parse(String uri, DefaultHandler dh)
+ throws SAXException, IOException
+ {
+ if (uri == null) {
+ throw new IllegalArgumentException("uri cannot be null");
}
- java.net.URL url = new java.net.URL("file", "", path);
- this.parse(new InputSource(url.toString()),base);
+
+ InputSource input = new InputSource(uri);
+ this.parse(input, dh);
}
-
+
/**
- * Parses the content of the given <code>InputSource</code> as an XML
- * document using the specified <code>HandlerBase</code> object.
+ * Parse the content of the file specified as XML using the
+ * specified <code>org.xml.sax.HandlerBase</code>.
*
- * @exception SAXException If there is a problem parsing the given XML
- * content.
- * @exception IOException if any IO Errors occur while reading content
- * from the given <code>InputSource</code>.
- * @exception IllegalArgumentException if the given
- * <code>InputSource</code> is <b>null</b>.
+ * @param f The file containing the XML to parse
+ * @param hb The SAX HandlerBase to use.
+ * @exception IOException If any IO errors occur.
+ * @exception IllegalArgumentException If the File object is null.
+ * @see org.xml.sax.DocumentHandler
*/
- public void parse(InputSource source, HandlerBase base)
- throws SAXException, IOException, IllegalArgumentException {
- if (source==null) throw new IllegalArgumentException();
-
- // Get the SAX parser instance
- Parser p=this.getParser();
- // Set the various handler instances
- if (base!=null) {
- p.setDocumentHandler(base);
- p.setDTDHandler(base);
- p.setEntityResolver(base);
- p.setErrorHandler(base);
+ public void parse(File f, HandlerBase hb)
+ throws SAXException, IOException
+ {
+ if (f == null) {
+ throw new IllegalArgumentException("File cannot be null");
}
-
- // Parse the specified source
- p.parse(source);
+
+ String uri = "file:" + f.getAbsolutePath();
+ if (File.separatorChar == '\\') {
+ uri = uri.replace('\\', '/');
+ }
+ InputSource input = new InputSource(uri);
+ this.parse(input, hb);
}
+
+ /**
+ * Parse the content of the file specified as XML using the
+ * specified <code>org.xml.sax.helpers.DefaultHandler</code>.
+ *
+ * @param f The file containing the XML to parse
+ * @param dh The SAX Handler to use.
+ * @exception IOException If any IO errors occur.
+ * @exception IllegalArgumentException If the File object is null.
+ * @see org.xml.sax.DocumentHandler
+ */
+ public void parse(File f, DefaultHandler dh)
+ throws SAXException, IOException
+ {
+ if (f == null) {
+ throw new IllegalArgumentException("File cannot be null");
+ }
+
+ String uri = "file:" + f.getAbsolutePath();
+ if (File.separatorChar == '\\') {
+ uri = uri.replace('\\', '/');
+ }
+ InputSource input = new InputSource(uri);
+ this.parse(input, dh);
+ }
+
/**
- * Returns the underlying <code>Parser</code> object which is wrapped by
- * this <code>SAXParser</code> implementation.
+ * Parse the content given <code>org.xml.sax.InputSource</code>
+ * as XML using the specified
+ * <code>org.xml.sax.HandlerBase</code>.
*
- * @exception SAXException If the initialization of the underlying parser
- * fails. <b>NOTE:</b> This Exception is specified on page
- * 21 of the specification, but later on omissed in this
- * method documentation on page 23. Wich one is correct?
+ * @param is The InputSource containing the content to be parsed.
+ * @param hb The SAX HandlerBase to use.
+ * @exception IOException If any IO errors occur.
+ * @exception IllegalArgumentException If the InputSource is null.
+ * @see org.xml.sax.DocumentHandler
*/
- public abstract Parser getParser()
- throws SAXException;
+
+ public void parse(InputSource is, HandlerBase hb)
+ throws SAXException, IOException
+ {
+ if (is == null) {
+ throw new IllegalArgumentException("InputSource cannot be null");
+ }
+
+ Parser parser = this.getParser();
+ if (hb != null) {
+ parser.setDocumentHandler(hb);
+ parser.setEntityResolver(hb);
+ parser.setErrorHandler(hb);
+ parser.setDTDHandler(hb);
+ }
+ parser.parse(is);
+ }
+
+ /**
+ * Parse the content given <code>org.xml.sax.InputSource</code>
+ * as XML using the specified
+ * <code>org.xml.sax.helpers.DefaultHandler</code>.
+ *
+ * @param is The InputSource containing the content to be parsed.
+ * @param dh The SAX DefaultHandler to use.
+ * @exception IOException If any IO errors occur.
+ * @exception IllegalArgumentException If the InputSource is null.
+ * @see org.xml.sax.DocumentHandler
+ */
+
+ public void parse(InputSource is, DefaultHandler dh)
+ throws SAXException, IOException
+ {
+ if (is == null) {
+ throw new IllegalArgumentException("InputSource cannot be null");
+ }
+
+ XMLReader reader = this.getXMLReader();
+ if (dh != null) {
+ reader.setContentHandler(dh);
+ reader.setEntityResolver(dh);
+ reader.setErrorHandler(dh);
+ reader.setDTDHandler(dh);
+ }
+ reader.parse(is);
+ }
+
+ /**
+ * Returns the SAX parser that is encapsultated by the
+ * implementation of this class.
+ */
+
+ public abstract org.xml.sax.Parser getParser() throws SAXException;
+
+ /**
+ * Returns the XMLReader that is encapsulated by the
+ * implementation of this class.
+ */
+ public abstract org.xml.sax.XMLReader getXMLReader() throws SAXException;
+
/**
- * Returns whether or not this parser supports XML namespaces.
+ * Indicates whether or not this parser is configured to
+ * understand namespaces.
*/
+
public abstract boolean isNamespaceAware();
/**
- * Returns whether or not this parser supports validating XML content.
+ * Indicates whether or not this parser is configured to
+ * validate XML documents.
*/
+
public abstract boolean isValidating();
+
+ /**
+ * Sets the particular property in the underlying implementation of
+ * org.xml.sax.XMLReader.
+ *
+ * @param name The name of the property to be set.
+ * @param value The value of the property to be set.
+ * @exception SAXNotRecognizedException When the underlying XMLReader does
+ * not recognize the property name.
+ *
+ * @exception SAXNotSupportedException When the underlying XMLReader
+ * recognizes the property name but doesn't support the
+ * property.
+ *
+ * @see org.xml.sax.XMLReader#setProperty
+ */
+ public abstract void setProperty(String name, Object value)
+ throws SAXNotRecognizedException, SAXNotSupportedException;
+
+ /**
+ *
+ * returns the particular property requested for in the underlying
+ * implementation of org.xml.sax.XMLReader.
+ *
+ * @param name The name of the property to be retrieved.
+ * @return Value of the requested property.
+ *
+ * @exception SAXNotRecognizedException When the underlying XMLReader does
+ * not recognize the property name.
+ *
+ * @exception SAXNotSupportedException When the underlying XMLReader
+ * recognizes the property name but doesn't support the
+ * property.
+ *
+ * @see org.xml.sax.XMLReader#getProperty
+ */
+ public abstract Object getProperty(String name)
+ throws SAXNotRecognizedException, SAXNotSupportedException;
+
+
+
}
1.3 +231 -105 xml-xalan/java/src/javax/xml/parsers/SAXParserFactory.java
Index: SAXParserFactory.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/javax/xml/parsers/SAXParserFactory.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- SAXParserFactory.java 2000/10/30 18:56:07 1.2
+++ SAXParserFactory.java 2000/11/16 03:15:40 1.3
@@ -57,8 +57,21 @@
package javax.xml.parsers;
+import org.xml.sax.Parser;
import org.xml.sax.SAXException;
+import org.xml.sax.SAXNotRecognizedException;
+import org.xml.sax.SAXNotSupportedException;
+import java.io.InputStream;
+import java.io.IOException;
+import java.io.File;
+import java.io.FileInputStream;
+import java.util.Locale;
+
+import java.util.Properties;
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+
/**
* The <code>SAXParserFactory</code> defines a factory API that enables
* applications to configure and obtain a SAX based parser to parse XML
@@ -72,8 +85,8 @@
* http://java.sun.com/aboutJava/communityprocess/jsr/jsr_005_xml.html
* </a><br>
* THIS IMPLEMENTATION IS CONFORMANT TO THE "JAVA API FOR XML PARSING"
- * SPECIFICATION VERSION 1.0 PUBLIC RELEASE 1 BY JAMES DUNCAN DAVIDSON
- * PUBLISHED BY SUN MICROSYSTEMS ON FEB. 18, 2000 AND FOUND AT
+ * SPECIFICATION VERSION 1.1 PUBLIC REVIEW 1 BY JAMES DUNCAN DAVIDSON
+ * PUBLISHED BY SUN MICROSYSTEMS ON NOV. 2, 2000 AND FOUND AT
* <a href="http://java.sun.com/xml">http://java.sun.com/xml</a>
* <br>
* <br>
@@ -90,140 +103,253 @@
*
* @author <a href="pier@betaversion.org">Pierpaolo Fumagalli</a>
* @author Copyright © 2000 The Apache Software Foundation.
- * @version 1.0 CVS $Revision: 1.2 $ $Date: 2000/10/30 18:56:07 $
+ * @version 1.0 CVS $Revision: 1.3 $ $Date: 2000/11/16 03:15:40 $
*/
-public abstract class SAXParserFactory {
- /** Wether the SAXParser to be generated must support namespaces. */
- private boolean namespaces=false;
- /** Wether the SAXParser to be generated must support validataion. */
- private boolean validation=false;
- /** The system property to check for the SAXParserFactory class name. */
- private static String property="javax.xml.parsers.SAXParserFactory";
- /** The default SAXParserFactory implementation class name. */
- private static String factory="org.apache.xerces.jaxp.SAXParserFactoryImpl";
-
- /**
- * Implementors of this abstract class <b>must</b> provide their own
- * public no-argument constructor in order for the static
- * <code>newInstance()</code> method to work correctly.
- * <br>
- * Application programmers should be able to instantiate an implementation
- * of this abstract class directly if they want to use a specfic
- * implementation of this API without using the static newInstance method
- * to obtain the configured or platform default implementation.
- */
- protected SAXParserFactory() {
- super();
+public abstract class SAXParserFactory {
+ /** The default property name according to the JAXP spec */
+ private static final String defaultPropName =
+ "javax.xml.parsers.SAXParserFactory";
+
+ private boolean validating = false;
+ private boolean namespaceAware= false;
+
+ protected SAXParserFactory () {
+
}
/**
- * Returns a new instance of a <code>SAXParserFactory</code>.
- * <br>
- * The implementation of the SAX-ParserFactory returned depends on the
- * setting of the <code>javax.xml.parsers.SAXParserFactory</code>
- * system property or, if the property is not set, a platform specific
- * default.
- *
- * @exception FactoryConfigurationError If the class implementing the
- * factory cannot be found or instantiated.
- * An <code>Error</code> is thrown instead of an exception
- * because the application is not expected to handle or
- * recover from such events.
+ * Obtain a new instance of a <code>SAXParserFactory</code>. This
+ * static method creates a new factory instance based on a System
+ * property setting or uses the platform default if no property
+ * has been defined.<p>
+ *
+ * The system property that controls which Factory implementation
+ * to create is named
+ * "javax.xml.parsers.SAXParserFactory". This property
+ * names a class that is a concrete subclass of this abstract
+ * class. If no property is defined, a platform default will be
+ * used.<p>
+ *
+ * Once an application has obtained a reference to a
+ * <code>SAXParserFactory</code> it can use the factory to
+ * configure and obtain parser instances.
+ *
+ * @exception FactoryConfigurationError if the implementation is
+ * not available or cannot be instantiated.
*/
- public static SAXParserFactory newInstance()
- {
- // Retrieve the javax.xml.parsers.SAXParserFactory system property
- String n=factory;
- try {
- n=System.getProperty(property, factory);
- } catch (SecurityException e) {
- // In applets System.getProperty throws a SecurityException.
- // Thanks to Aaron Buchanan <ab...@inovacorp.com> and to
- // James Duncan Davidson <ja...@eng.sun.com> for this
- n=factory;
+ public static SAXParserFactory newInstance() {
+ String factoryImplName = findFactory(defaultPropName,
+ "org.apache.xerces.jaxp.SAXParserFactoryImpl");
+ // the default can be removed after services are tested well enough
+
+ if (factoryImplName == null) {
+ throw new FactoryConfigurationError(
+ "No default implementation found");
}
+ SAXParserFactory factoryImpl = null;
try {
- // Attempt to load, instantiate and return the factory class
- return (SAXParserFactory)Class.forName(n).newInstance();
-
- } catch (ClassNotFoundException e) {
- // The factory class was not found
- throw new FactoryConfigurationError("Cannot load class "+
- "SAXParserFactory class \""+n+"\"");
-
- } catch (InstantiationException e) {
- // The factory class wasn't instantiated
- throw new FactoryConfigurationError("Cannot instantiate the "+
- "specified SAXParserFactory class \""+n+"\"");
-
- } catch (IllegalAccessException e) {
- // The factory class couldn't have been accessed
- throw new FactoryConfigurationError("Cannot access the specified "+
- "SAXParserFactory class \""+n+"\"");
-
- } catch (ClassCastException e) {
- // The factory class was not a SAXParserFactory
- throw new FactoryConfigurationError("The specified class \""+n+
- "\" is not instance of \"javax.xml.parsers.SAXParserFactory\"");
- }
+ Class clazz = Class.forName(factoryImplName);
+ factoryImpl = (SAXParserFactory)clazz.newInstance();
+ } catch (ClassNotFoundException cnfe) {
+ throw new FactoryConfigurationError(cnfe);
+ } catch (IllegalAccessException iae) {
+ throw new FactoryConfigurationError(iae);
+ } catch (InstantiationException ie) {
+ throw new FactoryConfigurationError(ie);
+ }
+ return factoryImpl;
}
-
+
/**
- * Returns a new configured instance of type <code>SAXParser</code>.
+ * Creates a new instance of a SAXParser using the currently
+ * configured factory parameters.
*
- * @exception ParserConfigurationException If the <code>SAXParser</code>
- * instance cannot be created with the requested
- * configuration.
- * @exception SAXException If the initialization of the underlying parser
- * fails.
+ * @exception ParserConfigurationException if a parser cannot
+ * be created which satisfies the requested configuration.
*/
+
public abstract SAXParser newSAXParser()
- throws ParserConfigurationException, SAXException;
+ throws ParserConfigurationException, SAXException;
+
/**
- * Configuration method that specifies whether the parsers created by this
- * factory are required to provide XML namespace support or not.
- * <br>
- * <b>NOTE:</b> if a parser cannot be created by this factory that
- * satisfies the requested namespace awareness value, a
- * <code>ParserConfigurationException</code> will be thrown when the
- * program attempts to aquire the parser calling the
- * <code>newSaxParser()</code> method.
+ * Specifies that the parser produced by this code will
+ * provide support for XML namespaces.
*/
- public void setNamespaceAware(boolean aware) {
- this.namespaces=aware;
+
+ public void setNamespaceAware(boolean awareness)
+ {
+ this.namespaceAware = awareness;
}
/**
- * Configuration method whether specifies if the parsers created by this
- * factory are required to validate the XML documents that they parse.
- * <br>
- * <b>NOTE:</b> if a parser cannot be created by this factory that
- * satisfies the requested validation capacity, a
- * <code>ParserConfigurationException</code> will be thrown when
- * the application attempts to aquire the parser via the
- * <code>newSaxParser()</code> method.
+ * Specifies that the parser produced by this code will
+ * validate documents as they are parsed.
*/
- public void setValidating(boolean validating) {
- this.validation=validating;
+
+ public void setValidating(boolean validating)
+ {
+ this.validating = validating;
}
/**
- * Indicates if this <code>SAXParserFactory</code> is configured to
- * produce parsers that are namespace aware or not.
+ * Indicates whether or not the factory is configured to produce
+ * parsers which are namespace aware.
*/
+
public boolean isNamespaceAware() {
- return(this.namespaces);
+ return namespaceAware;
}
/**
- * Indicates if this <code>SAXParserFactory</code> is configured to
- * produce parsers that validate XML documents as they are parsed.
+ * Indicates whether or not the factory is configured to produce
+ * parsers which validate the XML content during parse.
*/
+
public boolean isValidating() {
- return(this.validation);
+ return validating;
+ }
+
+ /**
+ *
+ * Sets the particular feature in the underlying implementation of
+ * org.xml.sax.XMLReader.
+ *
+ * @param name The name of the feature to be set.
+ * @param value The value of the feature to be set.
+ * @exception SAXNotRecognizedException When the underlying XMLReader does
+ * not recognize the property name.
+ *
+ * @exception SAXNotSupportedException When the underlying XMLReader
+ * recognizes the property name but doesn't support the
+ * property.
+ *
+ * @see org.xml.sax.XMLReader#setFeature
+ */
+ public abstract void setFeature(String name, boolean value)
+ throws ParserConfigurationException, SAXNotRecognizedException,
+ SAXNotSupportedException;
+
+ /**
+ *
+ * returns the particular property requested for in the underlying
+ * implementation of org.xml.sax.XMLReader.
+ *
+ * @param name The name of the property to be retrieved.
+ * @return Value of the requested property.
+ *
+ * @exception SAXNotRecognizedException When the underlying XMLReader does
+ * not recognize the property name.
+ *
+ * @exception SAXNotSupportedException When the underlying XMLReader
+ * recognizes the property name but doesn't support the
+ * property.
+ *
+ * @see org.xml.sax.XMLReader#getProperty
+ */
+ public abstract boolean getFeature(String name)
+ throws ParserConfigurationException, SAXNotRecognizedException,
+ SAXNotSupportedException;
+
+
+ // -------------------- private methods --------------------
+ // This code is duplicated in all factories.
+ // Keep it in sync or move it to a common place
+ // Because it's small probably it's easier to keep it here
+ /** Avoid reading all the files when the findFactory
+ method is called the second time ( cache the result of
+ finding the default impl )
+ */
+ private static String foundFactory=null;
+
+ /** Temp debug code - this will be removed after we test everything
+ */
+ private static final boolean debug=
+ System.getProperty( "jaxp.debug" ) != null;
+
+ /** Private implementation method - will find the implementation
+ class in the specified order.
+ @param factoryId Name of the factory interface
+ @param xmlProperties Name of the properties file based on JAVA/lib
+ @param defaultFactory Default implementation, if nothing else is found
+ */
+ private static String findFactory(String factoryId,
+ String defaultFactory)
+ {
+ // Use the system property first
+ try {
+ String systemProp =
+ System.getProperty( factoryId );
+ if( systemProp!=null) {
+ if( debug )
+ System.err.println("JAXP: found system property" +
+ systemProp );
+ return systemProp;
+ }
+
+ }catch (SecurityException se) {
+ }
+
+
+ if( foundFactory!=null)
+ return foundFactory;
+
+ // try to read from $java.home/lib/jaxp.properties
+ try {
+ String javah=System.getProperty( "java.home" );
+ String configFile = javah + File.separator +
+ "lib" + File.separator + "jaxp.properties";
+ File f=new File( configFile );
+ if( f.exists()) {
+ Properties props=new Properties();
+ props.load( new FileInputStream(f));
+ foundFactory=props.getProperty( factoryId );
+ if( debug )
+ System.err.println("JAXP: found java.home property " +
+ foundFactory );
+ if(foundFactory!=null )
+ return foundFactory;
+ }
+ } catch(Exception ex ) {
+ if( debug ) ex.printStackTrace();
+ }
+
+ String serviceId = "META-INF/services/" + factoryId;
+ // try to find services in CLASSPATH
+ try {
+ ClassLoader cl=SAXParserFactory.class.getClassLoader();
+ InputStream is=null;
+ if( cl == null ) {
+ is=ClassLoader.getSystemResourceAsStream( serviceId );
+ } else {
+ is=cl.getResourceAsStream( serviceId );
+ }
+
+ if( is!=null ) {
+ if( debug )
+ System.err.println("JAXP: found " +
+ serviceId);
+ BufferedReader rd=new BufferedReader( new
+ InputStreamReader(is));
+
+ foundFactory=rd.readLine();
+ rd.close();
+
+ if( debug )
+ System.err.println("JAXP: loaded from services: " +
+ foundFactory );
+ if( foundFactory != null &&
+ ! "".equals( foundFactory) ) {
+ return foundFactory;
+ }
+ }
+ } catch( Exception ex ) {
+ if( debug ) ex.printStackTrace();
+ }
+
+ return defaultFactory;
}
}