8054834: Modular Source Code

Co-authored-by: Alan Bateman <alan.bateman@oracle.com>
Co-authored-by: Alex Buckley <alex.buckley@oracle.com>
Co-authored-by: Erik Joelsson <erik.joelsson@oracle.com>
Co-authored-by: Jonathan Gibbons <jonathan.gibbons@oracle.com>
Co-authored-by: Karen Kinnear <karen.kinnear@oracle.com>
Co-authored-by: Magnus Ihse Bursie <magnus.ihse.bursie@oracle.com>
Co-authored-by: Mandy Chung <mandy.chung@oracle.com>
Co-authored-by: Mark Reinhold <mark.reinhold@oracle.com>
Co-authored-by: Paul Sandoz <paul.sandoz@oracle.com>
Reviewed-by: alanb, chegar, ihse, mduigou
This commit is contained in:
Chris Hegarty 2014-08-17 15:51:56 +01:00
parent e35087b430
commit 786f3dbbdf
2059 changed files with 0 additions and 1770 deletions

View file

@ -0,0 +1,349 @@
/*
* Copyright (c) 2000, 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.xml.parsers;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import javax.xml.validation.Schema;
import org.w3c.dom.Document;
import org.w3c.dom.DOMImplementation;
import org.xml.sax.EntityResolver;
import org.xml.sax.ErrorHandler;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
/**
* Defines the API to obtain DOM Document instances from an XML
* document. Using this class, an application programmer can obtain a
* {@link Document} from XML.<p>
*
* An instance of this class can be obtained from the
* {@link DocumentBuilderFactory#newDocumentBuilder()} method. Once
* an instance of this class is obtained, XML can be parsed from a
* variety of input sources. These input sources are InputStreams,
* Files, URLs, and SAX InputSources.<p>
*
* Note that this class reuses several classes from the SAX API. This
* does not require that the implementor of the underlying DOM
* implementation use a SAX parser to parse XML document into a
* <code>Document</code>. It merely requires that the implementation
* communicate with the application using these existing APIs.
*
* @author <a href="mailto:Jeff.Suttor@Sun.com">Jeff Suttor</a>
* @since 1.4
*/
public abstract class DocumentBuilder {
/** Protected constructor */
protected DocumentBuilder () {
}
/**
* <p>Reset this <code>DocumentBuilder</code> to its original configuration.</p>
*
* <p><code>DocumentBuilder</code> is reset to the same state as when it was created with
* {@link DocumentBuilderFactory#newDocumentBuilder()}.
* <code>reset()</code> is designed to allow the reuse of existing <code>DocumentBuilder</code>s
* thus saving resources associated with the creation of new <code>DocumentBuilder</code>s.</p>
*
* <p>The reset <code>DocumentBuilder</code> is not guaranteed to have the same {@link EntityResolver} or {@link ErrorHandler}
* <code>Object</code>s, e.g. {@link Object#equals(Object obj)}. It is guaranteed to have a functionally equal
* <code>EntityResolver</code> and <code>ErrorHandler</code>.</p>
*
* @throws UnsupportedOperationException When implementation does not
* override this method.
*
* @since 1.5
*/
public void reset() {
// implementors should override this method
throw new UnsupportedOperationException(
"This DocumentBuilder, \"" + this.getClass().getName() + "\", does not support the reset functionality."
+ " Specification \"" + this.getClass().getPackage().getSpecificationTitle() + "\""
+ " version \"" + this.getClass().getPackage().getSpecificationVersion() + "\""
);
}
/**
* Parse the content of the given <code>InputStream</code> as an XML
* document and return a new DOM {@link Document} object.
* An <code>IllegalArgumentException</code> is thrown if the
* <code>InputStream</code> is null.
*
* @param is InputStream containing the content to be parsed.
*
* @return <code>Document</code> result of parsing the
* <code>InputStream</code>
*
* @throws IOException If any IO errors occur.
* @throws SAXException If any parse errors occur.
* @throws IllegalArgumentException When <code>is</code> is <code>null</code>
*
* @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);
}
/**
* Parse the content of the given <code>InputStream</code> as an
* XML document and return a new DOM {@link Document} object.
* An <code>IllegalArgumentException</code> is thrown if the
* <code>InputStream</code> is null.
*
* @param is InputStream containing the content to be parsed.
* @param systemId Provide a base for resolving relative URIs.
*
* @return A new DOM Document object.
*
* @throws IOException If any IO errors occur.
* @throws SAXException If any parse errors occur.
* @throws IllegalArgumentException When <code>is</code> is <code>null</code>
*
* @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);
}
/**
* Parse the content of the given URI as an XML document
* and return a new DOM {@link Document} object.
* An <code>IllegalArgumentException</code> is thrown if the
* URI is <code>null</code> null.
*
* @param uri The location of the content to be parsed.
*
* @return A new DOM Document object.
*
* @throws IOException If any IO errors occur.
* @throws SAXException If any parse errors occur.
* @throws IllegalArgumentException When <code>uri</code> is <code>null</code>
*
* @see org.xml.sax.DocumentHandler
*/
public Document parse(String uri)
throws SAXException, IOException {
if (uri == null) {
throw new IllegalArgumentException("URI cannot be null");
}
InputSource in = new InputSource(uri);
return parse(in);
}
/**
* Parse the content of the given file as an XML document
* and return a new DOM {@link Document} object.
* An <code>IllegalArgumentException</code> is thrown if the
* <code>File</code> is <code>null</code> null.
*
* @param f The file containing the XML to parse.
*
* @throws IOException If any IO errors occur.
* @throws SAXException If any parse errors occur.
* @throws IllegalArgumentException When <code>f</code> is <code>null</code>
*
* @see org.xml.sax.DocumentHandler
* @return A new DOM Document object.
*/
public Document parse(File f) throws SAXException, IOException {
if (f == null) {
throw new IllegalArgumentException("File cannot be null");
}
//convert file to appropriate URI, f.toURI().toASCIIString()
//converts the URI to string as per rule specified in
//RFC 2396,
InputSource in = new InputSource(f.toURI().toASCIIString());
return parse(in);
}
/**
* Parse the content of the given input source as an XML document
* and return a new DOM {@link Document} object.
* An <code>IllegalArgumentException</code> is thrown if the
* <code>InputSource</code> is <code>null</code> null.
*
* @param is InputSource containing the content to be parsed.
*
* @return A new DOM Document object.
*
* @throws IOException If any IO errors occur.
* @throws SAXException If any parse errors occur.
* @throws IllegalArgumentException When <code>is</code> is <code>null</code>
*
* @see org.xml.sax.DocumentHandler
*/
public abstract Document parse(InputSource is)
throws SAXException, IOException;
/**
* Indicates whether or not this parser is configured to
* understand namespaces.
*
* @return true if this parser is configured to understand
* namespaces; false otherwise.
*/
public abstract boolean isNamespaceAware();
/**
* Indicates whether or not this parser is configured to
* validate XML documents.
*
* @return true if this parser is configured to validate
* XML documents; false otherwise.
*/
public abstract boolean isValidating();
/**
* Specify the {@link EntityResolver} 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.
*
* @param er The <code>EntityResolver</code> to be used to resolve entities
* present in the XML document to be parsed.
*/
public abstract void setEntityResolver(EntityResolver er);
/**
* Specify the {@link ErrorHandler} to be used by the parser.
* Setting this to <code>null</code> will result in the underlying
* implementation using it's own default implementation and
* behavior.
*
* @param eh The <code>ErrorHandler</code> to be used by the parser.
*/
public abstract void setErrorHandler(ErrorHandler eh);
/**
* Obtain a new instance of a DOM {@link Document} object
* to build a DOM tree with.
*
* @return A new instance of a DOM Document object.
*/
public abstract Document newDocument();
/**
* Obtain an instance of a {@link DOMImplementation} object.
*
* @return A new instance of a <code>DOMImplementation</code>.
*/
public abstract DOMImplementation getDOMImplementation();
/** <p>Get current state of canonicalization.</p>
*
* @return current state canonicalization control
*/
/*
public boolean getCanonicalization() {
return canonicalState;
}
*/
/** <p>Get a reference to the the {@link Schema} being used by
* the XML processor.</p>
*
* <p>If no schema is being used, <code>null</code> is returned.</p>
*
* @return {@link Schema} being used or <code>null</code>
* if none in use
*
* @throws UnsupportedOperationException When implementation does not
* override this method
*
* @since 1.5
*/
public Schema getSchema() {
throw new UnsupportedOperationException(
"This parser does not support specification \""
+ this.getClass().getPackage().getSpecificationTitle()
+ "\" version \""
+ this.getClass().getPackage().getSpecificationVersion()
+ "\""
);
}
/**
* <p>Get the XInclude processing mode for this parser.</p>
*
* @return
* the return value of
* the {@link DocumentBuilderFactory#isXIncludeAware()}
* when this parser was created from factory.
*
* @throws UnsupportedOperationException When implementation does not
* override this method
*
* @since 1.5
*
* @see DocumentBuilderFactory#setXIncludeAware(boolean)
*/
public boolean isXIncludeAware() {
throw new UnsupportedOperationException(
"This parser does not support specification \""
+ this.getClass().getPackage().getSpecificationTitle()
+ "\" version \""
+ this.getClass().getPackage().getSpecificationVersion()
+ "\""
);
}
}

