8054834: Modular Source Code

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

View file

@ -0,0 +1,119 @@
/*
* Copyright (c) 2000, 2005, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.xml.transform;
/**
* <p>To provide customized error handling, implement this interface and
* use the <code>setErrorListener</code> method to register an instance of the
* implementation with the {@link javax.xml.transform.Transformer}. The
* <code>Transformer</code> then reports all errors and warnings through this
* interface.</p>
*
* <p>If an application does <em>not</em> register its own custom
* <code>ErrorListener</code>, the default <code>ErrorListener</code>
* is used which reports all warnings and errors to <code>System.err</code>
* and does not throw any <code>Exception</code>s.
* Applications are <em>strongly</em> encouraged to register and use
* <code>ErrorListener</code>s that insure proper behavior for warnings and
* errors.</p>
*
* <p>For transformation errors, a <code>Transformer</code> must use this
* interface instead of throwing an <code>Exception</code>: it is up to the
* application to decide whether to throw an <code>Exception</code> for
* different types of errors and warnings. Note however that the
* <code>Transformer</code> is not required to continue with the transformation
* after a call to {@link #fatalError(TransformerException exception)}.</p>
*
* <p><code>Transformer</code>s may use this mechanism to report XML parsing
* errors as well as transformation errors.</p>
*
* @since 1.4
*/
public interface ErrorListener {
/**
* Receive notification of a warning.
*
* <p>{@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.</p>
*
* <p>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.</p>
*
* @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.
*
* <p>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.</p>
*
* @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;
/**
* <p>Receive notification of a non-recoverable error.</p>
*
* <p>The processor may choose to continue, but will not normally
* proceed to a successful completion.</p>
*
* <p>The method should throw an exception if it is unable to
* process the error, or if it wishes execution to terminate
* immediately. The processor will not necessarily honor this
* request.</p>
*
* @param exception The error information encapsulated in a
* <code>TransformerException</code>.
*
* @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;
}

View file

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

View file

@ -0,0 +1,201 @@
/*
* Copyright (c) 2000, 2005, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.xml.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.
* <p>All the fields in this class are read-only.</p>
*
* @see <a href="http://www.w3.org/TR/xslt#output">
* section 16 of the XSL Transformations (XSLT) W3C Recommendation</a>
* @since 1.4
*/
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" | <var>expanded name</var>.
*
* <p>The value of the method property 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}.</p>
*
* @see <a href="http://www.w3.org/TR/xslt#output">
* section 16 of the XSL Transformations (XSLT) W3C Recommendation</a>
*/
public static final String METHOD = "method";
/**
* version = <var>nmtoken</var>.
*
* <p><code>version</code> specifies the version of the output
* method.</p>
* <p>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.</p>
* @see <a href="http://www.w3.org/TR/xslt#output">
* section 16 of the XSL Transformations (XSLT) W3C Recommendation</a>
*/
public static final String VERSION = "version";
/**
* encoding = <var>string</var>.
*
* <p><code>encoding</code> specifies the preferred character
* encoding that the Transformer should use to encode sequences of
* characters as sequences of bytes. The value of the encoding property 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 <code>charset</code> registered with the Internet
* Assigned Numbers Authority <a href="http://www.iana.org/">[IANA]</a>,
* <a href="http://www.ietf.org/rfc/rfc2278.txt">[RFC2278]</a>
* or start with <code>X-</code>.</p>
* @see <a href="http://www.w3.org/TR/xslt#output">
* section 16 of the XSL Transformations (XSLT) W3C Recommendation</a>
*/
public static final String ENCODING = "encoding";
/**
* omit-xml-declaration = "yes" | "no".
*
* <p><code>omit-xml-declaration</code> specifies whether the XSLT
* processor should output an XML declaration; the value must be
* <code>yes</code> or <code>no</code>.</p>
* @see <a href="http://www.w3.org/TR/xslt#output">
* section 16 of the XSL Transformations (XSLT) W3C Recommendation</a>
*/
public static final String OMIT_XML_DECLARATION = "omit-xml-declaration";
/**
* standalone = "yes" | "no".
*
* <p><code>standalone</code> specifies whether the Transformer
* should output a standalone document declaration; the value must be
* <code>yes</code> or <code>no</code>.</p>
* @see <a href="http://www.w3.org/TR/xslt#output">
* section 16 of the XSL Transformations (XSLT) W3C Recommendation</a>
*/
public static final String STANDALONE = "standalone";
/**
* doctype-public = <var>string</var>.
* <p>See the documentation for the {@link #DOCTYPE_SYSTEM} property
* for a description of what the value of the key should be.</p>
*
* @see <a href="http://www.w3.org/TR/xslt#output">
* section 16 of the XSL Transformations (XSLT) W3C Recommendation</a>
*/
public static final String DOCTYPE_PUBLIC = "doctype-public";
/**
* doctype-system = <var>string</var>.
* <p><code>doctype-system</code> specifies the system identifier
* to be used in the document type declaration.</p>
* <p>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 &lt;!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 value of the doctype-public property should be ignored unless the doctype-system
* property is specified.</p>
* <p>If the doctype-public or doctype-system properties are specified,
* then the html output method should output a document type declaration
* immediately before the first element. The name following &lt;!DOCTYPE
* should be HTML or html. If the doctype-public property is specified,
* then the output method should output PUBLIC followed by the specified
* public identifier; if the doctype-system property is also specified,
* it should also output the specified system identifier following the
* public identifier. If the doctype-system property is specified but
* the doctype-public property is not specified, then the output method
* should output SYSTEM followed by the specified system identifier.</p>
*
* <p><code>doctype-system</code> specifies the system identifier
* to be used in the document type declaration.</p>
* @see <a href="http://www.w3.org/TR/xslt#output">
* section 16 of the XSL Transformations (XSLT) W3C Recommendation</a>
*/
public static final String DOCTYPE_SYSTEM = "doctype-system";
/**
* cdata-section-elements = <var>expanded names</var>.
*
* <p><code>cdata-section-elements</code> specifies a whitespace delimited
* list of the names of elements whose text node children should be output
* using CDATA sections. Note that these names must use the format
* described in the section Qualfied Name Representation in
* {@link javax.xml.transform}.</p>
*
* @see <a href="http://www.w3.org/TR/xslt#output">
* section 16 of the XSL Transformations (XSLT) W3C Recommendation.</a>
*/
public static final String CDATA_SECTION_ELEMENTS =
"cdata-section-elements";
/**
* indent = "yes" | "no".
*
* <p><code>indent</code> specifies whether the Transformer may
* add additional whitespace when outputting the result tree; the value
* must be <code>yes</code> or <code>no</code>. </p>
* @see <a href="http://www.w3.org/TR/xslt#output">
* section 16 of the XSL Transformations (XSLT) W3C Recommendation</a>
*/
public static final String INDENT = "indent";
/**
* media-type = <var>string</var>.
*
* <p><code>media-type</code> specifies the media type (MIME
* content type) of the data that results from outputting the result
* tree. The <code>charset</code> parameter should not be specified
* explicitly; instead, when the top-level media type is
* <code>text</code>, a <code>charset</code> parameter should be added
* according to the character encoding actually used by the output
* method. </p>
* @see <a href="http://www.w3.org/TR/xslt#output">s
* ection 16 of the XSL Transformations (XSLT) W3C Recommendation</a>
*/
public static final String MEDIA_TYPE = "media-type";
}

View file

@ -0,0 +1,87 @@
/*
* Copyright (c) 2000, 2005, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.xml.transform;
/**
* <p>An object that implements this interface contains the information
* needed to build a transformation result tree.</p>
*
* @author <a href="Jeff.Suttor@Sun.com">Jeff Suttor</a>
* @since 1.4
*/
public interface Result {
/**
* The name of the processing instruction that is sent if the
* result tree disables output escaping.
*
* <p>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. </p>
*
* <p>Result DOM trees may also have PI_DISABLE_OUTPUT_ESCAPING and
* PI_ENABLE_OUTPUT_ESCAPING inserted into the tree.</p>
*
* @see <a href="http://www.w3.org/TR/xslt#disable-output-escaping">disable-output-escaping in XSLT Specification</a>
*/
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 <a href="http://www.w3.org/TR/xslt#disable-output-escaping">disable-output-escaping in XSLT Specification</a>
*/
public static final String PI_ENABLE_OUTPUT_ESCAPING =
"javax.xml.transform.enable-output-escaping";
/**
* Set the system identifier for this Result.
*
* <p>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.</p>
*
* @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();
}

View file

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

View file

@ -0,0 +1,55 @@
/*
* Copyright (c) 2000, 2005, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.xml.transform;
/**
* An object that implements this interface contains the information
* needed to act as source input (XML source or transformation instructions).
*
* @since 1.4
*/
public interface Source {
/**
* Set the system identifier for this Source.
*
* <p>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.</p>
*
* @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();
}

View file

@ -0,0 +1,98 @@
/*
* Copyright (c) 2000, 2005, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.xml.transform;
/**
* This interface is primarily for the purposes of reporting where
* an error occurred in the XML source or transformation instructions.
*
* @since 1.4
*/
public interface SourceLocator {
/**
* Return the public identifier for the current document event.
*
* <p>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.</p>
*
* @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.
*
* <p>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.</p>
*
* <p>If the system identifier is a URL, the parser must resolve it
* fully before passing it to the application.</p>
*
* @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.
*
* <p><strong>Warning:</strong> 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.</p>
*
* <p>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.</p>
*
* @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.
*
* <p><strong>Warning:</strong> 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.</p>
*
* <p>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.</p>
*
* @return The column number, or -1 if none is available.
* @see #getLineNumber
*/
public int getColumnNumber();
}

View file

@ -0,0 +1,84 @@
/*
* Copyright (c) 2000, 2005, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.xml.transform;
import java.util.Properties;
/**
* An object that implements this interface is the runtime representation of processed
* transformation instructions.
*
* <p>Templates must be threadsafe for a given instance
* over multiple threads running concurrently, and may
* be used multiple times in a given session.</p>
*
* @since 1.4
*/
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 properties corresponding to the effective xsl:output element.
* 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}.
*
* <p>The properties returned should contain properties set by the stylesheet,
* and these properties are "defaulted" by default properties specified by
* <a href="http://www.w3.org/TR/xslt#output">section 16 of the
* XSL Transformations (XSLT) W3C Recommendation</a>. 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, <em>or</em> the default
* properties, while
* getOutputProperties().get(String key) will only retrieve properties
* that were explicitly set in the stylesheet.</p>
*
* <p>For XSLT,
* <a href="http://www.w3.org/TR/xslt#attribute-value-templates">Attribute
* Value Templates</a> 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.</p>
*
* @return A Properties object, never null.
*/
Properties getOutputProperties();
}

