mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-21 03:24:38 +02:00
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:
parent
e35087b430
commit
786f3dbbdf
2059 changed files with 0 additions and 1770 deletions
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 by Oracle Corporation. All Rights Reserved.
|
||||
*/
|
||||
|
||||
package javax.xml.stream;
|
||||
|
||||
import javax.xml.stream.events.XMLEvent;
|
||||
|
||||
/**
|
||||
* This interface declares a simple filter interface that one can
|
||||
* create to filter XMLEventReaders
|
||||
* @version 1.0
|
||||
* @author Copyright (c) 2009 by Oracle Corporation. All Rights Reserved.
|
||||
* @since 1.6
|
||||
*/
|
||||
public interface EventFilter {
|
||||
/**
|
||||
* Tests whether this event is part of this stream. This method
|
||||
* will return true if this filter accepts this event and false
|
||||
* otherwise.
|
||||
*
|
||||
* @param event the event to test
|
||||
* @return true if this filter accepts this event, false otherwise
|
||||
*/
|
||||
public boolean accept(XMLEvent event);
|
||||
}
|
|
@ -0,0 +1,125 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 by Oracle Corporation. All Rights Reserved.
|
||||
*/
|
||||
|
||||
package javax.xml.stream;
|
||||
|
||||
/**
|
||||
* An error class for reporting factory configuration errors.
|
||||
*
|
||||
* @version 1.0
|
||||
* @author Copyright (c) 2009 by Oracle Corporation. All Rights Reserved.
|
||||
* @since 1.6
|
||||
*/
|
||||
public class FactoryConfigurationError extends Error {
|
||||
private static final long serialVersionUID = -2994412584589975744L;
|
||||
|
||||
Exception nested;
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
public FactoryConfigurationError(){}
|
||||
|
||||
/**
|
||||
* Construct an exception with a nested inner exception
|
||||
*
|
||||
* @param e the exception to nest
|
||||
*/
|
||||
public FactoryConfigurationError(java.lang.Exception e){
|
||||
nested = e;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct an exception with a nested inner exception
|
||||
* and a message
|
||||
*
|
||||
* @param e the exception to nest
|
||||
* @param msg the message to report
|
||||
*/
|
||||
public FactoryConfigurationError(java.lang.Exception e, java.lang.String msg){
|
||||
super(msg);
|
||||
nested = e;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct an exception with a nested inner exception
|
||||
* and a message
|
||||
*
|
||||
* @param msg the message to report
|
||||
* @param e the exception to nest
|
||||
*/
|
||||
public FactoryConfigurationError(java.lang.String msg, java.lang.Exception e){
|
||||
super(msg);
|
||||
nested = e;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct an exception with associated message
|
||||
*
|
||||
* @param msg the message to report
|
||||
*/
|
||||
public FactoryConfigurationError(java.lang.String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the nested exception (if any)
|
||||
*
|
||||
* @return the nested exception or null
|
||||
*/
|
||||
public Exception getException() {
|
||||
return nested;
|
||||
}
|
||||
/**
|
||||
* use the exception chaining mechanism of JDK1.4
|
||||
*/
|
||||
@Override
|
||||
public Throwable getCause() {
|
||||
return nested;
|
||||
}
|
||||
|
||||
/**
|
||||
* Report the message associated with this error
|
||||
*
|
||||
* @return the string value of the message
|
||||
*/
|
||||
public String getMessage() {
|
||||
String msg = super.getMessage();
|
||||
if(msg != null)
|
||||
return msg;
|
||||
if(nested != null){
|
||||
msg = nested.getMessage();
|
||||
if(msg == null)
|
||||
msg = nested.getClass().toString();
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,375 @@
|
|||
/*
|
||||
* Copyright (c) 2005, 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.stream;
|
||||
|
||||
import java.io.File;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.util.Iterator;
|
||||
import java.util.Properties;
|
||||
import java.util.ServiceConfigurationError;
|
||||
import java.util.ServiceLoader;
|
||||
|
||||
/**
|
||||
* <p>Implements pluggable streams.</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
|
||||
*/
|
||||
class FactoryFinder {
|
||||
// Check we have access to package.
|
||||
private static final String DEFAULT_PACKAGE = "com.sun.xml.internal.";
|
||||
|
||||
/**
|
||||
* Internal debug flag.
|
||||
*/
|
||||
private static boolean debug = false;
|
||||
|
||||
/**
|
||||
* Cache for properties in java.home/lib/jaxp.properties
|
||||
*/
|
||||
final private static Properties cacheProps = new Properties();
|
||||
|
||||
/**
|
||||
* Flag indicating if properties from java.home/lib/jaxp.properties
|
||||
* have been cached.
|
||||
*/
|
||||
private static volatile boolean firstTime = true;
|
||||
|
||||
/**
|
||||
* Security support class use to check access control before
|
||||
* getting certain system resources.
|
||||
*/
|
||||
final private 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
|
||||
*/
|
||||
static <T> T newInstance(Class<T> type, String className, ClassLoader cl, boolean doFallback)
|
||||
throws FactoryConfigurationError
|
||||
{
|
||||
return newInstance(type, className, cl, doFallback, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an instance of a class. Delegates to method
|
||||
* <code>getProviderClass()</code> in order to load the class.
|
||||
*
|
||||
* @param type Base class / Service interface of the factory to
|
||||
* instantiate.
|
||||
*
|
||||
* @param className Name of the concrete class corresponding to the
|
||||
* service provider
|
||||
*
|
||||
* @param cl <code>ClassLoader</code> used to load the factory class. If <code>null</code>
|
||||
* current <code>Thread</code>'s context classLoader is used to load the factory class.
|
||||
*
|
||||
* @param doFallback True if the current ClassLoader should be tried as
|
||||
* a fallback if the class is not found using cl
|
||||
*
|
||||
* @param useBSClsLoader True if cl=null actually meant bootstrap classLoader. This parameter
|
||||
* is needed since DocumentBuilderFactory/SAXParserFactory defined null as context classLoader.
|
||||
*/
|
||||
static <T> T newInstance(Class<T> type, String className, ClassLoader cl,
|
||||
boolean doFallback, boolean useBSClsLoader)
|
||||
throws FactoryConfigurationError
|
||||
{
|
||||
assert type != null;
|
||||
|
||||
// make sure we have access to restricted packages
|
||||
if (System.getSecurityManager() != null) {
|
||||
if (className != null && className.startsWith(DEFAULT_PACKAGE)) {
|
||||
cl = null;
|
||||
useBSClsLoader = true;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
Class<?> providerClass = getProviderClass(className, cl, doFallback, useBSClsLoader);
|
||||
if (!type.isAssignableFrom(providerClass)) {
|
||||
throw new ClassCastException(className + " cannot be cast to " + type.getName());
|
||||
}
|
||||
Object instance = providerClass.newInstance();
|
||||
if (debug) { // Extra check to avoid computing cl strings
|
||||
dPrint("created new instance of " + providerClass +
|
||||
" using ClassLoader: " + cl);
|
||||
}
|
||||
return type.cast(instance);
|
||||
}
|
||||
catch (ClassNotFoundException x) {
|
||||
throw new FactoryConfigurationError(
|
||||
"Provider " + className + " not found", x);
|
||||
}
|
||||
catch (Exception x) {
|
||||
throw new FactoryConfigurationError(
|
||||
"Provider " + className + " could not be instantiated: " + x,
|
||||
x);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the implementation Class object in the specified order.
|
||||
*
|
||||
* @return Class object of factory, never null
|
||||
*
|
||||
* @param type Base class / Service interface of the
|
||||
* factory to find.
|
||||
*
|
||||
* @param fallbackClassName Implementation class name, if nothing else
|
||||
* is found. Use null to mean no fallback.
|
||||
*
|
||||
* Package private so this code can be shared.
|
||||
*/
|
||||
static <T> T find(Class<T> type, String fallbackClassName)
|
||||
throws FactoryConfigurationError
|
||||
{
|
||||
return find(type, type.getName(), null, fallbackClassName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 factoryId Name of the factory to find, same as
|
||||
* a property name
|
||||
*
|
||||
* @param cl ClassLoader to be used to load the class, null means to use
|
||||
* the bootstrap ClassLoader
|
||||
*
|
||||
* @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 factoryId, ClassLoader cl, String fallbackClassName)
|
||||
throws FactoryConfigurationError
|
||||
{
|
||||
dPrint("find factoryId =" + factoryId);
|
||||
|
||||
// Use the system property first
|
||||
try {
|
||||
|
||||
final String systemProp;
|
||||
if (type.getName().equals(factoryId)) {
|
||||
systemProp = ss.getSystemProperty(factoryId);
|
||||
} else {
|
||||
systemProp = System.getProperty(factoryId);
|
||||
}
|
||||
if (systemProp != null) {
|
||||
dPrint("found system property, value=" + systemProp);
|
||||
return newInstance(type, systemProp, cl, true);
|
||||
}
|
||||
}
|
||||
catch (SecurityException se) {
|
||||
throw new FactoryConfigurationError(
|
||||
"Failed to read factoryId '" + factoryId + "'", se);
|
||||
}
|
||||
|
||||
// Try read $java.home/lib/stax.properties followed by
|
||||
// $java.home/lib/jaxp.properties if former not present
|
||||
String configFile = null;
|
||||
try {
|
||||
if (firstTime) {
|
||||
synchronized (cacheProps) {
|
||||
if (firstTime) {
|
||||
configFile = ss.getSystemProperty("java.home") + File.separator +
|
||||
"lib" + File.separator + "stax.properties";
|
||||
File f = new File(configFile);
|
||||
firstTime = false;
|
||||
if (ss.doesFileExist(f)) {
|
||||
dPrint("Read properties file "+f);
|
||||
cacheProps.load(ss.getFileInputStream(f));
|
||||
}
|
||||
else {
|
||||
configFile = ss.getSystemProperty("java.home") + File.separator +
|
||||
"lib" + File.separator + "jaxp.properties";
|
||||
f = new File(configFile);
|
||||
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 " + configFile + " value=" + factoryClassName);
|
||||
return newInstance(type, factoryClassName, cl, true);
|
||||
}
|
||||
}
|
||||
catch (Exception ex) {
|
||||
if (debug) ex.printStackTrace();
|
||||
}
|
||||
|
||||
if (type.getName().equals(factoryId)) {
|
||||
// Try Jar Service Provider Mechanism
|
||||
final T provider = findServiceProvider(type, cl);
|
||||
if (provider != null) {
|
||||
return provider;
|
||||
}
|
||||
} else {
|
||||
// We're in the case where a 'custom' factoryId was provided,
|
||||
// and in every case where that happens, we expect that
|
||||
// fallbackClassName will be null.
|
||||
assert fallbackClassName == null;
|
||||
}
|
||||
if (fallbackClassName == null) {
|
||||
throw new FactoryConfigurationError(
|
||||
"Provider for " + factoryId + " cannot be found", null);
|
||||
}
|
||||
|
||||
dPrint("loaded from fallback value: " + fallbackClassName);
|
||||
return newInstance(type, fallbackClassName, cl, true);
|
||||
}
|
||||
|
||||
/*
|
||||
* Try to find provider using the ServiceLoader API
|
||||
*
|
||||
* @param type Base class / Service interface of the factory to find.
|
||||
*
|
||||
* @return instance of provider class if found or null
|
||||
*/
|
||||
private static <T> T findServiceProvider(final Class<T> type, final ClassLoader cl) {
|
||||
try {
|
||||
return AccessController.doPrivileged(new PrivilegedAction<T>() {
|
||||
@Override
|
||||
public T run() {
|
||||
final ServiceLoader<T> serviceLoader;
|
||||
if (cl == null) {
|
||||
//the current thread's context class loader
|
||||
serviceLoader = ServiceLoader.load(type);
|
||||
} else {
|
||||
serviceLoader = ServiceLoader.load(type, cl);
|
||||
}
|
||||
final Iterator<T> iterator = serviceLoader.iterator();
|
||||
if (iterator.hasNext()) {
|
||||
return iterator.next();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch(ServiceConfigurationError e) {
|
||||
// It is not possible to wrap an error directly in
|
||||
// FactoryConfigurationError - so we need to wrap the
|
||||
// ServiceConfigurationError in a RuntimeException.
|
||||
// The alternative would be to modify the logic in
|
||||
// FactoryConfigurationError to allow setting a
|
||||
// Throwable as the cause, but that could cause
|
||||
// compatibility issues down the road.
|
||||
final RuntimeException x = new RuntimeException(
|
||||
"Provider for " + type + " cannot be created", e);
|
||||
final FactoryConfigurationError error =
|
||||
new FactoryConfigurationError(x, x.getMessage());
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,77 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 by Oracle Corporation. All Rights Reserved.
|
||||
*/
|
||||
|
||||
package javax.xml.stream;
|
||||
|
||||
/**
|
||||
* Provides information on the location of an event.
|
||||
*
|
||||
* All the information provided by a Location is optional. For example
|
||||
* an application may only report line numbers.
|
||||
*
|
||||
* @version 1.0
|
||||
* @author Copyright (c) 2009 by Oracle Corporation. All Rights Reserved.
|
||||
* @since 1.6
|
||||
*/
|
||||
public interface Location {
|
||||
/**
|
||||
* Return the line number where the current event ends,
|
||||
* returns -1 if none is available.
|
||||
* @return the current line number
|
||||
*/
|
||||
int getLineNumber();
|
||||
|
||||
/**
|
||||
* Return the column number where the current event ends,
|
||||
* returns -1 if none is available.
|
||||
* @return the current column number
|
||||
*/
|
||||
int getColumnNumber();
|
||||
|
||||
/**
|
||||
* Return the byte or character offset into the input source this location
|
||||
* is pointing to. If the input source is a file or a byte stream then
|
||||
* this is the byte offset into that stream, but if the input source is
|
||||
* a character media then the offset is the character offset.
|
||||
* Returns -1 if there is no offset available.
|
||||
* @return the current offset
|
||||
*/
|
||||
int getCharacterOffset();
|
||||
|
||||
/**
|
||||
* Returns the public ID of the XML
|
||||
* @return the public ID, or null if not available
|
||||
*/
|
||||
public String getPublicId();
|
||||
|
||||
/**
|
||||
* Returns the system ID of the XML
|
||||
* @return the system ID, or null if not available
|
||||
*/
|
||||
public String getSystemId();
|
||||
}
|
|
@ -0,0 +1,110 @@
|
|||
/*
|
||||
* Copyright (c) 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.stream;
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 by Oracle Corporation. All Rights Reserved.
|
||||
*/
|
||||
|
||||
package javax.xml.stream;
|
||||
|
||||
/**
|
||||
* This interface declares a simple filter interface that one can
|
||||
* create to filter XMLStreamReaders
|
||||
* @version 1.0
|
||||
* @author Copyright (c) 2009 by Oracle Corporation. All Rights Reserved.
|
||||
* @since 1.6
|
||||
*/
|
||||
public interface StreamFilter {
|
||||
|
||||
/**
|
||||
* Tests whether the current state is part of this stream. This method
|
||||
* will return true if this filter accepts this event and false otherwise.
|
||||
*
|
||||
* The method should not change the state of the reader when accepting
|
||||
* a state.
|
||||
*
|
||||
* @param reader the event to test
|
||||
* @return true if this filter accepts this event, false otherwise
|
||||
*/
|
||||
public boolean accept(XMLStreamReader reader);
|
||||
}
|
|
@ -0,0 +1,464 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009, 2013, by Oracle Corporation. All Rights Reserved.
|
||||
*/
|
||||
|
||||
package javax.xml.stream;
|
||||
import java.util.Iterator;
|
||||
import javax.xml.namespace.NamespaceContext;
|
||||
import javax.xml.namespace.QName;
|
||||
import javax.xml.stream.events.*;
|
||||
/**
|
||||
* This interface defines a utility class for creating instances of
|
||||
* XMLEvents
|
||||
* @version 1.2
|
||||
* @author Copyright (c) 2009 by Oracle Corporation. All Rights Reserved.
|
||||
* @see javax.xml.stream.events.StartElement
|
||||
* @see javax.xml.stream.events.EndElement
|
||||
* @see javax.xml.stream.events.ProcessingInstruction
|
||||
* @see javax.xml.stream.events.Comment
|
||||
* @see javax.xml.stream.events.Characters
|
||||
* @see javax.xml.stream.events.StartDocument
|
||||
* @see javax.xml.stream.events.EndDocument
|
||||
* @see javax.xml.stream.events.DTD
|
||||
* @since 1.6
|
||||
*/
|
||||
public abstract class XMLEventFactory {
|
||||
protected XMLEventFactory(){}
|
||||
|
||||
static final String JAXPFACTORYID = "javax.xml.stream.XMLEventFactory";
|
||||
static final String DEFAULIMPL = "com.sun.xml.internal.stream.events.XMLEventFactoryImpl";
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new instance of the factory in exactly the same manner as the
|
||||
* {@link #newFactory()} method.
|
||||
* @throws FactoryConfigurationError if an instance of this factory cannot be loaded
|
||||
*/
|
||||
public static XMLEventFactory newInstance()
|
||||
throws FactoryConfigurationError
|
||||
{
|
||||
return FactoryFinder.find(XMLEventFactory.class, DEFAULIMPL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new instance of the factory.
|
||||
* <p>
|
||||
* This static method creates a new factory instance.
|
||||
* This method uses the following ordered lookup procedure to determine
|
||||
* the XMLEventFactory implementation class to load:
|
||||
* </p>
|
||||
* <ul>
|
||||
* <li>
|
||||
* Use the javax.xml.stream.XMLEventFactory system property.
|
||||
* </li>
|
||||
* <li>
|
||||
* Use the properties file "lib/stax.properties" in the JRE directory.
|
||||
* This configuration file is in standard java.util.Properties format
|
||||
* and contains the fully qualified name of the implementation class
|
||||
* with the key being the system property defined above.
|
||||
* </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 XMLEventFactory it
|
||||
* can use the factory to configure and obtain stream instances.
|
||||
* </p>
|
||||
* <p>
|
||||
* Note that this is a new method that replaces the deprecated newInstance() method.
|
||||
* No changes in behavior are defined by this replacement method relative to
|
||||
* the deprecated method.
|
||||
* </p>
|
||||
* @throws FactoryConfigurationError in case of {@linkplain
|
||||
* java.util.ServiceConfigurationError service configuration error} or if
|
||||
* the implementation is not available or cannot be instantiated.
|
||||
*/
|
||||
public static XMLEventFactory newFactory()
|
||||
throws FactoryConfigurationError
|
||||
{
|
||||
return FactoryFinder.find(XMLEventFactory.class, DEFAULIMPL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new instance of the factory
|
||||
*
|
||||
* @param factoryId Name of the factory to find, same as
|
||||
* a property name
|
||||
* @param classLoader classLoader to use
|
||||
* @return the factory implementation
|
||||
* @throws FactoryConfigurationError if an instance of this factory cannot be loaded
|
||||
*
|
||||
* @deprecated This method has been deprecated to maintain API consistency.
|
||||
* All newInstance methods have been replaced with corresponding
|
||||
* newFactory methods. The replacement {@link
|
||||
* #newFactory(java.lang.String, java.lang.ClassLoader)}
|
||||
* method defines no changes in behavior.
|
||||
*/
|
||||
public static XMLEventFactory newInstance(String factoryId,
|
||||
ClassLoader classLoader)
|
||||
throws FactoryConfigurationError {
|
||||
//do not fallback if given classloader can't find the class, throw exception
|
||||
return FactoryFinder.find(XMLEventFactory.class, factoryId, classLoader, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new instance of the factory.
|
||||
* If the classLoader argument is null, then the ContextClassLoader is used.
|
||||
* <p>
|
||||
* This method uses the following ordered lookup procedure to determine
|
||||
* the XMLEventFactory implementation class to load:
|
||||
* </p>
|
||||
* <ul>
|
||||
* <li>
|
||||
* Use the value of the system property identified by {@code factoryId}.
|
||||
* </li>
|
||||
* <li>
|
||||
* Use the properties file "lib/stax.properties" in the JRE directory.
|
||||
* This configuration file is in standard java.util.Properties format
|
||||
* and contains the fully qualified name of the implementation class
|
||||
* with the key being the given {@code factoryId}.
|
||||
* </li>
|
||||
* <li>
|
||||
* If {@code factoryId} is "javax.xml.stream.XMLEventFactory",
|
||||
* use the service-provider loading facilities, defined by the
|
||||
* {@link java.util.ServiceLoader} class, to attempt to {@linkplain
|
||||
* java.util.ServiceLoader#load(java.lang.Class, java.lang.ClassLoader) locate and load}
|
||||
* an implementation of the service using the specified {@code ClassLoader}.
|
||||
* If {@code classLoader} is null, the {@linkplain
|
||||
* java.util.ServiceLoader#load(java.lang.Class) default loading mechanism} will apply:
|
||||
* That is, 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, throws a {@link FactoryConfigurationError}.
|
||||
* </li>
|
||||
* </ul>
|
||||
*
|
||||
* <p>
|
||||
* Note that this is a new method that replaces the deprecated
|
||||
* {@link #newInstance(java.lang.String, java.lang.ClassLoader)
|
||||
* newInstance(String factoryId, ClassLoader classLoader)} method.
|
||||
* No changes in behavior are defined by this replacement method relative
|
||||
* to the deprecated method.
|
||||
* </p>
|
||||
*
|
||||
* @apiNote The parameter factoryId defined here is inconsistent with that
|
||||
* of other JAXP factories where the first parameter is fully qualified
|
||||
* factory class name that provides implementation of the factory.
|
||||
*
|
||||
* @param factoryId Name of the factory to find, same as
|
||||
* a property name
|
||||
* @param classLoader classLoader to use
|
||||
* @return the factory implementation
|
||||
* @throws FactoryConfigurationError in case of {@linkplain
|
||||
* java.util.ServiceConfigurationError service configuration error} or if
|
||||
* the implementation is not available or cannot be instantiated.
|
||||
*/
|
||||
public static XMLEventFactory newFactory(String factoryId,
|
||||
ClassLoader classLoader)
|
||||
throws FactoryConfigurationError {
|
||||
//do not fallback if given classloader can't find the class, throw exception
|
||||
return FactoryFinder.find(XMLEventFactory.class, factoryId, classLoader, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method allows setting of the Location on each event that
|
||||
* is created by this factory. The values are copied by value into
|
||||
* the events created by this factory. To reset the location
|
||||
* information set the location to null.
|
||||
* @param location the location to set on each event created
|
||||
*/
|
||||
public abstract void setLocation(Location location);
|
||||
|
||||
/**
|
||||
* Create a new Attribute
|
||||
* @param prefix the prefix of this attribute, may not be null
|
||||
* @param namespaceURI the attribute value is set to this value, may not be null
|
||||
* @param localName the local name of the XML name of the attribute, localName cannot be null
|
||||
* @param value the attribute value to set, may not be null
|
||||
* @return the Attribute with specified values
|
||||
*/
|
||||
public abstract Attribute createAttribute(String prefix, String namespaceURI, String localName, String value);
|
||||
|
||||
/**
|
||||
* Create a new Attribute
|
||||
* @param localName the local name of the XML name of the attribute, localName cannot be null
|
||||
* @param value the attribute value to set, may not be null
|
||||
* @return the Attribute with specified values
|
||||
*/
|
||||
public abstract Attribute createAttribute(String localName, String value);
|
||||
|
||||
/**
|
||||
* Create a new Attribute
|
||||
* @param name the qualified name of the attribute, may not be null
|
||||
* @param value the attribute value to set, may not be null
|
||||
* @return the Attribute with specified values
|
||||
*/
|
||||
public abstract Attribute createAttribute(QName name, String value);
|
||||
|
||||
/**
|
||||
* Create a new default Namespace
|
||||
* @param namespaceURI the default namespace uri
|
||||
* @return the Namespace with the specified value
|
||||
*/
|
||||
public abstract Namespace createNamespace(String namespaceURI);
|
||||
|
||||
/**
|
||||
* Create a new Namespace
|
||||
* @param prefix the prefix of this namespace, may not be null
|
||||
* @param namespaceUri the attribute value is set to this value, may not be null
|
||||
* @return the Namespace with the specified values
|
||||
*/
|
||||
public abstract Namespace createNamespace(String prefix, String namespaceUri);
|
||||
|
||||
/**
|
||||
* Create a new StartElement. Namespaces can be added to this StartElement
|
||||
* by passing in an Iterator that walks over a set of Namespace interfaces.
|
||||
* Attributes can be added to this StartElement by passing an iterator
|
||||
* that walks over a set of Attribute interfaces.
|
||||
*
|
||||
* @param name the qualified name of the attribute, may not be null
|
||||
* @param attributes an optional unordered set of objects that
|
||||
* implement Attribute to add to the new StartElement, may be null
|
||||
* @param namespaces an optional unordered set of objects that
|
||||
* implement Namespace to add to the new StartElement, may be null
|
||||
* @return an instance of the requested StartElement
|
||||
*/
|
||||
public abstract StartElement createStartElement(QName name,
|
||||
Iterator attributes,
|
||||
Iterator namespaces);
|
||||
|
||||
/**
|
||||
* Create a new StartElement. This defaults the NamespaceContext to
|
||||
* an empty NamespaceContext. Querying this event for its namespaces or
|
||||
* attributes will result in an empty iterator being returned.
|
||||
*
|
||||
* @param namespaceUri the uri of the QName of the new StartElement
|
||||
* @param localName the local name of the QName of the new StartElement
|
||||
* @param prefix the prefix of the QName of the new StartElement
|
||||
* @return an instance of the requested StartElement
|
||||
*/
|
||||
public abstract StartElement createStartElement(String prefix,
|
||||
String namespaceUri,
|
||||
String localName);
|
||||
/**
|
||||
* Create a new StartElement. Namespaces can be added to this StartElement
|
||||
* by passing in an Iterator that walks over a set of Namespace interfaces.
|
||||
* Attributes can be added to this StartElement by passing an iterator
|
||||
* that walks over a set of Attribute interfaces.
|
||||
*
|
||||
* @param namespaceUri the uri of the QName of the new StartElement
|
||||
* @param localName the local name of the QName of the new StartElement
|
||||
* @param prefix the prefix of the QName of the new StartElement
|
||||
* @param attributes an unordered set of objects that implement
|
||||
* Attribute to add to the new StartElement
|
||||
* @param namespaces an unordered set of objects that implement
|
||||
* Namespace to add to the new StartElement
|
||||
* @return an instance of the requested StartElement
|
||||
*/
|
||||
public abstract StartElement createStartElement(String prefix,
|
||||
String namespaceUri,
|
||||
String localName,
|
||||
Iterator attributes,
|
||||
Iterator namespaces
|
||||
);
|
||||
/**
|
||||
* Create a new StartElement. Namespaces can be added to this StartElement
|
||||
* by passing in an Iterator that walks over a set of Namespace interfaces.
|
||||
* Attributes can be added to this StartElement by passing an iterator
|
||||
* that walks over a set of Attribute interfaces.
|
||||
*
|
||||
* @param namespaceUri the uri of the QName of the new StartElement
|
||||
* @param localName the local name of the QName of the new StartElement
|
||||
* @param prefix the prefix of the QName of the new StartElement
|
||||
* @param attributes an unordered set of objects that implement
|
||||
* Attribute to add to the new StartElement, may be null
|
||||
* @param namespaces an unordered set of objects that implement
|
||||
* Namespace to add to the new StartElement, may be null
|
||||
* @param context the namespace context of this element
|
||||
* @return an instance of the requested StartElement
|
||||
*/
|
||||
public abstract StartElement createStartElement(String prefix,
|
||||
String namespaceUri,
|
||||
String localName,
|
||||
Iterator attributes,
|
||||
Iterator namespaces,
|
||||
NamespaceContext context
|
||||
);
|
||||
|
||||
/**
|
||||
* Create a new EndElement
|
||||
* @param name the qualified name of the EndElement
|
||||
* @param namespaces an optional unordered set of objects that
|
||||
* implement Namespace that have gone out of scope, may be null
|
||||
* @return an instance of the requested EndElement
|
||||
*/
|
||||
public abstract EndElement createEndElement(QName name,
|
||||
Iterator namespaces);
|
||||
|
||||
/**
|
||||
* Create a new EndElement
|
||||
* @param namespaceUri the uri of the QName of the new StartElement
|
||||
* @param localName the local name of the QName of the new StartElement
|
||||
* @param prefix the prefix of the QName of the new StartElement
|
||||
* @return an instance of the requested EndElement
|
||||
*/
|
||||
public abstract EndElement createEndElement(String prefix,
|
||||
String namespaceUri,
|
||||
String localName);
|
||||
/**
|
||||
* Create a new EndElement
|
||||
* @param namespaceUri the uri of the QName of the new StartElement
|
||||
* @param localName the local name of the QName of the new StartElement
|
||||
* @param prefix the prefix of the QName of the new StartElement
|
||||
* @param namespaces an unordered set of objects that implement
|
||||
* Namespace that have gone out of scope, may be null
|
||||
* @return an instance of the requested EndElement
|
||||
*/
|
||||
public abstract EndElement createEndElement(String prefix,
|
||||
String namespaceUri,
|
||||
String localName,
|
||||
Iterator namespaces);
|
||||
|
||||
/**
|
||||
* Create a Characters event, this method does not check if the content
|
||||
* is all whitespace. To create a space event use #createSpace(String)
|
||||
* @param content the string to create
|
||||
* @return a Characters event
|
||||
*/
|
||||
public abstract Characters createCharacters(String content);
|
||||
|
||||
/**
|
||||
* Create a Characters event with the CData flag set to true
|
||||
* @param content the string to create
|
||||
* @return a Characters event
|
||||
*/
|
||||
public abstract Characters createCData(String content);
|
||||
|
||||
/**
|
||||
* Create a Characters event with the isSpace flag set to true
|
||||
* @param content the content of the space to create
|
||||
* @return a Characters event
|
||||
*/
|
||||
public abstract Characters createSpace(String content);
|
||||
/**
|
||||
* Create an ignorable space
|
||||
* @param content the space to create
|
||||
* @return a Characters event
|
||||
*/
|
||||
public abstract Characters createIgnorableSpace(String content);
|
||||
|
||||
/**
|
||||
* Creates a new instance of a StartDocument event
|
||||
* @return a StartDocument event
|
||||
*/
|
||||
public abstract StartDocument createStartDocument();
|
||||
|
||||
/**
|
||||
* Creates a new instance of a StartDocument event
|
||||
*
|
||||
* @param encoding the encoding style
|
||||
* @param version the XML version
|
||||
* @param standalone the status of standalone may be set to "true" or "false"
|
||||
* @return a StartDocument event
|
||||
*/
|
||||
public abstract StartDocument createStartDocument(String encoding,
|
||||
String version,
|
||||
boolean standalone);
|
||||
|
||||
/**
|
||||
* Creates a new instance of a StartDocument event
|
||||
*
|
||||
* @param encoding the encoding style
|
||||
* @param version the XML version
|
||||
* @return a StartDocument event
|
||||
*/
|
||||
public abstract StartDocument createStartDocument(String encoding,
|
||||
String version);
|
||||
|
||||
/**
|
||||
* Creates a new instance of a StartDocument event
|
||||
*
|
||||
* @param encoding the encoding style
|
||||
* @return a StartDocument event
|
||||
*/
|
||||
public abstract StartDocument createStartDocument(String encoding);
|
||||
|
||||
/**
|
||||
* Creates a new instance of an EndDocument event
|
||||
* @return an EndDocument event
|
||||
*/
|
||||
public abstract EndDocument createEndDocument();
|
||||
|
||||
/** Creates a new instance of a EntityReference event
|
||||
*
|
||||
* @param name The name of the reference
|
||||
* @param declaration the declaration for the event
|
||||
* @return an EntityReference event
|
||||
*/
|
||||
public abstract EntityReference createEntityReference(String name,
|
||||
EntityDeclaration declaration);
|
||||
/**
|
||||
* Create a comment
|
||||
* @param text The text of the comment
|
||||
* a Comment event
|
||||
*/
|
||||
public abstract Comment createComment(String text);
|
||||
|
||||
/**
|
||||
* Create a processing instruction
|
||||
* @param target The target of the processing instruction
|
||||
* @param data The text of the processing instruction
|
||||
* @return a ProcessingInstruction event
|
||||
*/
|
||||
public abstract ProcessingInstruction createProcessingInstruction(String target,
|
||||
String data);
|
||||
|
||||
/**
|
||||
* Create a document type definition event
|
||||
* This string contains the entire document type declaration that matches
|
||||
* the doctypedecl in the XML 1.0 specification
|
||||
* @param dtd the text of the document type definition
|
||||
* @return a DTD event
|
||||
*/
|
||||
public abstract DTD createDTD(String dtd);
|
||||
}
|
|
@ -0,0 +1,106 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 by Oracle Corporation. All Rights Reserved.
|
||||
*/
|
||||
|
||||
package javax.xml.stream;
|
||||
|
||||
import javax.xml.stream.events.XMLEvent;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
*
|
||||
* This is the top level interface for parsing XML Events. It provides
|
||||
* the ability to peek at the next event and returns configuration
|
||||
* information through the property interface.
|
||||
*
|
||||
* @version 1.0
|
||||
* @author Copyright (c) 2009 by Oracle Corporation. All Rights Reserved.
|
||||
* @see XMLInputFactory
|
||||
* @see XMLEventWriter
|
||||
* @since 1.6
|
||||
*/
|
||||
public interface XMLEventReader extends Iterator {
|
||||
/**
|
||||
* Get the next XMLEvent
|
||||
* @see XMLEvent
|
||||
* @throws XMLStreamException if there is an error with the underlying XML.
|
||||
* @throws NoSuchElementException iteration has no more elements.
|
||||
*/
|
||||
public XMLEvent nextEvent() throws XMLStreamException;
|
||||
|
||||
/**
|
||||
* Check if there are more events.
|
||||
* Returns true if there are more events and false otherwise.
|
||||
* @return true if the event reader has more events, false otherwise
|
||||
*/
|
||||
public boolean hasNext();
|
||||
|
||||
/**
|
||||
* Check the next XMLEvent without reading it from the stream.
|
||||
* Returns null if the stream is at EOF or has no more XMLEvents.
|
||||
* A call to peek() will be equal to the next return of next().
|
||||
* @see XMLEvent
|
||||
* @throws XMLStreamException
|
||||
*/
|
||||
public XMLEvent peek() throws XMLStreamException;
|
||||
|
||||
/**
|
||||
* Reads the content of a text-only element. Precondition:
|
||||
* the current event is START_ELEMENT. Postcondition:
|
||||
* The current event is the corresponding END_ELEMENT.
|
||||
* @throws XMLStreamException if the current event is not a START_ELEMENT
|
||||
* or if a non text element is encountered
|
||||
*/
|
||||
public String getElementText() throws XMLStreamException;
|
||||
|
||||
/**
|
||||
* Skips any insignificant space events until a START_ELEMENT or
|
||||
* END_ELEMENT is reached. If anything other than space characters are
|
||||
* encountered, an exception is thrown. This method should
|
||||
* be used when processing element-only content because
|
||||
* the parser is not able to recognize ignorable whitespace if
|
||||
* the DTD is missing or not interpreted.
|
||||
* @throws XMLStreamException if anything other than space characters are encountered
|
||||
*/
|
||||
public XMLEvent nextTag() throws XMLStreamException;
|
||||
|
||||
/**
|
||||
* Get the value of a feature/property from the underlying implementation
|
||||
* @param name The name of the property
|
||||
* @return The value of the property
|
||||
* @throws IllegalArgumentException if the property is not supported
|
||||
*/
|
||||
public Object getProperty(java.lang.String name) throws java.lang.IllegalArgumentException;
|
||||
|
||||
/**
|
||||
* Frees any resources associated with this Reader. This method does not close the
|
||||
* underlying input source.
|
||||
* @throws XMLStreamException if there are errors freeing associated resources
|
||||
*/
|
||||
public void close() throws XMLStreamException;
|
||||
}
|
|
@ -0,0 +1,256 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 by Oracle Corporation. All Rights Reserved.
|
||||
*/
|
||||
|
||||
package javax.xml.stream;
|
||||
|
||||
import javax.xml.stream.events.*;
|
||||
import javax.xml.stream.util.XMLEventConsumer;
|
||||
import javax.xml.namespace.NamespaceContext;
|
||||
|
||||
/**
|
||||
*
|
||||
* This is the top level interface for writing XML documents.
|
||||
*
|
||||
* Instances of this interface are not required to validate the
|
||||
* form of the XML.
|
||||
*
|
||||
* @version 1.0
|
||||
* @author Copyright (c) 2009 by Oracle Corporation. All Rights Reserved.
|
||||
* @see XMLEventReader
|
||||
* @see javax.xml.stream.events.XMLEvent
|
||||
* @see javax.xml.stream.events.Characters
|
||||
* @see javax.xml.stream.events.ProcessingInstruction
|
||||
* @see javax.xml.stream.events.StartElement
|
||||
* @see javax.xml.stream.events.EndElement
|
||||
* @since 1.6
|
||||
*/
|
||||
public interface XMLEventWriter extends XMLEventConsumer {
|
||||
|
||||
/**
|
||||
* Writes any cached events to the underlying output mechanism
|
||||
* @throws XMLStreamException
|
||||
*/
|
||||
public void flush() throws XMLStreamException;
|
||||
|
||||
/**
|
||||
* Frees any resources associated with this stream
|
||||
* @throws XMLStreamException
|
||||
*/
|
||||
public void close() throws XMLStreamException;
|
||||
|
||||
/**
|
||||
* Add an event to the output stream
|
||||
* Adding a START_ELEMENT will open a new namespace scope that
|
||||
* will be closed when the corresponding END_ELEMENT is written.
|
||||
* <table border="2" rules="all" cellpadding="4">
|
||||
* <thead>
|
||||
* <tr>
|
||||
* <th align="center" colspan="2">
|
||||
* Required and optional fields for events added to the writer
|
||||
* </th>
|
||||
* </tr>
|
||||
* </thead>
|
||||
* <tbody>
|
||||
* <tr>
|
||||
* <th>Event Type</th>
|
||||
* <th>Required Fields</th>
|
||||
* <th>Optional Fields</th>
|
||||
* <th>Required Behavior</th>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td> START_ELEMENT </td>
|
||||
* <td> QName name </td>
|
||||
* <td> namespaces , attributes </td>
|
||||
* <td> A START_ELEMENT will be written by writing the name,
|
||||
* namespaces, and attributes of the event in XML 1.0 valid
|
||||
* syntax for START_ELEMENTs.
|
||||
* The name is written by looking up the prefix for
|
||||
* the namespace uri. The writer can be configured to
|
||||
* respect prefixes of QNames. If the writer is respecting
|
||||
* prefixes it must use the prefix set on the QName. The
|
||||
* default behavior is to lookup the value for the prefix
|
||||
* on the EventWriter's internal namespace context.
|
||||
* Each attribute (if any)
|
||||
* is written using the behavior specified in the attribute
|
||||
* section of this table. Each namespace (if any) is written
|
||||
* using the behavior specified in the namespace section of this
|
||||
* table.
|
||||
* </td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td> END_ELEMENT </td>
|
||||
* <td> Qname name </td>
|
||||
* <td> None </td>
|
||||
* <td> A well formed END_ELEMENT tag is written.
|
||||
* The name is written by looking up the prefix for
|
||||
* the namespace uri. The writer can be configured to
|
||||
* respect prefixes of QNames. If the writer is respecting
|
||||
* prefixes it must use the prefix set on the QName. The
|
||||
* default behavior is to lookup the value for the prefix
|
||||
* on the EventWriter's internal namespace context.
|
||||
* If the END_ELEMENT name does not match the START_ELEMENT
|
||||
* name an XMLStreamException is thrown.
|
||||
* </td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td> ATTRIBUTE </td>
|
||||
* <td> QName name , String value </td>
|
||||
* <td> QName type </td>
|
||||
* <td> An attribute is written using the same algorithm
|
||||
* to find the lexical form as used in START_ELEMENT.
|
||||
* The default is to use double quotes to wrap attribute
|
||||
* values and to escape any double quotes found in the
|
||||
* value. The type value is ignored.
|
||||
* </td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td> NAMESPACE </td>
|
||||
* <td> String prefix, String namespaceURI,
|
||||
* boolean isDefaultNamespaceDeclaration
|
||||
* </td>
|
||||
* <td> None </td>
|
||||
* <td> A namespace declaration is written. If the
|
||||
* namespace is a default namespace declaration
|
||||
* (isDefault is true) then xmlns="$namespaceURI"
|
||||
* is written and the prefix is optional. If
|
||||
* isDefault is false, the prefix must be declared
|
||||
* and the writer must prepend xmlns to the prefix
|
||||
* and write out a standard prefix declaration.
|
||||
* </td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td> PROCESSING_INSTRUCTION </td>
|
||||
* <td> None</td>
|
||||
* <td> String target, String data</td>
|
||||
* <td> The data does not need to be present and may be
|
||||
* null. Target is required and many not be null.
|
||||
* The writer
|
||||
* will write data section
|
||||
* directly after the target,
|
||||
* enclosed in appropriate XML 1.0 syntax
|
||||
* </td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td> COMMENT </td>
|
||||
* <td> None </td>
|
||||
* <td> String comment </td>
|
||||
* <td> If the comment is present (not null) it is written, otherwise an
|
||||
* an empty comment is written
|
||||
* </td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td> START_DOCUMENT </td>
|
||||
* <td> None </td>
|
||||
* <td> String encoding , boolean standalone, String version </td>
|
||||
* <td> A START_DOCUMENT event is not required to be written to the
|
||||
* stream. If present the attributes are written inside
|
||||
* the appropriate XML declaration syntax
|
||||
* </td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td> END_DOCUMENT </td>
|
||||
* <td> None </td>
|
||||
* <td> None </td>
|
||||
* <td> Nothing is written to the output </td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td> DTD </td>
|
||||
* <td> String DocumentTypeDefinition </td>
|
||||
* <td> None </td>
|
||||
* <td> The DocumentTypeDefinition is written to the output </td>
|
||||
* </tr>
|
||||
* </tbody>
|
||||
* </table>
|
||||
* @param event the event to be added
|
||||
* @throws XMLStreamException
|
||||
*/
|
||||
public void add(XMLEvent event) throws XMLStreamException;
|
||||
|
||||
/**
|
||||
* Adds an entire stream to an output stream,
|
||||
* calls next() on the inputStream argument until hasNext() returns false
|
||||
* This should be treated as a convenience method that will
|
||||
* perform the following loop over all the events in an
|
||||
* event reader and call add on each event.
|
||||
*
|
||||
* @param reader the event stream to add to the output
|
||||
* @throws XMLStreamException
|
||||
*/
|
||||
|
||||
public void add(XMLEventReader reader) throws XMLStreamException;
|
||||
|
||||
/**
|
||||
* Gets the prefix the uri is bound to
|
||||
* @param uri the uri to look up
|
||||
* @throws XMLStreamException
|
||||
*/
|
||||
public String getPrefix(String uri) throws XMLStreamException;
|
||||
|
||||
/**
|
||||
* Sets the prefix the uri is bound to. This prefix is bound
|
||||
* in the scope of the current START_ELEMENT / END_ELEMENT pair.
|
||||
* If this method is called before a START_ELEMENT has been written
|
||||
* the prefix is bound in the root scope.
|
||||
* @param prefix the prefix to bind to the uri
|
||||
* @param uri the uri to bind to the prefix
|
||||
* @throws XMLStreamException
|
||||
*/
|
||||
public void setPrefix(String prefix, String uri) throws XMLStreamException;
|
||||
|
||||
/**
|
||||
* Binds a URI to the default namespace
|
||||
* This URI is bound
|
||||
* in the scope of the current START_ELEMENT / END_ELEMENT pair.
|
||||
* If this method is called before a START_ELEMENT has been written
|
||||
* the uri is bound in the root scope.
|
||||
* @param uri the uri to bind to the default namespace
|
||||
* @throws XMLStreamException
|
||||
*/
|
||||
public void setDefaultNamespace(String uri) throws XMLStreamException;
|
||||
|
||||
/**
|
||||
* Sets the current namespace context for prefix and uri bindings.
|
||||
* This context becomes the root namespace context for writing and
|
||||
* will replace the current root namespace context. Subsequent calls
|
||||
* to setPrefix and setDefaultNamespace will bind namespaces using
|
||||
* the context passed to the method as the root context for resolving
|
||||
* namespaces.
|
||||
* @param context the namespace context to use for this writer
|
||||
* @throws XMLStreamException
|
||||
*/
|
||||
public void setNamespaceContext(NamespaceContext context)
|
||||
throws XMLStreamException;
|
||||
|
||||
/**
|
||||
* Returns the current namespace context.
|
||||
* @return the current namespace context
|
||||
*/
|
||||
public NamespaceContext getNamespaceContext();
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,510 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009, 2013, by Oracle Corporation. All Rights Reserved.
|
||||
*/
|
||||
|
||||
package javax.xml.stream;
|
||||
|
||||
import javax.xml.stream.util.XMLEventAllocator;
|
||||
import javax.xml.transform.Source;
|
||||
|
||||
/**
|
||||
* Defines an abstract implementation of a factory for getting streams.
|
||||
*
|
||||
* The following table defines the standard properties of this specification.
|
||||
* Each property varies in the level of support required by each implementation.
|
||||
* The level of support required is described in the 'Required' column.
|
||||
*
|
||||
* <table border="2" rules="all" cellpadding="4">
|
||||
* <thead>
|
||||
* <tr>
|
||||
* <th align="center" colspan="5">
|
||||
* Configuration parameters
|
||||
* </th>
|
||||
* </tr>
|
||||
* </thead>
|
||||
* <tbody>
|
||||
* <tr>
|
||||
* <th>Property Name</th>
|
||||
* <th>Behavior</th>
|
||||
* <th>Return type</th>
|
||||
* <th>Default Value</th>
|
||||
* <th>Required</th>
|
||||
* </tr>
|
||||
* <tr><td>javax.xml.stream.isValidating</td><td>Turns on/off implementation specific DTD validation</td><td>Boolean</td><td>False</td><td>No</td></tr>
|
||||
* <tr><td>javax.xml.stream.isNamespaceAware</td><td>Turns on/off namespace processing for XML 1.0 support</td><td>Boolean</td><td>True</td><td>True (required) / False (optional)</td></tr>
|
||||
* <tr><td>javax.xml.stream.isCoalescing</td><td>Requires the processor to coalesce adjacent character data</td><td>Boolean</td><td>False</td><td>Yes</td></tr>
|
||||
* <tr><td>javax.xml.stream.isReplacingEntityReferences</td><td>replace internal entity references with their replacement text and report them as characters</td><td>Boolean</td><td>True</td><td>Yes</td></tr>
|
||||
*<tr><td>javax.xml.stream.isSupportingExternalEntities</td><td>Resolve external parsed entities</td><td>Boolean</td><td>Unspecified</td><td>Yes</td></tr>
|
||||
*<tr><td>javax.xml.stream.supportDTD</td><td>Use this property to request processors that do not support DTDs</td><td>Boolean</td><td>True</td><td>Yes</td></tr>
|
||||
*<tr><td>javax.xml.stream.reporter</td><td>sets/gets the impl of the XMLReporter </td><td>javax.xml.stream.XMLReporter</td><td>Null</td><td>Yes</td></tr>
|
||||
*<tr><td>javax.xml.stream.resolver</td><td>sets/gets the impl of the XMLResolver interface</td><td>javax.xml.stream.XMLResolver</td><td>Null</td><td>Yes</td></tr>
|
||||
*<tr><td>javax.xml.stream.allocator</td><td>sets/gets the impl of the XMLEventAllocator interface</td><td>javax.xml.stream.util.XMLEventAllocator</td><td>Null</td><td>Yes</td></tr>
|
||||
* </tbody>
|
||||
* </table>
|
||||
*
|
||||
*
|
||||
* @version 1.2
|
||||
* @author Copyright (c) 2009 by Oracle Corporation. All Rights Reserved.
|
||||
* @see XMLOutputFactory
|
||||
* @see XMLEventReader
|
||||
* @see XMLStreamReader
|
||||
* @see EventFilter
|
||||
* @see XMLReporter
|
||||
* @see XMLResolver
|
||||
* @see javax.xml.stream.util.XMLEventAllocator
|
||||
* @since 1.6
|
||||
*/
|
||||
|
||||
public abstract class XMLInputFactory {
|
||||
/**
|
||||
* The property used to turn on/off namespace support,
|
||||
* this is to support XML 1.0 documents,
|
||||
* only the true setting must be supported
|
||||
*/
|
||||
public static final String IS_NAMESPACE_AWARE=
|
||||
"javax.xml.stream.isNamespaceAware";
|
||||
|
||||
/**
|
||||
* The property used to turn on/off implementation specific validation
|
||||
*/
|
||||
public static final String IS_VALIDATING=
|
||||
"javax.xml.stream.isValidating";
|
||||
|
||||
/**
|
||||
* The property that requires the parser to coalesce adjacent character data sections
|
||||
*/
|
||||
public static final String IS_COALESCING=
|
||||
"javax.xml.stream.isCoalescing";
|
||||
|
||||
/**
|
||||
* Requires the parser to replace internal
|
||||
* entity references with their replacement
|
||||
* text and report them as characters
|
||||
*/
|
||||
public static final String IS_REPLACING_ENTITY_REFERENCES=
|
||||
"javax.xml.stream.isReplacingEntityReferences";
|
||||
|
||||
/**
|
||||
* The property that requires the parser to resolve external parsed entities
|
||||
*/
|
||||
public static final String IS_SUPPORTING_EXTERNAL_ENTITIES=
|
||||
"javax.xml.stream.isSupportingExternalEntities";
|
||||
|
||||
/**
|
||||
* The property that requires the parser to support DTDs
|
||||
*/
|
||||
public static final String SUPPORT_DTD=
|
||||
"javax.xml.stream.supportDTD";
|
||||
|
||||
/**
|
||||
* The property used to
|
||||
* set/get the implementation of the XMLReporter interface
|
||||
*/
|
||||
public static final String REPORTER=
|
||||
"javax.xml.stream.reporter";
|
||||
|
||||
/**
|
||||
* The property used to set/get the implementation of the XMLResolver
|
||||
*/
|
||||
public static final String RESOLVER=
|
||||
"javax.xml.stream.resolver";
|
||||
|
||||
/**
|
||||
* The property used to set/get the implementation of the allocator
|
||||
*/
|
||||
public static final String ALLOCATOR=
|
||||
"javax.xml.stream.allocator";
|
||||
|
||||
static final String DEFAULIMPL = "com.sun.xml.internal.stream.XMLInputFactoryImpl";
|
||||
|
||||
protected XMLInputFactory(){}
|
||||
|
||||
/**
|
||||
* Creates a new instance of the factory in exactly the same manner as the
|
||||
* {@link #newFactory()} method.
|
||||
* @throws FactoryConfigurationError if an instance of this factory cannot be loaded
|
||||
*/
|
||||
public static XMLInputFactory newInstance()
|
||||
throws FactoryConfigurationError
|
||||
{
|
||||
return FactoryFinder.find(XMLInputFactory.class, DEFAULIMPL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new instance of the factory.
|
||||
* <p>
|
||||
* This static method creates a new factory instance.
|
||||
* This method uses the following ordered lookup procedure to determine
|
||||
* the XMLInputFactory implementation class to load:
|
||||
* </p>
|
||||
* <ul>
|
||||
* <li>
|
||||
* Use the javax.xml.stream.XMLInputFactory system property.
|
||||
* </li>
|
||||
* <li>
|
||||
* Use the properties file "lib/stax.properties" in the JRE directory.
|
||||
* This configuration file is in standard java.util.Properties format
|
||||
* and contains the fully qualified name of the implementation class
|
||||
* with the key being the system property defined above.
|
||||
* </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 XMLInputFactory it
|
||||
* can use the factory to configure and obtain stream instances.
|
||||
* </p>
|
||||
* <p>
|
||||
* Note that this is a new method that replaces the deprecated newInstance() method.
|
||||
* No changes in behavior are defined by this replacement method relative to
|
||||
* the deprecated method.
|
||||
* </p>
|
||||
* @throws FactoryConfigurationError in case of {@linkplain
|
||||
* java.util.ServiceConfigurationError service configuration error} or if
|
||||
* the implementation is not available or cannot be instantiated.
|
||||
*/
|
||||
public static XMLInputFactory newFactory()
|
||||
throws FactoryConfigurationError
|
||||
{
|
||||
return FactoryFinder.find(XMLInputFactory.class, DEFAULIMPL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new instance of the factory
|
||||
*
|
||||
* @param factoryId Name of the factory to find, same as
|
||||
* a property name
|
||||
* @param classLoader classLoader to use
|
||||
* @return the factory implementation
|
||||
* @throws FactoryConfigurationError if an instance of this factory cannot be loaded
|
||||
*
|
||||
* @deprecated This method has been deprecated to maintain API consistency.
|
||||
* All newInstance methods have been replaced with corresponding
|
||||
* newFactory methods. The replacement {@link
|
||||
* #newFactory(java.lang.String, java.lang.ClassLoader)} method
|
||||
* defines no changes in behavior.
|
||||
*/
|
||||
public static XMLInputFactory newInstance(String factoryId,
|
||||
ClassLoader classLoader)
|
||||
throws FactoryConfigurationError {
|
||||
//do not fallback if given classloader can't find the class, throw exception
|
||||
return FactoryFinder.find(XMLInputFactory.class, factoryId, classLoader, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new instance of the factory.
|
||||
* If the classLoader argument is null, then the ContextClassLoader is used.
|
||||
* <p>
|
||||
* This method uses the following ordered lookup procedure to determine
|
||||
* the XMLInputFactory implementation class to load:
|
||||
* </p>
|
||||
* <ul>
|
||||
* <li>
|
||||
* Use the value of the system property identified by {@code factoryId}.
|
||||
* </li>
|
||||
* <li>
|
||||
* Use the properties file "lib/stax.properties" in the JRE directory.
|
||||
* This configuration file is in standard java.util.Properties format
|
||||
* and contains the fully qualified name of the implementation class
|
||||
* with the key being the given {@code factoryId}.
|
||||
* </li>
|
||||
* <li>
|
||||
* If {@code factoryId} is "javax.xml.stream.XMLInputFactory",
|
||||
* use the service-provider loading facilities, defined by the
|
||||
* {@link java.util.ServiceLoader} class, to attempt to {@linkplain
|
||||
* java.util.ServiceLoader#load(java.lang.Class, java.lang.ClassLoader) locate and load}
|
||||
* an implementation of the service using the specified {@code ClassLoader}.
|
||||
* If {@code classLoader} is null, the {@linkplain
|
||||
* java.util.ServiceLoader#load(java.lang.Class) default loading mechanism} will apply:
|
||||
* That is, 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, throws a {@link FactoryConfigurationError}.
|
||||
* </li>
|
||||
* </ul>
|
||||
*
|
||||
* <p>
|
||||
* Note that this is a new method that replaces the deprecated
|
||||
* {@link #newInstance(java.lang.String, java.lang.ClassLoader)
|
||||
* newInstance(String factoryId, ClassLoader classLoader)} method.
|
||||
* No changes in behavior are defined by this replacement method relative
|
||||
* to the deprecated method.
|
||||
* </p>
|
||||
*
|
||||
* @apiNote The parameter factoryId defined here is inconsistent with that
|
||||
* of other JAXP factories where the first parameter is fully qualified
|
||||
* factory class name that provides implementation of the factory.
|
||||
*
|
||||
* @param factoryId Name of the factory to find, same as
|
||||
* a property name
|
||||
* @param classLoader classLoader to use
|
||||
* @return the factory implementation
|
||||
* @throws FactoryConfigurationError in case of {@linkplain
|
||||
* java.util.ServiceConfigurationError service configuration error} or if
|
||||
* the implementation is not available or cannot be instantiated.
|
||||
* @throws FactoryConfigurationError if an instance of this factory cannot be loaded
|
||||
*/
|
||||
public static XMLInputFactory newFactory(String factoryId,
|
||||
ClassLoader classLoader)
|
||||
throws FactoryConfigurationError {
|
||||
//do not fallback if given classloader can't find the class, throw exception
|
||||
return FactoryFinder.find(XMLInputFactory.class, factoryId, classLoader, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new XMLStreamReader from a reader
|
||||
* @param reader the XML data to read from
|
||||
* @throws XMLStreamException
|
||||
*/
|
||||
public abstract XMLStreamReader createXMLStreamReader(java.io.Reader reader)
|
||||
throws XMLStreamException;
|
||||
|
||||
/**
|
||||
* Create a new XMLStreamReader from a JAXP source. This method is optional.
|
||||
* @param source the source to read from
|
||||
* @throws UnsupportedOperationException if this method is not
|
||||
* supported by this XMLInputFactory
|
||||
* @throws XMLStreamException
|
||||
*/
|
||||
public abstract XMLStreamReader createXMLStreamReader(Source source)
|
||||
throws XMLStreamException;
|
||||
|
||||
/**
|
||||
* Create a new XMLStreamReader from a java.io.InputStream
|
||||
* @param stream the InputStream to read from
|
||||
* @throws XMLStreamException
|
||||
*/
|
||||
public abstract XMLStreamReader createXMLStreamReader(java.io.InputStream stream)
|
||||
throws XMLStreamException;
|
||||
|
||||
/**
|
||||
* Create a new XMLStreamReader from a java.io.InputStream
|
||||
* @param stream the InputStream to read from
|
||||
* @param encoding the character encoding of the stream
|
||||
* @throws XMLStreamException
|
||||
*/
|
||||
public abstract XMLStreamReader createXMLStreamReader(java.io.InputStream stream, String encoding)
|
||||
throws XMLStreamException;
|
||||
|
||||
/**
|
||||
* Create a new XMLStreamReader from a java.io.InputStream
|
||||
* @param systemId the system ID of the stream
|
||||
* @param stream the InputStream to read from
|
||||
*/
|
||||
public abstract XMLStreamReader createXMLStreamReader(String systemId, java.io.InputStream stream)
|
||||
throws XMLStreamException;
|
||||
|
||||
/**
|
||||
* Create a new XMLStreamReader from a java.io.InputStream
|
||||
* @param systemId the system ID of the stream
|
||||
* @param reader the InputStream to read from
|
||||
*/
|
||||
public abstract XMLStreamReader createXMLStreamReader(String systemId, java.io.Reader reader)
|
||||
throws XMLStreamException;
|
||||
|
||||
/**
|
||||
* Create a new XMLEventReader from a reader
|
||||
* @param reader the XML data to read from
|
||||
* @throws XMLStreamException
|
||||
*/
|
||||
public abstract XMLEventReader createXMLEventReader(java.io.Reader reader)
|
||||
throws XMLStreamException;
|
||||
|
||||
/**
|
||||
* Create a new XMLEventReader from a reader
|
||||
* @param systemId the system ID of the input
|
||||
* @param reader the XML data to read from
|
||||
* @throws XMLStreamException
|
||||
*/
|
||||
public abstract XMLEventReader createXMLEventReader(String systemId, java.io.Reader reader)
|
||||
throws XMLStreamException;
|
||||
|
||||
/**
|
||||
* Create a new XMLEventReader from an XMLStreamReader. After being used
|
||||
* to construct the XMLEventReader instance returned from this method
|
||||
* the XMLStreamReader must not be used.
|
||||
* @param reader the XMLStreamReader to read from (may not be modified)
|
||||
* @return a new XMLEventReader
|
||||
* @throws XMLStreamException
|
||||
*/
|
||||
public abstract XMLEventReader createXMLEventReader(XMLStreamReader reader)
|
||||
throws XMLStreamException;
|
||||
|
||||
/**
|
||||
* Create a new XMLEventReader from a JAXP source.
|
||||
* Support of this method is optional.
|
||||
* @param source the source to read from
|
||||
* @throws UnsupportedOperationException if this method is not
|
||||
* supported by this XMLInputFactory
|
||||
*/
|
||||
public abstract XMLEventReader createXMLEventReader(Source source)
|
||||
throws XMLStreamException;
|
||||
|
||||
/**
|
||||
* Create a new XMLEventReader from a java.io.InputStream
|
||||
* @param stream the InputStream to read from
|
||||
* @throws XMLStreamException
|
||||
*/
|
||||
public abstract XMLEventReader createXMLEventReader(java.io.InputStream stream)
|
||||
throws XMLStreamException;
|
||||
|
||||
/**
|
||||
* Create a new XMLEventReader from a java.io.InputStream
|
||||
* @param stream the InputStream to read from
|
||||
* @param encoding the character encoding of the stream
|
||||
* @throws XMLStreamException
|
||||
*/
|
||||
public abstract XMLEventReader createXMLEventReader(java.io.InputStream stream, String encoding)
|
||||
throws XMLStreamException;
|
||||
|
||||
/**
|
||||
* Create a new XMLEventReader from a java.io.InputStream
|
||||
* @param systemId the system ID of the stream
|
||||
* @param stream the InputStream to read from
|
||||
* @throws XMLStreamException
|
||||
*/
|
||||
public abstract XMLEventReader createXMLEventReader(String systemId, java.io.InputStream stream)
|
||||
throws XMLStreamException;
|
||||
|
||||
/**
|
||||
* Create a filtered reader that wraps the filter around the reader
|
||||
* @param reader the reader to filter
|
||||
* @param filter the filter to apply to the reader
|
||||
* @throws XMLStreamException
|
||||
*/
|
||||
public abstract XMLStreamReader createFilteredReader(XMLStreamReader reader, StreamFilter filter)
|
||||
throws XMLStreamException;
|
||||
|
||||
/**
|
||||
* Create a filtered event reader that wraps the filter around the event reader
|
||||
* @param reader the event reader to wrap
|
||||
* @param filter the filter to apply to the event reader
|
||||
* @throws XMLStreamException
|
||||
*/
|
||||
public abstract XMLEventReader createFilteredReader(XMLEventReader reader, EventFilter filter)
|
||||
throws XMLStreamException;
|
||||
|
||||
/**
|
||||
* The resolver that will be set on any XMLStreamReader or XMLEventReader created
|
||||
* by this factory instance.
|
||||
*/
|
||||
public abstract XMLResolver getXMLResolver();
|
||||
|
||||
/**
|
||||
* The resolver that will be set on any XMLStreamReader or XMLEventReader created
|
||||
* by this factory instance.
|
||||
* @param resolver the resolver to use to resolve references
|
||||
*/
|
||||
public abstract void setXMLResolver(XMLResolver resolver);
|
||||
|
||||
/**
|
||||
* The reporter that will be set on any XMLStreamReader or XMLEventReader created
|
||||
* by this factory instance.
|
||||
*/
|
||||
public abstract XMLReporter getXMLReporter();
|
||||
|
||||
/**
|
||||
* The reporter that will be set on any XMLStreamReader or XMLEventReader created
|
||||
* by this factory instance.
|
||||
* @param reporter the resolver to use to report non fatal errors
|
||||
*/
|
||||
public abstract void setXMLReporter(XMLReporter reporter);
|
||||
|
||||
/**
|
||||
* Allows the user to set specific feature/property on the underlying
|
||||
* implementation. The underlying implementation is not required to support
|
||||
* every setting of every property in the specification and may use
|
||||
* IllegalArgumentException to signal that an unsupported property may not be
|
||||
* set with the specified value.
|
||||
* <p>
|
||||
* All implementations that implement JAXP 1.5 or newer are required to
|
||||
* support the {@link javax.xml.XMLConstants#ACCESS_EXTERNAL_DTD} property.
|
||||
* </p>
|
||||
* <ul>
|
||||
* <li>
|
||||
* <p>
|
||||
* Access to external DTDs, external Entity References is restricted to the
|
||||
* protocols specified by the property. If access is denied during parsing
|
||||
* due to the restriction of this property, {@link javax.xml.stream.XMLStreamException}
|
||||
* will be thrown by the {@link javax.xml.stream.XMLStreamReader#next()} or
|
||||
* {@link javax.xml.stream.XMLEventReader#nextEvent()} method.
|
||||
* </p>
|
||||
* </li>
|
||||
* </ul>
|
||||
* @param name The name of the property (may not be null)
|
||||
* @param value The value of the property
|
||||
* @throws java.lang.IllegalArgumentException if the property is not supported
|
||||
*/
|
||||
public abstract void setProperty(java.lang.String name, Object value)
|
||||
throws java.lang.IllegalArgumentException;
|
||||
|
||||
/**
|
||||
* Get the value of a feature/property from the underlying implementation
|
||||
* @param name The name of the property (may not be null)
|
||||
* @return The value of the property
|
||||
* @throws IllegalArgumentException if the property is not supported
|
||||
*/
|
||||
public abstract Object getProperty(java.lang.String name)
|
||||
throws java.lang.IllegalArgumentException;
|
||||
|
||||
|
||||
/**
|
||||
* Query the set of properties that this factory supports.
|
||||
*
|
||||
* @param name The name of the property (may not be null)
|
||||
* @return true if the property is supported and false otherwise
|
||||
*/
|
||||
public abstract boolean isPropertySupported(String name);
|
||||
|
||||
/**
|
||||
* Set a user defined event allocator for events
|
||||
* @param allocator the user defined allocator
|
||||
*/
|
||||
public abstract void setEventAllocator(XMLEventAllocator allocator);
|
||||
|
||||
/**
|
||||
* Gets the allocator used by streams created with this factory
|
||||
*/
|
||||
public abstract XMLEventAllocator getEventAllocator();
|
||||
|
||||
}
|
|
@ -0,0 +1,359 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009, 2013, by Oracle Corporation. All Rights Reserved.
|
||||
*/
|
||||
|
||||
package javax.xml.stream;
|
||||
|
||||
import javax.xml.transform.Result;
|
||||
|
||||
/**
|
||||
* Defines an abstract implementation of a factory for
|
||||
* getting XMLEventWriters and XMLStreamWriters.
|
||||
*
|
||||
* The following table defines the standard properties of this specification.
|
||||
* Each property varies in the level of support required by each implementation.
|
||||
* The level of support required is described in the 'Required' column.
|
||||
*
|
||||
* <table border="2" rules="all" cellpadding="4">
|
||||
* <thead>
|
||||
* <tr>
|
||||
* <th align="center" colspan="2">
|
||||
* Configuration parameters
|
||||
* </th>
|
||||
* </tr>
|
||||
* </thead>
|
||||
* <tbody>
|
||||
* <tr>
|
||||
* <th>Property Name</th>
|
||||
* <th>Behavior</th>
|
||||
* <th>Return type</th>
|
||||
* <th>Default Value</th>
|
||||
* <th>Required</th>
|
||||
* </tr>
|
||||
* <tr><td>javax.xml.stream.isRepairingNamespaces</td><td>defaults prefixes on the output side</td><td>Boolean</td><td>False</td><td>Yes</td></tr>
|
||||
* </tbody>
|
||||
* </table>
|
||||
*
|
||||
* <p>The following paragraphs describe the namespace and prefix repair algorithm:</p>
|
||||
*
|
||||
* <p>The property can be set with the following code line:
|
||||
* <code>setProperty("javax.xml.stream.isRepairingNamespaces",new Boolean(true|false));</code></p>
|
||||
*
|
||||
* <p>This property specifies that the writer default namespace prefix declarations.
|
||||
* The default value is false. </p>
|
||||
*
|
||||
* <p>If a writer isRepairingNamespaces it will create a namespace declaration
|
||||
* on the current StartElement for
|
||||
* any attribute that does not
|
||||
* currently have a namespace declaration in scope. If the StartElement
|
||||
* has a uri but no prefix specified a prefix will be assigned, if the prefix
|
||||
* has not been declared in a parent of the current StartElement it will be declared
|
||||
* on the current StartElement. If the defaultNamespace is bound and in scope
|
||||
* and the default namespace matches the URI of the attribute or StartElement
|
||||
* QName no prefix will be assigned.</p>
|
||||
*
|
||||
* <p>If an element or attribute name has a prefix, but is not
|
||||
* bound to any namespace URI, then the prefix will be removed
|
||||
* during serialization.</p>
|
||||
*
|
||||
* <p>If element and/or attribute names in the same start or
|
||||
* empty-element tag are bound to different namespace URIs and
|
||||
* are using the same prefix then the element or the first
|
||||
* occurring attribute retains the original prefix and the
|
||||
* following attributes have their prefixes replaced with a
|
||||
* new prefix that is bound to the namespace URIs of those
|
||||
* attributes. </p>
|
||||
*
|
||||
* <p>If an element or attribute name uses a prefix that is
|
||||
* bound to a different URI than that inherited from the
|
||||
* namespace context of the parent of that element and there
|
||||
* is no namespace declaration in the context of the current
|
||||
* element then such a namespace declaration is added. </p>
|
||||
*
|
||||
* <p>If an element or attribute name is bound to a prefix and
|
||||
* there is a namespace declaration that binds that prefix
|
||||
* to a different URI then that namespace declaration is
|
||||
* either removed if the correct mapping is inherited from
|
||||
* the parent context of that element, or changed to the
|
||||
* namespace URI of the element or attribute using that prefix.</p>
|
||||
*
|
||||
* @version 1.2
|
||||
* @author Copyright (c) 2009 by Oracle Corporation. All Rights Reserved.
|
||||
* @see XMLInputFactory
|
||||
* @see XMLEventWriter
|
||||
* @see XMLStreamWriter
|
||||
* @since 1.6
|
||||
*/
|
||||
public abstract class XMLOutputFactory {
|
||||
/**
|
||||
* Property used to set prefix defaulting on the output side
|
||||
*/
|
||||
public static final String IS_REPAIRING_NAMESPACES=
|
||||
"javax.xml.stream.isRepairingNamespaces";
|
||||
|
||||
static final String DEFAULIMPL = "com.sun.xml.internal.stream.XMLOutputFactoryImpl";
|
||||
|
||||
protected XMLOutputFactory(){}
|
||||
|
||||
/**
|
||||
* Creates a new instance of the factory in exactly the same manner as the
|
||||
* {@link #newFactory()} method.
|
||||
* @throws FactoryConfigurationError if an instance of this factory cannot be loaded
|
||||
*/
|
||||
public static XMLOutputFactory newInstance()
|
||||
throws FactoryConfigurationError
|
||||
{
|
||||
return FactoryFinder.find(XMLOutputFactory.class, DEFAULIMPL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new instance of the factory.
|
||||
* <p>
|
||||
* This static method creates a new factory instance. This method uses the
|
||||
* following ordered lookup procedure to determine the XMLOutputFactory
|
||||
* implementation class to load:
|
||||
* </p>
|
||||
* <ul>
|
||||
* <li>
|
||||
* Use the javax.xml.stream.XMLOutputFactory system property.
|
||||
* </li>
|
||||
* <li>
|
||||
* Use the properties file "lib/stax.properties" in the JRE directory.
|
||||
* This configuration file is in standard java.util.Properties format
|
||||
* and contains the fully qualified name of the implementation class
|
||||
* with the key being the system property defined above.
|
||||
* </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>
|
||||
* <p>
|
||||
* Once an application has obtained a reference to a XMLOutputFactory it
|
||||
* can use the factory to configure and obtain stream instances.
|
||||
* </p>
|
||||
* <p>
|
||||
* Note that this is a new method that replaces the deprecated newInstance() method.
|
||||
* No changes in behavior are defined by this replacement method relative to the
|
||||
* deprecated method.
|
||||
* </p>
|
||||
* @throws FactoryConfigurationError in case of {@linkplain
|
||||
* java.util.ServiceConfigurationError service configuration error} or if
|
||||
* the implementation is not available or cannot be instantiated.
|
||||
*/
|
||||
public static XMLOutputFactory newFactory()
|
||||
throws FactoryConfigurationError
|
||||
{
|
||||
return FactoryFinder.find(XMLOutputFactory.class, DEFAULIMPL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new instance of the factory.
|
||||
*
|
||||
* @param factoryId Name of the factory to find, same as
|
||||
* a property name
|
||||
* @param classLoader classLoader to use
|
||||
* @return the factory implementation
|
||||
* @throws FactoryConfigurationError if an instance of this factory cannot be loaded
|
||||
*
|
||||
* @deprecated This method has been deprecated because it returns an
|
||||
* instance of XMLInputFactory, which is of the wrong class.
|
||||
* Use the new method {@link #newFactory(java.lang.String,
|
||||
* java.lang.ClassLoader)} instead.
|
||||
*/
|
||||
public static XMLInputFactory newInstance(String factoryId,
|
||||
ClassLoader classLoader)
|
||||
throws FactoryConfigurationError {
|
||||
//do not fallback if given classloader can't find the class, throw exception
|
||||
return FactoryFinder.find(XMLInputFactory.class, factoryId, classLoader, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new instance of the factory.
|
||||
* If the classLoader argument is null, then the ContextClassLoader is used.
|
||||
* <p>
|
||||
* This method uses the following ordered lookup procedure to determine
|
||||
* the XMLOutputFactory implementation class to load:
|
||||
* </p>
|
||||
* <ul>
|
||||
* <li>
|
||||
* Use the value of the system property identified by {@code factoryId}.
|
||||
* </li>
|
||||
* <li>
|
||||
* Use the properties file "lib/stax.properties" in the JRE directory.
|
||||
* This configuration file is in standard java.util.Properties format
|
||||
* and contains the fully qualified name of the implementation class
|
||||
* with the key being the given {@code factoryId}.
|
||||
* </li>
|
||||
* <li>
|
||||
* If {@code factoryId} is "javax.xml.stream.XMLOutputFactory",
|
||||
* use the service-provider loading facilities, defined by the
|
||||
* {@link java.util.ServiceLoader} class, to attempt to {@linkplain
|
||||
* java.util.ServiceLoader#load(java.lang.Class, java.lang.ClassLoader) locate and load}
|
||||
* an implementation of the service using the specified {@code ClassLoader}.
|
||||
* If {@code classLoader} is null, the {@linkplain
|
||||
* java.util.ServiceLoader#load(java.lang.Class) default loading mechanism} will apply:
|
||||
* That is, 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, throws a {@link FactoryConfigurationError}.
|
||||
* </li>
|
||||
* </ul>
|
||||
*
|
||||
* @apiNote The parameter factoryId defined here is inconsistent with that
|
||||
* of other JAXP factories where the first parameter is fully qualified
|
||||
* factory class name that provides implementation of the factory.
|
||||
*
|
||||
* <p>
|
||||
* Note that this is a new method that replaces the deprecated
|
||||
* {@link #newInstance(java.lang.String, java.lang.ClassLoader)
|
||||
* newInstance(String factoryId, ClassLoader classLoader)} method.
|
||||
* The original method was incorrectly defined to return XMLInputFactory.
|
||||
* </p>
|
||||
*
|
||||
* @param factoryId Name of the factory to find, same as
|
||||
* a property name
|
||||
* @param classLoader classLoader to use
|
||||
* @return the factory implementation
|
||||
* @throws FactoryConfigurationError in case of {@linkplain
|
||||
* java.util.ServiceConfigurationError service configuration error} or if
|
||||
* the implementation is not available or cannot be instantiated.
|
||||
*/
|
||||
public static XMLOutputFactory newFactory(String factoryId,
|
||||
ClassLoader classLoader)
|
||||
throws FactoryConfigurationError {
|
||||
//do not fallback if given classloader can't find the class, throw exception
|
||||
return FactoryFinder.find(XMLOutputFactory.class, factoryId, classLoader, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new XMLStreamWriter that writes to a writer
|
||||
* @param stream the writer to write to
|
||||
* @throws XMLStreamException
|
||||
*/
|
||||
public abstract XMLStreamWriter createXMLStreamWriter(java.io.Writer stream) throws XMLStreamException;
|
||||
|
||||
/**
|
||||
* Create a new XMLStreamWriter that writes to a stream
|
||||
* @param stream the stream to write to
|
||||
* @throws XMLStreamException
|
||||
*/
|
||||
public abstract XMLStreamWriter createXMLStreamWriter(java.io.OutputStream stream) throws XMLStreamException;
|
||||
|
||||
/**
|
||||
* Create a new XMLStreamWriter that writes to a stream
|
||||
* @param stream the stream to write to
|
||||
* @param encoding the encoding to use
|
||||
* @throws XMLStreamException
|
||||
*/
|
||||
public abstract XMLStreamWriter createXMLStreamWriter(java.io.OutputStream stream,
|
||||
String encoding) throws XMLStreamException;
|
||||
|
||||
/**
|
||||
* Create a new XMLStreamWriter that writes to a JAXP result. This method is optional.
|
||||
* @param result the result to write to
|
||||
* @throws UnsupportedOperationException if this method is not
|
||||
* supported by this XMLOutputFactory
|
||||
* @throws XMLStreamException
|
||||
*/
|
||||
public abstract XMLStreamWriter createXMLStreamWriter(Result result) throws XMLStreamException;
|
||||
|
||||
|
||||
/**
|
||||
* Create a new XMLEventWriter that writes to a JAXP result. This method is optional.
|
||||
* @param result the result to write to
|
||||
* @throws UnsupportedOperationException if this method is not
|
||||
* supported by this XMLOutputFactory
|
||||
* @throws XMLStreamException
|
||||
*/
|
||||
public abstract XMLEventWriter createXMLEventWriter(Result result) throws XMLStreamException;
|
||||
|
||||
/**
|
||||
* Create a new XMLEventWriter that writes to a stream
|
||||
* @param stream the stream to write to
|
||||
* @throws XMLStreamException
|
||||
*/
|
||||
public abstract XMLEventWriter createXMLEventWriter(java.io.OutputStream stream) throws XMLStreamException;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Create a new XMLEventWriter that writes to a stream
|
||||
* @param stream the stream to write to
|
||||
* @param encoding the encoding to use
|
||||
* @throws XMLStreamException
|
||||
*/
|
||||
public abstract XMLEventWriter createXMLEventWriter(java.io.OutputStream stream,
|
||||
String encoding) throws XMLStreamException;
|
||||
|
||||
/**
|
||||
* Create a new XMLEventWriter that writes to a writer
|
||||
* @param stream the stream to write to
|
||||
* @throws XMLStreamException
|
||||
*/
|
||||
public abstract XMLEventWriter createXMLEventWriter(java.io.Writer stream) throws XMLStreamException;
|
||||
|
||||
/**
|
||||
* Allows the user to set specific features/properties on the underlying implementation.
|
||||
* @param name The name of the property
|
||||
* @param value The value of the property
|
||||
* @throws java.lang.IllegalArgumentException if the property is not supported
|
||||
*/
|
||||
public abstract void setProperty(java.lang.String name,
|
||||
Object value)
|
||||
throws IllegalArgumentException;
|
||||
|
||||
/**
|
||||
* Get a feature/property on the underlying implementation
|
||||
* @param name The name of the property
|
||||
* @return The value of the property
|
||||
* @throws java.lang.IllegalArgumentException if the property is not supported
|
||||
*/
|
||||
public abstract Object getProperty(java.lang.String name)
|
||||
throws IllegalArgumentException;
|
||||
|
||||
/**
|
||||
* Query the set of properties that this factory supports.
|
||||
*
|
||||
* @param name The name of the property (may not be null)
|
||||
* @return true if the property is supported and false otherwise
|
||||
*/
|
||||
public abstract boolean isPropertySupported(String name);
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 by Oracle Corporation. All Rights Reserved.
|
||||
*/
|
||||
|
||||
package javax.xml.stream;
|
||||
|
||||
/**
|
||||
* This interface is used to report non-fatal errors.
|
||||
* Only warnings should be echoed through this interface.
|
||||
* @version 1.0
|
||||
* @author Copyright (c) 2009 by Oracle Corporation. All Rights Reserved.
|
||||
* @since 1.6
|
||||
*/
|
||||
public interface XMLReporter {
|
||||
|
||||
/**
|
||||
|
||||
* Report the desired message in an application specific format.
|
||||
|
||||
* Only warnings and non-fatal errors should be reported through
|
||||
|
||||
* this interface.
|
||||
|
||||
* Fatal errors should be thrown as XMLStreamException.
|
||||
|
||||
*
|
||||
|
||||
* @param message the error message
|
||||
|
||||
* @param errorType an implementation defined error type
|
||||
|
||||
* @param relatedInformation information related to the error, if available
|
||||
|
||||
* @param location the location of the error, if available
|
||||
|
||||
* @throws XMLStreamException
|
||||
|
||||
*/
|
||||
public void report(String message, String errorType, Object relatedInformation, Location location)
|
||||
throws XMLStreamException;
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 by Oracle Corporation. All Rights Reserved.
|
||||
*/
|
||||
|
||||
package javax.xml.stream;
|
||||
|
||||
/**
|
||||
* This interface is used to resolve resources during an XML parse. If an application wishes to
|
||||
* perform custom entity resolution it must register an instance of this interface with
|
||||
* the XMLInputFactory using the setXMLResolver method.
|
||||
*
|
||||
* @version 1.0
|
||||
* @author Copyright (c) 2009 by Oracle Corporation. All Rights Reserved.
|
||||
* @since 1.6
|
||||
*/
|
||||
public interface XMLResolver {
|
||||
|
||||
/**
|
||||
* Retrieves a resource. This resource can be of the following three return types:
|
||||
* (1) java.io.InputStream (2) javax.xml.stream.XMLStreamReader (3) java.xml.stream.XMLEventReader.
|
||||
* If this method returns null the processor will attempt to resolve the entity using its
|
||||
* default mechanism.
|
||||
*
|
||||
* @param publicID The public identifier of the external entity being referenced, or null if none was supplied.
|
||||
* @param systemID The system identifier of the external entity being referenced.
|
||||
* @param baseURI Absolute base URI associated with systemId.
|
||||
* @param namespace The namespace of the entity to resolve.
|
||||
* @return The resource requested or null.
|
||||
* @throws XMLStreamException if there was a failure attempting to resolve the resource.
|
||||
*/
|
||||
public Object resolveEntity(String publicID,
|
||||
String systemID,
|
||||
String baseURI,
|
||||
String namespace)
|
||||
throws XMLStreamException;
|
||||
}
|
|
@ -0,0 +1,127 @@
|
|||
/*
|
||||
* 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.stream;
|
||||
|
||||
/**
|
||||
* This interface declares the constants used in this API.
|
||||
* Numbers in the range 0 to 256 are reserved for the specification,
|
||||
* user defined events must use event codes outside that range.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
|
||||
public interface XMLStreamConstants {
|
||||
/**
|
||||
* Indicates an event is a start element
|
||||
* @see javax.xml.stream.events.StartElement
|
||||
*/
|
||||
public static final int START_ELEMENT=1;
|
||||
/**
|
||||
* Indicates an event is an end element
|
||||
* @see javax.xml.stream.events.EndElement
|
||||
*/
|
||||
public static final int END_ELEMENT=2;
|
||||
/**
|
||||
* Indicates an event is a processing instruction
|
||||
* @see javax.xml.stream.events.ProcessingInstruction
|
||||
*/
|
||||
public static final int PROCESSING_INSTRUCTION=3;
|
||||
|
||||
/**
|
||||
* Indicates an event is characters
|
||||
* @see javax.xml.stream.events.Characters
|
||||
*/
|
||||
public static final int CHARACTERS=4;
|
||||
|
||||
/**
|
||||
* Indicates an event is a comment
|
||||
* @see javax.xml.stream.events.Comment
|
||||
*/
|
||||
public static final int COMMENT=5;
|
||||
|
||||
/**
|
||||
* The characters are white space
|
||||
* (see [XML], 2.10 "White Space Handling").
|
||||
* Events are only reported as SPACE if they are ignorable white
|
||||
* space. Otherwise they are reported as CHARACTERS.
|
||||
* @see javax.xml.stream.events.Characters
|
||||
*/
|
||||
public static final int SPACE=6;
|
||||
|
||||
/**
|
||||
* Indicates an event is a start document
|
||||
* @see javax.xml.stream.events.StartDocument
|
||||
*/
|
||||
public static final int START_DOCUMENT=7;
|
||||
|
||||
/**
|
||||
* Indicates an event is an end document
|
||||
* @see javax.xml.stream.events.EndDocument
|
||||
*/
|
||||
public static final int END_DOCUMENT=8;
|
||||
|
||||
/**
|
||||
* Indicates an event is an entity reference
|
||||
* @see javax.xml.stream.events.EntityReference
|
||||
*/
|
||||
public static final int ENTITY_REFERENCE=9;
|
||||
|
||||
/**
|
||||
* Indicates an event is an attribute
|
||||
* @see javax.xml.stream.events.Attribute
|
||||
*/
|
||||
public static final int ATTRIBUTE=10;
|
||||
|
||||
/**
|
||||
* Indicates an event is a DTD
|
||||
* @see javax.xml.stream.events.DTD
|
||||
*/
|
||||
public static final int DTD=11;
|
||||
|
||||
/**
|
||||
* Indicates an event is a CDATA section
|
||||
* @see javax.xml.stream.events.Characters
|
||||
*/
|
||||
public static final int CDATA=12;
|
||||
|
||||
/**
|
||||
* Indicates the event is a namespace declaration
|
||||
*
|
||||
* @see javax.xml.stream.events.Namespace
|
||||
*/
|
||||
public static final int NAMESPACE=13;
|
||||
|
||||
/**
|
||||
* Indicates a Notation
|
||||
* @see javax.xml.stream.events.NotationDeclaration
|
||||
*/
|
||||
public static final int NOTATION_DECLARATION=14;
|
||||
|
||||
/**
|
||||
* Indicates a Entity Declaration
|
||||
* @see javax.xml.stream.events.NotationDeclaration
|
||||
*/
|
||||
public static final int ENTITY_DECLARATION=15;
|
||||
}
|
|
@ -0,0 +1,130 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 by Oracle Corporation. All Rights Reserved.
|
||||
*/
|
||||
|
||||
package javax.xml.stream;
|
||||
|
||||
/**
|
||||
* The base exception for unexpected processing errors. This Exception
|
||||
* class is used to report well-formedness errors as well as unexpected
|
||||
* processing conditions.
|
||||
* @version 1.0
|
||||
* @author Copyright (c) 2009 by Oracle Corporation. All Rights Reserved.
|
||||
* @since 1.6
|
||||
*/
|
||||
|
||||
public class XMLStreamException extends Exception {
|
||||
|
||||
protected Throwable nested;
|
||||
protected Location location;
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
public XMLStreamException(){
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct an exception with the assocated message.
|
||||
*
|
||||
* @param msg the message to report
|
||||
*/
|
||||
public XMLStreamException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct an exception with the assocated exception
|
||||
*
|
||||
* @param th a nested exception
|
||||
*/
|
||||
public XMLStreamException(Throwable th) {
|
||||
super(th);
|
||||
nested = th;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct an exception with the assocated message and exception
|
||||
*
|
||||
* @param th a nested exception
|
||||
* @param msg the message to report
|
||||
*/
|
||||
public XMLStreamException(String msg, Throwable th) {
|
||||
super(msg, th);
|
||||
nested = th;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct an exception with the assocated message, exception and location.
|
||||
*
|
||||
* @param th a nested exception
|
||||
* @param msg the message to report
|
||||
* @param location the location of the error
|
||||
*/
|
||||
public XMLStreamException(String msg, Location location, Throwable th) {
|
||||
super("ParseError at [row,col]:["+location.getLineNumber()+","+
|
||||
location.getColumnNumber()+"]\n"+
|
||||
"Message: "+msg);
|
||||
nested = th;
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct an exception with the assocated message, exception and location.
|
||||
*
|
||||
* @param msg the message to report
|
||||
* @param location the location of the error
|
||||
*/
|
||||
public XMLStreamException(String msg,
|
||||
Location location) {
|
||||
super("ParseError at [row,col]:["+location.getLineNumber()+","+
|
||||
location.getColumnNumber()+"]\n"+
|
||||
"Message: "+msg);
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the nested exception.
|
||||
*
|
||||
* @return Nested exception
|
||||
*/
|
||||
public Throwable getNestedException() {
|
||||
return nested;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the location of the exception
|
||||
*
|
||||
* @return the location of the exception, may be null if none is available
|
||||
*/
|
||||
public Location getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,704 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 by Oracle Corporation. All Rights Reserved.
|
||||
*/
|
||||
|
||||
package javax.xml.stream;
|
||||
|
||||
import java.io.Reader;
|
||||
import javax.xml.namespace.NamespaceContext;
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
/**
|
||||
* The XMLStreamReader interface allows forward, read-only access to XML.
|
||||
* It is designed to be the lowest level and most efficient way to
|
||||
* read XML data.
|
||||
*
|
||||
* <p> The XMLStreamReader is designed to iterate over XML using
|
||||
* next() and hasNext(). The data can be accessed using methods such as getEventType(),
|
||||
* getNamespaceURI(), getLocalName() and getText();
|
||||
*
|
||||
* <p> The <a href="#next()">next()</a> method causes the reader to read the next parse event.
|
||||
* The next() method returns an integer which identifies the type of event just read.
|
||||
* <p> The event type can be determined using <a href="#getEventType()">getEventType()</a>.
|
||||
* <p> Parsing events are defined as the XML Declaration, a DTD,
|
||||
* start tag, character data, white space, end tag, comment,
|
||||
* or processing instruction. An attribute or namespace event may be encountered
|
||||
* at the root level of a document as the result of a query operation.
|
||||
*
|
||||
* <p>For XML 1.0 compliance an XML processor must pass the
|
||||
* identifiers of declared unparsed entities, notation declarations and their
|
||||
* associated identifiers to the application. This information is
|
||||
* provided through the property API on this interface.
|
||||
* The following two properties allow access to this information:
|
||||
* javax.xml.stream.notations and javax.xml.stream.entities.
|
||||
* When the current event is a DTD the following call will return a
|
||||
* list of Notations
|
||||
* <code>List l = (List) getProperty("javax.xml.stream.notations");</code>
|
||||
* The following call will return a list of entity declarations:
|
||||
* <code>List l = (List) getProperty("javax.xml.stream.entities");</code>
|
||||
* These properties can only be accessed during a DTD event and
|
||||
* are defined to return null if the information is not available.
|
||||
*
|
||||
* <p>The following table describes which methods are valid in what state.
|
||||
* If a method is called in an invalid state the method will throw a
|
||||
* java.lang.IllegalStateException.
|
||||
*
|
||||
* <table border="2" rules="all" cellpadding="4">
|
||||
* <thead>
|
||||
* <tr>
|
||||
* <th align="center" colspan="2">
|
||||
* Valid methods for each state
|
||||
* </th>
|
||||
* </tr>
|
||||
* </thead>
|
||||
* <tbody>
|
||||
* <tr>
|
||||
* <th>Event Type</th>
|
||||
* <th>Valid Methods</th>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td> All States </td>
|
||||
* <td> getProperty(), hasNext(), require(), close(),
|
||||
* getNamespaceURI(), isStartElement(),
|
||||
* isEndElement(), isCharacters(), isWhiteSpace(),
|
||||
* getNamespaceContext(), getEventType(),getLocation(),
|
||||
* hasText(), hasName()
|
||||
* </td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td> START_ELEMENT </td>
|
||||
* <td> next(), getName(), getLocalName(), hasName(), getPrefix(),
|
||||
* getAttributeXXX(), isAttributeSpecified(),
|
||||
* getNamespaceXXX(),
|
||||
* getElementText(), nextTag()
|
||||
* </td>
|
||||
* </tr>
|
||||
* <td> ATTRIBUTE </td>
|
||||
* <td> next(), nextTag()
|
||||
* getAttributeXXX(), isAttributeSpecified(),
|
||||
* </td>
|
||||
* </tr>
|
||||
* </tr>
|
||||
* <td> NAMESPACE </td>
|
||||
* <td> next(), nextTag()
|
||||
* getNamespaceXXX()
|
||||
* </td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td> END_ELEMENT </td>
|
||||
* <td> next(), getName(), getLocalName(), hasName(), getPrefix(),
|
||||
* getNamespaceXXX(), nextTag()
|
||||
* </td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td> CHARACTERS </td>
|
||||
* <td> next(), getTextXXX(), nextTag() </td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td> CDATA </td>
|
||||
* <td> next(), getTextXXX(), nextTag() </td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td> COMMENT </td>
|
||||
* <td> next(), getTextXXX(), nextTag() </td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td> SPACE </td>
|
||||
* <td> next(), getTextXXX(), nextTag() </td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td> START_DOCUMENT </td>
|
||||
* <td> next(), getEncoding(), getVersion(), isStandalone(), standaloneSet(),
|
||||
* getCharacterEncodingScheme(), nextTag()</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td> END_DOCUMENT </td>
|
||||
* <td> close()</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td> PROCESSING_INSTRUCTION </td>
|
||||
* <td> next(), getPITarget(), getPIData(), nextTag() </td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td> ENTITY_REFERENCE </td>
|
||||
* <td> next(), getLocalName(), getText(), nextTag() </td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td> DTD </td>
|
||||
* <td> next(), getText(), nextTag() </td>
|
||||
* </tr>
|
||||
* </tbody>
|
||||
* </table>
|
||||
*
|
||||
* @version 1.0
|
||||
* @author Copyright (c) 2009 by Oracle Corporation. All Rights Reserved.
|
||||
* @see javax.xml.stream.events.XMLEvent
|
||||
* @see XMLInputFactory
|
||||
* @see XMLStreamWriter
|
||||
* @since 1.6
|
||||
*/
|
||||
public interface XMLStreamReader extends XMLStreamConstants {
|
||||
/**
|
||||
* Get the value of a feature/property from the underlying implementation
|
||||
* @param name The name of the property, may not be null
|
||||
* @return The value of the property
|
||||
* @throws IllegalArgumentException if name is null
|
||||
*/
|
||||
public Object getProperty(java.lang.String name) throws java.lang.IllegalArgumentException;
|
||||
|
||||
/**
|
||||
* Get next parsing event - a processor may return all contiguous
|
||||
* character data in a single chunk, or it may split it into several chunks.
|
||||
* If the property javax.xml.stream.isCoalescing is set to true
|
||||
* element content must be coalesced and only one CHARACTERS event
|
||||
* must be returned for contiguous element content or
|
||||
* CDATA Sections.
|
||||
*
|
||||
* By default entity references must be
|
||||
* expanded and reported transparently to the application.
|
||||
* An exception will be thrown if an entity reference cannot be expanded.
|
||||
* If element content is empty (i.e. content is "") then no CHARACTERS event will be reported.
|
||||
*
|
||||
* <p>Given the following XML:<br>
|
||||
* <foo><!--description-->content text<![CDATA[<greeting>Hello</greeting>]]>other content</foo><br>
|
||||
* The behavior of calling next() when being on foo will be:<br>
|
||||
* 1- the comment (COMMENT)<br>
|
||||
* 2- then the characters section (CHARACTERS)<br>
|
||||
* 3- then the CDATA section (another CHARACTERS)<br>
|
||||
* 4- then the next characters section (another CHARACTERS)<br>
|
||||
* 5- then the END_ELEMENT<br>
|
||||
*
|
||||
* <p><b>NOTE:</b> empty element (such as <tag/>) will be reported
|
||||
* with two separate events: START_ELEMENT, END_ELEMENT - This preserves
|
||||
* parsing equivalency of empty element to <tag></tag>.
|
||||
*
|
||||
* This method will throw an IllegalStateException if it is called after hasNext() returns false.
|
||||
* @see javax.xml.stream.events.XMLEvent
|
||||
* @return the integer code corresponding to the current parse event
|
||||
* @throws NoSuchElementException if this is called when hasNext() returns false
|
||||
* @throws XMLStreamException if there is an error processing the underlying XML source
|
||||
*/
|
||||
public int next() throws XMLStreamException;
|
||||
|
||||
/**
|
||||
* Test if the current event is of the given type and if the namespace and name match the current
|
||||
* namespace and name of the current event. If the namespaceURI is null it is not checked for equality,
|
||||
* if the localName is null it is not checked for equality.
|
||||
* @param type the event type
|
||||
* @param namespaceURI the uri of the event, may be null
|
||||
* @param localName the localName of the event, may be null
|
||||
* @throws XMLStreamException if the required values are not matched.
|
||||
*/
|
||||
public void require(int type, String namespaceURI, String localName) throws XMLStreamException;
|
||||
|
||||
/**
|
||||
* Reads the content of a text-only element, an exception is thrown if this is
|
||||
* not a text-only element.
|
||||
* Regardless of value of javax.xml.stream.isCoalescing this method always returns coalesced content.
|
||||
* <br /> Precondition: the current event is START_ELEMENT.
|
||||
* <br /> Postcondition: the current event is the corresponding END_ELEMENT.
|
||||
*
|
||||
* <br />The method does the following (implementations are free to optimized
|
||||
* but must do equivalent processing):
|
||||
* <pre>
|
||||
* if(getEventType() != XMLStreamConstants.START_ELEMENT) {
|
||||
* throw new XMLStreamException(
|
||||
* "parser must be on START_ELEMENT to read next text", getLocation());
|
||||
* }
|
||||
* int eventType = next();
|
||||
* StringBuffer content = new StringBuffer();
|
||||
* while(eventType != XMLStreamConstants.END_ELEMENT ) {
|
||||
* if(eventType == XMLStreamConstants.CHARACTERS
|
||||
* || eventType == XMLStreamConstants.CDATA
|
||||
* || eventType == XMLStreamConstants.SPACE
|
||||
* || eventType == XMLStreamConstants.ENTITY_REFERENCE) {
|
||||
* buf.append(getText());
|
||||
* } else if(eventType == XMLStreamConstants.PROCESSING_INSTRUCTION
|
||||
* || eventType == XMLStreamConstants.COMMENT) {
|
||||
* // skipping
|
||||
* } else if(eventType == XMLStreamConstants.END_DOCUMENT) {
|
||||
* throw new XMLStreamException(
|
||||
* "unexpected end of document when reading element text content", this);
|
||||
* } else if(eventType == XMLStreamConstants.START_ELEMENT) {
|
||||
* throw new XMLStreamException(
|
||||
* "element text content may not contain START_ELEMENT", getLocation());
|
||||
* } else {
|
||||
* throw new XMLStreamException(
|
||||
* "Unexpected event type "+eventType, getLocation());
|
||||
* }
|
||||
* eventType = next();
|
||||
* }
|
||||
* return buf.toString();
|
||||
* </pre>
|
||||
*
|
||||
* @throws XMLStreamException if the current event is not a START_ELEMENT
|
||||
* or if a non text element is encountered
|
||||
*/
|
||||
public String getElementText() throws XMLStreamException;
|
||||
|
||||
/**
|
||||
* Skips any white space (isWhiteSpace() returns true), COMMENT,
|
||||
* or PROCESSING_INSTRUCTION,
|
||||
* until a START_ELEMENT or END_ELEMENT is reached.
|
||||
* If other than white space characters, COMMENT, PROCESSING_INSTRUCTION, START_ELEMENT, END_ELEMENT
|
||||
* are encountered, an exception is thrown. This method should
|
||||
* be used when processing element-only content seperated by white space.
|
||||
*
|
||||
* <br /> Precondition: none
|
||||
* <br /> Postcondition: the current event is START_ELEMENT or END_ELEMENT
|
||||
* and cursor may have moved over any whitespace event.
|
||||
*
|
||||
* <br />Essentially it does the following (implementations are free to optimized
|
||||
* but must do equivalent processing):
|
||||
* <pre>
|
||||
* int eventType = next();
|
||||
* while((eventType == XMLStreamConstants.CHARACTERS && isWhiteSpace()) // skip whitespace
|
||||
* || (eventType == XMLStreamConstants.CDATA && isWhiteSpace())
|
||||
* // skip whitespace
|
||||
* || eventType == XMLStreamConstants.SPACE
|
||||
* || eventType == XMLStreamConstants.PROCESSING_INSTRUCTION
|
||||
* || eventType == XMLStreamConstants.COMMENT
|
||||
* ) {
|
||||
* eventType = next();
|
||||
* }
|
||||
* if (eventType != XMLStreamConstants.START_ELEMENT && eventType != XMLStreamConstants.END_ELEMENT) {
|
||||
* throw new String XMLStreamException("expected start or end tag", getLocation());
|
||||
* }
|
||||
* return eventType;
|
||||
* </pre>
|
||||
*
|
||||
* @return the event type of the element read (START_ELEMENT or END_ELEMENT)
|
||||
* @throws XMLStreamException if the current event is not white space, PROCESSING_INSTRUCTION,
|
||||
* START_ELEMENT or END_ELEMENT
|
||||
* @throws NoSuchElementException if this is called when hasNext() returns false
|
||||
*/
|
||||
public int nextTag() throws XMLStreamException;
|
||||
|
||||
/**
|
||||
* Returns true if there are more parsing events and false
|
||||
* if there are no more events. This method will return
|
||||
* false if the current state of the XMLStreamReader is
|
||||
* END_DOCUMENT
|
||||
* @return true if there are more events, false otherwise
|
||||
* @throws XMLStreamException if there is a fatal error detecting the next state
|
||||
*/
|
||||
public boolean hasNext() throws XMLStreamException;
|
||||
|
||||
/**
|
||||
* Frees any resources associated with this Reader. This method does not close the
|
||||
* underlying input source.
|
||||
* @throws XMLStreamException if there are errors freeing associated resources
|
||||
*/
|
||||
public void close() throws XMLStreamException;
|
||||
|
||||
/**
|
||||
* Return the uri for the given prefix.
|
||||
* The uri returned depends on the current state of the processor.
|
||||
*
|
||||
* <p><strong>NOTE:</strong>The 'xml' prefix is bound as defined in
|
||||
* <a href="http://www.w3.org/TR/REC-xml-names/#ns-using">Namespaces in XML</a>
|
||||
* specification to "http://www.w3.org/XML/1998/namespace".
|
||||
*
|
||||
* <p><strong>NOTE:</strong> The 'xmlns' prefix must be resolved to following namespace
|
||||
* <a href="http://www.w3.org/2000/xmlns/">http://www.w3.org/2000/xmlns/</a>
|
||||
* @param prefix The prefix to lookup, may not be null
|
||||
* @return the uri bound to the given prefix or null if it is not bound
|
||||
* @throws IllegalArgumentException if the prefix is null
|
||||
*/
|
||||
public String getNamespaceURI(String prefix);
|
||||
|
||||
/**
|
||||
* Returns true if the cursor points to a start tag (otherwise false)
|
||||
* @return true if the cursor points to a start tag, false otherwise
|
||||
*/
|
||||
public boolean isStartElement();
|
||||
|
||||
/**
|
||||
* Returns true if the cursor points to an end tag (otherwise false)
|
||||
* @return true if the cursor points to an end tag, false otherwise
|
||||
*/
|
||||
public boolean isEndElement();
|
||||
|
||||
/**
|
||||
* Returns true if the cursor points to a character data event
|
||||
* @return true if the cursor points to character data, false otherwise
|
||||
*/
|
||||
public boolean isCharacters();
|
||||
|
||||
/**
|
||||
* Returns true if the cursor points to a character data event
|
||||
* that consists of all whitespace
|
||||
* @return true if the cursor points to all whitespace, false otherwise
|
||||
*/
|
||||
public boolean isWhiteSpace();
|
||||
|
||||
|
||||
/**
|
||||
* Returns the normalized attribute value of the
|
||||
* attribute with the namespace and localName
|
||||
* If the namespaceURI is null the namespace
|
||||
* is not checked for equality
|
||||
* @param namespaceURI the namespace of the attribute
|
||||
* @param localName the local name of the attribute, cannot be null
|
||||
* @return returns the value of the attribute , returns null if not found
|
||||
* @throws IllegalStateException if this is not a START_ELEMENT or ATTRIBUTE
|
||||
*/
|
||||
public String getAttributeValue(String namespaceURI,
|
||||
String localName);
|
||||
|
||||
/**
|
||||
* Returns the count of attributes on this START_ELEMENT,
|
||||
* this method is only valid on a START_ELEMENT or ATTRIBUTE. This
|
||||
* count excludes namespace definitions. Attribute indices are
|
||||
* zero-based.
|
||||
* @return returns the number of attributes
|
||||
* @throws IllegalStateException if this is not a START_ELEMENT or ATTRIBUTE
|
||||
*/
|
||||
public int getAttributeCount();
|
||||
|
||||
/** Returns the qname of the attribute at the provided index
|
||||
*
|
||||
* @param index the position of the attribute
|
||||
* @return the QName of the attribute
|
||||
* @throws IllegalStateException if this is not a START_ELEMENT or ATTRIBUTE
|
||||
*/
|
||||
public QName getAttributeName(int index);
|
||||
|
||||
/**
|
||||
* Returns the namespace of the attribute at the provided
|
||||
* index
|
||||
* @param index the position of the attribute
|
||||
* @return the namespace URI (can be null)
|
||||
* @throws IllegalStateException if this is not a START_ELEMENT or ATTRIBUTE
|
||||
*/
|
||||
public String getAttributeNamespace(int index);
|
||||
|
||||
/**
|
||||
* Returns the localName of the attribute at the provided
|
||||
* index
|
||||
* @param index the position of the attribute
|
||||
* @return the localName of the attribute
|
||||
* @throws IllegalStateException if this is not a START_ELEMENT or ATTRIBUTE
|
||||
*/
|
||||
public String getAttributeLocalName(int index);
|
||||
|
||||
/**
|
||||
* Returns the prefix of this attribute at the
|
||||
* provided index
|
||||
* @param index the position of the attribute
|
||||
* @return the prefix of the attribute
|
||||
* @throws IllegalStateException if this is not a START_ELEMENT or ATTRIBUTE
|
||||
*/
|
||||
public String getAttributePrefix(int index);
|
||||
|
||||
/**
|
||||
* Returns the XML type of the attribute at the provided
|
||||
* index
|
||||
* @param index the position of the attribute
|
||||
* @return the XML type of the attribute
|
||||
* @throws IllegalStateException if this is not a START_ELEMENT or ATTRIBUTE
|
||||
*/
|
||||
public String getAttributeType(int index);
|
||||
|
||||
/**
|
||||
* Returns the value of the attribute at the
|
||||
* index
|
||||
* @param index the position of the attribute
|
||||
* @return the attribute value
|
||||
* @throws IllegalStateException if this is not a START_ELEMENT or ATTRIBUTE
|
||||
*/
|
||||
public String getAttributeValue(int index);
|
||||
|
||||
/**
|
||||
* Returns a boolean which indicates if this
|
||||
* attribute was created by default
|
||||
* @param index the position of the attribute
|
||||
* @return true if this is a default attribute
|
||||
* @throws IllegalStateException if this is not a START_ELEMENT or ATTRIBUTE
|
||||
*/
|
||||
public boolean isAttributeSpecified(int index);
|
||||
|
||||
/**
|
||||
* Returns the count of namespaces declared on this START_ELEMENT or END_ELEMENT,
|
||||
* this method is only valid on a START_ELEMENT, END_ELEMENT or NAMESPACE. On
|
||||
* an END_ELEMENT the count is of the namespaces that are about to go
|
||||
* out of scope. This is the equivalent of the information reported
|
||||
* by SAX callback for an end element event.
|
||||
* @return returns the number of namespace declarations on this specific element
|
||||
* @throws IllegalStateException if this is not a START_ELEMENT, END_ELEMENT or NAMESPACE
|
||||
*/
|
||||
public int getNamespaceCount();
|
||||
|
||||
/**
|
||||
* Returns the prefix for the namespace declared at the
|
||||
* index. Returns null if this is the default namespace
|
||||
* declaration
|
||||
*
|
||||
* @param index the position of the namespace declaration
|
||||
* @return returns the namespace prefix
|
||||
* @throws IllegalStateException if this is not a START_ELEMENT, END_ELEMENT or NAMESPACE
|
||||
*/
|
||||
public String getNamespacePrefix(int index);
|
||||
|
||||
/**
|
||||
* Returns the uri for the namespace declared at the
|
||||
* index.
|
||||
*
|
||||
* @param index the position of the namespace declaration
|
||||
* @return returns the namespace uri
|
||||
* @throws IllegalStateException if this is not a START_ELEMENT, END_ELEMENT or NAMESPACE
|
||||
*/
|
||||
public String getNamespaceURI(int index);
|
||||
|
||||
/**
|
||||
* Returns a read only namespace context for the current
|
||||
* position. The context is transient and only valid until
|
||||
* a call to next() changes the state of the reader.
|
||||
* @return return a namespace context
|
||||
*/
|
||||
public NamespaceContext getNamespaceContext();
|
||||
|
||||
/**
|
||||
* Returns a reader that points to the current start element
|
||||
* and all of its contents. Throws an XMLStreamException if the
|
||||
* cursor does not point to a START_ELEMENT.<p>
|
||||
* The sub stream is read from it MUST be read before the parent stream is
|
||||
* moved on, if not any call on the sub stream will cause an XMLStreamException to be
|
||||
* thrown. The parent stream will always return the same result from next()
|
||||
* whatever is done to the sub stream.
|
||||
* @return an XMLStreamReader which points to the next element
|
||||
*/
|
||||
// public XMLStreamReader subReader() throws XMLStreamException;
|
||||
|
||||
/**
|
||||
* Allows the implementation to reset and reuse any underlying tables
|
||||
*/
|
||||
// public void recycle() throws XMLStreamException;
|
||||
|
||||
/**
|
||||
* Returns an integer code that indicates the type
|
||||
* of the event the cursor is pointing to.
|
||||
*/
|
||||
public int getEventType();
|
||||
|
||||
/**
|
||||
* Returns the current value of the parse event as a string,
|
||||
* this returns the string value of a CHARACTERS event,
|
||||
* returns the value of a COMMENT, the replacement value
|
||||
* for an ENTITY_REFERENCE, the string value of a CDATA section,
|
||||
* the string value for a SPACE event,
|
||||
* or the String value of the internal subset of the DTD.
|
||||
* If an ENTITY_REFERENCE has been resolved, any character data
|
||||
* will be reported as CHARACTERS events.
|
||||
* @return the current text or null
|
||||
* @throws java.lang.IllegalStateException if this state is not
|
||||
* a valid text state.
|
||||
*/
|
||||
public String getText();
|
||||
|
||||
/**
|
||||
* Returns an array which contains the characters from this event.
|
||||
* This array should be treated as read-only and transient. I.e. the array will
|
||||
* contain the text characters until the XMLStreamReader moves on to the next event.
|
||||
* Attempts to hold onto the character array beyond that time or modify the
|
||||
* contents of the array are breaches of the contract for this interface.
|
||||
* @return the current text or an empty array
|
||||
* @throws java.lang.IllegalStateException if this state is not
|
||||
* a valid text state.
|
||||
*/
|
||||
public char[] getTextCharacters();
|
||||
|
||||
/**
|
||||
* Gets the the text associated with a CHARACTERS, SPACE or CDATA event.
|
||||
* Text starting a "sourceStart" is copied into "target" starting at "targetStart".
|
||||
* Up to "length" characters are copied. The number of characters actually copied is returned.
|
||||
*
|
||||
* The "sourceStart" argument must be greater or equal to 0 and less than or equal to
|
||||
* the number of characters associated with the event. Usually, one requests text starting at a "sourceStart" of 0.
|
||||
* If the number of characters actually copied is less than the "length", then there is no more text.
|
||||
* Otherwise, subsequent calls need to be made until all text has been retrieved. For example:
|
||||
*
|
||||
*<code>
|
||||
* int length = 1024;
|
||||
* char[] myBuffer = new char[ length ];
|
||||
*
|
||||
* for ( int sourceStart = 0 ; ; sourceStart += length )
|
||||
* {
|
||||
* int nCopied = stream.getTextCharacters( sourceStart, myBuffer, 0, length );
|
||||
*
|
||||
* if (nCopied < length)
|
||||
* break;
|
||||
* }
|
||||
* </code>
|
||||
* XMLStreamException may be thrown if there are any XML errors in the underlying source.
|
||||
* The "targetStart" argument must be greater than or equal to 0 and less than the length of "target",
|
||||
* Length must be greater than 0 and "targetStart + length" must be less than or equal to length of "target".
|
||||
*
|
||||
* @param sourceStart the index of the first character in the source array to copy
|
||||
* @param target the destination array
|
||||
* @param targetStart the start offset in the target array
|
||||
* @param length the number of characters to copy
|
||||
* @return the number of characters actually copied
|
||||
* @throws XMLStreamException if the underlying XML source is not well-formed
|
||||
* @throws IndexOutOfBoundsException if targetStart < 0 or > than the length of target
|
||||
* @throws IndexOutOfBoundsException if length < 0 or targetStart + length > length of target
|
||||
* @throws UnsupportedOperationException if this method is not supported
|
||||
* @throws NullPointerException is if target is null
|
||||
*/
|
||||
public int getTextCharacters(int sourceStart, char[] target, int targetStart, int length)
|
||||
throws XMLStreamException;
|
||||
|
||||
/**
|
||||
* Gets the text associated with a CHARACTERS, SPACE or CDATA event. Allows the underlying
|
||||
* implementation to return the text as a stream of characters. The reference to the
|
||||
* Reader returned by this method is only valid until next() is called.
|
||||
*
|
||||
* All characters must have been checked for well-formedness.
|
||||
*
|
||||
* <p> This method is optional and will throw UnsupportedOperationException if it is not supported.
|
||||
* @throws UnsupportedOperationException if this method is not supported
|
||||
* @throws IllegalStateException if this is not a valid text state
|
||||
*/
|
||||
//public Reader getTextStream();
|
||||
|
||||
/**
|
||||
* Returns the offset into the text character array where the first
|
||||
* character (of this text event) is stored.
|
||||
* @throws java.lang.IllegalStateException if this state is not
|
||||
* a valid text state.
|
||||
*/
|
||||
public int getTextStart();
|
||||
|
||||
/**
|
||||
* Returns the length of the sequence of characters for this
|
||||
* Text event within the text character array.
|
||||
* @throws java.lang.IllegalStateException if this state is not
|
||||
* a valid text state.
|
||||
*/
|
||||
public int getTextLength();
|
||||
|
||||
/**
|
||||
* Return input encoding if known or null if unknown.
|
||||
* @return the encoding of this instance or null
|
||||
*/
|
||||
public String getEncoding();
|
||||
|
||||
/**
|
||||
* Return true if the current event has text, false otherwise
|
||||
* The following events have text:
|
||||
* CHARACTERS,DTD ,ENTITY_REFERENCE, COMMENT, SPACE
|
||||
*/
|
||||
public boolean hasText();
|
||||
|
||||
/**
|
||||
* Return the current location of the processor.
|
||||
* If the Location is unknown the processor should return
|
||||
* an implementation of Location that returns -1 for the
|
||||
* location and null for the publicId and systemId.
|
||||
* The location information is only valid until next() is
|
||||
* called.
|
||||
*/
|
||||
public Location getLocation();
|
||||
|
||||
/**
|
||||
* Returns a QName for the current START_ELEMENT or END_ELEMENT event
|
||||
* @return the QName for the current START_ELEMENT or END_ELEMENT event
|
||||
* @throws IllegalStateException if this is not a START_ELEMENT or
|
||||
* END_ELEMENT
|
||||
*/
|
||||
public QName getName();
|
||||
|
||||
/**
|
||||
* Returns the (local) name of the current event.
|
||||
* For START_ELEMENT or END_ELEMENT returns the (local) name of the current element.
|
||||
* For ENTITY_REFERENCE it returns entity name.
|
||||
* The current event must be START_ELEMENT or END_ELEMENT,
|
||||
* or ENTITY_REFERENCE
|
||||
* @return the localName
|
||||
* @throws IllegalStateException if this not a START_ELEMENT,
|
||||
* END_ELEMENT or ENTITY_REFERENCE
|
||||
*/
|
||||
public String getLocalName();
|
||||
|
||||
/**
|
||||
* returns true if the current event has a name (is a START_ELEMENT or END_ELEMENT)
|
||||
* returns false otherwise
|
||||
*/
|
||||
public boolean hasName();
|
||||
|
||||
/**
|
||||
* If the current event is a START_ELEMENT or END_ELEMENT this method
|
||||
* returns the URI of the prefix or the default namespace.
|
||||
* Returns null if the event does not have a prefix.
|
||||
* @return the URI bound to this elements prefix, the default namespace, or null
|
||||
*/
|
||||
public String getNamespaceURI();
|
||||
|
||||
/**
|
||||
* Returns the prefix of the current event or null if the event does not have a prefix
|
||||
* @return the prefix or null
|
||||
*/
|
||||
public String getPrefix();
|
||||
|
||||
/**
|
||||
* Get the xml version declared on the xml declaration
|
||||
* Returns null if none was declared
|
||||
* @return the XML version or null
|
||||
*/
|
||||
public String getVersion();
|
||||
|
||||
/**
|
||||
* Get the standalone declaration from the xml declaration
|
||||
* @return true if this is standalone, or false otherwise
|
||||
*/
|
||||
public boolean isStandalone();
|
||||
|
||||
/**
|
||||
* Checks if standalone was set in the document
|
||||
* @return true if standalone was set in the document, or false otherwise
|
||||
*/
|
||||
public boolean standaloneSet();
|
||||
|
||||
/**
|
||||
* Returns the character encoding declared on the xml declaration
|
||||
* Returns null if none was declared
|
||||
* @return the encoding declared in the document or null
|
||||
*/
|
||||
public String getCharacterEncodingScheme();
|
||||
|
||||
/**
|
||||
* Get the target of a processing instruction
|
||||
* @return the target or null
|
||||
*/
|
||||
public String getPITarget();
|
||||
|
||||
/**
|
||||
* Get the data section of a processing instruction
|
||||
* @return the data or null
|
||||
*/
|
||||
public String getPIData();
|
||||
}
|
|
@ -0,0 +1,528 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 by Oracle Corporation. All Rights Reserved.
|
||||
*/
|
||||
|
||||
package javax.xml.stream;
|
||||
|
||||
import javax.xml.namespace.NamespaceContext;
|
||||
|
||||
/**
|
||||
* The XMLStreamWriter interface specifies how to write XML. The XMLStreamWriter does
|
||||
* not perform well formedness checking on its input. However
|
||||
* the writeCharacters method is required to escape & , < and >
|
||||
* For attribute values the writeAttribute method will escape the
|
||||
* above characters plus " to ensure that all character content
|
||||
* and attribute values are well formed.
|
||||
*
|
||||
* Each NAMESPACE
|
||||
* and ATTRIBUTE must be individually written.
|
||||
*
|
||||
* <table border="1" cellpadding="2" cellspacing="0">
|
||||
* <thead>
|
||||
* <tr>
|
||||
* <th colspan="5">XML Namespaces, <code>javax.xml.stream.isRepairingNamespaces</code> and write method behaviour</th>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <th>Method</th> <!-- method -->
|
||||
* <th colspan="2"><code>isRepairingNamespaces</code> == true</th>
|
||||
* <th colspan="2"><code>isRepairingNamespaces</code> == false</th>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <th></th> <!-- method -->
|
||||
* <th>namespaceURI bound</th>
|
||||
* <th>namespaceURI unbound</th>
|
||||
* <th>namespaceURI bound</th>
|
||||
* <th>namespaceURI unbound</th>
|
||||
* </tr>
|
||||
* </thead>
|
||||
*
|
||||
* <tbody>
|
||||
* <tr>
|
||||
* <th><code>writeAttribute(namespaceURI, localName, value)</code></th>
|
||||
* <!-- isRepairingNamespaces == true -->
|
||||
* <td>
|
||||
* <!-- namespaceURI bound -->
|
||||
* prefix:localName="value" <sup>[1]</sup>
|
||||
* </td>
|
||||
* <td>
|
||||
* <!-- namespaceURI unbound -->
|
||||
* xmlns:{generated}="namespaceURI" {generated}:localName="value"
|
||||
* </td>
|
||||
* <!-- isRepairingNamespaces == false -->
|
||||
* <td>
|
||||
* <!-- namespaceURI bound -->
|
||||
* prefix:localName="value" <sup>[1]</sup>
|
||||
* </td>
|
||||
* <td>
|
||||
* <!-- namespaceURI unbound -->
|
||||
* <code>XMLStreamException</code>
|
||||
* </td>
|
||||
* </tr>
|
||||
*
|
||||
* <tr>
|
||||
* <th><code>writeAttribute(prefix, namespaceURI, localName, value)</code></th>
|
||||
* <!-- isRepairingNamespaces == true -->
|
||||
* <td>
|
||||
* <!-- namespaceURI bound -->
|
||||
* bound to same prefix:<br />
|
||||
* prefix:localName="value" <sup>[1]</sup><br />
|
||||
* <br />
|
||||
* bound to different prefix:<br />
|
||||
* xmlns:{generated}="namespaceURI" {generated}:localName="value"
|
||||
* </td>
|
||||
* <td>
|
||||
* <!-- namespaceURI unbound -->
|
||||
* xmlns:prefix="namespaceURI" prefix:localName="value" <sup>[3]</sup>
|
||||
* </td>
|
||||
* <!-- isRepairingNamespaces == false -->
|
||||
* <td>
|
||||
* <!-- namespaceURI bound -->
|
||||
* bound to same prefix:<br />
|
||||
* prefix:localName="value" <sup>[1][2]</sup><br />
|
||||
* <br />
|
||||
* bound to different prefix:<br />
|
||||
* <code>XMLStreamException</code><sup>[2]</sup>
|
||||
* </td>
|
||||
* <td>
|
||||
* <!-- namespaceURI unbound -->
|
||||
* xmlns:prefix="namespaceURI" prefix:localName="value" <sup>[2][5]</sup>
|
||||
* </td>
|
||||
* </tr>
|
||||
*
|
||||
* <tr>
|
||||
* <th><code>writeStartElement(namespaceURI, localName)</code><br />
|
||||
* <br />
|
||||
* <code>writeEmptyElement(namespaceURI, localName)</code></th>
|
||||
* <!-- isRepairingNamespaces == true -->
|
||||
* <td >
|
||||
* <!-- namespaceURI bound -->
|
||||
* <prefix:localName> <sup>[1]</sup>
|
||||
* </td>
|
||||
* <td>
|
||||
* <!-- namespaceURI unbound -->
|
||||
* <{generated}:localName xmlns:{generated}="namespaceURI">
|
||||
* </td>
|
||||
* <!-- isRepairingNamespaces == false -->
|
||||
* <td>
|
||||
* <!-- namespaceURI bound -->
|
||||
* <prefix:localName> <sup>[1]</sup>
|
||||
* </td>
|
||||
* <td>
|
||||
* <!-- namespaceURI unbound -->
|
||||
* <code>XMLStreamException</code>
|
||||
* </td>
|
||||
* </tr>
|
||||
*
|
||||
* <tr>
|
||||
* <th><code>writeStartElement(prefix, localName, namespaceURI)</code><br />
|
||||
* <br />
|
||||
* <code>writeEmptyElement(prefix, localName, namespaceURI)</code></th>
|
||||
* <!-- isRepairingNamespaces == true -->
|
||||
* <td>
|
||||
* <!-- namespaceURI bound -->
|
||||
* bound to same prefix:<br />
|
||||
* <prefix:localName> <sup>[1]</sup><br />
|
||||
* <br />
|
||||
* bound to different prefix:<br />
|
||||
* <{generated}:localName xmlns:{generated}="namespaceURI">
|
||||
* </td>
|
||||
* <td>
|
||||
* <!-- namespaceURI unbound -->
|
||||
* <prefix:localName xmlns:prefix="namespaceURI"> <sup>[4]</sup>
|
||||
* </td>
|
||||
* <!-- isRepairingNamespaces == false -->
|
||||
* <td>
|
||||
* <!-- namespaceURI bound -->
|
||||
* bound to same prefix:<br />
|
||||
* <prefix:localName> <sup>[1]</sup><br />
|
||||
* <br />
|
||||
* bound to different prefix:<br />
|
||||
* <code>XMLStreamException</code>
|
||||
* </td>
|
||||
* <td>
|
||||
* <!-- namespaceURI unbound -->
|
||||
* <prefix:localName>
|
||||
* </td>
|
||||
* </tr>
|
||||
* </tbody>
|
||||
* <tfoot>
|
||||
* <tr>
|
||||
* <td colspan="5">
|
||||
* Notes:
|
||||
* <ul>
|
||||
* <li>[1] if namespaceURI == default Namespace URI, then no prefix is written</li>
|
||||
* <li>[2] if prefix == "" || null && namespaceURI == "", then no prefix or Namespace declaration is generated or written</li>
|
||||
* <li>[3] if prefix == "" || null, then a prefix is randomly generated</li>
|
||||
* <li>[4] if prefix == "" || null, then it is treated as the default Namespace and no prefix is generated or written, an xmlns declaration is generated and written if the namespaceURI is unbound</li>
|
||||
* <li>[5] if prefix == "" || null, then it is treated as an invalid attempt to define the default Namespace and an XMLStreamException is thrown</li>
|
||||
* </ul>
|
||||
* </td>
|
||||
* </tr>
|
||||
* </tfoot>
|
||||
* </table>
|
||||
*
|
||||
* @version 1.0
|
||||
* @author Copyright (c) 2009 by Oracle Corporation. All Rights Reserved.
|
||||
* @see XMLOutputFactory
|
||||
* @see XMLStreamReader
|
||||
* @since 1.6
|
||||
*/
|
||||
public interface XMLStreamWriter {
|
||||
|
||||
/**
|
||||
* Writes a start tag to the output. All writeStartElement methods
|
||||
* open a new scope in the internal namespace context. Writing the
|
||||
* corresponding EndElement causes the scope to be closed.
|
||||
* @param localName local name of the tag, may not be null
|
||||
* @throws XMLStreamException
|
||||
*/
|
||||
public void writeStartElement(String localName)
|
||||
throws XMLStreamException;
|
||||
|
||||
/**
|
||||
* Writes a start tag to the output
|
||||
* @param namespaceURI the namespaceURI of the prefix to use, may not be null
|
||||
* @param localName local name of the tag, may not be null
|
||||
* @throws XMLStreamException if the namespace URI has not been bound to a prefix and
|
||||
* javax.xml.stream.isRepairingNamespaces has not been set to true
|
||||
*/
|
||||
public void writeStartElement(String namespaceURI, String localName)
|
||||
throws XMLStreamException;
|
||||
|
||||
/**
|
||||
* Writes a start tag to the output
|
||||
* @param localName local name of the tag, may not be null
|
||||
* @param prefix the prefix of the tag, may not be null
|
||||
* @param namespaceURI the uri to bind the prefix to, may not be null
|
||||
* @throws XMLStreamException
|
||||
*/
|
||||
public void writeStartElement(String prefix,
|
||||
String localName,
|
||||
String namespaceURI)
|
||||
throws XMLStreamException;
|
||||
|
||||
/**
|
||||
* Writes an empty element tag to the output
|
||||
* @param namespaceURI the uri to bind the tag to, may not be null
|
||||
* @param localName local name of the tag, may not be null
|
||||
* @throws XMLStreamException if the namespace URI has not been bound to a prefix and
|
||||
* javax.xml.stream.isRepairingNamespaces has not been set to true
|
||||
*/
|
||||
public void writeEmptyElement(String namespaceURI, String localName)
|
||||
throws XMLStreamException;
|
||||
|
||||
/**
|
||||
* Writes an empty element tag to the output
|
||||
* @param prefix the prefix of the tag, may not be null
|
||||
* @param localName local name of the tag, may not be null
|
||||
* @param namespaceURI the uri to bind the tag to, may not be null
|
||||
* @throws XMLStreamException
|
||||
*/
|
||||
public void writeEmptyElement(String prefix, String localName, String namespaceURI)
|
||||
throws XMLStreamException;
|
||||
|
||||
/**
|
||||
* Writes an empty element tag to the output
|
||||
* @param localName local name of the tag, may not be null
|
||||
* @throws XMLStreamException
|
||||
*/
|
||||
public void writeEmptyElement(String localName)
|
||||
throws XMLStreamException;
|
||||
|
||||
/**
|
||||
* Writes string data to the output without checking for well formedness.
|
||||
* The data is opaque to the XMLStreamWriter, i.e. the characters are written
|
||||
* blindly to the underlying output. If the method cannot be supported
|
||||
* in the currrent writing context the implementation may throw a
|
||||
* UnsupportedOperationException. For example note that any
|
||||
* namespace declarations, end tags, etc. will be ignored and could
|
||||
* interfere with proper maintanence of the writers internal state.
|
||||
*
|
||||
* @param data the data to write
|
||||
*/
|
||||
// public void writeRaw(String data) throws XMLStreamException;
|
||||
|
||||
/**
|
||||
* Writes an end tag to the output relying on the internal
|
||||
* state of the writer to determine the prefix and local name
|
||||
* of the event.
|
||||
* @throws XMLStreamException
|
||||
*/
|
||||
public void writeEndElement()
|
||||
throws XMLStreamException;
|
||||
|
||||
/**
|
||||
* Closes any start tags and writes corresponding end tags.
|
||||
* @throws XMLStreamException
|
||||
*/
|
||||
public void writeEndDocument()
|
||||
throws XMLStreamException;
|
||||
|
||||
/**
|
||||
* Close this writer and free any resources associated with the
|
||||
* writer. This must not close the underlying output stream.
|
||||
* @throws XMLStreamException
|
||||
*/
|
||||
public void close()
|
||||
throws XMLStreamException;
|
||||
|
||||
/**
|
||||
* Write any cached data to the underlying output mechanism.
|
||||
* @throws XMLStreamException
|
||||
*/
|
||||
public void flush()
|
||||
throws XMLStreamException;
|
||||
|
||||
/**
|
||||
* Writes an attribute to the output stream without
|
||||
* a prefix.
|
||||
* @param localName the local name of the attribute
|
||||
* @param value the value of the attribute
|
||||
* @throws IllegalStateException if the current state does not allow Attribute writing
|
||||
* @throws XMLStreamException
|
||||
*/
|
||||
public void writeAttribute(String localName, String value)
|
||||
throws XMLStreamException;
|
||||
|
||||
/**
|
||||
* Writes an attribute to the output stream
|
||||
* @param prefix the prefix for this attribute
|
||||
* @param namespaceURI the uri of the prefix for this attribute
|
||||
* @param localName the local name of the attribute
|
||||
* @param value the value of the attribute
|
||||
* @throws IllegalStateException if the current state does not allow Attribute writing
|
||||
* @throws XMLStreamException if the namespace URI has not been bound to a prefix and
|
||||
* javax.xml.stream.isRepairingNamespaces has not been set to true
|
||||
*/
|
||||
|
||||
public void writeAttribute(String prefix,
|
||||
String namespaceURI,
|
||||
String localName,
|
||||
String value)
|
||||
throws XMLStreamException;
|
||||
|
||||
/**
|
||||
* Writes an attribute to the output stream
|
||||
* @param namespaceURI the uri of the prefix for this attribute
|
||||
* @param localName the local name of the attribute
|
||||
* @param value the value of the attribute
|
||||
* @throws IllegalStateException if the current state does not allow Attribute writing
|
||||
* @throws XMLStreamException if the namespace URI has not been bound to a prefix and
|
||||
* javax.xml.stream.isRepairingNamespaces has not been set to true
|
||||
*/
|
||||
public void writeAttribute(String namespaceURI,
|
||||
String localName,
|
||||
String value)
|
||||
throws XMLStreamException;
|
||||
|
||||
/**
|
||||
* Writes a namespace to the output stream
|
||||
* If the prefix argument to this method is the empty string,
|
||||
* "xmlns", or null this method will delegate to writeDefaultNamespace
|
||||
*
|
||||
* @param prefix the prefix to bind this namespace to
|
||||
* @param namespaceURI the uri to bind the prefix to
|
||||
* @throws IllegalStateException if the current state does not allow Namespace writing
|
||||
* @throws XMLStreamException
|
||||
*/
|
||||
public void writeNamespace(String prefix, String namespaceURI)
|
||||
throws XMLStreamException;
|
||||
|
||||
/**
|
||||
* Writes the default namespace to the stream
|
||||
* @param namespaceURI the uri to bind the default namespace to
|
||||
* @throws IllegalStateException if the current state does not allow Namespace writing
|
||||
* @throws XMLStreamException
|
||||
*/
|
||||
public void writeDefaultNamespace(String namespaceURI)
|
||||
throws XMLStreamException;
|
||||
|
||||
/**
|
||||
* Writes an xml comment with the data enclosed
|
||||
* @param data the data contained in the comment, may be null
|
||||
* @throws XMLStreamException
|
||||
*/
|
||||
public void writeComment(String data)
|
||||
throws XMLStreamException;
|
||||
|
||||
/**
|
||||
* Writes a processing instruction
|
||||
* @param target the target of the processing instruction, may not be null
|
||||
* @throws XMLStreamException
|
||||
*/
|
||||
public void writeProcessingInstruction(String target)
|
||||
throws XMLStreamException;
|
||||
|
||||
/**
|
||||
* Writes a processing instruction
|
||||
* @param target the target of the processing instruction, may not be null
|
||||
* @param data the data contained in the processing instruction, may not be null
|
||||
* @throws XMLStreamException
|
||||
*/
|
||||
public void writeProcessingInstruction(String target,
|
||||
String data)
|
||||
throws XMLStreamException;
|
||||
|
||||
/**
|
||||
* Writes a CData section
|
||||
* @param data the data contained in the CData Section, may not be null
|
||||
* @throws XMLStreamException
|
||||
*/
|
||||
public void writeCData(String data)
|
||||
throws XMLStreamException;
|
||||
|
||||
/**
|
||||
* Write a DTD section. This string represents the entire doctypedecl production
|
||||
* from the XML 1.0 specification.
|
||||
*
|
||||
* @param dtd the DTD to be written
|
||||
* @throws XMLStreamException
|
||||
*/
|
||||
public void writeDTD(String dtd)
|
||||
throws XMLStreamException;
|
||||
|
||||
/**
|
||||
* Writes an entity reference
|
||||
* @param name the name of the entity
|
||||
* @throws XMLStreamException
|
||||
*/
|
||||
public void writeEntityRef(String name)
|
||||
throws XMLStreamException;
|
||||
|
||||
/**
|
||||
* Write the XML Declaration. Defaults the XML version to 1.0, and the encoding to utf-8
|
||||
* @throws XMLStreamException
|
||||
*/
|
||||
public void writeStartDocument()
|
||||
throws XMLStreamException;
|
||||
|
||||
/**
|
||||
* Write the XML Declaration. Defaults the XML version to 1.0
|
||||
* @param version version of the xml document
|
||||
* @throws XMLStreamException
|
||||
*/
|
||||
public void writeStartDocument(String version)
|
||||
throws XMLStreamException;
|
||||
|
||||
/**
|
||||
* Write the XML Declaration. Note that the encoding parameter does
|
||||
* not set the actual encoding of the underlying output. That must
|
||||
* be set when the instance of the XMLStreamWriter is created using the
|
||||
* XMLOutputFactory
|
||||
* @param encoding encoding of the xml declaration
|
||||
* @param version version of the xml document
|
||||
* @throws XMLStreamException If given encoding does not match encoding
|
||||
* of the underlying stream
|
||||
*/
|
||||
public void writeStartDocument(String encoding,
|
||||
String version)
|
||||
throws XMLStreamException;
|
||||
|
||||
/**
|
||||
* Write text to the output
|
||||
* @param text the value to write
|
||||
* @throws XMLStreamException
|
||||
*/
|
||||
public void writeCharacters(String text)
|
||||
throws XMLStreamException;
|
||||
|
||||
/**
|
||||
* Write text to the output
|
||||
* @param text the value to write
|
||||
* @param start the starting position in the array
|
||||
* @param len the number of characters to write
|
||||
* @throws XMLStreamException
|
||||
*/
|
||||
public void writeCharacters(char[] text, int start, int len)
|
||||
throws XMLStreamException;
|
||||
|
||||
/**
|
||||
* Gets the prefix the uri is bound to
|
||||
* @return the prefix or null
|
||||
* @throws XMLStreamException
|
||||
*/
|
||||
public String getPrefix(String uri)
|
||||
throws XMLStreamException;
|
||||
|
||||
/**
|
||||
* Sets the prefix the uri is bound to. This prefix is bound
|
||||
* in the scope of the current START_ELEMENT / END_ELEMENT pair.
|
||||
* If this method is called before a START_ELEMENT has been written
|
||||
* the prefix is bound in the root scope.
|
||||
* @param prefix the prefix to bind to the uri, may not be null
|
||||
* @param uri the uri to bind to the prefix, may be null
|
||||
* @throws XMLStreamException
|
||||
*/
|
||||
public void setPrefix(String prefix, String uri)
|
||||
throws XMLStreamException;
|
||||
|
||||
|
||||
/**
|
||||
* Binds a URI to the default namespace
|
||||
* This URI is bound
|
||||
* in the scope of the current START_ELEMENT / END_ELEMENT pair.
|
||||
* If this method is called before a START_ELEMENT has been written
|
||||
* the uri is bound in the root scope.
|
||||
* @param uri the uri to bind to the default namespace, may be null
|
||||
* @throws XMLStreamException
|
||||
*/
|
||||
public void setDefaultNamespace(String uri)
|
||||
throws XMLStreamException;
|
||||
|
||||
/**
|
||||
* Sets the current namespace context for prefix and uri bindings.
|
||||
* This context becomes the root namespace context for writing and
|
||||
* will replace the current root namespace context. Subsequent calls
|
||||
* to setPrefix and setDefaultNamespace will bind namespaces using
|
||||
* the context passed to the method as the root context for resolving
|
||||
* namespaces. This method may only be called once at the start of
|
||||
* the document. It does not cause the namespaces to be declared.
|
||||
* If a namespace URI to prefix mapping is found in the namespace
|
||||
* context it is treated as declared and the prefix may be used
|
||||
* by the StreamWriter.
|
||||
* @param context the namespace context to use for this writer, may not be null
|
||||
* @throws XMLStreamException
|
||||
*/
|
||||
public void setNamespaceContext(NamespaceContext context)
|
||||
throws XMLStreamException;
|
||||
|
||||
/**
|
||||
* Returns the current namespace context.
|
||||
* @return the current NamespaceContext
|
||||
*/
|
||||
public NamespaceContext getNamespaceContext();
|
||||
|
||||
/**
|
||||
* Get the value of a feature/property from the underlying implementation
|
||||
* @param name The name of the property, may not be null
|
||||
* @return The value of the property
|
||||
* @throws IllegalArgumentException if the property is not supported
|
||||
* @throws NullPointerException if the name is null
|
||||
*/
|
||||
public Object getProperty(java.lang.String name) throws IllegalArgumentException;
|
||||
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 by Oracle Corporation. All Rights Reserved.
|
||||
*/
|
||||
|
||||
package javax.xml.stream.events;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
/**
|
||||
* An interface that contains information about an attribute. Attributes are reported
|
||||
* as a set of events accessible from a StartElement. Other applications may report
|
||||
* Attributes as first-order events, for example as the results of an XPath expression.
|
||||
*
|
||||
* @version 1.0
|
||||
* @author Copyright (c) 2009 by Oracle Corporation. All Rights Reserved.
|
||||
* @see StartElement
|
||||
* @since 1.6
|
||||
*/
|
||||
public interface Attribute extends XMLEvent {
|
||||
|
||||
/**
|
||||
* Returns the QName for this attribute
|
||||
*/
|
||||
QName getName();
|
||||
|
||||
/**
|
||||
* Gets the normalized value of this attribute
|
||||
*/
|
||||
public String getValue();
|
||||
|
||||
/**
|
||||
* Gets the type of this attribute, default is
|
||||
* the String "CDATA"
|
||||
* @return the type as a String, default is "CDATA"
|
||||
*/
|
||||
public String getDTDType();
|
||||
|
||||
/**
|
||||
* A flag indicating whether this attribute was actually
|
||||
* specified in the start-tag of its element, or was defaulted from the schema.
|
||||
* @return returns true if this was specified in the start element
|
||||
*/
|
||||
public boolean isSpecified();
|
||||
|
||||
}
|
|
@ -0,0 +1,76 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 by Oracle Corporation. All Rights Reserved.
|
||||
*/
|
||||
|
||||
package javax.xml.stream.events;
|
||||
|
||||
/**
|
||||
* This describes the interface to Characters events.
|
||||
* All text events get reported as Characters events.
|
||||
* Content, CData and whitespace are all reported as
|
||||
* Characters events. IgnorableWhitespace, in most cases,
|
||||
* will be set to false unless an element declaration of element
|
||||
* content is present for the current element.
|
||||
*
|
||||
* @version 1.0
|
||||
* @author Copyright (c) 2009 by Oracle Corporation. All Rights Reserved.
|
||||
* @since 1.6
|
||||
*/
|
||||
public interface Characters extends XMLEvent {
|
||||
/**
|
||||
* Get the character data of this event
|
||||
*/
|
||||
public String getData();
|
||||
|
||||
/**
|
||||
* Returns true if this set of Characters
|
||||
* is all whitespace. Whitespace inside a document
|
||||
* is reported as CHARACTERS. This method allows
|
||||
* checking of CHARACTERS events to see if they
|
||||
* are composed of only whitespace characters
|
||||
*/
|
||||
public boolean isWhiteSpace();
|
||||
|
||||
/**
|
||||
* Returns true if this is a CData section. If this
|
||||
* event is CData its event type will be CDATA
|
||||
*
|
||||
* If javax.xml.stream.isCoalescing is set to true CDATA Sections
|
||||
* that are surrounded by non CDATA characters will be reported
|
||||
* as a single Characters event. This method will return false
|
||||
* in this case.
|
||||
*/
|
||||
public boolean isCData();
|
||||
|
||||
/**
|
||||
* Return true if this is ignorableWhiteSpace. If
|
||||
* this event is ignorableWhiteSpace its event type will
|
||||
* be SPACE.
|
||||
*/
|
||||
public boolean isIgnorableWhiteSpace();
|
||||
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 by Oracle Corporation. All Rights Reserved.
|
||||
*/
|
||||
|
||||
package javax.xml.stream.events;
|
||||
|
||||
/**
|
||||
* An interface for comment events
|
||||
*
|
||||
* @version 1.0
|
||||
* @author Copyright (c) 2009 by Oracle Corporation. All Rights Reserved.
|
||||
* @since 1.6
|
||||
*/
|
||||
public interface Comment extends XMLEvent {
|
||||
|
||||
/**
|
||||
* Return the string data of the comment, returns empty string if it
|
||||
* does not exist
|
||||
*/
|
||||
public String getText();
|
||||
}
|
|
@ -0,0 +1,74 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 by Oracle Corporation. All Rights Reserved.
|
||||
*/
|
||||
|
||||
package javax.xml.stream.events;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This is the top level interface for events dealing with DTDs
|
||||
*
|
||||
* @version 1.0
|
||||
* @author Copyright (c) 2009 by Oracle Corporation. All Rights Reserved.
|
||||
* @since 1.6
|
||||
*/
|
||||
public interface DTD extends XMLEvent {
|
||||
|
||||
/**
|
||||
* Returns the entire Document Type Declaration as a string, including
|
||||
* the internal DTD subset.
|
||||
* This may be null if there is not an internal subset.
|
||||
* If it is not null it must return the entire
|
||||
* Document Type Declaration which matches the doctypedecl
|
||||
* production in the XML 1.0 specification
|
||||
*/
|
||||
String getDocumentTypeDeclaration();
|
||||
|
||||
/**
|
||||
* Returns an implementation defined representation of the DTD.
|
||||
* This method may return null if no representation is available.
|
||||
*/
|
||||
Object getProcessedDTD();
|
||||
|
||||
/**
|
||||
* Return a List containing the notations declared in the DTD.
|
||||
* This list must contain NotationDeclaration events.
|
||||
* @see NotationDeclaration
|
||||
* @return an unordered list of NotationDeclaration events
|
||||
*/
|
||||
List getNotations();
|
||||
|
||||
/**
|
||||
* Return a List containing the general entities,
|
||||
* both external and internal, declared in the DTD.
|
||||
* This list must contain EntityDeclaration events.
|
||||
* @see EntityDeclaration
|
||||
* @return an unordered list of EntityDeclaration events
|
||||
*/
|
||||
List getEntities();
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 by Oracle Corporation. All Rights Reserved.
|
||||
*/
|
||||
|
||||
package javax.xml.stream.events;
|
||||
|
||||
/**
|
||||
* A marker interface for the end of the document
|
||||
*
|
||||
* @version 1.0
|
||||
* @author Copyright (c) 2009 by Oracle Corporation. All Rights Reserved.
|
||||
* @since 1.6
|
||||
*/
|
||||
public interface EndDocument extends XMLEvent {
|
||||
/**
|
||||
* No methods are defined in this interface.
|
||||
*/
|
||||
}
|
|
@ -0,0 +1,59 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 by Oracle Corporation. All Rights Reserved.
|
||||
*/
|
||||
|
||||
package javax.xml.stream.events;
|
||||
|
||||
import java.util.Iterator;
|
||||
import javax.xml.namespace.QName;
|
||||
/**
|
||||
* An interface for the end element event. An EndElement is reported
|
||||
* for each End Tag in the document.
|
||||
*
|
||||
* @version 1.0
|
||||
* @author Copyright (c) 2009 by Oracle Corporation. All Rights Reserved.
|
||||
* @see XMLEvent
|
||||
* @since 1.6
|
||||
*/
|
||||
public interface EndElement extends XMLEvent {
|
||||
|
||||
/**
|
||||
* Get the name of this event
|
||||
* @return the qualified name of this event
|
||||
*/
|
||||
public QName getName();
|
||||
|
||||
/**
|
||||
* Returns an Iterator of namespaces that have gone out
|
||||
* of scope. Returns an empty iterator if no namespaces have gone
|
||||
* out of scope.
|
||||
* @return an Iterator over Namespace interfaces, or an
|
||||
* empty iterator
|
||||
*/
|
||||
public Iterator getNamespaces();
|
||||
|
||||
}
|
|
@ -0,0 +1,80 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 by Oracle Corporation. All Rights Reserved.
|
||||
*/
|
||||
|
||||
package javax.xml.stream.events;
|
||||
/**
|
||||
* An interface for handling Entity Declarations
|
||||
*
|
||||
* This interface is used to record and report unparsed entity declarations.
|
||||
*
|
||||
* @version 1.0
|
||||
* @author Copyright (c) 2009 by Oracle Corporation. All Rights Reserved.
|
||||
* @since 1.6
|
||||
*/
|
||||
public interface EntityDeclaration extends XMLEvent {
|
||||
|
||||
/**
|
||||
* The entity's public identifier, or null if none was given
|
||||
* @return the public ID for this declaration or null
|
||||
*/
|
||||
String getPublicId();
|
||||
|
||||
/**
|
||||
* The entity's system identifier.
|
||||
* @return the system ID for this declaration or null
|
||||
*/
|
||||
String getSystemId();
|
||||
|
||||
/**
|
||||
* The entity's name
|
||||
* @return the name, may not be null
|
||||
*/
|
||||
String getName();
|
||||
|
||||
/**
|
||||
* The name of the associated notation.
|
||||
* @return the notation name
|
||||
*/
|
||||
String getNotationName();
|
||||
|
||||
/**
|
||||
* The replacement text of the entity.
|
||||
* This method will only return non-null
|
||||
* if this is an internal entity.
|
||||
* @return null or the replacment text
|
||||
*/
|
||||
String getReplacementText();
|
||||
|
||||
/**
|
||||
* Get the base URI for this reference
|
||||
* or null if this information is not available
|
||||
* @return the base URI or null
|
||||
*/
|
||||
String getBaseURI();
|
||||
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 by Oracle Corporation. All Rights Reserved.
|
||||
*/
|
||||
|
||||
package javax.xml.stream.events;
|
||||
/**
|
||||
* An interface for handling Entity events.
|
||||
*
|
||||
* This event reports entities that have not been resolved
|
||||
* and reports their replacement text unprocessed (if
|
||||
* available). This event will be reported if javax.xml.stream.isReplacingEntityReferences
|
||||
* is set to false. If javax.xml.stream.isReplacingEntityReferences is set to true
|
||||
* entity references will be resolved transparently.
|
||||
*
|
||||
* Entities are handled in two possible ways:
|
||||
*
|
||||
* (1) If javax.xml.stream.isReplacingEntityReferences is set to true
|
||||
* all entity references are resolved and reported as markup transparently.
|
||||
* (2) If javax.xml.stream.isReplacingEntityReferences is set to false
|
||||
* Entity references are reported as an EntityReference Event.
|
||||
*
|
||||
* @version 1.0
|
||||
* @author Copyright (c) 2009 by Oracle Corporation. All Rights Reserved.
|
||||
* @since 1.6
|
||||
*/
|
||||
public interface EntityReference extends XMLEvent {
|
||||
|
||||
/**
|
||||
* Return the declaration of this entity.
|
||||
*/
|
||||
EntityDeclaration getDeclaration();
|
||||
|
||||
/**
|
||||
* The name of the entity
|
||||
* @return the entity's name, may not be null
|
||||
*/
|
||||
String getName();
|
||||
}
|
|
@ -0,0 +1,59 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 by Oracle Corporation. All Rights Reserved.
|
||||
*/
|
||||
|
||||
package javax.xml.stream.events;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
/**
|
||||
* An interface that contains information about a namespace.
|
||||
* Namespaces are accessed from a StartElement.
|
||||
*
|
||||
* @version 1.0
|
||||
* @author Copyright (c) 2009 by Oracle Corporation. All Rights Reserved.
|
||||
* @see StartElement
|
||||
* @since 1.6
|
||||
*/
|
||||
public interface Namespace extends Attribute {
|
||||
|
||||
/**
|
||||
* Gets the prefix, returns "" if this is a default
|
||||
* namespace declaration.
|
||||
*/
|
||||
public String getPrefix();
|
||||
|
||||
/**
|
||||
* Gets the uri bound to the prefix of this namespace
|
||||
*/
|
||||
public String getNamespaceURI();
|
||||
|
||||
/**
|
||||
* returns true if this attribute declares the default namespace
|
||||
*/
|
||||
public boolean isDefaultNamespaceDeclaration();
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 by Oracle Corporation. All Rights Reserved.
|
||||
*/
|
||||
|
||||
package javax.xml.stream.events;
|
||||
/**
|
||||
* An interface for handling Notation Declarations
|
||||
*
|
||||
* Receive notification of a notation declaration event.
|
||||
* It is up to the application to record the notation for later reference,
|
||||
* At least one of publicId and systemId must be non-null.
|
||||
* There is no guarantee that the notation declaration
|
||||
* will be reported before any unparsed entities that use it.
|
||||
*
|
||||
* @version 1.0
|
||||
* @author Copyright (c) 2009 by Oracle Corporation. All Rights Reserved.
|
||||
* @since 1.6
|
||||
*/
|
||||
public interface NotationDeclaration extends XMLEvent {
|
||||
/**
|
||||
* The notation name.
|
||||
*/
|
||||
String getName();
|
||||
|
||||
/**
|
||||
* The notation's public identifier, or null if none was given.
|
||||
*/
|
||||
String getPublicId();
|
||||
|
||||
/**
|
||||
* The notation's system identifier, or null if none was given.
|
||||
*/
|
||||
String getSystemId();
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 by Oracle Corporation. All Rights Reserved.
|
||||
*/
|
||||
|
||||
package javax.xml.stream.events;
|
||||
/**
|
||||
* An interface that describes the data found in processing instructions
|
||||
*
|
||||
* @version 1.0
|
||||
* @author Copyright (c) 2009 by Oracle Corporation. All Rights Reserved.
|
||||
* @since 1.6
|
||||
*/
|
||||
public interface ProcessingInstruction extends XMLEvent {
|
||||
|
||||
/**
|
||||
* The target section of the processing instruction
|
||||
*
|
||||
* @return the String value of the PI or null
|
||||
*/
|
||||
public String getTarget();
|
||||
|
||||
/**
|
||||
* The data section of the processing instruction
|
||||
*
|
||||
* @return the String value of the PI's data or null
|
||||
*/
|
||||
public String getData();
|
||||
}
|
|
@ -0,0 +1,74 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 by Oracle Corporation. All Rights Reserved.
|
||||
*/
|
||||
|
||||
package javax.xml.stream.events;
|
||||
/**
|
||||
* An interface for the start document event
|
||||
*
|
||||
* @version 1.0
|
||||
* @author Copyright (c) 2009 by Oracle Corporation. All Rights Reserved.
|
||||
* @since 1.6
|
||||
*/
|
||||
public interface StartDocument extends XMLEvent {
|
||||
|
||||
/**
|
||||
* Returns the system ID of the XML data
|
||||
* @return the system ID, defaults to ""
|
||||
*/
|
||||
public String getSystemId();
|
||||
|
||||
/**
|
||||
* Returns the encoding style of the XML data
|
||||
* @return the character encoding, defaults to "UTF-8"
|
||||
*/
|
||||
public String getCharacterEncodingScheme();
|
||||
|
||||
/**
|
||||
* Returns true if CharacterEncodingScheme was set in
|
||||
* the encoding declaration of the document
|
||||
*/
|
||||
public boolean encodingSet();
|
||||
|
||||
/**
|
||||
* Returns if this XML is standalone
|
||||
* @return the standalone state of XML, defaults to "no"
|
||||
*/
|
||||
public boolean isStandalone();
|
||||
|
||||
/**
|
||||
* Returns true if the standalone attribute was set in
|
||||
* the encoding declaration of the document.
|
||||
*/
|
||||
public boolean standaloneSet();
|
||||
|
||||
/**
|
||||
* Returns the version of XML of this XML stream
|
||||
* @return the version of XML, defaults to "1.0"
|
||||
*/
|
||||
public String getVersion();
|
||||
}
|
|
@ -0,0 +1,117 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 by Oracle Corporation. All Rights Reserved.
|
||||
*/
|
||||
|
||||
package javax.xml.stream.events;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
import javax.xml.namespace.NamespaceContext;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
* The StartElement interface provides access to information about
|
||||
* start elements. A StartElement is reported for each Start Tag
|
||||
* in the document.
|
||||
*
|
||||
* @version 1.0
|
||||
* @author Copyright (c) 2009 by Oracle Corporation. All Rights Reserved.
|
||||
* @since 1.6
|
||||
*/
|
||||
public interface StartElement extends XMLEvent {
|
||||
|
||||
/**
|
||||
* Get the name of this event
|
||||
* @return the qualified name of this event
|
||||
*/
|
||||
public QName getName();
|
||||
|
||||
/**
|
||||
* Returns an Iterator of non-namespace declared attributes declared on
|
||||
* this START_ELEMENT,
|
||||
* returns an empty iterator if there are no attributes. The
|
||||
* iterator must contain only implementations of the javax.xml.stream.Attribute
|
||||
* interface. Attributes are fundamentally unordered and may not be reported
|
||||
* in any order.
|
||||
*
|
||||
* @return a readonly Iterator over Attribute interfaces, or an
|
||||
* empty iterator
|
||||
*/
|
||||
public Iterator getAttributes();
|
||||
|
||||
/**
|
||||
* Returns an Iterator of namespaces declared on this element.
|
||||
* This Iterator does not contain previously declared namespaces
|
||||
* unless they appear on the current START_ELEMENT.
|
||||
* Therefore this list may contain redeclared namespaces and duplicate namespace
|
||||
* declarations. Use the getNamespaceContext() method to get the
|
||||
* current context of namespace declarations.
|
||||
*
|
||||
* <p>The iterator must contain only implementations of the
|
||||
* javax.xml.stream.Namespace interface.
|
||||
*
|
||||
* <p>A Namespace isA Attribute. One
|
||||
* can iterate over a list of namespaces as a list of attributes.
|
||||
* However this method returns only the list of namespaces
|
||||
* declared on this START_ELEMENT and does not
|
||||
* include the attributes declared on this START_ELEMENT.
|
||||
*
|
||||
* Returns an empty iterator if there are no namespaces.
|
||||
*
|
||||
* @return a readonly Iterator over Namespace interfaces, or an
|
||||
* empty iterator
|
||||
*
|
||||
*/
|
||||
public Iterator getNamespaces();
|
||||
|
||||
/**
|
||||
* Returns the attribute referred to by this name
|
||||
* @param name the qname of the desired name
|
||||
* @return the attribute corresponding to the name value or null
|
||||
*/
|
||||
public Attribute getAttributeByName(QName name);
|
||||
|
||||
/**
|
||||
* Gets a read-only namespace context. If no context is
|
||||
* available this method will return an empty namespace context.
|
||||
* The NamespaceContext contains information about all namespaces
|
||||
* in scope for this StartElement.
|
||||
*
|
||||
* @return the current namespace context
|
||||
*/
|
||||
public NamespaceContext getNamespaceContext();
|
||||
|
||||
/**
|
||||
* Gets the value that the prefix is bound to in the
|
||||
* context of this element. Returns null if
|
||||
* the prefix is not bound in this context
|
||||
* @param prefix the prefix to lookup
|
||||
* @return the uri bound to the prefix or null
|
||||
*/
|
||||
public String getNamespaceURI(String prefix);
|
||||
}
|
|
@ -0,0 +1,178 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 by Oracle Corporation. All Rights Reserved.
|
||||
*/
|
||||
|
||||
package javax.xml.stream.events;
|
||||
|
||||
import java.io.Writer;
|
||||
import javax.xml.namespace.QName;
|
||||
/**
|
||||
* This is the base event interface for handling markup events.
|
||||
* Events are value objects that are used to communicate the
|
||||
* XML 1.0 InfoSet to the Application. Events may be cached
|
||||
* and referenced after the parse has completed.
|
||||
*
|
||||
* @version 1.0
|
||||
* @author Copyright (c) 2009 by Oracle Corporation. All Rights Reserved.
|
||||
* @see javax.xml.stream.XMLEventReader
|
||||
* @see Characters
|
||||
* @see ProcessingInstruction
|
||||
* @see StartElement
|
||||
* @see EndElement
|
||||
* @see StartDocument
|
||||
* @see EndDocument
|
||||
* @see EntityReference
|
||||
* @see EntityDeclaration
|
||||
* @see NotationDeclaration
|
||||
* @since 1.6
|
||||
*/
|
||||
public interface XMLEvent extends javax.xml.stream.XMLStreamConstants {
|
||||
|
||||
/**
|
||||
* Returns an integer code for this event.
|
||||
* @see #START_ELEMENT
|
||||
* @see #END_ELEMENT
|
||||
* @see #CHARACTERS
|
||||
* @see #ATTRIBUTE
|
||||
* @see #NAMESPACE
|
||||
* @see #PROCESSING_INSTRUCTION
|
||||
* @see #COMMENT
|
||||
* @see #START_DOCUMENT
|
||||
* @see #END_DOCUMENT
|
||||
* @see #DTD
|
||||
*/
|
||||
public int getEventType();
|
||||
|
||||
/**
|
||||
* Return the location of this event. The Location
|
||||
* returned from this method is non-volatile and
|
||||
* will retain its information.
|
||||
* @see javax.xml.stream.Location
|
||||
*/
|
||||
javax.xml.stream.Location getLocation();
|
||||
|
||||
/**
|
||||
* A utility function to check if this event is a StartElement.
|
||||
* @see StartElement
|
||||
*/
|
||||
public boolean isStartElement();
|
||||
|
||||
/**
|
||||
* A utility function to check if this event is an Attribute.
|
||||
* @see Attribute
|
||||
*/
|
||||
public boolean isAttribute();
|
||||
|
||||
/**
|
||||
* A utility function to check if this event is a Namespace.
|
||||
* @see Namespace
|
||||
*/
|
||||
public boolean isNamespace();
|
||||
|
||||
|
||||
/**
|
||||
* A utility function to check if this event is a EndElement.
|
||||
* @see EndElement
|
||||
*/
|
||||
public boolean isEndElement();
|
||||
|
||||
/**
|
||||
* A utility function to check if this event is an EntityReference.
|
||||
* @see EntityReference
|
||||
*/
|
||||
public boolean isEntityReference();
|
||||
|
||||
/**
|
||||
* A utility function to check if this event is a ProcessingInstruction.
|
||||
* @see ProcessingInstruction
|
||||
*/
|
||||
public boolean isProcessingInstruction();
|
||||
|
||||
/**
|
||||
* A utility function to check if this event is Characters.
|
||||
* @see Characters
|
||||
*/
|
||||
public boolean isCharacters();
|
||||
|
||||
/**
|
||||
* A utility function to check if this event is a StartDocument.
|
||||
* @see StartDocument
|
||||
*/
|
||||
public boolean isStartDocument();
|
||||
|
||||
/**
|
||||
* A utility function to check if this event is an EndDocument.
|
||||
* @see EndDocument
|
||||
*/
|
||||
public boolean isEndDocument();
|
||||
|
||||
/**
|
||||
* Returns this event as a start element event, may result in
|
||||
* a class cast exception if this event is not a start element.
|
||||
*/
|
||||
public StartElement asStartElement();
|
||||
|
||||
/**
|
||||
* Returns this event as an end element event, may result in
|
||||
* a class cast exception if this event is not a end element.
|
||||
*/
|
||||
public EndElement asEndElement();
|
||||
|
||||
/**
|
||||
* Returns this event as Characters, may result in
|
||||
* a class cast exception if this event is not Characters.
|
||||
*/
|
||||
public Characters asCharacters();
|
||||
|
||||
/**
|
||||
* This method is provided for implementations to provide
|
||||
* optional type information about the associated event.
|
||||
* It is optional and will return null if no information
|
||||
* is available.
|
||||
*/
|
||||
public QName getSchemaType();
|
||||
|
||||
/**
|
||||
* This method will write the XMLEvent as per the XML 1.0 specification as Unicode characters.
|
||||
* No indentation or whitespace should be outputted.
|
||||
*
|
||||
* Any user defined event type SHALL have this method
|
||||
* called when being written to on an output stream.
|
||||
* Built in Event types MUST implement this method,
|
||||
* but implementations MAY choose not call these methods
|
||||
* for optimizations reasons when writing out built in
|
||||
* Events to an output stream.
|
||||
* The output generated MUST be equivalent in terms of the
|
||||
* infoset expressed.
|
||||
*
|
||||
* @param writer The writer that will output the data
|
||||
* @throws XMLStreamException if there is a fatal error writing the event
|
||||
*/
|
||||
public void writeAsEncodedUnicode(Writer writer)
|
||||
throws javax.xml.stream.XMLStreamException;
|
||||
|
||||
}
|
|
@ -0,0 +1,134 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 by Oracle Corporation. All Rights Reserved.
|
||||
*/
|
||||
|
||||
package javax.xml.stream.util;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
import javax.xml.namespace.NamespaceContext;
|
||||
import javax.xml.stream.XMLEventReader;
|
||||
import javax.xml.stream.events.XMLEvent;
|
||||
import javax.xml.stream.Location;
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
|
||||
/**
|
||||
* This is the base class for deriving an XMLEventReader
|
||||
* filter.
|
||||
*
|
||||
* This class is designed to sit between an XMLEventReader and an
|
||||
* application's XMLEventReader. By default each method
|
||||
* does nothing but call the corresponding method on the
|
||||
* parent interface.
|
||||
*
|
||||
* @version 1.0
|
||||
* @author Copyright (c) 2009 by Oracle Corporation. All Rights Reserved.
|
||||
* @see javax.xml.stream.XMLEventReader
|
||||
* @see StreamReaderDelegate
|
||||
* @since 1.6
|
||||
*/
|
||||
|
||||
public class EventReaderDelegate implements XMLEventReader {
|
||||
private XMLEventReader reader;
|
||||
|
||||
/**
|
||||
* Construct an empty filter with no parent.
|
||||
*/
|
||||
public EventReaderDelegate(){}
|
||||
|
||||
/**
|
||||
* Construct an filter with the specified parent.
|
||||
* @param reader the parent
|
||||
*/
|
||||
public EventReaderDelegate(XMLEventReader reader) {
|
||||
this.reader = reader;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the parent of this instance.
|
||||
* @param reader the new parent
|
||||
*/
|
||||
public void setParent(XMLEventReader reader) {
|
||||
this.reader = reader;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the parent of this instance.
|
||||
* @return the parent or null if none is set
|
||||
*/
|
||||
public XMLEventReader getParent() {
|
||||
return reader;
|
||||
}
|
||||
|
||||
public XMLEvent nextEvent()
|
||||
throws XMLStreamException
|
||||
{
|
||||
return reader.nextEvent();
|
||||
}
|
||||
|
||||
public Object next() {
|
||||
return reader.next();
|
||||
}
|
||||
|
||||
public boolean hasNext()
|
||||
{
|
||||
return reader.hasNext();
|
||||
}
|
||||
|
||||
public XMLEvent peek()
|
||||
throws XMLStreamException
|
||||
{
|
||||
return reader.peek();
|
||||
}
|
||||
|
||||
public void close()
|
||||
throws XMLStreamException
|
||||
{
|
||||
reader.close();
|
||||
}
|
||||
|
||||
public String getElementText()
|
||||
throws XMLStreamException
|
||||
{
|
||||
return reader.getElementText();
|
||||
}
|
||||
|
||||
public XMLEvent nextTag()
|
||||
throws XMLStreamException
|
||||
{
|
||||
return reader.nextTag();
|
||||
}
|
||||
|
||||
public Object getProperty(java.lang.String name)
|
||||
throws java.lang.IllegalArgumentException
|
||||
{
|
||||
return reader.getProperty(name);
|
||||
}
|
||||
|
||||
public void remove() {
|
||||
reader.remove();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,287 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 by Oracle Corporation. All Rights Reserved.
|
||||
*/
|
||||
|
||||
package javax.xml.stream.util;
|
||||
|
||||
import java.io.Reader;
|
||||
import javax.xml.namespace.QName;
|
||||
import javax.xml.namespace.NamespaceContext;
|
||||
import javax.xml.stream.XMLStreamReader;
|
||||
import javax.xml.stream.Location;
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
|
||||
/**
|
||||
* This is the base class for deriving an XMLStreamReader filter
|
||||
*
|
||||
* This class is designed to sit between an XMLStreamReader and an
|
||||
* application's XMLStreamReader. By default each method
|
||||
* does nothing but call the corresponding method on the
|
||||
* parent interface.
|
||||
*
|
||||
* @version 1.0
|
||||
* @author Copyright (c) 2009 by Oracle Corporation. All Rights Reserved.
|
||||
* @see javax.xml.stream.XMLStreamReader
|
||||
* @see EventReaderDelegate
|
||||
* @since 1.6
|
||||
*/
|
||||
|
||||
public class StreamReaderDelegate implements XMLStreamReader {
|
||||
private XMLStreamReader reader;
|
||||
|
||||
/**
|
||||
* Construct an empty filter with no parent.
|
||||
*/
|
||||
public StreamReaderDelegate(){}
|
||||
|
||||
/**
|
||||
* Construct an filter with the specified parent.
|
||||
* @param reader the parent
|
||||
*/
|
||||
public StreamReaderDelegate(XMLStreamReader reader) {
|
||||
this.reader = reader;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the parent of this instance.
|
||||
* @param reader the new parent
|
||||
*/
|
||||
public void setParent(XMLStreamReader reader) {
|
||||
this.reader = reader;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the parent of this instance.
|
||||
* @return the parent or null if none is set
|
||||
*/
|
||||
public XMLStreamReader getParent() {
|
||||
return reader;
|
||||
}
|
||||
|
||||
public int next()
|
||||
throws XMLStreamException
|
||||
{
|
||||
return reader.next();
|
||||
}
|
||||
|
||||
public int nextTag()
|
||||
throws XMLStreamException
|
||||
{
|
||||
return reader.nextTag();
|
||||
}
|
||||
|
||||
public String getElementText()
|
||||
throws XMLStreamException
|
||||
{
|
||||
return reader.getElementText();
|
||||
}
|
||||
|
||||
public void require(int type, String namespaceURI, String localName)
|
||||
throws XMLStreamException
|
||||
{
|
||||
reader.require(type,namespaceURI,localName);
|
||||
}
|
||||
|
||||
public boolean hasNext()
|
||||
throws XMLStreamException
|
||||
{
|
||||
return reader.hasNext();
|
||||
}
|
||||
|
||||
public void close()
|
||||
throws XMLStreamException
|
||||
{
|
||||
reader.close();
|
||||
}
|
||||
|
||||
public String getNamespaceURI(String prefix)
|
||||
{
|
||||
return reader.getNamespaceURI(prefix);
|
||||
}
|
||||
|
||||
public NamespaceContext getNamespaceContext() {
|
||||
return reader.getNamespaceContext();
|
||||
}
|
||||
|
||||
public boolean isStartElement() {
|
||||
return reader.isStartElement();
|
||||
}
|
||||
|
||||
public boolean isEndElement() {
|
||||
return reader.isEndElement();
|
||||
}
|
||||
|
||||
public boolean isCharacters() {
|
||||
return reader.isCharacters();
|
||||
}
|
||||
|
||||
public boolean isWhiteSpace() {
|
||||
return reader.isWhiteSpace();
|
||||
}
|
||||
|
||||
public String getAttributeValue(String namespaceUri,
|
||||
String localName)
|
||||
{
|
||||
return reader.getAttributeValue(namespaceUri,localName);
|
||||
}
|
||||
|
||||
public int getAttributeCount() {
|
||||
return reader.getAttributeCount();
|
||||
}
|
||||
|
||||
public QName getAttributeName(int index) {
|
||||
return reader.getAttributeName(index);
|
||||
}
|
||||
|
||||
public String getAttributePrefix(int index) {
|
||||
return reader.getAttributePrefix(index);
|
||||
}
|
||||
|
||||
public String getAttributeNamespace(int index) {
|
||||
return reader.getAttributeNamespace(index);
|
||||
}
|
||||
|
||||
public String getAttributeLocalName(int index) {
|
||||
return reader.getAttributeLocalName(index);
|
||||
}
|
||||
|
||||
public String getAttributeType(int index) {
|
||||
return reader.getAttributeType(index);
|
||||
}
|
||||
|
||||
public String getAttributeValue(int index) {
|
||||
return reader.getAttributeValue(index);
|
||||
}
|
||||
|
||||
public boolean isAttributeSpecified(int index) {
|
||||
return reader.isAttributeSpecified(index);
|
||||
}
|
||||
|
||||
public int getNamespaceCount() {
|
||||
return reader.getNamespaceCount();
|
||||
}
|
||||
|
||||
public String getNamespacePrefix(int index) {
|
||||
return reader.getNamespacePrefix(index);
|
||||
}
|
||||
|
||||
public String getNamespaceURI(int index) {
|
||||
return reader.getNamespaceURI(index);
|
||||
}
|
||||
|
||||
public int getEventType() {
|
||||
return reader.getEventType();
|
||||
}
|
||||
|
||||
public String getText() {
|
||||
return reader.getText();
|
||||
}
|
||||
|
||||
public int getTextCharacters(int sourceStart,
|
||||
char[] target,
|
||||
int targetStart,
|
||||
int length)
|
||||
throws XMLStreamException {
|
||||
return reader.getTextCharacters(sourceStart,
|
||||
target,
|
||||
targetStart,
|
||||
length);
|
||||
}
|
||||
|
||||
|
||||
public char[] getTextCharacters() {
|
||||
return reader.getTextCharacters();
|
||||
}
|
||||
|
||||
public int getTextStart() {
|
||||
return reader.getTextStart();
|
||||
}
|
||||
|
||||
public int getTextLength() {
|
||||
return reader.getTextLength();
|
||||
}
|
||||
|
||||
public String getEncoding() {
|
||||
return reader.getEncoding();
|
||||
}
|
||||
|
||||
public boolean hasText() {
|
||||
return reader.hasText();
|
||||
}
|
||||
|
||||
public Location getLocation() {
|
||||
return reader.getLocation();
|
||||
}
|
||||
|
||||
public QName getName() {
|
||||
return reader.getName();
|
||||
}
|
||||
|
||||
public String getLocalName() {
|
||||
return reader.getLocalName();
|
||||
}
|
||||
|
||||
public boolean hasName() {
|
||||
return reader.hasName();
|
||||
}
|
||||
|
||||
public String getNamespaceURI() {
|
||||
return reader.getNamespaceURI();
|
||||
}
|
||||
|
||||
public String getPrefix() {
|
||||
return reader.getPrefix();
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
return reader.getVersion();
|
||||
}
|
||||
|
||||
public boolean isStandalone() {
|
||||
return reader.isStandalone();
|
||||
}
|
||||
|
||||
public boolean standaloneSet() {
|
||||
return reader.standaloneSet();
|
||||
}
|
||||
|
||||
public String getCharacterEncodingScheme() {
|
||||
return reader.getCharacterEncodingScheme();
|
||||
}
|
||||
|
||||
public String getPITarget() {
|
||||
return reader.getPITarget();
|
||||
}
|
||||
|
||||
public String getPIData() {
|
||||
return reader.getPIData();
|
||||
}
|
||||
|
||||
public Object getProperty(String name) {
|
||||
return reader.getProperty(name);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,82 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 by Oracle Corporation. All Rights Reserved.
|
||||
*/
|
||||
|
||||
package javax.xml.stream.util;
|
||||
|
||||
import javax.xml.stream.events.XMLEvent;
|
||||
import javax.xml.stream.XMLStreamReader;
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
|
||||
/**
|
||||
* This interface defines a class that allows a user to register
|
||||
* a way to allocate events given an XMLStreamReader. An implementation
|
||||
* is not required to use the XMLEventFactory implementation but this
|
||||
* is recommended. The XMLEventAllocator can be set on an XMLInputFactory
|
||||
* using the property "javax.xml.stream.allocator"
|
||||
*
|
||||
* @version 1.0
|
||||
* @author Copyright (c) 2009 by Oracle Corporation. All Rights Reserved.
|
||||
* @see javax.xml.stream.XMLInputFactory
|
||||
* @see javax.xml.stream.XMLEventFactory
|
||||
* @since 1.6
|
||||
*/
|
||||
public interface XMLEventAllocator {
|
||||
|
||||
/**
|
||||
* This method creates an instance of the XMLEventAllocator. This
|
||||
* allows the XMLInputFactory to allocate a new instance per reader.
|
||||
*/
|
||||
public XMLEventAllocator newInstance();
|
||||
|
||||
/**
|
||||
* This method allocates an event given the current
|
||||
* state of the XMLStreamReader. If this XMLEventAllocator
|
||||
* does not have a one-to-one mapping between reader states
|
||||
* and events this method will return null. This method
|
||||
* must not modify the state of the XMLStreamReader.
|
||||
* @param reader The XMLStreamReader to allocate from
|
||||
* @return the event corresponding to the current reader state
|
||||
*/
|
||||
public XMLEvent allocate(XMLStreamReader reader)
|
||||
throws XMLStreamException;
|
||||
|
||||
/**
|
||||
* This method allocates an event or set of events
|
||||
* given the current
|
||||
* state of the XMLStreamReader and adds the event
|
||||
* or set of events to the
|
||||
* consumer that was passed in. This method can be used
|
||||
* to expand or contract reader states into event states.
|
||||
* This method may modify the state of the XMLStreamReader.
|
||||
* @param reader The XMLStreamReader to allocate from
|
||||
* @param consumer The XMLEventConsumer to add to.
|
||||
*/
|
||||
public void allocate(XMLStreamReader reader, XMLEventConsumer consumer)
|
||||
throws XMLStreamException;
|
||||
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 by Oracle Corporation. All Rights Reserved.
|
||||
*/
|
||||
|
||||
package javax.xml.stream.util;
|
||||
|
||||
import javax.xml.stream.events.XMLEvent;
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
|
||||
/**
|
||||
* This interface defines an event consumer interface. The contract of the
|
||||
* of a consumer is to accept the event. This interface can be used to
|
||||
* mark an object as able to receive events. Add may be called several
|
||||
* times in immediate succession so a consumer must be able to cache
|
||||
* events it hasn't processed yet.
|
||||
*
|
||||
* @version 1.0
|
||||
* @author Copyright (c) 2009 by Oracle Corporation. All Rights Reserved.
|
||||
* @since 1.6
|
||||
*/
|
||||
public interface XMLEventConsumer {
|
||||
|
||||
/**
|
||||
* This method adds an event to the consumer. Calling this method
|
||||
* invalidates the event parameter. The client application should
|
||||
* discard all references to this event upon calling add.
|
||||
* The behavior of an application that continues to use such references
|
||||
* is undefined.
|
||||
*
|
||||
* @param event the event to add, may not be null
|
||||
*/
|
||||
public void add(XMLEvent event)
|
||||
throws XMLStreamException;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue