revert mistaken commit to HEAD. This should restore HEAD to its correct state, leaving only the new tck-jaxp-1_2_0 branch with "unofficial" APIs

git-svn-id: https://svn.apache.org/repos/asf/xml/commons/trunk@226024 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
neilg 2002-12-12 16:52:03 +00:00
parent c9ce59d37b
commit 6ef6cd1d5f
20 changed files with 536 additions and 1366 deletions

View File

@ -100,7 +100,6 @@ public abstract class DocumentBuilder {
protected DocumentBuilder () {
}
private static final boolean DEBUG = false ;
/**
* Parse the content of the given <code>InputStream</code> as an XML
* document and return a new DOM {@link org.w3c.dom.Document} object.
@ -190,12 +189,11 @@ public abstract class DocumentBuilder {
throw new IllegalArgumentException("File cannot be null");
}
String escapedURI = FilePathToURI.filepath2URI(f.getAbsolutePath()) ;
if(DEBUG)
System.out.println("Escaped URI = " + escapedURI) ;
InputSource in = new InputSource(escapedURI);
String uri = "file:" + f.getAbsolutePath();
if (File.separatorChar == '\\') {
uri = uri.replace('\\', '/');
}
InputSource in = new InputSource(uri);
return parse(in);
}

View File

@ -140,7 +140,7 @@ public abstract class DocumentBuilderFactory {
/* The default property name according to the JAXP spec */
"javax.xml.parsers.DocumentBuilderFactory",
/* The fallback implementation class name */
"org.apache.xerces.jaxp.DocumentBuilderFactoryImpl");
null);
} catch (FactoryFinder.ConfigurationError e) {
throw new FactoryConfigurationError(e.getException(),
e.getMessage());

View File

@ -55,15 +55,17 @@
package javax.xml.parsers;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.io.IOException;
import java.io.File;
import java.io.FileInputStream;
import java.util.Properties;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Properties;
import java.lang.reflect.Method;
import java.lang.reflect.InvocationTargetException;
/**
* This class is duplicated for each JAXP subpackage so keep it in sync.
@ -71,170 +73,65 @@ import java.util.Properties;
* API.
*
* This code is designed to implement the JAXP 1.1 spec pluggability
* feature. The code runs both as part of an unbundled jar file and also
* when bundled as part of the JDK. Ideally the code should both compile
* and run on JDK version 1.1 and later. However, due to the complexities
* of invoking Java 2 security methods via reflection, this code will only
* compile on Java 2 although it will run under JDK 1.1 VMs. As of 1may02
* this file is on a "java2-branch".
*
* @author Edwin Goei
* feature and is designed to both compile and run on JDK version 1.1 and
* later. The code also runs both as part of an unbundled jar file and
* when bundled as part of the JDK.
*/
class FactoryFinder {
/** Controls debugging output to stderr */
private static boolean debug;
/** Set to true for debugging */
private static final boolean debug = false;
// Define system property "jaxp.debug" to get output
static {
try {
String val =
SecuritySupport.getInstance().getSystemProperty("jaxp.debug");
// Allow simply setting the prop to turn on debug
debug = val != null && (! "false".equals(val));
} catch (SecurityException se) {
debug = false;
}
}
/**
* Main entry point. Finds and creates a new instance of a concrete
* factory implementation in the specified order as stated in the JAXP
* spec. This code attempts to find a factory implementation in
* serveral locations. If one fails, the next one is tried. To be
* more robust, this occurs even if a SecurityException is thrown, but
* perhaps it may be better to propogate the SecurityException instead,
* so SecurityException-s are not masked.
*
* @return A new instance of the concrete factory class, never null
*
* @param factoryId
* Name of the factory to find, same as a property name
*
* @param fallbackClassName
* Implementation class name, if nothing else is found. Use
* null to mean not to use a fallback.
*
* @throws FactoryFinder.ConfigurationError
* If a factory instance cannot be returned
*
* Package private so this code can be shared.
*/
static Object find(String factoryId, String fallbackClassName)
throws ConfigurationError
{
SecuritySupport ss = SecuritySupport.getInstance();
// Figure out which ClassLoader to use for loading the provider
// class. If there is a Context ClassLoader then use it.
ClassLoader cl = ss.getContextClassLoader();
if (cl == null) {
// Assert: we are on JDK 1.1 or we have no Context ClassLoader
// so use the current ClassLoader
cl = FactoryFinder.class.getClassLoader();
}
dPrint("find factoryId=" + factoryId);
// Use the system property first
try {
String systemProp = ss.getSystemProperty(factoryId);
if (systemProp != null) {
dPrint("found system property, value=" + systemProp);
return newInstance(systemProp, cl, true);
}
} catch (SecurityException se) {
// Ignore and continue w/ next location
}
// Try to read from $java.home/lib/jaxp.properties
try {
String javah = ss.getSystemProperty("java.home");
String configFile = javah + File.separator +
"lib" + File.separator + "jaxp.properties";
FileInputStream fis = ss.getFileInputStream(new File(configFile));
Properties props = new Properties();
props.load(fis);
String factoryClassName = props.getProperty(factoryId);
if (factoryClassName != null) {
dPrint("found in jaxp.properties, value=" + factoryClassName);
return newInstance(factoryClassName, cl, true);
}
} catch (Exception x) {
// assert(x instanceof FileNotFoundException
// || x instanceof SecurityException)
// In both cases, ignore and continue w/ next location
}
// Try Jar Service Provider Mechanism
Object provider = findJarServiceProvider(factoryId);
if (provider != null) {
return provider;
}
if (fallbackClassName == null) {
throw new ConfigurationError(
"Provider for " + factoryId + " cannot be found", null);
}
dPrint("using fallback, value=" + fallbackClassName);
return newInstance(fallbackClassName, cl, true);
}
private static void dPrint(String msg) {
private static void debugPrintln(String msg) {
if (debug) {
System.err.println("JAXP: " + msg);
}
}
/**
* Create an instance of a class using the specified ClassLoader and
* optionally fall back to the current ClassLoader if not found.
*
* @param className Name of the concrete class corresponding to the
* service provider
*
* @param cl ClassLoader to use to load the class, null means to use
* the bootstrap ClassLoader
*
* @param doFallback true if the current ClassLoader should be tried as
* a fallback if the class is not found using cl
*/
private static Object newInstance(String className, ClassLoader cl,
boolean doFallback)
* Figure out which ClassLoader to use. For JDK 1.2 and later use
* the context ClassLoader.
*/
private static ClassLoader findClassLoader()
throws ConfigurationError
{
// assert(className != null);
Method m = null;
try {
Class providerClass;
if (cl == null) {
// XXX Use the bootstrap ClassLoader. There is no way to
// load a class using the bootstrap ClassLoader that works
// in both JDK 1.1 and Java 2. However, this should still
// work b/c the following should be true:
//
// (cl == null) iff current ClassLoader == null
//
// Thus Class.forName(String) will use the current
// ClassLoader which will be the bootstrap ClassLoader.
providerClass = Class.forName(className);
m = Thread.class.getMethod("getContextClassLoader", null);
} catch (NoSuchMethodException e) {
// Assume that we are running JDK 1.1, use the current ClassLoader
debugPrintln("assuming JDK 1.1");
return FactoryFinder.class.getClassLoader();
}
try {
return (ClassLoader) m.invoke(Thread.currentThread(), null);
} catch (IllegalAccessException e) {
// assert(false)
throw new ConfigurationError("Unexpected IllegalAccessException",
e);
} catch (InvocationTargetException e) {
// assert(e.getTargetException() instanceof SecurityException)
throw new ConfigurationError("Unexpected InvocationTargetException",
e);
}
}
/**
* Create an instance of a class using the specified ClassLoader
*/
private static Object newInstance(String className,
ClassLoader classLoader)
throws ConfigurationError
{
try {
Class spiClass;
if (classLoader == null) {
spiClass = Class.forName(className);
} else {
try {
providerClass = cl.loadClass(className);
} catch (ClassNotFoundException x) {
if (doFallback) {
// Fall back to current classloader
cl = FactoryFinder.class.getClassLoader();
providerClass = cl.loadClass(className);
} else {
throw x;
}
}
spiClass = classLoader.loadClass(className);
}
Object instance = providerClass.newInstance();
dPrint("created new instance of " + providerClass +
" using ClassLoader: " + cl);
return instance;
return spiClass.newInstance();
} catch (ClassNotFoundException x) {
throw new ConfigurationError(
"Provider " + className + " not found", x);
@ -245,91 +142,111 @@ class FactoryFinder {
}
}
/*
* Try to find provider using Jar Service Provider Mechanism
/**
* Finds the implementation Class object in the specified order. Main
* entry point.
* @return Class object of factory, never null
*
* @return instance of provider class if found or null
* @param factoryId Name of the factory to find, same as
* a property name
* @param fallbackClassName Implementation class name, if nothing else
* is found. Use null to mean no fallback.
*
* @exception FactoryFinder.ConfigurationError
*
* Package private so this code can be shared.
*/
private static Object findJarServiceProvider(String factoryId)
static Object find(String factoryId, String fallbackClassName)
throws ConfigurationError
{
SecuritySupport ss = SecuritySupport.getInstance();
String serviceId = "META-INF/services/" + factoryId;
InputStream is = null;
debugPrintln("debug is on");
// First try the Context ClassLoader
ClassLoader cl = ss.getContextClassLoader();
if (cl != null) {
is = ss.getResourceAsStream(cl, serviceId);
ClassLoader classLoader = findClassLoader();
// If no provider found then try the current ClassLoader
if (is == null) {
cl = FactoryFinder.class.getClassLoader();
is = ss.getResourceAsStream(cl, serviceId);
// Use the system property first
try {
String systemProp =
System.getProperty( factoryId );
if( systemProp!=null) {
debugPrintln("found system property " + systemProp);
return newInstance(systemProp, classLoader);
}
} else {
// No Context ClassLoader or JDK 1.1 so try the current
// ClassLoader
cl = FactoryFinder.class.getClassLoader();
is = ss.getResourceAsStream(cl, serviceId);
} catch (SecurityException se) {
}
if (is == null) {
// No provider found
return null;
}
dPrint("found jar resource=" + serviceId +
" using ClassLoader: " + cl);
// Read the service provider name in UTF-8 as specified in
// the jar spec. Unfortunately this fails in Microsoft
// VJ++, which does not implement the UTF-8
// encoding. Theoretically, we should simply let it fail in
// that case, since the JVM is obviously broken if it
// doesn't support such a basic standard. But since there
// are still some users attempting to use VJ++ for
// development, we have dropped in a fallback which makes a
// second attempt using the platform's default encoding. In
// VJ++ this is apparently ASCII, which is a subset of
// UTF-8... and since the strings we'll be reading here are
// also primarily limited to the 7-bit ASCII range (at
// least, in English versions), this should work well
// enough to keep us on the air until we're ready to
// officially decommit from VJ++. [Edited comment from
// jkesselm]
BufferedReader rd;
// try to read from $java.home/lib/xml.properties
try {
rd = new BufferedReader(new InputStreamReader(is, "UTF-8"));
} catch (java.io.UnsupportedEncodingException e) {
rd = new BufferedReader(new InputStreamReader(is));
String javah=System.getProperty( "java.home" );
String configFile = javah + File.separator +
"lib" + File.separator + "jaxp.properties";
File f=new File( configFile );
if( f.exists()) {
Properties props=new Properties();
props.load( new FileInputStream(f));
String factoryClassName = props.getProperty(factoryId);
debugPrintln("found java.home property " + factoryClassName);
return newInstance(factoryClassName, classLoader);
}
} catch(Exception ex ) {
if( debug ) ex.printStackTrace();
}
String serviceId = "META-INF/services/" + factoryId;
// try to find services in CLASSPATH
try {
InputStream is=null;
if (classLoader == null) {
is=ClassLoader.getSystemResourceAsStream( serviceId );
} else {
is=classLoader.getResourceAsStream( serviceId );
}
String factoryClassName = null;
try {
// XXX Does not handle all possible input as specified by the
// Jar Service Provider specification
factoryClassName = rd.readLine();
rd.close();
} catch (IOException x) {
// No provider found
return null;
if( is!=null ) {
debugPrintln("found " + serviceId);
// Read the service provider name in UTF-8 as specified in
// the jar spec. Unfortunately this fails in Microsoft
// VJ++, which does not implement the UTF-8
// encoding. Theoretically, we should simply let it fail in
// that case, since the JVM is obviously broken if it
// doesn't support such a basic standard. But since there
// are still some users attempting to use VJ++ for
// development, we have dropped in a fallback which makes a
// second attempt using the platform's default encoding. In
// VJ++ this is apparently ASCII, which is a subset of
// UTF-8... and since the strings we'll be reading here are
// also primarily limited to the 7-bit ASCII range (at
// least, in English versions), this should work well
// enough to keep us on the air until we're ready to
// officially decommit from VJ++. [Edited comment from
// jkesselm]
BufferedReader rd;
try {
rd = new BufferedReader(new InputStreamReader(is, "UTF-8"));
} catch (java.io.UnsupportedEncodingException e) {
rd = new BufferedReader(new InputStreamReader(is));
}
String factoryClassName = rd.readLine();
rd.close();
if (factoryClassName != null &&
! "".equals(factoryClassName)) {
debugPrintln("loaded from services: " + factoryClassName);
return newInstance(factoryClassName, classLoader);
}
}
} catch( Exception ex ) {
if( debug ) ex.printStackTrace();
}
if (factoryClassName != null &&
! "".equals(factoryClassName)) {
dPrint("found in resource, value="
+ factoryClassName);
// Note: here we do not want to fall back to the current
// ClassLoader because we want to avoid the case where the
// resource file was found using one ClassLoader and the
// provider class was instantiated using a different one.
return newInstance(factoryClassName, cl, false);
if (fallbackClassName == null) {
throw new ConfigurationError(
"Provider for " + factoryId + " cannot be found", null);
}
// No provider found
return null;
debugPrintln("loaded from fallback value: " + fallbackClassName);
return newInstance(fallbackClassName, classLoader);
}
static class ConfigurationError extends Error {

View File

@ -1,169 +0,0 @@
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2002 The Apache Software Foundation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xerces" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 1999, International
* Business Machines, Inc., http://www.apache.org. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package javax.xml.parsers;
class FilePathToURI {
// which ASCII characters need to be escaped
private static boolean gNeedEscaping[] = new boolean[128];
// the first hex character if a character needs to be escaped
private static char gAfterEscaping1[] = new char[128];
// the second hex character if a character needs to be escaped
private static char gAfterEscaping2[] = new char[128];
private static char[] gHexChs = {'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
// initialize the above 3 arrays
static {
for (int i = 0; i <= 0x1f; i++) {
gNeedEscaping[i] = true;
gAfterEscaping1[i] = gHexChs[i >> 4];
gAfterEscaping2[i] = gHexChs[i & 0xf];
}
gNeedEscaping[0x7f] = true;
gAfterEscaping1[0x7f] = '7';
gAfterEscaping2[0x7f] = 'F';
char[] escChs = {' ', '<', '>', '#', '%', '"', '{', '}',
'|', '\\', '^', '~', '[', ']', '`'};
int len = escChs.length;
char ch;
for (int i = 0; i < len; i++) {
ch = escChs[i];
gNeedEscaping[ch] = true;
gAfterEscaping1[ch] = gHexChs[ch >> 4];
gAfterEscaping2[ch] = gHexChs[ch & 0xf];
}
}
// To escape a file path to a URI, by using %HH to represent
// special ASCII characters: 0x00~0x1F, 0x7F, ' ', '<', '>', '#', '%'
// and '"' and non-ASCII characters (whose value >= 128).
public static String filepath2URI(String path){
// return null if path is null.
if (path == null)
return null;
char separator = java.io.File.separatorChar;
path = path.replace(separator, '/');
int len = path.length(), ch;
StringBuffer buffer = new StringBuffer(len*3);
buffer.append("file://");
// change C:/blah to /C:/blah
if (len >= 2 && path.charAt(1) == ':') {
ch = Character.toUpperCase(path.charAt(0));
if (ch >= 'A' && ch <= 'Z') {
buffer.append('/');
}
}
// for each character in the path
int i = 0;
for (; i < len; i++) {
ch = path.charAt(i);
// if it's not an ASCII character, break here, and use UTF-8 encoding
if (ch >= 128)
break;
if (gNeedEscaping[ch]) {
buffer.append('%');
buffer.append(gAfterEscaping1[ch]);
buffer.append(gAfterEscaping2[ch]);
// record the fact that it's escaped
}
else {
buffer.append((char)ch);
}
}
// we saw some non-ascii character
if (i < len) {
// get UTF-8 bytes for the remaining sub-string
byte[] bytes = null;
byte b;
try {
bytes = path.substring(i).getBytes("UTF-8");
} catch (java.io.UnsupportedEncodingException e) {
// should never happen
return path;
}
len = bytes.length;
// for each byte
for (i = 0; i < len; i++) {
b = bytes[i];
// for non-ascii character: make it positive, then escape
if (b < 0) {
ch = b + 256;
buffer.append('%');
buffer.append(gHexChs[ch >> 4]);
buffer.append(gHexChs[ch & 0xf]);
}
else if (gNeedEscaping[b]) {
buffer.append('%');
buffer.append(gAfterEscaping1[b]);
buffer.append(gAfterEscaping2[b]);
}
else {
buffer.append((char)b);
}
}
}
return buffer.toString();
}
}//FilePathToURI

View File

@ -107,7 +107,6 @@ import org.xml.sax.SAXNotSupportedException;
public abstract class SAXParser {
private static final boolean DEBUG = false ;
protected SAXParser () {
}
@ -294,16 +293,14 @@ public abstract class SAXParser {
throw new IllegalArgumentException("File cannot be null");
}
String escapedURI = FilePathToURI.filepath2URI(f.getAbsolutePath()) ;
if(DEBUG)
System.out.println("Escaped URI = " + escapedURI) ;
InputSource input = new InputSource(escapedURI);
String uri = "file:" + f.getAbsolutePath();
if (File.separatorChar == '\\') {
uri = uri.replace('\\', '/');
}
InputSource input = new InputSource(uri);
this.parse(input, hb);
}
/**
* Parse the content of the file specified as XML using the
* specified {@link org.xml.sax.helpers.DefaultHandler}.
@ -324,12 +321,11 @@ public abstract class SAXParser {
throw new IllegalArgumentException("File cannot be null");
}
String escapedURI = FilePathToURI.filepath2URI(f.getAbsolutePath()) ;
if(DEBUG)
System.out.println("Escaped URI = " + escapedURI) ;
InputSource input = new InputSource(escapedURI);
String uri = "file:" + f.getAbsolutePath();
if (File.separatorChar == '\\') {
uri = uri.replace('\\', '/');
}
InputSource input = new InputSource(uri);
this.parse(input, dh);
}
@ -357,7 +353,6 @@ public abstract class SAXParser {
}
Parser parser = this.getParser();
if (hb != null) {
parser.setDocumentHandler(hb);
parser.setEntityResolver(hb);

View File

@ -136,7 +136,7 @@ public abstract class SAXParserFactory {
/* The default property name according to the JAXP spec */
"javax.xml.parsers.SAXParserFactory",
/* The fallback implementation class name */
"org.apache.xerces.jaxp.SAXParserFactoryImpl");
null);
} catch (FactoryFinder.ConfigurationError e) {
throw new FactoryConfigurationError(e.getException(),
e.getMessage());

View File

@ -1,140 +0,0 @@
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The name "Apache Software Foundation" must not be used to endorse or
* promote products derived from this software without prior written
* permission. For written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 1999-2002, Sun Microsystems,
* Inc., http://www.sun.com. For more information on the Apache Software
* Foundation, please see <http://www.apache.org/>.
*/
package javax.xml.parsers;
import java.lang.reflect.*;
import java.net.*;
import java.io.*;
/**
* 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.
*
* Base class with security related methods that work on JDK 1.1.
*/
class SecuritySupport {
/*
* Make this of type Object so that the verifier won't try to
* prove its type, thus possibly trying to load the SecuritySupport12
* class.
*/
private static final Object securitySupport;
static {
SecuritySupport ss = null;
try {
Class c = Class.forName("java.security.AccessController");
// if that worked, we're on 1.2.
/*
// don't reference the class explicitly so it doesn't
// get dragged in accidentally.
c = Class.forName("javax.mail.SecuritySupport12");
Constructor cons = c.getConstructor(new Class[] { });
ss = (SecuritySupport)cons.newInstance(new Object[] { });
*/
/*
* Unfortunately, we can't load the class using reflection
* because the class is package private. And the class has
* to be package private so the APIs aren't exposed to other
* code that could use them to circumvent security. Thus,
* we accept the risk that the direct reference might fail
* on some JDK 1.1 JVMs, even though we would never execute
* this code in such a case. Sigh...
*/
ss = new SecuritySupport12();
} catch (Exception ex) {
// ignore it
} finally {
if (ss == null)
ss = new SecuritySupport();
securitySupport = ss;
}
}
/**
* Return an appropriate instance of this class, depending on whether
* we're on a JDK 1.1 or J2SE 1.2 (or later) system.
*/
public static SecuritySupport getInstance() {
return (SecuritySupport)securitySupport;
}
public ClassLoader getContextClassLoader() {
return null;
}
public String getSystemProperty(String propName) {
return System.getProperty(propName);
}
public FileInputStream getFileInputStream(File file)
throws FileNotFoundException
{
return new FileInputStream(file);
}
public InputStream getResourceAsStream(ClassLoader cl, String name) {
InputStream ris;
if (cl == null) {
ris = ClassLoader.getSystemResourceAsStream(name);
} else {
ris = cl.getResourceAsStream(name);
}
return ris;
}
}

View File

@ -1,125 +0,0 @@
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The name "Apache Software Foundation" must not be used to endorse or
* promote products derived from this software without prior written
* permission. For written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 1999-2002, Sun Microsystems,
* Inc., http://www.sun.com. For more information on the Apache Software
* Foundation, please see <http://www.apache.org/>.
*/
package javax.xml.parsers;
import java.security.*;
import java.net.*;
import java.io.*;
import java.util.*;
/**
* This class is duplicated for each JAXP subpackage so keep it in sync.
* It is package private and therefore is not exposed as part of the JAXP
* API.
*
* Security related methods that only work on J2SE 1.2 and newer.
*/
class SecuritySupport12 extends SecuritySupport {
public ClassLoader getContextClassLoader() {
return (ClassLoader)
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
ClassLoader cl = null;
try {
cl = Thread.currentThread().getContextClassLoader();
} catch (SecurityException ex) { }
return cl;
}
});
}
public String getSystemProperty(final String propName) {
return (String)
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
return System.getProperty(propName);
}
});
}
public 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();
}
}
public InputStream getResourceAsStream(final ClassLoader cl,
final String name)
{
return (InputStream)
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
InputStream ris;
if (cl == null) {
ris = ClassLoader.getSystemResourceAsStream(name);
} else {
ris = cl.getResourceAsStream(name);
}
return ris;
}
});
}
}