View file

@ -0,0 +1,340 @@
/*
* Copyright (c) 2000, 2005, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.xml.transform;
import java.util.Properties;
/**
* An instance of this abstract class can transform a
* source tree into a result tree.
*
* <p>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.</p>
*
* <p>An object of this class may not be used in multiple threads
* running concurrently. Different Transformers may be used
* concurrently by different threads.</p>
*
* <p>A <code>Transformer</code> may be used multiple times. Parameters and
* output properties are preserved across transformations.</p>
*
* @author <a href="Jeff.Suttor@Sun.com">Jeff Suttor</a>
* @since 1.4
*/
public abstract class Transformer {
/**
* Default constructor is protected on purpose.
*/
protected Transformer() { }
/**
* <p>Reset this <code>Transformer</code> to its original configuration.</p>
*
* <p><code>Transformer</code> is reset to the same state as when it was created with
* {@link TransformerFactory#newTransformer()},
* {@link TransformerFactory#newTransformer(Source source)} or
* {@link Templates#newTransformer()}.
* <code>reset()</code> is designed to allow the reuse of existing <code>Transformer</code>s
* thus saving resources associated with the creation of new <code>Transformer</code>s.</p>
*
* <p>The reset <code>Transformer</code> is not guaranteed to have the same {@link URIResolver}
* or {@link ErrorListener} <code>Object</code>s, e.g. {@link Object#equals(Object obj)}.
* It is guaranteed to have a functionally equal <code>URIResolver</code>
* and <code>ErrorListener</code>.</p>
*
* @throws UnsupportedOperationException When implementation does not
* override this method.
*
* @since 1.5
*/
public void reset() {
// implementors should override this method
throw new UnsupportedOperationException(
"This Transformer, \"" + this.getClass().getName() + "\", does not support the reset functionality."
+ " Specification \"" + this.getClass().getPackage().getSpecificationTitle() + "\""
+ " version \"" + this.getClass().getPackage().getSpecificationVersion() + "\""
);
}
/**
* <p>Transform the XML <code>Source</code> to a <code>Result</code>.
* Specific transformation behavior is determined by the settings of the
* <code>TransformerFactory</code> in effect when the
* <code>Transformer</code> was instantiated and any modifications made to
* the <code>Transformer</code> instance.</p>
*
* <p>An empty <code>Source</code> is represented as an empty document
* as constructed by {@link javax.xml.parsers.DocumentBuilder#newDocument()}.
* The result of transforming an empty <code>Source</code> depends on
* the transformation behavior; it is not always an empty
* <code>Result</code>.</p>
*
* @param xmlSource The XML input to transform.
* @param outputTarget The <code>Result</code> of transforming the
* <code>xmlSource</code>.
*
* @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.
*
* <p>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.</p>
* <p>For example, if a URI and local name were obtained from an element
* defined with &lt;xyz:foo
* xmlns:xyz="http://xyz.foo.com/yada/baz.html"/&gt;,
* then the qualified name would be "{http://xyz.foo.com/yada/baz.html}foo".
* Note that no prefix is used.</p>
*
* @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.
*
* @throws NullPointerException If value is null.
*/
public abstract void setParameter(String name, Object value);
/**
* Get a parameter that was explicitly set with setParameter.
*
* <p>This method does not return a default parameter value, which
* cannot be determined until the node context is evaluated during
* the transformation process.
*
* @param name of <code>Object</code> to get
*
* @return A parameter that has been set with setParameter.
*/
public abstract Object getParameter(String name);
/**
* <p>Set a list of parameters.</p>
*
* <p>Note that the list of parameters is specified as a
* <code>Properties</code> <code>Object</code> which limits the parameter
* values to <code>String</code>s. Multiple calls to
* {@link #setParameter(String name, Object value)} should be used when the
* desired values are non-<code>String</code> <code>Object</code>s.
* The parameter names should conform as specified in
* {@link #setParameter(String name, Object value)}.
* An <code>IllegalArgumentException</code> is thrown if any names do not
* conform.</p>
*
* <p>New parameters in the list are added to any existing parameters.
* If the name of a new parameter is equal to the name of an existing
* parameter as determined by {@link java.lang.Object#equals(Object obj)},
* the existing parameter is set to the new value.</p>
*
* @param params Parameters to set.
*
* @throws IllegalArgumentException If any parameter names do not conform
* to the naming rules.
*/
/**
* Clear all parameters set with setParameter.
*/
public abstract void clearParameters();
/**
* Set an object that will be used to resolve URIs used in
* document().
*
* <p>If the resolver argument is null, the URIResolver value will
* be cleared and the transformer will no longer have a resolver.</p>
*
* @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().
*
* @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.
*
* <p>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.</p>
*
* <p>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.</p>
* <p>For example, if a URI and local name were obtained from an element
* defined with &lt;xyz:foo
* xmlns:xyz="http://xyz.foo.com/yada/baz.html"/&gt;,
* then the qualified name would be "{http://xyz.foo.com/yada/baz.html}foo".
* Note that no prefix is used.</p>
* An <code>IllegalArgumentException</code> is thrown if any of the
* argument keys are not recognized and are not namespace qualified.
*
* @param oformat A set of output properties that will be
* used to override any of the same properties in affect
* for the transformation.
*
* @throws IllegalArgumentException When keys are not recognized and
* are not namespace qualified.
*
* @see javax.xml.transform.OutputKeys
* @see java.util.Properties
*
*/
public abstract void setOutputProperties(Properties oformat);
/**
* <p>Get a copy of the output properties for the transformation.</p>
*
* <p>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
* <a href="http://www.w3.org/TR/xslt#output">section 16 of the
* XSL Transformations (XSLT) W3C Recommendation</a>. 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, <em>or</em> 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.</p>
*
* <p>Note that mutation of the Properties object returned will not
* effect the properties that the transformer contains.</p>
*
* <p>If any of the argument keys are not recognized and are not
* namespace qualified, the property will be ignored and not returned.
* In other words the behaviour is not orthogonal with
* {@link #setOutputProperties setOutputProperties}.</p>
*
* @return A copy of the set of output properties in effect for
* the next transformation.
*
* @see javax.xml.transform.OutputKeys
* @see java.util.Properties
* @see <a href="http://www.w3.org/TR/xslt#output">
* XSL Transformations (XSLT) Version 1.0</a>
*/
public abstract Properties getOutputProperties();
/**
* Set an output property that will be in effect for the
* transformation.
*
* <p>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.</p>
* <p>For example, if a URI and local name were obtained from an element
* defined with &lt;xyz:foo
* xmlns:xyz="http://xyz.foo.com/yada/baz.html"/&gt;,
* then the qualified name would be "{http://xyz.foo.com/yada/baz.html}foo".
* Note that no prefix is used.</p>
*
* <p>The Properties object that was passed to {@link #setOutputProperties}
* won't be effected by calling this method.</p>
*
* @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;
/**
* <p>Get an output property that is in effect for the transformer.</p>
*
* <p>If a property has been set using {@link #setOutputProperty},
* that value will be returned. Otherwise, if a property is explicitly
* specified in the stylesheet, that value will be returned. If
* the value of the property has been defaulted, that is, if no
* value has been set explicitly either with {@link #setOutputProperty} or
* in the stylesheet, the result may vary depending on
* implementation and input stylesheet.</p>
*
* @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.
* Implementations must provide a default error listener.
*
* @return The current error handler, which should never be null.
*/
public abstract ErrorListener getErrorListener();
}

View file

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

View file

@ -0,0 +1,372 @@
/*
* Copyright (c) 2000, 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.xml.transform;
import java.lang.reflect.Method;
import java.lang.reflect.InvocationTargetException;
/**
* This class specifies an exceptional condition that occured
* during the transformation process.
*
* @since 1.4
*/
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 <code>null</code> 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 <i>cause</i> of this throwable to the specified value.
* (The cause is the throwable that caused this throwable to get thrown.)
*
* <p>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 <code>null</code> value is
* permitted, and indicates that the cause is nonexistent or
* unknown.)
* @return a reference to this <code>Throwable</code> instance.
* @throws IllegalArgumentException if <code>cause</code> 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.
*
* <p>This is used for throwing processor exceptions before
* the processing has started.</p>
*
* @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.
*
* <p>This constructor is especially useful when an application is
* creating its own exception from within a DocumentHandler
* callback.</p>
*
* @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 <code>String</code> 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",
(Class[]) null);
if (null != meth) {
Throwable prev = exception;
exception = (Throwable) meth.invoke(exception, (Object[]) null);
if (prev == exception) {
break;
}
} else {
exception = null;
}
} catch (InvocationTargetException ite) {
exception = null;
} catch (IllegalAccessException iae) {
exception = null;
} catch (NoSuchMethodException nsme) {
exception = null;
}
}
// insure output is written
s.flush();
}
}

