From cb24b2ecfa9909d386ad5b1a517abdd2885698da Mon Sep 17 00:00:00 2001 From: edwingo Date: Tue, 22 May 2001 01:01:03 +0000 Subject: [PATCH] Initial revision git-svn-id: https://svn.apache.org/repos/asf/xml/commons/trunk@225907 13f79535-47bb-0310-9956-ffa450edef68 --- .../javax/xml/parsers/DocumentBuilder.java | 246 ++++++++++ .../xml/parsers/DocumentBuilderFactory.java | 306 +++++++++++++ .../parsers/FactoryConfigurationError.java | 125 +++++ .../src/javax/xml/parsers/FactoryFinder.java | 231 ++++++++++ .../parsers/ParserConfigurationException.java | 46 ++ .../src/javax/xml/parsers/SAXParser.java | 431 ++++++++++++++++++ .../javax/xml/parsers/SAXParserFactory.java | 214 +++++++++ .../src/javax/xml/parsers/package.html | 31 ++ .../javax/xml/transform/ErrorListener.java | 101 ++++ .../javax/xml/transform/FactoryFinder.java | 231 ++++++++++ .../src/javax/xml/transform/OutputKeys.java | 179 ++++++++ .../src/javax/xml/transform/Result.java | 83 ++++ .../src/javax/xml/transform/Source.java | 52 +++ .../javax/xml/transform/SourceLocator.java | 89 ++++ .../src/javax/xml/transform/Templates.java | 76 +++ .../src/javax/xml/transform/Transformer.java | 246 ++++++++++ .../TransformerConfigurationException.java | 96 ++++ .../xml/transform/TransformerException.java | 365 +++++++++++++++ .../xml/transform/TransformerFactory.java | 259 +++++++++++ .../TransformerFactoryConfigurationError.java | 112 +++++ .../src/javax/xml/transform/URIResolver.java | 43 ++ .../javax/xml/transform/dom/DOMLocator.java | 43 ++ .../javax/xml/transform/dom/DOMResult.java | 142 ++++++ .../javax/xml/transform/dom/DOMSource.java | 131 ++++++ .../src/javax/xml/transform/dom/package.html | 36 ++ .../src/javax/xml/transform/overview.html | 258 +++++++++++ .../src/javax/xml/transform/package.html | 177 +++++++ .../javax/xml/transform/sax/SAXResult.java | 141 ++++++ .../javax/xml/transform/sax/SAXSource.java | 192 ++++++++ .../transform/sax/SAXTransformerFactory.java | 149 ++++++ .../xml/transform/sax/TemplatesHandler.java | 63 +++ .../xml/transform/sax/TransformerHandler.java | 70 +++ .../src/javax/xml/transform/sax/package.html | 69 +++ .../xml/transform/stream/StreamResult.java | 189 ++++++++ .../xml/transform/stream/StreamSource.java | 262 +++++++++++ .../javax/xml/transform/stream/package.html | 30 ++ 36 files changed, 5514 insertions(+) create mode 100644 java/external/src/javax/xml/parsers/DocumentBuilder.java create mode 100644 java/external/src/javax/xml/parsers/DocumentBuilderFactory.java create mode 100644 java/external/src/javax/xml/parsers/FactoryConfigurationError.java create mode 100644 java/external/src/javax/xml/parsers/FactoryFinder.java create mode 100644 java/external/src/javax/xml/parsers/ParserConfigurationException.java create mode 100644 java/external/src/javax/xml/parsers/SAXParser.java create mode 100644 java/external/src/javax/xml/parsers/SAXParserFactory.java create mode 100644 java/external/src/javax/xml/parsers/package.html create mode 100644 java/external/src/javax/xml/transform/ErrorListener.java create mode 100644 java/external/src/javax/xml/transform/FactoryFinder.java create mode 100644 java/external/src/javax/xml/transform/OutputKeys.java create mode 100644 java/external/src/javax/xml/transform/Result.java create mode 100644 java/external/src/javax/xml/transform/Source.java create mode 100644 java/external/src/javax/xml/transform/SourceLocator.java create mode 100644 java/external/src/javax/xml/transform/Templates.java create mode 100644 java/external/src/javax/xml/transform/Transformer.java create mode 100644 java/external/src/javax/xml/transform/TransformerConfigurationException.java create mode 100644 java/external/src/javax/xml/transform/TransformerException.java create mode 100644 java/external/src/javax/xml/transform/TransformerFactory.java create mode 100644 java/external/src/javax/xml/transform/TransformerFactoryConfigurationError.java create mode 100644 java/external/src/javax/xml/transform/URIResolver.java create mode 100644 java/external/src/javax/xml/transform/dom/DOMLocator.java create mode 100644 java/external/src/javax/xml/transform/dom/DOMResult.java create mode 100644 java/external/src/javax/xml/transform/dom/DOMSource.java create mode 100644 java/external/src/javax/xml/transform/dom/package.html create mode 100644 java/external/src/javax/xml/transform/overview.html create mode 100644 java/external/src/javax/xml/transform/package.html create mode 100644 java/external/src/javax/xml/transform/sax/SAXResult.java create mode 100644 java/external/src/javax/xml/transform/sax/SAXSource.java create mode 100644 java/external/src/javax/xml/transform/sax/SAXTransformerFactory.java create mode 100644 java/external/src/javax/xml/transform/sax/TemplatesHandler.java create mode 100644 java/external/src/javax/xml/transform/sax/TransformerHandler.java create mode 100644 java/external/src/javax/xml/transform/sax/package.html create mode 100644 java/external/src/javax/xml/transform/stream/StreamResult.java create mode 100644 java/external/src/javax/xml/transform/stream/StreamSource.java create mode 100644 java/external/src/javax/xml/transform/stream/package.html diff --git a/java/external/src/javax/xml/parsers/DocumentBuilder.java b/java/external/src/javax/xml/parsers/DocumentBuilder.java new file mode 100644 index 0000000..cd7670d --- /dev/null +++ b/java/external/src/javax/xml/parsers/DocumentBuilder.java @@ -0,0 +1,246 @@ +/** + * $Id$ + * + * Copyright (c) 1998-2000 Sun Microsystems, Inc. All Rights Reserved. + * + * This software is the confidential and proprietary information of Sun + * Microsystems, Inc. ("Confidential Information"). You shall not + * disclose such Confidential Information and shall use it only in + * accordance with the terms of the license agreement you entered into + * with Sun. + * + * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE + * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE + * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR + * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES + * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING + * THIS SOFTWARE OR ITS DERIVATIVES. + */ +package javax.xml.parsers; + +import java.io.InputStream; +import java.io.IOException; +import java.io.File; + +import org.xml.sax.Parser; +import org.xml.sax.HandlerBase; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; + +import org.w3c.dom.Document; +import org.w3c.dom.DOMImplementation; + +/** + * Defines the API to obtain DOM Document instances from an XML + * document. Using this class, an application programmer can obtain a + * {@link org.w3c.dom.Document} from XML.