View file

@ -0,0 +1,608 @@
/*
* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.xml.parsers;
import javax.xml.validation.Schema;
/**
* Defines a factory API that enables applications to obtain a
* parser that produces DOM object trees from XML documents.
*
* @author <a href="mailto:Jeff.Suttor@Sun.com">Jeff Suttor</a>
* @author <a href="mailto:Neeraj.Bajaj@sun.com">Neeraj Bajaj</a>
*
* @since 1.4
*/
public abstract class DocumentBuilderFactory {
private boolean validating = false;
private boolean namespaceAware = false;
private boolean whitespace = false;
private boolean expandEntityRef = true;
private boolean ignoreComments = false;
private boolean coalescing = false;
/**
* <p>Protected constructor to prevent instantiation.
* Use {@link #newInstance()}.</p>
*/
protected DocumentBuilderFactory () {
}
/**
* Obtain a new instance of a
* <code>DocumentBuilderFactory</code>. This static method creates
* a new factory instance.
* This method uses the following ordered lookup procedure to determine
* the <code>DocumentBuilderFactory</code> implementation class to
* load:
* <ul>
* <li>
* Use the <code>javax.xml.parsers.DocumentBuilderFactory</code> system
* property.
* </li>
* <li>
* Use the properties file "lib/jaxp.properties" in the JRE directory.
* This configuration file is in standard <code>java.util.Properties
* </code> format and contains the fully qualified name of the
* implementation class with the key being the system property defined
* above.
*
* The jaxp.properties file is read only once by the JAXP implementation
* and it's values are then cached for future use. If the file does not exist
* when the first attempt is made to read from it, no further attempts are
* made to check for its existence. It is not possible to change the value
* of any property in jaxp.properties after it has been read for the first time.
* </li>
* <li>
* Uses the service-provider loading facilities, defined by the
* {@link java.util.ServiceLoader} class, to attempt to locate and load an
* implementation of the service using the {@linkplain
* java.util.ServiceLoader#load(java.lang.Class) default loading mechanism}:
* the service-provider loading facility will use the {@linkplain
* java.lang.Thread#getContextClassLoader() current thread's context class loader}
* to attempt to load the service. If the context class
* loader is null, the {@linkplain
* ClassLoader#getSystemClassLoader() system class loader} will be used.
* </li>
* <li>
* Otherwise, the system-default implementation is returned.
* </li>
* </ul>
*
* Once an application has obtained a reference to a
* <code>DocumentBuilderFactory</code> it can use the factory to
* configure and obtain parser instances.
*
*
* <h2>Tip for Trouble-shooting</h2>
* <p>Setting the <code>jaxp.debug</code> system property will cause
* this method to print a lot of debug messages
* to <code>System.err</code> about what it is doing and where it is looking at.</p>
*
* <p> If you have problems loading {@link DocumentBuilder}s, try:</p>
* <pre>
* java -Djaxp.debug=1 YourProgram ....
* </pre>
*
* @return New instance of a <code>DocumentBuilderFactory</code>
*
* @throws FactoryConfigurationError in case of {@linkplain
* java.util.ServiceConfigurationError service configuration error} or if
* the implementation is not available or cannot be instantiated.
*/
public static DocumentBuilderFactory newInstance() {
return FactoryFinder.find(
/* The default property name according to the JAXP spec */
DocumentBuilderFactory.class, // "javax.xml.parsers.DocumentBuilderFactory"
/* The fallback implementation class name */
"com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl");
}
/**
* <p>Obtain a new instance of a <code>DocumentBuilderFactory</code> from class name.
* This function is useful when there are multiple providers in the classpath.
* It gives more control to the application as it can specify which provider
* should be loaded.</p>
*
* <p>Once an application has obtained a reference to a <code>DocumentBuilderFactory</code>
* it can use the factory to configure and obtain parser instances.</p>
*
*
* <h2>Tip for Trouble-shooting</h2>
* <p>Setting the <code>jaxp.debug</code> system property will cause
* this method to print a lot of debug messages
* to <code>System.err</code> about what it is doing and where it is looking at.</p>
*
* <p> If you have problems try:</p>
* <pre>
* java -Djaxp.debug=1 YourProgram ....
* </pre>
*
* @param factoryClassName fully qualified factory class name that provides implementation of <code>javax.xml.parsers.DocumentBuilderFactory</code>.
*
* @param classLoader <code>ClassLoader</code> used to load the factory class. If <code>null</code>
* current <code>Thread</code>'s context classLoader is used to load the factory class.
*
* @return New instance of a <code>DocumentBuilderFactory</code>
*
* @throws FactoryConfigurationError if <code>factoryClassName</code> is <code>null</code>, or
* the factory class cannot be loaded, instantiated.
*
* @see #newInstance()
*
* @since 1.6
*/
public static DocumentBuilderFactory newInstance(String factoryClassName, ClassLoader classLoader){
//do not fallback if given classloader can't find the class, throw exception
return FactoryFinder.newInstance(DocumentBuilderFactory.class,
factoryClassName, classLoader, false);
}
/**
* Creates a new instance of a {@link javax.xml.parsers.DocumentBuilder}
* using the currently configured parameters.
*
* @return A new instance of a DocumentBuilder.
*
* @throws ParserConfigurationException if a DocumentBuilder
* cannot be created which satisfies the configuration requested.
*/
public abstract DocumentBuilder newDocumentBuilder()
throws ParserConfigurationException;
/**
* Specifies that the parser produced by this code will
* provide support for XML namespaces. By default the value of this is set
* to <code>false</code>
*
* @param awareness true if the parser produced will provide support
* for XML namespaces; false otherwise.
*/
public void setNamespaceAware(boolean awareness) {
this.namespaceAware = awareness;
}
/**
* Specifies that the parser produced by this code will
* validate documents as they are parsed. By default the value of this
* is set to <code>false</code>.
*
* <p>
* Note that "the validation" here means
* <a href="http://www.w3.org/TR/REC-xml#proc-types">a validating
* parser</a> as defined in the XML recommendation.
* In other words, it essentially just controls the DTD validation.
* (except the legacy two properties defined in JAXP 1.2.)
* </p>
*
* <p>
* To use modern schema languages such as W3C XML Schema or
* RELAX NG instead of DTD, you can configure your parser to be
* a non-validating parser by leaving the {@link #setValidating(boolean)}
* method <code>false</code>, then use the {@link #setSchema(Schema)}
* method to associate a schema to a parser.
* </p>
*
* @param validating true if the parser produced will validate documents
* as they are parsed; false otherwise.
*/
public void setValidating(boolean validating) {
this.validating = validating;
}
/**
* Specifies that the parsers created by this factory must eliminate
* whitespace in element content (sometimes known loosely as
* 'ignorable whitespace') when parsing XML documents (see XML Rec
* 2.10). Note that only whitespace which is directly contained within
* element content that has an element only content model (see XML
* Rec 3.2.1) will be eliminated. Due to reliance on the content model
* this setting requires the parser to be in validating mode. By default
* the value of this is set to <code>false</code>.
*
* @param whitespace true if the parser created must eliminate whitespace
* in the element content when parsing XML documents;
* false otherwise.
*/
public void setIgnoringElementContentWhitespace(boolean whitespace) {
this.whitespace = whitespace;
}
/**
* Specifies that the parser produced by this code will
* expand entity reference nodes. By default the value of this is set to
* <code>true</code>
*
* @param expandEntityRef true if the parser produced will expand entity
* reference nodes; false otherwise.
*/
public void setExpandEntityReferences(boolean expandEntityRef) {
this.expandEntityRef = expandEntityRef;
}
/**
* <p>Specifies that the parser produced by this code will
* ignore comments. By default the value of this is set to <code>false
* </code>.</p>
*
* @param ignoreComments <code>boolean</code> value to ignore comments during processing
*/
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. By default the value of this is set to
* <code>false</code>
*
* @param coalescing true if the parser produced will convert CDATA nodes
* to Text nodes and append it to the adjacent (if any)
* text node; false otherwise.
*/
public void setCoalescing(boolean coalescing) {
this.coalescing = coalescing;
}
/**
* Indicates whether or not the factory is configured to produce
* parsers which are namespace aware.
*
* @return true if the factory is configured to produce parsers which
* are namespace aware; false otherwise.
*/
public boolean isNamespaceAware() {
return namespaceAware;
}
/**
* Indicates whether or not the factory is configured to produce
* parsers which validate the XML content during parse.
*
* @return true if the factory is configured to produce parsers
* which validate the XML content during parse; false otherwise.
*/
public boolean isValidating() {
return validating;
}
/**
* Indicates whether or not the factory is configured to produce
* parsers which ignore ignorable whitespace in element content.
*
* @return true if the factory is configured to produce parsers
* which ignore ignorable whitespace in element content;
* false otherwise.
*/
public boolean isIgnoringElementContentWhitespace() {
return whitespace;
}
/**
* Indicates whether or not the factory is configured to produce
* parsers which expand entity reference nodes.
*
* @return true if the factory is configured to produce parsers
* which expand entity reference nodes; false otherwise.
*/
public boolean isExpandEntityReferences() {
return expandEntityRef;
}
/**
* Indicates whether or not the factory is configured to produce
* parsers which ignores comments.
*
* @return true if the factory is configured to produce parsers
* which ignores comments; false otherwise.
*/
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.
*
* @return true if the factory is configured to produce parsers
* which converts CDATA nodes to Text nodes and appends it to
* the adjacent (if any) Text node; false otherwise.
*/
public boolean isCoalescing() {
return coalescing;
}
/**
* Allows the user to set specific attributes on the underlying
* implementation.
* <p>
* All implementations that implement JAXP 1.5 or newer are required to
* support the {@link javax.xml.XMLConstants#ACCESS_EXTERNAL_DTD} and
* {@link javax.xml.XMLConstants#ACCESS_EXTERNAL_SCHEMA} properties.
* </p>
* <ul>
* <li>
* <p>
* Setting the {@link javax.xml.XMLConstants#ACCESS_EXTERNAL_DTD} property
* restricts the access to external DTDs, external Entity References to the
* protocols specified by the property.
* If access is denied during parsing due to the restriction of this property,
* {@link org.xml.sax.SAXException} will be thrown by the parse methods defined by
* {@link javax.xml.parsers.DocumentBuilder}.
* </p>
* <p>
* Setting the {@link javax.xml.XMLConstants#ACCESS_EXTERNAL_SCHEMA} property
* restricts the access to external Schema set by the schemaLocation attribute to
* the protocols specified by the property. If access is denied during parsing
* due to the restriction of this property, {@link org.xml.sax.SAXException}
* will be thrown by the parse methods defined by
* {@link javax.xml.parsers.DocumentBuilder}.
* </p>
* </li>
* </ul>
*
* @param name The name of the attribute.
* @param value The value of the attribute.
*
* @throws 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.
*
* @throws IllegalArgumentException thrown if the underlying
* implementation doesn't recognize the attribute.
*/
public abstract Object getAttribute(String name)
throws IllegalArgumentException;
/**
* <p>Set a feature for this <code>DocumentBuilderFactory</code> and <code>DocumentBuilder</code>s created by this factory.</p>
*
* <p>
* Feature names are fully qualified {@link java.net.URI}s.
* Implementations may define their own features.
* A {@link ParserConfigurationException} is thrown if this <code>DocumentBuilderFactory</code> or the
* <code>DocumentBuilder</code>s it creates cannot support the feature.
* It is possible for a <code>DocumentBuilderFactory</code> to expose a feature value but be unable to change its state.
* </p>
*
* <p>
* All implementations are required to support the {@link javax.xml.XMLConstants#FEATURE_SECURE_PROCESSING} feature.
* When the feature is:</p>
* <ul>
* <li>
* <code>true</code>: the implementation will limit XML processing to conform to implementation limits.
* Examples include entity expansion limits and XML Schema constructs that would consume large amounts of resources.
* If XML processing is limited for security reasons, it will be reported via a call to the registered
* {@link org.xml.sax.ErrorHandler#fatalError(SAXParseException exception)}.
* See {@link DocumentBuilder#setErrorHandler(org.xml.sax.ErrorHandler errorHandler)}.
* </li>
* <li>
* <code>false</code>: the implementation will processing XML according to the XML specifications without
* regard to possible implementation limits.
* </li>
* </ul>
*
* @param name Feature name.
* @param value Is feature state <code>true</code> or <code>false</code>.
*
* @throws ParserConfigurationException if this <code>DocumentBuilderFactory</code> or the <code>DocumentBuilder</code>s
* it creates cannot support this feature.
* @throws NullPointerException If the <code>name</code> parameter is null.
* @since 1.5
*/
public abstract void setFeature(String name, boolean value)
throws ParserConfigurationException;
/**
* <p>Get the state of the named feature.</p>
*
* <p>
* Feature names are fully qualified {@link java.net.URI}s.
* Implementations may define their own features.
* An {@link ParserConfigurationException} is thrown if this <code>DocumentBuilderFactory</code> or the
* <code>DocumentBuilder</code>s it creates cannot support the feature.
* It is possible for an <code>DocumentBuilderFactory</code> to expose a feature value but be unable to change its state.
* </p>
*
* @param name Feature name.
*
* @return State of the named feature.
*
* @throws ParserConfigurationException if this <code>DocumentBuilderFactory</code>
* or the <code>DocumentBuilder</code>s it creates cannot support this feature.
* @since 1.5
*/
public abstract boolean getFeature(String name)
throws ParserConfigurationException;
/**
* Gets the {@link Schema} object specified through
* the {@link #setSchema(Schema schema)} method.
*
* @return
* the {@link Schema} object that was last set through
* the {@link #setSchema(Schema)} method, or null
* if the method was not invoked since a {@link DocumentBuilderFactory}
* is created.
*
* @throws UnsupportedOperationException When implementation does not
* override this method.
*
* @since 1.5
*/
public Schema getSchema() {
throw new UnsupportedOperationException(
"This parser does not support specification \""
+ this.getClass().getPackage().getSpecificationTitle()
+ "\" version \""
+ this.getClass().getPackage().getSpecificationVersion()
+ "\""
);
}
/**
* <p>Set the {@link Schema} to be used by parsers created
* from this factory.
*
* <p>
* When a {@link Schema} is non-null, a parser will use a validator
* created from it to validate documents before it passes information
* down to the application.
*
* <p>When errors are found by the validator, the parser is responsible
* to report them to the user-specified {@link org.xml.sax.ErrorHandler}
* (or if the error handler is not set, ignore them or throw them), just
* like any other errors found by the parser itself.
* In other words, if the user-specified {@link org.xml.sax.ErrorHandler}
* is set, it must receive those errors, and if not, they must be
* treated according to the implementation specific
* default error handling rules.
*
* <p>
* A validator may modify the outcome of a parse (for example by
* adding default values that were missing in documents), and a parser
* is responsible to make sure that the application will receive
* modified DOM trees.
*
* <p>
* Initially, null is set as the {@link Schema}.
*
* <p>
* This processing will take effect even if
* the {@link #isValidating()} method returns <code>false</code>.
*
* <p>It is an error to use
* the <code>http://java.sun.com/xml/jaxp/properties/schemaSource</code>
* property and/or the <code>http://java.sun.com/xml/jaxp/properties/schemaLanguage</code>
* property in conjunction with a {@link Schema} object.
* Such configuration will cause a {@link ParserConfigurationException}
* exception when the {@link #newDocumentBuilder()} is invoked.</p>
*
*
* <h4>Note for implementors</h4>
*
* <p>
* A parser must be able to work with any {@link Schema}
* implementation. However, parsers and schemas are allowed
* to use implementation-specific custom mechanisms
* as long as they yield the result described in the specification.
* </p>
*
* @param schema <code>Schema</code> to use or <code>null</code>
* to remove a schema.
*
* @throws UnsupportedOperationException When implementation does not
* override this method.
*
* @since 1.5
*/
public void setSchema(Schema schema) {
throw new UnsupportedOperationException(
"This parser does not support specification \""
+ this.getClass().getPackage().getSpecificationTitle()
+ "\" version \""
+ this.getClass().getPackage().getSpecificationVersion()
+ "\""
);
}
/**
* <p>Set state of XInclude processing.</p>
*
* <p>If XInclude markup is found in the document instance, should it be
* processed as specified in <a href="http://www.w3.org/TR/xinclude/">
* XML Inclusions (XInclude) Version 1.0</a>.</p>
*
* <p>XInclude processing defaults to <code>false</code>.</p>
*
* @param state Set XInclude processing to <code>true</code> or
* <code>false</code>
*
* @throws UnsupportedOperationException When implementation does not
* override this method.
*
* @since 1.5
*/
public void setXIncludeAware(final boolean state) {
if (state) {
throw new UnsupportedOperationException(" setXIncludeAware " +
"is not supported on this JAXP" +
" implementation or earlier: " + this.getClass());
}
}
/**
* <p>Get state of XInclude processing.</p>
*
* @return current state of XInclude processing
*
* @throws UnsupportedOperationException When implementation does not
* override this method.
*
* @since 1.5
*/
public boolean isXIncludeAware() {
throw new UnsupportedOperationException(
"This parser does not support specification \""
+ this.getClass().getPackage().getSpecificationTitle()
+ "\" version \""
+ this.getClass().getPackage().getSpecificationVersion()
+ "\""
);
}
}

View file

@ -0,0 +1,135 @@
/*
* Copyright (c) 2000, 2005, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.xml.parsers;
/**
* Thrown when a problem with configuration with the Parser Factories
* exists. This error will typically be thrown when the class of a
* parser factory specified in the system properties cannot be found
* or instantiated.
*
* @author <a href="mailto:Jeff.Suttor@Sun.com">Jeff Suttor</a>
* @since 1.4
*/
public class FactoryConfigurationError extends Error {
private static final long serialVersionUID = -827108682472263355L;
/**
*<code>Exception</code> that represents the error.
*/
private Exception exception;
/**
* Create a new <code>FactoryConfigurationError</code> with no
* detail message.
*/
public FactoryConfigurationError() {
super();
this.exception = null;
}
/**
* 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) {
super(msg);
this.exception = null;
}
/**
* 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) {
super(e.toString());
this.exception = e;
}
/**
* 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.
*/
public FactoryConfigurationError(Exception e, String msg) {
super(msg);
this.exception = e;
}
/**
* 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, if it exists will be
* returned. Else the name of the encapsulated exception will be
* returned.
*
* @return The error message.
*/
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;
}
/**
* use the exception chaining mechanism of JDK1.4
*/
@Override
public Throwable getCause() {
return exception;
}
}