View File

@ -40,14 +40,11 @@ public class SAXException extends Exception {
/**
* Create a new SAXException.
*/
/****
* commented out by neilg for JAXP 1.2 compatibiliby.
public SAXException ()
{
super();
this.exception = null;
}
****/
/**

View File

@ -34,13 +34,10 @@ public class SAXNotRecognizedException extends SAXException
/**
* Default constructor.
*/
/****
* commented out by neilg for JAXP 1.2 compatibiliby.
public SAXNotRecognizedException ()
{
super();
}
*****/
/**

View File

@ -34,13 +34,10 @@ public class SAXNotSupportedException extends SAXException
/**
* Construct a new exception with no message.
*/
/****
* commented out by neilg for JAXP 1.2 compatibiliby.
public SAXNotSupportedException ()
{
super();
}
*****/
/**

View File

@ -1,5 +1,6 @@
// NamespaceSupport.java - generic Namespace support for SAX.
// Written by David Megginson, sax@megginson.com
// http://www.saxproject.org
// Written by David Megginson
// This class is in the Public Domain. NO WARRANTY!
// $Id$
@ -13,11 +14,14 @@ import java.util.Vector;
/**
* Encapsulate Namespace logic for use by SAX drivers.
* Encapsulate Namespace logic for use by applications using SAX,
* or internally by SAX drivers.
*
* <blockquote>
* <em>This module, both source code and documentation, is in the
* Public Domain, and comes with <strong>NO WARRANTY</strong>.</em>
* See <a href='http://www.saxproject.org'>http://www.saxproject.org</a>
* for further information.
* </blockquote>
*
* <p>This class encapsulates the logic of Namespace processing:
@ -39,16 +43,16 @@ import java.util.Vector;
* support.declarePrefix("", "http://www.w3.org/1999/xhtml");
* support.declarePrefix("dc", "http://www.purl.org/dc#");
*
* String parts[] = support.processName("p", parts, false);
* parts = support.processName("p", parts, false);
* System.out.println("Namespace URI: " + parts[0]);
* System.out.println("Local name: " + parts[1]);
* System.out.println("Raw name: " + parts[2]);
* String parts[] = support.processName("dc:title", parts, false);
*
* parts = support.processName("dc:title", parts, false);
* System.out.println("Namespace URI: " + parts[0]);
* System.out.println("Local name: " + parts[1]);
* System.out.println("Raw name: " + parts[2]);
*
* support.popContext();
* </pre>
*
@ -57,15 +61,14 @@ import java.util.Vector;
* prefix/URI mapping is repeated for each context (for example), this
* class will be somewhat less efficient.</p>
*
* This class is <strong>not</strong> the 2.0.1 version; this was taken from Xerces
* to ensure JAXP 1.2 compatibility. It is unlikely the code changes
* between this class and the 2.0.1 version are significant, but
* it is best to be safe.
* <p>Although SAX drivers (parsers) may choose to use this class to
* implement namespace handling, they are not required to do so.
* Applications must track namespace information themselves if they
* want to use namespace information.
*
* @since SAX 2.0
* @author David Megginson,
* <a href="mailto:sax@megginson.com">sax@megginson.com</a>
* @version 2.0
* @author David Megginson
* @version 2.0.1 (sax2r2)
*/
public class NamespaceSupport
{
@ -77,7 +80,9 @@ public class NamespaceSupport
/**
* The XML Namespace as a constant.
* The XML Namespace URI as a constant.
* The value is <code>http://www.w3.org/XML/1998/namespace</code>
* as defined in the XML Namespaces specification.
*
* <p>This is the Namespace URI that is automatically mapped
* to the "xml" prefix.</p>
@ -130,21 +135,45 @@ public class NamespaceSupport
/**
* Start a new Namespace context.
*
* <p>Normally, you should push a new context at the beginning
* of each XML element: the new context will automatically inherit
* The new context will automatically inherit
* the declarations of its parent context, but it will also keep
* track of which declarations were made within this context.</p>
* track of which declarations were made within this context.
*
* <p>Event callback code should start a new context once per element.
* This means being ready to call this in either of two places.
* For elements that don't include namespace declarations, the
* <em>ContentHandler.startElement()</em> callback is the right place.
* For elements with such a declaration, it'd done in the first
* <em>ContentHandler.startPrefixMapping()</em> callback.
* A boolean flag can be used to
* track whether a context has been started yet. When either of
* those methods is called, it checks the flag to see if a new context
* needs to be started. If so, it starts the context and sets the
* flag. After <em>ContentHandler.startElement()</em>
* does that, it always clears the flag.
*
* <p>Normally, SAX drivers would push a new context at the beginning
* of each XML element. Then they perform a first pass over the
* attributes to process all namespace declarations, making
* <em>ContentHandler.startPrefixMapping()</em> callbacks.
* Then a second pass is made, to determine the namespace-qualified
* names for all attributes and for the element name.
* Finally all the information for the
* <em>ContentHandler.startElement()</em> callback is available,
* so it can then be made.
*
* <p>The Namespace support object always starts with a base context
* already in force: in this context, only the "xml" prefix is
* declared.</p>
*
* @see org.xml.sax.ContentHandler
* @see #popContext
*/
public void pushContext ()
{
int max = contexts.length;
contexts [contextPos].declsOK = false;
contextPos++;
// Extend the array if necessary
@ -183,6 +212,7 @@ public class NamespaceSupport
*/
public void popContext ()
{
contexts[contextPos].clear();
contextPos--;
if (contextPos < 0) {
throw new EmptyStackException();
@ -198,29 +228,42 @@ public class NamespaceSupport
/**
* Declare a Namespace prefix.
* Declare a Namespace prefix. All prefixes must be declared
* before they are referenced. For example, a SAX driver (parser)
* would scan an element's attributes
* in two passes: first for namespace declarations,
* then a second pass using {@link #processName processName()} to
* interpret prefixes against (potentially redefined) prefixes.
*
* <p>This method declares a prefix in the current Namespace
* context; the prefix will remain in force until this context
* is popped, unless it is shadowed in a descendant context.</p>
*
* <p>To declare a default Namespace, use the empty string. The
* prefix must not be "xml" or "xmlns".</p>
* <p>To declare the default element Namespace, use the empty string as
* the prefix.</p>
*
* <p>Note that you must <em>not</em> declare a prefix after
* you've pushed and popped another Namespace.</p>
* you've pushed and popped another Namespace context, or
* treated the declarations phase as complete by processing
* a prefixed name.</p>
*
* <p>Note that there is an asymmetry in this library: while {@link
* #getPrefix getPrefix} will not return the default "" prefix,
* even if you have declared one; to check for a default prefix,
* <p>Note that there is an asymmetry in this library: {@link
* #getPrefix getPrefix} will not return the "" prefix,
* even if you have declared a default element namespace.
* To check for a default namespace,
* you have to look it up explicitly using {@link #getURI getURI}.
* This asymmetry exists to make it easier to look up prefixes
* for attribute names, where the default prefix is not allowed.</p>
*
* @param prefix The prefix to declare, or null for the empty
* string.
* @param prefix The prefix to declare, or the empty string to
* indicate the default element namespace. This may never have
* the value "xml" or "xmlns".
* @param uri The Namespace URI to associate with the prefix.
* @return true if the prefix was legal, false otherwise
* @exception IllegalStateException when a prefix is declared
* after looking up a name in the context, or after pushing
* another context on top of it.
*
* @see #processName
* @see #getURI
* @see #getPrefix
@ -237,7 +280,8 @@ public class NamespaceSupport
/**
* Process a raw XML 1.0 name.
* Process a raw XML 1.0 name, after all declarations in the current
* context have been handled by {@link #declarePrefix declarePrefix()}.
*
* <p>This method processes a raw XML 1.0 name in the current
* context by removing the prefix and looking it up among the
@ -260,7 +304,7 @@ public class NamespaceSupport
*
* <p>Note that attribute names are processed differently than
* element names: an unprefixed element name will received the
* default Namespace (if any), while an unprefixed element name
* default Namespace (if any), while an unprefixed attribute name
* will not.</p>
*
* @param qName The raw XML 1.0 name to be processed.
@ -424,9 +468,14 @@ public class NamespaceSupport
/**
* Internal class for a single Namespace context.
*
* <p>This module caches and reuses Namespace contexts, so the number allocated
* <p>This module caches and reuses Namespace contexts,
* so the number allocated
* will be equal to the element depth of the document, not to the total
* number of elements (i.e. 5-10 rather than tens of thousands).</p>
* number of elements (i.e. 5-10 rather than tens of thousands).
* Also, data structures used to represent contexts are shared when
* possible (child contexts without declarations) to further reduce
* the amount of memory that's consumed.
* </p>
*/
final class Context {
@ -441,6 +490,8 @@ public class NamespaceSupport
/**
* (Re)set the parent of this Namespace context.
* The context must either have been freshly constructed,
* or must have been cleared.
*
* @param context The parent Namespace context object.
*/
@ -453,7 +504,24 @@ public class NamespaceSupport
elementNameTable = parent.elementNameTable;
attributeNameTable = parent.attributeNameTable;
defaultNS = parent.defaultNS;
tablesDirty = false;
declSeen = false;
declsOK = true;
}
/**
* Makes associated state become collectible,
* invalidating this context.
* {@link #setParent} must be called before
* this context may be used again.
*/
void clear ()
{
parent = null;
prefixTable = null;
uriTable = null;
elementNameTable = null;
attributeNameTable = null;
defaultNS = null;
}
@ -467,7 +535,10 @@ public class NamespaceSupport
void declarePrefix (String prefix, String uri)
{
// Lazy processing...
if (!tablesDirty) {
if (!declsOK)
throw new IllegalStateException (
"can't declare any more prefixes in this context");
if (!declSeen) {
copyTables();
}
if (declarations == null) {
@ -506,11 +577,14 @@ public class NamespaceSupport
String name[];
Hashtable table;
// detect errors in call sequence
declsOK = false;
// Select the appropriate table.
if (isAttribute) {
table = elementNameTable;
} else {
table = attributeNameTable;
} else {
table = elementNameTable;
}
// Start by looking in the cache, and
@ -522,8 +596,11 @@ public class NamespaceSupport
}
// We haven't seen this name in this
// context before.
// context before. Maybe in the parent
// context, but we can't assume prefix
// bindings are the same.
name = new String[3];
name[2] = qName.intern();
int index = qName.indexOf(':');
@ -534,8 +611,7 @@ public class NamespaceSupport
} else {
name[0] = defaultNS;
}
name[1] = qName.intern();
name[2] = name[1];
name[1] = name[2];
}
// Prefix
@ -553,12 +629,11 @@ public class NamespaceSupport
}
name[0] = uri;
name[1] = local.intern();
name[2] = qName.intern();
}
// Save in the cache for future use.
// (Could be shared with parent context...)
table.put(name[2], name);
tablesDirty = true;
return name;
}
@ -664,7 +739,7 @@ public class NamespaceSupport
}
elementNameTable = new Hashtable();
attributeNameTable = new Hashtable();
tablesDirty = true;
declSeen = true;
}
@ -678,6 +753,7 @@ public class NamespaceSupport
Hashtable elementNameTable;
Hashtable attributeNameTable;
String defaultNS = null;
boolean declsOK = true;
@ -686,7 +762,7 @@ public class NamespaceSupport
////////////////////////////////////////////////////////////////
private Vector declarations = null;
private boolean tablesDirty = false;
private boolean declSeen = false;
private Context parent = null;
}
}