+ * + * An instance of this class can be obtained from the + * {@link javax.xml.parsers.DocumentBuilderFactory#newDocumentBuilder() + * 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.

+ * + * 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 + * Document. It merely requires that the implementation + * communicate with the application using these existing APIs.

+ * + * An implementation of DocumentBuilder is NOT + * guaranteed to behave as per the specification if it is used concurrently by + * two or more threads. It is recommended to have one instance of the + * DocumentBuilder per thread or it is upto the application to + * make sure about the use of DocumentBuilder from more than one + * thread. + * + * @since JAXP 1.0 + * @version 1.0 + */ + +public abstract class DocumentBuilder { + + protected DocumentBuilder () { + } + + /** + * Parse the content of the given InputStream as an XML + * document and return a new DOM {@link org.w3c.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); + } + + /** + * Parse the content of the given InputStream as an XML + * document and return a new DOM {@link org.w3c.dom.Document} object. + * + * @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 + * @return A new DOM Document object. + */ + + 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 org.w3c.dom.Document} object. + * + * @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 + * @return A new DOM Document object. + */ + + 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 org.w3c.dom.Document} object. + * + * @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 + * @return A new DOM Document object. + */ + + 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); + } + + /** + * Parse the content of the given input source as an XML document + * and return a new DOM {@link org.w3c.dom.Document} object. + * + * @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 + * @return A new DOM Document object. + */ + + 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 org.xml.sax.EntityResolver} to be used to resolve + * entities present in the XML document to be parsed. Setting + * this to null will result in the underlying + * implementation using it's own default implementation and + * behavior. + * + * @param er The EntityResolver to be used to resolve entities + * present in the XML document to be parsed. + */ + + public abstract void setEntityResolver(org.xml.sax.EntityResolver er); + + /** + * Specify the {@link org.xml.sax.ErrorHandler} to be used to report + * errors present in the XML document to be parsed. Setting + * this to null will result in the underlying + * implementation using it's own default implementation and + * behavior. + * + * @param eh The ErrorHandler to be used to report errors + * present in the XML document to be parsed. + */ + + public abstract void setErrorHandler(org.xml.sax.ErrorHandler eh); + + /** + * Obtain a new instance of a DOM {@link org.w3c.dom.Document} object + * to build a DOM tree with. An alternative way to create a DOM + * Document object is to use the + * {@link #getDOMImplementation() getDOMImplementation} + * method to get a DOM Level 2 DOMImplementation object and then use + * DOM Level 2 methods on that object to create a DOM Document object. + * + * @return A new instance of a DOM Document object. + */ + + public abstract Document newDocument(); + + /** + * Obtain an instance of a {@link org.w3c.dom.DOMImplementation} object. + * + * @return A new instance of a DOMImplementation. + */ + + public abstract DOMImplementation getDOMImplementation(); +} diff --git a/java/external/src/javax/xml/parsers/DocumentBuilderFactory.java b/java/external/src/javax/xml/parsers/DocumentBuilderFactory.java new file mode 100644 index 0000000..a53191c --- /dev/null +++ b/java/external/src/javax/xml/parsers/DocumentBuilderFactory.java @@ -0,0 +1,306 @@ +/** + * $Id$ + * + * Copyright (c) 1998-2000 Sun Microsystems, Inc. All Rights Reserved. + * + * This software is the confidential and proprietary information of Sun + * Microsystems, Inc. ("Confidential Information"). You shall not + * disclose such Confidential Information and shall use it only in + * accordance with the terms of the license agreement you entered into + * with Sun. + * + * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE + * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE + * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR + * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES + * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING + * THIS SOFTWARE OR ITS DERIVATIVES. + */ + +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; + +/** + * Defines a factory API that enables applications to obtain a + * parser that produces DOM object trees from XML documents. + * + * An implementation of the DocumentBuilderFactory class is + * NOT guaranteed to be thread safe. It is up to the user application + * to make sure about the use of the DocumentBuilderFactory from + * more than one thread. Alternatively the application can have one instance + * of the DocumentBuilderFactory per thread. + * An application can use the same instance of the factory to obtain one or + * more instances of the DocumentBuilder provided the instance + * of the factory isn't being used in more than one thread at a time. + * + * @since JAXP 1.0 + * @version 1.0 + */ + +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; + + protected DocumentBuilderFactory () { + + } + + /** + * Obtain a new instance of a + * DocumentBuilderFactory. This static method creates + * a new factory instance. + * This method uses the following ordered lookup procedure to determine + * the DocumentBuilderFactory implementation class to + * load: + *

+ * + * Once an application has obtained a reference to a + * DocumentBuilderFactory 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() + throws FactoryConfigurationError + { + try { + return (DocumentBuilderFactory) FactoryFinder.find( + /* The default property name according to the JAXP spec */ + "javax.xml.parsers.DocumentBuilderFactory", + /* The fallback implementation class name */ + "org.apache.crimson.jaxp.DocumentBuilderFactoryImpl"); + } catch (FactoryFinder.ConfigurationError e) { + throw new FactoryConfigurationError(e.getException(), + e.getMessage()); + } + } + + /** + * Creates a new instance of a {@link javax.xml.parsers.DocumentBuilder} + * using the currently configured parameters. + * + * @exception ParserConfigurationException if a DocumentBuilder + * cannot be created which satisfies the configuration requested. + * @return A new instance of a DocumentBuilder. + */ + + 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 false + * + * @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 false. + * + * @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 false. + * + * @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 + * true + * + * @param expandEntityRef true if the parser produced will expand entity + * reference nodes; false otherwise. + */ + + public void setExpandEntityReferences(boolean expandEntityRef) { + this.expandEntityRef = expandEntityRef; + } + + /** + * Specifies that the parser produced by this code will + * ignore comments. By default the value of this is set to false + * + */ + + 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 + * false + * + * @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. + * @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; +} diff --git a/java/external/src/javax/xml/parsers/FactoryConfigurationError.java b/java/external/src/javax/xml/parsers/FactoryConfigurationError.java new file mode 100644 index 0000000..088a02b --- /dev/null +++ b/java/external/src/javax/xml/parsers/FactoryConfigurationError.java @@ -0,0 +1,125 @@ +/* + * $Id$ + * + * Copyright (c) 1998-1999 Sun Microsystems, Inc. All Rights Reserved. + * + * This software is the confidential and proprietary information of Sun + * Microsystems, Inc. ("Confidential Information"). You shall not + * disclose such Confidential Information and shall use it only in + * accordance with the terms of the license agreement you entered into + * with Sun. + * + * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE + * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE + * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR + * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES + * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING + * THIS SOFTWARE OR ITS DERIVATIVES. + */ + +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. + * + * @since JAXP 1.0 + * @version 1.0 + */ + +public class FactoryConfigurationError extends Error { + + private Exception exception; + + /** + * Create a new FactoryConfigurationError with no + * detail mesage. + */ + + public FactoryConfigurationError() { + super(); + this.exception = null; + } + + /** + * Create a new FactoryConfigurationError with + * the String 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 FactoryConfigurationError with a + * given Exception 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 FactoryConfigurationError with the + * given Exception 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; + } + + + /** + * 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; + } +} + + + + + + + diff --git a/java/external/src/javax/xml/parsers/FactoryFinder.java b/java/external/src/javax/xml/parsers/FactoryFinder.java new file mode 100644 index 0000000..8c25360 --- /dev/null +++ b/java/external/src/javax/xml/parsers/FactoryFinder.java @@ -0,0 +1,231 @@ +/* + * $Id$ + * + * Copyright (c) 1998-2001 Sun Microsystems, Inc. All Rights Reserved. + * + * This software is the confidential and proprietary information of Sun + * Microsystems, Inc. ("Confidential Information"). You shall not + * disclose such Confidential Information and shall use it only in + * accordance with the terms of the license agreement you entered into + * with Sun. + * + * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE + * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE + * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR + * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES + * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING + * THIS SOFTWARE OR ITS DERIVATIVES. + */ + +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; + +/** + * This class is duplicated for each JAXP subpackage so keep it in + * sync. It is package private. + * + * This code is designed to implement the JAXP 1.1 spec pluggability + * feature and is designed to run on JDK version 1.1 and later including + * JVMs that perform early linking like the Microsoft JVM in IE 5. Note + * however that it must be compiled on a JDK version 1.2 or later system + * since it calls Thread#getContextClassLoader(). The code also runs both + * as part of an unbundled jar file and when bundled as part of the JDK. + */ +class FactoryFinder { + /** Temp debug code - this will be removed after we test everything + */ + private static boolean debug = false; + static { + // Use try/catch block to support applets + try { + debug = System.getProperty("jaxp.debug") != null; + } catch (Exception x) { + } + } + + private static void debugPrintln(String msg) { + if (debug) { + System.err.println("JAXP: " + msg); + } + } + + /** + * Figure out which ClassLoader to use. For JDK 1.2 and later use the + * context ClassLoader if possible. Note: we defer linking the class + * that calls an API only in JDK 1.2 until runtime so that we can catch + * LinkageError so that this code will run in older non-Sun JVMs such + * as the Microsoft JVM in IE. + */ + private static ClassLoader findClassLoader() + throws ConfigurationError + { + ClassLoader classLoader; + try { + // Construct the name of the concrete class to instantiate + Class clazz = Class.forName(FactoryFinder.class.getName() + + "$ClassLoaderFinderConcrete"); + ClassLoaderFinder clf = (ClassLoaderFinder) clazz.newInstance(); + classLoader = clf.getContextClassLoader(); + } catch (LinkageError le) { + // Assume that we are running JDK 1.1, use the current ClassLoader + classLoader = FactoryFinder.class.getClassLoader(); + } catch (ClassNotFoundException x) { + // This case should not normally happen. MS IE can throw this + // instead of a LinkageError the second time Class.forName() is + // called so assume that we are running JDK 1.1 and use the + // current ClassLoader + classLoader = FactoryFinder.class.getClassLoader(); + } catch (Exception x) { + // Something abnormal happened so throw an error + throw new ConfigurationError(x.toString(), x); + } + return classLoader; + } + + /** + * Create an instance of a class using the specified ClassLoader + */ + private static Object newInstance(String className, + ClassLoader classLoader) + throws ConfigurationError + { + try { + Class spiClass; + if (classLoader == null) { + spiClass = Class.forName(className); + } else { + spiClass = classLoader.loadClass(className); + } + return spiClass.newInstance(); + } catch (ClassNotFoundException x) { + throw new ConfigurationError( + "Provider " + className + " not found", x); + } catch (Exception x) { + throw new ConfigurationError( + "Provider " + className + " could not be instantiated: " + x, + x); + } + } + + /** + * Finds the implementation Class object in the specified order. Main + * entry point. + * @return Class object of factory, never null + * + * @param factoryId Name of the factory to find, same as + * a property name + * @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 Object find(String factoryId, String fallbackClassName) + throws ConfigurationError + { + ClassLoader classLoader = findClassLoader(); + + // Use the system property first + try { + String systemProp = + System.getProperty( factoryId ); + if( systemProp!=null) { + debugPrintln("found system property" + systemProp); + return newInstance(systemProp, classLoader); + } + } catch (SecurityException se) { + } + + // 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)); + String factoryClassName = props.getProperty(factoryId); + debugPrintln("found java.home property " + factoryClassName); + return newInstance(factoryClassName, classLoader); + } + } catch(Exception ex ) { + if( debug ) ex.printStackTrace(); + } + + String serviceId = "META-INF/services/" + factoryId; + // try to find services in CLASSPATH + try { + InputStream is=null; + if (classLoader == null) { + is=ClassLoader.getSystemResourceAsStream( serviceId ); + } else { + is=classLoader.getResourceAsStream( serviceId ); + } + + if( is!=null ) { + debugPrintln("found " + serviceId); + BufferedReader rd = + new BufferedReader(new InputStreamReader(is)); + + String factoryClassName = rd.readLine(); + rd.close(); + + if (factoryClassName != null && + ! "".equals(factoryClassName)) { + debugPrintln("loaded from services: " + factoryClassName); + return newInstance(factoryClassName, classLoader); + } + } + } catch( Exception ex ) { + if( debug ) ex.printStackTrace(); + } + + if (fallbackClassName == null) { + throw new ConfigurationError( + "Provider for " + factoryId + " cannot be found", null); + } + + debugPrintln("loaded from fallback value: " + fallbackClassName); + return newInstance(fallbackClassName, classLoader); + } + + static class ConfigurationError extends Error { + private Exception exception; + + /** + * Construct a new instance with the specified detail string and + * exception. + */ + ConfigurationError(String msg, Exception x) { + super(msg); + this.exception = x; + } + + Exception getException() { + return exception; + } + } + + /* + * The following nested classes allow getContextClassLoader() to be + * called only on JDK 1.2 and yet run in older JDK 1.1 JVMs + */ + + private static abstract class ClassLoaderFinder { + abstract ClassLoader getContextClassLoader(); + } + + static class ClassLoaderFinderConcrete extends ClassLoaderFinder { + ClassLoader getContextClassLoader() { + return Thread.currentThread().getContextClassLoader(); + } + } +} diff --git a/java/external/src/javax/xml/parsers/ParserConfigurationException.java b/java/external/src/javax/xml/parsers/ParserConfigurationException.java new file mode 100644 index 0000000..df2622b --- /dev/null +++ b/java/external/src/javax/xml/parsers/ParserConfigurationException.java @@ -0,0 +1,46 @@ +/* + * $Id$ + * + * Copyright (c) 1998-1999 Sun Microsystems, Inc. All Rights Reserved. + * + * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE + * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE + * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR + * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES + * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING + * THIS SOFTWARE OR ITS DERIVATIVES. + */ + +package javax.xml.parsers; + +/** + * Indicates a serious configuration error. + * + * @since JAXP 1.0 + * @version 1.0 + */ + +public class ParserConfigurationException extends Exception { + + /** + * Create a new ParserConfigurationException with no + * detail mesage. + */ + + public ParserConfigurationException() { + super(); + } + + /** + * Create a new ParserConfigurationException with + * the String specified as an error message. + * + * @param msg The error message for the exception. + */ + + public ParserConfigurationException(String msg) { + super(msg); + } + +} + diff --git a/java/external/src/javax/xml/parsers/SAXParser.java b/java/external/src/javax/xml/parsers/SAXParser.java new file mode 100644 index 0000000..7b30643 --- /dev/null +++ b/java/external/src/javax/xml/parsers/SAXParser.java @@ -0,0 +1,431 @@ +/* + * $Id$ + * + * Copyright (c) 1998-1999 Sun Microsystems, Inc. All Rights Reserved. + * + * This software is the confidential and proprietary information of Sun + * Microsystems, Inc. ("Confidential Information"). You shall not + * disclose such Confidential Information and shall use it only in + * accordance with the terms of the license agreement you entered into + * with Sun. + * + * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE + * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE + * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR + * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES + * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING + * THIS SOFTWARE OR ITS DERIVATIVES. + */ + + +package javax.xml.parsers; + +import java.io.InputStream; +import java.io.IOException; +import java.io.File; + +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.SAXException; +import org.xml.sax.SAXNotRecognizedException; +import org.xml.sax.SAXNotSupportedException; + + +/** + * 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.

+ * + * 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.

+ * + * 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.

+ * + * 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.

+ * + * 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 impelemntation to work under + * this revised class.

+ * + * An implementation of SAXParser is NOT + * guaranteed to behave as per the specification if it is used concurrently by + * two or more threads. It is recommended to have one instance of the + * SAXParser per thread or it is upto the application to + * make sure about the use of SAXParser from more than one + * thread. + * + * @since JAXP 1.0 + * @version 1.0 + */ + +public abstract class SAXParser { + + protected SAXParser () { + + } + + /** + * Parse the content of the given {@link java.io.InputStream} + * instance as XML using the specified {@link org.xml.sax.HandlerBase}. + * Use of the DefaultHandler version of this method is recommended as + * the HandlerBase class has been deprecated in SAX 2.0 + * + * @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, HandlerBase hb) + throws SAXException, IOException + { + if (is == null) { + throw new IllegalArgumentException("InputStream cannot be null"); + } + + InputSource input = new InputSource(is); + this.parse(input, hb); + } + + /** + * Parse the content of the given {@link java.io.InputStream} + * instance as XML using the specified {@link org.xml.sax.HandlerBase}. + * Use of the DefaultHandler version of this method is recommended as + * the HandlerBase class has been deprecated in SAX 2.0 + * + * @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(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. + * @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); + } + + /** + * 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. + * @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(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}. + * Use of the DefaultHandler version of this method is recommended as + * the HandlerBase class has been deprecated in SAX 2.0 + * + * @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"); + } + + 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. + * @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"); + } + + 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}. + * Use of the DefaultHandler version of this method is recommended as + * the HandlerBase class has been deprecated in SAX 2.0 + * + * @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(File f, HandlerBase hb) + 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, 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. + * @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); + } + + /** + * Parse the content given {@link org.xml.sax.InputSource} + * as XML using the specified + * {@link org.xml.sax.HandlerBase}. + * Use of the DefaultHandler version of this method is recommended as + * the HandlerBase class has been deprecated in SAX 2.0 + * + * @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 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. + * @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. + * + * @return The SAX parser that is encapsultated by the + * implementation of this class. + */ + + 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. + */ + + 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(); + + /** + * 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 + * http://www.megginson.com/SAX/Java/features.html + * + * @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 {@link 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; + + + +} diff --git a/java/external/src/javax/xml/parsers/SAXParserFactory.java b/java/external/src/javax/xml/parsers/SAXParserFactory.java new file mode 100644 index 0000000..8a25447 --- /dev/null +++ b/java/external/src/javax/xml/parsers/SAXParserFactory.java @@ -0,0 +1,214 @@ +/* + * $Id$ + * + * Copyright (c) 1998-2000 Sun Microsystems, Inc. All Rights Reserved. + * + * This software is the confidential and proprietary information of Sun + * Microsystems, Inc. ("Confidential Information"). You shall not + * disclose such Confidential Information and shall use it only in + * accordance with the terms of the license agreement you entered into + * with Sun. + * + * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE + * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE + * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR + * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES + * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING + * THIS SOFTWARE OR ITS DERIVATIVES. + */ + +package javax.xml.parsers; + +import org.xml.sax.Parser; +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.

+ * An implementation of the SAXParserFactory class is + * NOT guaranteed to be thread safe. It is up to the user application + * to make sure about the use of the SAXParserFactory from + * more than one thread. Alternatively the application can have one instance + * of the SAXParserFactory per thread. + * An application can use the same instance of the factory to obtain one or + * more instances of the SAXParser provided the instance + * of the factory isn't being used in more than one thread at a time. + * + * @since JAXP 1.0 + * @version 1.0 + */ + +public abstract class SAXParserFactory { + private boolean validating = false; + private boolean namespaceAware= false; + + protected SAXParserFactory () { + + } + + /** + * Obtain a new instance of a SAXParserFactory. This + * static method creates a new factory instance + * This method uses the following ordered lookup procedure to determine + * the SAXParserFactory implementation class to + * load: + *

+ * + * Once an application has obtained a reference to a + * SAXParserFactory it can use the factory to + * configure and obtain parser instances. + * + * @return A new instance of a SAXParserFactory. + * + * @exception FactoryConfigurationError if the implementation is + * not available or cannot be instantiated. + */ + + public static SAXParserFactory newInstance() + throws FactoryConfigurationError + { + try { + return (SAXParserFactory) FactoryFinder.find( + /* The default property name according to the JAXP spec */ + "javax.xml.parsers.SAXParserFactory", + /* The fallback implementation class name */ + "org.apache.crimson.jaxp.SAXParserFactoryImpl"); + } catch (FactoryFinder.ConfigurationError e) { + throw new FactoryConfigurationError(e.getException(), + e.getMessage()); + } + } + + /** + * Creates a new instance of a SAXParser using the currently + * configured factory parameters. + * + * @return A new instance of a SAXParser. + * + * @exception ParserConfigurationException if a parser cannot + * be created which satisfies the requested configuration. + */ + + 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 false. + * + * @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 false. + * + * @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; + } + + /** + * + * 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 + * http://www.megginson.com/SAX/Java/features.html + * + * @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; +} diff --git a/java/external/src/javax/xml/parsers/package.html b/java/external/src/javax/xml/parsers/package.html new file mode 100644 index 0000000..458b558 --- /dev/null +++ b/java/external/src/javax/xml/parsers/package.html @@ -0,0 +1,31 @@ + + + + + +Provides classes allowing the processing of XML documents. Two types +of plugable parsers are supported: + + + + + diff --git a/java/external/src/javax/xml/transform/ErrorListener.java b/java/external/src/javax/xml/transform/ErrorListener.java new file mode 100644 index 0000000..e1617c6 --- /dev/null +++ b/java/external/src/javax/xml/transform/ErrorListener.java @@ -0,0 +1,101 @@ +/** + * $Id$ + * + * Copyright (c) 2000-2001 Sun Microsystems, Inc. All Rights Reserved. + * + * This software is the confidential and proprietary information of Sun + * Microsystems, Inc. ("Confidential Information"). You shall not + * disclose such Confidential Information and shall use it only in + * accordance with the terms of the license agreement you entered into + * with Sun. + * + * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE + * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE + * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR + * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES + * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING + * THIS SOFTWARE OR ITS DERIVATIVES. + */ +package javax.xml.transform; + +/** + *

To provide customized error handling, implement this interface and + * use the setErrorListener method to register an instance of the implmentation + * with the {@link javax.xml.transform.Transformer}. The Transformer then reports + * all errors and warnings through this interface.

+ * + *

If an application does not + * register an ErrorListener, errors are reported to System.err.

+ * + *

For transformation errors, a Transformer must use this interface + * instead of throwing an exception: it is up to the application + * to decide whether to throw an exception for different types of + * errors and warnings. Note however that the Transformer is not required + * to continue with the transformation after a call to fatalError.

+ * + *

Transformers may use this mechanism to report XML parsing errors + * as well as transformation errors.

+ */ +public interface ErrorListener { + + /** + * Receive notification of a warning. + * + *

{@link javax.xml.transform.Transformer} can use this method to report + * conditions that are not errors or fatal errors. The default behaviour + * is to take no action.

+ * + *

After invoking this method, the Transformer must continue with + * the transformation. It should still be possible for the + * application to process the document through to the end.

+ * + * @param exception The warning information encapsulated in a + * transformer exception. + * + * @throws javax.xml.transform.TransformerException if the application + * chooses to discontinue the transformation. + * + * @see javax.xml.transform.TransformerException + */ + public abstract void warning(TransformerException exception) + throws TransformerException; + + /** + * Receive notification of a recoverable error. + * + *

The transformer must continue to try and provide normal transformation + * after invoking this method. It should still be possible for the + * application to process the document through to the end if no other errors + * are encountered.

+ * + * @param exception The error information encapsulated in a + * transformer exception. + * + * @throws javax.xml.transform.TransformerException if the application + * chooses to discontinue the transformation. + * + * @see javax.xml.transform.TransformerException + */ + public abstract void error(TransformerException exception) + throws TransformerException; + + /** + * Receive notification of a non-recoverable error. + * + *

The transformer must continue to try and provide normal transformation + * after invoking this method. It should still be possible for the + * application to process the document through to the end if no other errors + * are encountered, but there is no guarantee that the output will be + * useable.

+ * + * @param exception The error information encapsulated in a + * transformer exception. + * + * @throws javax.xml.transform.TransformerException if the application + * chooses to discontinue the transformation. + * + * @see javax.xml.transform.TransformerException + */ + public abstract void fatalError(TransformerException exception) + throws TransformerException; +} diff --git a/java/external/src/javax/xml/transform/FactoryFinder.java b/java/external/src/javax/xml/transform/FactoryFinder.java new file mode 100644 index 0000000..267b338 --- /dev/null +++ b/java/external/src/javax/xml/transform/FactoryFinder.java @@ -0,0 +1,231 @@ +/* + * $Id$ + * + * Copyright (c) 1998-2001 Sun Microsystems, Inc. All Rights Reserved. + * + * This software is the confidential and proprietary information of Sun + * Microsystems, Inc. ("Confidential Information"). You shall not + * disclose such Confidential Information and shall use it only in + * accordance with the terms of the license agreement you entered into + * with Sun. + * + * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE + * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE + * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR + * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES + * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING + * THIS SOFTWARE OR ITS DERIVATIVES. + */ + +package javax.xml.transform; + +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; + +/** + * This class is duplicated for each JAXP subpackage so keep it in + * sync. It is package private. + * + * This code is designed to implement the JAXP 1.1 spec pluggability + * feature and is designed to run on JDK version 1.1 and later including + * JVMs that perform early linking like the Microsoft JVM in IE 5. Note + * however that it must be compiled on a JDK version 1.2 or later system + * since it calls Thread#getContextClassLoader(). The code also runs both + * as part of an unbundled jar file and when bundled as part of the JDK. + */ +class FactoryFinder { + /** Temp debug code - this will be removed after we test everything + */ + private static boolean debug = false; + static { + // Use try/catch block to support applets + try { + debug = System.getProperty("jaxp.debug") != null; + } catch (Exception x) { + } + } + + private static void debugPrintln(String msg) { + if (debug) { + System.err.println("JAXP: " + msg); + } + } + + /** + * Figure out which ClassLoader to use. For JDK 1.2 and later use the + * context ClassLoader if possible. Note: we defer linking the class + * that calls an API only in JDK 1.2 until runtime so that we can catch + * LinkageError so that this code will run in older non-Sun JVMs such + * as the Microsoft JVM in IE. + */ + private static ClassLoader findClassLoader() + throws ConfigurationError + { + ClassLoader classLoader; + try { + // Construct the name of the concrete class to instantiate + Class clazz = Class.forName(FactoryFinder.class.getName() + + "$ClassLoaderFinderConcrete"); + ClassLoaderFinder clf = (ClassLoaderFinder) clazz.newInstance(); + classLoader = clf.getContextClassLoader(); + } catch (LinkageError le) { + // Assume that we are running JDK 1.1, use the current ClassLoader + classLoader = FactoryFinder.class.getClassLoader(); + } catch (ClassNotFoundException x) { + // This case should not normally happen. MS IE can throw this + // instead of a LinkageError the second time Class.forName() is + // called so assume that we are running JDK 1.1 and use the + // current ClassLoader + classLoader = FactoryFinder.class.getClassLoader(); + } catch (Exception x) { + // Something abnormal happened so throw an error + throw new ConfigurationError(x.toString(), x); + } + return classLoader; + } + + /** + * Create an instance of a class using the specified ClassLoader + */ + private static Object newInstance(String className, + ClassLoader classLoader) + throws ConfigurationError + { + try { + Class spiClass; + if (classLoader == null) { + spiClass = Class.forName(className); + } else { + spiClass = classLoader.loadClass(className); + } + return spiClass.newInstance(); + } catch (ClassNotFoundException x) { + throw new ConfigurationError( + "Provider " + className + " not found", x); + } catch (Exception x) { + throw new ConfigurationError( + "Provider " + className + " could not be instantiated: " + x, + x); + } + } + + /** + * Finds the implementation Class object in the specified order. Main + * entry point. + * @return Class object of factory, never null + * + * @param factoryId Name of the factory to find, same as + * a property name + * @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 Object find(String factoryId, String fallbackClassName) + throws ConfigurationError + { + ClassLoader classLoader = findClassLoader(); + + // Use the system property first + try { + String systemProp = + System.getProperty( factoryId ); + if( systemProp!=null) { + debugPrintln("found system property" + systemProp); + return newInstance(systemProp, classLoader); + } + } catch (SecurityException se) { + } + + // 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)); + String factoryClassName = props.getProperty(factoryId); + debugPrintln("found java.home property " + factoryClassName); + return newInstance(factoryClassName, classLoader); + } + } catch(Exception ex ) { + if( debug ) ex.printStackTrace(); + } + + String serviceId = "META-INF/services/" + factoryId; + // try to find services in CLASSPATH + try { + InputStream is=null; + if (classLoader == null) { + is=ClassLoader.getSystemResourceAsStream( serviceId ); + } else { + is=classLoader.getResourceAsStream( serviceId ); + } + + if( is!=null ) { + debugPrintln("found " + serviceId); + BufferedReader rd = + new BufferedReader(new InputStreamReader(is)); + + String factoryClassName = rd.readLine(); + rd.close(); + + if (factoryClassName != null && + ! "".equals(factoryClassName)) { + debugPrintln("loaded from services: " + factoryClassName); + return newInstance(factoryClassName, classLoader); + } + } + } catch( Exception ex ) { + if( debug ) ex.printStackTrace(); + } + + if (fallbackClassName == null) { + throw new ConfigurationError( + "Provider for " + factoryId + " cannot be found", null); + } + + debugPrintln("loaded from fallback value: " + fallbackClassName); + return newInstance(fallbackClassName, classLoader); + } + + static class ConfigurationError extends Error { + private Exception exception; + + /** + * Construct a new instance with the specified detail string and + * exception. + */ + ConfigurationError(String msg, Exception x) { + super(msg); + this.exception = x; + } + + Exception getException() { + return exception; + } + } + + /* + * The following nested classes allow getContextClassLoader() to be + * called only on JDK 1.2 and yet run in older JDK 1.1 JVMs + */ + + private static abstract class ClassLoaderFinder { + abstract ClassLoader getContextClassLoader(); + } + + static class ClassLoaderFinderConcrete extends ClassLoaderFinder { + ClassLoader getContextClassLoader() { + return Thread.currentThread().getContextClassLoader(); + } + } +} diff --git a/java/external/src/javax/xml/transform/OutputKeys.java b/java/external/src/javax/xml/transform/OutputKeys.java new file mode 100644 index 0000000..c0dcb20 --- /dev/null +++ b/java/external/src/javax/xml/transform/OutputKeys.java @@ -0,0 +1,179 @@ +/** + * $Id$ + * + * Copyright (c) 2000-2001 Sun Microsystems, Inc. All Rights Reserved. + * + * This software is the confidential and proprietary information of Sun + * Microsystems, Inc. ("Confidential Information"). You shall not + * disclose such Confidential Information and shall use it only in + * accordance with the terms of the license agreement you entered into + * with Sun. + * + * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE + * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE + * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR + * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES + * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING + * THIS SOFTWARE OR ITS DERIVATIVES. + */ +package javax.xml.transform; + +/** + * Provides string constants that can be used to set + * output properties for a Transformer, or to retrieve + * output properties from a Transformer or Templates object. + *

A properties in this class are read-only.

+ * + * @see section 16 of the XSL Transformations (XSLT) W3C Recommendation + */ +public class OutputKeys { + + /** + * Default constructor is private on purpose. This class is + * only for static variable access, and should never be constructed. + */ + private OutputKeys() {} + + /** + * method = "xml" | "html" | "text" | expanded name. + * + *

The method attribute identifies the overall method that + * should be used for outputting the result tree. Other non-namespaced + * values may be used, such as "xhtml", but, if accepted, the handling + * of such values is implementation defined. If any of the method values + * are not accepted and are not namespace qualified, + * then {@link javax.xml.transform.Transformer#setOutputProperty} + * or {@link javax.xml.transform.Transformer#setOutputProperties} will + * throw a {@link java.lang.IllegalArgumentException}.

+ * + * @see section 16 of the XSL Transformations (XSLT) W3C Recommendation + */ + public static final String METHOD = "method"; + + /** + * version = nmtoken. + * + *

version specifies the version of the output + * method.

+ *

When the output method is "xml", the version value specifies the + * version of XML to be used for outputting the result tree. The default + * value for the xml output method is 1.0. When the output method is + * "html", the version value indicates the version of the HTML. + * The default value for the xml output method is 4.0, which specifies + * that the result should be output as HTML conforming to the HTML 4.0 + * Recommendation [HTML]. If the output method is "text", the version + * property is ignored.

+ * @see section 16 of the XSL Transformations (XSLT) W3C Recommendation + */ + public static final String VERSION = "version"; + + /** + * encoding = string. + * + *

encoding specifies the preferred character + * encoding that the Transformer should use to encode sequences of + * characters as sequences of bytes. The value of the attribute should be + * treated case-insensitively. The value must only contain characters in + * the range #x21 to #x7E (i.e., printable ASCII characters). The value + * should either be a charset registered with the Internet + * Assigned Numbers Authority [IANA], + * [RFC2278] or start with X-.

+ * @see section 16 of the XSL Transformations (XSLT) W3C Recommendation + */ + public static final String ENCODING = "encoding"; + + /** + * omit-xml-declaration = "yes" | "no". + * + *

omit-xml-declaration specifies whether the XSLT + * processor should output an XML declaration; the value must be + * yes or no.

+ * @see section 16 of the XSL Transformations (XSLT) W3C Recommendation + */ + public static final String OMIT_XML_DECLARATION = "omit-xml-declaration"; + + /** + * standalone = "yes" | "no". + * + *

standalone specifies whether the Transformer + * should output a standalone document declaration; the value must be + * yes or no.

+ * @see section 16 of the XSL Transformations (XSLT) W3C Recommendation + */ + public static final String STANDALONE = "standalone"; + + /** + * doctype-public = string. + *

See the documentation for the {@link #DOCTYPE_SYSTEM} property + * for a description of what the value of the key should be.

+ * + * @see section 16 of the XSL Transformations (XSLT) W3C Recommendation + */ + public static final String DOCTYPE_PUBLIC = "doctype-public"; + + /** + * doctype-system = string. + *

doctype-public specifies the public identifier + * to be used in the document type declaration.

+ *

If the doctype-system property is specified, the xml output method + * should output a document type declaration immediately before the first + * element. The name following <!DOCTYPE should be the name of the first + * element. If doctype-public property is also specified, then the xml + * output method should output PUBLIC followed by the public identifier + * and then the system identifier; otherwise, it should output SYSTEM + * followed by the system identifier. The internal subset should be empty. + * The doctype-public attribute should be ignored unless the doctype-system + * attribute is specified.

+ *

If the doctype-public or doctype-system attributes are specified, + * then the html output method should output a document type declaration + * immediately before the first element. The name following <!DOCTYPE + * should be HTML or html. If the doctype-public attribute is specified, + * then the output method should output PUBLIC followed by the specified + * public identifier; if the doctype-system attribute is also specified, + * it should also output the specified system identifier following the + * public identifier. If the doctype-system attribute is specified but + * the doctype-public attribute is not specified, then the output method + * should output SYSTEM followed by the specified system identifier.

+ * + *

doctype-system specifies the system identifier + * to be used in the document type declaration.

+ * @see section 16 of the XSL Transformations (XSLT) W3C Recommendation + */ + public static final String DOCTYPE_SYSTEM = "doctype-system"; + + /** + * cdata-section-elements = expanded names. + * + *

cdata-section-elements specifies a whitespace delimited + * list of the names of elements whose text node children should be output + * using CDATA sections.

+ * + * @see section 16 of the XSL Transformations (XSLT) W3C Recommendation. + */ + public static final String CDATA_SECTION_ELEMENTS = + "cdata-section-elements"; + + /** + * indent = "yes" | "no". + * + *

indent specifies whether the Transformer may + * add additional whitespace when outputting the result tree; the value + * must be yes or no.

+ * @see section 16 of the XSL Transformations (XSLT) W3C Recommendation + */ + public static final String INDENT = "indent"; + + /** + * media-type = string. + * + *

media-type specifies the media type (MIME + * content type) of the data that results from outputting the result + * tree. The charset parameter should not be specified + * explicitly; instead, when the top-level media type is + * text, a charset parameter should be added + * according to the character encoding actually used by the output + * method.

+ * @see section 16 of the XSL Transformations (XSLT) W3C Recommendation + */ + public static final String MEDIA_TYPE = "media-type"; +} diff --git a/java/external/src/javax/xml/transform/Result.java b/java/external/src/javax/xml/transform/Result.java new file mode 100644 index 0000000..70ff6ea --- /dev/null +++ b/java/external/src/javax/xml/transform/Result.java @@ -0,0 +1,83 @@ +/** + * $Id$ + * + * Copyright (c) 2000-2001 Sun Microsystems, Inc. All Rights Reserved. + * + * This software is the confidential and proprietary information of Sun + * Microsystems, Inc. ("Confidential Information"). You shall not + * disclose such Confidential Information and shall use it only in + * accordance with the terms of the license agreement you entered into + * with Sun. + * + * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE + * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE + * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR + * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES + * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING + * THIS SOFTWARE OR ITS DERIVATIVES. + */ +package javax.xml.transform; + +import java.lang.String; + +import java.io.OutputStream; +import java.io.Writer; + + +/** + * An object that implements this interface contains the information + * needed to build a transformation result tree. + */ +public interface Result { + + /** + * The name of the processing instruction that is sent if the + * result tree disables output escaping. + * + *

Normally, result tree serialization escapes & and < (and + * possibly other characters) when outputting text nodes. + * This ensures that the output is well-formed XML. However, + * it is sometimes convenient to be able to produce output that is + * almost, but not quite well-formed XML; for example, + * the output may include ill-formed sections that will + * be transformed into well-formed XML by a subsequent non-XML aware + * process. If a processing instruction is sent with this name, + * serialization should be output without any escaping.

+ * + *

Result DOM trees may also have PI_DISABLE_OUTPUT_ESCAPING and + * PI_ENABLE_OUTPUT_ESCAPING inserted into the tree.

+ * + * @see disable-output-escaping in XSLT Specification + */ + public static final String PI_DISABLE_OUTPUT_ESCAPING = + "javax.xml.transform.disable-output-escaping"; + + /** + * The name of the processing instruction that is sent + * if the result tree enables output escaping at some point after having + * received a PI_DISABLE_OUTPUT_ESCAPING processing instruction. + * + * @see disable-output-escaping in XSLT Specification + */ + public static final String PI_ENABLE_OUTPUT_ESCAPING = + "javax.xml.transform.enable-output-escaping"; + + /** + * Set the system identifier for this Result. + * + *

If the Result is not to be written to a file, the system identifier is optional. + * The application may still want to provide one, however, for use in error messages + * and warnings, or to resolve relative output identifiers.

+ * + * @param systemId The system identifier as a URI string. + */ + public void setSystemId(String systemId); + + /** + * Get the system identifier that was set with setSystemId. + * + * @return The system identifier that was set with setSystemId, + * or null if setSystemId was not called. + */ + public String getSystemId(); +} diff --git a/java/external/src/javax/xml/transform/Source.java b/java/external/src/javax/xml/transform/Source.java new file mode 100644 index 0000000..032e5dc --- /dev/null +++ b/java/external/src/javax/xml/transform/Source.java @@ -0,0 +1,52 @@ +/** + * $Id$ + * + * Copyright (c) 2000-2001 Sun Microsystems, Inc. All Rights Reserved. + * + * This software is the confidential and proprietary information of Sun + * Microsystems, Inc. ("Confidential Information"). You shall not + * disclose such Confidential Information and shall use it only in + * accordance with the terms of the license agreement you entered into + * with Sun. + * + * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE + * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE + * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR + * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES + * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING + * THIS SOFTWARE OR ITS DERIVATIVES. + */ +package javax.xml.transform; + +import java.lang.String; + +import java.io.InputStream; +import java.io.Reader; + + +/** + * An object that implements this interface contains the information + * needed to act as source input (XML source or transformation instructions). + */ +public interface Source { + + /** + * Set the system identifier for this Source. + * + *

The system identifier is optional if the source does not + * get its data from a URL, but it may still be useful to provide one. + * The application can use a system identifier, for example, to resolve + * relative URIs and to include in error messages and warnings.

+ * + * @param systemId The system identifier as a URL string. + */ + public void setSystemId(String systemId); + + /** + * Get the system identifier that was set with setSystemId. + * + * @return The system identifier that was set with setSystemId, or null + * if setSystemId was not called. + */ + public String getSystemId(); +} diff --git a/java/external/src/javax/xml/transform/SourceLocator.java b/java/external/src/javax/xml/transform/SourceLocator.java new file mode 100644 index 0000000..365d725 --- /dev/null +++ b/java/external/src/javax/xml/transform/SourceLocator.java @@ -0,0 +1,89 @@ +/** + * $Id$ + * + * Copyright (c) 2000-2001 Sun Microsystems, Inc. All Rights Reserved. + * + * This software is the confidential and proprietary information of Sun + * Microsystems, Inc. ("Confidential Information"). You shall not + * disclose such Confidential Information and shall use it only in + * accordance with the terms of the license agreement you entered into + * with Sun. + * + * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE + * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE + * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR + * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES + * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING + * THIS SOFTWARE OR ITS DERIVATIVES. + */ +package javax.xml.transform; + +/** + * This interface is primarily for the purposes of reporting where + * an error occurred in the XML source or transformation instructions. + */ +public interface SourceLocator { + + /** + * Return the public identifier for the current document event. + * + *

The return value is the public identifier of the document + * entity or of the external parsed entity in which the markup that + * triggered the event appears.

+ * + * @return A string containing the public identifier, or + * null if none is available. + * @see #getSystemId + */ + public String getPublicId(); + + /** + * Return the system identifier for the current document event. + * + *

The return value is the system identifier of the document + * entity or of the external parsed entity in which the markup that + * triggered the event appears.

+ * + *

If the system identifier is a URL, the parser must resolve it + * fully before passing it to the application.

+ * + * @return A string containing the system identifier, or null + * if none is available. + * @see #getPublicId + */ + public String getSystemId(); + + /** + * Return the line number where the current document event ends. + * + *

Warning: The return value from the method + * is intended only as an approximation for the sake of error + * reporting; it is not intended to provide sufficient information + * to edit the character content of the original XML document.

+ * + *

The return value is an approximation of the line number + * in the document entity or external parsed entity where the + * markup that triggered the event appears.

+ * + * @return The line number, or -1 if none is available. + * @see #getColumnNumber + */ + public int getLineNumber(); + + /** + * Return the character position where the current document event ends. + * + *

Warning: The return value from the method + * is intended only as an approximation for the sake of error + * reporting; it is not intended to provide sufficient information + * to edit the character content of the original XML document.

+ * + *

The return value is an approximation of the column number + * in the document entity or external parsed entity where the + * markup that triggered the event appears.

+ * + * @return The column number, or -1 if none is available. + * @see #getLineNumber + */ + public int getColumnNumber(); +} diff --git a/java/external/src/javax/xml/transform/Templates.java b/java/external/src/javax/xml/transform/Templates.java new file mode 100644 index 0000000..9cd54e6 --- /dev/null +++ b/java/external/src/javax/xml/transform/Templates.java @@ -0,0 +1,76 @@ +/** + * $Id$ + * + * Copyright (c) 2000-2001 Sun Microsystems, Inc. All Rights Reserved. + * + * This software is the confidential and proprietary information of Sun + * Microsystems, Inc. ("Confidential Information"). You shall not + * disclose such Confidential Information and shall use it only in + * accordance with the terms of the license agreement you entered into + * with Sun. + * + * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE + * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE + * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR + * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES + * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING + * THIS SOFTWARE OR ITS DERIVATIVES. + */ +package javax.xml.transform; + +import java.util.Properties; + +import javax.xml.transform.TransformerException; + + +/** + * An object that implements this interface is the runtime representation of processed + * transformation instructions. + * + *

Templates must be threadsafe for a given instance + * over multiple threads running concurrently, and may + * be used multiple times in a given session.

+ */ +public interface Templates { + + /** + * Create a new transformation context for this Templates object. + * + * @return A valid non-null instance of a Transformer. + * + * @throws TransformerConfigurationException if a Transformer can not be created. + */ + Transformer newTransformer() throws TransformerConfigurationException; + + /** + * Get the static properties for xsl:output. The object returned will + * be a clone of the internal values. Accordingly, it can be mutated + * without mutating the Templates object, and then handed in to + * {@link javax.xml.transform.Transformer#setOutputProperties}. + * + *

The properties returned should contain properties set by the stylesheet, + * and these properties are "defaulted" by default properties specified by + * section 16 of the + * XSL Transformations (XSLT) W3C Recommendation. The properties that + * were specifically set by the stylesheet should be in the base + * Properties list, while the XSLT default properties that were not + * specifically set should be in the "default" Properties list. Thus, + * getOutputProperties().getProperty(String key) will obtain any + * property in that was set by the stylesheet, or the default + * properties, while + * getOutputProperties().get(String key) will only retrieve properties + * that were explicitly set in the stylesheet.

+ * + *

For XSLT, + * Attribute + * Value Templates attribute values will + * be returned unexpanded (since there is no context at this point). The + * namespace prefixes inside Attribute Value Templates will be unexpanded, + * so that they remain valid XPath values. (For XSLT 1.0, this is not + * a problem since Attribute Value Templates are not allowed for xsl:output + * attributes. However, the will be allowed in versions after 1.1.)

+ * + * @return A Properties object, never null. + */ + Properties getOutputProperties(); +} diff --git a/java/external/src/javax/xml/transform/Transformer.java b/java/external/src/javax/xml/transform/Transformer.java new file mode 100644 index 0000000..24a1fb2 --- /dev/null +++ b/java/external/src/javax/xml/transform/Transformer.java @@ -0,0 +1,246 @@ +/** + * $Id$ + * + * Copyright (c) 2000-2001 Sun Microsystems, Inc. All Rights Reserved. + * + * This software is the confidential and proprietary information of Sun + * Microsystems, Inc. ("Confidential Information"). You shall not + * disclose such Confidential Information and shall use it only in + * accordance with the terms of the license agreement you entered into + * with Sun. + * + * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE + * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE + * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR + * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES + * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING + * THIS SOFTWARE OR ITS DERIVATIVES. + */ +package javax.xml.transform; + +import java.util.Properties; + + +/** + * An instance of this abstract class can transform a + * source tree into a result tree. + * + *

An instance of this class can be obtained with the + * {@link TransformerFactory#newTransformer TransformerFactory.newTransformer} + * method. This instance may then be used to process XML from a + * variety of sources and write the transformation output to a + * variety of sinks.

+ * + *

An object of this class may not be used in multiple threads + * running concurrently. Different Transformers may be used + * concurrently by different threads.

+ * + *

A Transformer may be used multiple times. Parameters and + * output properties are preserved across transformations.

+ */ +public abstract class Transformer { + + /** + * Default constructor is protected on purpose. + */ + protected Transformer() {} + + /** + * Process the source tree to the output result. + * @param xmlSource The input for the source tree. + * @param outputTarget The output target. + * + * @throws TransformerException If an unrecoverable error occurs + * during the course of the transformation. + */ + public abstract void transform(Source xmlSource, Result outputTarget) + throws TransformerException; + + /** + * Add a parameter for the transformation. + * + *

Pass a qualified name as a two-part string, the namespace URI + * enclosed in curly braces ({}), followed by the local name. If the + * name has a null URL, the String only contain the local name. An + * application can safely check for a non-null URI by testing to see if the first + * character of the name is a '{' character.

+ *

For example, if a URI and local name were obtained from an element + * defined with <xyz:foo xmlns:xyz="http://xyz.foo.com/yada/baz.html"/>, + * then the qualified name would be "{http://xyz.foo.com/yada/baz.html}foo". Note that + * no prefix is used.

+ * + * @param name The name of the parameter, which may begin with a namespace URI + * in curly braces ({}). + * @param value The value object. This can be any valid Java object. It is + * up to the processor to provide the proper object coersion or to simply + * pass the object on for use in an extension. + */ + public abstract void setParameter(String name, Object value); + + /** + * Get a parameter that was explicitly set with setParameter + * or setParameters. + * + *

This method does not return a default parameter value, which + * cannot be determined until the node context is evaluated during + * the transformation process. + * + * @return A parameter that has been set with setParameter. + */ + public abstract Object getParameter(String name); + + /** + * Clear all parameters set with setParameter. + */ + public abstract void clearParameters(); + + /** + * Set an object that will be used to resolve URIs used in + * document(). + * + *

If the resolver argument is null, the URIResolver value will + * be cleared, and the default behavior will be used.

+ * + * @param resolver An object that implements the URIResolver interface, + * or null. + */ + public abstract void setURIResolver(URIResolver resolver); + + /** + * Get an object that will be used to resolve URIs used in + * document(), etc. + * + * @return An object that implements the URIResolver interface, + * or null. + */ + public abstract URIResolver getURIResolver(); + + /** + * Set the output properties for the transformation. These + * properties will override properties set in the Templates + * with xsl:output. + * + *

If argument to this function is null, any properties + * previously set are removed, and the value will revert to the value + * defined in the templates object.

+ * + *

Pass a qualified property key name as a two-part string, the namespace URI + * enclosed in curly braces ({}), followed by the local name. If the + * name has a null URL, the String only contain the local name. An + * application can safely check for a non-null URI by testing to see if the first + * character of the name is a '{' character.

+ *

For example, if a URI and local name were obtained from an element + * defined with <xyz:foo xmlns:xyz="http://xyz.foo.com/yada/baz.html"/>, + * then the qualified name would be "{http://xyz.foo.com/yada/baz.html}foo". Note that + * no prefix is used.

+ * + * @param oformat A set of output properties that will be + * used to override any of the same properties in affect + * for the transformation. + * + * @see javax.xml.transform.OutputKeys + * @see java.util.Properties + * + * @throws IllegalArgumentException if any of the argument keys are not + * recognized and are not namespace qualified. + */ + public abstract void setOutputProperties(Properties oformat) + throws IllegalArgumentException; + + /** + * Get a copy of the output properties for the transformation. + * + *

The properties returned should contain properties set by the user, + * and properties set by the stylesheet, and these properties + * are "defaulted" by default properties specified by section 16 of the + * XSL Transformations (XSLT) W3C Recommendation. The properties that + * were specifically set by the user or the stylesheet should be in the base + * Properties list, while the XSLT default properties that were not + * specifically set should be the default Properties list. Thus, + * getOutputProperties().getProperty(String key) will obtain any + * property in that was set by {@link #setOutputProperty}, + * {@link #setOutputProperties}, in the stylesheet, or the default + * properties, while + * getOutputProperties().get(String key) will only retrieve properties + * that were explicitly set by {@link #setOutputProperty}, + * {@link #setOutputProperties}, or in the stylesheet.

+ * + *

Note that mutation of the Properties object returned will not + * effect the properties that the transformation contains.

+ * + *

If any of the argument keys are not recognized and are not + * namespace qualified, the property will be ignored. In other words the + * behaviour is not orthogonal with setOutputProperties.

+ * + * @returns A copy of the set of output properties in effect + * for the next transformation. + * + * @see javax.xml.transform.OutputKeys + * @see java.util.Properties + */ + public abstract Properties getOutputProperties(); + + /** + * Set an output property that will be in effect for the + * transformation. + * + *

Pass a qualified property name as a two-part string, the namespace URI + * enclosed in curly braces ({}), followed by the local name. If the + * name has a null URL, the String only contain the local name. An + * application can safely check for a non-null URI by testing to see if the first + * character of the name is a '{' character.

+ *

For example, if a URI and local name were obtained from an element + * defined with <xyz:foo xmlns:xyz="http://xyz.foo.com/yada/baz.html"/>, + * then the qualified name would be "{http://xyz.foo.com/yada/baz.html}foo". Note that + * no prefix is used.

+ * + *

The Properties object that was passed to {@link #setOutputProperties} won't + * be effected by calling this method.

+ * + * @param name A non-null String that specifies an output + * property name, which may be namespace qualified. + * @param value The non-null string value of the output property. + * + * @throws IllegalArgumentException If the property is not supported, and is + * not qualified with a namespace. + * + * @see javax.xml.transform.OutputKeys + */ + public abstract void setOutputProperty(String name, String value) + throws IllegalArgumentException; + + /** + * Get an output property that is in effect for the + * transformation. The property specified may be a property + * that was set with setOutputProperty, or it may be a + * property specified in the stylesheet. + * + * @param name A non-null String that specifies an output + * property name, which may be namespace qualified. + * + * @return The string value of the output property, or null + * if no property was found. + * + * @throws IllegalArgumentException If the property is not supported. + * + * @see javax.xml.transform.OutputKeys + */ + public abstract String getOutputProperty(String name) + throws IllegalArgumentException; + + /** + * Set the error event listener in effect for the transformation. + * + * @param listener The new error listener. + * @throws IllegalArgumentException if listener is null. + */ + public abstract void setErrorListener(ErrorListener listener) + throws IllegalArgumentException; + + /** + * Get the error event handler in effect for the transformation. + * + * @return The current error handler, which should never be null. + */ + public abstract ErrorListener getErrorListener(); +} diff --git a/java/external/src/javax/xml/transform/TransformerConfigurationException.java b/java/external/src/javax/xml/transform/TransformerConfigurationException.java new file mode 100644 index 0000000..95f62be --- /dev/null +++ b/java/external/src/javax/xml/transform/TransformerConfigurationException.java @@ -0,0 +1,96 @@ +/* + * $Id$ + * + * Copyright (c) 2000-2001 Sun Microsystems, Inc. All Rights Reserved. + * + * This software is the confidential and proprietary information of Sun + * Microsystems, Inc. ("Confidential Information"). You shall not + * disclose such Confidential Information and shall use it only in + * accordance with the terms of the license agreement you entered into + * with Sun. + * + * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE + * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE + * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR + * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES + * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING + * THIS SOFTWARE OR ITS DERIVATIVES. + */ +package javax.xml.transform; + +/** + * Indicates a serious configuration error. + */ +public class TransformerConfigurationException extends TransformerException { + + /** + * Create a new TransformerConfigurationException with no + * detail mesage. + */ + public TransformerConfigurationException() { + super("Configuration Error"); + } + + /** + * Create a new TransformerConfigurationException with + * the String specified as an error message. + * + * @param msg The error message for the exception. + */ + public TransformerConfigurationException(String msg) { + super(msg); + } + + /** + * Create a new TransformerConfigurationException with a + * given Exception base cause of the error. + * + * @param e The exception to be encapsulated in a + * TransformerConfigurationException. + */ + public TransformerConfigurationException(Throwable e) { + super(e); + } + + /** + * Create a new TransformerConfigurationException with the + * given Exception base cause and detail message. + * + * @param e The exception to be encapsulated in a + * TransformerConfigurationException + * @param msg The detail message. + * @param e The exception to be wrapped in a TransformerConfigurationException + */ + public TransformerConfigurationException(String msg, Throwable e) { + super(msg, e); + } + + /** + * Create a new TransformerConfigurationException from a message and a Locator. + * + *

This constructor is especially useful when an application is + * creating its own exception from within a DocumentHandler + * callback.

+ * + * @param message The error or warning message. + * @param locator The locator object for the error or warning. + */ + public TransformerConfigurationException(String message, + SourceLocator locator) { + super(message, locator); + } + + /** + * Wrap an existing exception in a TransformerConfigurationException. + * + * @param message The error or warning message, or null to + * use the message from the embedded exception. + * @param locator The locator object for the error or warning. + * @param e Any exception. + */ + public TransformerConfigurationException(String message, + SourceLocator locator, + Throwable e) { + super(message, locator, e); + } +} diff --git a/java/external/src/javax/xml/transform/TransformerException.java b/java/external/src/javax/xml/transform/TransformerException.java new file mode 100644 index 0000000..ad3f7ab --- /dev/null +++ b/java/external/src/javax/xml/transform/TransformerException.java @@ -0,0 +1,365 @@ +/** + * $Id$ + * + * Copyright (c) 2000-2001 Sun Microsystems, Inc. All Rights Reserved. + * + * This software is the confidential and proprietary information of Sun + * Microsystems, Inc. ("Confidential Information"). You shall not + * disclose such Confidential Information and shall use it only in + * accordance with the terms of the license agreement you entered into + * with Sun. + * + * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE + * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE + * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR + * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES + * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING + * THIS SOFTWARE OR ITS DERIVATIVES. + */ +package javax.xml.transform; + +import java.lang.reflect.Method; +import java.lang.IllegalAccessException; +import java.lang.reflect.InvocationTargetException; + +import javax.xml.transform.SourceLocator; + + +/** + * This class specifies an exceptional condition that occured + * during the transformation process. + */ +public class TransformerException extends Exception { + + /** Field locator specifies where the error occured */ + SourceLocator locator; + + /** + * Method getLocator retrieves an instance of a SourceLocator + * object that specifies where an error occured. + * + * @return A SourceLocator object, or null if none was specified. + */ + public SourceLocator getLocator() { + return locator; + } + + /** + * Method setLocator sets an instance of a SourceLocator + * object that specifies where an error occured. + * + * @param location A SourceLocator object, or null to clear the location. + */ + public void setLocator(SourceLocator location) { + locator = location; + } + + /** Field containedException specifies a wrapped exception. May be null. */ + Throwable containedException; + + /** + * This method retrieves an exception that this exception wraps. + * + * @return An Throwable object, or null. + * @see #getCause + */ + public Throwable getException() { + return containedException; + } + + /** + * Returns the cause of this throwable or null if the + * cause is nonexistent or unknown. (The cause is the throwable that + * caused this throwable to get thrown.) + */ + public Throwable getCause() { + + return ((containedException == this) + ? null + : containedException); + } + + /** + * Initializes the cause of this throwable to the specified value. + * (The cause is the throwable that caused this throwable to get thrown.) + * + *

This method can be called at most once. It is generally called from + * within the constructor, or immediately after creating the + * throwable. If this throwable was created + * with {@link #TransformerException(Throwable)} or + * {@link #TransformerException(String,Throwable)}, this method cannot be called + * even once. + * + * @param cause the cause (which is saved for later retrieval by the + * {@link #getCause()} method). (A null value is + * permitted, and indicates that the cause is nonexistent or + * unknown.) + * @return a reference to this Throwable instance. + * @throws IllegalArgumentException if cause is this + * throwable. (A throwable cannot + * be its own cause.) + * @throws IllegalStateException if this throwable was + * created with {@link #TransformerException(Throwable)} or + * {@link #TransformerException(String,Throwable)}, or this method has already + * been called on this throwable. + */ + public synchronized Throwable initCause(Throwable cause) { + + if (this.containedException != null) { + throw new IllegalStateException("Can't overwrite cause"); + } + + if (cause == this) { + throw new IllegalArgumentException( + "Self-causation not permitted"); + } + + this.containedException = cause; + + return this; + } + + /** + * Create a new TransformerException. + * + * @param message The error or warning message. + */ + public TransformerException(String message) { + + super(message); + + this.containedException = null; + this.locator = null; + } + + /** + * Create a new TransformerException wrapping an existing exception. + * + * @param e The exception to be wrapped. + */ + public TransformerException(Throwable e) { + + super(e.toString()); + + this.containedException = e; + this.locator = null; + } + + /** + * Wrap an existing exception in a TransformerException. + * + *

This is used for throwing processor exceptions before + * the processing has started.

+ * + * @param message The error or warning message, or null to + * use the message from the embedded exception. + * @param e Any exception + */ + public TransformerException(String message, Throwable e) { + + super(((message == null) || (message.length() == 0)) + ? e.toString() + : message); + + this.containedException = e; + this.locator = null; + } + + /** + * Create a new TransformerException from a message and a Locator. + * + *

This constructor is especially useful when an application is + * creating its own exception from within a DocumentHandler + * callback.

+ * + * @param message The error or warning message. + * @param locator The locator object for the error or warning. + */ + public TransformerException(String message, SourceLocator locator) { + + super(message); + + this.containedException = null; + this.locator = locator; + } + + /** + * Wrap an existing exception in a TransformerException. + * + * @param message The error or warning message, or null to + * use the message from the embedded exception. + * @param locator The locator object for the error or warning. + * @param e Any exception + */ + public TransformerException(String message, SourceLocator locator, + Throwable e) { + + super(message); + + this.containedException = e; + this.locator = locator; + } + + /** + * Get the error message with location information + * appended. + * + * @return A String representing the error message with + * location information appended. + */ + public String getMessageAndLocation() { + + StringBuffer sbuffer = new StringBuffer(); + String message = super.getMessage(); + + if (null != message) { + sbuffer.append(message); + } + + if (null != locator) { + String systemID = locator.getSystemId(); + int line = locator.getLineNumber(); + int column = locator.getColumnNumber(); + + if (null != systemID) { + sbuffer.append("; SystemID: "); + sbuffer.append(systemID); + } + + if (0 != line) { + sbuffer.append("; Line#: "); + sbuffer.append(line); + } + + if (0 != column) { + sbuffer.append("; Column#: "); + sbuffer.append(column); + } + } + + return sbuffer.toString(); + } + + /** + * Get the location information as a string. + * + * @return A string with location info, or null + * if there is no location information. + */ + public String getLocationAsString() { + + if (null != locator) { + StringBuffer sbuffer = new StringBuffer(); + String systemID = locator.getSystemId(); + int line = locator.getLineNumber(); + int column = locator.getColumnNumber(); + + if (null != systemID) { + sbuffer.append("; SystemID: "); + sbuffer.append(systemID); + } + + if (0 != line) { + sbuffer.append("; Line#: "); + sbuffer.append(line); + } + + if (0 != column) { + sbuffer.append("; Column#: "); + sbuffer.append(column); + } + + return sbuffer.toString(); + } else { + return null; + } + } + + /** + * Print the the trace of methods from where the error + * originated. This will trace all nested exception + * objects, as well as this object. + */ + public void printStackTrace() { + printStackTrace(new java.io.PrintWriter(System.err, true)); + } + + /** + * Print the the trace of methods from where the error + * originated. This will trace all nested exception + * objects, as well as this object. + * @param s The stream where the dump will be sent to. + */ + public void printStackTrace(java.io.PrintStream s) { + printStackTrace(new java.io.PrintWriter(s)); + } + + /** + * Print the the trace of methods from where the error + * originated. This will trace all nested exception + * objects, as well as this object. + * @param s The writer where the dump will be sent to. + */ + public void printStackTrace(java.io.PrintWriter s) { + + if (s == null) { + s = new java.io.PrintWriter(System.err, true); + } + + try { + String locInfo = getLocationAsString(); + + if (null != locInfo) { + s.println(locInfo); + } + + super.printStackTrace(s); + } catch (Throwable e) {} + + Throwable exception = getException(); + + for (int i = 0; (i < 10) && (null != exception); i++) { + s.println("---------"); + + try { + if (exception instanceof TransformerException) { + String locInfo = + ((TransformerException) exception) + .getLocationAsString(); + + if (null != locInfo) { + s.println(locInfo); + } + } + + exception.printStackTrace(s); + } catch (Throwable e) { + s.println("Could not print stack trace..."); + } + + try { + Method meth = + ((Object) exception).getClass().getMethod("getException", + null); + + if (null != meth) { + Throwable prev = exception; + + exception = (Throwable) meth.invoke(exception, null); + + if (prev == exception) { + break; + } + } else { + exception = null; + } + } catch (InvocationTargetException ite) { + exception = null; + } catch (IllegalAccessException iae) { + exception = null; + } catch (NoSuchMethodException nsme) { + exception = null; + } + } + } +} diff --git a/java/external/src/javax/xml/transform/TransformerFactory.java b/java/external/src/javax/xml/transform/TransformerFactory.java new file mode 100644 index 0000000..627e4fb --- /dev/null +++ b/java/external/src/javax/xml/transform/TransformerFactory.java @@ -0,0 +1,259 @@ +/** + * $Id$ + * + * Copyright (c) 2000-2001 Sun Microsystems, Inc. All Rights Reserved. + * + * This software is the confidential and proprietary information of Sun + * Microsystems, Inc. ("Confidential Information"). You shall not + * disclose such Confidential Information and shall use it only in + * accordance with the terms of the license agreement you entered into + * with Sun. + * + * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE + * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE + * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR + * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES + * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING + * THIS SOFTWARE OR ITS DERIVATIVES. + */ +package javax.xml.transform; + +import java.io.IOException; +import java.io.File; +import java.io.FileInputStream; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.BufferedReader; + +import java.util.Properties; +import java.util.Enumeration; + +import java.lang.reflect.Method; +import java.lang.reflect.InvocationTargetException; + +/** + * A TransformerFactory instance can be used to create + * {@link javax.xml.transform.Transformer} and + * {@link javax.xml.transform.Templates} objects. + * + *

The system property that determines which Factory implementation to + * create is named "javax.xml.transform.TransformerFactory". + * This property names a concrete subclass of the + * TransformerFactory abstract class. If the property is not + * defined, a platform default is be used.

+ * + * An implementation of the TransformerFactory class is + * NOT guaranteed to be thread safe. It is up to the user application + * to make sure about the use of the TransformerFactory from + * more than one thread. Alternatively the application can have one instance + * of the TransformerFactory per thread. + * An application can use the same instance of the factory to obtain one or + * more instances of a Transformer or Templates + * provided the instance of the factory isn't being used in more than one + * thread at a time. + */ +public abstract class TransformerFactory { + /** + * Default constructor is protected on purpose. + */ + protected TransformerFactory() {} + + /** + * Obtain a new instance of a TransformerFactory. + * This static method creates a new factory instance + * This method uses the following ordered lookup procedure to determine + * the TransformerFactory implementation class to + * load: + * + * + * Once an application has obtained a reference to a + * TransformerFactory it can use the factory to configure + * and obtain parser instances. + * + * @return new TransformerFactory instance, never null. + * + * @throws TransformerFactoryConfigurationError + * if the implmentation is not available or cannot be instantiated. + */ + public static TransformerFactory newInstance() + throws TransformerFactoryConfigurationError + { + try { + return (TransformerFactory) FactoryFinder.find( + /* The default property name according to the JAXP spec */ + "javax.xml.transform.TransformerFactory", + /* The fallback implementation class name */ + "org.apache.xalan.processor.TransformerFactoryImpl"); + } catch (FactoryFinder.ConfigurationError e) { + throw new TransformerFactoryConfigurationError(e.getException(), + e.getMessage()); + } + } + + /** + * Process the Source into a Transformer object. Care must + * be given not to use this object in multiple threads running concurrently. + * Different TransformerFactories can be used concurrently by different + * threads. + * + * @param source An object that holds a URI, input stream, etc. + * + * @return A Transformer object that may be used to perform a transformation + * in a single thread, never null. + * + * @exception TransformerConfigurationException May throw this during the parse + * when it is constructing the Templates object and fails. + */ + public abstract Transformer newTransformer(Source source) + throws TransformerConfigurationException; + + /** + * Create a new Transformer object that performs a copy + * of the source to the result. + * + * @param source An object that holds a URI, input stream, etc. + * + * @return A Transformer object that may be used to perform a transformation + * in a single thread, never null. + * + * @exception TransformerConfigurationException May throw this during + * the parse when it is constructing the + * Templates object and fails. + */ + public abstract Transformer newTransformer() + throws TransformerConfigurationException; + + /** + * Process the Source into a Templates object, which is a + * a compiled representation of the source. This Templates object + * may then be used concurrently across multiple threads. Creating + * a Templates object allows the TransformerFactory to do detailed + * performance optimization of transformation instructions, without + * penalizing runtime transformation. + * + * @param source An object that holds a URL, input stream, etc. + * + * @return A Templates object capable of being used for transformation purposes, + * never null. + * + * @exception TransformerConfigurationException May throw this during the parse when it + * is constructing the Templates object and fails. + */ + public abstract Templates newTemplates(Source source) + throws TransformerConfigurationException; + + /** + * Get the stylesheet specification(s) associated + * via the xml-stylesheet processing instruction (see + * http://www.w3.org/TR/xml-stylesheet/) with the document + * document specified in the source parameter, and that match + * the given criteria. Note that it is possible to return several + * stylesheets, in which case they are applied as if they were + * a list of imports or cascades in a single stylesheet. + * + * @param source The XML source document. + * @param media The media attribute to be matched. May be null, in which + * case the prefered templates will be used (i.e. alternate = no). + * @param title The value of the title attribute to match. May be null. + * @param charset The value of the charset attribute to match. May be null. + * + * @return A Source object suitable for passing to the TransformerFactory. + * + * @throws TransformerConfigurationException. + */ + public abstract Source getAssociatedStylesheet( + Source source, String media, String title, String charset) + throws TransformerConfigurationException; + + /** + * Set an object that is used by default during the transformation + * to resolve URIs used in xsl:import, or xsl:include. + * + * @param resolver An object that implements the URIResolver interface, + * or null. + */ + public abstract void setURIResolver(URIResolver resolver); + + /** + * Get the object that is used by default during the transformation + * to resolve URIs used in document(), xsl:import, or xsl:include. + * + * @return The URIResolver that was set with setURIResolver. + */ + public abstract URIResolver getURIResolver(); + + //======= CONFIGURATION METHODS ======= + + /** + * Look up the value of a feature. + * + *

The feature name is any absolute URI.

+ * @param name The feature name, which is an absolute URI. + * @return The current state of the feature (true or false). + */ + public abstract boolean getFeature(String name); + + /** + * Allows the user to set specific attributes on the underlying + * implementation. An attribute in this context is defined to + * be an option that the implementation provides. + * + * @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; + + /** + * Set the error event listener for the TransformerFactory, which + * is used for the processing of transformation instructions, + * and not for the transformation itself. + * + * @param listener The new error listener. + * @throws IllegalArgumentException if listener is null. + */ + public abstract void setErrorListener(ErrorListener listener) + throws IllegalArgumentException; + + /** + * Get the error event handler for the TransformerFactory. + * + * @return The current error handler, which should never be null. + */ + public abstract ErrorListener getErrorListener(); +} diff --git a/java/external/src/javax/xml/transform/TransformerFactoryConfigurationError.java b/java/external/src/javax/xml/transform/TransformerFactoryConfigurationError.java new file mode 100644 index 0000000..05e2729 --- /dev/null +++ b/java/external/src/javax/xml/transform/TransformerFactoryConfigurationError.java @@ -0,0 +1,112 @@ +/* + * $Id$ + * + * Copyright (c) 2000-2001 Sun Microsystems, Inc. All Rights Reserved. + * + * This software is the confidential and proprietary information of Sun + * Microsystems, Inc. ("Confidential Information"). You shall not + * disclose such Confidential Information and shall use it only in + * accordance with the terms of the license agreement you entered into + * with Sun. + * + * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE + * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE + * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR + * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES + * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING + * THIS SOFTWARE OR ITS DERIVATIVES. + */ +package javax.xml.transform; + +/** + * Thrown when a problem with configuration with the Transformer Factories + * exists. This error will typically be thrown when the class of a + * transformation factory specified in the system properties cannot be found + * or instantiated. + */ +public class TransformerFactoryConfigurationError extends Error { + + private Exception exception; + + /** + * Create a new TransformerFactoryConfigurationError with no + * detail mesage. + */ + public TransformerFactoryConfigurationError() { + + super(); + + this.exception = null; + } + + /** + * Create a new TransformerFactoryConfigurationError with + * the String specified as an error message. + * + * @param msg The error message for the exception. + */ + public TransformerFactoryConfigurationError(String msg) { + + super(msg); + + this.exception = null; + } + + /** + * Create a new TransformerFactoryConfigurationError with a + * given Exception base cause of the error. + * + * @param e The exception to be encapsulated in a + * TransformerFactoryConfigurationError. + */ + public TransformerFactoryConfigurationError(Exception e) { + + super(e.toString()); + + this.exception = e; + } + + /** + * Create a new TransformerFactoryConfigurationError with the + * given Exception base cause and detail message. + * + * @param e The exception to be encapsulated in a + * TransformerFactoryConfigurationError + * @param msg The detail message. + * @param e The exception to be wrapped in a TransformerFactoryConfigurationError + */ + public TransformerFactoryConfigurationError(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 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; + } +} diff --git a/java/external/src/javax/xml/transform/URIResolver.java b/java/external/src/javax/xml/transform/URIResolver.java new file mode 100644 index 0000000..e66ed08 --- /dev/null +++ b/java/external/src/javax/xml/transform/URIResolver.java @@ -0,0 +1,43 @@ +/** + * $Id$ + * + * Copyright (c) 2000-2001 Sun Microsystems, Inc. All Rights Reserved. + * + * This software is the confidential and proprietary information of Sun + * Microsystems, Inc. ("Confidential Information"). You shall not + * disclose such Confidential Information and shall use it only in + * accordance with the terms of the license agreement you entered into + * with Sun. + * + * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE + * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE + * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR + * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES + * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING + * THIS SOFTWARE OR ITS DERIVATIVES. + */ +package javax.xml.transform; + +/** + *

An object that implements this interface that can be called by the processor + * to turn a URI used in document(), xsl:import, or xsl:include into a Source object. + */ +public interface URIResolver { + + /** + * Called by the processor when it encounters + * an xsl:include, xsl:import, or document() function. + * + * @param href An href attribute, which may be relative or absolute. + * @param base The base URI in effect when the href attribute + * was encountered. + * + * @return A Source object, or null if the href cannot be resolved, + * and the processor should try to resolve the URI itself. + * + * @throws TransformerException if an error occurs when trying to + * resolve the URI. + */ + public Source resolve(String href, String base) + throws TransformerException; +} diff --git a/java/external/src/javax/xml/transform/dom/DOMLocator.java b/java/external/src/javax/xml/transform/dom/DOMLocator.java new file mode 100644 index 0000000..803ac4d --- /dev/null +++ b/java/external/src/javax/xml/transform/dom/DOMLocator.java @@ -0,0 +1,43 @@ +/** + * $Id$ + * + * Copyright (c) 2000-2001 Sun Microsystems, Inc. All Rights Reserved. + * + * This software is the confidential and proprietary information of Sun + * Microsystems, Inc. ("Confidential Information"). You shall not + * disclose such Confidential Information and shall use it only in + * accordance with the terms of the license agreement you entered into + * with Sun. + * + * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE + * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE + * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR + * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES + * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING + * THIS SOFTWARE OR ITS DERIVATIVES. + */ +package javax.xml.transform.dom; + +import javax.xml.transform.SourceLocator; + +import org.w3c.dom.Node; + + +/** + * Indicates the position of a node in a source DOM, intended + * primarily for error reporting. To use a DOMLocator, the receiver of an + * error must downcast the {@link javax.xml.transform.SourceLocator} + * object returned by an exception. A {@link javax.xml.transform.Transformer} + * may use this object for purposes other than error reporting, for instance, + * to indicate the source node that originated a result node. + */ +public interface DOMLocator extends SourceLocator { + + /** + * Return the node where the event occurred. + * + * @return The node that is the location for the event. + */ + public Node getOriginatingNode(); +} + diff --git a/java/external/src/javax/xml/transform/dom/DOMResult.java b/java/external/src/javax/xml/transform/dom/DOMResult.java new file mode 100644 index 0000000..241ad80 --- /dev/null +++ b/java/external/src/javax/xml/transform/dom/DOMResult.java @@ -0,0 +1,142 @@ +/** + * $Id$ + * + * Copyright (c) 2000-2001 Sun Microsystems, Inc. All Rights Reserved. + * + * This software is the confidential and proprietary information of Sun + * Microsystems, Inc. ("Confidential Information"). You shall not + * disclose such Confidential Information and shall use it only in + * accordance with the terms of the license agreement you entered into + * with Sun. + * + * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE + * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE + * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR + * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES + * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING + * THIS SOFTWARE OR ITS DERIVATIVES. + */ +package javax.xml.transform.dom; + +import javax.xml.transform.*; + +import java.lang.String; + +import java.io.OutputStream; +import java.io.Writer; + +import org.w3c.dom.Node; + + +/** + * Acts as a holder for a transformation result tree, in the + * form of a Document Object Model (DOM) tree. If no output DOM source is set, + * the transformation will create a Document node as the holder + * for the result of the transformation, which may be retrieved + * with getNode. + */ +public class DOMResult implements Result { + + /** If {@link javax.xml.transform.TransformerFactory#getFeature} + * returns true when passed this value as an argument, + * the Transformer supports Result output of this type. + */ + public static final String FEATURE = + "http://javax.xml.transform.dom.DOMResult/feature"; + + /** + * Zero-argument default constructor. + */ + public DOMResult() {} + + /** + * Use a DOM node to create a new output target. In practice, + * the node should be a {@link org.w3c.dom.Document} node, + * a {@link org.w3c.dom.DocumentFragment} node, or a + * {@link org.w3c.dom.Element} node. In other words, a node + * that accepts children. + * + * @param n The DOM node that will contain the result tree. + */ + public DOMResult(Node node) { + setNode(node); + } + + /** + * Create a new output target with a DOM node. In practice, + * the node should be a {@link org.w3c.dom.Document} node, + * a {@link org.w3c.dom.DocumentFragment} node, or a + * {@link org.w3c.dom.Element} node. In other words, a node + * that accepts children. + * + * @param node The DOM node that will contain the result tree. + * @param systemID The system identifier which may be used in association + * with this node. + */ + public DOMResult(Node node, String systemID) { + setNode(node); + setSystemId(systemID); + } + + /** + * Set the node that will contain the result DOM tree. In practice, + * the node should be a {@link org.w3c.dom.Document} node, + * a {@link org.w3c.dom.DocumentFragment} node, or a + * {@link org.w3c.dom.Element} node. In other words, a node + * that accepts children. + * + * @param node The node to which the transformation + * will be appended. + */ + public void setNode(Node node) { + this.node = node; + } + + /** + * Get the node that will contain the result DOM tree. + * If no node was set via setNode, the node will be + * set by the transformation, and may be obtained from + * this method once the transformation is complete. + * + * @return The node to which the transformation + * will be appended. + */ + public Node getNode() { + return node; + } + + /** + * Method setSystemId Set the systemID that may be used in association + * with the node. + * + * @param systemId The system identifier as a URI string. + */ + public void setSystemId(String systemId) { + this.systemId = systemId; + } + + /** + * Get the system identifier that was set with setSystemId. + * + * @return The system identifier that was set with setSystemId, or null + * if setSystemId was not called. + */ + public String getSystemId() { + return systemId; + } + + ////////////////////////////////////////////////////////////////////// + // Internal state. + ////////////////////////////////////////////////////////////////////// + + /** + * The node to which the transformation will be appended. + */ + private Node node; + + /** + * The systemID that may be used in association + * with the node. + */ + private String systemId; +} diff --git a/java/external/src/javax/xml/transform/dom/DOMSource.java b/java/external/src/javax/xml/transform/dom/DOMSource.java new file mode 100644 index 0000000..91fb5fc --- /dev/null +++ b/java/external/src/javax/xml/transform/dom/DOMSource.java @@ -0,0 +1,131 @@ +/** + * $Id$ + * + * Copyright (c) 2000-2001 Sun Microsystems, Inc. All Rights Reserved. + * + * This software is the confidential and proprietary information of Sun + * Microsystems, Inc. ("Confidential Information"). You shall not + * disclose such Confidential Information and shall use it only in + * accordance with the terms of the license agreement you entered into + * with Sun. + * + * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE + * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE + * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR + * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES + * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING + * THIS SOFTWARE OR ITS DERIVATIVES. + */ +package javax.xml.transform.dom; + +import javax.xml.transform.*; + +import java.lang.String; + +import java.io.OutputStream; +import java.io.Writer; + +import org.w3c.dom.Node; + + +/** + * Acts as a holder for a transformation Source tree in the + * form of a Document Object Model (DOM) tree. + * + * @see Document Object Model (DOM) Level 2 Specification + */ +public class DOMSource implements Source { + + /** If {@link javax.xml.transform.TransformerFactory#getFeature} + * returns true when passed this value as an argument, + * the Transformer supports Source input of this type. + */ + public static final String FEATURE = + "http://javax.xml.transform.dom.DOMSource/feature"; + + /** + * Zero-argument default constructor. If this is used, and + * no DOM source is set, then the Transformer will + * create an empty source Document using + * {@link javax.xml.parsers.DocumentBuilder#newDocument}. + */ + public DOMSource() {} + + /** + * Create a new input source with a DOM node. The operation + * will be applied to the subtree rooted at this node. In XSLT, + * a "/" pattern still means the root of the tree (not the subtree), + * and the evaluation of global variables and parameters is done + * from the root node also. + * + * @param n The DOM node that will contain the Source tree. + */ + public DOMSource(Node n) { + setNode(n); + } + + /** + * Create a new input source with a DOM node, and with the + * system ID also passed in as the base URI. + * + * @param node The DOM node that will contain the Source tree. + * @param systemID Specifies the base URI associated with node. + */ + public DOMSource(Node node, String systemID) { + setNode(node); + setSystemId(systemID); + } + + /** + * Set the node that will represents a Source DOM tree. + * + * @param node The node that is to be transformed. + */ + public void setNode(Node node) { + this.node = node; + } + + /** + * Get the node that represents a Source DOM tree. + * + * @return The node that is to be transformed. + */ + public Node getNode() { + return node; + } + + /** + * Set the base ID (URL or system ID) from where URLs + * will be resolved. + * + * @param baseID Base URL for this DOM tree. + */ + public void setSystemId(String baseID) { + this.baseID = baseID; + } + + /** + * Get the base ID (URL or system ID) from where URLs + * will be resolved. + * + * @return Base URL for this DOM tree. + */ + public String getSystemId() { + return this.baseID; + } + + ////////////////////////////////////////////////////////////////////// + // Internal state. + ////////////////////////////////////////////////////////////////////// + + /** + * Field node + */ + private Node node; + + /** + * The base ID (URL or system ID) from where URLs + * will be resolved. + */ + String baseID; +} diff --git a/java/external/src/javax/xml/transform/dom/package.html b/java/external/src/javax/xml/transform/dom/package.html new file mode 100644 index 0000000..267e771 --- /dev/null +++ b/java/external/src/javax/xml/transform/dom/package.html @@ -0,0 +1,36 @@ + + + + +javax.xml.transform.dom + + +

This package implements DOM-specific transformation APIs.

+

The {@link javax.xml.transform.dom.DOMSource} class allows the +client of the implementation of this API to specify a DOM +{@link org.w3c.dom.Node} as the source of the input tree. The model of +how the Transformer deals with the DOM tree in terms of mismatches with the +XSLT data model or +other data models is beyond the scope of this document. Any of the nodes +derived from {@link org.w3c.dom.Node} are legal input.

+

The {@link javax.xml.transform.dom.DOMResult} class allows +a {@link org.w3c.dom.Node} to be specified to which result DOM nodes will +be appended. If an output node is not specified, the transformer will use +{@link javax.xml.parsers.DocumentBuilder#newDocument} to create an +output {@link org.w3c.dom.Document} node. If a node is specified, it +should be one of the following: {@link org.w3c.dom.Document}, +{@link org.w3c.dom.Element}, or +{@link org.w3c.dom.DocumentFragment}. Specification of any other node +type is implementation dependent and undefined by this API. If the result is a +{@link org.w3c.dom.Document}, the output of the transformation must have +a single element root to set as the document element.

+

The {@link javax.xml.transform.dom.DOMLocator} node may be passed +to {@link javax.xml.transform.TransformerException} objects, and +retrieved by trying to cast the result of the +{@link javax.xml.transform.TransformerException#getLocator()} method. +The implementation has no responsibility to use a DOMLocator instead of a +{@link javax.xml.transform.SourceLocator} (though line numbers and the +like do not make much sense for a DOM), so the result of getLocator must always +be tested with an instanceof.

+ + diff --git a/java/external/src/javax/xml/transform/overview.html b/java/external/src/javax/xml/transform/overview.html new file mode 100644 index 0000000..0cb1eac --- /dev/null +++ b/java/external/src/javax/xml/transform/overview.html @@ -0,0 +1,258 @@ + + + + + + + + +

Transformation API For XML

+ + +

Introduction

+ +

This overview describes the set of APIs contained in + javax.xml.transform. For the sake of brevity, these interfaces are referred to + as TrAX (Transformations for XML).

+ +

There is a broad need for Java applications to be able to transform XML + and related tree-shaped data structures. In fact, XML is not normally very + useful to an application without going through some sort of transformation, + unless the semantic structure is used directly as data. Almost all XML-related + applications need to perform transformations. Transformations may be described + by Java code, Perl code, XSLT + Stylesheets, other types of script, or by proprietary formats. The inputs, one + or multiple, to a transformation, may be a URL, XML stream, a DOM tree, SAX + Events, or a proprietary format or data structure. The output types are the + pretty much the same types as the inputs, but different inputs may need to be + combined with different outputs.

+ +

The great challenge of a transformation API is how to deal with all the + possible combinations of inputs and outputs, without becoming specialized for + any of the given types.

+ +

The Java community will greatly benefit from a common API that will + allow them to understand and apply a single model, write to consistent + interfaces, and apply the transformations polymorphically. TrAX attempts to + define a model that is clean and generic, yet fills general application + requirements across a wide variety of uses.

+ + +

General Terminology

+ +

This section will explain some general terminology used in this + document. Technical terminology will be explained in the Model section. In many + cases, the general terminology overlaps with the technical terminology.

+ + + + + +

Model

+ +

The section defines the abstract model for TrAX, apart from the details + of the interfaces.

+ +

A TRaX TransformerFactory is an object + that processes transformation instructions, and produces + Templates (in the technical + terminology). A Templates + object provides a Transformer, which transforms one or + more Sources into one or more + Results.

+ +

To use the TRaX interface, you create a + TransformerFactory, + which may directly provide a Transformers, or which can provide + Templates from a variety of + Sources. The + Templates object is a processed + or compiled representation of the transformation instructions, and provides a + Transformer. The + Transformer processes a + Source according to the + instructions found in the Templates, and produces a + Result.

+ +

The process of transformation from a tree, either in the form of an + object model, or in the form of parse events, into a stream, is known as + serialization. We believe this is the most suitable term for + this process, despite the overlap with Java object serialization.

+ +

TRaX Patterns

+ + + + + diff --git a/java/external/src/javax/xml/transform/package.html b/java/external/src/javax/xml/transform/package.html new file mode 100644 index 0000000..5ee47f2 --- /dev/null +++ b/java/external/src/javax/xml/transform/package.html @@ -0,0 +1,177 @@ + + + + +javax.xml.transform + + +

This package defines the generic APIs for processing transformation + instructions, and performing a transformation from source to result. These + interfaces have no dependencies on SAX or the DOM standard, and try to make as + few assumptions as possible about the details of the source and result of a + transformation. It achieves this by defining + {@link javax.xml.transform.Source} and + {@link javax.xml.transform.Result} interfaces.

+

To define concrete classes for the user, the API defines specializations + of the interfaces found at the root level. These interfaces are found in + {@link javax.xml.transform.sax}, {@link javax.xml.transform.dom}, + and {@link javax.xml.transform.stream}.

+ +

Creating Objects

+ +

The API allows a concrete + {@link javax.xml.transform.TransformerFactory} object to be created from + the static function + {@link javax.xml.transform.TransformerFactory#newInstance}. + + +

Specification of Inputs and Outputs

+ +

This API defines two interface objects called + {@link javax.xml.transform.Source} and + {@link javax.xml.transform.Result}. In order to pass Source and Result + objects to the interfaces, concrete classes must be used. + Three concrete representations are defined for each of these + objects: + {@link javax.xml.transform.stream.StreamSource} and + {@link javax.xml.transform.stream.StreamResult}, + {@link javax.xml.transform.sax.SAXSource} and + {@link javax.xml.transform.sax.SAXResult}, and + {@link javax.xml.transform.dom.DOMSource} and + {@link javax.xml.transform.dom.DOMResult}. Each of these objects defines + a FEATURE string (which is i the form of a URL), which can be passed into + {@link javax.xml.transform.TransformerFactory#getFeature} to see if the + given type of Source or Result object is supported. For instance, to test if a + DOMSource and a StreamResult is supported, you can apply the following + test.

+ + +
    TransformerFactory tfactory = TransformerFactory.newInstance();
+
+    if (tfactory.getFeature(DOMSource.FEATURE) && tfactory.getFeature(StreamResult.FEATURE))
+    {
+       ...
+    }
+
+ + +

+Qualified Name Representation +

+ +

+Namespaces + present something of a problem area when dealing with XML objects. Qualified + Names appear in XML markup as prefixed names. But the prefixes themselves do + not hold identity. Rather, it is the URIs that they contextually map to that + hold the identity. Therefore, when passing a Qualified Name like "xyz:foo" + among Java programs, one must provide a means to map "xyz" to a namespace. +

+ +

One solution has been to create a "QName" object that holds the + namespace URI, as well as the prefix and local name, but this is not always an + optimal solution, as when, for example, you want to use unique strings as keys + in a dictionary object. Not having a string representation also makes it + difficult to specify a namespaced identity outside the context of an XML + document.

+ +

In order to pass namespaced values to transformations, for instance + as a set of properties to the Serializer, this specification defines that a + String "qname" object parameter be passed as two-part string, the namespace URI + enclosed in curly braces ({}), followed by the local name. If the qname has a + null URI, then the String object only contains the local name. An application + can safely check for a non-null URI by testing to see if the first character of + the name is a '{' character.

+ +

For example, if a URI and local name were obtained from an element + defined with <xyz:foo xmlns:xyz="http://xyz.foo.com/yada/baz.html"/>, + then the Qualified Name would be "{http://xyz.foo.com/yada/baz.html}foo". + Note that the prefix is lost.

+ + +

Result Tree Serialization

+ +

Serialization of the result tree to a stream can be controlled with + the {@link javax.xml.transform.Transformer#setOutputProperties} and the + {@link javax.xml.transform.Transformer#setOutputProperty} methods. + Strings that match the XSLT + specification for xsl:output attributes can be referenced from the + {@link javax.xml.transform.OutputKeys} class. Other strings can be + specified as well. If the transformer does not recognize an output key, a + {@link java.lang.IllegalArgumentException} is thrown, unless the + key name is namespace qualified. Output key names that are + qualified by a namespace are ignored or passed on to the serializer + mechanism.

+ +

If all that is desired is the simple identity transformation of a + source to a result, then {@link javax.xml.transform.TransformerFactory} + provides a + {@link javax.xml.transform.TransformerFactory#newTransformer()} method + with no arguments. This method creates a Transformer that effectively copies + the source to the result. This method may be used to create a DOM from SAX + events or to create an XML or HTML stream from a DOM or SAX events.

+ + + +

Exceptions and Error Reporting

+ +

The transformation API throw three types of specialized exceptions. A + {@link javax.xml.transform.TransformerFactoryConfigurationError} is parallel to + the {@link javax.xml.parsers.FactoryConfigurationError}, and is thrown + when a configuration problem with the TransformerFactory exists. This error + will typically be thrown when the transformation factory class specified with + the "javax.xml.transform.TransformerFactory" system property cannot be found or + instantiated.

+ +

A {@link javax.xml.transform.TransformerConfigurationException} + may be thrown if for any reason a Transformer can not be created. A + TransformerConfigurationException may be thrown if there is a syntax error in + the transformation instructions, for example when + {@link javax.xml.transform.TransformerFactory#newTransformer} is + called.

+ +

{@link javax.xml.transform.TransformerException} is a general + exception that occurs during the course of a transformation. A transformer + exception may wrap another exception, and if any of the + {@link javax.xml.transform.TransformerException#printStackTrace()} + methods are called on it, it will produce a list of stack dumps, starting from + the most recent. The transformer exception also provides a + {@link javax.xml.transform.SourceLocator} object which indicates where + in the source tree or transformation instructions the error occurred. + {@link javax.xml.transform.TransformerException#getMessageAndLocation()} + may be called to get an error message with location info, and + {@link javax.xml.transform.TransformerException#getLocationAsString()} + may be called to get just the location string.

+ +

Transformation warnings and errors are normally first sent to a + {@link javax.xml.transform.ErrorListener}, at which point the + implementor may decide to report the error or warning, and may decide to throw + an exception for a non-fatal error. The error listener may be set via + {@link javax.xml.transform.TransformerFactory#setErrorListener} for + reporting errors that have to do with syntax errors in the transformation + instructions, or via + {@link javax.xml.transform.Transformer#setErrorListener} to report + errors that occur during the transformation. The error listener on both objects + should always be valid and non-null, whether set by the user or a default + implementation provided by the processor.

+ + +

Resolution of URIs within a transformation

+ +

The API provides a way for URIs referenced from within the stylesheet + instructions or within the transformation to be resolved by the calling + application. This can be done by creating a class that implements the + {@link javax.xml.transform.URIResolver} interface, with its one method, + {@link javax.xml.transform.URIResolver#resolve}, and use this class to + set the URI resolution for the transformation instructions or transformation + with {@link javax.xml.transform.TransformerFactory#setURIResolver} or + {@link javax.xml.transform.Transformer#setURIResolver}. The + URIResolver.resolve method takes two String arguments, the URI found in the + stylesheet instructions or built as part of the transformation process, and the + base URI in effect when the URI passed as the first argument was encountered. + The returned {@link javax.xml.transform.Source} object must be usable by + the transformer, as specified in its implemented features.

+ + + + diff --git a/java/external/src/javax/xml/transform/sax/SAXResult.java b/java/external/src/javax/xml/transform/sax/SAXResult.java new file mode 100644 index 0000000..c31a64d --- /dev/null +++ b/java/external/src/javax/xml/transform/sax/SAXResult.java @@ -0,0 +1,141 @@ +/** + * $Id$ + * + * Copyright (c) 2000-2001 Sun Microsystems, Inc. All Rights Reserved. + * + * This software is the confidential and proprietary information of Sun + * Microsystems, Inc. ("Confidential Information"). You shall not + * disclose such Confidential Information and shall use it only in + * accordance with the terms of the license agreement you entered into + * with Sun. + * + * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE + * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE + * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR + * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES + * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING + * THIS SOFTWARE OR ITS DERIVATIVES. + */ +package javax.xml.transform.sax; + +import javax.xml.transform.*; + +import java.lang.String; + +import java.io.OutputStream; +import java.io.Writer; + +import org.xml.sax.ContentHandler; +import org.xml.sax.ext.DeclHandler; +import org.xml.sax.ext.LexicalHandler; + + +/** + * Acts as an holder for a transformation Result. + */ +public class SAXResult implements Result { + + /** + * If {@link javax.xml.transform.TransformerFactory#getFeature} + * returns true when passed this value as an argument, + * the Transformer supports Result output of this type. + */ + public static final String FEATURE = + "http://javax.xml.transform.sax.SAXResult/feature"; + + /** + * Zero-argument default constructor. + */ + public SAXResult() {} + + /** + * Create a SAXResult that targets a SAX2 {@link org.xml.sax.ContentHandler}. + * + * @param handler Must be a non-null ContentHandler reference. + */ + public SAXResult(ContentHandler handler) { + setHandler(handler); + } + + /** + * Set the target to be a SAX2 {@link org.xml.sax.ContentHandler}. + * + * @param handler Must be a non-null ContentHandler reference. + */ + public void setHandler(ContentHandler handler) { + this.handler = handler; + } + + /** + * Get the {@link org.xml.sax.ContentHandler} that is the Result. + * + * @return The ContentHandler that is to be transformation output. + */ + public ContentHandler getHandler() { + return handler; + } + + /** + * Set the SAX2 {@link org.xml.sax.ext.LexicalHandler} for the output. + * + *

This is needed to handle XML comments and the like. If the + * lexical handler is not set, an attempt should be made by the + * transformer to cast the {@link org.xml.sax.ContentHandler} to a + * LexicalHandler.

+ * + * @param handler A non-null LexicalHandler for + * handling lexical parse events. + */ + public void setLexicalHandler(LexicalHandler handler) { + this.lexhandler = handler; + } + + /** + * Get a SAX2 {@link org.xml.sax.ext.LexicalHandler} for the output. + * + * @return A LexicalHandler, or null. + */ + public LexicalHandler getLexicalHandler() { + return lexhandler; + } + + /** + * Method setSystemId Set the systemID that may be used in association + * with the {@link org.xml.sax.ContentHandler}. + * + * @param systemId The system identifier as a URI string. + */ + public void setSystemId(String systemId) { + this.systemId = systemId; + } + + /** + * Get the system identifier that was set with setSystemId. + * + * @return The system identifier that was set with setSystemId, or null + * if setSystemId was not called. + */ + public String getSystemId() { + return systemId; + } + + ////////////////////////////////////////////////////////////////////// + // Internal state. + ////////////////////////////////////////////////////////////////////// + + /** + * The handler for parse events. + */ + private ContentHandler handler; + + /** + * The handler for lexical events. + */ + private LexicalHandler lexhandler; + + /** + * The systemID that may be used in association + * with the node. + */ + private String systemId; +} diff --git a/java/external/src/javax/xml/transform/sax/SAXSource.java b/java/external/src/javax/xml/transform/sax/SAXSource.java new file mode 100644 index 0000000..88f0aad --- /dev/null +++ b/java/external/src/javax/xml/transform/sax/SAXSource.java @@ -0,0 +1,192 @@ +/** + * $Id$ + * + * Copyright (c) 2000-2001 Sun Microsystems, Inc. All Rights Reserved. + * + * This software is the confidential and proprietary information of Sun + * Microsystems, Inc. ("Confidential Information"). You shall not + * disclose such Confidential Information and shall use it only in + * accordance with the terms of the license agreement you entered into + * with Sun. + * + * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE + * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE + * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR + * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES + * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING + * THIS SOFTWARE OR ITS DERIVATIVES. + */ +package javax.xml.transform.sax; + +import javax.xml.transform.Source; +import javax.xml.transform.stream.StreamSource; + +import java.lang.String; + +import java.io.OutputStream; +import java.io.Writer; + +import org.xml.sax.XMLReader; +import org.xml.sax.ext.DeclHandler; +import org.xml.sax.ext.LexicalHandler; +import org.xml.sax.InputSource; + + +/** + * Acts as an holder for SAX-style Source. + */ +public class SAXSource implements Source { + + /** + * If {@link javax.xml.transform.TransformerFactory#getFeature} + * returns true when passed this value as an argument, + * the Transformer supports Source input of this type. + */ + public static final String FEATURE = + "http://javax.xml.transform.sax.SAXSource/feature"; + + /** + * Zero-argument default constructor. If this constructor + * is used, and no other method is called, the + * {@link javax.xml.transform.Transformer} + * assumes an empty input tree, with a default root node. + */ + public SAXSource() {} + + /** + * Create a SAXSource, using an {@link org.xml.sax.XMLReader} + * and a SAX InputSource. The {@link javax.xml.transform.Transformer} + * or {@link javax.xml.transform.sax.SAXTransformerFactory} will set itself + * to be the reader's {@link org.xml.sax.ContentHandler}, and then will call + * reader.parse(inputSource). + * + * @param reader An XMLReader to be used for the parse. + * @param inputSource A SAX input source reference that must be non-null + * and that will be passed to the reader parse method. + */ + public SAXSource(XMLReader reader, InputSource inputSource) { + this.reader = reader; + this.inputSource = inputSource; + } + + /** + * Create a SAXSource, using a SAX InputSource. + * The {@link javax.xml.transform.Transformer} or + * {@link javax.xml.transform.sax.SAXTransformerFactory} creates a + * reader via {@link org.xml.sax.helpers.XMLReaderFactory} + * (if setXMLReader is not used), sets itself as + * the reader's {@link org.xml.sax.ContentHandler}, and calls + * reader.parse(inputSource). + * + * @param inputSource An input source reference that must be non-null + * and that will be passed to the parse method of the reader. + */ + public SAXSource(InputSource inputSource) { + this.inputSource = inputSource; + } + + /** + * Set the XMLReader to be used for the Source. + * + * @param reader A valid XMLReader or XMLFilter reference. + */ + public void setXMLReader(XMLReader reader) { + this.reader = reader; + } + + /** + * Get the XMLReader to be used for the Source. + * + * @return A valid XMLReader or XMLFilter reference, or null. + */ + public XMLReader getXMLReader() { + return reader; + } + + /** + * Set the SAX InputSource to be used for the Source. + * + * @param inputSource A valid InputSource reference. + */ + public void setInputSource(InputSource inputSource) { + this.inputSource = inputSource; + } + + /** + * Get the SAX InputSource to be used for the Source. + * + * @return A valid InputSource reference, or null. + */ + public InputSource getInputSource() { + return inputSource; + } + + /** + * Set the system identifier for this Source. If an input source + * has already been set, it will set the system ID or that + * input source, otherwise it will create a new input source. + * + *

The system identifier is optional if there is a byte stream + * or a character stream, but it is still useful to provide one, + * since the application can use it to resolve relative URIs + * and can include it in error messages and warnings (the parser + * will attempt to open a connection to the URI only if + * no byte stream or character stream is specified).

+ * + * @param systemId The system identifier as a URI string. + */ + public void setSystemId(String systemId) { + + if (null == inputSource) { + inputSource = new InputSource(systemId); + } else { + inputSource.setSystemId(systemId); + } + } + + /** + * Get the base ID (URI or system ID) from where URIs + * will be resolved. + * + * @return Base URL for the Source, or null. + */ + public String getSystemId() { + + return (null != inputSource) + ? inputSource.getSystemId() + : null; + } + + /** The XMLReader to be used for the source tree input. May be null. */ + private XMLReader reader; + + /** The SAX InputSource to be used for the source tree input. Should not be null. */ + private InputSource inputSource; + + /** + * Attempt to obtain a SAX InputSource object from a TrAX Source + * object. + * + * @param source Must be a non-null Source reference. + * + * @return An InputSource, or null if Source can not be converted. + */ + public static InputSource sourceToInputSource(Source source) { + + if (source instanceof SAXSource) { + return ((SAXSource) source).getInputSource(); + } else if (source instanceof StreamSource) { + StreamSource ss = (StreamSource) source; + InputSource isource = new InputSource(ss.getSystemId()); + + isource.setByteStream(ss.getInputStream()); + isource.setCharacterStream(ss.getReader()); + isource.setPublicId(ss.getPublicId()); + + return isource; + } else { + return null; + } + } +} + diff --git a/java/external/src/javax/xml/transform/sax/SAXTransformerFactory.java b/java/external/src/javax/xml/transform/sax/SAXTransformerFactory.java new file mode 100644 index 0000000..ed4177f --- /dev/null +++ b/java/external/src/javax/xml/transform/sax/SAXTransformerFactory.java @@ -0,0 +1,149 @@ +/** + * $Id$ + * + * Copyright (c) 2000-2001 Sun Microsystems, Inc. All Rights Reserved. + * + * This software is the confidential and proprietary information of Sun + * Microsystems, Inc. ("Confidential Information"). You shall not + * disclose such Confidential Information and shall use it only in + * accordance with the terms of the license agreement you entered into + * with Sun. + * + * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE + * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE + * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR + * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES + * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING + * THIS SOFTWARE OR ITS DERIVATIVES. + */ +package javax.xml.transform.sax; + +import javax.xml.transform.*; + +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; +import org.xml.sax.SAXNotSupportedException; +import org.xml.sax.SAXNotRecognizedException; +import org.xml.sax.XMLReader; +import org.xml.sax.XMLFilter; + + +/** + * This class extends TransformerFactory to provide SAX-specific + * factory methods. It provides two types of ContentHandlers, + * one for creating Transformers, the other for creating Templates + * objects. + * + *

If an application wants to set the ErrorHandler or EntityResolver + * for an XMLReader used during a transformation, it should use a URIResolver + * to return the SAXSource which provides (with getXMLReader) a reference to + * the XMLReader.

+ */ +public abstract class SAXTransformerFactory extends TransformerFactory { + + /** If {@link javax.xml.transform.TransformerFactory#getFeature} + * returns true when passed this value as an argument, + * the TransformerFactory returned from + * {@link javax.xml.transform.TransformerFactory#newInstance} may + * be safely cast to a SAXTransformerFactory. + */ + public static final String FEATURE = + "http://javax.xml.transform.sax.SAXTransformerFactory/feature"; + + /** If {@link javax.xml.transform.TransformerFactory#getFeature} + * returns true when passed this value as an argument, + * the {@link #newXMLFilter(Source src)} + * and {@link #newXMLFilter(Templates templates)} methods are supported. + */ + public static final String FEATURE_XMLFILTER = + "http://javax.xml.transform.sax.SAXTransformerFactory/feature/xmlfilter"; + + /** + * The default constructor is protected on purpose. + */ + protected SAXTransformerFactory() {} + + /** + * Get a TransformerHandler object that can process SAX + * ContentHandler events into a Result, based on the transformation + * instructions specified by the argument. + * + * @param src The Source of the transformation instructions. + * + * @return TransformerHandler ready to transform SAX events. + * + * @throws TransformerConfigurationException If for some reason the + * TransformerHandler can not be created. + */ + public abstract TransformerHandler newTransformerHandler(Source src) + throws TransformerConfigurationException; + + /** + * Get a TransformerHandler object that can process SAX + * ContentHandler events into a Result, based on the Templates argument. + * + * @param templates The compiled transformation instructions. + * + * @return TransformerHandler ready to transform SAX events. + * + * @throws TransformerConfigurationException If for some reason the + * TransformerHandler can not be created. + */ + public abstract TransformerHandler newTransformerHandler( + Templates templates) throws TransformerConfigurationException; + + /** + * Get a TransformerHandler object that can process SAX + * ContentHandler events into a Result. The transformation + * is defined as an identity (or copy) transformation, for example + * to copy a series of SAX parse events into a DOM tree. + * + * @return A non-null reference to a TransformerHandler, that may + * be used as a ContentHandler for SAX parse events. + * + * @throws TransformerConfigurationException If for some reason the + * TransformerHandler cannot be created. + */ + public abstract TransformerHandler newTransformerHandler() + throws TransformerConfigurationException; + + /** + * Get a TemplatesHandler object that can process SAX + * ContentHandler events into a Templates object. + * + * @return A non-null reference to a TransformerHandler, that may + * be used as a ContentHandler for SAX parse events. + * + * @throws TransformerConfigurationException If for some reason the + * TemplatesHandler cannot be created. + */ + public abstract TemplatesHandler newTemplatesHandler() + throws TransformerConfigurationException; + + /** + * Create an XMLFilter that uses the given Source as the + * transformation instructions. + * + * @param src The Source of the transformation instructions. + * + * @return An XMLFilter object, or null if this feature is not supported. + * + * @throws TransformerConfigurationException If for some reason the + * TemplatesHandler cannot be created. + */ + public abstract XMLFilter newXMLFilter(Source src) + throws TransformerConfigurationException; + + /** + * Create an XMLFilter, based on the Templates argument.. + * + * @param templates The compiled transformation instructions. + * + * @return An XMLFilter object, or null if this feature is not supported. + * + * @throws TransformerConfigurationException If for some reason the + * TemplatesHandler cannot be created. + */ + public abstract XMLFilter newXMLFilter(Templates templates) + throws TransformerConfigurationException; +} diff --git a/java/external/src/javax/xml/transform/sax/TemplatesHandler.java b/java/external/src/javax/xml/transform/sax/TemplatesHandler.java new file mode 100644 index 0000000..eef3006 --- /dev/null +++ b/java/external/src/javax/xml/transform/sax/TemplatesHandler.java @@ -0,0 +1,63 @@ +/** + * $Id$ + * + * Copyright (c) 2000-2001 Sun Microsystems, Inc. All Rights Reserved. + * + * This software is the confidential and proprietary information of Sun + * Microsystems, Inc. ("Confidential Information"). You shall not + * disclose such Confidential Information and shall use it only in + * accordance with the terms of the license agreement you entered into + * with Sun. + * + * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE + * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE + * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR + * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES + * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING + * THIS SOFTWARE OR ITS DERIVATIVES. + */ +package javax.xml.transform.sax; + +import javax.xml.transform.*; + +import org.xml.sax.ContentHandler; +import org.xml.sax.ext.LexicalHandler; + + +/** + * A SAX ContentHandler that may be used to process SAX + * parse events (parsing transformation instructions) into a Templates object. + * + *

Note that TemplatesHandler does not need to implement LexicalHandler.

+ */ +public interface TemplatesHandler extends ContentHandler { + + /** + * When a TemplatesHandler object is used as a ContentHandler + * for the parsing of transformation instructions, it creates a Templates object, + * which the caller can get once the SAX events have been completed. + * + * @return The Templates object that was created during + * the SAX event process, or null if no Templates object has + * been created. + * + */ + public Templates getTemplates(); + + /** + * Set the base ID (URI or system ID) for the Templates object + * created by this builder. This must be set in order to + * resolve relative URIs in the stylesheet. This must be + * called before the startDocument event. + * + * @param baseID Base URI for this stylesheet. + */ + public void setSystemId(String systemID); + + /** + * Get the base ID (URI or system ID) from where relative + * URLs will be resolved. + * @return The systemID that was set with {@link #setSystemId}. + */ + public String getSystemId(); +} diff --git a/java/external/src/javax/xml/transform/sax/TransformerHandler.java b/java/external/src/javax/xml/transform/sax/TransformerHandler.java new file mode 100644 index 0000000..a3f8cbd --- /dev/null +++ b/java/external/src/javax/xml/transform/sax/TransformerHandler.java @@ -0,0 +1,70 @@ +/** + * $Id$ + * + * Copyright (c) 2000-2001 Sun Microsystems, Inc. All Rights Reserved. + * + * This software is the confidential and proprietary information of Sun + * Microsystems, Inc. ("Confidential Information"). You shall not + * disclose such Confidential Information and shall use it only in + * accordance with the terms of the license agreement you entered into + * with Sun. + * + * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE + * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE + * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR + * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES + * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING + * THIS SOFTWARE OR ITS DERIVATIVES. + */ +package javax.xml.transform.sax; + +import java.util.Properties; + +import javax.xml.transform.Result; +import javax.xml.transform.URIResolver; +import javax.xml.transform.TransformerException; +import javax.xml.transform.Transformer; + +import org.xml.sax.ContentHandler; +import org.xml.sax.ext.LexicalHandler; +import org.xml.sax.DTDHandler; + + +/** + * A TransformerHandler + * listens for SAX ContentHandler parse events and transforms + * them to a Result. + */ +public interface TransformerHandler + extends ContentHandler, LexicalHandler, DTDHandler { + + /** + * Enables the user of the TransformerHandler to set the + * to set the Result for the transformation. + * + * @param result A Result instance, should not be null. + * + * @throws IllegalArgumentException if result is invalid for some reason. + */ + public void setResult(Result result) throws IllegalArgumentException; + + /** + * Set the base ID (URI or system ID) from where relative + * URLs will be resolved. + * @param systemID Base URI for the source tree. + */ + public void setSystemId(String systemID); + + /** + * Get the base ID (URI or system ID) from where relative + * URLs will be resolved. + * @return The systemID that was set with {@link #setSystemId}. + */ + public String getSystemId(); + + /** + * Get the Transformer associated with this handler, which + * is needed in order to set parameters and output properties. + */ + public Transformer getTransformer(); +} diff --git a/java/external/src/javax/xml/transform/sax/package.html b/java/external/src/javax/xml/transform/sax/package.html new file mode 100644 index 0000000..7a0d707 --- /dev/null +++ b/java/external/src/javax/xml/transform/sax/package.html @@ -0,0 +1,69 @@ + + + + +javax.xml.transform.sax + + +

This package implements SAX2-specific transformation APIs. It provides + classes which allow input from {@link org.xml.sax.ContentHandler} + events, and also classes that produce org.xml.sax.ContentHandler events. It + also provides methods to set the input source as an + {@link org.xml.sax.XMLReader}, or to use a + {@link org.xml.sax.InputSource} as the source. It also allows the + creation of a {@link org.xml.sax.XMLFilter}, which enables + transformations to "pull" from other transformations, and lets the transformer + to be used polymorphically as an {@link org.xml.sax.XMLReader}.

+

The {@link javax.xml.transform.sax.SAXSource} class allows the + setting of an {@link org.xml.sax.XMLReader} to be used for "pulling" + parse events, and an {@link org.xml.sax.InputSource} that may be used to + specify the SAX source.

+

The {@link javax.xml.transform.sax.SAXResult} class allows the + setting of a {@link org.xml.sax.ContentHandler} to be the receiver of + SAX2 events from the transformation. +

The {@link javax.xml.transform.sax.SAXTransformerFactory} extends + {@link javax.xml.transform.TransformerFactory} to provide factory + methods for creating {@link javax.xml.transform.sax.TemplatesHandler}, + {@link javax.xml.transform.sax.TransformerHandler}, and + {@link org.xml.sax.XMLReader} instances.

+

To obtain a {@link javax.xml.transform.sax.SAXTransformerFactory}, + the caller must cast the {@link javax.xml.transform.TransformerFactory} + instance returned from + {@link javax.xml.transform.TransformerFactory#newInstance}. + +

The {@link javax.xml.transform.sax.TransformerHandler} interface + allows a transformation to be created from SAX2 parse events, which is a "push" + model rather than the "pull" model that normally occurs for a transformation. + Normal parse events are received through the + {@link org.xml.sax.ContentHandler} interface, lexical events such as + startCDATA and endCDATA are received through the + {@link org.xml.sax.ext.LexicalHandler} interface, and events that signal + the start or end of disabling output escaping are received via + {@link org.xml.sax.ContentHandler#processingInstruction}, with the + target parameter being + {@link javax.xml.transform.Result#PI_DISABLE_OUTPUT_ESCAPING} and + {@link javax.xml.transform.Result#PI_ENABLE_OUTPUT_ESCAPING}. If + parameters, output properties, or other features need to be set on the + Transformer handler, a {@link javax.xml.transform.Transformer} reference + will need to be obtained from + {@link javax.xml.transform.sax.TransformerHandler#getTransformer}, and + the methods invoked from that reference. + +

The {@link javax.xml.transform.sax.TemplatesHandler} interface + allows the creation of {@link javax.xml.transform.Templates} objects + from SAX2 parse events. Once the {@link org.xml.sax.ContentHandler} + events are complete, the Templates object may be obtained from + {@link javax.xml.transform.sax.TemplatesHandler#getTemplates}. Note that + {@link javax.xml.transform.sax.TemplatesHandler#setSystemId} should + normally be called in order to establish a base system ID from which relative + URLs may be resolved. +

The + {@link javax.xml.transform.sax.SAXTransformerFactory#newXMLFilter} + method allows the creation of a {@link org.xml.sax.XMLFilter}, which + encapsulates the SAX2 notion of a "pull" transformation. The following + illustrates several transformations chained together. Each filter points to a + parent {@link org.xml.sax.XMLReader}, and the final transformation is + caused by invoking {@link org.xml.sax.XMLReader#parse} on the final + reader in the chain.

+ + diff --git a/java/external/src/javax/xml/transform/stream/StreamResult.java b/java/external/src/javax/xml/transform/stream/StreamResult.java new file mode 100644 index 0000000..d5ac708 --- /dev/null +++ b/java/external/src/javax/xml/transform/stream/StreamResult.java @@ -0,0 +1,189 @@ +/** + * $Id$ + * + * Copyright (c) 2000-2001 Sun Microsystems, Inc. All Rights Reserved. + * + * This software is the confidential and proprietary information of Sun + * Microsystems, Inc. ("Confidential Information"). You shall not + * disclose such Confidential Information and shall use it only in + * accordance with the terms of the license agreement you entered into + * with Sun. + * + * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE + * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE + * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR + * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES + * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING + * THIS SOFTWARE OR ITS DERIVATIVES. + */ +package javax.xml.transform.stream; + +import javax.xml.transform.*; + +import java.lang.String; + +import java.io.OutputStream; +import java.io.Writer; +import java.io.File; + + +/** + * Acts as an holder for a transformation result, + * which may be XML, plain Text, HTML, or some other form of markup. + * + */ +public class StreamResult implements Result { + + /** If {@link javax.xml.transform.TransformerFactory#getFeature} + * returns true when passed this value as an argument, + * the Transformer supports Result output of this type. + */ + public static final String FEATURE = + "http://javax.xml.transform.stream.StreamResult/feature"; + + /** + * Zero-argument default constructor. + */ + public StreamResult() {} + + /** + * Construct a StreamResult from a byte stream. Normally, + * a stream should be used rather than a reader, so that + * the transformer may use instructions contained in the + * transformation instructions to control the encoding. + * + * @param outputStream A valid OutputStream reference. + */ + public StreamResult(OutputStream outputStream) { + setOutputStream(outputStream); + } + + /** + * Construct a StreamResult from a character stream. Normally, + * a stream should be used rather than a reader, so that + * the transformer may use instructions contained in the + * transformation instructions to control the encoding. However, + * there are times when it is useful to write to a character + * stream, such as when using a StringWriter. + * + * @param writer A valid Writer reference. + */ + public StreamResult(Writer writer) { + setWriter(writer); + } + + /** + * Construct a StreamResult from a URL. + * + * @param systemId Must be a String that conforms to the URI syntax. + */ + public StreamResult(String systemId) { + this.systemId = systemId; + } + + /** + * Construct a StreamResult from a File. + * + * @param f Must a non-null File reference. + */ + public StreamResult(File f) { + setSystemId(f); + } + + /** + * Set the ByteStream that is to be written to. Normally, + * a stream should be used rather than a reader, so that + * the transformer may use instructions contained in the + * transformation instructions to control the encoding. + * + * @param outputStream A valid OutputStream reference. + */ + public void setOutputStream(OutputStream outputStream) { + this.outputStream = outputStream; + } + + /** + * Get the byte stream that was set with setOutputStream. + * + * @return The byte stream that was set with setOutputStream, or null + * if setOutputStream or the ByteStream constructor was not called. + */ + public OutputStream getOutputStream() { + return outputStream; + } + + /** + * Set the writer that is to receive the result. Normally, + * a stream should be used rather than a writer, so that + * the transformer may use instructions contained in the + * transformation instructions to control the encoding. However, + * there are times when it is useful to write to a writer, + * such as when using a StringWriter. + * + * @param writer A valid Writer reference. + */ + public void setWriter(Writer writer) { + this.writer = writer; + } + + /** + * Get the character stream that was set with setWriter. + * + * @return The character stream that was set with setWriter, or null + * if setWriter or the Writer constructor was not called. + */ + public Writer getWriter() { + return writer; + } + + /** + * Set the systemID that may be used in association + * with the byte or character stream, or, if neither is set, use + * this value as a writeable URI (probably a file name). + * + * @param systemId The system identifier as a URI string. + */ + public void setSystemId(String systemId) { + this.systemId = systemId; + } + + /** + * Set the system ID from a File reference. + * + * @param f Must a non-null File reference. + */ + public void setSystemId(File f) { + this.systemId = "file:///" + f.getAbsolutePath(); + } + + /** + * Get the system identifier that was set with setSystemId. + * + * @return The system identifier that was set with setSystemId, or null + * if setSystemId was not called. + */ + public String getSystemId() { + return systemId; + } + + ////////////////////////////////////////////////////////////////////// + // Internal state. + ////////////////////////////////////////////////////////////////////// + + /** + * The systemID that may be used in association + * with the byte or character stream, or, if neither is set, use + * this value as a writeable URI (probably a file name). + */ + private String systemId; + + /** + * The byte stream that is to be written to. + */ + private OutputStream outputStream; + + /** + * The character stream that is to be written to. + */ + private Writer writer; +} diff --git a/java/external/src/javax/xml/transform/stream/StreamSource.java b/java/external/src/javax/xml/transform/stream/StreamSource.java new file mode 100644 index 0000000..573a69b --- /dev/null +++ b/java/external/src/javax/xml/transform/stream/StreamSource.java @@ -0,0 +1,262 @@ +/** + * $Id$ + * + * Copyright (c) 2000-2001 Sun Microsystems, Inc. All Rights Reserved. + * + * This software is the confidential and proprietary information of Sun + * Microsystems, Inc. ("Confidential Information"). You shall not + * disclose such Confidential Information and shall use it only in + * accordance with the terms of the license agreement you entered into + * with Sun. + * + * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE + * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE + * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR + * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES + * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING + * THIS SOFTWARE OR ITS DERIVATIVES. + */ +package javax.xml.transform.stream; + +import javax.xml.transform.Source; + +import java.io.InputStream; +import java.io.Reader; +import java.io.File; + + +/** + * Acts as an holder for a transformation Source in the form + * of a stream of XML markup. + * + */ +public class StreamSource implements Source { + + /** If {@link javax.xml.transform.TransformerFactory#getFeature} + * returns true when passed this value as an argument, + * the Transformer supports Source input of this type. + */ + public static final String FEATURE = + "http://javax.xml.transform.stream.StreamSource/feature"; + + /** + * Zero-argument default constructor. If this constructor + * is used, and no other method is called, the transformer + * will assume an empty input tree, with a default root node. + */ + public StreamSource() {} + + /** + * Construct a StreamSource from a byte stream. Normally, + * a stream should be used rather than a reader, so + * the XML parser can resolve character encoding specified + * by the XML declaration. + * + *

If this constructor is used to process a stylesheet, normally + * setSystemId should also be called, so that relative URI references + * can be resolved.

+ * + * @param inputStream A valid InputStream reference to an XML stream. + */ + public StreamSource(InputStream inputStream) { + setInputStream(inputStream); + } + + /** + * Construct a StreamSource from a byte stream. Normally, + * a stream should be used rather than a reader, so that + * the XML parser can resolve character encoding specified + * by the XML declaration. + * + *

This constructor allows the systemID to be set in addition + * to the input stream, which allows relative URIs + * to be processed.

+ * + * @param inputStream A valid InputStream reference to an XML stream. + * @param systemId Must be a String that conforms to the URI syntax. + */ + public StreamSource(InputStream inputStream, String systemId) { + setInputStream(inputStream); + setSystemId(systemId); + } + + /** + * Construct a StreamSource from a character reader. Normally, + * a stream should be used rather than a reader, so that + * the XML parser can resolve character encoding specified + * by the XML declaration. However, in many cases the encoding + * of the input stream is already resolved, as in the case of + * reading XML from a StringReader. + * + * @param reader A valid Reader reference to an XML character stream. + */ + public StreamSource(Reader reader) { + setReader(reader); + } + + /** + * Construct a StreamSource from a character reader. Normally, + * a stream should be used rather than a reader, so that + * the XML parser may resolve character encoding specified + * by the XML declaration. However, in many cases the encoding + * of the input stream is already resolved, as in the case of + * reading XML from a StringReader. + * + * @param reader A valid Reader reference to an XML character stream. + * @param systemId Must be a String that conforms to the URI syntax. + */ + public StreamSource(Reader reader, String systemId) { + setReader(reader); + setSystemId(systemId); + } + + /** + * Construct a StreamSource from a URL. + * + * @param systemId Must be a String that conforms to the URI syntax. + */ + public StreamSource(String systemId) { + this.systemId = systemId; + } + + /** + * Construct a StreamSource from a File. + * + * @param f Must a non-null File reference. + */ + public StreamSource(File f) { + this.systemId = "file:///" + f.getAbsolutePath(); + } + + /** + * Set the byte stream to be used as input. Normally, + * a stream should be used rather than a reader, so that + * the XML parser can resolve character encoding specified + * by the XML declaration. + * + *

If this Source object is used to process a stylesheet, normally + * setSystemId should also be called, so that relative URL references + * can be resolved.

+ * + * @param inputStream A valid InputStream reference to an XML stream. + */ + public void setInputStream(InputStream inputStream) { + this.inputStream = inputStream; + } + + /** + * Get the byte stream that was set with setByteStream. + * + * @return The byte stream that was set with setByteStream, or null + * if setByteStream or the ByteStream constructor was not called. + */ + public InputStream getInputStream() { + return inputStream; + } + + /** + * Set the input to be a character reader. Normally, + * a stream should be used rather than a reader, so that + * the XML parser can resolve character encoding specified + * by the XML declaration. However, in many cases the encoding + * of the input stream is already resolved, as in the case of + * reading XML from a StringReader. + * + * @param reader A valid Reader reference to an XML CharacterStream. + */ + public void setReader(Reader reader) { + this.reader = reader; + } + + /** + * Get the character stream that was set with setReader. + * + * @return The character stream that was set with setReader, or null + * if setReader or the Reader constructor was not called. + */ + public Reader getReader() { + return reader; + } + + /** + * Set the public identifier for this Source. + * + *

The public identifier is always optional: if the application + * writer includes one, it will be provided as part of the + * location information.

+ * + * @param publicId The public identifier as a string. + */ + public void setPublicId(String publicId) { + this.publicId = publicId; + } + + /** + * Get the public identifier that was set with setPublicId. + * + * @return The public identifier that was set with setPublicId, or null + * if setPublicId was not called. + */ + public String getPublicId() { + return publicId; + } + + /** + * Set the system identifier for this Source. + * + *

The system identifier is optional if there is a byte stream + * or a character stream, but it is still useful to provide one, + * since the application can use it to resolve relative URIs + * and can include it in error messages and warnings (the parser + * will attempt to open a connection to the URI only if + * there is no byte stream or character stream specified).

+ * + * @param systemId The system identifier as a URL string. + */ + public void setSystemId(String systemId) { + this.systemId = systemId; + } + + /** + * Get the system identifier that was set with setSystemId. + * + * @return The system identifier that was set with setSystemId, or null + * if setSystemId was not called. + */ + public String getSystemId() { + return systemId; + } + + /** + * Set the system ID from a File reference. + * + * @param f Must a non-null File reference. + */ + public void setSystemId(File f) { + this.systemId = "file:///" + f.toString(); + } + + ////////////////////////////////////////////////////////////////////// + // Internal state. + ////////////////////////////////////////////////////////////////////// + + /** + * The public identifier for this input source, or null. + */ + private String publicId; + + /** + * The system identifier as a URL string, or null. + */ + private String systemId; + + /** + * The byte stream for this Source, or null. + */ + private InputStream inputStream; + + /** + * The character stream for this Source, or null. + */ + private Reader reader; +} diff --git a/java/external/src/javax/xml/transform/stream/package.html b/java/external/src/javax/xml/transform/stream/package.html new file mode 100644 index 0000000..df54abd --- /dev/null +++ b/java/external/src/javax/xml/transform/stream/package.html @@ -0,0 +1,30 @@ + + + + +javax.xml.transform.stream + + +

This package implements stream- and URI- specific transformation APIs. +

+

The {@link javax.xml.transform.stream.StreamSource} class + provides methods for specifying {@link java.io.InputStream} input, + {@link java.io.Reader} input, and URL input in the form of strings. Even + if an input stream or reader is specified as the source, + {@link javax.xml.transform.stream.StreamSource#setSystemId} should still + be called, so that the transformer can know from where it should resolve + relative URIs. The public identifier is always optional: if the application + writer includes one, it will be provided as part of the + {@link javax.xml.transform.SourceLocator} information.

+

The {@link javax.xml.transform.stream.StreamResult} class + provides methods for specifying {@link java.io.OutputStream}, + {@link java.io.Writer}, or an output system ID, as the output of the + transformation result.

+

Normally streams should be used rather than readers or writers, for + both the Source and Result, since readers and writers already have the encoding + established to and from the internal Unicode format. However, there are times + when it is useful to write to a character stream, such as when using a + StringWriter in order to write to a String, or in the case of reading source + XML from a StringReader.

+ +