View file

@ -0,0 +1,316 @@
/*
* Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.xml.parsers;
import java.io.File;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.Iterator;
import java.util.Properties;
import java.util.ServiceConfigurationError;
import java.util.ServiceLoader;
/**
* <p>Implements pluggable Parsers.</p>
*
* <p>This class is duplicated for each JAXP subpackage so keep it in
* sync. It is package private for secure class loading.</p>
*
* @author Santiago.PericasGeertsen@sun.com
* @author Huizhe.Wang@oracle.com
*/
class FactoryFinder {
private static final String DEFAULT_PACKAGE = "com.sun.org.apache.xerces.internal";
/**
* Internal debug flag.
*/
private static boolean debug = false;
/**
* Cache for properties in java.home/lib/jaxp.properties
*/
private static final Properties cacheProps = new Properties();
/**
* Flag indicating if properties from java.home/lib/jaxp.properties
* have been cached.
*/
static volatile boolean firstTime = true;
/**
* Security support class use to check access control before
* getting certain system resources.
*/
private static final SecuritySupport ss = new SecuritySupport();
// Define system property "jaxp.debug" to get output
static {
// Use try/catch block to support applets, which throws
// SecurityException out of this code.
try {
String val = ss.getSystemProperty("jaxp.debug");
// Allow simply setting the prop to turn on debug
debug = val != null && !"false".equals(val);
}
catch (SecurityException se) {
debug = false;
}
}
private static void dPrint(String msg) {
if (debug) {
System.err.println("JAXP: " + msg);
}
}
/**
* Attempt to load a class using the class loader supplied. If that fails
* and fall back is enabled, the current (i.e. bootstrap) class loader is
* tried.
*
* If the class loader supplied is <code>null</code>, first try using the
* context class loader followed by the current (i.e. bootstrap) class
* loader.
*
* Use bootstrap classLoader if cl = null and useBSClsLoader is true
*/
static private Class<?> getProviderClass(String className, ClassLoader cl,
boolean doFallback, boolean useBSClsLoader) throws ClassNotFoundException
{
try {
if (cl == null) {
if (useBSClsLoader) {
return Class.forName(className, false, FactoryFinder.class.getClassLoader());
} else {
cl = ss.getContextClassLoader();
if (cl == null) {
throw new ClassNotFoundException();
}
else {
return Class.forName(className, false, cl);
}
}
}
else {
return Class.forName(className, false, cl);
}
}
catch (ClassNotFoundException e1) {
if (doFallback) {
// Use current class loader - should always be bootstrap CL
return Class.forName(className, false, FactoryFinder.class.getClassLoader());
}
else {
throw e1;
}
}
}
/**
* Create an instance of a class. Delegates to method
* <code>getProviderClass()</code> in order to load the class.
*
* @param type Base class / Service interface of the factory to
* instantiate.
*
* @param className Name of the concrete class corresponding to the
* service provider
*
* @param cl <code>ClassLoader</code> used to load the factory class. If <code>null</code>
* current <code>Thread</code>'s context classLoader is used to load the factory class.
*
* @param doFallback True if the current ClassLoader should be tried as
* a fallback if the class is not found using cl
*/
static <T> T newInstance(Class<T> type, String className, ClassLoader cl,
boolean doFallback)
throws FactoryConfigurationError
{
return newInstance(type, className, cl, doFallback, false);
}
/**
* Create an instance of a class. Delegates to method
* <code>getProviderClass()</code> in order to load the class.
*
* @param type Base class / Service interface of the factory to
* instantiate.
*
* @param className Name of the concrete class corresponding to the
* service provider
*
* @param cl <code>ClassLoader</code> used to load the factory class. If <code>null</code>
* current <code>Thread</code>'s context classLoader is used to load the factory class.
*
* @param doFallback True if the current ClassLoader should be tried as
* a fallback if the class is not found using cl
*
* @param useBSClsLoader True if cl=null actually meant bootstrap classLoader. This parameter
* is needed since DocumentBuilderFactory/SAXParserFactory defined null as context classLoader.
*/
static <T> T newInstance(Class<T> type, String className, ClassLoader cl,
boolean doFallback, boolean useBSClsLoader)
throws FactoryConfigurationError
{
assert type != null;
// make sure we have access to restricted packages
if (System.getSecurityManager() != null) {
if (className != null && className.startsWith(DEFAULT_PACKAGE)) {
cl = null;
useBSClsLoader = true;
}
}
try {
Class<?> providerClass = getProviderClass(className, cl, doFallback, useBSClsLoader);
if (!type.isAssignableFrom(providerClass)) {
throw new ClassCastException(className + " cannot be cast to " + type.getName());
}
Object instance = providerClass.newInstance();
if (debug) { // Extra check to avoid computing cl strings
dPrint("created new instance of " + providerClass +
" using ClassLoader: " + cl);
}
return type.cast(instance);
}
catch (ClassNotFoundException x) {
throw new FactoryConfigurationError(x,
"Provider " + className + " not found");
}
catch (Exception x) {
throw new FactoryConfigurationError(x,
"Provider " + className + " could not be instantiated: " + x);
}
}
/**
* Finds the implementation Class object in the specified order. Main
* entry point.
* @return Class object of factory, never null
*
* @param type Base class / Service interface of the
* factory to find.
* @param fallbackClassName Implementation class name, if nothing else
* is found. Use null to mean no fallback.
*
* Package private so this code can be shared.
*/
static <T> T find(Class<T> type, String fallbackClassName)
throws FactoryConfigurationError
{
final String factoryId = type.getName();
dPrint("find factoryId =" + factoryId);
// Use the system property first
try {
String systemProp = ss.getSystemProperty(factoryId);
if (systemProp != null) {
dPrint("found system property, value=" + systemProp);
return newInstance(type, systemProp, null, true);
}
}
catch (SecurityException se) {
if (debug) se.printStackTrace();
}
// try to read from $java.home/lib/jaxp.properties
try {
if (firstTime) {
synchronized (cacheProps) {
if (firstTime) {
String configFile = ss.getSystemProperty("java.home") + File.separator +
"lib" + File.separator + "jaxp.properties";
File f = new File(configFile);
firstTime = false;
if (ss.doesFileExist(f)) {
dPrint("Read properties file "+f);
cacheProps.load(ss.getFileInputStream(f));
}
}
}
}
final String factoryClassName = cacheProps.getProperty(factoryId);
if (factoryClassName != null) {
dPrint("found in $java.home/jaxp.properties, value=" + factoryClassName);
return newInstance(type, factoryClassName, null, true);
}
}
catch (Exception ex) {
if (debug) ex.printStackTrace();
}
// Try Jar Service Provider Mechanism
T provider = findServiceProvider(type);
if (provider != null) {
return provider;
}
if (fallbackClassName == null) {
throw new FactoryConfigurationError(
"Provider for " + factoryId + " cannot be found");
}
dPrint("loaded from fallback value: " + fallbackClassName);
return newInstance(type, fallbackClassName, null, true);
}
/*
* Try to find provider using the ServiceLoader API
*
* @param type Base class / Service interface of the factory to find.
*
* @return instance of provider class if found or null
*/
private static <T> T findServiceProvider(final Class<T> type) {
try {
return AccessController.doPrivileged(new PrivilegedAction<T>() {
public T run() {
final ServiceLoader<T> serviceLoader = ServiceLoader.load(type);
final Iterator<T> iterator = serviceLoader.iterator();
if (iterator.hasNext()) {
return iterator.next();
} else {
return null;
}
}
});
} catch(ServiceConfigurationError e) {
// It is not possible to wrap an error directly in
// FactoryConfigurationError - so we need to wrap the
// ServiceConfigurationError in a RuntimeException.
// The alternative would be to modify the logic in
// FactoryConfigurationError to allow setting a
// Throwable as the cause, but that could cause
// compatibility issues down the road.
final RuntimeException x = new RuntimeException(
"Provider for " + type + " cannot be created", e);
final FactoryConfigurationError error =
new FactoryConfigurationError(x, x.getMessage());
throw error;
}
}
}