View File

@ -3,6 +3,7 @@
// Written by Edwin Goei, edwingo@apache.org
// and by David Brownell, dbrownell@users.sourceforge.net
// NO WARRANTY! This class is in the Public Domain.
// $Id$
package org.xml.sax.helpers;
@ -23,64 +24,32 @@ import java.lang.reflect.InvocationTargetException;
* <p>This class contains a static method for creating an instance of a
* class from an explicit class name. It tries to use the thread's context
* ClassLoader if possible and falls back to using
* Class.forName(String). It also takes into account JDK 1.2+'s
* AccessController mechanism for performing its actions. </p>
* Class.forName(String).</p>
*
* <p>This code is designed to run on JDK version 1.1 and later and compile
* on versions of Java 2 and later.</p>
* <p>This code is designed to compile and run on JDK version 1.1 and later
* including versions of Java 2.</p>
*
* <p>This is <strong>not</strong> the NewInstance accompanying SAX 2.0.1; it
* represents some fixes to that code.
*
* @author Edwin Goei, David Brownell, Neil Graham
* @version $Id$
* @author Edwin Goei, David Brownell
* @version 2.0.1 (sax2r2)
*/
class NewInstance {
// constants
// governs whether, if we fail in finding a class even
// when given a classloader, we'll make a last-ditch attempt
// to use the current classloader.
private static final boolean DO_FALLBACK = true;
/**
* Creates a new instance of the specified class name
*
* Package private so this code is not exposed at the API level.
*/
static Object newInstance (ClassLoader cl, String className)
static Object newInstance (ClassLoader classLoader, String className)
throws ClassNotFoundException, IllegalAccessException,
InstantiationException
{
Class providerClass;
if (cl == null) {
// XXX Use the bootstrap ClassLoader. There is no way to
// load a class using the bootstrap ClassLoader that works
// in both JDK 1.1 and Java 2. However, this should still
// work b/c the following should be true:
//
// (cl == null) iff current ClassLoader == null
//
// Thus Class.forName(String) will use the current
// ClassLoader which will be the bootstrap ClassLoader.
providerClass = Class.forName(className);
Class driverClass;
if (classLoader == null) {
driverClass = Class.forName(className);
} else {
try {
providerClass = cl.loadClass(className);
} catch (ClassNotFoundException x) {
if (DO_FALLBACK) {
// Fall back to current classloader
cl = NewInstance.class.getClassLoader();
providerClass = cl.loadClass(className);
} else {
throw x;
}
}
driverClass = classLoader.loadClass(className);
}
Object instance = providerClass.newInstance();
return instance;
return driverClass.newInstance();
}
/**
@ -89,18 +58,23 @@ class NewInstance {
*/
static ClassLoader getClassLoader ()
{
Method m = null;
SecuritySupport ss = SecuritySupport.getInstance();
// Figure out which ClassLoader to use for loading the provider
// class. If there is a Context ClassLoader then use it.
ClassLoader cl = ss.getContextClassLoader();
if (cl == null) {
// Assert: we are on JDK 1.1 or we have no Context ClassLoader
// so use the current ClassLoader
cl = NewInstance.class.getClassLoader();
try {
m = Thread.class.getMethod("getContextClassLoader", null);
} catch (NoSuchMethodException e) {
// Assume that we are running JDK 1.1, use the current ClassLoader
return NewInstance.class.getClassLoader();
}
return cl;
try {
return (ClassLoader) m.invoke(Thread.currentThread(), null);
} catch (IllegalAccessException e) {
// assert(false)
throw new UnknownError(e.getMessage());
} catch (InvocationTargetException e) {
// assert(e.getTargetException() instanceof SecurityException)
throw new UnknownError(e.getMessage());
}
}
}

View File

@ -1,5 +1,6 @@
// ParserAdapter.java - adapt a SAX1 Parser to a SAX2 XMLReader.
// Written by David Megginson, sax@megginson.com
// http://www.saxproject.org
// Written by David Megginson
// NO WARRANTY! This class is in the public domain.
// $Id$
@ -8,6 +9,7 @@ package org.xml.sax.helpers;
import java.io.IOException;
import java.util.Enumeration;
import java.util.Vector;
import org.xml.sax.Parser; // deprecated
import org.xml.sax.InputSource;
@ -33,6 +35,8 @@ import org.xml.sax.SAXNotSupportedException;
* <blockquote>
* <em>This module, both source code and documentation, is in the
* Public Domain, and comes with <strong>NO WARRANTY</strong>.</em>
* See <a href='http://www.saxproject.org'>http://www.saxproject.org</a>
* for further information.
* </blockquote>
*
* <p>This class wraps a SAX1 {@link org.xml.sax.Parser Parser}
@ -44,15 +48,9 @@ import org.xml.sax.SAXNotSupportedException;
* <p>This adapter does not test for duplicate Namespace-qualified
* attribute names.</p>
*
* <p> Note that this is <strong>not</strong> the class shipped with
* SAX 2.0.1; this class takes into account the presence of AccessControllers
* in J2EE 1.4. It also throws NullPointerExceptions when setters are
* called with null parameters; the 2.0.1 version does not exhibit this behaviour.</p>
*
* @since SAX 2.0
* @author David Megginson,
* <a href="mailto:sax@megginson.com">sax@megginson.com</a>
* @version 2.0
* @author David Megginson
* @version 2.0.1 (sax2r2)
* @see org.xml.sax.helpers.XMLReaderAdapter
* @see org.xml.sax.XMLReader
* @see org.xml.sax.Parser
@ -72,7 +70,7 @@ public class ParserAdapter implements XMLReader, DocumentHandler
* <p>Use the "org.xml.sax.parser" property to locate the
* embedded SAX1 driver.</p>
*
* @exception org.xml.sax.SAXException If the embedded driver
* @exception SAXException If the embedded driver
* cannot be instantiated or if the
* org.xml.sax.parser property is not specified.
*/
@ -81,8 +79,7 @@ public class ParserAdapter implements XMLReader, DocumentHandler
{
super();
SecuritySupport ss = SecuritySupport.getInstance();
String driver = ss.getSystemProperty("org.xml.sax.parser");
String driver = System.getProperty("org.xml.sax.parser");
try {
setup(ParserFactory.makeParser());
@ -162,46 +159,37 @@ public class ParserAdapter implements XMLReader, DocumentHandler
private final static String FEATURES = "http://xml.org/sax/features/";
private final static String NAMESPACES = FEATURES + "namespaces";
private final static String NAMESPACE_PREFIXES = FEATURES + "namespace-prefixes";
private final static String VALIDATION = FEATURES + "validation";
private final static String EXTERNAL_GENERAL =
FEATURES + "external-general-entities";
private final static String EXTERNAL_PARAMETER =
FEATURES + "external-parameter-entities";
/**
* Set a feature for the parser.
* Set a feature flag for the parser.
*
* <p>The only features supported are namespaces and
* <p>The only features recognized are namespaces and
* namespace-prefixes.</p>
*
* @param name The feature name, as a complete URI.
* @param state The requested feature state.
* @exception org.xml.sax.SAXNotRecognizedException If the feature
* name is not known.
* @exception org.xml.sax.SAXNotSupportedException If the feature
* state is not supported.
* @param value The requested feature value.
* @exception SAXNotRecognizedException If the feature
* can't be assigned or retrieved.
* @exception SAXNotSupportedException If the feature
* can't be assigned that value.
* @see org.xml.sax.XMLReader#setFeature
*/
public void setFeature (String name, boolean state)
public void setFeature (String name, boolean value)
throws SAXNotRecognizedException, SAXNotSupportedException
{
if (name.equals(NAMESPACES)) {
checkNotParsing("feature", name);
namespaces = state;
namespaces = value;
if (!namespaces && !prefixes) {
prefixes = true;
}
} else if (name.equals(NAMESPACE_PREFIXES)) {
checkNotParsing("feature", name);
prefixes = state;
prefixes = value;
if (!prefixes && !namespaces) {
namespaces = true;
}
} else if (name.equals(VALIDATION) ||
name.equals(EXTERNAL_GENERAL) ||
name.equals(EXTERNAL_PARAMETER)) {
throw new SAXNotSupportedException("Feature: " + name);
} else {
throw new SAXNotRecognizedException("Feature: " + name);
}
@ -209,17 +197,17 @@ public class ParserAdapter implements XMLReader, DocumentHandler
/**
* Check a parser feature.
* Check a parser feature flag.
*
* <p>The only features supported are namespaces and
* <p>The only features recognized are namespaces and
* namespace-prefixes.</p>
*
* @param name The feature name, as a complete URI.
* @return The current feature state.
* @exception org.xml.sax.SAXNotRecognizedException If the feature
* name is not known.
* @exception org.xml.sax.SAXNotSupportedException If querying the
* feature state is not supported.
* @return The current feature value.
* @exception SAXNotRecognizedException If the feature
* value can't be assigned or retrieved.
* @exception SAXNotSupportedException If the
* feature is not currently readable.
* @see org.xml.sax.XMLReader#setFeature
*/
public boolean getFeature (String name)
@ -229,10 +217,6 @@ public class ParserAdapter implements XMLReader, DocumentHandler
return namespaces;
} else if (name.equals(NAMESPACE_PREFIXES)) {
return prefixes;
} else if (name.equals(VALIDATION) ||
name.equals(EXTERNAL_GENERAL) ||
name.equals(EXTERNAL_PARAMETER)) {
throw new SAXNotSupportedException("Feature: " + name);
} else {
throw new SAXNotRecognizedException("Feature: " + name);
}
@ -242,14 +226,14 @@ public class ParserAdapter implements XMLReader, DocumentHandler
/**
* Set a parser property.
*
* <p>No special properties are currently supported.</p>
* <p>No properties are currently recognized.</p>
*
* @param name The property name.
* @param value The property value.
* @exception org.xml.sax.SAXNotRecognizedException If the feature
* name is not known.
* @exception org.xml.sax.SAXNotSupportedException If the feature
* state is not supported.
* @exception SAXNotRecognizedException If the property
* value can't be assigned or retrieved.
* @exception SAXNotSupportedException If the property
* can't be assigned that value.
* @see org.xml.sax.XMLReader#setProperty
*/
public void setProperty (String name, Object value)
@ -262,14 +246,14 @@ public class ParserAdapter implements XMLReader, DocumentHandler
/**
* Get a parser property.
*
* <p>No special properties are currently supported.</p>
* <p>No properties are currently recognized.</p>
*
* @param name The property name.
* @return The property value.
* @exception org.xml.sax.SAXNotRecognizedException If the feature
* name is not known.
* @exception org.xml.sax.SAXNotSupportedException If the feature
* state is not supported.
* @exception SAXNotRecognizedException If the property
* value can't be assigned or retrieved.
* @exception SAXNotSupportedException If the property
* value is not currently readable.
* @see org.xml.sax.XMLReader#getProperty
*/
public Object getProperty (String name)
@ -283,15 +267,10 @@ public class ParserAdapter implements XMLReader, DocumentHandler
* Set the entity resolver.
*
* @param resolver The new entity resolver.
* @exception java.lang.NullPointerException If the entity resolver
* parameter is null.
* @see org.xml.sax.XMLReader#setEntityResolver
*/
public void setEntityResolver (EntityResolver resolver)
{
if (resolver == null) {
throw new NullPointerException("Null entity resolver");
}
entityResolver = resolver;
}
@ -312,15 +291,10 @@ public class ParserAdapter implements XMLReader, DocumentHandler
* Set the DTD handler.
*
* @param resolver The new DTD handler.
* @exception java.lang.NullPointerException If the DTD handler
* parameter is null.
* @see org.xml.sax.XMLReader#setEntityResolver
*/
public void setDTDHandler (DTDHandler handler)
{
if (handler == null) {
throw new NullPointerException("Null DTD handler");
}
dtdHandler = handler;
}
@ -341,15 +315,10 @@ public class ParserAdapter implements XMLReader, DocumentHandler
* Set the content handler.
*
* @param resolver The new content handler.
* @exception java.lang.NullPointerException If the content handler
* parameter is null.
* @see org.xml.sax.XMLReader#setEntityResolver
*/
public void setContentHandler (ContentHandler handler)
{
if (handler == null) {
throw new NullPointerException("Null content handler");
}
contentHandler = handler;
}
@ -370,15 +339,10 @@ public class ParserAdapter implements XMLReader, DocumentHandler
* Set the error handler.
*
* @param resolver The new error handler.
* @exception java.lang.NullPointerException If the error handler
* parameter is null.
* @see org.xml.sax.XMLReader#setEntityResolver
*/
public void setErrorHandler (ErrorHandler handler)
{
if (handler == null) {
throw new NullPointerException("Null error handler");
}
errorHandler = handler;
}
@ -401,7 +365,7 @@ public class ParserAdapter implements XMLReader, DocumentHandler
* @param systemId The absolute URL of the document.
* @exception java.io.IOException If there is a problem reading
* the raw content of the document.
* @exception org.xml.sax.SAXException If there is a problem
* @exception SAXException If there is a problem
* processing the document.
* @see #parse(org.xml.sax.InputSource)
* @see org.xml.sax.Parser#parse(java.lang.String)
@ -419,7 +383,7 @@ public class ParserAdapter implements XMLReader, DocumentHandler
* @param input An input source for the document.
* @exception java.io.IOException If there is a problem reading
* the raw content of the document.
* @exception org.xml.sax.SAXException If there is a problem
* @exception SAXException If there is a problem
* processing the document.
* @see #parse(java.lang.String)
* @see org.xml.sax.Parser#parse(org.xml.sax.InputSource)
@ -448,6 +412,7 @@ public class ParserAdapter implements XMLReader, DocumentHandler
/**
* Adapter implementation method; do not call.
* Adapt a SAX1 document locator event.
*
* @param locator A document locator.
@ -463,9 +428,10 @@ public class ParserAdapter implements XMLReader, DocumentHandler
/**
* Adapter implementation method; do not call.
* Adapt a SAX1 start document event.
*
* @exception org.xml.sax.SAXException The client may raise a
* @exception SAXException The client may raise a
* processing exception.
* @see org.xml.sax.DocumentHandler#startDocument
*/
@ -479,9 +445,10 @@ public class ParserAdapter implements XMLReader, DocumentHandler
/**
* Adapter implementation method; do not call.
* Adapt a SAX1 end document event.
*
* @exception org.xml.sax.SAXException The client may raise a
* @exception SAXException The client may raise a
* processing exception.
* @see org.xml.sax.DocumentHandler#endDocument
*/
@ -495,16 +462,25 @@ public class ParserAdapter implements XMLReader, DocumentHandler
/**
* Adapter implementation method; do not call.
* Adapt a SAX1 startElement event.
*
* <p>If necessary, perform Namespace processing.</p>
*
* @param qName The qualified (prefixed) name.
* @param qAtts The XML 1.0 attribute list (with qnames).
* @exception SAXException The client may raise a
* processing exception.
*/
public void startElement (String qName, AttributeList qAtts)
throws SAXException
{
// These are exceptions from the
// first pass; they should be
// ignored if there's a second pass,
// but reported otherwise.
Vector exceptions = null;
// If we're not doing Namespace
// processing, dispatch this quickly.
if (!namespaces) {
@ -519,80 +495,103 @@ public class ParserAdapter implements XMLReader, DocumentHandler
// OK, we're doing Namespace processing.
nsSupport.pushContext();
boolean seenDecl = false;
atts.clear();
// Take a first pass and copy all
// attributes into the SAX2 attribute
// list, noting any Namespace
// declarations.
int length = qAtts.getLength();
// First pass: handle NS decls
for (int i = 0; i < length; i++) {
String attQName = qAtts.getName(i);
if (!attQName.startsWith("xmlns"))
continue;
// Could be a declaration...
String prefix;
int n = attQName.indexOf(':');
// xmlns=...
if (n == -1 && attQName.length () == 5) {
prefix = "";
} else if (n != 5) {
// XML namespaces spec doesn't discuss "xmlnsf:oo"
// (and similarly named) attributes ... at most, warn
continue;
} else // xmlns:foo=...
prefix = attQName.substring(n+1);
String value = qAtts.getValue(i);
if (!nsSupport.declarePrefix(prefix, value)) {
reportError("Illegal Namespace prefix: " + prefix);
continue;
}
if (contentHandler != null)
contentHandler.startPrefixMapping(prefix, value);
}
// Second pass: copy all relevant
// attributes into the SAX2 AttributeList
// using updated prefix bindings
atts.clear();
for (int i = 0; i < length; i++) {
String attQName = qAtts.getName(i);
String type = qAtts.getType(i);
String value = qAtts.getValue(i);
// Found a declaration...
// Declaration?
if (attQName.startsWith("xmlns")) {
String prefix;
int n = attQName.indexOf(':');
if (n == -1) {
if (n == -1 && attQName.length () == 5) {
prefix = "";
} else if (n != 5) {
// XML namespaces spec doesn't discuss "xmlnsf:oo"
// (and similarly named) attributes ... ignore
prefix = null;
} else {
prefix = attQName.substring(n+1);
}
if (!nsSupport.declarePrefix(prefix, value)) {
reportError("Illegal Namespace prefix: " + prefix);
}
if (contentHandler != null) {
contentHandler.startPrefixMapping(prefix, value);
}
// We may still have to add this to
// the list.
if (prefixes) {
atts.addAttribute("", "", attQName.intern(),
// Yes, decl: report or prune
if (prefix != null) {
if (prefixes)
atts.addAttribute("", "", attQName.intern(),
type, value);
continue;
}
seenDecl = true;
}
// This isn't a declaration.
} else {
String attName[] = processName(attQName, true);
// Not a declaration -- report
try {
String attName[] = processName(attQName, true, true);
atts.addAttribute(attName[0], attName[1], attName[2],
type, value);
} catch (SAXException e) {
if (exceptions == null)
exceptions = new Vector();
exceptions.addElement(e);
atts.addAttribute("", attQName, attQName, type, value);
}
}
// If there was a Namespace declaration,
// we have to make a second pass just
// to be safe -- this will happen very
// rarely, possibly only once for each
// document.
if (seenDecl) {
length = atts.getLength();
for (int i = 0; i < length; i++) {
String attQName = atts.getQName(i);
if (!attQName.startsWith("xmlns")) {
String attName[] = processName(attQName, true);
atts.setURI(i, attName[0]);
atts.setLocalName(i, attName[1]);
}
}
// now handle the deferred exception reports
if (exceptions != null && errorHandler != null) {
for (int i = 0; i < exceptions.size(); i++)
errorHandler.error((SAXParseException)
(exceptions.elementAt(i)));
}
// OK, finally report the event.
if (contentHandler != null) {
String name[] = processName(qName, false);
String name[] = processName(qName, false, false);
contentHandler.startElement(name[0], name[1], name[2], atts);
}
}
/**
* Adapter implementation method; do not call.
* Adapt a SAX1 end element event.
*
* @param qName The qualified (prefixed) name.
* @exception org.xml.sax.SAXException The client may raise a
* @exception SAXException The client may raise a
* processing exception.
* @see org.xml.sax.DocumentHandler#endElement
*/
@ -609,7 +608,7 @@ public class ParserAdapter implements XMLReader, DocumentHandler
}
// Split the name.
String names[] = processName(qName, false);
String names[] = processName(qName, false, false);
if (contentHandler != null) {
contentHandler.endElement(names[0], names[1], names[2]);
Enumeration prefixes = nsSupport.getDeclaredPrefixes();
@ -623,12 +622,13 @@ public class ParserAdapter implements XMLReader, DocumentHandler
/**
* Adapter implementation method; do not call.
* Adapt a SAX1 characters event.
*
* @param ch An array of characters.
* @param start The starting position in the array.
* @param length The number of characters to use.
* @exception org.xml.sax.SAXException The client may raise a
* @exception SAXException The client may raise a
* processing exception.
* @see org.xml.sax.DocumentHandler#characters
*/
@ -642,12 +642,13 @@ public class ParserAdapter implements XMLReader, DocumentHandler
/**
* Adapter implementation method; do not call.
* Adapt a SAX1 ignorable whitespace event.
*
* @param ch An array of characters.
* @param start The starting position in the array.
* @param length The number of characters to use.
* @exception org.xml.sax.SAXException The client may raise a
* @exception SAXException The client may raise a
* processing exception.
* @see org.xml.sax.DocumentHandler#ignorableWhitespace
*/
@ -661,11 +662,12 @@ public class ParserAdapter implements XMLReader, DocumentHandler
/**
* Adapter implementation method; do not call.
* Adapt a SAX1 processing instruction event.
*
* @param target The processing instruction target.
* @param data The remainder of the processing instruction
* @exception org.xml.sax.SAXException The client may raise a
* @exception SAXException The client may raise a
* processing exception.
* @see org.xml.sax.DocumentHandler#processingInstruction
*/
@ -715,18 +717,22 @@ public class ParserAdapter implements XMLReader, DocumentHandler
* @param qName The qualified (prefixed) name.
* @param isAttribute true if this is an attribute name.
* @return The name split into three parts.
* @exception org.xml.sax.SAXException The client may throw
* @exception SAXException The client may throw
* an exception if there is an error callback.
*/
private String [] processName (String qName, boolean isAttribute)
private String [] processName (String qName, boolean isAttribute,
boolean useException)
throws SAXException
{
String parts[] = nsSupport.processName(qName, nameParts,
isAttribute);
if (parts == null) {
parts = new String[3];
parts[2] = qName.intern();
if (useException)
throw makeException("Undeclared prefix: " + qName);
reportError("Undeclared prefix: " + qName);
parts = new String[3];
parts[0] = parts[1] = "";
parts[2] = qName.intern();
}
return parts;
}
@ -736,23 +742,29 @@ public class ParserAdapter implements XMLReader, DocumentHandler
* Report a non-fatal error.
*
* @param message The error message.
* @exception org.xml.sax.SAXException The client may throw
* @exception SAXException The client may throw
* an exception.
*/
void reportError (String message)
throws SAXException
{
if (errorHandler == null) {
return;
}
if (errorHandler != null)
errorHandler.error(makeException(message));
}
SAXParseException e;
/**
* Construct an exception for the current context.
*
* @param message The error message.
*/
private SAXParseException makeException (String message)
{
if (locator != null) {
e = new SAXParseException(message, locator);
return new SAXParseException(message, locator);
} else {
e = new SAXParseException(message, null, null, -1, -1);
return new SAXParseException(message, null, null, -1, -1);
}
errorHandler.error(e);
}
@ -764,7 +776,7 @@ public class ParserAdapter implements XMLReader, DocumentHandler
*
* @param type The type of thing (feature or property).
* @param name The feature or property name.
* @exception org.xml.sax.SAXNotSupportedException If a
* @exception SAXNotSupportedException If a
* document is currently being parsed.
*/
private void checkNotParsing (String type, String name)

View File

@ -39,15 +39,12 @@ import org.xml.sax.Parser;
* <p>Note that the application still requires an XML parser that
* implements SAX1.</p>
*
* <p>Note that this is <strong>not</strong> the ParserFactory shipped with SAX 2.0.1;
* this class takes into account the needs of J2EE 1.4 AccessControllers.</p>
*
* @deprecated This class works with the deprecated
* {@link org.xml.sax.Parser Parser}
* interface.
* @since SAX 1.0
* @author David Megginson
* @version 2.0r2pre3
* @version 2.0.1 (sax2r2)
*/
public class ParserFactory {
@ -88,8 +85,7 @@ public class ParserFactory {
NullPointerException,
ClassCastException
{
SecuritySupport ss = SecuritySupport.getInstance();
String className = ss.getSystemProperty("org.xml.sax.parser");
String className = System.getProperty("org.xml.sax.parser");
if (className == null) {
throw new NullPointerException("No value for sax.parser property");
} else {

View File

@ -1,133 +0,0 @@
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The name "Apache Software Foundation" must not be used to endorse or
* promote products derived from this software without prior written
* permission. For written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 1999-2002, Sun Microsystems,
* Inc., http://www.sun.com. For more information on the Apache Software
* Foundation, please see <http://www.apache.org/>.
*/
package org.xml.sax.helpers;
import java.lang.reflect.*;
import java.net.*;
import java.io.*;
/**
* 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.
*
* Base class with security related methods that work on JDK 1.1.
*/
class SecuritySupport {
/*
* Make this of type Object so that the verifier won't try to
* prove its type, thus possibly trying to load the SecuritySupport12
* class.
*/
private static final Object securitySupport;
static {
SecuritySupport ss = null;
try {
Class c = Class.forName("java.security.AccessController");
// if that worked, we're on 1.2.
/*
* Unfortunately, we can't load the class using reflection
* because the class is package private. And the class has
* to be package private so the APIs aren't exposed to other
* code that could use them to circumvent security. Thus,
* we accept the risk that the direct reference might fail
* on some JDK 1.1 JVMs, even though we would never execute
* this code in such a case. Sigh...
*/
ss = new SecuritySupport12();
} catch (Exception ex) {
// ignore it
} finally {
if (ss == null)
ss = new SecuritySupport();
securitySupport = ss;
}
}
/**
* Return an appropriate instance of this class, depending on whether
* we're on a JDK 1.1 or J2SE 1.2 (or later) system.
*/
public static SecuritySupport getInstance() {
return (SecuritySupport)securitySupport;
}
public ClassLoader getContextClassLoader() {
return null;
}
public String getSystemProperty(String propName) {
return System.getProperty(propName);
}
public FileInputStream getFileInputStream(File file)
throws FileNotFoundException
{
return new FileInputStream(file);
}
public InputStream getResourceAsStream(ClassLoader cl, String name) {
InputStream ris;
if (cl == null) {
ris = ClassLoader.getSystemResourceAsStream(name);
} else {
ris = cl.getResourceAsStream(name);
}
return ris;
}
}

View File

@ -1,125 +0,0 @@
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The name "Apache Software Foundation" must not be used to endorse or
* promote products derived from this software without prior written
* permission. For written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 1999-2002, Sun Microsystems,
* Inc., http://www.sun.com. For more information on the Apache Software
* Foundation, please see <http://www.apache.org/>.
*/
package org.xml.sax.helpers;
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 SecuritySupport12 extends SecuritySupport {
public ClassLoader getContextClassLoader() {
return (ClassLoader)
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
ClassLoader cl = null;
try {
cl = Thread.currentThread().getContextClassLoader();
} catch (SecurityException ex) { }
return cl;
}
});
}
public String getSystemProperty(final String propName) {
return (String)
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
return System.getProperty(propName);
}
});
}
public 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();
}
}
public InputStream getResourceAsStream(final ClassLoader cl,
final String name)
{
return (InputStream)
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
InputStream ris;
if (cl == null) {
ris = ClassLoader.getSystemResourceAsStream(name);
} else {
ris = cl.getResourceAsStream(name);
}
return ris;
}
});
}
}

View File

@ -1,5 +1,6 @@
// XMLFilterImpl.java - base SAX2 filter implementation.
// Written by David Megginson, sax@megginson.com
// http://www.saxproject.org
// Written by David Megginson
// NO WARRANTY! This class is in the Public Domain.
// $Id$
@ -29,6 +30,8 @@ import org.xml.sax.SAXNotRecognizedException;
* <blockquote>
* <em>This module, both source code and documentation, is in the
* Public Domain, and comes with <strong>NO WARRANTY</strong>.</em>
* See <a href='http://www.saxproject.org'>http://www.saxproject.org</a>
* for further information.
* </blockquote>
*
* <p>This class is designed to sit between an {@link org.xml.sax.XMLReader
@ -38,14 +41,9 @@ import org.xml.sax.SAXNotRecognizedException;
* specific methods to modify the event stream or the configuration
* requests as they pass through.</p>
*
* <p>Note that this is <strong>not</strong> the version shipped with SAX 2.0.1; this class
* throws NullPointerExceptions when setter methods are called with null parameters;
* the 2.0.1 version does not exhibit this behaviour. </p>
*
* @since SAX 2.0
* @author David Megginson,
* <a href="mailto:sax@megginson.com">sax@megginson.com</a>
* @version 2.0
* @author David Megginson
* @version 2.0.1 (sax2r2)
* @see org.xml.sax.XMLFilter
* @see org.xml.sax.XMLReader
* @see org.xml.sax.EntityResolver
@ -68,10 +66,12 @@ public class XMLFilterImpl
*
* <p>This filter will have no parent: you must assign a parent
* before you start a parse or do any configuration with
* setFeature or setProperty.</p>
* setFeature or setProperty, unless you use this as a pure event
* consumer rather than as an {@link XMLReader}.</p>
*
* @see org.xml.sax.XMLReader#setFeature
* @see org.xml.sax.XMLReader#setProperty
* @see #setParent
*/
public XMLFilterImpl ()
{
@ -109,14 +109,10 @@ public class XMLFilterImpl
* or to set or get a feature or property will fail.</p>
*
* @param parent The parent XML reader.
* @exception java.lang.NullPointerException If the parent is null.
* @see #getParent
*/
public void setParent (XMLReader parent)
{
if (parent == null) {
throw new NullPointerException("Null parent");
}
this.parent = parent;
}
@ -140,24 +136,23 @@ public class XMLFilterImpl
/**
* Set the state of a feature.
* Set the value of a feature.
*
* <p>This will always fail if the parent is null.</p>
*
* @param name The feature name.
* @param state The requested feature state.
* @exception org.xml.sax.SAXNotRecognizedException When the
* XMLReader does not recognize the feature name.
* @param value The requested feature value.
* @exception org.xml.sax.SAXNotRecognizedException If the feature
* value can't be assigned or retrieved from the parent.
* @exception org.xml.sax.SAXNotSupportedException When the
* XMLReader recognizes the feature name but
* parent recognizes the feature name but
* cannot set the requested value.
* @see org.xml.sax.XMLReader#setFeature
*/
public void setFeature (String name, boolean state)
public void setFeature (String name, boolean value)
throws SAXNotRecognizedException, SAXNotSupportedException
{
if (parent != null) {
parent.setFeature(name, state);
parent.setFeature(name, value);
} else {
throw new SAXNotRecognizedException("Feature: " + name);
}
@ -165,18 +160,17 @@ public class XMLFilterImpl
/**
* Look up the state of a feature.
* Look up the value of a feature.
*
* <p>This will always fail if the parent is null.</p>
*
* @param name The feature name.
* @return The current state of the feature.
* @exception org.xml.sax.SAXNotRecognizedException When the
* XMLReader does not recognize the feature name.
* @return The current value of the feature.
* @exception org.xml.sax.SAXNotRecognizedException If the feature
* value can't be assigned or retrieved from the parent.
* @exception org.xml.sax.SAXNotSupportedException When the
* XMLReader recognizes the feature name but
* cannot determine its state at this time.
* @see org.xml.sax.XMLReader#getFeature
* parent recognizes the feature name but
* cannot determine its value at this time.
*/
public boolean getFeature (String name)
throws SAXNotRecognizedException, SAXNotSupportedException
@ -195,13 +189,12 @@ public class XMLFilterImpl
* <p>This will always fail if the parent is null.</p>
*
* @param name The property name.
* @param state The requested property value.
* @exception org.xml.sax.SAXNotRecognizedException When the
* XMLReader does not recognize the property name.
* @param value The requested property value.
* @exception org.xml.sax.SAXNotRecognizedException If the property
* value can't be assigned or retrieved from the parent.
* @exception org.xml.sax.SAXNotSupportedException When the
* XMLReader recognizes the property name but
* parent recognizes the property name but
* cannot set the requested value.
* @see org.xml.sax.XMLReader#setProperty
*/
public void setProperty (String name, Object value)
throws SAXNotRecognizedException, SAXNotSupportedException
@ -219,12 +212,11 @@ public class XMLFilterImpl
*
* @param name The property name.
* @return The current value of the property.
* @exception org.xml.sax.SAXNotRecognizedException When the
* XMLReader does not recognize the feature name.
* @exception org.xml.sax.SAXNotRecognizedException If the property
* value can't be assigned or retrieved from the parent.
* @exception org.xml.sax.SAXNotSupportedException When the
* XMLReader recognizes the property name but
* parent recognizes the property name but
* cannot determine its value at this time.
* @see org.xml.sax.XMLReader#setFeature
*/
public Object getProperty (String name)
throws SAXNotRecognizedException, SAXNotSupportedException
@ -241,17 +233,10 @@ public class XMLFilterImpl
* Set the entity resolver.
*
* @param resolver The new entity resolver.
* @exception java.lang.NullPointerException If the resolver
* is null.
* @see org.xml.sax.XMLReader#setEntityResolver
*/
public void setEntityResolver (EntityResolver resolver)
{
if (resolver == null) {
throw new NullPointerException("Null entity resolver");
} else {
entityResolver = resolver;
}
entityResolver = resolver;
}
@ -259,7 +244,6 @@ public class XMLFilterImpl
* Get the current entity resolver.
*
* @return The current entity resolver, or null if none was set.
* @see org.xml.sax.XMLReader#getEntityResolver
*/
public EntityResolver getEntityResolver ()
{
@ -271,17 +255,10 @@ public class XMLFilterImpl
* Set the DTD event handler.
*
* @param resolver The new DTD handler.
* @exception java.lang.NullPointerException If the handler
* is null.
* @see org.xml.sax.XMLReader#setDTDHandler
*/
public void setDTDHandler (DTDHandler handler)
{
if (handler == null) {
throw new NullPointerException("Null DTD handler");
} else {
dtdHandler = handler;
}
dtdHandler = handler;
}
@ -289,7 +266,6 @@ public class XMLFilterImpl
* Get the current DTD event handler.
*
* @return The current DTD handler, or null if none was set.
* @see org.xml.sax.XMLReader#getDTDHandler
*/
public DTDHandler getDTDHandler ()
{
@ -301,17 +277,10 @@ public class XMLFilterImpl
* Set the content event handler.
*
* @param resolver The new content handler.
* @exception java.lang.NullPointerException If the handler
* is null.
* @see org.xml.sax.XMLReader#setContentHandler
*/
public void setContentHandler (ContentHandler handler)
{
if (handler == null) {
throw new NullPointerException("Null content handler");
} else {
contentHandler = handler;
}
contentHandler = handler;
}
@ -319,7 +288,6 @@ public class XMLFilterImpl
* Get the content event handler.
*
* @return The current content handler, or null if none was set.
* @see org.xml.sax.XMLReader#getContentHandler
*/
public ContentHandler getContentHandler ()
{
@ -331,17 +299,10 @@ public class XMLFilterImpl
* Set the error event handler.
*
* @param handle The new error handler.
* @exception java.lang.NullPointerException If the handler
* is null.
* @see org.xml.sax.XMLReader#setErrorHandler
*/
public void setErrorHandler (ErrorHandler handler)
{
if (handler == null) {
throw new NullPointerException("Null error handler");
} else {
errorHandler = handler;
}
errorHandler = handler;
}
@ -349,7 +310,6 @@ public class XMLFilterImpl
* Get the current error event handler.
*
* @return The current error handler, or null if none was set.
* @see org.xml.sax.XMLReader#getErrorHandler
*/
public ErrorHandler getErrorHandler ()
{
@ -366,7 +326,6 @@ public class XMLFilterImpl
* @exception java.io.IOException An IO exception from the parser,
* possibly from a byte stream or character stream
* supplied by the application.
* @see org.xml.sax.XMLReader#parse(org.xml.sax.InputSource)
*/
public void parse (InputSource input)
throws SAXException, IOException
@ -385,7 +344,6 @@ public class XMLFilterImpl
* @exception java.io.IOException An IO exception from the parser,
* possibly from a byte stream or character stream
* supplied by the application.
* @see org.xml.sax.XMLReader#parse(java.lang.String)
*/
public void parse (String systemId)
throws SAXException, IOException
@ -411,7 +369,6 @@ public class XMLFilterImpl
* @exception java.io.IOException The client may throw an
* I/O-related exception while obtaining the
* new InputSource.
* @see org.xml.sax.EntityResolver#resolveEntity
*/
public InputSource resolveEntity (String publicId, String systemId)
throws SAXException, IOException
@ -438,7 +395,6 @@ public class XMLFilterImpl
* @param systemId The notation's system identifier, or null.
* @exception org.xml.sax.SAXException The client may throw
* an exception during processing.
* @see org.xml.sax.DTDHandler#notationDecl
*/
public void notationDecl (String name, String publicId, String systemId)
throws SAXException
@ -458,7 +414,6 @@ public class XMLFilterImpl
* @param notationName The name of the associated notation.
* @exception org.xml.sax.SAXException The client may throw
* an exception during processing.
* @see org.xml.sax.DTDHandler#unparsedEntityDecl
*/
public void unparsedEntityDecl (String name, String publicId,
String systemId, String notationName)
@ -481,7 +436,6 @@ public class XMLFilterImpl
* Filter a new document locator event.
*
* @param locator The document locator.
* @see org.xml.sax.ContentHandler#setDocumentLocator
*/
public void setDocumentLocator (Locator locator)
{
@ -497,7 +451,6 @@ public class XMLFilterImpl
*
* @exception org.xml.sax.SAXException The client may throw
* an exception during processing.
* @see org.xml.sax.ContentHandler#startDocument
*/
public void startDocument ()
throws SAXException
@ -513,7 +466,6 @@ public class XMLFilterImpl
*
* @exception org.xml.sax.SAXException The client may throw
* an exception during processing.
* @see org.xml.sax.ContentHandler#endDocument
*/
public void endDocument ()
throws SAXException
@ -531,7 +483,6 @@ public class XMLFilterImpl
* @param uri The Namespace URI.
* @exception org.xml.sax.SAXException The client may throw
* an exception during processing.
* @see org.xml.sax.ContentHandler#startPrefixMapping
*/
public void startPrefixMapping (String prefix, String uri)
throws SAXException
@ -548,7 +499,6 @@ public class XMLFilterImpl
* @param prefix The Namespace prefix.
* @exception org.xml.sax.SAXException The client may throw
* an exception during processing.
* @see org.xml.sax.ContentHandler#endPrefixMapping
*/
public void endPrefixMapping (String prefix)
throws SAXException
@ -569,7 +519,6 @@ public class XMLFilterImpl
* @param atts The element's attributes.
* @exception org.xml.sax.SAXException The client may throw
* an exception during processing.
* @see org.xml.sax.ContentHandler#startElement
*/
public void startElement (String uri, String localName, String qName,
Attributes atts)
@ -590,7 +539,6 @@ public class XMLFilterImpl
* string.
* @exception org.xml.sax.SAXException The client may throw
* an exception during processing.
* @see org.xml.sax.ContentHandler#endElement
*/
public void endElement (String uri, String localName, String qName)
throws SAXException
@ -609,7 +557,6 @@ public class XMLFilterImpl
* @param length The number of characters to use from the array.
* @exception org.xml.sax.SAXException The client may throw
* an exception during processing.
* @see org.xml.sax.ContentHandler#characters
*/
public void characters (char ch[], int start, int length)
throws SAXException
@ -628,7 +575,6 @@ public class XMLFilterImpl
* @param length The number of characters to use from the array.
* @exception org.xml.sax.SAXException The client may throw
* an exception during processing.
* @see org.xml.sax.ContentHandler#ignorableWhitespace
*/
public void ignorableWhitespace (char ch[], int start, int length)
throws SAXException
@ -646,7 +592,6 @@ public class XMLFilterImpl
* @param data The text following the target.
* @exception org.xml.sax.SAXException The client may throw
* an exception during processing.
* @see org.xml.sax.ContentHandler#processingInstruction
*/
public void processingInstruction (String target, String data)
throws SAXException
@ -663,7 +608,6 @@ public class XMLFilterImpl
* @param name The name of the skipped entity.
* @exception org.xml.sax.SAXException The client may throw
* an exception during processing.
* @see org.xml.sax.ContentHandler#skippedEntity
*/
public void skippedEntity (String name)
throws SAXException
@ -683,10 +627,9 @@ public class XMLFilterImpl
/**
* Filter a warning event.
*
* @param e The nwarning as an exception.
* @param e The warning as an exception.
* @exception org.xml.sax.SAXException The client may throw
* an exception during processing.
* @see org.xml.sax.ErrorHandler#warning
*/
public void warning (SAXParseException e)
throws SAXException
@ -703,7 +646,6 @@ public class XMLFilterImpl
* @param e The error as an exception.
* @exception org.xml.sax.SAXException The client may throw
* an exception during processing.
* @see org.xml.sax.ErrorHandler#error
*/
public void error (SAXParseException e)
throws SAXException
@ -720,7 +662,6 @@ public class XMLFilterImpl
* @param e The error as an exception.
* @exception org.xml.sax.SAXException The client may throw
* an exception during processing.
* @see org.xml.sax.ErrorHandler#fatalError
*/
public void fatalError (SAXParseException e)
throws SAXException

View File

@ -1,5 +1,6 @@
// XMLReaderAdapter.java - adapt an SAX2 XMLReader to a SAX1 Parser
// Written by David Megginson, sax@megginson.com
// http://www.saxproject.org
// Written by David Megginson
// NO WARRANTY! This class is in the public domain.
// $Id$
@ -31,6 +32,8 @@ import org.xml.sax.SAXNotSupportedException;
* <blockquote>
* <em>This module, both source code and documentation, is in the
* Public Domain, and comes with <strong>NO WARRANTY</strong>.</em>
* See <a href='http://www.saxproject.org'>http://www.saxproject.org</a>
* for further information.
* </blockquote>
*
* <p>This class wraps a SAX2 {@link org.xml.sax.XMLReader XMLReader}
@ -41,14 +44,9 @@ import org.xml.sax.SAXNotSupportedException;
* supports a false value for the http://xml.org/sax/features/namespaces
* property, that will also be used to improve efficiency.</p>
*
* <p>Note that this is <strong>not</strong> the version shipped with SAX 2.0.1; this class
* throws NullPointerExceptions when setter methods are called with null parameters;
* the 2.0.1 version does not exhibit this behaviour. </p>
*
* @since SAX 2.0
* @author David Megginson,
* <a href="mailto:sax@megginson.com">sax@megginson.com</a>
* @version 2.0
* @author David Megginson
* @version 2.0.1 (sax2r2)
* @see org.xml.sax.Parser
* @see org.xml.sax.XMLReader
*/
@ -124,6 +122,7 @@ public class XMLReaderAdapter implements Parser, ContentHandler
*
* @param The locale for error reporting.
* @see org.xml.sax.Parser#setLocale
* @exception org.xml.sax.SAXException Thrown unless overridden.
*/
public void setLocale (Locale locale)
throws SAXException
@ -259,7 +258,8 @@ public class XMLReaderAdapter implements Parser, ContentHandler
*/
public void setDocumentLocator (Locator locator)
{
documentHandler.setDocumentLocator(locator);
if (documentHandler != null)
documentHandler.setDocumentLocator(locator);
}
@ -273,7 +273,8 @@ public class XMLReaderAdapter implements Parser, ContentHandler
public void startDocument ()
throws SAXException
{
documentHandler.startDocument();
if (documentHandler != null)
documentHandler.startDocument();
}
@ -287,7 +288,8 @@ public class XMLReaderAdapter implements Parser, ContentHandler
public void endDocument ()
throws SAXException
{
documentHandler.endDocument();
if (documentHandler != null)
documentHandler.endDocument();
}
@ -329,8 +331,10 @@ public class XMLReaderAdapter implements Parser, ContentHandler
String qName, Attributes atts)
throws SAXException
{
qAtts.setAttributes(atts);
documentHandler.startElement(qName, qAtts);
if (documentHandler != null) {
qAtts.setAttributes(atts);
documentHandler.startElement(qName, qAtts);
}
}
@ -348,7 +352,8 @@ public class XMLReaderAdapter implements Parser, ContentHandler
String qName)
throws SAXException
{
documentHandler.endElement(qName);
if (documentHandler != null)
documentHandler.endElement(qName);
}
@ -365,7 +370,8 @@ public class XMLReaderAdapter implements Parser, ContentHandler
public void characters (char ch[], int start, int length)
throws SAXException
{
documentHandler.characters(ch, start, length);
if (documentHandler != null)
documentHandler.characters(ch, start, length);
}
@ -382,7 +388,8 @@ public class XMLReaderAdapter implements Parser, ContentHandler
public void ignorableWhitespace (char ch[], int start, int length)
throws SAXException
{
documentHandler.ignorableWhitespace(ch, start, length);
if (documentHandler != null)
documentHandler.ignorableWhitespace(ch, start, length);
}
@ -398,7 +405,8 @@ public class XMLReaderAdapter implements Parser, ContentHandler
public void processingInstruction (String target, String data)
throws SAXException
{
documentHandler.processingInstruction(target, data);
if (documentHandler != null)
documentHandler.processingInstruction(target, data);
}
@ -407,6 +415,7 @@ public class XMLReaderAdapter implements Parser, ContentHandler
*
* @param name The name of the skipped entity.
* @see org.xml.sax.ContentHandler#skippedEntity
* @exception org.xml.sax.SAXException Throwable by subclasses.
*/
public void skippedEntity (String name)
throws SAXException

View File

@ -3,6 +3,7 @@
// Written by David Megginson
// and by David Brownell
// NO WARRANTY! This class is in the Public Domain.
// $Id$
package org.xml.sax.helpers;
@ -42,12 +43,9 @@ import org.xml.sax.SAXException;
* nothing bound its class name to <code>org.xml.sax.driver</code> so
* those configuration mechanisms would see it.</p>
*
* <p>Note that this is <strong>not</strong> the XMLReaderFactory shipped with SAX 2.0.1;
* this class takes into account the needs of J2EE 1.4 AccessControllers.</p>
*
* @since SAX 2.0
* @author David Megginson, David Brownell
* @version 2.0r2pre3
* @version 2.0.1 (sax2r2)
*/
final public class XMLReaderFactory
{
@ -107,89 +105,44 @@ final public class XMLReaderFactory
public static XMLReader createXMLReader ()
throws SAXException
{
String className = null;
SecuritySupport ss = SecuritySupport.getInstance();
ClassLoader loader = NewInstance.getClassLoader ();
String className = null;
ClassLoader loader = NewInstance.getClassLoader ();
// 1. try the JVM-instance-wide system property
try {
className = ss.getSystemProperty(property);
} catch (Exception e) { /* normally fails for applets */ }
// 1. try the JVM-instance-wide system property
try { className = System.getProperty (property); }
catch (Exception e) { /* normally fails for applets */ }
// 2. if that fails, try META-INF/services/
if (className == null) {
String service = "META-INF/services/" + property;
try {
String service = "META-INF/services/" + property;
InputStream in;
BufferedReader reader;
InputStream is = null;
if (loader == null)
in = ClassLoader.getSystemResourceAsStream (service);
else
in = loader.getResourceAsStream (service);
// First try the Context ClassLoader
ClassLoader cl = ss.getContextClassLoader();
if (cl != null) {
is = ss.getResourceAsStream(cl, service);
// If no provider found then try the current ClassLoader
if (is == null) {
cl = XMLReaderFactory.class.getClassLoader();
is = ss.getResourceAsStream(cl, service);
}
} else {
// No Context ClassLoader or JDK 1.1 so try the current
// ClassLoader
cl = XMLReaderFactory.class.getClassLoader();
is = ss.getResourceAsStream(cl, service);
}
if (is != null) {
// Read the service provider name in UTF-8 as specified in
// the jar spec. Unfortunately this fails in Microsoft
// VJ++, which does not implement the UTF-8
// encoding. Theoretically, we should simply let it fail in
// that case, since the JVM is obviously broken if it
// doesn't support such a basic standard. But since there
// are still some users attempting to use VJ++ for
// development, we have dropped in a fallback which makes a
// second attempt using the platform's default encoding. In
// VJ++ this is apparently ASCII, which is a subset of
// UTF-8... and since the strings we'll be reading here are
// also primarily limited to the 7-bit ASCII range (at
// least, in English versions), this should work well
// enough to keep us on the air until we're ready to
// officially decommit from VJ++. [Edited comment from
// jkesselm]
BufferedReader rd;
try {
rd = new BufferedReader(new InputStreamReader(is, "UTF-8"));
} catch (java.io.UnsupportedEncodingException e) {
rd = new BufferedReader(new InputStreamReader(is));
}
try {
// XXX Does not handle all possible input as specified by the
// Jar Service Provider specification
className = rd.readLine();
rd.close();
} catch (Exception x) {
// No provider found
}
}
if (in != null) {
reader = new BufferedReader (
new InputStreamReader (in, "UTF8"));
className = reader.readLine ();
in.close ();
}
} catch (Exception e) {
}
}
// REVISIT: there is a comment in the original FactoryFinder codde to the effect:
//
// ClassLoader because we want to avoid the case where the
// resource file was found using one ClassLoader and the
// provider class was instantiated using a different one.
//
// But it's not clear how the class loader "cl" (now out of scope!)
// that loaded the inputStream would matter here...
// 3. Distro-specific fallback
if (className == null) {
// modified by neilg in accordance with the "strong encouragement"
// provided to distributions which include parsers.
// BEGIN DISTRIBUTION-SPECIFIC
className = "org.apache.xerces.parsers.SAXParser";
// EXAMPLE:
// className = "com.example.sax.XmlReader";
// or a $JAVA_HOME/jre/lib/*properties setting...
// END DISTRIBUTION-SPECIFIC
}
// do we know the XMLReader implementation class yet?