View file

@ -0,0 +1,419 @@
/*
* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.xml.transform;
/**
* <p>A TransformerFactory instance can be used to create
* {@link javax.xml.transform.Transformer} and
* {@link javax.xml.transform.Templates} objects.</p>
*
* <p>The system property that determines which Factory implementation
* to create is named <code>"javax.xml.transform.TransformerFactory"</code>.
* This property names a concrete subclass of the
* <code>TransformerFactory</code> abstract class. If the property is not
* defined, a platform default is be used.</p>
*
* @author <a href="mailto:Jeff.Suttor@Sun.com">Jeff Suttor</a>
* @author <a href="mailto:Neeraj.Bajaj@sun.com">Neeraj Bajaj</a>
*
* @since 1.5
*/
public abstract class TransformerFactory {
/**
* Default constructor is protected on purpose.
*/
protected TransformerFactory() { }
/**
* <p>Obtain a new instance of a <code>TransformerFactory</code>.
* This static method creates a new factory instance.</p>
* <p>This method uses the following ordered lookup procedure to determine
* the <code>TransformerFactory</code> implementation class to
* load:</p>
* <ul>
* <li>
* Use the <code>javax.xml.transform.TransformerFactory</code> system
* property.
* </li>
* <li>
* Use the properties file "lib/jaxp.properties" in the JRE directory.
* This configuration file is in standard <code>java.util.Properties
* </code> format and contains the fully qualified name of the
* implementation class with the key being the system property defined
* above.
* <br>
* The jaxp.properties file is read only once by the JAXP implementation
* and it's values are then cached for future use. If the file does not exist
* when the first attempt is made to read from it, no further attempts are
* made to check for its existence. It is not possible to change the value
* of any property in jaxp.properties after it has been read for the first time.
* </li>
* <li>
* Use the service-provider loading facilities, defined by the
* {@link java.util.ServiceLoader} class, to attempt to locate and load an
* implementation of the service using the {@linkplain
* java.util.ServiceLoader#load(java.lang.Class) default loading mechanism}:
* the service-provider loading facility will use the {@linkplain
* java.lang.Thread#getContextClassLoader() current thread's context class loader}
* to attempt to load the service. If the context class
* loader is null, the {@linkplain
* ClassLoader#getSystemClassLoader() system class loader} will be used.
* </li>
* <li>
* Otherwise, the system-default implementation is returned.
* </li>
* </ul>
*
* <p>Once an application has obtained a reference to a <code>
* TransformerFactory</code> it can use the factory to configure
* and obtain transformer instances.</p>
*
* @return new TransformerFactory instance, never null.
*
* @throws TransformerFactoryConfigurationError Thrown in case of {@linkplain
* java.util.ServiceConfigurationError service configuration error} or if
* the implementation is not available or cannot be instantiated.
*/
public static TransformerFactory newInstance()
throws TransformerFactoryConfigurationError {
return FactoryFinder.find(
/* The default property name according to the JAXP spec */
TransformerFactory.class,
/* The fallback implementation class name, XSLTC */
"com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl");
}
/**
* <p>Obtain a new instance of a <code>TransformerFactory</code> from factory class name.
* This function is useful when there are multiple providers in the classpath.
* It gives more control to the application as it can specify which provider
* should be loaded.</p>
*
* <p>Once an application has obtained a reference to a <code>
* TransformerFactory</code> it can use the factory to configure
* and obtain transformer instances.</p>
*
* <h2>Tip for Trouble-shooting</h2>
* <p>Setting the <code>jaxp.debug</code> system property will cause
* this method to print a lot of debug messages
* to <code>System.err</code> about what it is doing and where it is looking at.</p>
*
* <p> If you have problems try:</p>
* <pre>
* java -Djaxp.debug=1 YourProgram ....
* </pre>
*
* @param factoryClassName fully qualified factory class name that provides implementation of <code>javax.xml.transform.TransformerFactory</code>.
*
* @param classLoader <code>ClassLoader</code> used to load the factory class. If <code>null</code>
* current <code>Thread</code>'s context classLoader is used to load the factory class.
*
* @return new TransformerFactory instance, never null.
*
* @throws TransformerFactoryConfigurationError
* if <code>factoryClassName</code> is <code>null</code>, or
* the factory class cannot be loaded, instantiated.
*
* @see #newInstance()
*
* @since 1.6
*/
public static TransformerFactory newInstance(String factoryClassName, ClassLoader classLoader)
throws TransformerFactoryConfigurationError{
//do not fallback if given classloader can't find the class, throw exception
return FactoryFinder.newInstance(TransformerFactory.class,
factoryClassName, classLoader, false, false);
}
/**
* <p>Process the <code>Source</code> into a <code>Transformer</code>
* <code>Object</code>. The <code>Source</code> is an XSLT document that
* conforms to <a href="http://www.w3.org/TR/xslt">
* XSL Transformations (XSLT) Version 1.0</a>. Care must
* be taken not to use this <code>Transformer</code> in multiple
* <code>Thread</code>s running concurrently.
* Different <code>TransformerFactories</code> can be used concurrently by
* different <code>Thread</code>s.</p>
*
* @param source <code>Source </code> of XSLT document used to create
* <code>Transformer</code>.
* Examples of XML <code>Source</code>s include
* {@link javax.xml.transform.dom.DOMSource DOMSource},
* {@link javax.xml.transform.sax.SAXSource SAXSource}, and
* {@link javax.xml.transform.stream.StreamSource StreamSource}.
*
* @return A <code>Transformer</code> object that may be used to perform
* a transformation in a single <code>Thread</code>, never
* <code>null</code>.
*
* @throws TransformerConfigurationException Thrown if there are errors when
* parsing the <code>Source</code> or it is not possible to create a
* <code>Transformer</code> instance.
*
* @see <a href="http://www.w3.org/TR/xslt">
* XSL Transformations (XSLT) Version 1.0</a>
*/
public abstract Transformer newTransformer(Source source)
throws TransformerConfigurationException;
/**
* <p>Create a new <code>Transformer</code> that performs a copy
* of the <code>Source</code> to the <code>Result</code>.
* i.e. the "<em>identity transform</em>".</p>
*
* @return A Transformer object that may be used to perform a transformation
* in a single thread, never null.
*
* @throws TransformerConfigurationException When it is not
* possible to create a <code>Transformer</code> instance.
*/
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 <code>null</code>.
*
* @throws TransformerConfigurationException When parsing to
* construct the Templates object fails.
*/
public abstract Templates newTemplates(Source source)
throws TransformerConfigurationException;
/**
* <p>Get the stylesheet specification(s) associated with the
* XML <code>Source</code> document via the
* <a href="http://www.w3.org/TR/xml-stylesheet/">
* xml-stylesheet processing instruction</a> 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.</p>
*
* @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 <code>Source</code> <code>Object</code> suitable for passing
* to the <code>TransformerFactory</code>.
*
* @throws TransformerConfigurationException An <code>Exception</code>
* is thrown if an error occurings during parsing of the
* <code>source</code>.
*
* @see <a href="http://www.w3.org/TR/xml-stylesheet/">
* Associating Style Sheets with XML documents Version 1.0</a>
*/
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 document(), 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 =======
/**
* <p>Set a feature for this <code>TransformerFactory</code> and <code>Transformer</code>s
* or <code>Template</code>s created by this factory.</p>
*
* <p>
* Feature names are fully qualified {@link java.net.URI}s.
* Implementations may define their own features.
* An {@link TransformerConfigurationException} is thrown if this <code>TransformerFactory</code> or the
* <code>Transformer</code>s or <code>Template</code>s it creates cannot support the feature.
* It is possible for an <code>TransformerFactory</code> to expose a feature value but be unable to change its state.
* </p>
*
* <p>All implementations are required to support the {@link javax.xml.XMLConstants#FEATURE_SECURE_PROCESSING} feature.
* When the feature is:</p>
* <ul>
* <li>
* <code>true</code>: the implementation will limit XML processing to conform to implementation limits
* and behave in a secure fashion as defined by the implementation.
* Examples include resolving user defined style sheets and functions.
* If XML processing is limited for security reasons, it will be reported via a call to the registered
* {@link ErrorListener#fatalError(TransformerException exception)}.
* See {@link #setErrorListener(ErrorListener listener)}.
* </li>
* <li>
* <code>false</code>: the implementation will processing XML according to the XML specifications without
* regard to possible implementation limits.
* </li>
* </ul>
*
* @param name Feature name.
* @param value Is feature state <code>true</code> or <code>false</code>.
*
* @throws TransformerConfigurationException if this <code>TransformerFactory</code>
* or the <code>Transformer</code>s or <code>Template</code>s it creates cannot support this feature.
* @throws NullPointerException If the <code>name</code> parameter is null.
*/
public abstract void setFeature(String name, boolean value)
throws TransformerConfigurationException;
/**
* Look up the value of a feature.
*
* <p>
* Feature names are fully qualified {@link java.net.URI}s.
* Implementations may define their own features.
* <code>false</code> is returned if this <code>TransformerFactory</code> or the
* <code>Transformer</code>s or <code>Template</code>s it creates cannot support the feature.
* It is possible for an <code>TransformerFactory</code> to expose a feature value but be unable to change its state.
* </p>
*
* @param name Feature name.
*
* @return The current state of the feature, <code>true</code> or <code>false</code>.
*
* @throws NullPointerException If the <code>name</code> parameter is null.
*/
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.
* An <code>IllegalArgumentException</code> is thrown if the underlying
* implementation doesn't recognize the attribute.
* <p>
* All implementations that implement JAXP 1.5 or newer are required to
* support the {@link javax.xml.XMLConstants#ACCESS_EXTERNAL_DTD} and
* {@link javax.xml.XMLConstants#ACCESS_EXTERNAL_STYLESHEET} properties.
* </p>
* <ul>
* <li>
* <p>
* Access to external DTDs in the source file is restricted to the protocols
* specified by the {@link javax.xml.XMLConstants#ACCESS_EXTERNAL_DTD} property.
* If access is denied during transformation due to the restriction of this property,
* {@link javax.xml.transform.TransformerException} will be thrown by
* {@link javax.xml.transform.Transformer#transform(Source, Result)}.
* </p>
* <p>
* Access to external DTDs in the stylesheet is restricted to the protocols
* specified by the {@link javax.xml.XMLConstants#ACCESS_EXTERNAL_DTD} property.
* If access is denied during the creation of a new transformer due to the
* restriction of this property,
* {@link javax.xml.transform.TransformerConfigurationException} will be thrown
* by the {@link #newTransformer(Source)} method.
* </p>
* <p>
* Access to external reference set by the stylesheet processing instruction,
* Import and Include element is restricted to the protocols specified by the
* {@link javax.xml.XMLConstants#ACCESS_EXTERNAL_STYLESHEET} property.
* If access is denied during the creation of a new transformer due to the
* restriction of this property,
* {@link javax.xml.transform.TransformerConfigurationException} will be thrown
* by the {@link #newTransformer(Source)} method.
* </p>
* <p>
* Access to external document through XSLT document function is restricted
* to the protocols specified by the property. If access is denied during
* the transformation due to the restriction of this property,
* {@link javax.xml.transform.TransformerException} will be thrown by the
* {@link javax.xml.transform.Transformer#transform(Source, Result)} method.
* </p>
* </li>
* </ul>
*
* @param name The name of the attribute.
* @param value The value of the attribute.
*
* @throws IllegalArgumentException When implementation does not
* recognize the attribute.
*/
public abstract void setAttribute(String name, Object value);
/**
* Allows the user to retrieve specific attributes on the underlying
* implementation.
* An <code>IllegalArgumentException</code> is thrown if the underlying
* implementation doesn't recognize the attribute.
*
* @param name The name of the attribute.
*
* @return value The value of the attribute.
*
* @throws IllegalArgumentException When implementation does not
* recognize the attribute.
*/
public abstract Object getAttribute(String name);
/**
* Set the error event listener for the TransformerFactory, which
* is used for the processing of transformation instructions,
* and not for the transformation itself.
* An <code>IllegalArgumentException</code> is thrown if the
* <code>ErrorListener</code> listener is <code>null</code>.
*
* @param listener The new error listener.
*
* @throws IllegalArgumentException When <code>listener</code> is
* <code>null</code>
*/
public abstract void setErrorListener(ErrorListener listener);
/**
* Get the error event handler for the TransformerFactory.
*
* @return The current error handler, which should never be null.
*/
public abstract ErrorListener getErrorListener();
}

View file

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

View file

@ -0,0 +1,52 @@
/*
* Copyright (c) 2000, 2005, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.xml.transform;
/**
* <p>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.
*
* @since 1.4
*/
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 against which the first argument will be made
* absolute if the absolute URI is required.
*
* @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;
}

View file

@ -0,0 +1,51 @@
/*
* Copyright (c) 2000, 2005, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.xml.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.
*
* @since 1.4
*/
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();
}

View file

@ -0,0 +1,363 @@
/*
* Copyright (c) 2000, 2005, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.xml.transform.dom;
import javax.xml.transform.Result;
import org.w3c.dom.Node;
/**
* <p>Acts as a holder for a transformation result tree in the form of a Document Object Model (DOM) tree.</p>
*
* <p>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 {@link #getNode()}.</p>
*
* @author <a href="Jeff.Suttor@Sun.com">Jeff Suttor</a>
* @since 1.4
*/
public class DOMResult implements Result {
/** <p>If {@link javax.xml.transform.TransformerFactory#getFeature}
* returns <code>true</code> when passed this value as an argument,
* the <code>Transformer</code> supports <code>Result</code> output of this type.</p>
*/
public static final String FEATURE = "http://javax.xml.transform.dom.DOMResult/feature";
/**
* <p>Zero-argument default constructor.</p>
*
* <p><code>node</code>,
* <code>siblingNode</code> and
* <code>systemId</code>
* will be set to <code>null</code>.</p>
*/
public DOMResult() {
setNode(null);
setNextSibling(null);
setSystemId(null);
}
/**
* <p>Use a DOM node to create a new output target.</p>
*
* <p>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.</p>
*
* <p><code>siblingNode</code> and
* <code>systemId</code>
* will be set to <code>null</code>.</p>
*
* @param node The DOM node that will contain the result tree.
*/
public DOMResult(Node node) {
setNode(node);
setNextSibling(null);
setSystemId(null);
}
/**
* <p>Use a DOM node to create a new output target with the specified System ID.<p>
*
* <p>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.</p>
*
* <p><code>siblingNode</code> will be set to <code>null</code>.</p>
*
* @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);
setNextSibling(null);
setSystemId(systemId);
}
/**
* <p>Use a DOM node to create a new output target specifying the child node where the result nodes should be inserted before.</p>
*
* <p>In practice, <code>node</code> and <code>nextSibling</code> 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.</p>
*
* <p>Use <code>nextSibling</code> to specify the child node
* where the result nodes should be inserted before.
* If <code>nextSibling</code> is not a sibling of <code>node</code>,
* then an <code>IllegalArgumentException</code> is thrown.
* If <code>node</code> is <code>null</code> and <code>nextSibling</code> is not <code>null</code>,
* then an <code>IllegalArgumentException</code> is thrown.
* If <code>nextSibling</code> is <code>null</code>,
* then the behavior is the same as calling {@link #DOMResult(Node node)},
* i.e. append the result nodes as the last child of the specified <code>node</code>.</p>
*
* <p><code>systemId</code> will be set to <code>null</code>.</p>
*
* @param node The DOM node that will contain the result tree.
* @param nextSibling The child node where the result nodes should be inserted before.
*
* @throws IllegalArgumentException If <code>nextSibling</code> is not a sibling of <code>node</code> or
* <code>node</code> is <code>null</code> and <code>nextSibling</code>
* is not <code>null</code>.
*
* @since 1.5
*/
public DOMResult(Node node, Node nextSibling) {
// does the corrent parent/child relationship exist?
if (nextSibling != null) {
// cannot be a sibling of a null node
if (node == null) {
throw new IllegalArgumentException("Cannot create a DOMResult when the nextSibling is contained by the \"null\" node.");
}
// nextSibling contained by node?
if ((node.compareDocumentPosition(nextSibling)&Node.DOCUMENT_POSITION_CONTAINED_BY)==0) {
throw new IllegalArgumentException("Cannot create a DOMResult when the nextSibling is not contained by the node.");
}
}
setNode(node);
setNextSibling(nextSibling);
setSystemId(null);
}
/**
* <p>Use a DOM node to create a new output target specifying the child node where the result nodes should be inserted before and
* the specified System ID.</p>
*
* <p>In practice, <code>node</code> and <code>nextSibling</code> 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.</p>
*
* <p>Use <code>nextSibling</code> to specify the child node
* where the result nodes should be inserted before.
* If <code>nextSibling</code> is not a sibling of <code>node</code>,
* then an <code>IllegalArgumentException</code> is thrown.
* If <code>node</code> is <code>null</code> and <code>nextSibling</code> is not <code>null</code>,
* then an <code>IllegalArgumentException</code> is thrown.
* If <code>nextSibling</code> is <code>null</code>,
* then the behavior is the same as calling {@link #DOMResult(Node node, String systemId)},
* i.e. append the result nodes as the last child of the specified node and use the specified System ID.</p>
*
* @param node The DOM node that will contain the result tree.
* @param nextSibling The child node where the result nodes should be inserted before.
* @param systemId The system identifier which may be used in association with this node.
*
* @throws IllegalArgumentException If <code>nextSibling</code> is not a
* sibling of <code>node</code> or
* <code>node</code> is <code>null</code> and <code>nextSibling</code>
* is not <code>null</code>.
*
* @since 1.5
*/
public DOMResult(Node node, Node nextSibling, String systemId) {
// does the corrent parent/child relationship exist?
if (nextSibling != null) {
// cannot be a sibling of a null node
if (node == null) {
throw new IllegalArgumentException("Cannot create a DOMResult when the nextSibling is contained by the \"null\" node.");
}
// nextSibling contained by node?
if ((node.compareDocumentPosition(nextSibling)&Node.DOCUMENT_POSITION_CONTAINED_BY)==0) {
throw new IllegalArgumentException("Cannot create a DOMResult when the nextSibling is not contained by the node.");
}
}
setNode(node);
setNextSibling(nextSibling);
setSystemId(systemId);
}
/**
* <p>Set the node that will contain the result DOM tree.<p>
*
* <p>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.</p>
*
* <p>An <code>IllegalStateException</code> is thrown if
* <code>nextSibling</code> is not <code>null</code> and
* <code>node</code> is not a parent of <code>nextSibling</code>.
* An <code>IllegalStateException</code> is thrown if <code>node</code> is <code>null</code> and
* <code>nextSibling</code> is not <code>null</code>.</p>
*
* @param node The node to which the transformation will be appended.
*
* @throws IllegalStateException If <code>nextSibling</code> is not
* <code>null</code> and
* <code>nextSibling</code> is not a child of <code>node</code> or
* <code>node</code> is <code>null</code> and
* <code>nextSibling</code> is not <code>null</code>.
*/
public void setNode(Node node) {
// does the corrent parent/child relationship exist?
if (nextSibling != null) {
// cannot be a sibling of a null node
if (node == null) {
throw new IllegalStateException("Cannot create a DOMResult when the nextSibling is contained by the \"null\" node.");
}
// nextSibling contained by node?
if ((node.compareDocumentPosition(nextSibling)&Node.DOCUMENT_POSITION_CONTAINED_BY)==0) {
throw new IllegalArgumentException("Cannot create a DOMResult when the nextSibling is not contained by the node.");
}
}
this.node = node;
}
/**
* <p>Get the node that will contain the result DOM tree.</p>
*
* <p>If no node was set via
* {@link #DOMResult(Node node)},
* {@link #DOMResult(Node node, String systeId)},
* {@link #DOMResult(Node node, Node nextSibling)},
* {@link #DOMResult(Node node, Node nextSibling, String systemId)} or
* {@link #setNode(Node node)},
* then the node will be set by the transformation, and may be obtained from this method once the transformation is complete.
* Calling this method before the transformation will return <code>null</code>.</p>
*
* @return The node to which the transformation will be appended.
*/
public Node getNode() {
return node;
}
/**
* <p>Set the child node before which the result nodes will be inserted.</p>
*
* <p>Use <code>nextSibling</code> to specify the child node
* before which the result nodes should be inserted.
* If <code>nextSibling</code> is not a descendant of <code>node</code>,
* then an <code>IllegalArgumentException</code> is thrown.
* If <code>node</code> is <code>null</code> and <code>nextSibling</code> is not <code>null</code>,
* then an <code>IllegalStateException</code> is thrown.
* If <code>nextSibling</code> is <code>null</code>,
* then the behavior is the same as calling {@link #DOMResult(Node node)},
* i.e. append the result nodes as the last child of the specified <code>node</code>.</p>
*
* @param nextSibling The child node before which the result nodes will be inserted.
*
* @throws IllegalArgumentException If <code>nextSibling</code> is not a
* descendant of <code>node</code>.
* @throws IllegalStateException If <code>node</code> is <code>null</code>
* and <code>nextSibling</code> is not <code>null</code>.
*
* @since 1.5
*/
public void setNextSibling(Node nextSibling) {
// does the corrent parent/child relationship exist?
if (nextSibling != null) {
// cannot be a sibling of a null node
if (node == null) {
throw new IllegalStateException("Cannot create a DOMResult when the nextSibling is contained by the \"null\" node.");
}
// nextSibling contained by node?
if ((node.compareDocumentPosition(nextSibling)&Node.DOCUMENT_POSITION_CONTAINED_BY)==0) {
throw new IllegalArgumentException("Cannot create a DOMResult when the nextSibling is not contained by the node.");
}
}
this.nextSibling = nextSibling;
}
/**
* <p>Get the child node before which the result nodes will be inserted.</p>
*
* <p>If no node was set via
* {@link #DOMResult(Node node, Node nextSibling)},
* {@link #DOMResult(Node node, Node nextSibling, String systemId)} or
* {@link #setNextSibling(Node nextSibling)},
* then <code>null</code> will be returned.</p>
*
* @return The child node before which the result nodes will be inserted.
*
* @since 1.5
*/
public Node getNextSibling() {
return nextSibling;
}
/**
* <p>Set the systemId that may be used in association with the node.</p>
*
* @param systemId The system identifier as a URI string.
*/
public void setSystemId(String systemId) {
this.systemId = systemId;
}
/**
* <p>Get the System Identifier.</p>
*
* <p>If no System ID was set via
* {@link #DOMResult(Node node, String systemId)},
* {@link #DOMResult(Node node, Node nextSibling, String systemId)} or
* {@link #setSystemId(String systemId)},
* then <code>null</code> will be returned.</p>
*
* @return The system identifier.
*/
public String getSystemId() {
return systemId;
}
//////////////////////////////////////////////////////////////////////
// Internal state.
//////////////////////////////////////////////////////////////////////
/**
* <p>The node to which the transformation will be appended.</p>
*/
private Node node = null;
/**
* <p>The child node before which the result nodes will be inserted.</p>
*
* @since 1.5
*/
private Node nextSibling = null;
/**
* <p>The System ID that may be used in association with the node.</p>
*/
private String systemId = null;
}

View file

@ -0,0 +1,138 @@
/*
* Copyright (c) 2000, 2005, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.xml.transform.dom;
import javax.xml.transform.Source;
import org.w3c.dom.Node;
/**
* <p>Acts as a holder for a transformation Source tree in the
* form of a Document Object Model (DOM) tree.</p>
*
* <p>Note that XSLT requires namespace support. Attempting to transform a DOM
* that was not contructed with a namespace-aware parser may result in errors.
* Parsers can be made namespace aware by calling
* {@link javax.xml.parsers.DocumentBuilderFactory#setNamespaceAware(boolean awareness)}.</p>
*
* @author <a href="Jeff.Suttor@Sun.com">Jeff Suttor</a>
* @see <a href="http://www.w3.org/TR/DOM-Level-2">Document Object Model (DOM) Level 2 Specification</a>
* @since 1.4
*/
public class DOMSource implements Source {
/**
* <p><code>Node</code> to serve as DOM source.</p>
*/
private Node node;
/**
* <p>The base ID (URL or system ID) from where URLs
* will be resolved.</p>
*/
private String systemID;
/** 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";
/**
* <p>Zero-argument default constructor. If this constructor is used, and
* no DOM source is set using {@link #setNode(Node node)} , then the
* <code>Transformer</code> will
* create an empty source {@link org.w3c.dom.Document} using
* {@link javax.xml.parsers.DocumentBuilder#newDocument()}.</p>
*
* @see javax.xml.transform.Transformer#transform(Source xmlSource, Result outputTarget)
*/
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 systemID Base URL for this DOM tree.
*/
public void setSystemId(String systemID) {
this.systemID = systemID;
}
/**
* 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.systemID;
}
}

View file

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

View file

@ -0,0 +1,291 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2000, 2005, Oracle and/or its affiliates. All rights reserved.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
This code is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License version 2 only, as
published by the Free Software Foundation. Oracle designates this
particular file as subject to the "Classpath" exception as provided
by Oracle in the LICENSE file that accompanied this code.
This code is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
version 2 for more details (a copy is included in the LICENSE file that
accompanied this code).
You should have received a copy of the GNU General Public License version
2 along with this work; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
or visit www.oracle.com if you need additional information or have any
questions.
-->
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Transformation API For XML</title>
<meta name="CVS"
content="$Id: overview.html,v 1.2 2005/06/10 03:50:39 jeffsuttor Exp $" />
<meta name="AUTHOR"
content="Jeff.Suttor@Sun.com" />
</head>
<body>
<h2>Transformation API For XML</h2>
<h3>Introduction</h3>
<p>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). </p>
<p>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, <A href="http://www.w3.org/TR/xslt">XSLT</A>
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.</p>
<p>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.</p>
<p>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. </p>
<h3>General Terminology</h3>
<p>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.</p>
<ul>
<li>
<p>
<b>Tree</b>
<br>This term, as used within this document, describes an
abstract structure that consists of nodes or events that may be produced by
XML. A Tree physically may be a DOM tree, a series of well balanced parse
events (such as those coming from a SAX2 ContentHander), a series of requests
(the result of which can describe a tree), or a stream of marked-up
characters.</p>
</li>
<li>
<p>
<b>Source Tree(s)</b>
<br>One or more trees that are the inputs to the
transformation.</p>
</li>
<li>
<p>
<b>Result Tree(s)</b>
<br>One or more trees that are the output of the
transformation.</p>
</li>
<li>
<p>
<b>Transformation</b>
<br>The processor of consuming a stream or tree to produce
another stream or tree.</p>
</li>
<li>
<p>
<b>Identity (or Copy) Transformation</b>
<br>The process of transformation from a source to a result,
making as few structural changes as possible and no informational changes. The
term is somewhat loosely used, as the process is really a copy. from one
"format" (such as a DOM tree, stream, or set of SAX events) to
another.</p>
</li>
<li>
<p>
<b>Serialization</b>
<br>The process of taking a tree and turning it into a stream. In
some sense, a serialization is a specialized transformation.</p>
</li>
<li>
<p>
<b>Parsing</b>
<br>The process of taking a stream and turning it into a tree. In
some sense, parsing is a specialized transformation.</p>
</li>
<li>
<p>
<b>Transformer</b>
<br>A Transformer is the object that executes the transformation.
</p>
</li>
<li>
<p>
<b>Transformation instructions</b>
<br>Describes the transformation. A form of code, script, or
simply a declaration or series of declarations.</p>
</li>
<li>
<p>
<b>Stylesheet</b>
<br>The same as "transformation instructions," except it is
likely to be used in conjunction with <A href="http://www.w3.org/TR/xslt">XSLT</A>.</p>
</li>
<li>
<p>
<b>Templates</b>
<br>Another form of "transformation instructions." In the TrAX
interface, this term is used to describe processed or compiled transformation
instructions. The Source flows through a Templates object to be formed into the
Result.</p>
</li>
<li>
<p>
<b>Processor</b>
<br>A general term for the thing that may both process the
transformation instructions, and perform the transformation.</p>
</li>
<li>
<p>
<b>DOM</b>
<br>Document Object Model, specifically referring to the
<A href="#http://www.w3.org/TR/DOM-Level-2%20">Document Object Model
(DOM) Level 2 Specification</A>.</p>
</li>
<li>
<p>
<b>SAX</b><br>
Simple API for XML, specifically referring to the <a href="http://sax.sourceforge.net/">SAX 2.0.2 release</a>.
</p>
</li>
</ul>
<h3>Model</h3>
<p>The section defines the abstract model for TrAX, apart from the details
of the interfaces.</p>
<p>A TRaX <A href="#pattern-TransformerFactory">TransformerFactory</A> is an object
that processes transformation instructions, and produces
<A href="#pattern-Templates">Templates</A> (in the technical
terminology). A <A href="#pattern-Templates">Templates</A>
object provides a <A href="#pattern-Transformer">Transformer</A>, which transforms one or
more <A href="#pattern-Source">Source</A>s into one or more
<A href="#pattern-Result">Result</A>s.</p>
<p>To use the TRaX interface, you create a
<A href="#pattern-TransformerFactory">TransformerFactory</A>,
which may directly provide a <A href="#pattern-Transformers">Transformers</A>, or which can provide
<A href="#pattern-Templates">Templates</A> from a variety of
<A href="#pattern-Source">Source</A>s. The
<A href="#pattern-Templates">Templates</A> object is a processed
or compiled representation of the transformation instructions, and provides a
<A href="#pattern-Transformer">Transformer</A>. The
<A href="#pattern-Transformer">Transformer</A> processes a
<A href="#pattern-Transformer">Source</A> according to the
instructions found in the <A href="#pattern-Templates">Templates</A>, and produces a
<A href="#pattern-Result">Result</A>.</p>
<p>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
<code>serialization</code>. We believe this is the most suitable term for
this process, despite the overlap with Java object serialization.</p>
<H3>TRaX Patterns</H3>
<ul>
<p>
<b><a name="pattern-Processor">Processor</a></b>
<br>
<br>
<i>Intent: </i>Generic concept for the
set of objects that implement the TrAX interfaces.<br>
<i>Responsibilities: </i>Create compiled transformation instructions, transform
sources, and manage transformation parameters and
properties.<br>
<i>Thread safety: </i>Only the Templates object can be
used concurrently in multiple threads. The rest of the processor does not do
synchronized blocking, and so may not be used to perform multiple concurrent
operations. Different Processors can be used concurrently by different
threads.</p>
<p>
<b><a name="pattern-TransformerFactory">TransformerFactory</a></b>
<br>
<br>
<i>Intent: </i>Serve as a vendor-neutral Processor interface for
<A href="http://www.w3.org/TR/xslt">XSLT</A> and similar
processors.<br>
<i>Responsibilities: </i>Serve as a factory for a concrete
implementation of an TransformerFactory, serve as a direct factory for
Transformer objects, serve as a factory for Templates objects, and manage
processor specific features.<br>
<i>Thread safety: </i>A
TransformerFactory may not perform mulitple concurrent
operations.</p>
<p>
<b><a name="pattern-Templates">Templates</a></b>
<br>
<br>
<i>Intent: </i>The
runtime representation of the transformation instructions.<br>
<i>Responsibilities: </i>A data bag for transformation instructions; act as a factory
for Transformers.<br>
<i>Thread safety: </i>Threadsafe for concurrent
usage over multiple threads once construction is complete.</p>
<p>
<b><a name="pattern-Transformer">Transformer</a></b>
<br>
<br>
<i>Intent: </i>Act as a per-thread
execution context for transformations, act as an interface for performing the
transformation.<br>
<i>Responsibilities: </i>Perform the
transformation.<br>
<i>Thread safety: </i>Only one instance per thread
is safe.<br>
<i>Notes: </i>The Transformer is bound to the Templates
object that created it.</p>
<p>
<b><a name="pattern-Source">Source</a></b>
<br>
<br>
<i>Intent: </i>Serve as a
single vendor-neutral object for multiple types of input.<br>
<i>Responsibilities: </i>Act as simple data holder for System IDs, DOM nodes, streams,
etc.<br>
<i>Thread safety: </i>Threadsafe concurrently over multiple
threads for read-only operations; must be synchronized for edit
operations.</p>
<p>
<b><a name="pattern-Result">Result</a></b>
<br>
<br>
<i>Potential alternate name: </i>ResultTarget<br>
<i>Intent: </i>Serve
as a single object for multiple types of output, so there can be simple process
method signatures.<br>
<i>Responsibilities: </i>Act as simple data holder for
output stream, DOM node, ContentHandler, etc.<br>
<i>Thread safety: </i>Threadsafe concurrently over multiple threads for read-only,
must be synchronized for edit.</p>
</ul>
</body>
</html>

View file

@ -0,0 +1,233 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2000, 2005, Oracle and/or its affiliates. All rights reserved.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
This code is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License version 2 only, as
published by the Free Software Foundation. Oracle designates this
particular file as subject to the "Classpath" exception as provided
by Oracle in the LICENSE file that accompanied this code.
This code is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
version 2 for more details (a copy is included in the LICENSE file that
accompanied this code).
You should have received a copy of the GNU General Public License version
2 along with this work; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
or visit www.oracle.com if you need additional information or have any
questions.
-->
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>javax.xml.transform</title>
<meta name="CVS"
content="$Id: package.html,v 1.2 2005/06/10 03:50:39 jeffsuttor Exp $" />
<meta name="AUTHOR"
content="Jeff.Suttor@Sun.com" />
</head>
<body>
<p>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.
</p>
<p>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}.
</p>
<h3>Creating Objects</h3>
<p>The API allows a concrete
{@link javax.xml.transform.TransformerFactory} object to be created from
the static function
{@link javax.xml.transform.TransformerFactory#newInstance}.
</p>
<h3>Specification of Inputs and Outputs</h3>
<p>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.
</p>
<pre>
<code>
TransformerFactory tfactory = TransformerFactory.newInstance();
if (tfactory.getFeature(DOMSource.FEATURE) &amp;&amp; tfactory.getFeature(StreamResult.FEATURE)) {
...
}
</code>
</pre>
<h3>
<a name="qname-delimiter">Qualified Name Representation</a>
</h3>
<p><a href="http://www.w3.org/TR/REC-xml-names">Namespaces</a>
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.
</p>
<p>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.
</p>
<p>In order to pass namespaced values to transformations,
for
instance when setting a property or a parameter on a
{@link javax.xml.transform.Transformer} object,
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.
</p>
<p>For example, if a URI and local name were obtained from an element
defined with &lt;xyz:foo xmlns:xyz="http://xyz.foo.com/yada/baz.html"/&gt;,
then the Qualified Name would be "{http://xyz.foo.com/yada/baz.html}foo".
Note that the prefix is lost.
</p>
<h3>Result Tree Serialization</h3>
<p>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.
These properties only apply to stream results, they have no effect when
the result is a DOM tree or SAX event stream.</p>
<p>Strings that match the <a href="http://www.w3.org/TR/xslt#output">XSLT
specification for xsl:output attributes</a> 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 <a href="#qname-delimiter">namespace qualified</a>. Output key names
that are namespace qualified are always allowed, although they may be
ignored by some implementations.</p>
<p>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. </p>
<h3>Exceptions and Error Reporting</h3>
<p>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.</p>
<p>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.</p>
<p>{@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.</p>
<p>Transformation warnings and errors are sent to an
{@link javax.xml.transform.ErrorListener}, at which point the
application may decide to report the error or warning, and may decide to throw
an <code>Exception</code> for a non-fatal error. The <code>ErrorListener</code> 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 <code>ErrorListener</code> on both objects
will always be valid and non-<code>null</code>, whether set by the application or a default
implementation provided by the processor.
The default implementation provided by the processor will report all warnings and errors to <code>System.err</code>
and does not throw any <code>Exception</code>s.
Applications are <em>strongly</em> encouraged to register and use
<code>ErrorListener</code>s that insure proper behavior for warnings and
errors.
</p>
<h3>Resolution of URIs within a transformation</h3>
<p>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
<code>URIResolver.resolve</code> method takes two String arguments, the URI found in the
stylesheet instructions or built as part of the transformation process, and the
base URI
against which the first argument will be made absolute if the
absolute URI is required.
The returned {@link javax.xml.transform.Source} object must be usable by
the transformer, as specified in its implemented features.</p>
</body>
</html>

View file

@ -0,0 +1,145 @@
/*
* Copyright (c) 2000, 2005, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.xml.transform.sax;
import javax.xml.transform.Result;
import org.xml.sax.ContentHandler;
import org.xml.sax.ext.LexicalHandler;
/**
* <p>Acts as an holder for a transformation Result.</p>
*
* @author <a href="Jeff.Suttor@Sun.com">Jeff Suttor</a>
* @since 1.4
*/
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.
*
* <p>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
* <code>LexicalHandler</code>.</p>
*
* @param handler A non-null <code>LexicalHandler</code> 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 <code>LexicalHandler</code>, 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;
}

View file

@ -0,0 +1,210 @@
/*
* Copyright (c) 2000, 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.xml.transform.sax;
import javax.xml.transform.Source;
import javax.xml.transform.stream.StreamSource;
import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;
/**
* <p>Acts as an holder for SAX-style Source.</p>
*
* <p>Note that XSLT requires namespace support. Attempting to transform an
* input source that is not
* generated with a namespace-aware parser may result in errors.
* Parsers can be made namespace aware by calling the
* {@link javax.xml.parsers.SAXParserFactory#setNamespaceAware(boolean awareness)} method.</p>
*
* @author <a href="mailto:Jeff.Suttor@Sun.com">Jeff Suttor</a>
* @since 1.4
*/
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";
/**
* <p>Zero-argument default constructor. If this constructor is used, and
* no SAX source is set using
* {@link #setInputSource(InputSource inputSource)} , then the
* <code>Transformer</code> will
* create an empty source {@link org.xml.sax.InputSource} using
* {@link org.xml.sax.InputSource#InputSource() new InputSource()}.</p>
*
* @see javax.xml.transform.Transformer#transform(Source xmlSource, Result outputTarget)
*/
public SAXSource() { }
/**
* Create a <code>SAXSource</code>, 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 <code>SAXSource</code>, using a SAX <code>InputSource</code>.
* 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.
*
* <p>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).</p>
*
* @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);
}
}
/**
* <p>Get the base ID (URI or system ID) from where URIs
* will be resolved.</p>
*
* @return Base URL for the <code>Source</code>, or <code>null</code>.
*/
public String getSystemId() {
if (inputSource == null) {
return null;
} else {
return inputSource.getSystemId();
}
}
/**
* The XMLReader to be used for the source tree input. May be null.
*/
private XMLReader reader;
/**
* <p>The SAX InputSource to be used for the source tree input.
* Should not be <code>null</code>.</p>
*/
private InputSource inputSource;
/**
* Attempt to obtain a SAX InputSource object from a 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;
}
}
}

View file

@ -0,0 +1,152 @@
/*
* Copyright (c) 2000, 2005, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.xml.transform.sax;
import javax.xml.transform.*;
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.
*
* <p>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.</p>
*
* @since 1.4
*/
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;
}

View file

@ -0,0 +1,70 @@
/*
* Copyright (c) 2000, 2005, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.xml.transform.sax;
import javax.xml.transform.*;
import org.xml.sax.ContentHandler;
/**
* A SAX ContentHandler that may be used to process SAX
* parse events (parsing transformation instructions) into a Templates object.
*
* <p>Note that TemplatesHandler does not need to implement LexicalHandler.</p>
*
* @since 1.4
*/
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 systemID 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();
}

View file

@ -0,0 +1,78 @@
/*
* Copyright (c) 2000, 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.xml.transform.sax;
import javax.xml.transform.Result;
import javax.xml.transform.Transformer;
import org.xml.sax.ContentHandler;
import org.xml.sax.DTDHandler;
import org.xml.sax.ext.LexicalHandler;
/**
* A TransformerHandler
* listens for SAX ContentHandler parse events and transforms
* them to a Result.
*
* @since 1.4
*/
public interface TransformerHandler
extends ContentHandler, LexicalHandler, DTDHandler {
/**
* <p>Set the <code>Result</code> associated with this
* <code>TransformerHandler</code> to be used for the transformation.</p>
*
* @param result A <code>Result</code> instance, should not be
* <code>null</code>.
*
* @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();
/**
* <p>Get the <code>Transformer</code> associated with this handler, which
* is needed in order to set parameters and output properties.</p>
*
* @return <code>Transformer</code> associated with this
* <code>TransformerHandler</code>.
*/
public Transformer getTransformer();
}

View file

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

View file

@ -0,0 +1,183 @@
/*
* Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.xml.transform.stax;
import javax.xml.stream.XMLEventWriter;
import javax.xml.stream.XMLStreamWriter;
import javax.xml.transform.Result;
/**
* <p>Acts as a holder for an XML {@link Result} in the
* form of a StAX writer,i.e.
* {@link XMLStreamWriter} or {@link XMLEventWriter}.
* <code>StAXResult</code> can be used in all cases that accept
* a <code>Result</code>, e.g. {@link javax.xml.transform.Transformer},
* {@link javax.xml.validation.Validator} which accept
* <code>Result</code> as input.
*
* @author <a href="mailto:Neeraj.Bajaj@Sun.com">Neeraj Bajaj</a>
* @author <a href="mailto:Jeff.Suttor@Sun.com">Jeff Suttor</a>
*
* @see <a href="http://jcp.org/en/jsr/detail?id=173">
* JSR 173: Streaming API for XML</a>
* @see XMLStreamWriter
* @see XMLEventWriter
*
* @since 1.6
*/
public class StAXResult implements Result {
/** If {@link javax.xml.transform.TransformerFactory#getFeature(String name)}
* 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.stax.StAXResult/feature";
/**
* <p><code>XMLEventWriter</code> to be used for
* <code>Result</code> output.</p>
*/
private XMLEventWriter xmlEventWriter = null;
/**
* <p><code>XMLStreamWriter</code> to be used for
* <code>Result</code> output.</p>
*/
private XMLStreamWriter xmlStreamWriter = null;
/** <p>System identifier for this <code>StAXResult</code>.<p> */
private String systemId = null;
/**
* <p>Creates a new instance of a <code>StAXResult</code>
* by supplying an {@link XMLEventWriter}.</p>
*
* <p><code>XMLEventWriter</code> must be a
* non-<code>null</code> reference.</p>
*
* @param xmlEventWriter <code>XMLEventWriter</code> used to create
* this <code>StAXResult</code>.
*
* @throws IllegalArgumentException If <code>xmlEventWriter</code> ==
* <code>null</code>.
*/
public StAXResult(final XMLEventWriter xmlEventWriter) {
if (xmlEventWriter == null) {
throw new IllegalArgumentException(
"StAXResult(XMLEventWriter) with XMLEventWriter == null");
}
this.xmlEventWriter = xmlEventWriter;
}
/**
* <p>Creates a new instance of a <code>StAXResult</code>
* by supplying an {@link XMLStreamWriter}.</p>
*
* <p><code>XMLStreamWriter</code> must be a
* non-<code>null</code> reference.</p>
*
* @param xmlStreamWriter <code>XMLStreamWriter</code> used to create
* this <code>StAXResult</code>.
*
* @throws IllegalArgumentException If <code>xmlStreamWriter</code> ==
* <code>null</code>.
*/
public StAXResult(final XMLStreamWriter xmlStreamWriter) {
if (xmlStreamWriter == null) {
throw new IllegalArgumentException(
"StAXResult(XMLStreamWriter) with XMLStreamWriter == null");
}
this.xmlStreamWriter = xmlStreamWriter;
}
/**
* <p>Get the <code>XMLEventWriter</code> used by this
* <code>StAXResult</code>.</p>
*
* <p><code>XMLEventWriter</code> will be <code>null</code>
* if this <code>StAXResult</code> was created with a
* <code>XMLStreamWriter</code>.</p>
*
* @return <code>XMLEventWriter</code> used by this
* <code>StAXResult</code>.
*/
public XMLEventWriter getXMLEventWriter() {
return xmlEventWriter;
}
/**
* <p>Get the <code>XMLStreamWriter</code> used by this
* <code>StAXResult</code>.</p>
*
* <p><code>XMLStreamWriter</code> will be <code>null</code>
* if this <code>StAXResult</code> was created with a
* <code>XMLEventWriter</code>.</p>
*
* @return <code>XMLStreamWriter</code> used by this
* <code>StAXResult</code>.
*/
public XMLStreamWriter getXMLStreamWriter() {
return xmlStreamWriter;
}
/**
* <p>In the context of a <code>StAXResult</code>, it is not appropriate
* to explicitly set the system identifier.
* The <code>XMLEventWriter</code> or <code>XMLStreamWriter</code>
* used to construct this <code>StAXResult</code> determines the
* system identifier of the XML result.</p>
*
* <p>An {@link UnsupportedOperationException} is <strong>always</strong>
* thrown by this method.</p>
*
* @param systemId Ignored.
*
* @throws UnsupportedOperationException Is <strong>always</strong>
* thrown by this method.
*/
public void setSystemId(final String systemId) {
throw new UnsupportedOperationException(
"StAXResult#setSystemId(systemId) cannot set the "
+ "system identifier for a StAXResult");
}
/**
* <p>The returned system identifier is always <code>null</code>.</p>
*
* @return The returned system identifier is always <code>null</code>.
*/
public String getSystemId() {
return null;
}
}

View file

@ -0,0 +1,236 @@
/*
* Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.xml.transform.stax;
import javax.xml.stream.XMLEventReader;
import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import javax.xml.stream.events.XMLEvent;
import javax.xml.transform.Source;
/**
* <p>Acts as a holder for an XML {@link Source} in the
* form of a StAX reader,i.e.
* {@link XMLStreamReader} or {@link XMLEventReader}.
* <code>StAXSource</code> can be used in all cases that accept
* a <code>Source</code>, e.g. {@link javax.xml.transform.Transformer},
* {@link javax.xml.validation.Validator} which accept
* <code>Source</code> as input.
*
* <p><code>StAXSource</code>s are consumed during processing
* and are not reusable.</p>
*
* @author <a href="mailto:Neeraj.Bajaj@Sun.com">Neeraj Bajaj</a>
* @author <a href="mailto:Jeff.Suttor@Sun.com">Jeff Suttor</a>
*
* @see <a href="http://jcp.org/en/jsr/detail?id=173">
* JSR 173: Streaming API for XML</a>
* @see XMLStreamReader
* @see XMLEventReader
*
* @since 1.6
*/
public class StAXSource implements Source {
/** If {@link javax.xml.transform.TransformerFactory#getFeature(String name)}
* 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.stax.StAXSource/feature";
/** <p><code>XMLEventReader</code> to be used for source input.</p> */
private XMLEventReader xmlEventReader = null;
/** <p><code>XMLStreamReader</code> to be used for source input.</p> */
private XMLStreamReader xmlStreamReader = null;
/** <p>System identifier of source input.</p> */
private String systemId = null;
/**
* <p>Creates a new instance of a <code>StAXSource</code>
* by supplying an {@link XMLEventReader}.</p>
*
* <p><code>XMLEventReader</code> must be a
* non-<code>null</code> reference.</p>
*
* <p><code>XMLEventReader</code> must be in
* {@link XMLStreamConstants#START_DOCUMENT} or
* {@link XMLStreamConstants#START_ELEMENT} state.</p>
*
* @param xmlEventReader <code>XMLEventReader</code> used to create
* this <code>StAXSource</code>.
*
* @throws XMLStreamException If <code>xmlEventReader</code> access
* throws an <code>Exception</code>.
* @throws IllegalArgumentException If <code>xmlEventReader</code> ==
* <code>null</code>.
* @throws IllegalStateException If <code>xmlEventReader</code>
* is not in <code>XMLStreamConstants.START_DOCUMENT</code> or
* <code>XMLStreamConstants.START_ELEMENT</code> state.
*/
public StAXSource(final XMLEventReader xmlEventReader)
throws XMLStreamException {
if (xmlEventReader == null) {
throw new IllegalArgumentException(
"StAXSource(XMLEventReader) with XMLEventReader == null");
}
// TODO: This is ugly ...
// there is no way to know the current position(event) of
// XMLEventReader. peek() is the only way to know the next event.
// The next event on the input stream should be
// XMLStreamConstants.START_DOCUMENT or
// XMLStreamConstants.START_ELEMENT.
XMLEvent event = xmlEventReader.peek();
int eventType = event.getEventType();
if (eventType != XMLStreamConstants.START_DOCUMENT
&& eventType != XMLStreamConstants.START_ELEMENT) {
throw new IllegalStateException(
"StAXSource(XMLEventReader) with XMLEventReader "
+ "not in XMLStreamConstants.START_DOCUMENT or "
+ "XMLStreamConstants.START_ELEMENT state");
}
this.xmlEventReader = xmlEventReader;
systemId = event.getLocation().getSystemId();
}
/**
* <p>Creates a new instance of a <code>StAXSource</code>
* by supplying an {@link XMLStreamReader}.</p>
*
* <p><code>XMLStreamReader</code> must be a
* non-<code>null</code> reference.</p>
*
* <p><code>XMLStreamReader</code> must be in
* {@link XMLStreamConstants#START_DOCUMENT} or
* {@link XMLStreamConstants#START_ELEMENT} state.</p>
*
* @param xmlStreamReader <code>XMLStreamReader</code> used to create
* this <code>StAXSource</code>.
*
* @throws IllegalArgumentException If <code>xmlStreamReader</code> ==
* <code>null</code>.
* @throws IllegalStateException If <code>xmlStreamReader</code>
* is not in <code>XMLStreamConstants.START_DOCUMENT</code> or
* <code>XMLStreamConstants.START_ELEMENT</code> state.
*/
public StAXSource(final XMLStreamReader xmlStreamReader) {
if (xmlStreamReader == null) {
throw new IllegalArgumentException(
"StAXSource(XMLStreamReader) with XMLStreamReader == null");
}
int eventType = xmlStreamReader.getEventType();
if (eventType != XMLStreamConstants.START_DOCUMENT
&& eventType != XMLStreamConstants.START_ELEMENT) {
throw new IllegalStateException(
"StAXSource(XMLStreamReader) with XMLStreamReader"
+ "not in XMLStreamConstants.START_DOCUMENT or "
+ "XMLStreamConstants.START_ELEMENT state");
}
this.xmlStreamReader = xmlStreamReader;
systemId = xmlStreamReader.getLocation().getSystemId();
}
/**
* <p>Get the <code>XMLEventReader</code> used by this
* <code>StAXSource</code>.</p>
*
* <p><code>XMLEventReader</code> will be <code>null</code>.
* if this <code>StAXSource</code> was created with a
* <code>XMLStreamReader</code>.</p>
*
* @return <code>XMLEventReader</code> used by this
* <code>StAXSource</code>.
*/
public XMLEventReader getXMLEventReader() {
return xmlEventReader;
}
/**
* <p>Get the <code>XMLStreamReader</code> used by this
* <code>StAXSource</code>.</p>
*
* <p><code>XMLStreamReader</code> will be <code>null</code>
* if this <code>StAXSource</code> was created with a
* <code>XMLEventReader</code>.</p>
*
* @return <code>XMLStreamReader</code> used by this
* <code>StAXSource</code>.
*/
public XMLStreamReader getXMLStreamReader() {
return xmlStreamReader;
}
/**
* <p>In the context of a <code>StAXSource</code>, it is not appropriate
* to explicitly set the system identifier.
* The <code>XMLStreamReader</code> or <code>XMLEventReader</code>
* used to construct this <code>StAXSource</code> determines the
* system identifier of the XML source.</p>
*
* <p>An {@link UnsupportedOperationException} is <strong>always</strong>
* thrown by this method.</p>
*
* @param systemId Ignored.
*
* @throws UnsupportedOperationException Is <strong>always</strong>
* thrown by this method.
*/
public void setSystemId(final String systemId) {
throw new UnsupportedOperationException(
"StAXSource#setSystemId(systemId) cannot set the "
+ "system identifier for a StAXSource");
}
/**
* <p>Get the system identifier used by this
* <code>StAXSource</code>.</p>
*
* <p>The <code>XMLStreamReader</code> or <code>XMLEventReader</code>
* used to construct this <code>StAXSource</code> is queried to determine
* the system identifier of the XML source.</p>
*
* <p>The system identifier may be <code>null</code> or
* an empty <code>""</code> <code>String</code>.</p>
*
* @return System identifier used by this <code>StAXSource</code>.
*/
public String getSystemId() {
return systemId;
}
}

View file

@ -0,0 +1,73 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
This code is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License version 2 only, as
published by the Free Software Foundation. Oracle designates this
particular file as subject to the "Classpath" exception as provided
by Oracle in the LICENSE file that accompanied this code.
This code is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
version 2 for more details (a copy is included in the LICENSE file that
accompanied this code).
You should have received a copy of the GNU General Public License version
2 along with this work; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
or visit www.oracle.com if you need additional information or have any
questions.
-->
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>javax.xml.transform.stax</title>
<meta name="CVS"
content="$Id: package.html,v 1.2 2005/11/03 19:34:28 jeffsuttor Exp $" />
<meta name="AUTHOR"
content="Jeff.Suttor@Sun.com" />
<meta name="AUTHOR"
content="Neeraj.Bajaj@Sun.com" />
</head>
<body>
<p>
Provides for StAX-specific transformation APIs.
TODO: better description(s).
</p>
<h2>Package Specification</h2>
<ul>
<li><a href="http://jcp.org/en/jsr/detail?id=173">JSR 173: Streaming API for XML</a></li>
</ul>
<h2>Related Documentation</h2>
<p>For overviews, tutorials, examples, guides, and tool documentation, please see:</p>
<ul>
<li><a href="">TODO: Refer to non-spec documentation</a></li>
</ul>
<!-- Put @see and @since tags down here. -->
<ul>
<li>@see XMLStreamReader</li>
<li>@see XMLEventReader</li>
</ul>
<p>
@since 1.6
</p>
</body>
</html>

View file

@ -0,0 +1,204 @@
/*
* Copyright (c) 2000, 2005, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.xml.transform.stream;
import javax.xml.transform.Result;
import java.io.File;
import java.io.OutputStream;
import java.io.Writer;
import java.net.MalformedURLException;
/**
* <p>Acts as an holder for a transformation result,
* which may be XML, plain Text, HTML, or some other form of markup.</p>
*
* @author <a href="Jeff.Suttor@Sun.com">Jeff Suttor</a>
* @since 1.4
*/
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) {
//convert file to appropriate URI, f.toURI().toASCIIString()
//converts the URI to string as per rule specified in
//RFC 2396,
setSystemId(f.toURI().toASCIIString());
}
/**
* 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;
}
/**
* <p>Set the system ID from a <code>File</code> reference.</p>
*
*
* @param f Must a non-null File reference.
*/
public void setSystemId(File f) {
//convert file to appropriate URI, f.toURI().toASCIIString()
//converts the URI to string as per rule specified in
//RFC 2396,
this.systemId = f.toURI().toASCIIString();
}
/**
* 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;
}

View file

@ -0,0 +1,285 @@
/*
* Copyright (c) 2000, 2005, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.xml.transform.stream;
import java.io.File;
import java.io.InputStream;
import java.io.Reader;
import javax.xml.transform.Source;
/**
* <p>Acts as an holder for a transformation Source in the form
* of a stream of XML markup.</p>
*
* <p><em>Note:</em> Due to their internal use of either a {@link Reader} or {@link InputStream} instance,
* <code>StreamSource</code> instances may only be used once.</p>
*
* @author <a href="Jeff.Suttor@Sun.com">Jeff Suttor</a>
* @since 1.4
*/
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";
/**
* <p>Zero-argument default constructor. If this constructor is used, and
* no Stream source is set using
* {@link #setInputStream(java.io.InputStream inputStream)} or
* {@link #setReader(java.io.Reader reader)}, then the
* <code>Transformer</code> will
* create an empty source {@link java.io.InputStream} using
* {@link java.io.InputStream#InputStream() new InputStream()}.</p>
*
* @see javax.xml.transform.Transformer#transform(Source xmlSource, Result outputTarget)
*/
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.
*
* <p>If this constructor is used to process a stylesheet, normally
* setSystemId should also be called, so that relative URI references
* can be resolved.</p>
*
* @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.
*
* <p>This constructor allows the systemID to be set in addition
* to the input stream, which allows relative URIs
* to be processed.</p>
*
* @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) {
//convert file to appropriate URI, f.toURI().toASCIIString()
//converts the URI to string as per rule specified in
//RFC 2396,
setSystemId(f.toURI().toASCIIString());
}
/**
* 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.
*
* <p>If this Source object is used to process a stylesheet, normally
* setSystemId should also be called, so that relative URL references
* can be resolved.</p>
*
* @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.
*
* <p>The public identifier is always optional: if the application
* writer includes one, it will be provided as part of the
* location information.</p>
*
* @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.
*
* <p>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).</p>
*
* @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) {
//convert file to appropriate URI, f.toURI().toASCIIString()
//converts the URI to string as per rule specified in
//RFC 2396,
this.systemId = f.toURI().toASCIIString();
}
//////////////////////////////////////////////////////////////////////
// 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;
}

View file

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