View file

@ -0,0 +1,57 @@
/*
* Copyright (c) 2000, 2005, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.xml.parsers;
/**
* Indicates a serious configuration error.
*
* @author <a href="mailto:Jeff.Suttor@Sun.com">Jeff Suttor</a>
* @since 1.4
*/
public class ParserConfigurationException extends Exception {
/**
* Create a new <code>ParserConfigurationException</code> with no
* detail message.
*/
public ParserConfigurationException() {
super();
}
/**
* Create a new <code>ParserConfigurationException</code> with
* the <code>String</code> specified as an error message.
*
* @param msg The error message for the exception.
*/
public ParserConfigurationException(String msg) {
super(msg);
}
}

View file

@ -0,0 +1,556 @@
/*
* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.xml.parsers;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import javax.xml.validation.Schema;
import org.xml.sax.HandlerBase;
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;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.DefaultHandler;
/**
* Defines the API that wraps an {@link org.xml.sax.XMLReader}
* implementation class. In JAXP 1.0, this class wrapped the
* {@link org.xml.sax.Parser} interface, however this interface was
* replaced by the {@link org.xml.sax.XMLReader}. For ease
* of transition, this class continues to support the same name
* and interface as well as supporting new methods.
*
* An instance of this class can be obtained from the
* {@link javax.xml.parsers.SAXParserFactory#newSAXParser()} method.
* Once an instance of this class is obtained, XML can be parsed from
* a variety of input sources. These input sources are InputStreams,
* Files, URLs, and SAX InputSources.<p>
*
* 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 <code>&quot;javax.xml.parsers.SAXParserFactory&quot;</code>.
* 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>
*
* As the content is parsed by the underlying parser, methods of the
* given {@link org.xml.sax.HandlerBase} or the
* {@link org.xml.sax.helpers.DefaultHandler} are called.<p>
*
* Implementors of this class which wrap an underlying implementation
* can consider using the {@link org.xml.sax.helpers.ParserAdapter}
* class to initially adapt their SAX1 implementation to work under
* this revised class.
*
* @author <a href="mailto:Jeff.Suttor@Sun.com">Jeff Suttor</a>
* @since 1.4
*/
public abstract class SAXParser {
/**
* <p>Protected constructor to prevent instantiation.
* Use {@link javax.xml.parsers.SAXParserFactory#newSAXParser()}.</p>
*/
protected SAXParser () {
}
/**
* <p>Reset this <code>SAXParser</code> to its original configuration.</p>
*
* <p><code>SAXParser</code> is reset to the same state as when it was created with
* {@link SAXParserFactory#newSAXParser()}.
* <code>reset()</code> is designed to allow the reuse of existing <code>SAXParser</code>s
* thus saving resources associated with the creation of new <code>SAXParser</code>s.</p>
*
* <p>The reset <code>SAXParser</code> is not guaranteed to have the same {@link Schema}
* <code>Object</code>, e.g. {@link Object#equals(Object obj)}. It is guaranteed to have a functionally equal
* <code>Schema</code>.</p>
*
* @throws UnsupportedOperationException When Implementations do not
* override this method
*
* @since 1.5
*/
public void reset() {
// implementors should override this method
throw new UnsupportedOperationException(
"This SAXParser, \"" + this.getClass().getName() + "\", does not support the reset functionality."
+ " Specification \"" + this.getClass().getPackage().getSpecificationTitle() + "\""
+ " version \"" + this.getClass().getPackage().getSpecificationVersion() + "\""
);
}
/**
* <p>Parse the content of the given {@link java.io.InputStream}
* instance as XML using the specified {@link org.xml.sax.HandlerBase}.
* <i> Use of the DefaultHandler version of this method is recommended as
* the HandlerBase class has been deprecated in SAX 2.0</i>.</p>
*
* @param is InputStream containing the content to be parsed.
* @param hb The SAX HandlerBase to use.
*
* @throws IllegalArgumentException If the given InputStream is null.
* @throws SAXException If parse produces a SAX error.
* @throws IOException If an IO error occurs interacting with the
* <code>InputStream</code>.
*
* @see org.xml.sax.DocumentHandler
*/
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);
}
/**
* <p>Parse the content of the given {@link java.io.InputStream}
* instance as XML using the specified {@link org.xml.sax.HandlerBase}.
* <i> Use of the DefaultHandler version of this method is recommended as
* the HandlerBase class has been deprecated in SAX 2.0</i>.</p>
*
* @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.
*
* @throws IllegalArgumentException If the given <code>InputStream</code> is
* <code>null</code>.
* @throws IOException If any IO error occurs interacting with the
* <code>InputStream</code>.
* @throws SAXException If any SAX errors occur during processing.
*
* @see org.xml.sax.DocumentHandler version of this method instead.
*/
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 {@link java.io.InputStream}
* instance as XML using the specified
* {@link org.xml.sax.helpers.DefaultHandler}.
*
* @param is InputStream containing the content to be parsed.
* @param dh The SAX DefaultHandler to use.
*
* @throws IllegalArgumentException If the given InputStream is null.
* @throws IOException If any IO errors occur.
* @throws SAXException If any SAX errors occur during processing.
*
* @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);
}
/**
* Parse the content of the given {@link java.io.InputStream}
* instance as XML using the specified
* {@link org.xml.sax.helpers.DefaultHandler}.
*
* @param is InputStream containing the content to be parsed.
* @param dh The SAX DefaultHandler to use.
* @param systemId The systemId which is needed for resolving relative URIs.
*
* @throws IllegalArgumentException If the given InputStream is null.
* @throws IOException If any IO errors occur.
* @throws SAXException If any SAX errors occur during processing.
*
* @see org.xml.sax.DocumentHandler version of this method instead.
*/
public void parse(
InputStream is,
DefaultHandler dh,
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, dh);
}
/**
* Parse the content described by the giving Uniform Resource
* Identifier (URI) as XML using the specified
* {@link org.xml.sax.HandlerBase}.
* <i> Use of the DefaultHandler version of this method is recommended as
* the <code>HandlerBase</code> class has been deprecated in SAX 2.0</i>
*
* @param uri The location of the content to be parsed.
* @param hb The SAX HandlerBase to use.
*
* @throws IllegalArgumentException If the uri is null.
* @throws IOException If any IO errors occur.
* @throws SAXException If any SAX errors occur during processing.
*
* @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");
}
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
* {@link org.xml.sax.helpers.DefaultHandler}.
*
* @param uri The location of the content to be parsed.
* @param dh The SAX DefaultHandler to use.
*
* @throws IllegalArgumentException If the uri is null.
* @throws IOException If any IO errors occur.
* @throws SAXException If any SAX errors occur during processing.
*
* @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");
}
InputSource input = new InputSource(uri);
this.parse(input, dh);
}
/**
* Parse the content of the file specified as XML using the
* specified {@link org.xml.sax.HandlerBase}.
* <i> Use of the DefaultHandler version of this method is recommended as
* the HandlerBase class has been deprecated in SAX 2.0</i>
*
* @param f The file containing the XML to parse
* @param hb The SAX HandlerBase to use.
*
* @throws IllegalArgumentException If the File object is null.
* @throws IOException If any IO errors occur.
* @throws SAXException If any SAX errors occur during processing.
*
* @see org.xml.sax.DocumentHandler
*/
public void parse(File f, HandlerBase hb)
throws SAXException, IOException {
if (f == null) {
throw new IllegalArgumentException("File cannot be null");
}
//convert file to appropriate URI, f.toURI().toASCIIString()
//converts the URI to string as per rule specified in
//RFC 2396,
InputSource input = new InputSource(f.toURI().toASCIIString());
this.parse(input, hb);
}
/**
* Parse the content of the file specified as XML using the
* specified {@link org.xml.sax.helpers.DefaultHandler}.
*
* @param f The file containing the XML to parse
* @param dh The SAX DefaultHandler to use.
*
* @throws IllegalArgumentException If the File object is null.
* @throws IOException If any IO errors occur.
* @throws SAXException If any SAX errors occur during processing.
*
* @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");
}
//convert file to appropriate URI, f.toURI().toASCIIString()
//converts the URI to string as per rule specified in
//RFC 2396,
InputSource input = new InputSource(f.toURI().toASCIIString());
this.parse(input, dh);
}
/**
* Parse the content given {@link org.xml.sax.InputSource}
* as XML using the specified
* {@link org.xml.sax.HandlerBase}.
* <i> Use of the DefaultHandler version of this method is recommended as
* the HandlerBase class has been deprecated in SAX 2.0</i>
*
* @param is The InputSource containing the content to be parsed.
* @param hb The SAX HandlerBase to use.
*
* @throws IllegalArgumentException If the <code>InputSource</code> object
* is <code>null</code>.
* @throws IOException If any IO errors occur.
* @throws SAXException If any SAX errors occur during processing.
*
* @see org.xml.sax.DocumentHandler
*/
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 {@link org.xml.sax.InputSource}
* as XML using the specified
* {@link org.xml.sax.helpers.DefaultHandler}.
*
* @param is The InputSource containing the content to be parsed.
* @param dh The SAX DefaultHandler to use.
*
* @throws IllegalArgumentException If the <code>InputSource</code> object
* is <code>null</code>.
* @throws IOException If any IO errors occur.
* @throws SAXException If any SAX errors occur during processing.
*
* @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 encapsulated by the
* implementation of this class.
*
* @return The SAX parser that is encapsulated by the
* implementation of this class.
*
* @throws SAXException If any SAX errors occur during processing.
*/
public abstract org.xml.sax.Parser getParser() throws SAXException;
/**
* Returns the {@link org.xml.sax.XMLReader} that is encapsulated by the
* implementation of this class.
*
* @return The XMLReader that is encapsulated by the
* implementation of this class.
*
* @throws SAXException If any SAX errors occur during processing.
*/
public abstract org.xml.sax.XMLReader getXMLReader() throws SAXException;
/**
* Indicates whether or not this parser is configured to
* understand namespaces.
*
* @return true if this parser is configured to
* understand namespaces; false otherwise.
*/
public abstract boolean isNamespaceAware();
/**
* Indicates whether or not this parser is configured to
* validate XML documents.
*
* @return true if this parser is configured to
* validate XML documents; false otherwise.
*/
public abstract boolean isValidating();
/**
* <p>Sets the particular property in the underlying implementation of
* {@link org.xml.sax.XMLReader}.
* A list of the core features and properties can be found at
* <a href="http://sax.sourceforge.net/?selected=get-set">
* http://sax.sourceforge.net/?selected=get-set</a>.</p>
* <p>
* All implementations that implement JAXP 1.5 or newer are required to
* support the {@link javax.xml.XMLConstants#ACCESS_EXTERNAL_DTD} and
* {@link javax.xml.XMLConstants#ACCESS_EXTERNAL_SCHEMA} properties.
* </p>
* <ul>
* <li>
* <p>
* Setting the {@link javax.xml.XMLConstants#ACCESS_EXTERNAL_DTD} property
* restricts the access to external DTDs, external Entity References to
* the protocols specified by the property. If access is denied during parsing
* due to the restriction of this property, {@link org.xml.sax.SAXException}
* will be thrown by the parse methods defined by {@link javax.xml.parsers.SAXParser}.
* </p>
* <p>
* Setting the {@link javax.xml.XMLConstants#ACCESS_EXTERNAL_SCHEMA} property
* restricts the access to external Schema set by the schemaLocation attribute to
* the protocols specified by the property. If access is denied during parsing
* due to the restriction of this property, {@link org.xml.sax.SAXException}
* will be thrown by the parse methods defined by the {@link javax.xml.parsers.SAXParser}.
* </p>
* </li>
* </ul>
*
* @param name The name of the property to be set.
* @param value The value of the property to be set.
*
* @throws SAXNotRecognizedException When the underlying XMLReader does
* not recognize the property name.
* @throws 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;
/**
* <p>Returns the particular property requested for in the underlying
* implementation of {@link org.xml.sax.XMLReader}.</p>
*
* @param name The name of the property to be retrieved.
* @return Value of the requested property.
*
* @throws SAXNotRecognizedException When the underlying XMLReader does
* not recognize the property name.
* @throws 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;
/** <p>Get current state of canonicalization.</p>
*
* @return current state canonicalization control
*/
/*
public boolean getCanonicalization() {
return canonicalState;
}
*/
/** <p>Get a reference to the the {@link Schema} being used by
* the XML processor.</p>
*
* <p>If no schema is being used, <code>null</code> is returned.</p>
*
* @return {@link Schema} being used or <code>null</code>
* if none in use
*
* @throws UnsupportedOperationException When implementation does not
* override this method
*
* @since 1.5
*/
public Schema getSchema() {
throw new UnsupportedOperationException(
"This parser does not support specification \""
+ this.getClass().getPackage().getSpecificationTitle()
+ "\" version \""
+ this.getClass().getPackage().getSpecificationVersion()
+ "\""
);
}
/**
* <p>Get the XInclude processing mode for this parser.</p>
*
* @return
* the return value of
* the {@link SAXParserFactory#isXIncludeAware()}
* when this parser was created from factory.
*
* @throws UnsupportedOperationException When implementation does not
* override this method
*
* @since 1.5
*
* @see SAXParserFactory#setXIncludeAware(boolean)
*/
public boolean isXIncludeAware() {
throw new UnsupportedOperationException(
"This parser does not support specification \""
+ this.getClass().getPackage().getSpecificationTitle()
+ "\" version \""
+ this.getClass().getPackage().getSpecificationVersion()
+ "\""
);
}
}

View file

@ -0,0 +1,442 @@
/*
* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.xml.parsers;
import javax.xml.validation.Schema;
import org.xml.sax.SAXException;
import org.xml.sax.SAXNotRecognizedException;
import org.xml.sax.SAXNotSupportedException;
/**
* Defines a factory API that enables applications to configure and
* obtain a SAX based parser to parse XML documents.
*
* @author <a href="mailto:Jeff.Suttor@Sun.com">Jeff Suttor</a>
* @author <a href="mailto:Neeraj.Bajaj@sun.com">Neeraj Bajaj</a>
*
* @since 1.4
*/
public abstract class SAXParserFactory {
/**
* <p>Should Parsers be validating?</p>
*/
private boolean validating = false;
/**
* <p>Should Parsers be namespace aware?</p>
*/
private boolean namespaceAware = false;
/**
* <p>Protected constructor to force use of {@link #newInstance()}.</p>
*/
protected SAXParserFactory () {
}
/**
* Obtain a new instance of a <code>SAXParserFactory</code>. This
* static method creates a new factory instance
* This method uses the following ordered lookup procedure to determine
* the <code>SAXParserFactory</code> implementation class to
* load:
* <ul>
* <li>
* Use the <code>javax.xml.parsers.SAXParserFactory</code> system
* property.
* </li>
* <li>
* Use the properties file "lib/jaxp.properties" in the JRE directory.
* This configuration file is in standard <code>java.util.Properties
* </code> format and contains the fully qualified name of the
* implementation class with the key being the system property defined
* above.
*
* The jaxp.properties file is read only once by the JAXP implementation
* and it's values are then cached for future use. If the file does not exist
* when the first attempt is made to read from it, no further attempts are
* made to check for its existence. It is not possible to change the value
* of any property in jaxp.properties after it has been read for the first time.
* </li>
* <li>
* Use the service-provider loading facilities, defined by the
* {@link java.util.ServiceLoader} class, to attempt to locate and load an
* implementation of the service using the {@linkplain
* java.util.ServiceLoader#load(java.lang.Class) default loading mechanism}:
* the service-provider loading facility will use the {@linkplain
* java.lang.Thread#getContextClassLoader() current thread's context class loader}
* to attempt to load the service. If the context class
* loader is null, the {@linkplain
* ClassLoader#getSystemClassLoader() system class loader} will be used.
* </li>
* <li>
* Otherwise the system-default implementation is returned.
* </li>
* </ul>
*
* Once an application has obtained a reference to a
* <code>SAXParserFactory</code> it can use the factory to
* configure and obtain parser instances.
*
*
*
* <h2>Tip for Trouble-shooting</h2>
* <p>Setting the <code>jaxp.debug</code> system property will cause
* this method to print a lot of debug messages
* to <code>System.err</code> about what it is doing and where it is looking at.</p>
*
* <p> If you have problems loading {@link SAXParser}s, try:</p>
* <pre>
* java -Djaxp.debug=1 YourProgram ....
* </pre>
*
*
* @return A new instance of a SAXParserFactory.
*
* @throws FactoryConfigurationError in case of {@linkplain
* java.util.ServiceConfigurationError service configuration error} or if
* the implementation is not available or cannot be instantiated.
*/
public static SAXParserFactory newInstance() {
return FactoryFinder.find(
/* The default property name according to the JAXP spec */
SAXParserFactory.class,
/* The fallback implementation class name */
"com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl");
}
/**
* <p>Obtain a new instance of a <code>SAXParserFactory</code> from class name.
* This function is useful when there are multiple providers in the classpath.
* It gives more control to the application as it can specify which provider
* should be loaded.</p>
*
* <p>Once an application has obtained a reference to a <code>SAXParserFactory</code>
* it can use the factory to configure and obtain parser instances.</p>
*
*
* <h2>Tip for Trouble-shooting</h2>
* <p>Setting the <code>jaxp.debug</code> system property will cause
* this method to print a lot of debug messages
* to <code>System.err</code> about what it is doing and where it is looking at.</p>
*
* <p> If you have problems, try:</p>
* <pre>
* java -Djaxp.debug=1 YourProgram ....
* </pre>
*
* @param factoryClassName fully qualified factory class name that provides implementation of <code>javax.xml.parsers.SAXParserFactory</code>.
*
* @param classLoader <code>ClassLoader</code> used to load the factory class. If <code>null</code>
* current <code>Thread</code>'s context classLoader is used to load the factory class.
*
* @return New instance of a <code>SAXParserFactory</code>
*
* @throws FactoryConfigurationError if <code>factoryClassName</code> is <code>null</code>, or
* the factory class cannot be loaded, instantiated.
*
* @see #newInstance()
*
* @since 1.6
*/
public static SAXParserFactory newInstance(String factoryClassName, ClassLoader classLoader){
//do not fallback if given classloader can't find the class, throw exception
return FactoryFinder.newInstance(SAXParserFactory.class,
factoryClassName, classLoader, false);
}
/**
* <p>Creates a new instance of a SAXParser using the currently
* configured factory parameters.</p>
*
* @return A new instance of a SAXParser.
*
* @throws ParserConfigurationException if a parser cannot
* be created which satisfies the requested configuration.
* @throws SAXException for SAX errors.
*/
public abstract SAXParser newSAXParser()
throws ParserConfigurationException, SAXException;
/**
* Specifies that the parser produced by this code will
* provide support for XML namespaces. By default the value of this is set
* to <code>false</code>.
*
* @param awareness true if the parser produced by this code will
* provide support for XML namespaces; false otherwise.
*/
public void setNamespaceAware(boolean awareness) {
this.namespaceAware = awareness;
}
/**
* Specifies that the parser produced by this code will
* validate documents as they are parsed. By default the value of this is
* set to <code>false</code>.
*
* <p>
* Note that "the validation" here means
* <a href="http://www.w3.org/TR/REC-xml#proc-types">a validating
* parser</a> as defined in the XML recommendation.
* In other words, it essentially just controls the DTD validation.
* (except the legacy two properties defined in JAXP 1.2.)
* </p>
*
* <p>
* To use modern schema languages such as W3C XML Schema or
* RELAX NG instead of DTD, you can configure your parser to be
* a non-validating parser by leaving the {@link #setValidating(boolean)}
* method <code>false</code>, then use the {@link #setSchema(Schema)}
* method to associate a schema to a parser.
* </p>
*
* @param validating true if the parser produced by this code will
* validate documents as they are parsed; false otherwise.
*/
public void setValidating(boolean validating) {
this.validating = validating;
}
/**
* Indicates whether or not the factory is configured to produce
* parsers which are namespace aware.
*
* @return true if the factory is configured to produce
* parsers which are namespace aware; false otherwise.
*/
public boolean isNamespaceAware() {
return namespaceAware;
}
/**
* Indicates whether or not the factory is configured to produce
* parsers which validate the XML content during parse.
*
* @return true if the factory is configured to produce parsers which validate
* the XML content during parse; false otherwise.
*/
public boolean isValidating() {
return validating;
}
/**
*
* <p>Sets the particular feature in the underlying implementation of
* org.xml.sax.XMLReader.
* A list of the core features and properties can be found at
* <a href="http://www.saxproject.org/">http://www.saxproject.org/</a></p>
*
* <p>All implementations are required to support the {@link javax.xml.XMLConstants#FEATURE_SECURE_PROCESSING} feature.
* When the feature is</p>
* <ul>
* <li>
* <code>true</code>: the implementation will limit XML processing to conform to implementation limits.
* Examples include entity expansion limits and XML Schema constructs that would consume large amounts of resources.
* If XML processing is limited for security reasons, it will be reported via a call to the registered
* {@link org.xml.sax.ErrorHandler#fatalError(SAXParseException exception)}.
* See {@link SAXParser} <code>parse</code> methods for handler specification.
* </li>
* <li>
* When the feature is <code>false</code>, the implementation will processing XML according to the XML specifications without
* regard to possible implementation limits.
* </li>
* </ul>
*
* @param name The name of the feature to be set.
* @param value The value of the feature to be set.
*
* @throws ParserConfigurationException if a parser cannot
* be created which satisfies the requested configuration.
* @throws SAXNotRecognizedException When the underlying XMLReader does
* not recognize the property name.
* @throws SAXNotSupportedException When the underlying XMLReader
* recognizes the property name but doesn't support the
* property.
* @throws NullPointerException If the <code>name</code> parameter is null.
*
* @see org.xml.sax.XMLReader#setFeature
*/
public abstract void setFeature(String name, boolean value)
throws ParserConfigurationException, SAXNotRecognizedException,
SAXNotSupportedException;
/**
*
* <p>Returns the particular property requested for in the underlying
* implementation of org.xml.sax.XMLReader.</p>
*
* @param name The name of the property to be retrieved.
*
* @return Value of the requested property.
*
* @throws ParserConfigurationException if a parser cannot be created which satisfies the requested configuration.
* @throws SAXNotRecognizedException When the underlying XMLReader does not recognize the property name.
* @throws 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;
/**
* Gets the {@link Schema} object specified through
* the {@link #setSchema(Schema schema)} method.
*
*
* @throws UnsupportedOperationException When implementation does not
* override this method
*
* @return
* the {@link Schema} object that was last set through
* the {@link #setSchema(Schema)} method, or null
* if the method was not invoked since a {@link SAXParserFactory}
* is created.
*
* @since 1.5
*/
public Schema getSchema() {
throw new UnsupportedOperationException(
"This parser does not support specification \""
+ this.getClass().getPackage().getSpecificationTitle()
+ "\" version \""
+ this.getClass().getPackage().getSpecificationVersion()
+ "\""
);
}
/**
* <p>Set the {@link Schema} to be used by parsers created
* from this factory.</p>
*
* <p>When a {@link Schema} is non-null, a parser will use a validator
* created from it to validate documents before it passes information
* down to the application.</p>
*
* <p>When warnings/errors/fatal errors are found by the validator, the parser must
* handle them as if those errors were found by the parser itself.
* In other words, if the user-specified {@link org.xml.sax.ErrorHandler}
* is set, it must receive those errors, and if not, they must be
* treated according to the implementation specific
* default error handling rules.
*
* <p>A validator may modify the SAX event stream (for example by
* adding default values that were missing in documents), and a parser
* is responsible to make sure that the application will receive
* those modified event stream.</p>
*
* <p>Initially, <code>null</code> is set as the {@link Schema}.</p>
*
* <p>This processing will take effect even if
* the {@link #isValidating()} method returns <code>false</code>.
*
* <p>It is an error to use
* the <code>http://java.sun.com/xml/jaxp/properties/schemaSource</code>
* property and/or the <code>http://java.sun.com/xml/jaxp/properties/schemaLanguage</code>
* property in conjunction with a non-null {@link Schema} object.
* Such configuration will cause a {@link SAXException}
* exception when those properties are set on a {@link SAXParser}.</p>
*
* <h4>Note for implementors</h4>
* <p>
* A parser must be able to work with any {@link Schema}
* implementation. However, parsers and schemas are allowed
* to use implementation-specific custom mechanisms
* as long as they yield the result described in the specification.
* </p>
*
* @param schema <code>Schema</code> to use, <code>null</code> to remove a schema.
*
* @throws UnsupportedOperationException When implementation does not
* override this method
*
* @since 1.5
*/
public void setSchema(Schema schema) {
throw new UnsupportedOperationException(
"This parser does not support specification \""
+ this.getClass().getPackage().getSpecificationTitle()
+ "\" version \""
+ this.getClass().getPackage().getSpecificationVersion()
+ "\""
);
}
/**
* <p>Set state of XInclude processing.</p>
*
* <p>If XInclude markup is found in the document instance, should it be
* processed as specified in <a href="http://www.w3.org/TR/xinclude/">
* XML Inclusions (XInclude) Version 1.0</a>.</p>
*
* <p>XInclude processing defaults to <code>false</code>.</p>
*
* @param state Set XInclude processing to <code>true</code> or
* <code>false</code>
*
* @throws UnsupportedOperationException When implementation does not
* override this method
*
* @since 1.5
*/
public void setXIncludeAware(final boolean state) {
if (state) {
throw new UnsupportedOperationException(" setXIncludeAware " +
"is not supported on this JAXP" +
" implementation or earlier: " + this.getClass());
}
}
/**
* <p>Get state of XInclude processing.</p>
*
* @return current state of XInclude processing
*
* @throws UnsupportedOperationException When implementation does not
* override this method
*
* @since 1.5
*/
public boolean isXIncludeAware() {
throw new UnsupportedOperationException(
"This parser does not support specification \""
+ this.getClass().getPackage().getSpecificationTitle()
+ "\" version \""
+ this.getClass().getPackage().getSpecificationVersion()
+ "\""
);
}
}

View file

@ -0,0 +1,110 @@
/*
* Copyright (c) 2004, 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.xml.parsers;
import java.security.*;
import java.net.*;
import java.io.*;
import java.util.*;
/**
* This class is duplicated for each JAXP subpackage so keep it in sync.
* It is package private and therefore is not exposed as part of the JAXP
* API.
*
* Security related methods that only work on J2SE 1.2 and newer.
*/
class SecuritySupport {
ClassLoader getContextClassLoader() throws SecurityException{
return (ClassLoader)
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
ClassLoader cl = null;
//try {
cl = Thread.currentThread().getContextClassLoader();
//} catch (SecurityException ex) { }
if (cl == null)
cl = ClassLoader.getSystemClassLoader();
return cl;
}
});
}
String getSystemProperty(final String propName) {
return (String)
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
return System.getProperty(propName);
}
});
}
FileInputStream getFileInputStream(final File file)
throws FileNotFoundException
{
try {
return (FileInputStream)
AccessController.doPrivileged(new PrivilegedExceptionAction() {
public Object run() throws FileNotFoundException {
return new FileInputStream(file);
}
});
} catch (PrivilegedActionException e) {
throw (FileNotFoundException)e.getException();
}
}
InputStream getResourceAsStream(final ClassLoader cl,
final String name)
{
return (InputStream)
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
InputStream ris;
if (cl == null) {
ris = Object.class.getResourceAsStream(name);
} else {
ris = cl.getResourceAsStream(name);
}
return ris;
}
});
}
boolean doesFileExist(final File f) {
return ((Boolean)
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
return new Boolean(f.exists());
}
})).booleanValue();
}
}

View file

@ -0,0 +1,51 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2000, 2005, Oracle and/or its affiliates. All rights reserved.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
This code is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License version 2 only, as
published by the Free Software Foundation. Oracle designates this
particular file as subject to the "Classpath" exception as provided
by Oracle in the LICENSE file that accompanied this code.
This code is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
version 2 for more details (a copy is included in the LICENSE file that
accompanied this code).
You should have received a copy of the GNU General Public License version
2 along with this work; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
or visit www.oracle.com if you need additional information or have any
questions.
-->
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>javax.xml.parsers</title>
<meta name="CVS"
content="$Id: package.html,v 1.2 2005/06/10 03:50:29 jeffsuttor Exp $" />
<meta name="AUTHOR"
content="Jeff.Suttor@Sun.com" />
</head>
<body>
<p>
Provides classes allowing the processing of XML documents. Two types
of plugable parsers are supported:
</p>
<ul>
<li>SAX (Simple API for XML)</li>
<li>DOM (Document Object Model)</li>
</ul>
</body>
</html>