7160380: Sync JDK8 with JAXP 1.4.5

Bring JDK8 up to date to what we have in 7u4

Reviewed-by: lancea, mullan
This commit is contained in:
Joe Wang 2012-04-17 11:17:59 -07:00
parent 60663487f6
commit db4db38876
213 changed files with 5006 additions and 15178 deletions

View file

@ -0,0 +1,60 @@
/*
* Copyright (c) 2011 Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.org.apache.xalan.internal;
import com.sun.org.apache.xerces.internal.impl.*;
import java.util.Enumeration;
import java.util.NoSuchElementException;
/**
* Commonly used constants.
*
* @author Huizhe Wang, Oracle
*
* @version $Id: Constants.java,v 1.14 2011-06-07 04:39:40 joehw Exp $
*/
public final class XalanConstants {
//
// Constants
//
// Oracle Feature:
/**
* <p>Use Service Mechanism</p>
*
* <ul>
* <li>
* <code>true</code> instructs the implementation to use service mechanism to find implementation.
* This is the default behavior.
* </li>
* <li>
* <code>false</code> instructs the implementation to skip service mechanism and use the default implementation.
* </li>
* </ul>
*/
public static final String ORACLE_FEATURE_SERVICE_MECHANISM = "http://www.oracle.com/feature/use-service-mechanism";
} // class Constants

View file

@ -97,7 +97,7 @@ public class ExsltDatetime
// In a few cases, the time zone may be +/-hh:30.
int min = offset%(60*60*1000);
char posneg = hrs < 0? '-': '+';
buff.append(posneg + formatDigits(hrs) + ':' + formatDigits(min));
buff.append(posneg).append(formatDigits(hrs)).append(':').append(formatDigits(min));
}
return buff.toString();
}

View file

@ -381,7 +381,7 @@ public class ExsltMath extends ExsltBase
if (bits <= value.length())
value = value.substring(0, bits);
return new Double(value).doubleValue();
return Double.parseDouble(value);
}
else
return Double.NaN;

View file

@ -35,6 +35,7 @@ import com.sun.org.apache.xpath.internal.NodeSet;
import com.sun.org.apache.xpath.internal.objects.XBoolean;
import com.sun.org.apache.xpath.internal.objects.XNumber;
import com.sun.org.apache.xpath.internal.objects.XObject;
import com.sun.org.apache.xalan.internal.utils.ObjectFactory;
import org.w3c.dom.Document;
import org.w3c.dom.DocumentFragment;
@ -363,8 +364,7 @@ public class Extensions
try
{
// Use reflection to try to find xml-commons utility 'Which'
Class clazz = ObjectFactory.findProviderClass(
WHICH_CLASSNAME, ObjectFactory.findClassLoader(), true);
Class clazz = ObjectFactory.findProviderClass(WHICH_CLASSNAME, true);
if (null == clazz)
return null;

View file

@ -1,661 +0,0 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 2001-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: ObjectFactory.java,v 1.2.4.1 2005/09/15 02:39:54 jeffsuttor Exp $
*/
package com.sun.org.apache.xalan.internal.lib;
import java.io.InputStream;
import java.io.IOException;
import java.io.File;
import java.io.FileInputStream;
import java.util.Properties;
import java.io.BufferedReader;
import java.io.InputStreamReader;
/**
* This class is duplicated for each JAXP subpackage so keep it in sync.
* It is package private and therefore is not exposed as part of the JAXP
* API.
* <p>
* This code is designed to implement the JAXP 1.1 spec pluggability
* feature and is designed to run on JDK version 1.1 and
* later, and to compile on JDK 1.2 and onward.
* The code also runs both as part of an unbundled jar file and
* when bundled as part of the JDK.
* <p>
* This class was moved from the <code>javax.xml.parsers.ObjectFactory</code>
* class and modified to be used as a general utility for creating objects
* dynamically.
*
* @version $Id: ObjectFactory.java,v 1.9 2008/04/02 00:40:59 joehw Exp $
*/
class ObjectFactory {
//
// Constants
//
// name of default properties file to look for in JDK's jre/lib directory
private static final String DEFAULT_PROPERTIES_FILENAME =
"xalan.properties";
private static final String SERVICES_PATH = "META-INF/services/";
/** Set to true for debugging */
private static final boolean DEBUG = false;
/** cache the contents of the xalan.properties file.
* Until an attempt has been made to read this file, this will
* be null; if the file does not exist or we encounter some other error
* during the read, this will be empty.
*/
private static Properties fXalanProperties = null;
/***
* Cache the time stamp of the xalan.properties file so
* that we know if it's been modified and can invalidate
* the cache when necessary.
*/
private static long fLastModified = -1;
//
// Public static methods
//
/**
* Finds the implementation Class object in the specified order. The
* specified order is the following:
* <ol>
* <li>query the system property using <code>System.getProperty</code>
* <li>read <code>META-INF/services/<i>factoryId</i></code> file
* <li>use fallback classname
* </ol>
*
* @return instance of factory, never null
*
* @param factoryId Name of the factory to find, same as
* a property name
* @param fallbackClassName Implementation class name, if nothing else
* is found. Use null to mean no fallback.
*
* @exception ObjectFactory.ConfigurationError
*/
static Object createObject(String factoryId, String fallbackClassName)
throws ConfigurationError {
return createObject(factoryId, null, fallbackClassName);
} // createObject(String,String):Object
/**
* Finds the implementation Class object in the specified order. The
* specified order is the following:
* <ol>
* <li>query the system property using <code>System.getProperty</code>
* <li>read <code>$java.home/lib/<i>propertiesFilename</i></code> file
* <li>read <code>META-INF/services/<i>factoryId</i></code> file
* <li>use fallback classname
* </ol>
*
* @return instance of factory, never null
*
* @param factoryId Name of the factory to find, same as
* a property name
* @param propertiesFilename The filename in the $java.home/lib directory
* of the properties file. If none specified,
* ${java.home}/lib/xalan.properties will be used.
* @param fallbackClassName Implementation class name, if nothing else
* is found. Use null to mean no fallback.
*
* @exception ObjectFactory.ConfigurationError
*/
static Object createObject(String factoryId,
String propertiesFilename,
String fallbackClassName)
throws ConfigurationError
{
Class factoryClass = lookUpFactoryClass(factoryId,
propertiesFilename,
fallbackClassName);
if (factoryClass == null) {
throw new ConfigurationError(
"Provider for " + factoryId + " cannot be found", null);
}
try{
Object instance = factoryClass.newInstance();
if (DEBUG) debugPrintln("created new instance of factory " + factoryId);
return instance;
} catch (Exception x) {
throw new ConfigurationError(
"Provider for factory " + factoryId
+ " could not be instantiated: " + x, x);
}
} // createObject(String,String,String):Object
/**
* Finds the implementation Class object in the specified order. The
* specified order is the following:
* <ol>
* <li>query the system property using <code>System.getProperty</code>
* <li>read <code>$java.home/lib/<i>propertiesFilename</i></code> file
* <li>read <code>META-INF/services/<i>factoryId</i></code> file
* <li>use fallback classname
* </ol>
*
* @return Class object of factory, never null
*
* @param factoryId Name of the factory to find, same as
* a property name
* @param propertiesFilename The filename in the $java.home/lib directory
* of the properties file. If none specified,
* ${java.home}/lib/xalan.properties will be used.
* @param fallbackClassName Implementation class name, if nothing else
* is found. Use null to mean no fallback.
*
* @exception ObjectFactory.ConfigurationError
*/
static Class lookUpFactoryClass(String factoryId)
throws ConfigurationError
{
return lookUpFactoryClass(factoryId, null, null);
} // lookUpFactoryClass(String):Class
/**
* Finds the implementation Class object in the specified order. The
* specified order is the following:
* <ol>
* <li>query the system property using <code>System.getProperty</code>
* <li>read <code>$java.home/lib/<i>propertiesFilename</i></code> file
* <li>read <code>META-INF/services/<i>factoryId</i></code> file
* <li>use fallback classname
* </ol>
*
* @return Class object that provides factory service, never null
*
* @param factoryId Name of the factory to find, same as
* a property name
* @param propertiesFilename The filename in the $java.home/lib directory
* of the properties file. If none specified,
* ${java.home}/lib/xalan.properties will be used.
* @param fallbackClassName Implementation class name, if nothing else
* is found. Use null to mean no fallback.
*
* @exception ObjectFactory.ConfigurationError
*/
static Class lookUpFactoryClass(String factoryId,
String propertiesFilename,
String fallbackClassName)
throws ConfigurationError
{
String factoryClassName = lookUpFactoryClassName(factoryId,
propertiesFilename,
fallbackClassName);
ClassLoader cl = findClassLoader();
if (factoryClassName == null) {
factoryClassName = fallbackClassName;
}
// assert(className != null);
try{
Class providerClass = findProviderClass(factoryClassName,
cl,
true);
if (DEBUG) debugPrintln("created new instance of " + providerClass +
" using ClassLoader: " + cl);
return providerClass;
} catch (ClassNotFoundException x) {
throw new ConfigurationError(
"Provider " + factoryClassName + " not found", x);
} catch (Exception x) {
throw new ConfigurationError(
"Provider "+factoryClassName+" could not be instantiated: "+x,
x);
}
} // lookUpFactoryClass(String,String,String):Class
/**
* Finds the name of the required implementation class in the specified
* order. The specified order is the following:
* <ol>
* <li>query the system property using <code>System.getProperty</code>
* <li>read <code>$java.home/lib/<i>propertiesFilename</i></code> file
* <li>read <code>META-INF/services/<i>factoryId</i></code> file
* <li>use fallback classname
* </ol>
*
* @return name of class that provides factory service, never null
*
* @param factoryId Name of the factory to find, same as
* a property name
* @param propertiesFilename The filename in the $java.home/lib directory
* of the properties file. If none specified,
* ${java.home}/lib/xalan.properties will be used.
* @param fallbackClassName Implementation class name, if nothing else
* is found. Use null to mean no fallback.
*
* @exception ObjectFactory.ConfigurationError
*/
static String lookUpFactoryClassName(String factoryId,
String propertiesFilename,
String fallbackClassName)
{
SecuritySupport ss = SecuritySupport.getInstance();
// Use the system property first
try {
String systemProp = ss.getSystemProperty(factoryId);
if (systemProp != null) {
if (DEBUG) debugPrintln("found system property, value=" + systemProp);
return systemProp;
}
} catch (SecurityException se) {
// Ignore and continue w/ next location
}
// Try to read from propertiesFilename, or
// $java.home/lib/xalan.properties
String factoryClassName = null;
// no properties file name specified; use
// $JAVA_HOME/lib/xalan.properties:
if (propertiesFilename == null) {
File propertiesFile = null;
boolean propertiesFileExists = false;
try {
String javah = ss.getSystemProperty("java.home");
propertiesFilename = javah + File.separator +
"lib" + File.separator + DEFAULT_PROPERTIES_FILENAME;
propertiesFile = new File(propertiesFilename);
propertiesFileExists = ss.getFileExists(propertiesFile);
} catch (SecurityException e) {
// try again...
fLastModified = -1;
fXalanProperties = null;
}
synchronized (ObjectFactory.class) {
boolean loadProperties = false;
FileInputStream fis = null;
try {
// file existed last time
if(fLastModified >= 0) {
if(propertiesFileExists &&
(fLastModified < (fLastModified = ss.getLastModified(propertiesFile)))) {
loadProperties = true;
} else {
// file has stopped existing...
if(!propertiesFileExists) {
fLastModified = -1;
fXalanProperties = null;
} // else, file wasn't modified!
}
} else {
// file has started to exist:
if(propertiesFileExists) {
loadProperties = true;
fLastModified = ss.getLastModified(propertiesFile);
} // else, nothing's changed
}
if(loadProperties) {
// must never have attempted to read xalan.properties
// before (or it's outdeated)
fXalanProperties = new Properties();
fis = ss.getFileInputStream(propertiesFile);
fXalanProperties.load(fis);
}
} catch (Exception x) {
fXalanProperties = null;
fLastModified = -1;
// assert(x instanceof FileNotFoundException
// || x instanceof SecurityException)
// In both cases, ignore and continue w/ next location
}
finally {
// try to close the input stream if one was opened.
if (fis != null) {
try {
fis.close();
}
// Ignore the exception.
catch (IOException exc) {}
}
}
}
if(fXalanProperties != null) {
factoryClassName = fXalanProperties.getProperty(factoryId);
}
} else {
FileInputStream fis = null;
try {
fis = ss.getFileInputStream(new File(propertiesFilename));
Properties props = new Properties();
props.load(fis);
factoryClassName = props.getProperty(factoryId);
} catch (Exception x) {
// assert(x instanceof FileNotFoundException
// || x instanceof SecurityException)
// In both cases, ignore and continue w/ next location
}
finally {
// try to close the input stream if one was opened.
if (fis != null) {
try {
fis.close();
}
// Ignore the exception.
catch (IOException exc) {}
}
}
}
if (factoryClassName != null) {
if (DEBUG) debugPrintln("found in " + propertiesFilename + ", value="
+ factoryClassName);
return factoryClassName;
}
// Try Jar Service Provider Mechanism
return findJarServiceProviderName(factoryId);
} // lookUpFactoryClass(String,String):String
//
// Private static methods
//
/** Prints a message to standard error if debugging is enabled. */
private static void debugPrintln(String msg) {
System.err.println("JAXP: " + msg);
} // debugPrintln(String)
/**
* Figure out which ClassLoader to use. For JDK 1.2 and later use
* the context ClassLoader.
*/
static ClassLoader findClassLoader()
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 context = ss.getContextClassLoader();
ClassLoader system = ss.getSystemClassLoader();
ClassLoader chain = system;
while (true) {
if (context == chain) {
// Assert: we are on JDK 1.1 or we have no Context ClassLoader
// or any Context ClassLoader in chain of system classloader
// (including extension ClassLoader) so extend to widest
// ClassLoader (always look in system ClassLoader if Xalan
// is in boot/extension/system classpath and in current
// ClassLoader otherwise); normal classloaders delegate
// back to system ClassLoader first so this widening doesn't
// change the fact that context ClassLoader will be consulted
ClassLoader current = ObjectFactory.class.getClassLoader();
chain = system;
while (true) {
if (current == chain) {
// Assert: Current ClassLoader in chain of
// boot/extension/system ClassLoaders
return system;
}
if (chain == null) {
break;
}
chain = ss.getParentClassLoader(chain);
}
// Assert: Current ClassLoader not in chain of
// boot/extension/system ClassLoaders
return current;
}
if (chain == null) {
// boot ClassLoader reached
break;
}
// Check for any extension ClassLoaders in chain up to
// boot ClassLoader
chain = ss.getParentClassLoader(chain);
};
// Assert: Context ClassLoader not in chain of
// boot/extension/system ClassLoaders
return context;
} // findClassLoader():ClassLoader
/**
* Create an instance of a class using the specified ClassLoader
*/
static Object newInstance(String className, ClassLoader cl,
boolean doFallback)
throws ConfigurationError
{
// assert(className != null);
try{
Class providerClass = findProviderClass(className, cl, doFallback);
Object instance = providerClass.newInstance();
if (DEBUG) debugPrintln("created new instance of " + providerClass +
" using ClassLoader: " + cl);
return instance;
} catch (ClassNotFoundException x) {
throw new ConfigurationError(
"Provider " + className + " not found", x);
} catch (Exception x) {
throw new ConfigurationError(
"Provider " + className + " could not be instantiated: " + x,
x);
}
}
/**
* Find a Class using the specified ClassLoader
*/
static Class findProviderClass(String className, ClassLoader cl,
boolean doFallback)
throws ClassNotFoundException, ConfigurationError
{
//throw security exception if the calling thread is not allowed to access the
//class. Restrict the access to the package classes as specified in java.security policy.
SecurityManager security = System.getSecurityManager();
try{
if (security != null){
final int lastDot = className.lastIndexOf(".");
String packageName = className;
if (lastDot != -1) packageName = className.substring(0, lastDot);
security.checkPackageAccess(packageName);
}
}catch(SecurityException e){
throw e;
}
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);
} else {
try {
providerClass = cl.loadClass(className);
} catch (ClassNotFoundException x) {
if (doFallback) {
// Fall back to current classloader
ClassLoader current = ObjectFactory.class.getClassLoader();
if (current == null) {
providerClass = Class.forName(className);
} else if (cl != current) {
cl = current;
providerClass = cl.loadClass(className);
} else {
throw x;
}
} else {
throw x;
}
}
}
return providerClass;
}
/**
* Find the name of service provider using Jar Service Provider Mechanism
*
* @return instance of provider class if found or null
*/
private static String findJarServiceProviderName(String factoryId)
{
SecuritySupport ss = SecuritySupport.getInstance();
String serviceId = SERVICES_PATH + factoryId;
InputStream is = null;
// First try the Context ClassLoader
ClassLoader cl = findClassLoader();
is = ss.getResourceAsStream(cl, serviceId);
// If no provider found then try the current ClassLoader
if (is == null) {
ClassLoader current = ObjectFactory.class.getClassLoader();
if (cl != current) {
cl = current;
is = ss.getResourceAsStream(cl, serviceId);
}
}
if (is == null) {
// No provider found
return null;
}
if (DEBUG) debugPrintln("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 {
rd = new BufferedReader(new InputStreamReader(is, "UTF-8"));
} catch (java.io.UnsupportedEncodingException e) {
rd = new BufferedReader(new InputStreamReader(is));
}
String factoryClassName = null;
try {
// XXX Does not handle all possible input as specified by the
// Jar Service Provider specification
factoryClassName = rd.readLine();
} catch (IOException x) {
// No provider found
return null;
}
finally {
try {
// try to close the reader.
rd.close();
}
// Ignore the exception.
catch (IOException exc) {}
}
if (factoryClassName != null &&
! "".equals(factoryClassName)) {
if (DEBUG) debugPrintln("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 factoryClassName;
}
// No provider found
return null;
}
//
// Classes
//
/**
* A configuration error.
*/
static class ConfigurationError
extends Error {
static final long serialVersionUID = -7640369932165775029L;
//
// Data
//
/** Exception. */
private Exception exception;
//
// Constructors
//
/**
* Construct a new instance with the specified detail string and
* exception.
*/
ConfigurationError(String msg, Exception x) {
super(msg);
this.exception = x;
} // <init>(String,Exception)
//
// Public methods
//
/** Returns the exception associated to this error. */
Exception getException() {
return exception;
} // getException():Exception
} // class ConfigurationError
} // class ObjectFactory

View file

@ -1,127 +0,0 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 2002-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: SecuritySupport.java,v 1.1.2.1 2005/08/01 02:08:48 jeffsuttor Exp $
*/
package com.sun.org.apache.xalan.internal.lib;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.Properties;
/**
* This class is duplicated for each Xalan-Java subpackage so keep it in sync.
* It is package private and therefore is not exposed as part of the Xalan-Java
* 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.
*/
static SecuritySupport getInstance() {
return (SecuritySupport)securitySupport;
}
ClassLoader getContextClassLoader() {
return null;
}
ClassLoader getSystemClassLoader() {
return null;
}
ClassLoader getParentClassLoader(ClassLoader cl) {
return null;
}
String getSystemProperty(String propName) {
return System.getProperty(propName);
}
FileInputStream getFileInputStream(File file)
throws FileNotFoundException
{
return new FileInputStream(file);
}
InputStream getResourceAsStream(ClassLoader cl, String name) {
InputStream ris;
if (cl == null) {
ris = ClassLoader.getSystemResourceAsStream(name);
} else {
ris = cl.getResourceAsStream(name);
}
return ris;
}
boolean getFileExists(File f) {
return f.exists();
}
long getLastModified(File f) {
return f.lastModified();
}
}

View file

@ -1,148 +0,0 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 2002-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: SecuritySupport12.java,v 1.1.2.1 2005/08/01 02:08:47 jeffsuttor Exp $
*/
package com.sun.org.apache.xalan.internal.lib;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.util.Properties;
/**
* This class is duplicated for each Xalan-Java subpackage so keep it in sync.
* It is package private and therefore is not exposed as part of the Xalan-Java
* API.
*
* Security related methods that only work on J2SE 1.2 and newer.
*/
class SecuritySupport12 extends SecuritySupport {
ClassLoader getContextClassLoader() {
return (ClassLoader)
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
ClassLoader cl = null;
try {
cl = Thread.currentThread().getContextClassLoader();
} catch (SecurityException ex) { }
return cl;
}
});
}
ClassLoader getSystemClassLoader() {
return (ClassLoader)
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
ClassLoader cl = null;
try {
cl = ClassLoader.getSystemClassLoader();
} catch (SecurityException ex) {}
return cl;
}
});
}
ClassLoader getParentClassLoader(final ClassLoader cl) {
return (ClassLoader)
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
ClassLoader parent = null;
try {
parent = cl.getParent();
} catch (SecurityException ex) {}
// eliminate loops in case of the boot
// ClassLoader returning itself as a parent
return (parent == cl) ? null : parent;
}
});
}
String getSystemProperty(final String propName) {
return (String)
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
return System.getProperty(propName);
}
});
}
FileInputStream getFileInputStream(final File file)
throws FileNotFoundException
{
try {
return (FileInputStream)
AccessController.doPrivileged(new PrivilegedExceptionAction() {
public Object run() throws FileNotFoundException {
return new FileInputStream(file);
}
});
} catch (PrivilegedActionException e) {
throw (FileNotFoundException)e.getException();
}
}
InputStream getResourceAsStream(final ClassLoader cl,
final String name)
{
return (InputStream)
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
InputStream ris;
if (cl == null) {
ris = ClassLoader.getSystemResourceAsStream(name);
} else {
ris = cl.getResourceAsStream(name);
}
return ris;
}
});
}
boolean getFileExists(final File f) {
return ((Boolean)
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
return new Boolean(f.exists());
}
})).booleanValue();
}
long getLastModified(final File f) {
return ((Long)
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
return new Long(f.lastModified());
}
})).longValue();
}
}

View file

@ -0,0 +1,61 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 2001-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: ObjectFactory.java,v 1.2.4.1 2005/09/15 02:39:54 jeffsuttor Exp $
*/
package com.sun.org.apache.xalan.internal.utils;
/**
* A configuration error. This was an internal class in ObjectFactory previously
*/
public final class ConfigurationError
extends Error {
//
// Data
//
/** Exception. */
private Exception exception;
//
// Constructors
//
/**
* Construct a new instance with the specified detail string and
* exception.
*/
ConfigurationError(String msg, Exception x) {
super(msg);
this.exception = x;
} // <init>(String,Exception)
//
// methods
//
/** Returns the exception associated to this error. */
public Exception getException() {
return exception;
} // getException():Exception
} // class ConfigurationError

View file

@ -0,0 +1,57 @@
/*
* Copyright (c) 2011 Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.org.apache.xalan.internal.utils;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.SAXParserFactory;
/**
*
* @author huizhe wang
*/
public class FactoryImpl {
static final String DBF = "com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl";
static final String SF = "com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl";
static public DocumentBuilderFactory getDOMFactory(boolean useServicesMechanism) {
DocumentBuilderFactory dbf =
useServicesMechanism ?
DocumentBuilderFactory.newInstance() :
DocumentBuilderFactory.newInstance( DBF,
FactoryImpl.class.getClassLoader());
return dbf;
}
static public SAXParserFactory getSAXFactory(boolean useServicesMechanism) {
SAXParserFactory factory =
useServicesMechanism ?
SAXParserFactory.newInstance() :
SAXParserFactory.newInstance(SF,
FactoryImpl.class.getClassLoader());
return factory;
}
}

View file

@ -18,10 +18,10 @@
* limitations under the License.
*/
/*
* $Id: ObjectFactory.java,v 1.2.4.1 2005/09/14 20:25:54 jeffsuttor Exp $
* $Id: ObjectFactory.java,v 1.2.4.1 2005/09/15 02:39:54 jeffsuttor Exp $
*/
package com.sun.org.apache.xpath.internal.functions;
package com.sun.org.apache.xalan.internal.utils;
import java.io.InputStream;
import java.io.IOException;
@ -47,9 +47,9 @@ import java.io.InputStreamReader;
* class and modified to be used as a general utility for creating objects
* dynamically.
*
* @version $Id: ObjectFactory.java,v 1.7 2008/04/02 00:40:59 joehw Exp $
* @version $Id: ObjectFactory.java,v 1.11 2010-11-01 04:34:25 joehw Exp $
*/
class ObjectFactory {
public class ObjectFactory {
//
// Constants
@ -100,7 +100,7 @@ class ObjectFactory {
*
* @exception ObjectFactory.ConfigurationError
*/
static Object createObject(String factoryId, String fallbackClassName)
public static Object createObject(String factoryId, String fallbackClassName)
throws ConfigurationError {
return createObject(factoryId, null, fallbackClassName);
} // createObject(String,String):Object
@ -174,7 +174,7 @@ class ObjectFactory {
*
* @exception ObjectFactory.ConfigurationError
*/
static Class lookUpFactoryClass(String factoryId)
public static Class lookUpFactoryClass(String factoryId)
throws ConfigurationError
{
return lookUpFactoryClass(factoryId, null, null);
@ -202,7 +202,7 @@ class ObjectFactory {
*
* @exception ObjectFactory.ConfigurationError
*/
static Class lookUpFactoryClass(String factoryId,
public static Class lookUpFactoryClass(String factoryId,
String propertiesFilename,
String fallbackClassName)
throws ConfigurationError
@ -260,11 +260,9 @@ class ObjectFactory {
String propertiesFilename,
String fallbackClassName)
{
SecuritySupport ss = SecuritySupport.getInstance();
// Use the system property first
try {
String systemProp = ss.getSystemProperty(factoryId);
String systemProp = SecuritySupport.getSystemProperty(factoryId);
if (systemProp != null) {
if (DEBUG) debugPrintln("found system property, value=" + systemProp);
return systemProp;
@ -282,11 +280,11 @@ class ObjectFactory {
File propertiesFile = null;
boolean propertiesFileExists = false;
try {
String javah = ss.getSystemProperty("java.home");
String javah = SecuritySupport.getSystemProperty("java.home");
propertiesFilename = javah + File.separator +
"lib" + File.separator + DEFAULT_PROPERTIES_FILENAME;
propertiesFile = new File(propertiesFilename);
propertiesFileExists = ss.getFileExists(propertiesFile);
propertiesFileExists = SecuritySupport.getFileExists(propertiesFile);
} catch (SecurityException e) {
// try again...
fLastModified = -1;
@ -300,7 +298,7 @@ class ObjectFactory {
// file existed last time
if(fLastModified >= 0) {
if(propertiesFileExists &&
(fLastModified < (fLastModified = ss.getLastModified(propertiesFile)))) {
(fLastModified < (fLastModified = SecuritySupport.getLastModified(propertiesFile)))) {
loadProperties = true;
} else {
// file has stopped existing...
@ -313,14 +311,14 @@ class ObjectFactory {
// file has started to exist:
if(propertiesFileExists) {
loadProperties = true;
fLastModified = ss.getLastModified(propertiesFile);
fLastModified = SecuritySupport.getLastModified(propertiesFile);
} // else, nothing's changed
}
if(loadProperties) {
// must never have attempted to read xalan.properties
// before (or it's outdeated)
fXalanProperties = new Properties();
fis = ss.getFileInputStream(propertiesFile);
fis = SecuritySupport.getFileInputStream(propertiesFile);
fXalanProperties.load(fis);
}
} catch (Exception x) {
@ -347,7 +345,7 @@ class ObjectFactory {
} else {
FileInputStream fis = null;
try {
fis = ss.getFileInputStream(new File(propertiesFilename));
fis = SecuritySupport.getFileInputStream(new File(propertiesFilename));
Properties props = new Properties();
props.load(fis);
factoryClassName = props.getProperty(factoryId);
@ -392,15 +390,18 @@ class ObjectFactory {
* Figure out which ClassLoader to use. For JDK 1.2 and later use
* the context ClassLoader.
*/
static ClassLoader findClassLoader()
public static ClassLoader findClassLoader()
throws ConfigurationError
{
SecuritySupport ss = SecuritySupport.getInstance();
if (System.getSecurityManager()!=null) {
//this will ensure bootclassloader is used
return null;
}
// Figure out which ClassLoader to use for loading the provider
// class. If there is a Context ClassLoader then use it.
ClassLoader context = ss.getContextClassLoader();
ClassLoader system = ss.getSystemClassLoader();
ClassLoader context = SecuritySupport.getContextClassLoader();
ClassLoader system = SecuritySupport.getSystemClassLoader();
ClassLoader chain = system;
while (true) {
@ -425,7 +426,7 @@ class ObjectFactory {
if (chain == null) {
break;
}
chain = ss.getParentClassLoader(chain);
chain = SecuritySupport.getParentClassLoader(chain);
}
// Assert: Current ClassLoader not in chain of
@ -440,14 +441,29 @@ class ObjectFactory {
// Check for any extension ClassLoaders in chain up to
// boot ClassLoader
chain = ss.getParentClassLoader(chain);
};
chain = SecuritySupport.getParentClassLoader(chain);
}
// Assert: Context ClassLoader not in chain of
// boot/extension/system ClassLoaders
return context;
} // findClassLoader():ClassLoader
/**
* Create an instance of a class using the same classloader for the ObjectFactory by default
* or bootclassloader when Security Manager is in place
*/
public static Object newInstance(String className, boolean doFallback)
throws ConfigurationError
{
if (System.getSecurityManager()!=null) {
return newInstance(className, null, doFallback);
} else {
return newInstance(className,
findClassLoader (), doFallback);
}
}
/**
* Create an instance of a class using the specified ClassLoader
*/
@ -472,6 +488,21 @@ class ObjectFactory {
}
}
/**
* Find a Class using the same classloader for the ObjectFactory by default
* or bootclassloader when Security Manager is in place
*/
public static Class findProviderClass(String className, boolean doFallback)
throws ClassNotFoundException, ConfigurationError
{
if (System.getSecurityManager()!=null) {
return Class.forName(className);
} else {
return findProviderClass (className,
findClassLoader (), doFallback);
}
}
/**
* Find a Class using the specified ClassLoader
*/
@ -536,21 +567,20 @@ class ObjectFactory {
*/
private static String findJarServiceProviderName(String factoryId)
{
SecuritySupport ss = SecuritySupport.getInstance();
String serviceId = SERVICES_PATH + factoryId;
InputStream is = null;
// First try the Context ClassLoader
ClassLoader cl = findClassLoader();
is = ss.getResourceAsStream(cl, serviceId);
is = SecuritySupport.getResourceAsStream(cl, serviceId);
// If no provider found then try the current ClassLoader
if (is == null) {
ClassLoader current = ObjectFactory.class.getClassLoader();
if (cl != current) {
cl = current;
is = ss.getResourceAsStream(cl, serviceId);
is = SecuritySupport.getResourceAsStream(cl, serviceId);
}
}
@ -619,45 +649,4 @@ class ObjectFactory {
return null;
}
//
// Classes
//
/**
* A configuration error.
*/
static class ConfigurationError
extends Error {
static final long serialVersionUID = -5782303800588797207L;
//
// Data
//
/** Exception. */
private Exception exception;
//
// Constructors
//
/**
* Construct a new instance with the specified detail string and
* exception.
*/
ConfigurationError(String msg, Exception x) {
super(msg);
this.exception = x;
} // <init>(String,Exception)
//
// Public methods
//
/** Returns the exception associated to this error. */
Exception getException() {
return exception;
} // getException():Exception
} // class ConfigurationError
} // class ObjectFactory

View file

@ -3,13 +3,13 @@
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 2002,2004 The Apache Software Foundation.
* Copyright 2002-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@ -17,8 +17,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: SecuritySupport.java,v 1.1.2.1 2005/08/01 02:08:48 jeffsuttor Exp $
*/
package com.sun.org.apache.xerces.internal.impl.dv;
package com.sun.org.apache.xalan.internal.utils;
import java.io.File;
import java.io.FileInputStream;
@ -36,18 +39,18 @@ import java.security.PrivilegedExceptionAction;
*
* @xerces.internal
*/
final class SecuritySupport {
public final class SecuritySupport {
private static final SecuritySupport securitySupport = new SecuritySupport();
/**
* Return an instance of this class.
*/
static SecuritySupport getInstance() {
public static SecuritySupport getInstance() {
return securitySupport;
}
ClassLoader getContextClassLoader() {
static ClassLoader getContextClassLoader() {
return (ClassLoader)
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
@ -60,7 +63,7 @@ final class SecuritySupport {
});
}
ClassLoader getSystemClassLoader() {
static ClassLoader getSystemClassLoader() {
return (ClassLoader)
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
@ -73,7 +76,7 @@ final class SecuritySupport {
});
}
ClassLoader getParentClassLoader(final ClassLoader cl) {
static ClassLoader getParentClassLoader(final ClassLoader cl) {
return (ClassLoader)
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
@ -89,7 +92,7 @@ final class SecuritySupport {
});
}
String getSystemProperty(final String propName) {
public static String getSystemProperty(final String propName) {
return (String)
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
@ -98,7 +101,7 @@ final class SecuritySupport {
});
}
FileInputStream getFileInputStream(final File file)
static FileInputStream getFileInputStream(final File file)
throws FileNotFoundException
{
try {
@ -112,8 +115,19 @@ final class SecuritySupport {
throw (FileNotFoundException)e.getException();
}
}
/**
* Return resource using the same classloader for the ObjectFactory by default
* or bootclassloader when Security Manager is in place
*/
public static InputStream getResourceAsStream(final String name) {
if (System.getSecurityManager()!=null) {
return getResourceAsStream(null, name);
} else {
return getResourceAsStream(ObjectFactory.findClassLoader(), name);
}
}
InputStream getResourceAsStream(final ClassLoader cl,
public static InputStream getResourceAsStream(final ClassLoader cl,
final String name)
{
return (InputStream)
@ -121,7 +135,7 @@ final class SecuritySupport {
public Object run() {
InputStream ris;
if (cl == null) {
ris = ClassLoader.getSystemResourceAsStream(name);
ris = Object.class.getResourceAsStream("/"+name);
} else {
ris = cl.getResourceAsStream(name);
}
@ -130,16 +144,16 @@ final class SecuritySupport {
});
}
boolean getFileExists(final File f) {
static boolean getFileExists(final File f) {
return ((Boolean)
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
return new Boolean(f.exists());
return f.exists() ? Boolean.TRUE : Boolean.FALSE;
}
})).booleanValue();
}
long getLastModified(final File f) {
static long getLastModified(final File f) {
return ((Long)
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {

View file

@ -22,6 +22,8 @@
*/
package com.sun.org.apache.xalan.internal.xslt;
import com.sun.org.apache.xalan.internal.utils.ObjectFactory;
import java.io.File;
import java.io.FileWriter;
import java.io.PrintWriter;
@ -794,8 +796,7 @@ public class EnvironmentCheck
{
final String JAXP1_CLASS = "javax.xml.stream.XMLStreamConstants";
clazz = ObjectFactory.findProviderClass(
JAXP1_CLASS, ObjectFactory.findClassLoader(), true);
clazz = ObjectFactory.findProviderClass(JAXP1_CLASS, true);
// If we succeeded, we have JAXP 1.4 available
h.put(VERSION + "JAXP", "1.4");
@ -825,8 +826,7 @@ public class EnvironmentCheck
final String XALAN1_VERSION_CLASS =
"com.sun.org.apache.xalan.internal.xslt.XSLProcessorVersion";
Class clazz = ObjectFactory.findProviderClass(
XALAN1_VERSION_CLASS, ObjectFactory.findClassLoader(), true);
Class clazz = ObjectFactory.findProviderClass(XALAN1_VERSION_CLASS, true);
// Found Xalan-J 1.x, grab it's version fields
StringBuffer buf = new StringBuffer();
@ -858,8 +858,7 @@ public class EnvironmentCheck
final String XALAN2_VERSION_CLASS =
"com.sun.org.apache.xalan.internal.processor.XSLProcessorVersion";
Class clazz = ObjectFactory.findProviderClass(
XALAN2_VERSION_CLASS, ObjectFactory.findClassLoader(), true);
Class clazz = ObjectFactory.findProviderClass(XALAN2_VERSION_CLASS, true);
// Found Xalan-J 2.x, grab it's version fields
StringBuffer buf = new StringBuffer();
@ -880,8 +879,7 @@ public class EnvironmentCheck
final String XALAN2_2_VERSION_METHOD = "getVersion";
final Class noArgs[] = new Class[0];
Class clazz = ObjectFactory.findProviderClass(
XALAN2_2_VERSION_CLASS, ObjectFactory.findClassLoader(), true);
Class clazz = ObjectFactory.findProviderClass(XALAN2_2_VERSION_CLASS, true);
Method method = clazz.getMethod(XALAN2_2_VERSION_METHOD, noArgs);
Object returnValue = method.invoke(null, new Object[0]);
@ -913,8 +911,7 @@ public class EnvironmentCheck
{
final String XERCES1_VERSION_CLASS = "com.sun.org.apache.xerces.internal.framework.Version";
Class clazz = ObjectFactory.findProviderClass(
XERCES1_VERSION_CLASS, ObjectFactory.findClassLoader(), true);
Class clazz = ObjectFactory.findProviderClass(XERCES1_VERSION_CLASS, true);
// Found Xerces-J 1.x, grab it's version fields
Field f = clazz.getField("fVersion");
@ -932,8 +929,7 @@ public class EnvironmentCheck
{
final String XERCES2_VERSION_CLASS = "com.sun.org.apache.xerces.internal.impl.Version";
Class clazz = ObjectFactory.findProviderClass(
XERCES2_VERSION_CLASS, ObjectFactory.findClassLoader(), true);
Class clazz = ObjectFactory.findProviderClass(XERCES2_VERSION_CLASS, true);
// Found Xerces-J 2.x, grab it's version fields
Field f = clazz.getField("fVersion");
@ -950,8 +946,7 @@ public class EnvironmentCheck
{
final String CRIMSON_CLASS = "org.apache.crimson.parser.Parser2";
Class clazz = ObjectFactory.findProviderClass(
CRIMSON_CLASS, ObjectFactory.findClassLoader(), true);
Class clazz = ObjectFactory.findProviderClass(CRIMSON_CLASS, true);
//@todo determine specific crimson version
h.put(VERSION + "crimson", CLASS_PRESENT);
@ -979,8 +974,7 @@ public class EnvironmentCheck
final String ANT_VERSION_METHOD = "getAntVersion"; // noArgs
final Class noArgs[] = new Class[0];
Class clazz = ObjectFactory.findProviderClass(
ANT_VERSION_CLASS, ObjectFactory.findClassLoader(), true);
Class clazz = ObjectFactory.findProviderClass(ANT_VERSION_CLASS, true);
Method method = clazz.getMethod(ANT_VERSION_METHOD, noArgs);
Object returnValue = method.invoke(null, new Object[0]);
@ -1009,8 +1003,7 @@ public class EnvironmentCheck
try
{
Class clazz = ObjectFactory.findProviderClass(
DOM_CLASS, ObjectFactory.findClassLoader(), true);
Class clazz = ObjectFactory.findProviderClass(DOM_CLASS, true);
Method method = clazz.getMethod(DOM_LEVEL3_METHOD, null);
@ -1052,8 +1045,7 @@ public class EnvironmentCheck
try
{
Class clazz = ObjectFactory.findProviderClass(
DOM_LEVEL2_CLASS, ObjectFactory.findClassLoader(), true);
Class clazz = ObjectFactory.findProviderClass(DOM_LEVEL2_CLASS, true);
Method method = clazz.getMethod(DOM_LEVEL2_METHOD, twoStringArgs);
@ -1065,8 +1057,7 @@ public class EnvironmentCheck
{
// Check for the working draft version, which is
// commonly found, but won't work anymore
clazz = ObjectFactory.findProviderClass(
DOM_LEVEL2WD_CLASS, ObjectFactory.findClassLoader(), true);
clazz = ObjectFactory.findProviderClass(DOM_LEVEL2WD_CLASS, true);
method = clazz.getMethod(DOM_LEVEL2WD_METHOD, twoStringArgs);
@ -1078,8 +1069,7 @@ public class EnvironmentCheck
try
{
// Check for the final draft version as well
clazz = ObjectFactory.findProviderClass(
DOM_LEVEL2FD_CLASS, ObjectFactory.findClassLoader(), true);
clazz = ObjectFactory.findProviderClass(DOM_LEVEL2FD_CLASS, true);
method = clazz.getMethod(DOM_LEVEL2FD_METHOD, twoStringArgs);
@ -1133,8 +1123,7 @@ public class EnvironmentCheck
{
// This method was only added in the final SAX 2.0 release;
// see changes.html "Changes from SAX 2.0beta2 to SAX 2.0prerelease"
Class clazz = ObjectFactory.findProviderClass(
SAX_VERSION2BETA_CLASSNF, ObjectFactory.findClassLoader(), true);
Class clazz = ObjectFactory.findProviderClass(SAX_VERSION2BETA_CLASSNF, true);
Method method = clazz.getMethod(SAX_VERSION2BETA_METHODNF, attributesArg);
@ -1151,8 +1140,7 @@ public class EnvironmentCheck
try
{
Class clazz = ObjectFactory.findProviderClass(
SAX_VERSION2_CLASS, ObjectFactory.findClassLoader(), true);
Class clazz = ObjectFactory.findProviderClass(SAX_VERSION2_CLASS, true);
Method method = clazz.getMethod(SAX_VERSION2_METHOD, oneStringArg);
@ -1170,8 +1158,7 @@ public class EnvironmentCheck
try
{
Class clazz = ObjectFactory.findProviderClass(
SAX_VERSION1_CLASS, ObjectFactory.findClassLoader(), true);
Class clazz = ObjectFactory.findProviderClass(SAX_VERSION1_CLASS, true);
Method method = clazz.getMethod(SAX_VERSION1_METHOD, oneStringArg);

View file

@ -1,663 +0,0 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 2001-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: ObjectFactory.java,v 1.2.4.1 2005/09/12 12:18:06 pvedula Exp $
*/
package com.sun.org.apache.xalan.internal.xslt;
import java.io.InputStream;
import java.io.IOException;
import java.io.File;
import java.io.FileInputStream;
import java.util.Properties;
import java.io.BufferedReader;
import java.io.InputStreamReader;
/**
* This class is duplicated for each JAXP subpackage so keep it in sync.
* It is package private and therefore is not exposed as part of the JAXP
* API.
* <p>
* This code is designed to implement the JAXP 1.1 spec pluggability
* feature and is designed to run on JDK version 1.1 and
* later, and to compile on JDK 1.2 and onward.
* The code also runs both as part of an unbundled jar file and
* when bundled as part of the JDK.
* <p>
* This class was moved from the <code>javax.xml.parsers.ObjectFactory</code>
* class and modified to be used as a general utility for creating objects
* dynamically.
*
* @version $Id: ObjectFactory.java,v 1.9 2008/04/02 00:41:00 joehw Exp $
*/
class ObjectFactory {
//
// Constants
//
// name of default properties file to look for in JDK's jre/lib directory
private static final String DEFAULT_PROPERTIES_FILENAME =
"xalan.properties";
private static final String SERVICES_PATH = "META-INF/services/";
/** Set to true for debugging */
private static final boolean DEBUG = false;
/** cache the contents of the xalan.properties file.
* Until an attempt has been made to read this file, this will
* be null; if the file does not exist or we encounter some other error
* during the read, this will be empty.
*/
private static Properties fXalanProperties = null;
/***
* Cache the time stamp of the xalan.properties file so
* that we know if it's been modified and can invalidate
* the cache when necessary.
*/
private static long fLastModified = -1;
//
// Public static methods
//
/**
* Finds the implementation Class object in the specified order. The
* specified order is the following:
* <ol>
* <li>query the system property using <code>System.getProperty</code>
* <li>read <code>META-INF/services/<i>factoryId</i></code> file
* <li>use fallback classname
* </ol>
*
* @return instance of factory, never null
*
* @param factoryId Name of the factory to find, same as
* a property name
* @param fallbackClassName Implementation class name, if nothing else
* is found. Use null to mean no fallback.
*
* @exception ObjectFactory.ConfigurationError
*/
static Object createObject(String factoryId, String fallbackClassName)
throws ConfigurationError {
return createObject(factoryId, null, fallbackClassName);
} // createObject(String,String):Object
/**
* Finds the implementation Class object in the specified order. The
* specified order is the following:
* <ol>
* <li>query the system property using <code>System.getProperty</code>
* <li>read <code>$java.home/lib/<i>propertiesFilename</i></code> file
* <li>read <code>META-INF/services/<i>factoryId</i></code> file
* <li>use fallback classname
* </ol>
*
* @return instance of factory, never null
*
* @param factoryId Name of the factory to find, same as
* a property name
* @param propertiesFilename The filename in the $java.home/lib directory
* of the properties file. If none specified,
* ${java.home}/lib/xalan.properties will be used.
* @param fallbackClassName Implementation class name, if nothing else
* is found. Use null to mean no fallback.
*
* @exception ObjectFactory.ConfigurationError
*/
static Object createObject(String factoryId,
String propertiesFilename,
String fallbackClassName)
throws ConfigurationError
{
Class factoryClass = lookUpFactoryClass(factoryId,
propertiesFilename,
fallbackClassName);
if (factoryClass == null) {
throw new ConfigurationError(
"Provider for " + factoryId + " cannot be found", null);
}
try{
Object instance = factoryClass.newInstance();
if (DEBUG) debugPrintln("created new instance of factory " + factoryId);
return instance;
} catch (Exception x) {
throw new ConfigurationError(
"Provider for factory " + factoryId
+ " could not be instantiated: " + x, x);
}
} // createObject(String,String,String):Object
/**
* Finds the implementation Class object in the specified order. The
* specified order is the following:
* <ol>
* <li>query the system property using <code>System.getProperty</code>
* <li>read <code>$java.home/lib/<i>propertiesFilename</i></code> file
* <li>read <code>META-INF/services/<i>factoryId</i></code> file
* <li>use fallback classname
* </ol>
*
* @return Class object of factory, never null
*
* @param factoryId Name of the factory to find, same as
* a property name
* @param propertiesFilename The filename in the $java.home/lib directory
* of the properties file. If none specified,
* ${java.home}/lib/xalan.properties will be used.
* @param fallbackClassName Implementation class name, if nothing else
* is found. Use null to mean no fallback.
*
* @exception ObjectFactory.ConfigurationError
*/
static Class lookUpFactoryClass(String factoryId)
throws ConfigurationError
{
return lookUpFactoryClass(factoryId, null, null);
} // lookUpFactoryClass(String):Class
/**
* Finds the implementation Class object in the specified order. The
* specified order is the following:
* <ol>
* <li>query the system property using <code>System.getProperty</code>
* <li>read <code>$java.home/lib/<i>propertiesFilename</i></code> file
* <li>read <code>META-INF/services/<i>factoryId</i></code> file
* <li>use fallback classname
* </ol>
*
* @return Class object that provides factory service, never null
*
* @param factoryId Name of the factory to find, same as
* a property name
* @param propertiesFilename The filename in the $java.home/lib directory
* of the properties file. If none specified,
* ${java.home}/lib/xalan.properties will be used.
* @param fallbackClassName Implementation class name, if nothing else
* is found. Use null to mean no fallback.
*
* @exception ObjectFactory.ConfigurationError
*/
static Class lookUpFactoryClass(String factoryId,
String propertiesFilename,
String fallbackClassName)
throws ConfigurationError
{
String factoryClassName = lookUpFactoryClassName(factoryId,
propertiesFilename,
fallbackClassName);
ClassLoader cl = findClassLoader();
if (factoryClassName == null) {
factoryClassName = fallbackClassName;
}
// assert(className != null);
try{
Class providerClass = findProviderClass(factoryClassName,
cl,
true);
if (DEBUG) debugPrintln("created new instance of " + providerClass +
" using ClassLoader: " + cl);
return providerClass;
} catch (ClassNotFoundException x) {
throw new ConfigurationError(
"Provider " + factoryClassName + " not found", x);
} catch (Exception x) {
throw new ConfigurationError(
"Provider "+factoryClassName+" could not be instantiated: "+x,
x);
}
} // lookUpFactoryClass(String,String,String):Class
/**
* Finds the name of the required implementation class in the specified
* order. The specified order is the following:
* <ol>
* <li>query the system property using <code>System.getProperty</code>
* <li>read <code>$java.home/lib/<i>propertiesFilename</i></code> file
* <li>read <code>META-INF/services/<i>factoryId</i></code> file
* <li>use fallback classname
* </ol>
*
* @return name of class that provides factory service, never null
*
* @param factoryId Name of the factory to find, same as
* a property name
* @param propertiesFilename The filename in the $java.home/lib directory
* of the properties file. If none specified,
* ${java.home}/lib/xalan.properties will be used.
* @param fallbackClassName Implementation class name, if nothing else
* is found. Use null to mean no fallback.
*
* @exception ObjectFactory.ConfigurationError
*/
static String lookUpFactoryClassName(String factoryId,
String propertiesFilename,
String fallbackClassName)
{
SecuritySupport ss = SecuritySupport.getInstance();
// Use the system property first
try {
String systemProp = ss.getSystemProperty(factoryId);
if (systemProp != null) {
if (DEBUG) debugPrintln("found system property, value=" + systemProp);
return systemProp;
}
} catch (SecurityException se) {
// Ignore and continue w/ next location
}
// Try to read from propertiesFilename, or
// $java.home/lib/xalan.properties
String factoryClassName = null;
// no properties file name specified; use
// $JAVA_HOME/lib/xalan.properties:
if (propertiesFilename == null) {
File propertiesFile = null;
boolean propertiesFileExists = false;
try {
String javah = ss.getSystemProperty("java.home");
propertiesFilename = javah + File.separator +
"lib" + File.separator + DEFAULT_PROPERTIES_FILENAME;
propertiesFile = new File(propertiesFilename);
propertiesFileExists = ss.getFileExists(propertiesFile);
} catch (SecurityException e) {
// try again...
fLastModified = -1;
fXalanProperties = null;
}
synchronized (ObjectFactory.class) {
boolean loadProperties = false;
FileInputStream fis = null;
try {
// file existed last time
if(fLastModified >= 0) {
if(propertiesFileExists &&
(fLastModified < (fLastModified = ss.getLastModified(propertiesFile)))) {
loadProperties = true;
} else {
// file has stopped existing...
if(!propertiesFileExists) {
fLastModified = -1;
fXalanProperties = null;
} // else, file wasn't modified!
}
} else {
// file has started to exist:
if(propertiesFileExists) {
loadProperties = true;
fLastModified = ss.getLastModified(propertiesFile);
} // else, nothing's changed
}
if(loadProperties) {
// must never have attempted to read xalan.properties
// before (or it's outdeated)
fXalanProperties = new Properties();
fis = ss.getFileInputStream(propertiesFile);
fXalanProperties.load(fis);
}
} catch (Exception x) {
fXalanProperties = null;
fLastModified = -1;
// assert(x instanceof FileNotFoundException
// || x instanceof SecurityException)
// In both cases, ignore and continue w/ next location
}
finally {
// try to close the input stream if one was opened.
if (fis != null) {
try {
fis.close();
}
// Ignore the exception.
catch (IOException exc) {}
}
}
}
if(fXalanProperties != null) {
factoryClassName = fXalanProperties.getProperty(factoryId);
}
} else {
FileInputStream fis = null;
try {
fis = ss.getFileInputStream(new File(propertiesFilename));
Properties props = new Properties();
props.load(fis);
factoryClassName = props.getProperty(factoryId);
} catch (Exception x) {
// assert(x instanceof FileNotFoundException
// || x instanceof SecurityException)
// In both cases, ignore and continue w/ next location
}
finally {
// try to close the input stream if one was opened.
if (fis != null) {
try {
fis.close();
}
// Ignore the exception.
catch (IOException exc) {}
}
}
}
if (factoryClassName != null) {
if (DEBUG) debugPrintln("found in " + propertiesFilename + ", value="
+ factoryClassName);
return factoryClassName;
}
// Try Jar Service Provider Mechanism
return findJarServiceProviderName(factoryId);
} // lookUpFactoryClass(String,String):String
//
// Private static methods
//
/** Prints a message to standard error if debugging is enabled. */
private static void debugPrintln(String msg) {
if (DEBUG) {
System.err.println("JAXP: " + msg);
}
} // debugPrintln(String)
/**
* Figure out which ClassLoader to use. For JDK 1.2 and later use
* the context ClassLoader.
*/
static ClassLoader findClassLoader()
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 context = ss.getContextClassLoader();
ClassLoader system = ss.getSystemClassLoader();
ClassLoader chain = system;
while (true) {
if (context == chain) {
// Assert: we are on JDK 1.1 or we have no Context ClassLoader
// or any Context ClassLoader in chain of system classloader
// (including extension ClassLoader) so extend to widest
// ClassLoader (always look in system ClassLoader if Xalan
// is in boot/extension/system classpath and in current
// ClassLoader otherwise); normal classloaders delegate
// back to system ClassLoader first so this widening doesn't
// change the fact that context ClassLoader will be consulted
ClassLoader current = ObjectFactory.class.getClassLoader();
chain = system;
while (true) {
if (current == chain) {
// Assert: Current ClassLoader in chain of
// boot/extension/system ClassLoaders
return system;
}
if (chain == null) {
break;
}
chain = ss.getParentClassLoader(chain);
}
// Assert: Current ClassLoader not in chain of
// boot/extension/system ClassLoaders
return current;
}
if (chain == null) {
// boot ClassLoader reached
break;
}
// Check for any extension ClassLoaders in chain up to
// boot ClassLoader
chain = ss.getParentClassLoader(chain);
};
// Assert: Context ClassLoader not in chain of
// boot/extension/system ClassLoaders
return context;
} // findClassLoader():ClassLoader
/**
* Create an instance of a class using the specified ClassLoader
*/
static Object newInstance(String className, ClassLoader cl,
boolean doFallback)
throws ConfigurationError
{
// assert(className != null);
try{
Class providerClass = findProviderClass(className, cl, doFallback);
Object instance = providerClass.newInstance();
if (DEBUG) debugPrintln("created new instance of " + providerClass +
" using ClassLoader: " + cl);
return instance;
} catch (ClassNotFoundException x) {
throw new ConfigurationError(
"Provider " + className + " not found", x);
} catch (Exception x) {
throw new ConfigurationError(
"Provider " + className + " could not be instantiated: " + x,
x);
}
}
/**
* Find a Class using the specified ClassLoader
*/
static Class findProviderClass(String className, ClassLoader cl,
boolean doFallback)
throws ClassNotFoundException, ConfigurationError
{
//throw security exception if the calling thread is not allowed to access the
//class. Restrict the access to the package classes as specified in java.security policy.
SecurityManager security = System.getSecurityManager();
try{
if (security != null){
final int lastDot = className.lastIndexOf(".");
String packageName = className;
if (lastDot != -1) packageName = className.substring(0, lastDot);
security.checkPackageAccess(packageName);
}
}catch(SecurityException e){
throw e;
}
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);
} else {
try {
providerClass = cl.loadClass(className);
} catch (ClassNotFoundException x) {
if (doFallback) {
// Fall back to current classloader
ClassLoader current = ObjectFactory.class.getClassLoader();
if (current == null) {
providerClass = Class.forName(className);
} else if (cl != current) {
cl = current;
providerClass = cl.loadClass(className);
} else {
throw x;
}
} else {
throw x;
}
}
}
return providerClass;
}
/**
* Find the name of service provider using Jar Service Provider Mechanism
*
* @return instance of provider class if found or null
*/
private static String findJarServiceProviderName(String factoryId)
{
SecuritySupport ss = SecuritySupport.getInstance();
String serviceId = SERVICES_PATH + factoryId;
InputStream is = null;
// First try the Context ClassLoader
ClassLoader cl = findClassLoader();
is = ss.getResourceAsStream(cl, serviceId);
// If no provider found then try the current ClassLoader
if (is == null) {
ClassLoader current = ObjectFactory.class.getClassLoader();
if (cl != current) {
cl = current;
is = ss.getResourceAsStream(cl, serviceId);
}
}
if (is == null) {
// No provider found
return null;
}
if (DEBUG) debugPrintln("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 {
rd = new BufferedReader(new InputStreamReader(is, "UTF-8"));
} catch (java.io.UnsupportedEncodingException e) {
rd = new BufferedReader(new InputStreamReader(is));
}
String factoryClassName = null;
try {
// XXX Does not handle all possible input as specified by the
// Jar Service Provider specification
factoryClassName = rd.readLine();
} catch (IOException x) {
// No provider found
return null;
}
finally {
try {
// try to close the reader.
rd.close();
}
// Ignore the exception.
catch (IOException exc) {}
}
if (factoryClassName != null &&
! "".equals(factoryClassName)) {
if (DEBUG) debugPrintln("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 factoryClassName;
}
// No provider found
return null;
}
//
// Classes
//
/**
* A configuration error.
*/
static class ConfigurationError
extends Error {
static final long serialVersionUID = 2276082712114762609L;
//
// Data
//
/** Exception. */
private Exception exception;
//
// Constructors
//
/**
* Construct a new instance with the specified detail string and
* exception.
*/
ConfigurationError(String msg, Exception x) {
super(msg);
this.exception = x;
} // <init>(String,Exception)
//
// Public methods
//
/** Returns the exception associated to this error. */
Exception getException() {
return exception;
} // getException():Exception
} // class ConfigurationError
} // class ObjectFactory

View file

@ -55,6 +55,8 @@ import javax.xml.transform.stream.StreamSource;
import com.sun.org.apache.xalan.internal.Version;
import com.sun.org.apache.xalan.internal.res.XSLMessages;
import com.sun.org.apache.xalan.internal.res.XSLTErrorResources;
import com.sun.org.apache.xalan.internal.utils.ObjectFactory;
import com.sun.org.apache.xalan.internal.utils.ConfigurationError;
//J2SE does not support Xalan interpretive
/*
@ -457,12 +459,11 @@ public class Process
{
try
{
uriResolver = (URIResolver) ObjectFactory.newInstance(
argv[++i], ObjectFactory.findClassLoader(), true);
uriResolver = (URIResolver) ObjectFactory.newInstance(argv[++i], true);
tfactory.setURIResolver(uriResolver);
}
catch (ObjectFactory.ConfigurationError cnfe)
catch (ConfigurationError cnfe)
{
msg = XSLMessages.createMessage(
XSLTErrorResources.ER_CLASS_NOT_FOUND_FOR_OPTION,
@ -486,10 +487,9 @@ public class Process
{
try
{
entityResolver = (EntityResolver) ObjectFactory.newInstance(
argv[++i], ObjectFactory.findClassLoader(), true);
entityResolver = (EntityResolver) ObjectFactory.newInstance(argv[++i], true);
}
catch (ObjectFactory.ConfigurationError cnfe)
catch (ConfigurationError cnfe)
{
msg = XSLMessages.createMessage(
XSLTErrorResources.ER_CLASS_NOT_FOUND_FOR_OPTION,
@ -514,10 +514,9 @@ public class Process
{
try
{
contentHandler = (ContentHandler) ObjectFactory.newInstance(
argv[++i], ObjectFactory.findClassLoader(), true);
contentHandler = (ContentHandler) ObjectFactory.newInstance(argv[++i], true);
}
catch (ObjectFactory.ConfigurationError cnfe)
catch (ConfigurationError cnfe)
{
msg = XSLMessages.createMessage(
XSLTErrorResources.ER_CLASS_NOT_FOUND_FOR_OPTION,

View file

@ -1,127 +0,0 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 2002-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: SecuritySupport.java,v 1.2.4.1 2005/09/09 07:17:15 pvedula Exp $
*/
package com.sun.org.apache.xalan.internal.xslt;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.Properties;
/**
* This class is duplicated for each Xalan-Java subpackage so keep it in sync.
* It is package private and therefore is not exposed as part of the Xalan-Java
* 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.
*/
static SecuritySupport getInstance() {
return (SecuritySupport)securitySupport;
}
ClassLoader getContextClassLoader() {
return null;
}
ClassLoader getSystemClassLoader() {
return null;
}
ClassLoader getParentClassLoader(ClassLoader cl) {
return null;
}
String getSystemProperty(String propName) {
return System.getProperty(propName);
}
FileInputStream getFileInputStream(File file)
throws FileNotFoundException
{
return new FileInputStream(file);
}
InputStream getResourceAsStream(ClassLoader cl, String name) {
InputStream ris;
if (cl == null) {
ris = ClassLoader.getSystemResourceAsStream(name);
} else {
ris = cl.getResourceAsStream(name);
}
return ris;
}
boolean getFileExists(File f) {
return f.exists();
}
long getLastModified(File f) {
return f.lastModified();
}
}

View file

@ -1,148 +0,0 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 2002-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: SecuritySupport12.java,v 1.2.4.1 2005/09/09 07:17:45 pvedula Exp $
*/
package com.sun.org.apache.xalan.internal.xslt;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.util.Properties;
/**
* This class is duplicated for each Xalan-Java subpackage so keep it in sync.
* It is package private and therefore is not exposed as part of the Xalan-Java
* API.
*
* Security related methods that only work on J2SE 1.2 and newer.
*/
class SecuritySupport12 extends SecuritySupport {
ClassLoader getContextClassLoader() {
return (ClassLoader)
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
ClassLoader cl = null;
try {
cl = Thread.currentThread().getContextClassLoader();
} catch (SecurityException ex) { }
return cl;
}
});
}
ClassLoader getSystemClassLoader() {
return (ClassLoader)
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
ClassLoader cl = null;
try {
cl = ClassLoader.getSystemClassLoader();
} catch (SecurityException ex) {}
return cl;
}
});
}
ClassLoader getParentClassLoader(final ClassLoader cl) {
return (ClassLoader)
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
ClassLoader parent = null;
try {
parent = cl.getParent();
} catch (SecurityException ex) {}
// eliminate loops in case of the boot
// ClassLoader returning itself as a parent
return (parent == cl) ? null : parent;
}
});
}
String getSystemProperty(final String propName) {
return (String)
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
return System.getProperty(propName);
}
});
}
FileInputStream getFileInputStream(final File file)
throws FileNotFoundException
{
try {
return (FileInputStream)
AccessController.doPrivileged(new PrivilegedExceptionAction() {
public Object run() throws FileNotFoundException {
return new FileInputStream(file);
}
});
} catch (PrivilegedActionException e) {
throw (FileNotFoundException)e.getException();
}
}
InputStream getResourceAsStream(final ClassLoader cl,
final String name)
{
return (InputStream)
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
InputStream ris;
if (cl == null) {
ris = ClassLoader.getSystemResourceAsStream(name);
} else {
ris = cl.getResourceAsStream(name);
}
return ris;
}
});
}
boolean getFileExists(final File f) {
return ((Boolean)
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
return new Boolean(f.exists());
}
})).booleanValue();
}
long getLastModified(final File f) {
return ((Long)
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
return new Long(f.lastModified());
}
})).longValue();
}
}

View file

@ -51,4 +51,7 @@ public interface Translet {
public String[] getUrisArray();
public int[] getTypesArray();
public String[] getNamespaceArray();
public boolean useServicesMechnism();
public void setServicesMechnism(boolean flag);
}

View file

@ -55,11 +55,10 @@ public final class Compile {
public static void printUsage() {
StringBuffer vers = new StringBuffer("XSLTC version " +
VERSION_MAJOR + "." + VERSION_MINOR +
((VERSION_DELTA > 0) ? ("."+VERSION_DELTA) : ("")));
System.err.println(vers + "\n" +
new ErrorMsg(ErrorMsg.COMPILE_USAGE_STR));
System.err.println("XSLTC version " +
VERSION_MAJOR + "." + VERSION_MINOR +
((VERSION_DELTA > 0) ? ("." + VERSION_DELTA) : ("")) + "\n" +
new ErrorMsg(ErrorMsg.COMPILE_USAGE_STR));
if (_allowExit) System.exit(-1);
}
@ -78,7 +77,7 @@ public final class Compile {
final GetOpt getopt = new GetOpt(args, "o:d:j:p:uxhsinv");
if (args.length < 1) printUsage();
final XSLTC xsltc = new XSLTC();
final XSLTC xsltc = new XSLTC(true);
xsltc.init();
int c;

View file

@ -1,663 +0,0 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 2001-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: ObjectFactory.java,v 1.2.4.1 2005/09/12 09:12:02 pvedula Exp $
*/
package com.sun.org.apache.xalan.internal.xsltc.cmdline;
import java.io.InputStream;
import java.io.IOException;
import java.io.File;
import java.io.FileInputStream;
import java.util.Properties;
import java.io.BufferedReader;
import java.io.InputStreamReader;
/**
* This class is duplicated for each JAXP subpackage so keep it in sync.
* It is package private and therefore is not exposed as part of the JAXP
* API.
* <p>
* This code is designed to implement the JAXP 1.1 spec pluggability
* feature and is designed to run on JDK version 1.1 and
* later, and to compile on JDK 1.2 and onward.
* The code also runs both as part of an unbundled jar file and
* when bundled as part of the JDK.
* <p>
* This class was moved from the <code>javax.xml.parsers.ObjectFactory</code>
* class and modified to be used as a general utility for creating objects
* dynamically.
*
* @version $Id: ObjectFactory.java,v 1.9 2008/04/02 00:41:02 joehw Exp $
*/
class ObjectFactory {
//
// Constants
//
// name of default properties file to look for in JDK's jre/lib directory
private static final String DEFAULT_PROPERTIES_FILENAME =
"xalan.properties";
private static final String SERVICES_PATH = "META-INF/services/";
/** Set to true for debugging */
private static final boolean DEBUG = false;
/** cache the contents of the xalan.properties file.
* Until an attempt has been made to read this file, this will
* be null; if the file does not exist or we encounter some other error
* during the read, this will be empty.
*/
private static Properties fXalanProperties = null;
/***
* Cache the time stamp of the xalan.properties file so
* that we know if it's been modified and can invalidate
* the cache when necessary.
*/
private static long fLastModified = -1;
//
// Public static methods
//
/**
* Finds the implementation Class object in the specified order. The
* specified order is the following:
* <ol>
* <li>query the system property using <code>System.getProperty</code>
* <li>read <code>META-INF/services/<i>factoryId</i></code> file
* <li>use fallback classname
* </ol>
*
* @return instance of factory, never null
*
* @param factoryId Name of the factory to find, same as
* a property name
* @param fallbackClassName Implementation class name, if nothing else
* is found. Use null to mean no fallback.
*
* @exception ObjectFactory.ConfigurationError
*/
static Object createObject(String factoryId, String fallbackClassName)
throws ConfigurationError {
return createObject(factoryId, null, fallbackClassName);
} // createObject(String,String):Object
/**
* Finds the implementation Class object in the specified order. The
* specified order is the following:
* <ol>
* <li>query the system property using <code>System.getProperty</code>
* <li>read <code>$java.home/lib/<i>propertiesFilename</i></code> file
* <li>read <code>META-INF/services/<i>factoryId</i></code> file
* <li>use fallback classname
* </ol>
*
* @return instance of factory, never null
*
* @param factoryId Name of the factory to find, same as
* a property name
* @param propertiesFilename The filename in the $java.home/lib directory
* of the properties file. If none specified,
* ${java.home}/lib/xalan.properties will be used.
* @param fallbackClassName Implementation class name, if nothing else
* is found. Use null to mean no fallback.
*
* @exception ObjectFactory.ConfigurationError
*/
static Object createObject(String factoryId,
String propertiesFilename,
String fallbackClassName)
throws ConfigurationError
{
Class factoryClass = lookUpFactoryClass(factoryId,
propertiesFilename,
fallbackClassName);
if (factoryClass == null) {
throw new ConfigurationError(
"Provider for " + factoryId + " cannot be found", null);
}
try{
Object instance = factoryClass.newInstance();
if (DEBUG) debugPrintln("created new instance of factory " + factoryId);
return instance;
} catch (Exception x) {
throw new ConfigurationError(
"Provider for factory " + factoryId
+ " could not be instantiated: " + x, x);
}
} // createObject(String,String,String):Object
/**
* Finds the implementation Class object in the specified order. The
* specified order is the following:
* <ol>
* <li>query the system property using <code>System.getProperty</code>
* <li>read <code>$java.home/lib/<i>propertiesFilename</i></code> file
* <li>read <code>META-INF/services/<i>factoryId</i></code> file
* <li>use fallback classname
* </ol>
*
* @return Class object of factory, never null
*
* @param factoryId Name of the factory to find, same as
* a property name
* @param propertiesFilename The filename in the $java.home/lib directory
* of the properties file. If none specified,
* ${java.home}/lib/xalan.properties will be used.
* @param fallbackClassName Implementation class name, if nothing else
* is found. Use null to mean no fallback.
*
* @exception ObjectFactory.ConfigurationError
*/
static Class lookUpFactoryClass(String factoryId)
throws ConfigurationError
{
return lookUpFactoryClass(factoryId, null, null);
} // lookUpFactoryClass(String):Class
/**
* Finds the implementation Class object in the specified order. The
* specified order is the following:
* <ol>
* <li>query the system property using <code>System.getProperty</code>
* <li>read <code>$java.home/lib/<i>propertiesFilename</i></code> file
* <li>read <code>META-INF/services/<i>factoryId</i></code> file
* <li>use fallback classname
* </ol>
*
* @return Class object that provides factory service, never null
*
* @param factoryId Name of the factory to find, same as
* a property name
* @param propertiesFilename The filename in the $java.home/lib directory
* of the properties file. If none specified,
* ${java.home}/lib/xalan.properties will be used.
* @param fallbackClassName Implementation class name, if nothing else
* is found. Use null to mean no fallback.
*
* @exception ObjectFactory.ConfigurationError
*/
static Class lookUpFactoryClass(String factoryId,
String propertiesFilename,
String fallbackClassName)
throws ConfigurationError
{
String factoryClassName = lookUpFactoryClassName(factoryId,
propertiesFilename,
fallbackClassName);
ClassLoader cl = findClassLoader();
if (factoryClassName == null) {
factoryClassName = fallbackClassName;
}
// assert(className != null);
try{
Class providerClass = findProviderClass(factoryClassName,
cl,
true);
if (DEBUG) debugPrintln("created new instance of " + providerClass +
" using ClassLoader: " + cl);
return providerClass;
} catch (ClassNotFoundException x) {
throw new ConfigurationError(
"Provider " + factoryClassName + " not found", x);
} catch (Exception x) {
throw new ConfigurationError(
"Provider "+factoryClassName+" could not be instantiated: "+x,
x);
}
} // lookUpFactoryClass(String,String,String):Class
/**
* Finds the name of the required implementation class in the specified
* order. The specified order is the following:
* <ol>
* <li>query the system property using <code>System.getProperty</code>
* <li>read <code>$java.home/lib/<i>propertiesFilename</i></code> file
* <li>read <code>META-INF/services/<i>factoryId</i></code> file
* <li>use fallback classname
* </ol>
*
* @return name of class that provides factory service, never null
*
* @param factoryId Name of the factory to find, same as
* a property name
* @param propertiesFilename The filename in the $java.home/lib directory
* of the properties file. If none specified,
* ${java.home}/lib/xalan.properties will be used.
* @param fallbackClassName Implementation class name, if nothing else
* is found. Use null to mean no fallback.
*
* @exception ObjectFactory.ConfigurationError
*/
static String lookUpFactoryClassName(String factoryId,
String propertiesFilename,
String fallbackClassName)
{
SecuritySupport ss = SecuritySupport.getInstance();
// Use the system property first
try {
String systemProp = ss.getSystemProperty(factoryId);
if (systemProp != null) {
if (DEBUG) debugPrintln("found system property, value=" + systemProp);
return systemProp;
}
} catch (SecurityException se) {
// Ignore and continue w/ next location
}
// Try to read from propertiesFilename, or
// $java.home/lib/xalan.properties
String factoryClassName = null;
// no properties file name specified; use
// $JAVA_HOME/lib/xalan.properties:
if (propertiesFilename == null) {
File propertiesFile = null;
boolean propertiesFileExists = false;
try {
String javah = ss.getSystemProperty("java.home");
propertiesFilename = javah + File.separator +
"lib" + File.separator + DEFAULT_PROPERTIES_FILENAME;
propertiesFile = new File(propertiesFilename);
propertiesFileExists = ss.getFileExists(propertiesFile);
} catch (SecurityException e) {
// try again...
fLastModified = -1;
fXalanProperties = null;
}
synchronized (ObjectFactory.class) {
boolean loadProperties = false;
FileInputStream fis = null;
try {
// file existed last time
if(fLastModified >= 0) {
if(propertiesFileExists &&
(fLastModified < (fLastModified = ss.getLastModified(propertiesFile)))) {
loadProperties = true;
} else {
// file has stopped existing...
if(!propertiesFileExists) {
fLastModified = -1;
fXalanProperties = null;
} // else, file wasn't modified!
}
} else {
// file has started to exist:
if(propertiesFileExists) {
loadProperties = true;
fLastModified = ss.getLastModified(propertiesFile);
} // else, nothing's changed
}
if(loadProperties) {
// must never have attempted to read xalan.properties
// before (or it's outdeated)
fXalanProperties = new Properties();
fis = ss.getFileInputStream(propertiesFile);
fXalanProperties.load(fis);
}
} catch (Exception x) {
fXalanProperties = null;
fLastModified = -1;
// assert(x instanceof FileNotFoundException
// || x instanceof SecurityException)
// In both cases, ignore and continue w/ next location
}
finally {
// try to close the input stream if one was opened.
if (fis != null) {
try {
fis.close();
}
// Ignore the exception.
catch (IOException exc) {}
}
}
}
if(fXalanProperties != null) {
factoryClassName = fXalanProperties.getProperty(factoryId);
}
} else {
FileInputStream fis = null;
try {
fis = ss.getFileInputStream(new File(propertiesFilename));
Properties props = new Properties();
props.load(fis);
factoryClassName = props.getProperty(factoryId);
} catch (Exception x) {
// assert(x instanceof FileNotFoundException
// || x instanceof SecurityException)
// In both cases, ignore and continue w/ next location
}
finally {
// try to close the input stream if one was opened.
if (fis != null) {
try {
fis.close();
}
// Ignore the exception.
catch (IOException exc) {}
}
}
}
if (factoryClassName != null) {
if (DEBUG) debugPrintln("found in " + propertiesFilename + ", value="
+ factoryClassName);
return factoryClassName;
}
// Try Jar Service Provider Mechanism
return findJarServiceProviderName(factoryId);
} // lookUpFactoryClass(String,String):String
//
// Private static methods
//
/** Prints a message to standard error if debugging is enabled. */
private static void debugPrintln(String msg) {
if (DEBUG) {
System.err.println("JAXP: " + msg);
}
} // debugPrintln(String)
/**
* Figure out which ClassLoader to use. For JDK 1.2 and later use
* the context ClassLoader.
*/
static ClassLoader findClassLoader()
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 context = ss.getContextClassLoader();
ClassLoader system = ss.getSystemClassLoader();
ClassLoader chain = system;
while (true) {
if (context == chain) {
// Assert: we are on JDK 1.1 or we have no Context ClassLoader
// or any Context ClassLoader in chain of system classloader
// (including extension ClassLoader) so extend to widest
// ClassLoader (always look in system ClassLoader if Xalan
// is in boot/extension/system classpath and in current
// ClassLoader otherwise); normal classloaders delegate
// back to system ClassLoader first so this widening doesn't
// change the fact that context ClassLoader will be consulted
ClassLoader current = ObjectFactory.class.getClassLoader();
chain = system;
while (true) {
if (current == chain) {
// Assert: Current ClassLoader in chain of
// boot/extension/system ClassLoaders
return system;
}
if (chain == null) {
break;
}
chain = ss.getParentClassLoader(chain);
}
// Assert: Current ClassLoader not in chain of
// boot/extension/system ClassLoaders
return current;
}
if (chain == null) {
// boot ClassLoader reached
break;
}
// Check for any extension ClassLoaders in chain up to
// boot ClassLoader
chain = ss.getParentClassLoader(chain);
};
// Assert: Context ClassLoader not in chain of
// boot/extension/system ClassLoaders
return context;
} // findClassLoader():ClassLoader
/**
* Create an instance of a class using the specified ClassLoader
*/
static Object newInstance(String className, ClassLoader cl,
boolean doFallback)
throws ConfigurationError
{
// assert(className != null);
try{
Class providerClass = findProviderClass(className, cl, doFallback);
Object instance = providerClass.newInstance();
if (DEBUG) debugPrintln("created new instance of " + providerClass +
" using ClassLoader: " + cl);
return instance;
} catch (ClassNotFoundException x) {
throw new ConfigurationError(
"Provider " + className + " not found", x);
} catch (Exception x) {
throw new ConfigurationError(
"Provider " + className + " could not be instantiated: " + x,
x);
}
}
/**
* Find a Class using the specified ClassLoader
*/
static Class findProviderClass(String className, ClassLoader cl,
boolean doFallback)
throws ClassNotFoundException, ConfigurationError
{
//throw security exception if the calling thread is not allowed to access the
//class. Restrict the access to the package classes as specified in java.security policy.
SecurityManager security = System.getSecurityManager();
try{
if (security != null){
final int lastDot = className.lastIndexOf(".");
String packageName = className;
if (lastDot != -1) packageName = className.substring(0, lastDot);
security.checkPackageAccess(packageName);
}
}catch(SecurityException e){
throw e;
}
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);
} else {
try {
providerClass = cl.loadClass(className);
} catch (ClassNotFoundException x) {
if (doFallback) {
// Fall back to current classloader
ClassLoader current = ObjectFactory.class.getClassLoader();
if (current == null) {
providerClass = Class.forName(className);
} else if (cl != current) {
cl = current;
providerClass = cl.loadClass(className);
} else {
throw x;
}
} else {
throw x;
}
}
}
return providerClass;
}
/**
* Find the name of service provider using Jar Service Provider Mechanism
*
* @return instance of provider class if found or null
*/
private static String findJarServiceProviderName(String factoryId)
{
SecuritySupport ss = SecuritySupport.getInstance();
String serviceId = SERVICES_PATH + factoryId;
InputStream is = null;
// First try the Context ClassLoader
ClassLoader cl = findClassLoader();
is = ss.getResourceAsStream(cl, serviceId);
// If no provider found then try the current ClassLoader
if (is == null) {
ClassLoader current = ObjectFactory.class.getClassLoader();
if (cl != current) {
cl = current;
is = ss.getResourceAsStream(cl, serviceId);
}
}
if (is == null) {
// No provider found
return null;
}
if (DEBUG) debugPrintln("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 {
rd = new BufferedReader(new InputStreamReader(is, "UTF-8"));
} catch (java.io.UnsupportedEncodingException e) {
rd = new BufferedReader(new InputStreamReader(is));
}
String factoryClassName = null;
try {
// XXX Does not handle all possible input as specified by the
// Jar Service Provider specification
factoryClassName = rd.readLine();
} catch (IOException x) {
// No provider found
return null;
}
finally {
try {
// try to close the reader.
rd.close();
}
// Ignore the exception.
catch (IOException exc) {}
}
if (factoryClassName != null &&
! "".equals(factoryClassName)) {
if (DEBUG) debugPrintln("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 factoryClassName;
}
// No provider found
return null;
}
//
// Classes
//
/**
* A configuration error.
*/
static class ConfigurationError
extends Error {
static final long serialVersionUID = -6072257854297546607L;
//
// Data
//
/** Exception. */
private Exception exception;
//
// Constructors
//
/**
* Construct a new instance with the specified detail string and
* exception.
*/
ConfigurationError(String msg, Exception x) {
super(msg);
this.exception = x;
} // <init>(String,Exception)
//
// Public methods
//
/** Returns the exception associated to this error. */
Exception getException() {
return exception;
} // getException():Exception
} // class ConfigurationError
} // class ObjectFactory

View file

@ -1,127 +0,0 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 2002-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: SecuritySupport.java,v 1.2.4.1 2005/08/31 11:30:44 pvedula Exp $
*/
package com.sun.org.apache.xalan.internal.xsltc.cmdline;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.Properties;
/**
* This class is duplicated for each Xalan-Java subpackage so keep it in sync.
* It is package private and therefore is not exposed as part of the Xalan-Java
* 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.
*/
static SecuritySupport getInstance() {
return (SecuritySupport)securitySupport;
}
ClassLoader getContextClassLoader() {
return null;
}
ClassLoader getSystemClassLoader() {
return null;
}
ClassLoader getParentClassLoader(ClassLoader cl) {
return null;
}
String getSystemProperty(String propName) {
return System.getProperty(propName);
}
FileInputStream getFileInputStream(File file)
throws FileNotFoundException
{
return new FileInputStream(file);
}
InputStream getResourceAsStream(ClassLoader cl, String name) {
InputStream ris;
if (cl == null) {
ris = ClassLoader.getSystemResourceAsStream(name);
} else {
ris = cl.getResourceAsStream(name);
}
return ris;
}
boolean getFileExists(File f) {
return f.exists();
}
long getLastModified(File f) {
return f.lastModified();
}
}

View file

@ -1,148 +0,0 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 2002-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: SecuritySupport12.java,v 1.2.4.1 2005/08/31 11:33:55 pvedula Exp $
*/
package com.sun.org.apache.xalan.internal.xsltc.cmdline;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.util.Properties;
/**
* This class is duplicated for each Xalan-Java subpackage so keep it in sync.
* It is package private and therefore is not exposed as part of the Xalan-Java
* API.
*
* Security related methods that only work on J2SE 1.2 and newer.
*/
class SecuritySupport12 extends SecuritySupport {
ClassLoader getContextClassLoader() {
return (ClassLoader)
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
ClassLoader cl = null;
try {
cl = Thread.currentThread().getContextClassLoader();
} catch (SecurityException ex) { }
return cl;
}
});
}
ClassLoader getSystemClassLoader() {
return (ClassLoader)
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
ClassLoader cl = null;
try {
cl = ClassLoader.getSystemClassLoader();
} catch (SecurityException ex) {}
return cl;
}
});
}
ClassLoader getParentClassLoader(final ClassLoader cl) {
return (ClassLoader)
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
ClassLoader parent = null;
try {
parent = cl.getParent();
} catch (SecurityException ex) {}
// eliminate loops in case of the boot
// ClassLoader returning itself as a parent
return (parent == cl) ? null : parent;
}
});
}
String getSystemProperty(final String propName) {
return (String)
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
return System.getProperty(propName);
}
});
}
FileInputStream getFileInputStream(final File file)
throws FileNotFoundException
{
try {
return (FileInputStream)
AccessController.doPrivileged(new PrivilegedExceptionAction() {
public Object run() throws FileNotFoundException {
return new FileInputStream(file);
}
});
} catch (PrivilegedActionException e) {
throw (FileNotFoundException)e.getException();
}
}
InputStream getResourceAsStream(final ClassLoader cl,
final String name)
{
return (InputStream)
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
InputStream ris;
if (cl == null) {
ris = ClassLoader.getSystemResourceAsStream(name);
} else {
ris = cl.getResourceAsStream(name);
}
return ris;
}
});
}
boolean getFileExists(final File f) {
return ((Boolean)
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
return new Boolean(f.exists());
}
})).booleanValue();
}
long getLastModified(final File f) {
return ((Long)
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
return new Long(f.lastModified());
}
})).longValue();
}
}

View file

@ -49,6 +49,7 @@ import org.xml.sax.XMLReader;
import com.sun.org.apache.xalan.internal.xsltc.StripFilter;
import com.sun.org.apache.xml.internal.dtm.DTMWSFilter;
import com.sun.org.apache.xalan.internal.xsltc.dom.DOMWSFilter;
import com.sun.org.apache.xalan.internal.utils.ObjectFactory;
/**
* @author Jacek Ambroziak
@ -97,8 +98,7 @@ final public class Transform {
private void doTransform() {
try {
final Class clazz = ObjectFactory.findProviderClass(
_className, ObjectFactory.findClassLoader(), true);
final Class clazz = ObjectFactory.findProviderClass(_className, true);
final AbstractTranslet translet = (AbstractTranslet)clazz.newInstance();
translet.postInitialization();

View file

@ -106,13 +106,15 @@ final class AbsoluteLocationPath extends Expression {
LocalVariableGen relPathIterator
= methodGen.addLocalVariable("abs_location_path_tmp",
Util.getJCRefType(NODE_ITERATOR_SIG),
il.getEnd(), null);
il.append(new ASTORE(relPathIterator.getIndex()));
null, null);
relPathIterator.setStart(
il.append(new ASTORE(relPathIterator.getIndex())));
// Create new AbsoluteIterator
il.append(new NEW(cpg.addClass(ABSOLUTE_ITERATOR)));
il.append(DUP);
il.append(new ALOAD(relPathIterator.getIndex()));
relPathIterator.setEnd(
il.append(new ALOAD(relPathIterator.getIndex())));
// Initialize AbsoluteIterator with iterator from the stack
il.append(new INVOKESPECIAL(initAI));

View file

@ -87,9 +87,9 @@ final class AbsolutePathPattern extends LocationPathPattern {
// absolute path pattern temporary
methodGen.addLocalVariable2("apptmp",
Util.getJCRefType(NODE_SIG),
il.getEnd());
null);
il.append(DUP);
il.append(new ISTORE(local.getIndex()));
local.setStart(il.append(new ISTORE(local.getIndex())));
_left.translate(classGen, methodGen);
il.append(methodGen.loadDOM());
local.setEnd(il.append(new ILOAD(local.getIndex())));

View file

@ -192,11 +192,7 @@ final class AttributeSet extends TopLevelElement {
final InstructionList il = methodGen.getInstructionList();
il.append(RETURN);
methodGen.stripAttributes(true);
methodGen.setMaxLocals();
methodGen.setMaxStack();
methodGen.removeNOPs();
classGen.addMethod(methodGen.getMethod());
classGen.addMethod(methodGen);
}
public String toString() {

View file

@ -84,11 +84,11 @@ final class Copy extends Instruction {
final LocalVariableGen name =
methodGen.addLocalVariable2("name",
Util.getJCRefType(STRING_SIG),
il.getEnd());
null);
final LocalVariableGen length =
methodGen.addLocalVariable2("length",
Util.getJCRefType("I"),
il.getEnd());
null);
// Get the name of the node to copy and save for later
il.append(methodGen.loadDOM());
@ -102,7 +102,7 @@ final class Copy extends Instruction {
+ ")" + STRING_SIG);
il.append(new INVOKEINTERFACE(cpy, 3));
il.append(DUP);
il.append(new ASTORE(name.getIndex()));
name.setStart(il.append(new ASTORE(name.getIndex())));
final BranchHandle ifBlock1 = il.append(new IFNULL(null));
// Get the length of the node name and save for later
@ -110,7 +110,7 @@ final class Copy extends Instruction {
final int lengthMethod = cpg.addMethodref(STRING_CLASS,"length","()I");
il.append(new INVOKEVIRTUAL(lengthMethod));
il.append(DUP);
il.append(new ISTORE(length.getIndex()));
length.setStart(il.append(new ISTORE(length.getIndex())));
// Ignore attribute sets if current node is ROOT. DOM.shallowCopy()
// returns "" for ROOT, so skip attribute sets if length == 0
@ -144,10 +144,10 @@ final class Copy extends Instruction {
// Call the output handler's endElement() if we copied an element
// (The DOM.shallowCopy() method calls startElement().)
il.append(new ILOAD(length.getIndex()));
length.setEnd(il.append(new ILOAD(length.getIndex())));
final BranchHandle ifBlock3 = il.append(new IFEQ(null));
il.append(methodGen.loadHandler());
il.append(new ALOAD(name.getIndex()));
name.setEnd(il.append(new ALOAD(name.getIndex())));
il.append(methodGen.endElement());
final InstructionHandle end = il.append(NOP);

View file

@ -28,11 +28,12 @@ import java.util.Vector;
import com.sun.org.apache.bcel.internal.generic.ALOAD;
import com.sun.org.apache.bcel.internal.generic.ASTORE;
import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen;
import com.sun.org.apache.bcel.internal.generic.NEW;
import com.sun.org.apache.bcel.internal.generic.ILOAD;
import com.sun.org.apache.bcel.internal.generic.INVOKEINTERFACE;
import com.sun.org.apache.bcel.internal.generic.INVOKESPECIAL;
import com.sun.org.apache.bcel.internal.generic.INVOKESTATIC;
import com.sun.org.apache.bcel.internal.generic.InstructionList;
import com.sun.org.apache.bcel.internal.generic.ISTORE;
import com.sun.org.apache.bcel.internal.generic.LocalVariableGen;
import com.sun.org.apache.bcel.internal.generic.NEW;
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator;
@ -99,6 +100,7 @@ class FilterExpr extends Expression {
*/
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
Type ptype = _primary.typeCheck(stable);
boolean canOptimize = _primary instanceof KeyCall;
if (ptype instanceof NodeSetType == false) {
if (ptype instanceof ReferenceType) {
@ -109,11 +111,14 @@ class FilterExpr extends Expression {
}
}
// Type check predicates and turn all optimizations off
// Type check predicates and turn all optimizations off if appropriate
int n = _predicates.size();
for (int i = 0; i < n; i++) {
Predicate pred = (Predicate) _predicates.elementAt(i);
pred.dontOptimize();
if (!canOptimize) {
pred.dontOptimize();
}
pred.typeCheck(stable);
}
return _type = Type.NodeSet;
@ -155,52 +160,95 @@ class FilterExpr extends Expression {
translateFilterExpr(classGen, methodGen, predicateIndex);
}
else {
// Translate predicates from right to left
final int initCNLI = cpg.addMethodref(CURRENT_NODE_LIST_ITERATOR,
"<init>",
"("+NODE_ITERATOR_SIG+"Z"+
CURRENT_NODE_LIST_FILTER_SIG +
NODE_SIG+TRANSLET_SIG+")V");
// Backwards branches are prohibited if an uninitialized object is
// on the stack by section 4.9.4 of the JVM Specification, 2nd Ed.
// We don't know whether this code might contain backwards branches,
// so we mustn't create the new object until after we've created
// the suspect arguments to its constructor. Instead we calculate
// the values of the arguments to the constructor first, store them
// in temporary variables, create the object and reload the
// arguments from the temporaries to avoid the problem.
// Get the next predicate to be translated
Predicate predicate = (Predicate) _predicates.get(predicateIndex--);
// Translate the rest of the predicates from right to left
translatePredicates(classGen, methodGen, predicateIndex);
LocalVariableGen nodeIteratorTemp =
methodGen.addLocalVariable("filter_expr_tmp1",
Util.getJCRefType(NODE_ITERATOR_SIG),
il.getEnd(), null);
il.append(new ASTORE(nodeIteratorTemp.getIndex()));
if (predicate.isNthPositionFilter()) {
int nthIteratorIdx = cpg.addMethodref(NTH_ITERATOR_CLASS,
"<init>",
"("+NODE_ITERATOR_SIG+"I)V");
predicate.translate(classGen, methodGen);
LocalVariableGen filterTemp =
methodGen.addLocalVariable("filter_expr_tmp2",
Util.getJCRefType(CURRENT_NODE_LIST_FILTER_SIG),
il.getEnd(), null);
il.append(new ASTORE(filterTemp.getIndex()));
// Backwards branches are prohibited if an uninitialized object
// is on the stack by section 4.9.4 of the JVM Specification,
// 2nd Ed. We don't know whether this code might contain
// backwards branches, so we mustn't create the new object unti
// Create a CurrentNodeListIterator
il.append(new NEW(cpg.addClass(CURRENT_NODE_LIST_ITERATOR)));
il.append(DUP);
// after we've created the suspect arguments to its constructor
// Initialize CurrentNodeListIterator
il.append(new ALOAD(nodeIteratorTemp.getIndex()));
il.append(ICONST_1);
il.append(new ALOAD(filterTemp.getIndex()));
il.append(methodGen.loadCurrentNode());
il.append(classGen.loadTranslet());
il.append(new INVOKESPECIAL(initCNLI));
// Instead we calculate the values of the arguments to the
// constructor first, store them in temporary variables, create
// the object and reload the arguments from the temporaries to
// avoid the problem.
LocalVariableGen iteratorTemp
= methodGen.addLocalVariable("filter_expr_tmp1",
Util.getJCRefType(NODE_ITERATOR_SIG),
null, null);
iteratorTemp.setStart(
il.append(new ASTORE(iteratorTemp.getIndex())));
predicate.translate(classGen, methodGen);
LocalVariableGen predicateValueTemp
= methodGen.addLocalVariable("filter_expr_tmp2",
Util.getJCRefType("I"),
null, null);
predicateValueTemp.setStart(
il.append(new ISTORE(predicateValueTemp.getIndex())));
il.append(new NEW(cpg.addClass(NTH_ITERATOR_CLASS)));
il.append(DUP);
iteratorTemp.setEnd(
il.append(new ALOAD(iteratorTemp.getIndex())));
predicateValueTemp.setEnd(
il.append(new ILOAD(predicateValueTemp.getIndex())));
il.append(new INVOKESPECIAL(nthIteratorIdx));
} else {
// Translate predicates from right to left
final int initCNLI = cpg.addMethodref(CURRENT_NODE_LIST_ITERATOR,
"<init>",
"("+NODE_ITERATOR_SIG+"Z"+
CURRENT_NODE_LIST_FILTER_SIG +
NODE_SIG+TRANSLET_SIG+")V");
// Backwards branches are prohibited if an uninitialized object is
// on the stack by section 4.9.4 of the JVM Specification, 2nd Ed.
// We don't know whether this code might contain backwards branches,
// so we mustn't create the new object until after we've created
// the suspect arguments to its constructor. Instead we calculate
// the values of the arguments to the constructor first, store them
// in temporary variables, create the object and reload the
// arguments from the temporaries to avoid the problem.
LocalVariableGen nodeIteratorTemp =
methodGen.addLocalVariable("filter_expr_tmp1",
Util.getJCRefType(NODE_ITERATOR_SIG),
null, null);
nodeIteratorTemp.setStart(
il.append(new ASTORE(nodeIteratorTemp.getIndex())));
predicate.translate(classGen, methodGen);
LocalVariableGen filterTemp =
methodGen.addLocalVariable("filter_expr_tmp2",
Util.getJCRefType(CURRENT_NODE_LIST_FILTER_SIG),
null, null);
filterTemp.setStart(il.append(new ASTORE(filterTemp.getIndex())));
// Create a CurrentNodeListIterator
il.append(new NEW(cpg.addClass(CURRENT_NODE_LIST_ITERATOR)));
il.append(DUP);
// Initialize CurrentNodeListIterator
nodeIteratorTemp.setEnd(
il.append(new ALOAD(nodeIteratorTemp.getIndex())));
il.append(ICONST_1);
filterTemp.setEnd(il.append(new ALOAD(filterTemp.getIndex())));
il.append(methodGen.loadCurrentNode());
il.append(classGen.loadTranslet());
il.append(new INVOKESPECIAL(initCNLI));
}
}
}
}

View file

@ -128,20 +128,20 @@ final class FilterParentPath extends Expression {
LocalVariableGen filterTemp =
methodGen.addLocalVariable("filter_parent_path_tmp1",
Util.getJCRefType(NODE_ITERATOR_SIG),
il.getEnd(), null);
il.append(new ASTORE(filterTemp.getIndex()));
null, null);
filterTemp.setStart(il.append(new ASTORE(filterTemp.getIndex())));
_path.translate(classGen, methodGen);
LocalVariableGen pathTemp =
methodGen.addLocalVariable("filter_parent_path_tmp2",
Util.getJCRefType(NODE_ITERATOR_SIG),
il.getEnd(), null);
il.append(new ASTORE(pathTemp.getIndex()));
null, null);
pathTemp.setStart(il.append(new ASTORE(pathTemp.getIndex())));
il.append(new NEW(cpg.addClass(STEP_ITERATOR_CLASS)));
il.append(DUP);
il.append(new ALOAD(filterTemp.getIndex()));
il.append(new ALOAD(pathTemp.getIndex()));
filterTemp.setEnd(il.append(new ALOAD(filterTemp.getIndex())));
pathTemp.setEnd(il.append(new ALOAD(pathTemp.getIndex())));
// Initialize StepIterator with iterators from the stack
il.append(new INVOKESPECIAL(initSI));
@ -154,8 +154,16 @@ final class FilterParentPath extends Expression {
il.append(new INVOKEVIRTUAL(incl));
}
if (!(getParent() instanceof RelativeLocationPath) &&
!(getParent() instanceof FilterParentPath)) {
SyntaxTreeNode parent = getParent();
boolean parentAlreadyOrdered =
(parent instanceof RelativeLocationPath)
|| (parent instanceof FilterParentPath)
|| (parent instanceof KeyCall)
|| (parent instanceof CurrentCall)
|| (parent instanceof DocumentCall);
if (!parentAlreadyOrdered) {
final int order = cpg.addInterfaceMethodref(DOM_INTF,
ORDER_ITERATOR,
ORDER_ITERATOR_SIG);

View file

@ -104,14 +104,14 @@ final class FilteredAbsoluteLocationPath extends Expression {
LocalVariableGen pathTemp =
methodGen.addLocalVariable("filtered_absolute_location_path_tmp",
Util.getJCRefType(NODE_ITERATOR_SIG),
il.getEnd(), null);
null, null);
_path.translate(classGen, methodGen);
il.append(new ASTORE(pathTemp.getIndex()));
pathTemp.setStart(il.append(new ASTORE(pathTemp.getIndex())));
// Create new Dup Filter Iterator
il.append(new NEW(cpg.addClass(DUP_FILTERED_ITERATOR)));
il.append(DUP);
il.append(new ALOAD(pathTemp.getIndex()));
pathTemp.setEnd(il.append(new ALOAD(pathTemp.getIndex())));
// Initialize Dup Filter Iterator with iterator from the stack
il.append(new INVOKESPECIAL(initDFI));

View file

@ -35,6 +35,7 @@ import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator;
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type;
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError;
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Util;
import com.sun.org.apache.xalan.internal.utils.ObjectFactory;
/**
* @author G. Todd Miller
@ -132,8 +133,7 @@ final class FunctionAvailableCall extends FunctionCall {
methodName = replaceDash(methodName);
try {
final Class clazz = ObjectFactory.findProviderClass(
className, ObjectFactory.findClassLoader(), true);
final Class clazz = ObjectFactory.findProviderClass(className, true);
if (clazz == null) {
return false;

View file

@ -53,6 +53,7 @@ import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ObjectType;
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ReferenceType;
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type;
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError;
import com.sun.org.apache.xalan.internal.utils.ObjectFactory;
/**
* @author Jacek Ambroziak
@ -355,8 +356,7 @@ class FunctionCall extends Expression {
else {
if (_className != null && _className.length() > 0) {
try {
_clazz = ObjectFactory.findProviderClass(
_className, ObjectFactory.findClassLoader(), true);
_clazz = ObjectFactory.findProviderClass(_className, true);
_namespace_format = NAMESPACE_FORMAT_CLASS;
}
catch (ClassNotFoundException e) {
@ -775,8 +775,10 @@ class FunctionCall extends Expression {
paramTemp[i] =
methodGen.addLocalVariable("function_call_tmp"+i,
expType.toJCType(),
il.getEnd(), null);
il.append(expType.STORE(paramTemp[i].getIndex()));
null, null);
paramTemp[i].setStart(
il.append(expType.STORE(paramTemp[i].getIndex())));
}
il.append(new NEW(cpg.addClass(_className)));
@ -784,7 +786,8 @@ class FunctionCall extends Expression {
for (int i = 0; i < n; i++) {
final Expression arg = argument(i);
il.append(arg.getType().LOAD(paramTemp[i].getIndex()));
paramTemp[i].setEnd(
il.append(arg.getType().LOAD(paramTemp[i].getIndex())));
}
final StringBuffer buffer = new StringBuffer();
@ -882,8 +885,7 @@ class FunctionCall extends Expression {
final int nArgs = _arguments.size();
try {
if (_clazz == null) {
_clazz = ObjectFactory.findProviderClass(
_className, ObjectFactory.findClassLoader(), true);
_clazz = ObjectFactory.findProviderClass(_className, true);
if (_clazz == null) {
final ErrorMsg msg =
@ -929,8 +931,7 @@ class FunctionCall extends Expression {
final int nArgs = _arguments.size();
try {
if (_clazz == null) {
_clazz = ObjectFactory.findProviderClass(
_className, ObjectFactory.findClassLoader(), true);
_clazz = ObjectFactory.findProviderClass(_className, true);
if (_clazz == null) {
final ErrorMsg msg = new ErrorMsg(ErrorMsg.CLASS_NOT_FOUND_ERR, _className);

View file

@ -166,10 +166,10 @@ final class Key extends TopLevelElement {
final LocalVariableGen parentNode =
methodGen.addLocalVariable("parentNode",
Util.getJCRefType("I"),
il.getEnd(), null);
null, null);
// Get the 'parameter' from the stack and store it in a local var.
il.append(new ISTORE(parentNode.getIndex()));
parentNode.setStart(il.append(new ISTORE(parentNode.getIndex())));
// Save current node and current iterator on the stack
il.append(methodGen.loadCurrentNode());
@ -186,9 +186,9 @@ final class Key extends TopLevelElement {
// Prepare to call buildKeyIndex(String name, int node, String value);
il.append(classGen.loadTranslet());
il.append(new PUSH(cpg, _name.toString()));
il.append(new ILOAD(parentNode.getIndex()));
parentNode.setEnd(il.append(new ILOAD(parentNode.getIndex())));
// Now get the node value and feck it on the parameter stack
// Now get the node value and push it on the parameter stack
il.append(methodGen.loadDOM());
il.append(methodGen.loadCurrentNode());
il.append(new INVOKEINTERFACE(getNodeValue, 2));

View file

@ -24,6 +24,7 @@
package com.sun.org.apache.xalan.internal.xsltc.compiler;
import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen;
import com.sun.org.apache.bcel.internal.generic.INVOKEINTERFACE;
import com.sun.org.apache.bcel.internal.generic.INVOKESPECIAL;
import com.sun.org.apache.bcel.internal.generic.INVOKEVIRTUAL;
import com.sun.org.apache.bcel.internal.generic.InstructionList;
@ -97,36 +98,41 @@ final class Message extends Instruction {
// Invoke output.setWriter(STRING_WRITER)
il.append(methodGen.loadHandler());
il.append(SWAP);
il.append(new INVOKEVIRTUAL(
cpg.addMethodref(OUTPUT_BASE, "setWriter",
"("+WRITER_SIG+")V")));
il.append(new INVOKEINTERFACE(
cpg.addInterfaceMethodref(TRANSLET_OUTPUT_INTERFACE,
"setWriter",
"("+WRITER_SIG+")V"), 2));
// Invoke output.setEncoding("UTF-8")
il.append(methodGen.loadHandler());
il.append(new PUSH(cpg, "UTF-8")); // other encodings?
il.append(new INVOKEVIRTUAL(
cpg.addMethodref(OUTPUT_BASE, "setEncoding",
"("+STRING_SIG+")V")));
il.append(new INVOKEINTERFACE(
cpg.addInterfaceMethodref(TRANSLET_OUTPUT_INTERFACE,
"setEncoding",
"("+STRING_SIG+")V"), 2));
// Invoke output.setOmitXMLDeclaration(true)
il.append(methodGen.loadHandler());
il.append(ICONST_1);
il.append(new INVOKEVIRTUAL(
cpg.addMethodref(OUTPUT_BASE, "setOmitXMLDeclaration",
"(Z)V")));
il.append(new INVOKEINTERFACE(
cpg.addInterfaceMethodref(TRANSLET_OUTPUT_INTERFACE,
"setOmitXMLDeclaration",
"(Z)V"), 2));
il.append(methodGen.loadHandler());
il.append(new INVOKEVIRTUAL(
cpg.addMethodref(OUTPUT_BASE, "startDocument",
"()V")));
il.append(new INVOKEINTERFACE(
cpg.addInterfaceMethodref(TRANSLET_OUTPUT_INTERFACE,
"startDocument",
"()V"), 1));
// Inline translation of contents
translateContents(classGen, methodGen);
il.append(methodGen.loadHandler());
il.append(new INVOKEVIRTUAL(
cpg.addMethodref(OUTPUT_BASE, "endDocument",
"()V")));
il.append(new INVOKEINTERFACE(
cpg.addInterfaceMethodref(TRANSLET_OUTPUT_INTERFACE,
"endDocument",
"()V"), 1));
// Call toString() on StringWriter
il.append(new INVOKEVIRTUAL(

View file

@ -553,11 +553,7 @@ for (int i = 0; i < _templates.size(); i++) {
il.append(template.compile(classGen, methodGen));
il.append(RETURN);
methodGen.stripAttributes(true);
methodGen.setMaxLocals();
methodGen.setMaxStack();
methodGen.removeNOPs();
classGen.addMethod(methodGen.getMethod());
classGen.addMethod(methodGen);
}
private void compileTemplates(ClassGenerator classGen,
@ -765,12 +761,16 @@ for (int i = 0; i < _templates.size(); i++) {
getClassName(), mainIL,
classGen.getConstantPool());
methodGen.addException("com.sun.org.apache.xalan.internal.xsltc.TransletException");
// Insert an extra NOP just to keep "current" from appearing as if it
// has a value before the start of the loop.
mainIL.append(NOP);
// Create a local variable to hold the current node
final LocalVariableGen current;
current = methodGen.addLocalVariable2("current",
com.sun.org.apache.bcel.internal.generic.Type.INT,
mainIL.getEnd());
null);
_currentIndex = current.getIndex();
// Create the "body" instruction list that will eventually hold the
@ -793,6 +793,11 @@ for (int i = 0; i < _templates.size(); i++) {
ifeq.setTarget(ilLoop.append(RETURN)); // applyTemplates() ends here!
final InstructionHandle ihLoop = ilLoop.getStart();
current.setStart(mainIL.append(new GOTO_W(ihLoop)));
// Live range of "current" ends at end of loop
current.setEnd(loop);
// Compile default handling of elements (traverse children)
InstructionList ilRecurse =
compileDefaultRecursion(classGen, methodGen, ihLoop);
@ -1029,18 +1034,12 @@ for (int i = 0; i < _templates.size(); i++) {
body.append(ilText);
// putting together constituent instruction lists
mainIL.append(new GOTO_W(ihLoop));
mainIL.append(body);
// fall through to ilLoop
mainIL.append(ilLoop);
peepHoleOptimization(methodGen);
methodGen.stripAttributes(true);
methodGen.setMaxLocals();
methodGen.setMaxStack();
methodGen.removeNOPs();
classGen.addMethod(methodGen.getMethod());
classGen.addMethod(methodGen);
// Compile method(s) for <xsl:apply-imports/> for this mode
if (_importLevels != null) {
@ -1131,11 +1130,11 @@ for (int i = 0; i < _templates.size(); i++) {
final LocalVariableGen current;
current = methodGen.addLocalVariable2("current",
com.sun.org.apache.bcel.internal.generic.Type.INT,
mainIL.getEnd());
null);
_currentIndex = current.getIndex();
mainIL.append(new ILOAD(methodGen.getLocalIndex(NODE_PNAME)));
mainIL.append(new ISTORE(_currentIndex));
mainIL.append(new ILOAD(methodGen.getLocalIndex(NODE_PNAME)));
current.setStart(mainIL.append(new ISTORE(_currentIndex)));
// Create the "body" instruction list that will eventually hold the
// code for the entire method (other ILs will be appended).
@ -1145,7 +1144,7 @@ for (int i = 0; i < _templates.size(); i++) {
// Create an instruction list that contains the default next-node
// iteration
final InstructionList ilLoop = new InstructionList();
ilLoop.append(RETURN);
ilLoop.append(RETURN);
final InstructionHandle ihLoop = ilLoop.getStart();
// Compile default handling of elements (traverse children)
@ -1385,16 +1384,15 @@ for (int i = 0; i < _templates.size(); i++) {
// putting together constituent instruction lists
mainIL.append(body);
// Mark the end of the live range for the "current" variable
current.setEnd(body.getEnd());
// fall through to ilLoop
mainIL.append(ilLoop);
peepHoleOptimization(methodGen);
methodGen.stripAttributes(true);
methodGen.setMaxLocals();
methodGen.setMaxStack();
methodGen.removeNOPs();
classGen.addMethod(methodGen.getMethod());
classGen.addMethod(methodGen);
// Restore original (complete) set of templates for this transformation
_templates = oldTemplates;

View file

@ -323,10 +323,7 @@ final class Number extends Instruction implements Closure {
il.append(new INVOKESPECIAL(index));
il.append(RETURN);
cons.stripAttributes(true);
cons.setMaxLocals();
cons.setMaxStack();
classGen.addMethod(cons.getMethod());
classGen.addMethod(cons);
}
/**
@ -349,7 +346,7 @@ final class Number extends Instruction implements Closure {
ITERATOR_FIELD_SIG);
il.append(ALOAD_0); // 'this' pointer on stack
il.append(new GETFIELD(field));
il.append(new ASTORE(local.getIndex()));
local.setStart(il.append(new ASTORE(local.getIndex())));
matchGen.setIteratorIndex(local.getIndex());
// Get NodeCounter._translet and store locally
@ -361,7 +358,7 @@ final class Number extends Instruction implements Closure {
il.append(ALOAD_0); // 'this' pointer on stack
il.append(new GETFIELD(field));
il.append(new CHECKCAST(cpg.addClass(TRANSLET_CLASS)));
il.append(new ASTORE(local.getIndex()));
local.setStart(il.append(new ASTORE(local.getIndex())));
nodeCounterGen.setTransletIndex(local.getIndex());
// Get NodeCounter._document and store locally
@ -372,7 +369,7 @@ final class Number extends Instruction implements Closure {
il.append(ALOAD_0); // 'this' pointer on stack
il.append(new GETFIELD(field));
// Make sure we have the correct DOM type on the stack!!!
il.append(new ASTORE(local.getIndex()));
local.setStart(il.append(new ASTORE(local.getIndex())));
matchGen.setDomIndex(local.getIndex());
}
@ -436,11 +433,7 @@ final class Number extends Instruction implements Closure {
_from.synthesize(nodeCounterGen, matchGen);
il.append(IRETURN);
matchGen.stripAttributes(true);
matchGen.setMaxLocals();
matchGen.setMaxStack();
matchGen.removeNOPs();
nodeCounterGen.addMethod(matchGen.getMethod());
nodeCounterGen.addMethod(matchGen);
}
/*
@ -467,11 +460,7 @@ final class Number extends Instruction implements Closure {
il.append(IRETURN);
matchGen.stripAttributes(true);
matchGen.setMaxLocals();
matchGen.setMaxStack();
matchGen.removeNOPs();
nodeCounterGen.addMethod(matchGen.getMethod());
nodeCounterGen.addMethod(matchGen);
}
getXSLTC().dumpClass(nodeCounterGen.getJavaClass());

View file

@ -1,663 +0,0 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 2001-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: ObjectFactory.java,v 1.2.4.1 2005/09/12 10:51:22 pvedula Exp $
*/
package com.sun.org.apache.xalan.internal.xsltc.compiler;
import java.io.InputStream;
import java.io.IOException;
import java.io.File;
import java.io.FileInputStream;
import java.util.Properties;
import java.io.BufferedReader;
import java.io.InputStreamReader;
/**
* This class is duplicated for each JAXP subpackage so keep it in sync.
* It is package private and therefore is not exposed as part of the JAXP
* API.
* <p>
* This code is designed to implement the JAXP 1.1 spec pluggability
* feature and is designed to run on JDK version 1.1 and
* later, and to compile on JDK 1.2 and onward.
* The code also runs both as part of an unbundled jar file and
* when bundled as part of the JDK.
* <p>
* This class was moved from the <code>javax.xml.parsers.ObjectFactory</code>
* class and modified to be used as a general utility for creating objects
* dynamically.
*
* @version $Id: ObjectFactory.java,v 1.9 2008/04/02 00:41:01 joehw Exp $
*/
class ObjectFactory {
//
// Constants
//
// name of default properties file to look for in JDK's jre/lib directory
private static final String DEFAULT_PROPERTIES_FILENAME =
"xalan.properties";
private static final String SERVICES_PATH = "META-INF/services/";
/** Set to true for debugging */
private static final boolean DEBUG = false;
/** cache the contents of the xalan.properties file.
* Until an attempt has been made to read this file, this will
* be null; if the file does not exist or we encounter some other error
* during the read, this will be empty.
*/
private static Properties fXalanProperties = null;
/***
* Cache the time stamp of the xalan.properties file so
* that we know if it's been modified and can invalidate
* the cache when necessary.
*/
private static long fLastModified = -1;
//
// Public static methods
//
/**
* Finds the implementation Class object in the specified order. The
* specified order is the following:
* <ol>
* <li>query the system property using <code>System.getProperty</code>
* <li>read <code>META-INF/services/<i>factoryId</i></code> file
* <li>use fallback classname
* </ol>
*
* @return instance of factory, never null
*
* @param factoryId Name of the factory to find, same as
* a property name
* @param fallbackClassName Implementation class name, if nothing else
* is found. Use null to mean no fallback.
*
* @exception ObjectFactory.ConfigurationError
*/
static Object createObject(String factoryId, String fallbackClassName)
throws ConfigurationError {
return createObject(factoryId, null, fallbackClassName);
} // createObject(String,String):Object
/**
* Finds the implementation Class object in the specified order. The
* specified order is the following:
* <ol>
* <li>query the system property using <code>System.getProperty</code>
* <li>read <code>$java.home/lib/<i>propertiesFilename</i></code> file
* <li>read <code>META-INF/services/<i>factoryId</i></code> file
* <li>use fallback classname
* </ol>
*
* @return instance of factory, never null
*
* @param factoryId Name of the factory to find, same as
* a property name
* @param propertiesFilename The filename in the $java.home/lib directory
* of the properties file. If none specified,
* ${java.home}/lib/xalan.properties will be used.
* @param fallbackClassName Implementation class name, if nothing else
* is found. Use null to mean no fallback.
*
* @exception ObjectFactory.ConfigurationError
*/
static Object createObject(String factoryId,
String propertiesFilename,
String fallbackClassName)
throws ConfigurationError
{
Class factoryClass = lookUpFactoryClass(factoryId,
propertiesFilename,
fallbackClassName);
if (factoryClass == null) {
throw new ConfigurationError(
"Provider for " + factoryId + " cannot be found", null);
}
try{
Object instance = factoryClass.newInstance();
if (DEBUG) debugPrintln("created new instance of factory " + factoryId);
return instance;
} catch (Exception x) {
throw new ConfigurationError(
"Provider for factory " + factoryId
+ " could not be instantiated: " + x, x);
}
} // createObject(String,String,String):Object
/**
* Finds the implementation Class object in the specified order. The
* specified order is the following:
* <ol>
* <li>query the system property using <code>System.getProperty</code>
* <li>read <code>$java.home/lib/<i>propertiesFilename</i></code> file
* <li>read <code>META-INF/services/<i>factoryId</i></code> file
* <li>use fallback classname
* </ol>
*
* @return Class object of factory, never null
*
* @param factoryId Name of the factory to find, same as
* a property name
* @param propertiesFilename The filename in the $java.home/lib directory
* of the properties file. If none specified,
* ${java.home}/lib/xalan.properties will be used.
* @param fallbackClassName Implementation class name, if nothing else
* is found. Use null to mean no fallback.
*
* @exception ObjectFactory.ConfigurationError
*/
static Class lookUpFactoryClass(String factoryId)
throws ConfigurationError
{
return lookUpFactoryClass(factoryId, null, null);
} // lookUpFactoryClass(String):Class
/**
* Finds the implementation Class object in the specified order. The
* specified order is the following:
* <ol>
* <li>query the system property using <code>System.getProperty</code>
* <li>read <code>$java.home/lib/<i>propertiesFilename</i></code> file
* <li>read <code>META-INF/services/<i>factoryId</i></code> file
* <li>use fallback classname
* </ol>
*
* @return Class object that provides factory service, never null
*
* @param factoryId Name of the factory to find, same as
* a property name
* @param propertiesFilename The filename in the $java.home/lib directory
* of the properties file. If none specified,
* ${java.home}/lib/xalan.properties will be used.
* @param fallbackClassName Implementation class name, if nothing else
* is found. Use null to mean no fallback.
*
* @exception ObjectFactory.ConfigurationError
*/
static Class lookUpFactoryClass(String factoryId,
String propertiesFilename,
String fallbackClassName)
throws ConfigurationError
{
String factoryClassName = lookUpFactoryClassName(factoryId,
propertiesFilename,
fallbackClassName);
ClassLoader cl = findClassLoader();
if (factoryClassName == null) {
factoryClassName = fallbackClassName;
}
// assert(className != null);
try{
Class providerClass = findProviderClass(factoryClassName,
cl,
true);
if (DEBUG) debugPrintln("created new instance of " + providerClass +
" using ClassLoader: " + cl);
return providerClass;
} catch (ClassNotFoundException x) {
throw new ConfigurationError(
"Provider " + factoryClassName + " not found", x);
} catch (Exception x) {
throw new ConfigurationError(
"Provider "+factoryClassName+" could not be instantiated: "+x,
x);
}
} // lookUpFactoryClass(String,String,String):Class
/**
* Finds the name of the required implementation class in the specified
* order. The specified order is the following:
* <ol>
* <li>query the system property using <code>System.getProperty</code>
* <li>read <code>$java.home/lib/<i>propertiesFilename</i></code> file
* <li>read <code>META-INF/services/<i>factoryId</i></code> file
* <li>use fallback classname
* </ol>
*
* @return name of class that provides factory service, never null
*
* @param factoryId Name of the factory to find, same as
* a property name
* @param propertiesFilename The filename in the $java.home/lib directory
* of the properties file. If none specified,
* ${java.home}/lib/xalan.properties will be used.
* @param fallbackClassName Implementation class name, if nothing else
* is found. Use null to mean no fallback.
*
* @exception ObjectFactory.ConfigurationError
*/
static String lookUpFactoryClassName(String factoryId,
String propertiesFilename,
String fallbackClassName)
{
SecuritySupport ss = SecuritySupport.getInstance();
// Use the system property first
try {
String systemProp = ss.getSystemProperty(factoryId);
if (systemProp != null) {
if (DEBUG) debugPrintln("found system property, value=" + systemProp);
return systemProp;
}
} catch (SecurityException se) {
// Ignore and continue w/ next location
}
// Try to read from propertiesFilename, or
// $java.home/lib/xalan.properties
String factoryClassName = null;
// no properties file name specified; use
// $JAVA_HOME/lib/xalan.properties:
if (propertiesFilename == null) {
File propertiesFile = null;
boolean propertiesFileExists = false;
try {
String javah = ss.getSystemProperty("java.home");
propertiesFilename = javah + File.separator +
"lib" + File.separator + DEFAULT_PROPERTIES_FILENAME;
propertiesFile = new File(propertiesFilename);
propertiesFileExists = ss.getFileExists(propertiesFile);
} catch (SecurityException e) {
// try again...
fLastModified = -1;
fXalanProperties = null;
}
synchronized (ObjectFactory.class) {
boolean loadProperties = false;
FileInputStream fis = null;
try {
// file existed last time
if(fLastModified >= 0) {
if(propertiesFileExists &&
(fLastModified < (fLastModified = ss.getLastModified(propertiesFile)))) {
loadProperties = true;
} else {
// file has stopped existing...
if(!propertiesFileExists) {
fLastModified = -1;
fXalanProperties = null;
} // else, file wasn't modified!
}
} else {
// file has started to exist:
if(propertiesFileExists) {
loadProperties = true;
fLastModified = ss.getLastModified(propertiesFile);
} // else, nothing's changed
}
if(loadProperties) {
// must never have attempted to read xalan.properties
// before (or it's outdeated)
fXalanProperties = new Properties();
fis = ss.getFileInputStream(propertiesFile);
fXalanProperties.load(fis);
}
} catch (Exception x) {
fXalanProperties = null;
fLastModified = -1;
// assert(x instanceof FileNotFoundException
// || x instanceof SecurityException)
// In both cases, ignore and continue w/ next location
}
finally {
// try to close the input stream if one was opened.
if (fis != null) {
try {
fis.close();
}
// Ignore the exception.
catch (IOException exc) {}
}
}
}
if(fXalanProperties != null) {
factoryClassName = fXalanProperties.getProperty(factoryId);
}
} else {
FileInputStream fis = null;
try {
fis = ss.getFileInputStream(new File(propertiesFilename));
Properties props = new Properties();
props.load(fis);
factoryClassName = props.getProperty(factoryId);
} catch (Exception x) {
// assert(x instanceof FileNotFoundException
// || x instanceof SecurityException)
// In both cases, ignore and continue w/ next location
}
finally {
// try to close the input stream if one was opened.
if (fis != null) {
try {
fis.close();
}
// Ignore the exception.
catch (IOException exc) {}
}
}
}
if (factoryClassName != null) {
if (DEBUG) debugPrintln("found in " + propertiesFilename + ", value="
+ factoryClassName);
return factoryClassName;
}
// Try Jar Service Provider Mechanism
return findJarServiceProviderName(factoryId);
} // lookUpFactoryClass(String,String):String
//
// Private static methods
//
/** Prints a message to standard error if debugging is enabled. */
private static void debugPrintln(String msg) {
if (DEBUG) {
System.err.println("JAXP: " + msg);
}
} // debugPrintln(String)
/**
* Figure out which ClassLoader to use. For JDK 1.2 and later use
* the context ClassLoader.
*/
static ClassLoader findClassLoader()
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 context = ss.getContextClassLoader();
ClassLoader system = ss.getSystemClassLoader();
ClassLoader chain = system;
while (true) {
if (context == chain) {
// Assert: we are on JDK 1.1 or we have no Context ClassLoader
// or any Context ClassLoader in chain of system classloader
// (including extension ClassLoader) so extend to widest
// ClassLoader (always look in system ClassLoader if Xalan
// is in boot/extension/system classpath and in current
// ClassLoader otherwise); normal classloaders delegate
// back to system ClassLoader first so this widening doesn't
// change the fact that context ClassLoader will be consulted
ClassLoader current = ObjectFactory.class.getClassLoader();
chain = system;
while (true) {
if (current == chain) {
// Assert: Current ClassLoader in chain of
// boot/extension/system ClassLoaders
return system;
}
if (chain == null) {
break;
}
chain = ss.getParentClassLoader(chain);
}
// Assert: Current ClassLoader not in chain of
// boot/extension/system ClassLoaders
return current;
}
if (chain == null) {
// boot ClassLoader reached
break;
}
// Check for any extension ClassLoaders in chain up to
// boot ClassLoader
chain = ss.getParentClassLoader(chain);
};
// Assert: Context ClassLoader not in chain of
// boot/extension/system ClassLoaders
return context;
} // findClassLoader():ClassLoader
/**
* Create an instance of a class using the specified ClassLoader
*/
static Object newInstance(String className, ClassLoader cl,
boolean doFallback)
throws ConfigurationError
{
// assert(className != null);
try{
Class providerClass = findProviderClass(className, cl, doFallback);
Object instance = providerClass.newInstance();
if (DEBUG) debugPrintln("created new instance of " + providerClass +
" using ClassLoader: " + cl);
return instance;
} catch (ClassNotFoundException x) {
throw new ConfigurationError(
"Provider " + className + " not found", x);
} catch (Exception x) {
throw new ConfigurationError(
"Provider " + className + " could not be instantiated: " + x,
x);
}
}
/**
* Find a Class using the specified ClassLoader
*/
static Class findProviderClass(String className, ClassLoader cl,
boolean doFallback)
throws ClassNotFoundException, ConfigurationError
{
//throw security exception if the calling thread is not allowed to access the
//class. Restrict the access to the package classes as specified in java.security policy.
SecurityManager security = System.getSecurityManager();
try{
if (security != null){
final int lastDot = className.lastIndexOf(".");
String packageName = className;
if (lastDot != -1) packageName = className.substring(0, lastDot);
security.checkPackageAccess(packageName);
}
}catch(SecurityException e){
throw e;
}
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);
} else {
try {
providerClass = cl.loadClass(className);
} catch (ClassNotFoundException x) {
if (doFallback) {
// Fall back to current classloader
ClassLoader current = ObjectFactory.class.getClassLoader();
if (current == null) {
providerClass = Class.forName(className);
} else if (cl != current) {
cl = current;
providerClass = cl.loadClass(className);
} else {
throw x;
}
} else {
throw x;
}
}
}
return providerClass;
}
/**
* Find the name of service provider using Jar Service Provider Mechanism
*
* @return instance of provider class if found or null
*/
private static String findJarServiceProviderName(String factoryId)
{
SecuritySupport ss = SecuritySupport.getInstance();
String serviceId = SERVICES_PATH + factoryId;
InputStream is = null;
// First try the Context ClassLoader
ClassLoader cl = findClassLoader();
is = ss.getResourceAsStream(cl, serviceId);
// If no provider found then try the current ClassLoader
if (is == null) {
ClassLoader current = ObjectFactory.class.getClassLoader();
if (cl != current) {
cl = current;
is = ss.getResourceAsStream(cl, serviceId);
}
}
if (is == null) {
// No provider found
return null;
}
if (DEBUG) debugPrintln("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 {
rd = new BufferedReader(new InputStreamReader(is, "UTF-8"));
} catch (java.io.UnsupportedEncodingException e) {
rd = new BufferedReader(new InputStreamReader(is));
}
String factoryClassName = null;
try {
// XXX Does not handle all possible input as specified by the
// Jar Service Provider specification
factoryClassName = rd.readLine();
} catch (IOException x) {
// No provider found
return null;
}
finally {
try {
// try to close the reader.
rd.close();
}
// Ignore the exception.
catch (IOException exc) {}
}
if (factoryClassName != null &&
! "".equals(factoryClassName)) {
if (DEBUG) debugPrintln("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 factoryClassName;
}
// No provider found
return null;
}
//
// Classes
//
/**
* A configuration error.
*/
static class ConfigurationError
extends Error {
static final long serialVersionUID = 3326843611085065902L;
//
// Data
//
/** Exception. */
private Exception exception;
//
// Constructors
//
/**
* Construct a new instance with the specified detail string and
* exception.
*/
ConfigurationError(String msg, Exception x) {
super(msg);
this.exception = x;
} // <init>(String,Exception)
//
// Public methods
//
/** Returns the exception associated to this error. */
Exception getException() {
return exception;
} // getException():Exception
} // class ConfigurationError
} // class ObjectFactory

View file

@ -84,12 +84,10 @@ final class ParameterRef extends VariableRefBase {
}
else {
il.append(_variable.loadInstruction());
_variable.removeReference(this);
}
}
else {
il.append(_variable.loadInstruction());
_variable.removeReference(this);
}
}
else {

View file

@ -190,15 +190,15 @@ final class ParentLocationPath extends RelativeLocationPath {
LocalVariableGen pathTemp
= methodGen.addLocalVariable("parent_location_path_tmp1",
Util.getJCRefType(NODE_ITERATOR_SIG),
il.getEnd(), null);
il.append(new ASTORE(pathTemp.getIndex()));
null, null);
pathTemp.setStart(il.append(new ASTORE(pathTemp.getIndex())));
_step.translate(classGen, methodGen);
LocalVariableGen stepTemp
= methodGen.addLocalVariable("parent_location_path_tmp2",
Util.getJCRefType(NODE_ITERATOR_SIG),
il.getEnd(), null);
il.append(new ASTORE(stepTemp.getIndex()));
null, null);
stepTemp.setStart(il.append(new ASTORE(stepTemp.getIndex())));
// Create new StepIterator
final int initSI = cpg.addMethodref(STEP_ITERATOR_CLASS,
@ -210,8 +210,8 @@ final class ParentLocationPath extends RelativeLocationPath {
il.append(new NEW(cpg.addClass(STEP_ITERATOR_CLASS)));
il.append(DUP);
il.append(new ALOAD(pathTemp.getIndex()));
il.append(new ALOAD(stepTemp.getIndex()));
pathTemp.setEnd(il.append(new ALOAD(pathTemp.getIndex())));
stepTemp.setEnd(il.append(new ALOAD(stepTemp.getIndex())));
// Initialize StepIterator with iterators from the stack
il.append(new INVOKESPECIAL(initSI));

View file

@ -27,6 +27,7 @@ import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen;
import com.sun.org.apache.bcel.internal.generic.ILOAD;
import com.sun.org.apache.bcel.internal.generic.INVOKEINTERFACE;
import com.sun.org.apache.bcel.internal.generic.ISTORE;
import com.sun.org.apache.bcel.internal.generic.InstructionHandle;
import com.sun.org.apache.bcel.internal.generic.InstructionList;
import com.sun.org.apache.bcel.internal.generic.LocalVariableGen;
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator;
@ -77,7 +78,7 @@ final class ParentPattern extends RelativePathPattern {
final LocalVariableGen local =
methodGen.addLocalVariable2("ppt",
Util.getJCRefType(NODE_SIG),
il.getEnd());
null);
final com.sun.org.apache.bcel.internal.generic.Instruction loadLocal =
new ILOAD(local.getIndex());
@ -90,7 +91,7 @@ final class ParentPattern extends RelativePathPattern {
}
else if (_right instanceof StepPattern) {
il.append(DUP);
il.append(storeLocal);
local.setStart(il.append(storeLocal));
_right.translate(classGen, methodGen);
@ -119,7 +120,11 @@ final class ParentPattern extends RelativePathPattern {
}
else {
il.append(DUP);
il.append(storeLocal);
InstructionHandle storeInst = il.append(storeLocal);
if (local.getStart() == null) {
local.setStart(storeInst);
}
_left.translate(classGen, methodGen);

View file

@ -44,6 +44,8 @@ import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg;
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodType;
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type;
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError;
import com.sun.org.apache.xalan.internal.utils.FactoryImpl;
import com.sun.org.apache.xalan.internal.utils.ObjectFactory;
import org.xml.sax.Attributes;
import org.xml.sax.helpers.AttributesImpl;
import org.xml.sax.ContentHandler;
@ -93,8 +95,11 @@ public class Parser implements Constants, ContentHandler {
private int _currentImportPrecedence;
public Parser(XSLTC xsltc) {
private boolean _useServicesMechanism = true;
public Parser(XSLTC xsltc, boolean useServicesMechanism) {
_xsltc = xsltc;
_useServicesMechanism = useServicesMechanism;
}
public void init() {
@ -306,17 +311,22 @@ public class Parser implements Constants, ContentHandler {
}
else {
Dictionary space = (Dictionary)_namespaces.get(namespace);
String lexicalQName =
(prefix == null || prefix.length() == 0)
? localname
: (prefix + ':' + localname);
if (space == null) {
final QName name = new QName(namespace, prefix, localname);
_namespaces.put(namespace, space = new Hashtable());
space.put(localname, name);
space.put(lexicalQName, name);
return name;
}
else {
QName name = (QName)space.get(localname);
QName name = (QName)space.get(lexicalQName);
if (name == null) {
name = new QName(namespace, prefix, localname);
space.put(localname, name);
space.put(lexicalQName, name);
}
return name;
}
@ -449,7 +459,7 @@ public class Parser implements Constants, ContentHandler {
public SyntaxTreeNode parse(InputSource input) {
try {
// Create a SAX parser and get the XMLReader object it uses
final SAXParserFactory factory = SAXParserFactory.newInstance();
final SAXParserFactory factory = FactoryImpl.getSAXFactory(_useServicesMechanism);
if (_xsltc.isSecureProcessing()) {
try {
@ -918,8 +928,7 @@ public class Parser implements Constants, ContentHandler {
if (className != null) {
try {
final Class clazz = ObjectFactory.findProviderClass(
className, ObjectFactory.findClassLoader(), true);
final Class clazz = ObjectFactory.findProviderClass(className, true);
node = (SyntaxTreeNode)clazz.newInstance();
node.setQName(qname);
node.setParser(this);
@ -1273,7 +1282,7 @@ public class Parser implements Constants, ContentHandler {
// handled at this point in order to correctly generate
// Fallback elements from <xsl:fallback>s.
getSymbolTable().setCurrentNode(element);
((Stylesheet)element).excludeExtensionPrefixes(this);
((Stylesheet)element).declareExtensionPrefixes(this);
}
_prefixMapping = null;

View file

@ -412,7 +412,7 @@ final class Predicate extends Expression implements Closure {
il.append(new CHECKCAST(cpg.addClass(className)));
il.append(new GETFIELD(cpg.addFieldref(className,
DOM_FIELD, DOM_INTF_SIG)));
il.append(new ASTORE(local.getIndex()));
local.setStart(il.append(new ASTORE(local.getIndex())));
// Store the dom index in the test generator
testGen.setDomIndex(local.getIndex());
@ -420,12 +420,8 @@ final class Predicate extends Expression implements Closure {
_exp.translate(filterGen, testGen);
il.append(IRETURN);
testGen.stripAttributes(true);
testGen.setMaxLocals();
testGen.setMaxStack();
testGen.removeNOPs();
filterGen.addEmptyConstructor(ACC_PUBLIC);
filterGen.addMethod(testGen.getMethod());
filterGen.addMethod(testGen);
getXSLTC().dumpClass(filterGen.getJavaClass());
}

View file

@ -83,13 +83,14 @@ final class ProcessingInstruction extends Instruction {
if (!_isLiteral) {
// if the ncname is an AVT, then the ncname has to be checked at runtime if it is a valid ncname
LocalVariableGen nameValue = methodGen.addLocalVariable2("nameValue",
LocalVariableGen nameValue =
methodGen.addLocalVariable2("nameValue",
Util.getJCRefType(STRING_SIG),
il.getEnd());
null);
// store the name into a variable first so _name.translate only needs to be called once
_name.translate(classGen, methodGen);
il.append(new ASTORE(nameValue.getIndex()));
nameValue.setStart(il.append(new ASTORE(nameValue.getIndex())));
il.append(new ALOAD(nameValue.getIndex()));
// call checkNCName if the name is an AVT
@ -104,7 +105,7 @@ final class ProcessingInstruction extends Instruction {
il.append(DUP); // first arg to "attributes" call
// load name value again
il.append(new ALOAD(nameValue.getIndex()));
nameValue.setEnd(il.append(new ALOAD(nameValue.getIndex())));
} else {
// Save the current handler base on the stack
il.append(methodGen.loadHandler());

View file

@ -1,127 +0,0 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 2002-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: SecuritySupport.java,v 1.2.4.1 2005/09/05 08:57:13 pvedula Exp $
*/
package com.sun.org.apache.xalan.internal.xsltc.compiler;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.Properties;
/**
* This class is duplicated for each Xalan-Java subpackage so keep it in sync.
* It is package private and therefore is not exposed as part of the Xalan-Java
* 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.
*/
static SecuritySupport getInstance() {
return (SecuritySupport)securitySupport;
}
ClassLoader getContextClassLoader() {
return null;
}
ClassLoader getSystemClassLoader() {
return null;
}
ClassLoader getParentClassLoader(ClassLoader cl) {
return null;
}
String getSystemProperty(String propName) {
return System.getProperty(propName);
}
FileInputStream getFileInputStream(File file)
throws FileNotFoundException
{
return new FileInputStream(file);
}
InputStream getResourceAsStream(ClassLoader cl, String name) {
InputStream ris;
if (cl == null) {
ris = ClassLoader.getSystemResourceAsStream(name);
} else {
ris = cl.getResourceAsStream(name);
}
return ris;
}
boolean getFileExists(File f) {
return f.exists();
}
long getLastModified(File f) {
return f.lastModified();
}
}

View file

@ -1,148 +0,0 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 2002-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: SecuritySupport12.java,v 1.2.4.1 2005/09/05 08:58:02 pvedula Exp $
*/
package com.sun.org.apache.xalan.internal.xsltc.compiler;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.util.Properties;
/**
* This class is duplicated for each Xalan-Java subpackage so keep it in sync.
* It is package private and therefore is not exposed as part of the Xalan-Java
* API.
*
* Security related methods that only work on J2SE 1.2 and newer.
*/
class SecuritySupport12 extends SecuritySupport {
ClassLoader getContextClassLoader() {
return (ClassLoader)
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
ClassLoader cl = null;
try {
cl = Thread.currentThread().getContextClassLoader();
} catch (SecurityException ex) { }
return cl;
}
});
}
ClassLoader getSystemClassLoader() {
return (ClassLoader)
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
ClassLoader cl = null;
try {
cl = ClassLoader.getSystemClassLoader();
} catch (SecurityException ex) {}
return cl;
}
});
}
ClassLoader getParentClassLoader(final ClassLoader cl) {
return (ClassLoader)
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
ClassLoader parent = null;
try {
parent = cl.getParent();
} catch (SecurityException ex) {}
// eliminate loops in case of the boot
// ClassLoader returning itself as a parent
return (parent == cl) ? null : parent;
}
});
}
String getSystemProperty(final String propName) {
return (String)
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
return System.getProperty(propName);
}
});
}
FileInputStream getFileInputStream(final File file)
throws FileNotFoundException
{
try {
return (FileInputStream)
AccessController.doPrivileged(new PrivilegedExceptionAction() {
public Object run() throws FileNotFoundException {
return new FileInputStream(file);
}
});
} catch (PrivilegedActionException e) {
throw (FileNotFoundException)e.getException();
}
}
InputStream getResourceAsStream(final ClassLoader cl,
final String name)
{
return (InputStream)
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
InputStream ris;
if (cl == null) {
ris = ClassLoader.getSystemResourceAsStream(name);
} else {
ris = cl.getResourceAsStream(name);
}
return ris;
}
});
}
boolean getFileExists(final File f) {
return ((Boolean)
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
return new Boolean(f.exists());
}
})).booleanValue();
}
long getLastModified(final File f) {
return ((Long)
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
return new Long(f.lastModified());
}
})).longValue();
}
}

View file

@ -270,12 +270,12 @@ final class Sort extends Instruction implements Closure {
LocalVariableGen nodesTemp =
methodGen.addLocalVariable("sort_tmp1",
Util.getJCRefType(NODE_ITERATOR_SIG),
il.getEnd(), null);
null, null);
LocalVariableGen sortRecordFactoryTemp =
methodGen.addLocalVariable("sort_tmp2",
Util.getJCRefType(NODE_SORT_FACTORY_SIG),
il.getEnd(), null);
null, null);
// Get the current node iterator
if (nodeSet == null) { // apply-templates default
@ -291,17 +291,19 @@ final class Sort extends Instruction implements Closure {
nodeSet.translate(classGen, methodGen);
}
il.append(new ASTORE(nodesTemp.getIndex()));
nodesTemp.setStart(il.append(new ASTORE(nodesTemp.getIndex())));
// Compile the code for the NodeSortRecord producing class and pass
// that as the last argument to the SortingIterator constructor.
compileSortRecordFactory(sortObjects, classGen, methodGen);
il.append(new ASTORE(sortRecordFactoryTemp.getIndex()));
sortRecordFactoryTemp.setStart(
il.append(new ASTORE(sortRecordFactoryTemp.getIndex())));
il.append(new NEW(cpg.addClass(SORT_ITERATOR)));
il.append(DUP);
il.append(new ALOAD(nodesTemp.getIndex()));
il.append(new ALOAD(sortRecordFactoryTemp.getIndex()));
nodesTemp.setEnd(il.append(new ALOAD(nodesTemp.getIndex())));
sortRecordFactoryTemp.setEnd(
il.append(new ALOAD(sortRecordFactoryTemp.getIndex())));
il.append(new INVOKESPECIAL(init));
}
@ -346,7 +348,7 @@ final class Sort extends Instruction implements Closure {
LocalVariableGen sortOrderTemp
= methodGen.addLocalVariable("sort_order_tmp",
Util.getJCRefType("[" + STRING_SIG),
il.getEnd(), null);
null, null);
il.append(new PUSH(cpg, nsorts));
il.append(new ANEWARRAY(cpg.addClass(STRING)));
for (int level = 0; level < nsorts; level++) {
@ -356,12 +358,12 @@ final class Sort extends Instruction implements Closure {
sort.translateSortOrder(classGen, methodGen);
il.append(AASTORE);
}
il.append(new ASTORE(sortOrderTemp.getIndex()));
sortOrderTemp.setStart(il.append(new ASTORE(sortOrderTemp.getIndex())));
LocalVariableGen sortTypeTemp
= methodGen.addLocalVariable("sort_type_tmp",
Util.getJCRefType("[" + STRING_SIG),
il.getEnd(), null);
null, null);
il.append(new PUSH(cpg, nsorts));
il.append(new ANEWARRAY(cpg.addClass(STRING)));
for (int level = 0; level < nsorts; level++) {
@ -371,12 +373,12 @@ final class Sort extends Instruction implements Closure {
sort.translateSortType(classGen, methodGen);
il.append(AASTORE);
}
il.append(new ASTORE(sortTypeTemp.getIndex()));
sortTypeTemp.setStart(il.append(new ASTORE(sortTypeTemp.getIndex())));
LocalVariableGen sortLangTemp
= methodGen.addLocalVariable("sort_lang_tmp",
Util.getJCRefType("[" + STRING_SIG),
il.getEnd(), null);
null, null);
il.append(new PUSH(cpg, nsorts));
il.append(new ANEWARRAY(cpg.addClass(STRING)));
for (int level = 0; level < nsorts; level++) {
@ -386,12 +388,12 @@ final class Sort extends Instruction implements Closure {
sort.translateLang(classGen, methodGen);
il.append(AASTORE);
}
il.append(new ASTORE(sortLangTemp.getIndex()));
sortLangTemp.setStart(il.append(new ASTORE(sortLangTemp.getIndex())));
LocalVariableGen sortCaseOrderTemp
= methodGen.addLocalVariable("sort_case_order_tmp",
Util.getJCRefType("[" + STRING_SIG),
il.getEnd(), null);
null, null);
il.append(new PUSH(cpg, nsorts));
il.append(new ANEWARRAY(cpg.addClass(STRING)));
for (int level = 0; level < nsorts; level++) {
@ -401,7 +403,8 @@ final class Sort extends Instruction implements Closure {
sort.translateCaseOrder(classGen, methodGen);
il.append(AASTORE);
}
il.append(new ASTORE(sortCaseOrderTemp.getIndex()));
sortCaseOrderTemp.setStart(
il.append(new ASTORE(sortCaseOrderTemp.getIndex())));
il.append(new NEW(cpg.addClass(sortRecordFactoryClass)));
il.append(DUP);
@ -409,10 +412,11 @@ final class Sort extends Instruction implements Closure {
il.append(new PUSH(cpg, sortRecordClass));
il.append(classGen.loadTranslet());
il.append(new ALOAD(sortOrderTemp.getIndex()));
il.append(new ALOAD(sortTypeTemp.getIndex()));
il.append(new ALOAD(sortLangTemp.getIndex()));
il.append(new ALOAD(sortCaseOrderTemp.getIndex()));
sortOrderTemp.setEnd(il.append(new ALOAD(sortOrderTemp.getIndex())));
sortTypeTemp.setEnd(il.append(new ALOAD(sortTypeTemp.getIndex())));
sortLangTemp.setEnd(il.append(new ALOAD(sortLangTemp.getIndex())));
sortCaseOrderTemp.setEnd(
il.append(new ALOAD(sortCaseOrderTemp.getIndex())));
il.append(new INVOKESPECIAL(
cpg.addMethodref(sortRecordFactoryClass, "<init>",
@ -584,10 +588,10 @@ final class Sort extends Instruction implements Closure {
constructor.setMaxLocals();
constructor.setMaxStack();
sortRecordFactory.addMethod(constructor.getMethod());
sortRecordFactory.addMethod(constructor);
makeNodeSortRecord.setMaxLocals();
makeNodeSortRecord.setMaxStack();
sortRecordFactory.addMethod(makeNodeSortRecord.getMethod());
sortRecordFactory.addMethod(makeNodeSortRecord);
xsltc.dumpClass(sortRecordFactory.getJavaClass());
return className;
@ -640,9 +644,9 @@ final class Sort extends Instruction implements Closure {
}
}
Method init = compileInit(sortObjects, sortRecord,
MethodGenerator init = compileInit(sortObjects, sortRecord,
cpg, className);
Method extract = compileExtract(sortObjects, sortRecord,
MethodGenerator extract = compileExtract(sortObjects, sortRecord,
cpg, className);
sortRecord.addMethod(init);
sortRecord.addMethod(extract);
@ -656,7 +660,7 @@ final class Sort extends Instruction implements Closure {
* collator in the super calls only when the stylesheet specifies a new
* language in xsl:sort.
*/
private static Method compileInit(Vector sortObjects,
private static MethodGenerator compileInit(Vector sortObjects,
NodeSortRecordGenerator sortRecord,
ConstantPoolGen cpg,
String className)
@ -677,18 +681,14 @@ final class Sort extends Instruction implements Closure {
il.append(RETURN);
init.stripAttributes(true);
init.setMaxLocals();
init.setMaxStack();
return init.getMethod();
return init;
}
/**
* Compiles a method that overloads NodeSortRecord.extractValueFromDOM()
*/
private static Method compileExtract(Vector sortObjects,
private static MethodGenerator compileExtract(Vector sortObjects,
NodeSortRecordGenerator sortRecord,
ConstantPoolGen cpg,
String className) {
@ -745,11 +745,6 @@ final class Sort extends Instruction implements Closure {
il.append(ARETURN);
}
extractMethod.stripAttributes(true);
extractMethod.setMaxLocals();
extractMethod.setMaxStack();
extractMethod.removeNOPs();
return extractMethod.getMethod();
return extractMethod;
}
}

View file

@ -447,20 +447,24 @@ final class Step extends RelativeLocationPath {
LocalVariableGen iteratorTemp
= methodGen.addLocalVariable("step_tmp1",
Util.getJCRefType(NODE_ITERATOR_SIG),
il.getEnd(), null);
il.append(new ASTORE(iteratorTemp.getIndex()));
null, null);
iteratorTemp.setStart(
il.append(new ASTORE(iteratorTemp.getIndex())));
predicate.translate(classGen, methodGen);
LocalVariableGen predicateValueTemp
= methodGen.addLocalVariable("step_tmp2",
Util.getJCRefType("I"),
il.getEnd(), null);
il.append(new ISTORE(predicateValueTemp.getIndex()));
null, null);
predicateValueTemp.setStart(
il.append(new ISTORE(predicateValueTemp.getIndex())));
il.append(new NEW(cpg.addClass(NTH_ITERATOR_CLASS)));
il.append(DUP);
il.append(new ALOAD(iteratorTemp.getIndex()));
il.append(new ILOAD(predicateValueTemp.getIndex()));
iteratorTemp.setEnd(
il.append(new ALOAD(iteratorTemp.getIndex())));
predicateValueTemp.setEnd(
il.append(new ILOAD(predicateValueTemp.getIndex())));
il.append(new INVOKESPECIAL(idx));
}
else {
@ -486,22 +490,24 @@ final class Step extends RelativeLocationPath {
LocalVariableGen iteratorTemp
= methodGen.addLocalVariable("step_tmp1",
Util.getJCRefType(NODE_ITERATOR_SIG),
il.getEnd(), null);
il.append(new ASTORE(iteratorTemp.getIndex()));
null, null);
iteratorTemp.setStart(
il.append(new ASTORE(iteratorTemp.getIndex())));
predicate.translateFilter(classGen, methodGen);
LocalVariableGen filterTemp
= methodGen.addLocalVariable("step_tmp2",
Util.getJCRefType(CURRENT_NODE_LIST_FILTER_SIG),
il.getEnd(), null);
il.append(new ASTORE(filterTemp.getIndex()));
null, null);
filterTemp.setStart(
il.append(new ASTORE(filterTemp.getIndex())));
// create new CurrentNodeListIterator
il.append(new NEW(cpg.addClass(CURRENT_NODE_LIST_ITERATOR)));
il.append(DUP);
il.append(new ALOAD(iteratorTemp.getIndex()));
il.append(new ALOAD(filterTemp.getIndex()));
iteratorTemp.setEnd(
il.append(new ALOAD(iteratorTemp.getIndex())));
filterTemp.setEnd(il.append(new ALOAD(filterTemp.getIndex())));
il.append(methodGen.loadCurrentNode());
il.append(classGen.loadTranslet());

View file

@ -328,8 +328,8 @@ class StepPattern extends RelativePathPattern {
LocalVariableGen match;
match = methodGen.addLocalVariable("step_pattern_tmp1",
Util.getJCRefType(NODE_SIG),
il.getEnd(), null);
il.append(new ISTORE(match.getIndex()));
null, null);
match.setStart(il.append(new ISTORE(match.getIndex())));
// If pattern not reduced then check kernel
if (!_isEpsilon) {
@ -358,13 +358,15 @@ class StepPattern extends RelativePathPattern {
LocalVariableGen stepIteratorTemp =
methodGen.addLocalVariable("step_pattern_tmp2",
Util.getJCRefType(NODE_ITERATOR_SIG),
il.getEnd(), null);
il.append(new ASTORE(stepIteratorTemp.getIndex()));
null, null);
stepIteratorTemp.setStart(
il.append(new ASTORE(stepIteratorTemp.getIndex())));
il.append(new NEW(cpg.addClass(MATCHING_ITERATOR)));
il.append(DUP);
il.append(new ILOAD(match.getIndex()));
il.append(new ALOAD(stepIteratorTemp.getIndex()));
stepIteratorTemp.setEnd(
il.append(new ALOAD(stepIteratorTemp.getIndex())));
il.append(new INVOKESPECIAL(index));
// Get the parent of the matching node
@ -378,7 +380,7 @@ class StepPattern extends RelativePathPattern {
// Overwrite current iterator and current node
il.append(methodGen.storeIterator());
il.append(new ILOAD(match.getIndex()));
match.setEnd(il.append(new ILOAD(match.getIndex())));
il.append(methodGen.storeCurrentNode());
// Translate the expression of the predicate
@ -415,13 +417,13 @@ class StepPattern extends RelativePathPattern {
// Store node on the stack into a local variable
node = methodGen.addLocalVariable("step_pattern_tmp1",
Util.getJCRefType(NODE_SIG),
il.getEnd(), null);
il.append(new ISTORE(node.getIndex()));
null, null);
node.setStart(il.append(new ISTORE(node.getIndex())));
// Create a new local to store the iterator
iter = methodGen.addLocalVariable("step_pattern_tmp2",
Util.getJCRefType(NODE_ITERATOR_SIG),
il.getEnd(), null);
null, null);
// Add a new private field if this is the main class
if (!classGen.isExternal()) {
@ -438,20 +440,24 @@ class StepPattern extends RelativePathPattern {
il.append(classGen.loadTranslet());
il.append(new GETFIELD(iteratorIndex));
il.append(DUP);
il.append(new ASTORE(iter.getIndex()));
iter.setStart(il.append(new ASTORE(iter.getIndex())));
ifBlock = il.append(new IFNONNULL(null));
il.append(classGen.loadTranslet());
}
// Compile the step created at type checking time
_step.translate(classGen, methodGen);
il.append(new ASTORE(iter.getIndex()));
InstructionHandle iterStore = il.append(new ASTORE(iter.getIndex()));
// If in the main class update the field too
if (!classGen.isExternal()) {
il.append(new ALOAD(iter.getIndex()));
il.append(new PUTFIELD(iteratorIndex));
ifBlock.setTarget(il.append(NOP));
} else {
// If class is not external, start of range for iter variable was
// set above
iter.setStart(iterStore);
}
// Get the parent of the node on the stack
@ -478,10 +484,11 @@ class StepPattern extends RelativePathPattern {
InstructionHandle begin, next;
node2 = methodGen.addLocalVariable("step_pattern_tmp3",
Util.getJCRefType(NODE_SIG),
il.getEnd(), null);
null, null);
skipNext = il.append(new GOTO(null));
next = il.append(new ALOAD(iter.getIndex()));
node2.setStart(next);
begin = il.append(methodGen.nextNode());
il.append(DUP);
il.append(new ISTORE(node2.getIndex()));
@ -489,10 +496,10 @@ class StepPattern extends RelativePathPattern {
il.append(new ILOAD(node2.getIndex()));
il.append(new ILOAD(node.getIndex()));
il.append(new IF_ICMPLT(next));
iter.setEnd(il.append(new IF_ICMPLT(next)));
il.append(new ILOAD(node2.getIndex()));
il.append(new ILOAD(node.getIndex()));
node2.setEnd(il.append(new ILOAD(node2.getIndex())));
node.setEnd(il.append(new ILOAD(node.getIndex())));
_falseList.add(il.append(new IF_ICMPNE(null)));
skipNext.setTarget(begin);

View file

@ -23,9 +23,6 @@
package com.sun.org.apache.xalan.internal.xsltc.compiler;
import java.net.URL;
import java.net.MalformedURLException;
import java.util.Vector;
import java.util.Enumeration;
import java.util.Hashtable;
@ -203,8 +200,9 @@ public final class Stylesheet extends SyntaxTreeNode {
/**
* Set to true to enable template inlining optimization.
* @see XSLTC#_templateInlining
*/
private boolean _templateInlining = true;
private boolean _templateInlining = false;
/**
* A reference to the last xsl:output object found in the styleshet.
@ -467,11 +465,11 @@ public final class Stylesheet extends SyntaxTreeNode {
for (int i = 0; i < n; i++) {
final Template template = (Template)templates.elementAt(i);
if (template.hasParams()) {
_hasLocalParams = new Boolean(true);
_hasLocalParams = Boolean.TRUE;
return true;
}
}
_hasLocalParams = new Boolean(false);
_hasLocalParams = Boolean.FALSE;
return false;
}
else {
@ -509,15 +507,9 @@ public final class Stylesheet extends SyntaxTreeNode {
return (_extensions.get(uri) != null);
}
public void excludeExtensionPrefixes(Parser parser) {
public void declareExtensionPrefixes(Parser parser) {
final SymbolTable stable = parser.getSymbolTable();
final String excludePrefixes = getAttribute("exclude-result-prefixes");
final String extensionPrefixes = getAttribute("extension-element-prefixes");
// Exclude XSLT uri
stable.excludeURI(Constants.XSLT_URI);
stable.excludeNamespaces(excludePrefixes);
stable.excludeNamespaces(extensionPrefixes);
extensionURI(extensionPrefixes, stable);
}
@ -571,6 +563,16 @@ public final class Stylesheet extends SyntaxTreeNode {
* Parse all direct children of the <xsl:stylesheet/> element.
*/
public final void parseOwnChildren(Parser parser) {
final SymbolTable stable = parser.getSymbolTable();
final String excludePrefixes = getAttribute("exclude-result-prefixes");
final String extensionPrefixes = getAttribute("extension-element-prefixes");
// Exclude XSLT uri
stable.pushExcludedNamespacesContext();
stable.excludeURI(Constants.XSLT_URI);
stable.excludeNamespaces(excludePrefixes);
stable.excludeNamespaces(extensionPrefixes);
final Vector contents = getContents();
final int count = contents.size();
@ -602,6 +604,8 @@ public final class Stylesheet extends SyntaxTreeNode {
template.setName(parser.getQName(name));
}
}
stable.popExcludedNamespacesContext();
}
public void processModes() {
@ -801,81 +805,99 @@ public final class Stylesheet extends SyntaxTreeNode {
}
}
staticConst.markChunkStart();
il.append(new PUSH(cpg, size));
il.append(new ANEWARRAY(cpg.addClass(STRING)));
int namesArrayRef = cpg.addFieldref(_className,
STATIC_NAMES_ARRAY_FIELD,
NAMES_INDEX_SIG);
il.append(new PUTSTATIC(namesArrayRef));
staticConst.markChunkEnd();
for (int i = 0; i < size; i++) {
final String name = namesArray[i];
il.append(DUP);
staticConst.markChunkStart();
il.append(new GETSTATIC(namesArrayRef));
il.append(new PUSH(cpg, i));
il.append(new PUSH(cpg, name));
il.append(AASTORE);
staticConst.markChunkEnd();
}
il.append(new PUTSTATIC(cpg.addFieldref(_className,
STATIC_NAMES_ARRAY_FIELD,
NAMES_INDEX_SIG)));
staticConst.markChunkStart();
il.append(new PUSH(cpg, size));
il.append(new ANEWARRAY(cpg.addClass(STRING)));
int urisArrayRef = cpg.addFieldref(_className,
STATIC_URIS_ARRAY_FIELD,
URIS_INDEX_SIG);
il.append(new PUTSTATIC(urisArrayRef));
staticConst.markChunkEnd();
for (int i = 0; i < size; i++) {
final String uri = urisArray[i];
il.append(DUP);
staticConst.markChunkStart();
il.append(new GETSTATIC(urisArrayRef));
il.append(new PUSH(cpg, i));
il.append(new PUSH(cpg, uri));
il.append(AASTORE);
staticConst.markChunkEnd();
}
il.append(new PUTSTATIC(cpg.addFieldref(_className,
STATIC_URIS_ARRAY_FIELD,
URIS_INDEX_SIG)));
staticConst.markChunkStart();
il.append(new PUSH(cpg, size));
il.append(new NEWARRAY(BasicType.INT));
int typesArrayRef = cpg.addFieldref(_className,
STATIC_TYPES_ARRAY_FIELD,
TYPES_INDEX_SIG);
il.append(new PUTSTATIC(typesArrayRef));
staticConst.markChunkEnd();
for (int i = 0; i < size; i++) {
final int nodeType = typesArray[i];
il.append(DUP);
staticConst.markChunkStart();
il.append(new GETSTATIC(typesArrayRef));
il.append(new PUSH(cpg, i));
il.append(new PUSH(cpg, nodeType));
il.append(IASTORE);
}
il.append(new PUTSTATIC(cpg.addFieldref(_className,
STATIC_TYPES_ARRAY_FIELD,
TYPES_INDEX_SIG)));
// Put the namespace names array into the translet
final Vector namespaces = getXSLTC().getNamespaceIndex();
staticConst.markChunkStart();
il.append(new PUSH(cpg, namespaces.size()));
il.append(new ANEWARRAY(cpg.addClass(STRING)));
int namespaceArrayRef = cpg.addFieldref(_className,
STATIC_NAMESPACE_ARRAY_FIELD,
NAMESPACE_INDEX_SIG);
il.append(new PUTSTATIC(namespaceArrayRef));
staticConst.markChunkEnd();
for (int i = 0; i < namespaces.size(); i++) {
final String ns = (String)namespaces.elementAt(i);
il.append(DUP);
staticConst.markChunkStart();
il.append(new GETSTATIC(namespaceArrayRef));
il.append(new PUSH(cpg, i));
il.append(new PUSH(cpg, ns));
il.append(AASTORE);
staticConst.markChunkEnd();
}
il.append(new PUTSTATIC(cpg.addFieldref(_className,
STATIC_NAMESPACE_ARRAY_FIELD,
NAMESPACE_INDEX_SIG)));
// Grab all the literal text in the stylesheet and put it in a char[]
final int charDataCount = getXSLTC().getCharacterDataCount();
final int toCharArray = cpg.addMethodref(STRING, "toCharArray", "()[C");
for (int i = 0; i < charDataCount; i++) {
staticConst.markChunkStart();
il.append(new PUSH(cpg, getXSLTC().getCharacterData(i)));
il.append(new INVOKEVIRTUAL(toCharArray));
il.append(new PUTSTATIC(cpg.addFieldref(_className,
STATIC_CHAR_DATA_FIELD+i,
STATIC_CHAR_DATA_FIELD_SIG)));
staticConst.markChunkEnd();
}
il.append(RETURN);
staticConst.stripAttributes(true);
staticConst.setMaxLocals();
staticConst.setMaxStack();
classGen.addMethod(staticConst.getMethod());
classGen.addMethod(staticConst);
}
@ -898,6 +920,7 @@ public final class Stylesheet extends SyntaxTreeNode {
il.append(new INVOKESPECIAL(cpg.addMethodref(TRANSLET_CLASS,
"<init>", "()V")));
constructor.markChunkStart();
il.append(classGen.loadTranslet());
il.append(new GETSTATIC(cpg.addFieldref(_className,
STATIC_NAMES_ARRAY_FIELD,
@ -913,7 +936,9 @@ public final class Stylesheet extends SyntaxTreeNode {
il.append(new PUTFIELD(cpg.addFieldref(TRANSLET_CLASS,
URIS_INDEX,
URIS_INDEX_SIG)));
constructor.markChunkEnd();
constructor.markChunkStart();
il.append(classGen.loadTranslet());
il.append(new GETSTATIC(cpg.addFieldref(_className,
STATIC_TYPES_ARRAY_FIELD,
@ -921,7 +946,9 @@ public final class Stylesheet extends SyntaxTreeNode {
il.append(new PUTFIELD(cpg.addFieldref(TRANSLET_CLASS,
TYPES_INDEX,
TYPES_INDEX_SIG)));
constructor.markChunkEnd();
constructor.markChunkStart();
il.append(classGen.loadTranslet());
il.append(new GETSTATIC(cpg.addFieldref(_className,
STATIC_NAMESPACE_ARRAY_FIELD,
@ -929,38 +956,45 @@ public final class Stylesheet extends SyntaxTreeNode {
il.append(new PUTFIELD(cpg.addFieldref(TRANSLET_CLASS,
NAMESPACE_INDEX,
NAMESPACE_INDEX_SIG)));
constructor.markChunkEnd();
constructor.markChunkStart();
il.append(classGen.loadTranslet());
il.append(new PUSH(cpg, AbstractTranslet.CURRENT_TRANSLET_VERSION));
il.append(new PUTFIELD(cpg.addFieldref(TRANSLET_CLASS,
TRANSLET_VERSION_INDEX,
TRANSLET_VERSION_INDEX_SIG)));
constructor.markChunkEnd();
if (_hasIdCall) {
constructor.markChunkStart();
il.append(classGen.loadTranslet());
il.append(new PUSH(cpg, Boolean.TRUE));
il.append(new PUTFIELD(cpg.addFieldref(TRANSLET_CLASS,
HASIDCALL_INDEX,
HASIDCALL_INDEX_SIG)));
constructor.markChunkEnd();
}
// Compile in code to set the output configuration from <xsl:output>
if (output != null) {
// Set all the output settings files in the translet
constructor.markChunkStart();
output.translate(classGen, constructor);
constructor.markChunkEnd();
}
// Compile default decimal formatting symbols.
// This is an implicit, nameless xsl:decimal-format top-level element.
if (_numberFormattingUsed)
if (_numberFormattingUsed) {
constructor.markChunkStart();
DecimalFormatting.translateDefaultDFS(classGen, constructor);
constructor.markChunkEnd();
}
il.append(RETURN);
constructor.stripAttributes(true);
constructor.setMaxLocals();
constructor.setMaxStack();
classGen.addMethod(constructor.getMethod());
classGen.addMethod(constructor);
}
/**
@ -1000,25 +1034,23 @@ public final class Stylesheet extends SyntaxTreeNode {
toplevel.addException("com.sun.org.apache.xalan.internal.xsltc.TransletException");
// Define and initialize 'current' variable with the root node
final LocalVariableGen current =
toplevel.addLocalVariable("current",
com.sun.org.apache.bcel.internal.generic.Type.INT,
null, null);
final int setFilter = cpg.addInterfaceMethodref(DOM_INTF,
"setFilter",
"(Lcom/sun/org/apache/xalan/internal/xsltc/StripFilter;)V");
// Define and initialize 'current' variable with the root node
final LocalVariableGen current =
toplevel.addLocalVariable("current",
com.sun.org.apache.bcel.internal.generic.Type.INT,
il.getEnd(), null);
// Get root node from main DOM by calling dom.getIterator().next()
final int gitr = cpg.addInterfaceMethodref(DOM_INTF,
"getIterator", "()"+NODE_ITERATOR_SIG);
final int next = cpg.addInterfaceMethodref(NODE_ITERATOR,
"next", "()I");
"getIterator",
"()"+NODE_ITERATOR_SIG);
il.append(toplevel.loadDOM());
il.append(new INVOKEINTERFACE(gitr, 1));
il.append(new INVOKEINTERFACE(next, 1));
il.append(new ISTORE(current.getIndex()));
il.append(toplevel.nextNode());
current.setStart(il.append(new ISTORE(current.getIndex())));
// Create a new list containing variables/params + keys
Vector varDepElements = new Vector(_globals);
@ -1073,12 +1105,7 @@ public final class Stylesheet extends SyntaxTreeNode {
il.append(RETURN);
// Compute max locals + stack and add method to class
toplevel.stripAttributes(true);
toplevel.setMaxLocals();
toplevel.setMaxStack();
toplevel.removeNOPs();
classGen.addMethod(toplevel.getMethod());
classGen.addMethod(toplevel);
return("("+DOM_INTF_SIG+NODE_ITERATOR_SIG+TRANSLET_OUTPUT_SIG+")V");
}
@ -1233,7 +1260,7 @@ public final class Stylesheet extends SyntaxTreeNode {
final LocalVariableGen current =
transf.addLocalVariable("current",
com.sun.org.apache.bcel.internal.generic.Type.INT,
il.getEnd(), null);
null, null);
final String applyTemplatesSig = classGen.getApplyTemplatesSig();
final int applyTemplates = cpg.addMethodref(getClassName(),
"applyTemplates",
@ -1270,6 +1297,15 @@ public final class Stylesheet extends SyntaxTreeNode {
//store to _dom variable
il.append(new PUTFIELD(domField));
// continue with globals initialization
final int gitr = cpg.addInterfaceMethodref(DOM_INTF,
"getIterator",
"()"+NODE_ITERATOR_SIG);
il.append(transf.loadDOM());
il.append(new INVOKEINTERFACE(gitr, 1));
il.append(transf.nextNode());
current.setStart(il.append(new ISTORE(current.getIndex())));
// Transfer the output settings to the output post-processor
il.append(classGen.loadTranslet());
il.append(transf.loadHandler());
@ -1326,12 +1362,8 @@ public final class Stylesheet extends SyntaxTreeNode {
il.append(RETURN);
// Compute max locals + stack and add method to class
transf.stripAttributes(true);
transf.setMaxLocals();
transf.setMaxStack();
transf.removeNOPs();
classGen.addMethod(transf);
classGen.addMethod(transf.getMethod());
}
/**

View file

@ -24,6 +24,7 @@
package com.sun.org.apache.xalan.internal.xsltc.compiler;
import java.util.Hashtable;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.Vector;
@ -46,6 +47,7 @@ final class SymbolTable {
private Hashtable _attributeSets = null;
private Hashtable _aliases = null;
private Hashtable _excludedURI = null;
private Stack _excludedURIStack = null;
private Hashtable _decimalFormats = null;
private Hashtable _keys = null;
@ -158,7 +160,7 @@ final class SymbolTable {
private int _nsCounter = 0;
public String generateNamespacePrefix() {
return(new String("ns"+(_nsCounter++)));
return("ns"+(_nsCounter++));
}
/**
@ -261,5 +263,33 @@ final class SymbolTable {
}
}
}
/**
* Exclusion of namespaces by a stylesheet does not extend to any stylesheet
* imported or included by the stylesheet. Upon entering the context of a
* new stylesheet, a call to this method is needed to clear the current set
* of excluded namespaces temporarily. Every call to this method requires
* a corresponding call to {@link #popExcludedNamespacesContext()}.
*/
public void pushExcludedNamespacesContext() {
if (_excludedURIStack == null) {
_excludedURIStack = new Stack();
}
_excludedURIStack.push(_excludedURI);
_excludedURI = null;
}
/**
* Exclusion of namespaces by a stylesheet does not extend to any stylesheet
* imported or included by the stylesheet. Upon exiting the context of a
* stylesheet, a call to this method is needed to restore the set of
* excluded namespaces that was in effect prior to entering the context of
* the current stylesheet.
*/
public void popExcludedNamespacesContext() {
_excludedURI = (Hashtable) _excludedURIStack.pop();
if (_excludedURIStack.isEmpty()) {
_excludedURIStack = null;
}
}
}

View file

@ -512,9 +512,12 @@ public abstract class SyntaxTreeNode implements Constants {
MethodGenerator methodGen) {
// Call translate() on all child nodes
final int n = elementCount();
for (int i = 0; i < n; i++) {
methodGen.markChunkStart();
final SyntaxTreeNode item = (SyntaxTreeNode)_contents.elementAt(i);
item.translate(classGen, methodGen);
methodGen.markChunkEnd();
}
// After translation, unmap any registers for any variables/parameters

View file

@ -108,10 +108,10 @@ final class TestSeq {
(LocationPathPattern) _patterns.elementAt(i);
if (i == 0) {
result.append("Testseq for kernel " + _kernelType)
result.append("Testseq for kernel ").append(_kernelType)
.append('\n');
}
result.append(" pattern " + i + ": ")
result.append(" pattern ").append(i).append(": ")
.append(pattern.toString())
.append('\n');
}

View file

@ -28,6 +28,7 @@ import com.sun.org.apache.bcel.internal.generic.ACONST_NULL;
import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen;
import com.sun.org.apache.bcel.internal.generic.DCONST;
import com.sun.org.apache.bcel.internal.generic.ICONST;
import com.sun.org.apache.bcel.internal.generic.InstructionHandle;
import com.sun.org.apache.bcel.internal.generic.InstructionList;
import com.sun.org.apache.bcel.internal.generic.PUTFIELD;
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.BooleanType;
@ -128,7 +129,7 @@ final class Variable extends VariableBase {
if (_local == null) {
_local = methodGen.addLocalVariable2(getEscapedName(),
_type.toJCType(),
il.getEnd());
null);
}
// Push the default value on the JVM's stack
if ((_type instanceof IntType) ||
@ -139,7 +140,10 @@ final class Variable extends VariableBase {
il.append(new DCONST(0)); // 0.0 for floating point numbers
else
il.append(new ACONST_NULL()); // and 'null' for anything else
il.append(_type.STORE(_local.getIndex()));
// Mark the store as the start of the live range of the variable
_local.setStart(il.append(_type.STORE(_local.getIndex())));
}
}
@ -163,10 +167,20 @@ final class Variable extends VariableBase {
translateValue(classGen, methodGen);
// Add a new local variable and store value
if (_local == null) {
boolean createLocal = _local == null;
if (createLocal) {
mapRegister(methodGen);
}
InstructionHandle storeInst =
il.append(_type.STORE(_local.getIndex()));
// If the local is just being created, mark the store as the start
// of its live range. Note that it might have been created by
// initializeVariables already, which would have set the start of
// the live range already.
if (createLocal) {
_local.setStart(storeInst);
}
}
else {
String signature = _type.toSignature();

View file

@ -83,14 +83,6 @@ class VariableBase extends TopLevelElement {
_refs.addElement(vref);
}
/**
* Remove a reference to this variable. Called by VariableRef when this
* variable goes out of scope.
*/
public void removeReference(VariableRefBase vref) {
_refs.remove(vref);
}
/**
* When a variable is overriden by another, e.g. via xsl:import,
* its references need to be copied or otherwise it may be
@ -121,7 +113,7 @@ class VariableBase extends TopLevelElement {
* Called when we leave the AST scope of the variable's declaration
*/
public void unmapRegister(MethodGenerator methodGen) {
if (_refs.isEmpty() && (_local != null)) {
if (_local != null) {
_local.setEnd(methodGen.getInstructionList().getEnd());
methodGen.removeLocalVariable(_local);
_refs = null;

View file

@ -70,12 +70,10 @@ final class VariableRef extends VariableRefBase {
}
else {
il.append(_variable.loadInstruction());
_variable.removeReference(this);
}
}
else {
il.append(_variable.loadInstruction());
_variable.removeReference(this);
}
}
else {

View file

@ -157,8 +157,7 @@ final class Whitespace extends TopLevelElement {
if (col != -1) {
namespace = lookupNamespace(token.substring(0,col));
if (namespace != null) {
elements.append(namespace+":"+
token.substring(col+1,token.length()));
elements.append(namespace).append(':').append(token.substring(col + 1));
} else {
elements.append(token);
}
@ -426,12 +425,7 @@ final class Whitespace extends TopLevelElement {
compileStripSpace(strip, sCount, il);
}
stripSpace.stripAttributes(true);
stripSpace.setMaxLocals();
stripSpace.setMaxStack();
stripSpace.removeNOPs();
classGen.addMethod(stripSpace.getMethod());
classGen.addMethod(stripSpace);
}
/**
@ -463,12 +457,7 @@ final class Whitespace extends TopLevelElement {
il.append(ICONST_0);
il.append(IRETURN);
stripSpace.stripAttributes(true);
stripSpace.setMaxLocals();
stripSpace.setMaxStack();
stripSpace.removeNOPs();
classGen.addMethod(stripSpace.getMethod());
classGen.addMethod(stripSpace);
}

View file

@ -131,11 +131,13 @@ public final class XSLTC {
*/
private boolean _isSecureProcessing = false;
private boolean _useServicesMechanism = true;
/**
* XSLTC compiler constructor
*/
public XSLTC() {
_parser = new Parser(this);
public XSLTC(boolean useServicesMechanism) {
_parser = new Parser(this, useServicesMechanism);
}
/**
@ -151,6 +153,19 @@ public final class XSLTC {
public boolean isSecureProcessing() {
return _isSecureProcessing;
}
/**
* Return the state of the services mechanism feature.
*/
public boolean useServicesMechnism() {
return _useServicesMechanism;
}
/**
* Set the state of the services mechanism feature.
*/
public void setServicesMechnism(boolean flag) {
_useServicesMechanism = flag;
}
/**
* Only for user by the internal TrAX implementation.
@ -230,6 +245,12 @@ public final class XSLTC {
public void setTemplateInlining(boolean templateInlining) {
_templateInlining = templateInlining;
}
/**
* Return the state of the template inlining feature.
*/
public boolean getTemplateInlining() {
return _templateInlining;
}
/**
* Set the parameters to use to locate the correct <?xml-stylesheet ...?>

View file

@ -209,13 +209,14 @@ final class XslAttribute extends Instruction {
if (!_isLiteral) {
// if the qname is an AVT, then the qname has to be checked at runtime if it is a valid qname
LocalVariableGen nameValue = methodGen.addLocalVariable2("nameValue",
LocalVariableGen nameValue =
methodGen.addLocalVariable2("nameValue",
Util.getJCRefType(STRING_SIG),
il.getEnd());
null);
// store the name into a variable first so _name.translate only needs to be called once
_name.translate(classGen, methodGen);
il.append(new ASTORE(nameValue.getIndex()));
nameValue.setStart(il.append(new ASTORE(nameValue.getIndex())));
il.append(new ALOAD(nameValue.getIndex()));
// call checkQName if the name is an AVT
@ -230,7 +231,7 @@ final class XslAttribute extends Instruction {
il.append(DUP); // first arg to "attributes" call
// load name value again
il.append(new ALOAD(nameValue.getIndex()));
nameValue.setEnd(il.append(new ALOAD(nameValue.getIndex())));
} else {
// Save the current handler base on the stack
il.append(methodGen.loadHandler());

View file

@ -224,13 +224,14 @@ final class XslElement extends Instruction {
if (!_ignore) {
// if the qname is an AVT, then the qname has to be checked at runtime if it is a valid qname
LocalVariableGen nameValue = methodGen.addLocalVariable2("nameValue",
Util.getJCRefType(STRING_SIG),
il.getEnd());
LocalVariableGen nameValue =
methodGen.addLocalVariable2("nameValue",
Util.getJCRefType(STRING_SIG),
null);
// store the name into a variable first so _name.translate only needs to be called once
_name.translate(classGen, methodGen);
il.append(new ASTORE(nameValue.getIndex()));
nameValue.setStart(il.append(new ASTORE(nameValue.getIndex())));
il.append(new ALOAD(nameValue.getIndex()));
// call checkQName if the name is an AVT
@ -244,7 +245,7 @@ final class XslElement extends Instruction {
il.append(methodGen.loadHandler());
// load name value again
il.append(new ALOAD(nameValue.getIndex()));
nameValue.setEnd(il.append(new ALOAD(nameValue.getIndex())));
if (_namespace != null) {
_namespace.translate(classGen, methodGen);

View file

@ -23,6 +23,7 @@
package com.sun.org.apache.xalan.internal.xsltc.compiler.util;
import com.sun.org.apache.bcel.internal.classfile.Method;
import com.sun.org.apache.bcel.internal.generic.ALOAD;
import com.sun.org.apache.bcel.internal.generic.ClassGen;
import com.sun.org.apache.bcel.internal.generic.Instruction;
@ -134,4 +135,10 @@ public class ClassGenerator extends ClassGen {
public boolean isExternal() {
return false;
}
public void addMethod(MethodGenerator methodGen) {
Method[] methodsToAdd = methodGen.getGeneratedMethods(this);
for (int i = 0; i < methodsToAdd.length; i++) {
addMethod(methodsToAdd[i]);
}
}
}

View file

@ -941,7 +941,64 @@ public class ErrorMessages extends ListResourceBundle {
"Cannot set the feature ''{0}'' on this TransformerFactory."},
{ErrorMsg.JAXP_SECUREPROCESSING_FEATURE,
"FEATURE_SECURE_PROCESSING: Cannot set the feature to false when security manager is present."}
"FEATURE_SECURE_PROCESSING: Cannot set the feature to false when security manager is present."},
/*
* Note to translators: This message describes an internal error in the
* processor. The term "byte code" is a Java technical term for the
* executable code in a Java method, and "try-catch-finally block"
* refers to the Java keywords with those names. "Outlined" is a
* technical term internal to XSLTC and should not be translated.
*/
{ErrorMsg.OUTLINE_ERR_TRY_CATCH,
"Internal XSLTC error: the generated byte code contains a " +
"try-catch-finally block and cannot be outlined."},
/*
* Note to translators: This message describes an internal error in the
* processor. The terms "OutlineableChunkStart" and
* "OutlineableChunkEnd" are the names of classes internal to XSLTC and
* should not be translated. The message indicates that for every
* "start" there must be a corresponding "end", and vice versa, and
* that if one of a pair of "start" and "end" appears between another
* pair of corresponding "start" and "end", then the other half of the
* pair must also be between that same enclosing pair.
*/
{ErrorMsg.OUTLINE_ERR_UNBALANCED_MARKERS,
"Internal XSLTC error: OutlineableChunkStart and " +
"OutlineableChunkEnd markers must be balanced and properly nested."},
/*
* Note to translators: This message describes an internal error in the
* processor. The term "byte code" is a Java technical term for the
* executable code in a Java method. The "method" that is being
* referred to is a Java method in a translet that XSLTC is generating
* in processing a stylesheet. The "instruction" that is being
* referred to is one of the instrutions in the Java byte code in that
* method. "Outlined" is a technical term internal to XSLTC and
* should not be translated.
*/
{ErrorMsg.OUTLINE_ERR_DELETED_TARGET,
"Internal XSLTC error: an instruction that was part of a block of " +
"byte code that was outlined is still referred to in the original " +
"method."
},
/*
* Note to translators: This message describes an internal error in the
* processor. The "method" that is being referred to is a Java method
* in a translet that XSLTC is generating.
*
*/
{ErrorMsg.OUTLINE_ERR_METHOD_TOO_BIG,
"Internal XSLTC error: a method in the translet exceeds the Java " +
"Virtual Machine limitation on the length of a method of 64 " +
"kilobytes. This is usually caused by templates in a stylesheet " +
"that are very large. Try restructuring your stylesheet to use " +
"smaller templates."
}
};
/** Get the lookup table for error messages.

View file

@ -157,6 +157,14 @@ public final class ErrorMsg {
public static final String INVALID_NCNAME_ERR = "INVALID_NCNAME_ERR";
public static final String INVALID_METHOD_IN_OUTPUT = "INVALID_METHOD_IN_OUTPUT";
public static final String OUTLINE_ERR_TRY_CATCH = "OUTLINE_ERR_TRY_CATCH";
public static final String OUTLINE_ERR_UNBALANCED_MARKERS =
"OUTLINE_ERR_UNBALANCED_MARKERS";
public static final String OUTLINE_ERR_DELETED_TARGET =
"OUTLINE_ERR_DELETED_TARGET";
public static final String OUTLINE_ERR_METHOD_TOO_BIG =
"OUTLINE_ERR_METHOD_TOO_BIG";
// All error messages are localized and are stored in resource bundles.
// This array and the following 4 strings are read from that bundle.
private static ResourceBundle _bundle;
@ -261,7 +269,7 @@ public final class ErrorMsg {
*/
public String toString() {
String suffix = (_params == null) ?
(null != _code ? new String(getErrorMessage()) : _message)
(null != _code ? getErrorMessage() : _message)
: MessageFormat.format(getErrorMessage(), _params);
return formatLine() + suffix;
}

View file

@ -0,0 +1,37 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 2001-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: InternalError.java,v 1.0 2011-08-18 04:34:19 joehw Exp $
*/
package com.sun.org.apache.xalan.internal.xsltc.compiler.util;
/**
* Marks a class of errors in which XSLTC has reached some incorrect internal
* state from which it cannot recover.
*/
public class InternalError extends Error {
/**
* Construct an <code>InternalError</code> with the specified error message.
* @param msg the error message
*/
public InternalError(String msg) {
super(msg);
}
}

View file

@ -0,0 +1,98 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 2001-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: MethodGenerator.java,v 1.10 2010-11-01 04:34:19 joehw Exp $
*/
package com.sun.org.apache.xalan.internal.xsltc.compiler.util;
import java.io.DataOutputStream;
import java.io.IOException;
import com.sun.org.apache.bcel.internal.Constants;
import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen;
import com.sun.org.apache.bcel.internal.generic.Instruction;
import com.sun.org.apache.bcel.internal.generic.Visitor;
/**
* A special abstract dummy subclass of
* {@link org.apache.bcel.generic.Instruction} used to mark locations of
* interest in an {@link com.sun.org.apache.bcel.internal.generic.InstructionList}. It and
* its subclasses are only used as placeholders, and do not contribute to the
* actual byte code instruction stream.
*/
abstract class MarkerInstruction extends Instruction {
/**
* Zero-argument constructor. Sets the opcode to an invalid value and
* sets the length to zero, as it will not be written as part of the
* generated byte code.
*/
public MarkerInstruction() {
super(Constants.UNDEFINED, (short) 0);
}
/**
* {@link com.sun.org.apache.bcel.internal.generic.Visitor}s will know nothing about this
* kind of {@link org.apche.bcel.generic.Instruction}, so this method does
* nothing.
*/
public void accept(Visitor v) {
}
/**
* The number of JVM stack entries consumed by the instruction.
* This instruction is just a place holder, so it does not consume any
* stack entries.
* @param cpg The {@link com.sun.org.apache.bcel.internal.generic.ConstantPoolGen} for the
* current {@link com.sun.org.apache.bcel.internal.generic.ClassGen}
* @return <code>0</code> always
*/
final public int consumeStack(ConstantPoolGen cpg) {
return 0;
}
/**
* The number of JVM stack entries produced by the instruction.
* This instruction is just a place holder, so it does not produce any
* stack entries.
* @param cpg The {@link com.sun.org.apache.bcel.internal.generic.ConstantPoolGen} for the
* current {@link com.sun.org.apache.bcel.internal.generic.ClassGen}
* @return <code>0</code> always
*/
final public int produceStack(ConstantPoolGen cpg) {
return 0;
}
/**
* Produce a copy of the instruction. By default a
* {@link MarkerInstruction} has no parameters, so the base implementation
* of {@link #copy()} returns the instruction itself.
* @return The instruction itself.
*/
public Instruction copy() {
return this;
}
/**
* Dump instruction as byte code to stream out. A {@link MarkerInstruction}
* has no effect on the generated byte code so it is never emitted to the
* output stream.
* @param out Output stream
*/
final public void dump(DataOutputStream out) throws IOException {
}
}

View file

@ -1,663 +0,0 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 2001-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: ObjectFactory.java,v 1.2.4.1 2005/09/12 11:45:06 pvedula Exp $
*/
package com.sun.org.apache.xalan.internal.xsltc.compiler.util;
import java.io.InputStream;
import java.io.IOException;
import java.io.File;
import java.io.FileInputStream;
import java.util.Properties;
import java.io.BufferedReader;
import java.io.InputStreamReader;
/**
* This class is duplicated for each JAXP subpackage so keep it in sync.
* It is package private and therefore is not exposed as part of the JAXP
* API.
* <p>
* This code is designed to implement the JAXP 1.1 spec pluggability
* feature and is designed to run on JDK version 1.1 and
* later, and to compile on JDK 1.2 and onward.
* The code also runs both as part of an unbundled jar file and
* when bundled as part of the JDK.
* <p>
* This class was moved from the <code>javax.xml.parsers.ObjectFactory</code>
* class and modified to be used as a general utility for creating objects
* dynamically.
*
* @version $Id: ObjectFactory.java,v 1.9 2008/04/02 00:40:59 joehw Exp $
*/
class ObjectFactory {
//
// Constants
//
// name of default properties file to look for in JDK's jre/lib directory
private static final String DEFAULT_PROPERTIES_FILENAME =
"xalan.properties";
private static final String SERVICES_PATH = "META-INF/services/";
/** Set to true for debugging */
private static final boolean DEBUG = false;
/** cache the contents of the xalan.properties file.
* Until an attempt has been made to read this file, this will
* be null; if the file does not exist or we encounter some other error
* during the read, this will be empty.
*/
private static Properties fXalanProperties = null;
/***
* Cache the time stamp of the xalan.properties file so
* that we know if it's been modified and can invalidate
* the cache when necessary.
*/
private static long fLastModified = -1;
//
// Public static methods
//
/**
* Finds the implementation Class object in the specified order. The
* specified order is the following:
* <ol>
* <li>query the system property using <code>System.getProperty</code>
* <li>read <code>META-INF/services/<i>factoryId</i></code> file
* <li>use fallback classname
* </ol>
*
* @return instance of factory, never null
*
* @param factoryId Name of the factory to find, same as
* a property name
* @param fallbackClassName Implementation class name, if nothing else
* is found. Use null to mean no fallback.
*
* @exception ObjectFactory.ConfigurationError
*/
static Object createObject(String factoryId, String fallbackClassName)
throws ConfigurationError {
return createObject(factoryId, null, fallbackClassName);
} // createObject(String,String):Object
/**
* Finds the implementation Class object in the specified order. The
* specified order is the following:
* <ol>
* <li>query the system property using <code>System.getProperty</code>
* <li>read <code>$java.home/lib/<i>propertiesFilename</i></code> file
* <li>read <code>META-INF/services/<i>factoryId</i></code> file
* <li>use fallback classname
* </ol>
*
* @return instance of factory, never null
*
* @param factoryId Name of the factory to find, same as
* a property name
* @param propertiesFilename The filename in the $java.home/lib directory
* of the properties file. If none specified,
* ${java.home}/lib/xalan.properties will be used.
* @param fallbackClassName Implementation class name, if nothing else
* is found. Use null to mean no fallback.
*
* @exception ObjectFactory.ConfigurationError
*/
static Object createObject(String factoryId,
String propertiesFilename,
String fallbackClassName)
throws ConfigurationError
{
Class factoryClass = lookUpFactoryClass(factoryId,
propertiesFilename,
fallbackClassName);
if (factoryClass == null) {
throw new ConfigurationError(
"Provider for " + factoryId + " cannot be found", null);
}
try{
Object instance = factoryClass.newInstance();
if (DEBUG) debugPrintln("created new instance of factory " + factoryId);
return instance;
} catch (Exception x) {
throw new ConfigurationError(
"Provider for factory " + factoryId
+ " could not be instantiated: " + x, x);
}
} // createObject(String,String,String):Object
/**
* Finds the implementation Class object in the specified order. The
* specified order is the following:
* <ol>
* <li>query the system property using <code>System.getProperty</code>
* <li>read <code>$java.home/lib/<i>propertiesFilename</i></code> file
* <li>read <code>META-INF/services/<i>factoryId</i></code> file
* <li>use fallback classname
* </ol>
*
* @return Class object of factory, never null
*
* @param factoryId Name of the factory to find, same as
* a property name
* @param propertiesFilename The filename in the $java.home/lib directory
* of the properties file. If none specified,
* ${java.home}/lib/xalan.properties will be used.
* @param fallbackClassName Implementation class name, if nothing else
* is found. Use null to mean no fallback.
*
* @exception ObjectFactory.ConfigurationError
*/
static Class lookUpFactoryClass(String factoryId)
throws ConfigurationError
{
return lookUpFactoryClass(factoryId, null, null);
} // lookUpFactoryClass(String):Class
/**
* Finds the implementation Class object in the specified order. The
* specified order is the following:
* <ol>
* <li>query the system property using <code>System.getProperty</code>
* <li>read <code>$java.home/lib/<i>propertiesFilename</i></code> file
* <li>read <code>META-INF/services/<i>factoryId</i></code> file
* <li>use fallback classname
* </ol>
*
* @return Class object that provides factory service, never null
*
* @param factoryId Name of the factory to find, same as
* a property name
* @param propertiesFilename The filename in the $java.home/lib directory
* of the properties file. If none specified,
* ${java.home}/lib/xalan.properties will be used.
* @param fallbackClassName Implementation class name, if nothing else
* is found. Use null to mean no fallback.
*
* @exception ObjectFactory.ConfigurationError
*/
static Class lookUpFactoryClass(String factoryId,
String propertiesFilename,
String fallbackClassName)
throws ConfigurationError
{
String factoryClassName = lookUpFactoryClassName(factoryId,
propertiesFilename,
fallbackClassName);
ClassLoader cl = findClassLoader();
if (factoryClassName == null) {
factoryClassName = fallbackClassName;
}
// assert(className != null);
try{
Class providerClass = findProviderClass(factoryClassName,
cl,
true);
if (DEBUG) debugPrintln("created new instance of " + providerClass +
" using ClassLoader: " + cl);
return providerClass;
} catch (ClassNotFoundException x) {
throw new ConfigurationError(
"Provider " + factoryClassName + " not found", x);
} catch (Exception x) {
throw new ConfigurationError(
"Provider "+factoryClassName+" could not be instantiated: "+x,
x);
}
} // lookUpFactoryClass(String,String,String):Class
/**
* Finds the name of the required implementation class in the specified
* order. The specified order is the following:
* <ol>
* <li>query the system property using <code>System.getProperty</code>
* <li>read <code>$java.home/lib/<i>propertiesFilename</i></code> file
* <li>read <code>META-INF/services/<i>factoryId</i></code> file
* <li>use fallback classname
* </ol>
*
* @return name of class that provides factory service, never null
*
* @param factoryId Name of the factory to find, same as
* a property name
* @param propertiesFilename The filename in the $java.home/lib directory
* of the properties file. If none specified,
* ${java.home}/lib/xalan.properties will be used.
* @param fallbackClassName Implementation class name, if nothing else
* is found. Use null to mean no fallback.
*
* @exception ObjectFactory.ConfigurationError
*/
static String lookUpFactoryClassName(String factoryId,
String propertiesFilename,
String fallbackClassName)
{
SecuritySupport ss = SecuritySupport.getInstance();
// Use the system property first
try {
String systemProp = ss.getSystemProperty(factoryId);
if (systemProp != null) {
if (DEBUG) debugPrintln("found system property, value=" + systemProp);
return systemProp;
}
} catch (SecurityException se) {
// Ignore and continue w/ next location
}
// Try to read from propertiesFilename, or
// $java.home/lib/xalan.properties
String factoryClassName = null;
// no properties file name specified; use
// $JAVA_HOME/lib/xalan.properties:
if (propertiesFilename == null) {
File propertiesFile = null;
boolean propertiesFileExists = false;
try {
String javah = ss.getSystemProperty("java.home");
propertiesFilename = javah + File.separator +
"lib" + File.separator + DEFAULT_PROPERTIES_FILENAME;
propertiesFile = new File(propertiesFilename);
propertiesFileExists = ss.getFileExists(propertiesFile);
} catch (SecurityException e) {
// try again...
fLastModified = -1;
fXalanProperties = null;
}
synchronized (ObjectFactory.class) {
boolean loadProperties = false;
FileInputStream fis = null;
try {
// file existed last time
if(fLastModified >= 0) {
if(propertiesFileExists &&
(fLastModified < (fLastModified = ss.getLastModified(propertiesFile)))) {
loadProperties = true;
} else {
// file has stopped existing...
if(!propertiesFileExists) {
fLastModified = -1;
fXalanProperties = null;
} // else, file wasn't modified!
}
} else {
// file has started to exist:
if(propertiesFileExists) {
loadProperties = true;
fLastModified = ss.getLastModified(propertiesFile);
} // else, nothing's changed
}
if(loadProperties) {
// must never have attempted to read xalan.properties
// before (or it's outdeated)
fXalanProperties = new Properties();
fis = ss.getFileInputStream(propertiesFile);
fXalanProperties.load(fis);
}
} catch (Exception x) {
fXalanProperties = null;
fLastModified = -1;
// assert(x instanceof FileNotFoundException
// || x instanceof SecurityException)
// In both cases, ignore and continue w/ next location
}
finally {
// try to close the input stream if one was opened.
if (fis != null) {
try {
fis.close();
}
// Ignore the exception.
catch (IOException exc) {}
}
}
}
if(fXalanProperties != null) {
factoryClassName = fXalanProperties.getProperty(factoryId);
}
} else {
FileInputStream fis = null;
try {
fis = ss.getFileInputStream(new File(propertiesFilename));
Properties props = new Properties();
props.load(fis);
factoryClassName = props.getProperty(factoryId);
} catch (Exception x) {
// assert(x instanceof FileNotFoundException
// || x instanceof SecurityException)
// In both cases, ignore and continue w/ next location
}
finally {
// try to close the input stream if one was opened.
if (fis != null) {
try {
fis.close();
}
// Ignore the exception.
catch (IOException exc) {}
}
}
}
if (factoryClassName != null) {
if (DEBUG) debugPrintln("found in " + propertiesFilename + ", value="
+ factoryClassName);
return factoryClassName;
}
// Try Jar Service Provider Mechanism
return findJarServiceProviderName(factoryId);
} // lookUpFactoryClass(String,String):String
//
// Private static methods
//
/** Prints a message to standard error if debugging is enabled. */
private static void debugPrintln(String msg) {
if (DEBUG) {
System.err.println("JAXP: " + msg);
}
} // debugPrintln(String)
/**
* Figure out which ClassLoader to use. For JDK 1.2 and later use
* the context ClassLoader.
*/
static ClassLoader findClassLoader()
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 context = ss.getContextClassLoader();
ClassLoader system = ss.getSystemClassLoader();
ClassLoader chain = system;
while (true) {
if (context == chain) {
// Assert: we are on JDK 1.1 or we have no Context ClassLoader
// or any Context ClassLoader in chain of system classloader
// (including extension ClassLoader) so extend to widest
// ClassLoader (always look in system ClassLoader if Xalan
// is in boot/extension/system classpath and in current
// ClassLoader otherwise); normal classloaders delegate
// back to system ClassLoader first so this widening doesn't
// change the fact that context ClassLoader will be consulted
ClassLoader current = ObjectFactory.class.getClassLoader();
chain = system;
while (true) {
if (current == chain) {
// Assert: Current ClassLoader in chain of
// boot/extension/system ClassLoaders
return system;
}
if (chain == null) {
break;
}
chain = ss.getParentClassLoader(chain);
}
// Assert: Current ClassLoader not in chain of
// boot/extension/system ClassLoaders
return current;
}
if (chain == null) {
// boot ClassLoader reached
break;
}
// Check for any extension ClassLoaders in chain up to
// boot ClassLoader
chain = ss.getParentClassLoader(chain);
};
// Assert: Context ClassLoader not in chain of
// boot/extension/system ClassLoaders
return context;
} // findClassLoader():ClassLoader
/**
* Create an instance of a class using the specified ClassLoader
*/
static Object newInstance(String className, ClassLoader cl,
boolean doFallback)
throws ConfigurationError
{
// assert(className != null);
try{
Class providerClass = findProviderClass(className, cl, doFallback);
Object instance = providerClass.newInstance();
if (DEBUG) debugPrintln("created new instance of " + providerClass +
" using ClassLoader: " + cl);
return instance;
} catch (ClassNotFoundException x) {
throw new ConfigurationError(
"Provider " + className + " not found", x);
} catch (Exception x) {
throw new ConfigurationError(
"Provider " + className + " could not be instantiated: " + x,
x);
}
}
/**
* Find a Class using the specified ClassLoader
*/
static Class findProviderClass(String className, ClassLoader cl,
boolean doFallback)
throws ClassNotFoundException, ConfigurationError
{
//throw security exception if the calling thread is not allowed to access the
//class. Restrict the access to the package classes as specified in java.security policy.
SecurityManager security = System.getSecurityManager();
try{
if (security != null){
final int lastDot = className.lastIndexOf(".");
String packageName = className;
if (lastDot != -1) packageName = className.substring(0, lastDot);
security.checkPackageAccess(packageName);
}
}catch(SecurityException e){
throw e;
}
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);
} else {
try {
providerClass = cl.loadClass(className);
} catch (ClassNotFoundException x) {
if (doFallback) {
// Fall back to current classloader
ClassLoader current = ObjectFactory.class.getClassLoader();
if (current == null) {
providerClass = Class.forName(className);
} else if (cl != current) {
cl = current;
providerClass = cl.loadClass(className);
} else {
throw x;
}
} else {
throw x;
}
}
}
return providerClass;
}
/**
* Find the name of service provider using Jar Service Provider Mechanism
*
* @return instance of provider class if found or null
*/
private static String findJarServiceProviderName(String factoryId)
{
SecuritySupport ss = SecuritySupport.getInstance();
String serviceId = SERVICES_PATH + factoryId;
InputStream is = null;
// First try the Context ClassLoader
ClassLoader cl = findClassLoader();
is = ss.getResourceAsStream(cl, serviceId);
// If no provider found then try the current ClassLoader
if (is == null) {
ClassLoader current = ObjectFactory.class.getClassLoader();
if (cl != current) {
cl = current;
is = ss.getResourceAsStream(cl, serviceId);
}
}
if (is == null) {
// No provider found
return null;
}
if (DEBUG) debugPrintln("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 {
rd = new BufferedReader(new InputStreamReader(is, "UTF-8"));
} catch (java.io.UnsupportedEncodingException e) {
rd = new BufferedReader(new InputStreamReader(is));
}
String factoryClassName = null;
try {
// XXX Does not handle all possible input as specified by the
// Jar Service Provider specification
factoryClassName = rd.readLine();
} catch (IOException x) {
// No provider found
return null;
}
finally {
try {
// try to close the reader.
rd.close();
}
// Ignore the exception.
catch (IOException exc) {}
}
if (factoryClassName != null &&
! "".equals(factoryClassName)) {
if (DEBUG) debugPrintln("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 factoryClassName;
}
// No provider found
return null;
}
//
// Classes
//
/**
* A configuration error.
*/
static class ConfigurationError
extends Error {
static final long serialVersionUID = -4417969773510154215L;
//
// Data
//
/** Exception. */
private Exception exception;
//
// Constructors
//
/**
* Construct a new instance with the specified detail string and
* exception.
*/
ConfigurationError(String msg, Exception x) {
super(msg);
this.exception = x;
} // <init>(String,Exception)
//
// Public methods
//
/** Returns the exception associated to this error. */
Exception getException() {
return exception;
} // getException():Exception
} // class ConfigurationError
} // class ObjectFactory

View file

@ -34,6 +34,7 @@ import com.sun.org.apache.bcel.internal.generic.Instruction;
import com.sun.org.apache.bcel.internal.generic.InstructionList;
import com.sun.org.apache.bcel.internal.generic.PUSH;
import com.sun.org.apache.xalan.internal.xsltc.compiler.Constants;
import com.sun.org.apache.xalan.internal.utils.ObjectFactory;
/**
* @author Todd Miller
@ -53,8 +54,7 @@ public final class ObjectType extends Type {
_javaClassName = javaClassName;
try {
_clazz = ObjectFactory.findProviderClass(
javaClassName, ObjectFactory.findClassLoader(), true);
_clazz = ObjectFactory.findProviderClass(javaClassName, true);
}
catch (ClassNotFoundException e) {
_clazz = null;

View file

@ -0,0 +1,70 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 2001-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: OutlineableChunkEnd.java,v 1.10 2010-11-01 04:34:19 joehw Exp $
*/
package com.sun.org.apache.xalan.internal.xsltc.compiler.util;
import com.sun.org.apache.bcel.internal.generic.Instruction;
/**
* <p>Marks the end of a region of byte code that can be copied into a new
* method. See the {@link OutlineableChunkStart} pseudo-instruction for
* details.</p>
*/
class OutlineableChunkEnd extends MarkerInstruction {
/**
* A constant instance of {@link OutlineableChunkEnd}. As it has no fields,
* there should be no need to create an instance of this class.
*/
public static final Instruction OUTLINEABLECHUNKEND =
new OutlineableChunkEnd();
/**
* Private default constructor. As it has no fields,
* there should be no need to create an instance of this class. See
* {@link OutlineableChunkEnd#OUTLINEABLECHUNKEND}.
*/
private OutlineableChunkEnd() {
}
/**
* Get the name of this instruction. Used for debugging.
* @return the instruction name
*/
public String getName() {
return OutlineableChunkEnd.class.getName();
}
/**
* Get the name of this instruction. Used for debugging.
* @return the instruction name
*/
public String toString() {
return getName();
}
/**
* Get the name of this instruction. Used for debugging.
* @return the instruction name
*/
public String toString(boolean verbose) {
return getName();
}
}

View file

@ -0,0 +1,80 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 2001-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: MethodGenerator.java,v 1.10 2010-11-01 04:34:19 joehw Exp $
*/
package com.sun.org.apache.xalan.internal.xsltc.compiler.util;
import com.sun.org.apache.bcel.internal.generic.Instruction;
/**
* <p>This pseudo-instruction marks the beginning of a region of byte code that
* can be copied into a new method, termed an "outlineable" chunk. The size of
* the Java stack must be the same at the start of the region as it is at the
* end of the region, any value on the stack at the start of the region must not
* be consumed by an instruction in the region of code, the region must not
* contain a return instruction, no branch instruction in the region is
* permitted to have a target that is outside the region, and no branch
* instruction outside the region is permitted to have a target that is inside
* the region.</p>
* <p>The end of the region is marked by an {@link OutlineableChunkEnd}
* pseudo-instruction.</p>
* <p>Such a region of code may contain other outlineable regions.</p>
*/
class OutlineableChunkStart extends MarkerInstruction {
/**
* A constant instance of {@link OutlineableChunkStart}. As it has no fields,
* there should be no need to create an instance of this class.
*/
public static final Instruction OUTLINEABLECHUNKSTART =
new OutlineableChunkStart();
/**
* Private default constructor. As it has no fields,
* there should be no need to create an instance of this class. See
* {@link OutlineableChunkStart#OUTLINEABLECHUNKSTART}.
*/
private OutlineableChunkStart() {
}
/**
* Get the name of this instruction. Used for debugging.
* @return the instruction name
*/
public String getName() {
return OutlineableChunkStart.class.getName();
}
/**
* Get the name of this instruction. Used for debugging.
* @return the instruction name
*/
public String toString() {
return getName();
}
/**
* Get the name of this instruction. Used for debugging.
* @return the instruction name
*/
public String toString(boolean verbose) {
return getName();
}
}

View file

@ -170,8 +170,8 @@ public final class RealType extends NumberType {
il.append(DUP2);
local = methodGen.addLocalVariable("real_to_boolean_tmp",
com.sun.org.apache.bcel.internal.generic.Type.DOUBLE,
il.getEnd(), null);
il.append(new DSTORE(local.getIndex()));
null, null);
local.setStart(il.append(new DSTORE(local.getIndex())));
// Compare it to 0.0
il.append(DCONST_0);
@ -181,7 +181,7 @@ public final class RealType extends NumberType {
//!!! call isNaN
// Compare it to itself to see if NaN
il.append(new DLOAD(local.getIndex()));
il.append(new DLOAD(local.getIndex()));
local.setEnd(il.append(new DLOAD(local.getIndex())));
il.append(DCMPG);
flowlist.add(il.append(new IFNE(null))); // NaN != NaN
return flowlist;

View file

@ -180,7 +180,7 @@ public final class ResultTreeType extends Type {
methodGen.addLocalVariable("rt_to_string_handler",
Util.getJCRefType(STRING_VALUE_HANDLER_SIG),
null, null);
il.append(new ASTORE(handler.getIndex()));
handler.setStart(il.append(new ASTORE(handler.getIndex())));
// Call the method that implements this result tree
index = cpg.addMethodref(className, _methodName,
@ -188,7 +188,7 @@ public final class ResultTreeType extends Type {
il.append(new INVOKEVIRTUAL(index));
// Restore new handler and call getValue()
il.append(new ALOAD(handler.getIndex()));
handler.setEnd(il.append(new ALOAD(handler.getIndex())));
index = cpg.addMethodref(STRING_VALUE_HANDLER,
"getValue",
"()" + STRING_SIG);
@ -255,7 +255,7 @@ public final class ResultTreeType extends Type {
Util.getJCRefType(DOM_INTF_SIG),
null, null);
il.append(new CHECKCAST(cpg.addClass(DOM_INTF_SIG)));
il.append(new ASTORE(newDom.getIndex()));
newDom.setStart(il.append(new ASTORE(newDom.getIndex())));
// Overwrite old handler with DOM handler
index = cpg.addInterfaceMethodref(DOM_INTF,
@ -275,7 +275,7 @@ public final class ResultTreeType extends Type {
methodGen.addLocalVariable("rt_to_reference_handler",
Util.getJCRefType(TRANSLET_OUTPUT_SIG),
null, null);
il.append(new ASTORE(domBuilder.getIndex()));
domBuilder.setStart(il.append(new ASTORE(domBuilder.getIndex())));
// Call startDocument on the new handler
index = cpg.addInterfaceMethodref(TRANSLET_OUTPUT_INTERFACE,
@ -292,13 +292,13 @@ public final class ResultTreeType extends Type {
il.append(new INVOKEVIRTUAL(index));
// Call endDocument on the DOM handler
il.append(new ALOAD(domBuilder.getIndex()));
domBuilder.setEnd(il.append(new ALOAD(domBuilder.getIndex())));
index = cpg.addInterfaceMethodref(TRANSLET_OUTPUT_INTERFACE,
"endDocument", "()V");
il.append(new INVOKEINTERFACE(index, 1));
// Push the new DOM on the stack
il.append(new ALOAD(newDom.getIndex()));
newDom.setEnd(il.append(new ALOAD(newDom.getIndex())));
}
}

View file

@ -1,127 +0,0 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 2002-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: SecuritySupport.java,v 1.2.4.1 2005/09/05 11:31:37 pvedula Exp $
*/
package com.sun.org.apache.xalan.internal.xsltc.compiler.util;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.Properties;
/**
* This class is duplicated for each Xalan-Java subpackage so keep it in sync.
* It is package private and therefore is not exposed as part of the Xalan-Java
* 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.
*/
static SecuritySupport getInstance() {
return (SecuritySupport)securitySupport;
}
ClassLoader getContextClassLoader() {
return null;
}
ClassLoader getSystemClassLoader() {
return null;
}
ClassLoader getParentClassLoader(ClassLoader cl) {
return null;
}
String getSystemProperty(String propName) {
return System.getProperty(propName);
}
FileInputStream getFileInputStream(File file)
throws FileNotFoundException
{
return new FileInputStream(file);
}
InputStream getResourceAsStream(ClassLoader cl, String name) {
InputStream ris;
if (cl == null) {
ris = ClassLoader.getSystemResourceAsStream(name);
} else {
ris = cl.getResourceAsStream(name);
}
return ris;
}
boolean getFileExists(File f) {
return f.exists();
}
long getLastModified(File f) {
return f.lastModified();
}
}

View file

@ -1,148 +0,0 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 2002-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: SecuritySupport12.java,v 1.2.4.1 2005/09/05 11:32:07 pvedula Exp $
*/
package com.sun.org.apache.xalan.internal.xsltc.compiler.util;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.util.Properties;
/**
* This class is duplicated for each Xalan-Java subpackage so keep it in sync.
* It is package private and therefore is not exposed as part of the Xalan-Java
* API.
*
* Security related methods that only work on J2SE 1.2 and newer.
*/
class SecuritySupport12 extends SecuritySupport {
ClassLoader getContextClassLoader() {
return (ClassLoader)
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
ClassLoader cl = null;
try {
cl = Thread.currentThread().getContextClassLoader();
} catch (SecurityException ex) { }
return cl;
}
});
}
ClassLoader getSystemClassLoader() {
return (ClassLoader)
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
ClassLoader cl = null;
try {
cl = ClassLoader.getSystemClassLoader();
} catch (SecurityException ex) {}
return cl;
}
});
}
ClassLoader getParentClassLoader(final ClassLoader cl) {
return (ClassLoader)
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
ClassLoader parent = null;
try {
parent = cl.getParent();
} catch (SecurityException ex) {}
// eliminate loops in case of the boot
// ClassLoader returning itself as a parent
return (parent == cl) ? null : parent;
}
});
}
String getSystemProperty(final String propName) {
return (String)
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
return System.getProperty(propName);
}
});
}
FileInputStream getFileInputStream(final File file)
throws FileNotFoundException
{
try {
return (FileInputStream)
AccessController.doPrivileged(new PrivilegedExceptionAction() {
public Object run() throws FileNotFoundException {
return new FileInputStream(file);
}
});
} catch (PrivilegedActionException e) {
throw (FileNotFoundException)e.getException();
}
}
InputStream getResourceAsStream(final ClassLoader cl,
final String name)
{
return (InputStream)
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
InputStream ris;
if (cl == null) {
ris = ClassLoader.getSystemResourceAsStream(name);
} else {
ris = cl.getResourceAsStream(name);
}
return ris;
}
});
}
boolean getFileExists(final File f) {
return ((Boolean)
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
return new Boolean(f.exists());
}
})).booleanValue();
}
long getLastModified(final File f) {
return ((Long)
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
return new Long(f.lastModified());
}
})).longValue();
}
}

View file

@ -0,0 +1,91 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 2001-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: ArrayNodeListIterator.java,v 1.0 2009-11-25 04:34:24 joehw Exp $
*/
package com.sun.org.apache.xalan.internal.xsltc.dom;
import com.sun.org.apache.xml.internal.dtm.DTMAxisIterator;
public class ArrayNodeListIterator implements DTMAxisIterator {
private int _pos = 0;
private int _mark = 0;
private int _nodes[];
private static final int[] EMPTY = { };
public ArrayNodeListIterator(int[] nodes) {
_nodes = nodes;
}
public int next() {
return _pos < _nodes.length ? _nodes[_pos++] : END;
}
public DTMAxisIterator reset() {
_pos = 0;
return this;
}
public int getLast() {
return _nodes.length;
}
public int getPosition() {
return _pos;
}
public void setMark() {
_mark = _pos;
}
public void gotoMark() {
_pos = _mark;
}
public DTMAxisIterator setStartNode(int node) {
if (node == END) _nodes = EMPTY;
return this;
}
public int getStartNode() {
return END;
}
public boolean isReverse() {
return false;
}
public DTMAxisIterator cloneIterator() {
return new ArrayNodeListIterator(_nodes);
}
public void setRestartable(boolean isRestartable) {
}
public int getNodeByPosition(int position) {
return _nodes[position - 1];
}
}

View file

@ -88,7 +88,9 @@ public final class DupFilterIterator extends DTMAxisIteratorBase {
if (_isRestartable) {
// KeyIndex iterators are always relative to the root node, so there
// is never any point in re-reading the iterator (and we SHOULD NOT).
if (_source instanceof KeyIndex
boolean sourceIsKeyIndex = _source instanceof KeyIndex;
if (sourceIsKeyIndex
&& _startNode == DTMDefaultBase.ROOTNODE) {
return this;
}
@ -100,7 +102,12 @@ public final class DupFilterIterator extends DTMAxisIteratorBase {
while ((node = _source.next()) != END) {
_nodes.add(node);
}
_nodes.sort();
// Nodes produced by KeyIndex are known to be in document order.
// Take advantage of it.
if (!sourceIsKeyIndex) {
_nodes.sort();
}
_nodesSize = _nodes.cardinality();
_current = 0;
_lastNext = END;

View file

@ -32,6 +32,7 @@ import com.sun.org.apache.xalan.internal.xsltc.DOM;
import com.sun.org.apache.xalan.internal.xsltc.TransletException;
import com.sun.org.apache.xalan.internal.xsltc.runtime.AbstractTranslet;
import com.sun.org.apache.xml.internal.utils.StringComparable;
import com.sun.org.apache.xalan.internal.utils.ObjectFactory;
/**
* Base class for sort records containing application specific sort keys
@ -119,8 +120,7 @@ public abstract class NodeSortRecord {
if (colFactClassname != null) {
try {
Object candObj = ObjectFactory.findProviderClass(
colFactClassname, ObjectFactory.findClassLoader(), true);
Object candObj = ObjectFactory.findProviderClass(colFactClassname, true);
_collatorFactory = (CollatorFactory)candObj;
} catch (ClassNotFoundException e) {
throw new TransletException(e);

View file

@ -28,6 +28,7 @@ import com.sun.org.apache.xalan.internal.xsltc.Translet;
import com.sun.org.apache.xalan.internal.xsltc.TransletException;
import com.sun.org.apache.xalan.internal.xsltc.runtime.AbstractTranslet;
import com.sun.org.apache.xml.internal.utils.LocaleUtility;
import com.sun.org.apache.xalan.internal.utils.ObjectFactory;
import java.util.Locale;
import java.text.Collator;
@ -82,8 +83,7 @@ public class NodeSortRecordFactory {
_class = translet.getAuxiliaryClass(className);
// This code is only run when the native API is used
if (_class == null) {
_class = ObjectFactory.findProviderClass(
className, ObjectFactory.findClassLoader(), true);
_class = ObjectFactory.findProviderClass(className, true);
}
int levels = order.length;

View file

@ -1,663 +0,0 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 2001-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: ObjectFactory.java,v 1.2.4.1 2005/09/12 11:53:33 pvedula Exp $
*/
package com.sun.org.apache.xalan.internal.xsltc.dom;
import java.io.InputStream;
import java.io.IOException;
import java.io.File;
import java.io.FileInputStream;
import java.util.Properties;
import java.io.BufferedReader;
import java.io.InputStreamReader;
/**
* This class is duplicated for each JAXP subpackage so keep it in sync.
* It is package private and therefore is not exposed as part of the JAXP
* API.
* <p>
* This code is designed to implement the JAXP 1.1 spec pluggability
* feature and is designed to run on JDK version 1.1 and
* later, and to compile on JDK 1.2 and onward.
* The code also runs both as part of an unbundled jar file and
* when bundled as part of the JDK.
* <p>
* This class was moved from the <code>javax.xml.parsers.ObjectFactory</code>
* class and modified to be used as a general utility for creating objects
* dynamically.
*
* @version $Id: ObjectFactory.java,v 1.9 2008/04/02 00:41:00 joehw Exp $
*/
class ObjectFactory {
//
// Constants
//
// name of default properties file to look for in JDK's jre/lib directory
private static final String DEFAULT_PROPERTIES_FILENAME =
"xalan.properties";
private static final String SERVICES_PATH = "META-INF/services/";
/** Set to true for debugging */
private static final boolean DEBUG = false;
/** cache the contents of the xalan.properties file.
* Until an attempt has been made to read this file, this will
* be null; if the file does not exist or we encounter some other error
* during the read, this will be empty.
*/
private static Properties fXalanProperties = null;
/***
* Cache the time stamp of the xalan.properties file so
* that we know if it's been modified and can invalidate
* the cache when necessary.
*/
private static long fLastModified = -1;
//
// Public static methods
//
/**
* Finds the implementation Class object in the specified order. The
* specified order is the following:
* <ol>
* <li>query the system property using <code>System.getProperty</code>
* <li>read <code>META-INF/services/<i>factoryId</i></code> file
* <li>use fallback classname
* </ol>
*
* @return instance of factory, never null
*
* @param factoryId Name of the factory to find, same as
* a property name
* @param fallbackClassName Implementation class name, if nothing else
* is found. Use null to mean no fallback.
*
* @exception ObjectFactory.ConfigurationError
*/
static Object createObject(String factoryId, String fallbackClassName)
throws ConfigurationError {
return createObject(factoryId, null, fallbackClassName);
} // createObject(String,String):Object
/**
* Finds the implementation Class object in the specified order. The
* specified order is the following:
* <ol>
* <li>query the system property using <code>System.getProperty</code>
* <li>read <code>$java.home/lib/<i>propertiesFilename</i></code> file
* <li>read <code>META-INF/services/<i>factoryId</i></code> file
* <li>use fallback classname
* </ol>
*
* @return instance of factory, never null
*
* @param factoryId Name of the factory to find, same as
* a property name
* @param propertiesFilename The filename in the $java.home/lib directory
* of the properties file. If none specified,
* ${java.home}/lib/xalan.properties will be used.
* @param fallbackClassName Implementation class name, if nothing else
* is found. Use null to mean no fallback.
*
* @exception ObjectFactory.ConfigurationError
*/
static Object createObject(String factoryId,
String propertiesFilename,
String fallbackClassName)
throws ConfigurationError
{
Class factoryClass = lookUpFactoryClass(factoryId,
propertiesFilename,
fallbackClassName);
if (factoryClass == null) {
throw new ConfigurationError(
"Provider for " + factoryId + " cannot be found", null);
}
try{
Object instance = factoryClass.newInstance();
if (DEBUG) debugPrintln("created new instance of factory " + factoryId);
return instance;
} catch (Exception x) {
throw new ConfigurationError(
"Provider for factory " + factoryId
+ " could not be instantiated: " + x, x);
}
} // createObject(String,String,String):Object
/**
* Finds the implementation Class object in the specified order. The
* specified order is the following:
* <ol>
* <li>query the system property using <code>System.getProperty</code>
* <li>read <code>$java.home/lib/<i>propertiesFilename</i></code> file
* <li>read <code>META-INF/services/<i>factoryId</i></code> file
* <li>use fallback classname
* </ol>
*
* @return Class object of factory, never null
*
* @param factoryId Name of the factory to find, same as
* a property name
* @param propertiesFilename The filename in the $java.home/lib directory
* of the properties file. If none specified,
* ${java.home}/lib/xalan.properties will be used.
* @param fallbackClassName Implementation class name, if nothing else
* is found. Use null to mean no fallback.
*
* @exception ObjectFactory.ConfigurationError
*/
static Class lookUpFactoryClass(String factoryId)
throws ConfigurationError
{
return lookUpFactoryClass(factoryId, null, null);
} // lookUpFactoryClass(String):Class
/**
* Finds the implementation Class object in the specified order. The
* specified order is the following:
* <ol>
* <li>query the system property using <code>System.getProperty</code>
* <li>read <code>$java.home/lib/<i>propertiesFilename</i></code> file
* <li>read <code>META-INF/services/<i>factoryId</i></code> file
* <li>use fallback classname
* </ol>
*
* @return Class object that provides factory service, never null
*
* @param factoryId Name of the factory to find, same as
* a property name
* @param propertiesFilename The filename in the $java.home/lib directory
* of the properties file. If none specified,
* ${java.home}/lib/xalan.properties will be used.
* @param fallbackClassName Implementation class name, if nothing else
* is found. Use null to mean no fallback.
*
* @exception ObjectFactory.ConfigurationError
*/
static Class lookUpFactoryClass(String factoryId,
String propertiesFilename,
String fallbackClassName)
throws ConfigurationError
{
String factoryClassName = lookUpFactoryClassName(factoryId,
propertiesFilename,
fallbackClassName);
ClassLoader cl = findClassLoader();
if (factoryClassName == null) {
factoryClassName = fallbackClassName;
}
// assert(className != null);
try{
Class providerClass = findProviderClass(factoryClassName,
cl,
true);
if (DEBUG) debugPrintln("created new instance of " + providerClass +
" using ClassLoader: " + cl);
return providerClass;
} catch (ClassNotFoundException x) {
throw new ConfigurationError(
"Provider " + factoryClassName + " not found", x);
} catch (Exception x) {
throw new ConfigurationError(
"Provider "+factoryClassName+" could not be instantiated: "+x,
x);
}
} // lookUpFactoryClass(String,String,String):Class
/**
* Finds the name of the required implementation class in the specified
* order. The specified order is the following:
* <ol>
* <li>query the system property using <code>System.getProperty</code>
* <li>read <code>$java.home/lib/<i>propertiesFilename</i></code> file
* <li>read <code>META-INF/services/<i>factoryId</i></code> file
* <li>use fallback classname
* </ol>
*
* @return name of class that provides factory service, never null
*
* @param factoryId Name of the factory to find, same as
* a property name
* @param propertiesFilename The filename in the $java.home/lib directory
* of the properties file. If none specified,
* ${java.home}/lib/xalan.properties will be used.
* @param fallbackClassName Implementation class name, if nothing else
* is found. Use null to mean no fallback.
*
* @exception ObjectFactory.ConfigurationError
*/
static String lookUpFactoryClassName(String factoryId,
String propertiesFilename,
String fallbackClassName)
{
SecuritySupport ss = SecuritySupport.getInstance();
// Use the system property first
try {
String systemProp = ss.getSystemProperty(factoryId);
if (systemProp != null) {
if (DEBUG) debugPrintln("found system property, value=" + systemProp);
return systemProp;
}
} catch (SecurityException se) {
// Ignore and continue w/ next location
}
// Try to read from propertiesFilename, or
// $java.home/lib/xalan.properties
String factoryClassName = null;
// no properties file name specified; use
// $JAVA_HOME/lib/xalan.properties:
if (propertiesFilename == null) {
File propertiesFile = null;
boolean propertiesFileExists = false;
try {
String javah = ss.getSystemProperty("java.home");
propertiesFilename = javah + File.separator +
"lib" + File.separator + DEFAULT_PROPERTIES_FILENAME;
propertiesFile = new File(propertiesFilename);
propertiesFileExists = ss.getFileExists(propertiesFile);
} catch (SecurityException e) {
// try again...
fLastModified = -1;
fXalanProperties = null;
}
synchronized (ObjectFactory.class) {
boolean loadProperties = false;
FileInputStream fis = null;
try {
// file existed last time
if(fLastModified >= 0) {
if(propertiesFileExists &&
(fLastModified < (fLastModified = ss.getLastModified(propertiesFile)))) {
loadProperties = true;
} else {
// file has stopped existing...
if(!propertiesFileExists) {
fLastModified = -1;
fXalanProperties = null;
} // else, file wasn't modified!
}
} else {
// file has started to exist:
if(propertiesFileExists) {
loadProperties = true;
fLastModified = ss.getLastModified(propertiesFile);
} // else, nothing's changed
}
if(loadProperties) {
// must never have attempted to read xalan.properties
// before (or it's outdeated)
fXalanProperties = new Properties();
fis = ss.getFileInputStream(propertiesFile);
fXalanProperties.load(fis);
}
} catch (Exception x) {
fXalanProperties = null;
fLastModified = -1;
// assert(x instanceof FileNotFoundException
// || x instanceof SecurityException)
// In both cases, ignore and continue w/ next location
}
finally {
// try to close the input stream if one was opened.
if (fis != null) {
try {
fis.close();
}
// Ignore the exception.
catch (IOException exc) {}
}
}
}
if(fXalanProperties != null) {
factoryClassName = fXalanProperties.getProperty(factoryId);
}
} else {
FileInputStream fis = null;
try {
fis = ss.getFileInputStream(new File(propertiesFilename));
Properties props = new Properties();
props.load(fis);
factoryClassName = props.getProperty(factoryId);
} catch (Exception x) {
// assert(x instanceof FileNotFoundException
// || x instanceof SecurityException)
// In both cases, ignore and continue w/ next location
}
finally {
// try to close the input stream if one was opened.
if (fis != null) {
try {
fis.close();
}
// Ignore the exception.
catch (IOException exc) {}
}
}
}
if (factoryClassName != null) {
if (DEBUG) debugPrintln("found in " + propertiesFilename + ", value="
+ factoryClassName);
return factoryClassName;
}
// Try Jar Service Provider Mechanism
return findJarServiceProviderName(factoryId);
} // lookUpFactoryClass(String,String):String
//
// Private static methods
//
/** Prints a message to standard error if debugging is enabled. */
private static void debugPrintln(String msg) {
if (DEBUG) {
System.err.println("JAXP: " + msg);
}
} // debugPrintln(String)
/**
* Figure out which ClassLoader to use. For JDK 1.2 and later use
* the context ClassLoader.
*/
static ClassLoader findClassLoader()
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 context = ss.getContextClassLoader();
ClassLoader system = ss.getSystemClassLoader();
ClassLoader chain = system;
while (true) {
if (context == chain) {
// Assert: we are on JDK 1.1 or we have no Context ClassLoader
// or any Context ClassLoader in chain of system classloader
// (including extension ClassLoader) so extend to widest
// ClassLoader (always look in system ClassLoader if Xalan
// is in boot/extension/system classpath and in current
// ClassLoader otherwise); normal classloaders delegate
// back to system ClassLoader first so this widening doesn't
// change the fact that context ClassLoader will be consulted
ClassLoader current = ObjectFactory.class.getClassLoader();
chain = system;
while (true) {
if (current == chain) {
// Assert: Current ClassLoader in chain of
// boot/extension/system ClassLoaders
return system;
}
if (chain == null) {
break;
}
chain = ss.getParentClassLoader(chain);
}
// Assert: Current ClassLoader not in chain of
// boot/extension/system ClassLoaders
return current;
}
if (chain == null) {
// boot ClassLoader reached
break;
}
// Check for any extension ClassLoaders in chain up to
// boot ClassLoader
chain = ss.getParentClassLoader(chain);
};
// Assert: Context ClassLoader not in chain of
// boot/extension/system ClassLoaders
return context;
} // findClassLoader():ClassLoader
/**
* Create an instance of a class using the specified ClassLoader
*/
static Object newInstance(String className, ClassLoader cl,
boolean doFallback)
throws ConfigurationError
{
// assert(className != null);
try{
Class providerClass = findProviderClass(className, cl, doFallback);
Object instance = providerClass.newInstance();
if (DEBUG) debugPrintln("created new instance of " + providerClass +
" using ClassLoader: " + cl);
return instance;
} catch (ClassNotFoundException x) {
throw new ConfigurationError(
"Provider " + className + " not found", x);
} catch (Exception x) {
throw new ConfigurationError(
"Provider " + className + " could not be instantiated: " + x,
x);
}
}
/**
* Find a Class using the specified ClassLoader
*/
static Class findProviderClass(String className, ClassLoader cl,
boolean doFallback)
throws ClassNotFoundException, ConfigurationError
{
//throw security exception if the calling thread is not allowed to access the
//class. Restrict the access to the package classes as specified in java.security policy.
SecurityManager security = System.getSecurityManager();
try{
if (security != null){
final int lastDot = className.lastIndexOf(".");
String packageName = className;
if (lastDot != -1) packageName = className.substring(0, lastDot);
security.checkPackageAccess(packageName);
}
}catch(SecurityException e){
throw e;
}
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);
} else {
try {
providerClass = cl.loadClass(className);
} catch (ClassNotFoundException x) {
if (doFallback) {
// Fall back to current classloader
ClassLoader current = ObjectFactory.class.getClassLoader();
if (current == null) {
providerClass = Class.forName(className);
} else if (cl != current) {
cl = current;
providerClass = cl.loadClass(className);
} else {
throw x;
}
} else {
throw x;
}
}
}
return providerClass;
}
/**
* Find the name of service provider using Jar Service Provider Mechanism
*
* @return instance of provider class if found or null
*/
private static String findJarServiceProviderName(String factoryId)
{
SecuritySupport ss = SecuritySupport.getInstance();
String serviceId = SERVICES_PATH + factoryId;
InputStream is = null;
// First try the Context ClassLoader
ClassLoader cl = findClassLoader();
is = ss.getResourceAsStream(cl, serviceId);
// If no provider found then try the current ClassLoader
if (is == null) {
ClassLoader current = ObjectFactory.class.getClassLoader();
if (cl != current) {
cl = current;
is = ss.getResourceAsStream(cl, serviceId);
}
}
if (is == null) {
// No provider found
return null;
}
if (DEBUG) debugPrintln("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 {
rd = new BufferedReader(new InputStreamReader(is, "UTF-8"));
} catch (java.io.UnsupportedEncodingException e) {
rd = new BufferedReader(new InputStreamReader(is));
}
String factoryClassName = null;
try {
// XXX Does not handle all possible input as specified by the
// Jar Service Provider specification
factoryClassName = rd.readLine();
} catch (IOException x) {
// No provider found
return null;
}
finally {
try {
// try to close the reader.
rd.close();
}
// Ignore the exception.
catch (IOException exc) {}
}
if (factoryClassName != null &&
! "".equals(factoryClassName)) {
if (DEBUG) debugPrintln("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 factoryClassName;
}
// No provider found
return null;
}
//
// Classes
//
/**
* A configuration error.
*/
static class ConfigurationError
extends Error {
static final long serialVersionUID = -5948733402959678002L;
//
// Data
//
/** Exception. */
private Exception exception;
//
// Constructors
//
/**
* Construct a new instance with the specified detail string and
* exception.
*/
ConfigurationError(String msg, Exception x) {
super(msg);
this.exception = x;
} // <init>(String,Exception)
//
// Public methods
//
/** Returns the exception associated to this error. */
Exception getException() {
return exception;
} // getException():Exception
} // class ConfigurationError
} // class ObjectFactory

View file

@ -1,127 +0,0 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 2002-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: SecuritySupport.java,v 1.2.4.1 2005/09/06 10:03:40 pvedula Exp $
*/
package com.sun.org.apache.xalan.internal.xsltc.dom;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.Properties;
/**
* This class is duplicated for each Xalan-Java subpackage so keep it in sync.
* It is package private and therefore is not exposed as part of the Xalan-Java
* 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.
*/
static SecuritySupport getInstance() {
return (SecuritySupport)securitySupport;
}
ClassLoader getContextClassLoader() {
return null;
}
ClassLoader getSystemClassLoader() {
return null;
}
ClassLoader getParentClassLoader(ClassLoader cl) {
return null;
}
String getSystemProperty(String propName) {
return System.getProperty(propName);
}
FileInputStream getFileInputStream(File file)
throws FileNotFoundException
{
return new FileInputStream(file);
}
InputStream getResourceAsStream(ClassLoader cl, String name) {
InputStream ris;
if (cl == null) {
ris = ClassLoader.getSystemResourceAsStream(name);
} else {
ris = cl.getResourceAsStream(name);
}
return ris;
}
boolean getFileExists(File f) {
return f.exists();
}
long getLastModified(File f) {
return f.lastModified();
}
}

View file

@ -1,148 +0,0 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 2002-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: SecuritySupport12.java,v 1.2.4.1 2005/09/06 10:06:07 pvedula Exp $
*/
package com.sun.org.apache.xalan.internal.xsltc.dom;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.util.Properties;
/**
* This class is duplicated for each Xalan-Java subpackage so keep it in sync.
* It is package private and therefore is not exposed as part of the Xalan-Java
* API.
*
* Security related methods that only work on J2SE 1.2 and newer.
*/
class SecuritySupport12 extends SecuritySupport {
ClassLoader getContextClassLoader() {
return (ClassLoader)
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
ClassLoader cl = null;
try {
cl = Thread.currentThread().getContextClassLoader();
} catch (SecurityException ex) { }
return cl;
}
});
}
ClassLoader getSystemClassLoader() {
return (ClassLoader)
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
ClassLoader cl = null;
try {
cl = ClassLoader.getSystemClassLoader();
} catch (SecurityException ex) {}
return cl;
}
});
}
ClassLoader getParentClassLoader(final ClassLoader cl) {
return (ClassLoader)
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
ClassLoader parent = null;
try {
parent = cl.getParent();
} catch (SecurityException ex) {}
// eliminate loops in case of the boot
// ClassLoader returning itself as a parent
return (parent == cl) ? null : parent;
}
});
}
String getSystemProperty(final String propName) {
return (String)
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
return System.getProperty(propName);
}
});
}
FileInputStream getFileInputStream(final File file)
throws FileNotFoundException
{
try {
return (FileInputStream)
AccessController.doPrivileged(new PrivilegedExceptionAction() {
public Object run() throws FileNotFoundException {
return new FileInputStream(file);
}
});
} catch (PrivilegedActionException e) {
throw (FileNotFoundException)e.getException();
}
}
InputStream getResourceAsStream(final ClassLoader cl,
final String name)
{
return (InputStream)
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
InputStream ris;
if (cl == null) {
ris = ClassLoader.getSystemResourceAsStream(name);
} else {
ris = cl.getResourceAsStream(name);
}
return ris;
}
});
}
boolean getFileExists(final File f) {
return ((Boolean)
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
return new Boolean(f.exists());
}
})).booleanValue();
}
long getLastModified(final File f) {
return ((Long)
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
return new Long(f.lastModified());
}
})).longValue();
}
}

View file

@ -42,6 +42,7 @@ import com.sun.org.apache.xml.internal.utils.SystemIDResolver;
import com.sun.org.apache.xalan.internal.xsltc.trax.DOM2SAX;
import com.sun.org.apache.xalan.internal.xsltc.trax.StAXEvent2SAX;
import com.sun.org.apache.xalan.internal.xsltc.trax.StAXStream2SAX;
import com.sun.org.apache.xalan.internal.utils.ObjectFactory;
import org.xml.sax.InputSource;
import org.xml.sax.SAXNotRecognizedException;
@ -102,9 +103,22 @@ public class XSLTCDTMManager extends DTMManagerDefault
* The default is <code>com.sun.org.apache.xalan.internal.xsltc.dom.XSLTCDTMManager</code>.
*/
public static Class getDTMManagerClass() {
Class mgrClass = ObjectFactory.lookUpFactoryClass(DEFAULT_PROP_NAME,
return getDTMManagerClass(true);
}
public static Class getDTMManagerClass(boolean useServicesMechanism) {
Class mgrClass = null;
if (useServicesMechanism) {
mgrClass = ObjectFactory.lookUpFactoryClass(DEFAULT_PROP_NAME,
null,
DEFAULT_CLASS_NAME);
} else {
try {
mgrClass = ObjectFactory.findProviderClass(DEFAULT_CLASS_NAME, true);
} catch (Exception e) {
//will not happen
}
}
// If no class found, default to this one. (This should never happen -
// the ObjectFactory has already been told that the current class is
// the default).

View file

@ -23,6 +23,7 @@
package com.sun.org.apache.xalan.internal.xsltc.runtime;
import com.sun.org.apache.xalan.internal.utils.FactoryImpl;
import java.io.File;
import java.io.FileOutputStream;
import java.io.BufferedOutputStream;
@ -66,6 +67,8 @@ public abstract class AbstractTranslet implements Translet {
public String _encoding = "UTF-8";
public boolean _omitHeader = false;
public String _standalone = null;
//see OutputPropertiesFactory.ORACLE_IS_STANDALONE
public boolean _isStandalone = false;
public String _doctypePublic = null;
public String _doctypeSystem = null;
public boolean _indent = false;
@ -105,6 +108,7 @@ public abstract class AbstractTranslet implements Translet {
// This is the name of the index used for ID attributes
private final static String ID_INDEX_NAME = "##id";
private boolean _useServicesMechanism;
/************************************************************************
* Debugging
@ -669,6 +673,7 @@ public abstract class AbstractTranslet implements Translet {
if (_doctypeSystem != null) {
handler.setDoctype(_doctypeSystem, _doctypePublic);
}
handler.setIsStandalone(_isStandalone);
}
else if (_method.equals("html")) {
handler.setIndent(_indent);
@ -691,6 +696,7 @@ public abstract class AbstractTranslet implements Translet {
}
handler.setIndent(_indent);
handler.setDoctype(_doctypeSystem, _doctypePublic);
handler.setIsStandalone(_isStandalone);
}
}
@ -738,6 +744,19 @@ public abstract class AbstractTranslet implements Translet {
public void setTemplates(Templates templates) {
_templates = templates;
}
/**
* Return the state of the services mechanism feature.
*/
public boolean useServicesMechnism() {
return _useServicesMechanism;
}
/**
* Set the state of the services mechanism feature.
*/
public void setServicesMechnism(boolean flag) {
_useServicesMechanism = flag;
}
/************************************************************************
* DOMImplementation caching for basis library
@ -748,8 +767,8 @@ public abstract class AbstractTranslet implements Translet {
throws ParserConfigurationException
{
if (_domImplementation == null) {
_domImplementation = DocumentBuilderFactory.newInstance()
.newDocumentBuilder().getDOMImplementation();
DocumentBuilderFactory dbf = FactoryImpl.getDOMFactory(_useServicesMechanism);
_domImplementation = dbf.newDocumentBuilder().getDOMImplementation();
}
return _domImplementation.createDocument(uri, qname, null);
}

View file

@ -40,12 +40,17 @@ import com.sun.org.apache.xalan.internal.xsltc.dom.DOMAdapter;
import com.sun.org.apache.xalan.internal.xsltc.dom.MultiDOM;
import com.sun.org.apache.xalan.internal.xsltc.dom.SingletonIterator;
import com.sun.org.apache.xalan.internal.xsltc.dom.StepIterator;
import com.sun.org.apache.xalan.internal.xsltc.dom.ArrayNodeListIterator;
import com.sun.org.apache.xml.internal.dtm.DTM;
import com.sun.org.apache.xml.internal.dtm.DTMAxisIterator;
import com.sun.org.apache.xml.internal.dtm.DTMManager;
import com.sun.org.apache.xml.internal.dtm.ref.DTMDefaultBase;
import com.sun.org.apache.xml.internal.dtm.ref.DTMNodeProxy;
import org.w3c.dom.DOMException;
import org.w3c.dom.Attr;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
import com.sun.org.apache.xml.internal.serializer.NamespaceMappings;
@ -153,7 +158,7 @@ public final class BasisLibrary {
return dom.getStringValueX(((Node)obj).node);
}
else if (obj instanceof DOM) {
// When the first argument is a DOM we want the whole fecking
// When the first argument is a DOM we want the whole
// DOM and not just a single node - that would not make sense.
//return ((DOM)obj).getStringValueX(node);
return ((DOM)obj).getStringValue();
@ -1003,7 +1008,7 @@ public final class BasisLibrary {
}
// Convert var/param -> node-set
else if (obj instanceof DTMAxisIterator) {
return(((DTMAxisIterator)obj).cloneIterator());
return(((DTMAxisIterator)obj).cloneIterator().reset());
}
else {
final String className = obj.getClass().getName();
@ -1143,90 +1148,42 @@ public final class BasisLibrary {
}
/**
* Utility function used to copy a node list to be under a parent node.
* In a perfect world, this would be the implementation for
* nodeList2Iterator. In reality, though, this causes a
* ClassCastException in getDTMHandleFromNode because SAXImpl is
* not an instance of DOM2DTM. So we use the more lengthy
* implementation below until this issue has been addressed.
*
* @see org.apache.xml.dtm.ref.DTMManagerDefault#getDTMHandleFromNode
*/
private static void copyNodes(org.w3c.dom.NodeList nodeList,
org.w3c.dom.Document doc, org.w3c.dom.Node parent)
private static DTMAxisIterator nodeList2IteratorUsingHandleFromNode(
org.w3c.dom.NodeList nodeList,
Translet translet, DOM dom)
{
final int size = nodeList.getLength();
// copy Nodes from NodeList into new w3c DOM
for (int i = 0; i < size; i++)
{
org.w3c.dom.Node curr = nodeList.item(i);
int nodeType = curr.getNodeType();
String value = null;
try {
value = curr.getNodeValue();
} catch (DOMException ex) {
runTimeError(RUN_TIME_INTERNAL_ERR, ex.getMessage());
return;
final int n = nodeList.getLength();
final int[] dtmHandles = new int[n];
DTMManager dtmManager = null;
if (dom instanceof MultiDOM)
dtmManager = ((MultiDOM) dom).getDTMManager();
for (int i = 0; i < n; ++i) {
org.w3c.dom.Node node = nodeList.item(i);
int handle;
if (dtmManager != null) {
handle = dtmManager.getDTMHandleFromNode(node);
}
String nodeName = curr.getNodeName();
org.w3c.dom.Node newNode = null;
switch (nodeType){
case org.w3c.dom.Node.ATTRIBUTE_NODE:
newNode = doc.createAttributeNS(curr.getNamespaceURI(),
nodeName);
break;
case org.w3c.dom.Node.CDATA_SECTION_NODE:
newNode = doc.createCDATASection(value);
break;
case org.w3c.dom.Node.COMMENT_NODE:
newNode = doc.createComment(value);
break;
case org.w3c.dom.Node.DOCUMENT_FRAGMENT_NODE:
newNode = doc.createDocumentFragment();
break;
case org.w3c.dom.Node.DOCUMENT_NODE:
newNode = doc.createElementNS(null, "__document__");
copyNodes(curr.getChildNodes(), doc, newNode);
break;
case org.w3c.dom.Node.DOCUMENT_TYPE_NODE:
// nothing?
break;
case org.w3c.dom.Node.ELEMENT_NODE:
// For Element node, also copy the children and the
// attributes.
org.w3c.dom.Element element = doc.createElementNS(
curr.getNamespaceURI(), nodeName);
if (curr.hasAttributes())
{
org.w3c.dom.NamedNodeMap attributes = curr.getAttributes();
for (int k = 0; k < attributes.getLength(); k++) {
org.w3c.dom.Node attr = attributes.item(k);
element.setAttributeNS(attr.getNamespaceURI(),
attr.getNodeName(), attr.getNodeValue());
}
}
copyNodes(curr.getChildNodes(), doc, element);
newNode = element;
break;
case org.w3c.dom.Node.ENTITY_NODE:
// nothing ?
break;
case org.w3c.dom.Node.ENTITY_REFERENCE_NODE:
newNode = doc.createEntityReference(nodeName);
break;
case org.w3c.dom.Node.NOTATION_NODE:
// nothing ?
break;
case org.w3c.dom.Node.PROCESSING_INSTRUCTION_NODE:
newNode = doc.createProcessingInstruction(nodeName,
value);
break;
case org.w3c.dom.Node.TEXT_NODE:
newNode = doc.createTextNode(value);
break;
else if (node instanceof DTMNodeProxy
&& ((DTMNodeProxy) node).getDTM() == dom) {
handle = ((DTMNodeProxy) node).getDTMNodeNumber();
}
try {
parent.appendChild(newNode);
} catch (DOMException e) {
runTimeError(RUN_TIME_INTERNAL_ERR, e.getMessage());
return;
else {
runTimeError(RUN_TIME_INTERNAL_ERR, "need MultiDOM");
return null;
}
dtmHandles[i] = handle;
System.out.println("Node " + i + " has handle 0x" +
Integer.toString(handle, 16));
}
return new ArrayNodeListIterator(dtmHandles);
}
/**
@ -1237,26 +1194,93 @@ public final class BasisLibrary {
org.w3c.dom.NodeList nodeList,
Translet translet, DOM dom)
{
// w3c NodeList -> w3c DOM
// First pass: build w3c DOM for all nodes not proxied from our DOM.
//
// Notice: this looses some (esp. parent) context for these nodes,
// so some way to wrap the original nodes inside a DTMAxisIterator
// might be preferable in the long run.
int n = 0; // allow for change in list length, just in case.
Document doc = null;
try {
doc = ((AbstractTranslet) translet).newDocument("", "__top__");
DTMManager dtmManager = null;
int[] proxyNodes = new int[nodeList.getLength()];
if (dom instanceof MultiDOM)
dtmManager = ((MultiDOM) dom).getDTMManager();
for (int i = 0; i < nodeList.getLength(); ++i) {
org.w3c.dom.Node node = nodeList.item(i);
if (node instanceof DTMNodeProxy) {
DTMNodeProxy proxy = (DTMNodeProxy)node;
DTM nodeDTM = proxy.getDTM();
int handle = proxy.getDTMNodeNumber();
boolean isOurDOM = (nodeDTM == dom);
if (!isOurDOM && dtmManager != null) {
try {
isOurDOM = (nodeDTM == dtmManager.getDTM(handle));
}
catch (ArrayIndexOutOfBoundsException e) {
// invalid node handle, so definitely not our doc
}
}
if (isOurDOM) {
proxyNodes[i] = handle;
++n;
continue;
}
}
proxyNodes[i] = DTM.NULL;
int nodeType = node.getNodeType();
if (doc == null) {
if (dom instanceof MultiDOM == false) {
runTimeError(RUN_TIME_INTERNAL_ERR, "need MultiDOM");
return null;
}
try {
AbstractTranslet at = (AbstractTranslet) translet;
doc = at.newDocument("", "__top__");
}
catch (javax.xml.parsers.ParserConfigurationException e) {
runTimeError(RUN_TIME_INTERNAL_ERR, e.getMessage());
return null;
}
}
// Use one dummy element as container for each node of the
// list. That way, it is easier to detect resp. avoid
// funny things which change the number of nodes,
// e.g. auto-concatenation of text nodes.
Element mid;
switch (nodeType) {
case org.w3c.dom.Node.ELEMENT_NODE:
case org.w3c.dom.Node.TEXT_NODE:
case org.w3c.dom.Node.CDATA_SECTION_NODE:
case org.w3c.dom.Node.COMMENT_NODE:
case org.w3c.dom.Node.ENTITY_REFERENCE_NODE:
case org.w3c.dom.Node.PROCESSING_INSTRUCTION_NODE:
mid = doc.createElementNS(null, "__dummy__");
mid.appendChild(doc.importNode(node, true));
doc.getDocumentElement().appendChild(mid);
++n;
break;
case org.w3c.dom.Node.ATTRIBUTE_NODE:
// The mid element also serves as a container for
// attributes, avoiding problems with conflicting
// attributes or node order.
mid = doc.createElementNS(null, "__dummy__");
mid.setAttributeNodeNS((Attr)doc.importNode(node, true));
doc.getDocumentElement().appendChild(mid);
++n;
break;
default:
// Better play it safe for all types we aren't sure we know
// how to deal with.
runTimeError(RUN_TIME_INTERNAL_ERR,
"Don't know how to convert node type "
+ nodeType);
}
}
catch (javax.xml.parsers.ParserConfigurationException e) {
runTimeError(RUN_TIME_INTERNAL_ERR, e.getMessage());
return null;
}
// Copy all the nodes in the nodelist to be under the top element
copyNodes(nodeList, doc, doc.getDocumentElement());
// w3cDOM -> DTM -> DOMImpl
if (dom instanceof MultiDOM) {
DTMAxisIterator iter = null, childIter = null, attrIter = null;
if (doc != null) {
final MultiDOM multiDOM = (MultiDOM) dom;
DTMDefaultBase dtm = (DTMDefaultBase)((DOMAdapter)multiDOM.getMain()).getDOMImpl();
DTMManager dtmManager = dtm.getManager();
DOM idom = (DOM)dtmManager.getDTM(new DOMSource(doc), false,
null, true, false);
// Create DOMAdapter and register with MultiDOM
@ -1269,16 +1293,57 @@ public final class BasisLibrary {
DTMAxisIterator iter1 = idom.getAxisIterator(Axis.CHILD);
DTMAxisIterator iter2 = idom.getAxisIterator(Axis.CHILD);
DTMAxisIterator iter = new AbsoluteIterator(
iter = new AbsoluteIterator(
new StepIterator(iter1, iter2));
iter.setStartNode(DTMDefaultBase.ROOTNODE);
return iter;
childIter = idom.getAxisIterator(Axis.CHILD);
attrIter = idom.getAxisIterator(Axis.ATTRIBUTE);
}
else {
runTimeError(RUN_TIME_INTERNAL_ERR, "nodeList2Iterator()");
return null;
// Second pass: find DTM handles for every node in the list.
int[] dtmHandles = new int[n];
n = 0;
for (int i = 0; i < nodeList.getLength(); ++i) {
if (proxyNodes[i] != DTM.NULL) {
dtmHandles[n++] = proxyNodes[i];
continue;
}
org.w3c.dom.Node node = nodeList.item(i);
DTMAxisIterator iter3 = null;
int nodeType = node.getNodeType();
switch (nodeType) {
case org.w3c.dom.Node.ELEMENT_NODE:
case org.w3c.dom.Node.TEXT_NODE:
case org.w3c.dom.Node.CDATA_SECTION_NODE:
case org.w3c.dom.Node.COMMENT_NODE:
case org.w3c.dom.Node.ENTITY_REFERENCE_NODE:
case org.w3c.dom.Node.PROCESSING_INSTRUCTION_NODE:
iter3 = childIter;
break;
case org.w3c.dom.Node.ATTRIBUTE_NODE:
iter3 = attrIter;
break;
default:
// Should not happen, as first run should have got all these
throw new InternalRuntimeError("Mismatched cases");
}
if (iter3 != null) {
iter3.setStartNode(iter.next());
dtmHandles[n] = iter3.next();
// For now, play it self and perform extra checks:
if (dtmHandles[n] == DTMAxisIterator.END)
throw new InternalRuntimeError("Expected element missing at " + i);
if (iter3.next() != DTMAxisIterator.END)
throw new InternalRuntimeError("Too many elements at " + i);
++n;
}
}
if (n != dtmHandles.length)
throw new InternalRuntimeError("Nodes lost in second pass");
return new ArrayNodeListIterator(dtmHandles);
}
/**

View file

@ -294,7 +294,7 @@ public class Hashtable {
for (i = 0; i <= max; i++) {
String s1 = k.nextElement().toString();
String s2 = e.nextElement().toString();
buf.append(s1 + "=" + s2);
buf.append(s1).append('=').append(s2);
if (i < max) buf.append(", ");
}
buf.append("}");

View file

@ -0,0 +1,36 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 2001-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: InternalRuntimeError.java,v 1.0 2009-11-25 04:34:28 joehw Exp $
*/
package com.sun.org.apache.xalan.internal.xsltc.runtime;
/**
* Class to express failed assertions and similar for the xsltc runtime.
* As java.lang.AssertionError was introduced in JDK 1.4 we can't use that yet.
*/
public class InternalRuntimeError extends Error {
public InternalRuntimeError(String message) {
super(message);
}
}

View file

@ -1,663 +0,0 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 2001-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: ObjectFactory.java,v 1.2.4.1 2005/09/12 12:01:33 pvedula Exp $
*/
package com.sun.org.apache.xalan.internal.xsltc.runtime;
import java.io.InputStream;
import java.io.IOException;
import java.io.File;
import java.io.FileInputStream;
import java.util.Properties;
import java.io.BufferedReader;
import java.io.InputStreamReader;
/**
* This class is duplicated for each JAXP subpackage so keep it in sync.
* It is package private and therefore is not exposed as part of the JAXP
* API.
* <p>
* This code is designed to implement the JAXP 1.1 spec pluggability
* feature and is designed to run on JDK version 1.1 and
* later, and to compile on JDK 1.2 and onward.
* The code also runs both as part of an unbundled jar file and
* when bundled as part of the JDK.
* <p>
* This class was moved from the <code>javax.xml.parsers.ObjectFactory</code>
* class and modified to be used as a general utility for creating objects
* dynamically.
*
* @version $Id: ObjectFactory.java,v 1.9 2008/04/02 00:40:59 joehw Exp $
*/
class ObjectFactory {
//
// Constants
//
// name of default properties file to look for in JDK's jre/lib directory
private static final String DEFAULT_PROPERTIES_FILENAME =
"xalan.properties";
private static final String SERVICES_PATH = "META-INF/services/";
/** Set to true for debugging */
private static final boolean DEBUG = false;
/** cache the contents of the xalan.properties file.
* Until an attempt has been made to read this file, this will
* be null; if the file does not exist or we encounter some other error
* during the read, this will be empty.
*/
private static Properties fXalanProperties = null;
/***
* Cache the time stamp of the xalan.properties file so
* that we know if it's been modified and can invalidate
* the cache when necessary.
*/
private static long fLastModified = -1;
//
// Public static methods
//
/**
* Finds the implementation Class object in the specified order. The
* specified order is the following:
* <ol>
* <li>query the system property using <code>System.getProperty</code>
* <li>read <code>META-INF/services/<i>factoryId</i></code> file
* <li>use fallback classname
* </ol>
*
* @return instance of factory, never null
*
* @param factoryId Name of the factory to find, same as
* a property name
* @param fallbackClassName Implementation class name, if nothing else
* is found. Use null to mean no fallback.
*
* @exception ObjectFactory.ConfigurationError
*/
static Object createObject(String factoryId, String fallbackClassName)
throws ConfigurationError {
return createObject(factoryId, null, fallbackClassName);
} // createObject(String,String):Object
/**
* Finds the implementation Class object in the specified order. The
* specified order is the following:
* <ol>
* <li>query the system property using <code>System.getProperty</code>
* <li>read <code>$java.home/lib/<i>propertiesFilename</i></code> file
* <li>read <code>META-INF/services/<i>factoryId</i></code> file
* <li>use fallback classname
* </ol>
*
* @return instance of factory, never null
*
* @param factoryId Name of the factory to find, same as
* a property name
* @param propertiesFilename The filename in the $java.home/lib directory
* of the properties file. If none specified,
* ${java.home}/lib/xalan.properties will be used.
* @param fallbackClassName Implementation class name, if nothing else
* is found. Use null to mean no fallback.
*
* @exception ObjectFactory.ConfigurationError
*/
static Object createObject(String factoryId,
String propertiesFilename,
String fallbackClassName)
throws ConfigurationError
{
Class factoryClass = lookUpFactoryClass(factoryId,
propertiesFilename,
fallbackClassName);
if (factoryClass == null) {
throw new ConfigurationError(
"Provider for " + factoryId + " cannot be found", null);
}
try{
Object instance = factoryClass.newInstance();
if (DEBUG) debugPrintln("created new instance of factory " + factoryId);
return instance;
} catch (Exception x) {
throw new ConfigurationError(
"Provider for factory " + factoryId
+ " could not be instantiated: " + x, x);
}
} // createObject(String,String,String):Object
/**
* Finds the implementation Class object in the specified order. The
* specified order is the following:
* <ol>
* <li>query the system property using <code>System.getProperty</code>
* <li>read <code>$java.home/lib/<i>propertiesFilename</i></code> file
* <li>read <code>META-INF/services/<i>factoryId</i></code> file
* <li>use fallback classname
* </ol>
*
* @return Class object of factory, never null
*
* @param factoryId Name of the factory to find, same as
* a property name
* @param propertiesFilename The filename in the $java.home/lib directory
* of the properties file. If none specified,
* ${java.home}/lib/xalan.properties will be used.
* @param fallbackClassName Implementation class name, if nothing else
* is found. Use null to mean no fallback.
*
* @exception ObjectFactory.ConfigurationError
*/
static Class lookUpFactoryClass(String factoryId)
throws ConfigurationError
{
return lookUpFactoryClass(factoryId, null, null);
} // lookUpFactoryClass(String):Class
/**
* Finds the implementation Class object in the specified order. The
* specified order is the following:
* <ol>
* <li>query the system property using <code>System.getProperty</code>
* <li>read <code>$java.home/lib/<i>propertiesFilename</i></code> file
* <li>read <code>META-INF/services/<i>factoryId</i></code> file
* <li>use fallback classname
* </ol>
*
* @return Class object that provides factory service, never null
*
* @param factoryId Name of the factory to find, same as
* a property name
* @param propertiesFilename The filename in the $java.home/lib directory
* of the properties file. If none specified,
* ${java.home}/lib/xalan.properties will be used.
* @param fallbackClassName Implementation class name, if nothing else
* is found. Use null to mean no fallback.
*
* @exception ObjectFactory.ConfigurationError
*/
static Class lookUpFactoryClass(String factoryId,
String propertiesFilename,
String fallbackClassName)
throws ConfigurationError
{
String factoryClassName = lookUpFactoryClassName(factoryId,
propertiesFilename,
fallbackClassName);
ClassLoader cl = findClassLoader();
if (factoryClassName == null) {
factoryClassName = fallbackClassName;
}
// assert(className != null);
try{
Class providerClass = findProviderClass(factoryClassName,
cl,
true);
if (DEBUG) debugPrintln("created new instance of " + providerClass +
" using ClassLoader: " + cl);
return providerClass;
} catch (ClassNotFoundException x) {
throw new ConfigurationError(
"Provider " + factoryClassName + " not found", x);
} catch (Exception x) {
throw new ConfigurationError(
"Provider "+factoryClassName+" could not be instantiated: "+x,
x);
}
} // lookUpFactoryClass(String,String,String):Class
/**
* Finds the name of the required implementation class in the specified
* order. The specified order is the following:
* <ol>
* <li>query the system property using <code>System.getProperty</code>
* <li>read <code>$java.home/lib/<i>propertiesFilename</i></code> file
* <li>read <code>META-INF/services/<i>factoryId</i></code> file
* <li>use fallback classname
* </ol>
*
* @return name of class that provides factory service, never null
*
* @param factoryId Name of the factory to find, same as
* a property name
* @param propertiesFilename The filename in the $java.home/lib directory
* of the properties file. If none specified,
* ${java.home}/lib/xalan.properties will be used.
* @param fallbackClassName Implementation class name, if nothing else
* is found. Use null to mean no fallback.
*
* @exception ObjectFactory.ConfigurationError
*/
static String lookUpFactoryClassName(String factoryId,
String propertiesFilename,
String fallbackClassName)
{
SecuritySupport ss = SecuritySupport.getInstance();
// Use the system property first
try {
String systemProp = ss.getSystemProperty(factoryId);
if (systemProp != null) {
if (DEBUG) debugPrintln("found system property, value=" + systemProp);
return systemProp;
}
} catch (SecurityException se) {
// Ignore and continue w/ next location
}
// Try to read from propertiesFilename, or
// $java.home/lib/xalan.properties
String factoryClassName = null;
// no properties file name specified; use
// $JAVA_HOME/lib/xalan.properties:
if (propertiesFilename == null) {
File propertiesFile = null;
boolean propertiesFileExists = false;
try {
String javah = ss.getSystemProperty("java.home");
propertiesFilename = javah + File.separator +
"lib" + File.separator + DEFAULT_PROPERTIES_FILENAME;
propertiesFile = new File(propertiesFilename);
propertiesFileExists = ss.getFileExists(propertiesFile);
} catch (SecurityException e) {
// try again...
fLastModified = -1;
fXalanProperties = null;
}
synchronized (ObjectFactory.class) {
boolean loadProperties = false;
FileInputStream fis = null;
try {
// file existed last time
if(fLastModified >= 0) {
if(propertiesFileExists &&
(fLastModified < (fLastModified = ss.getLastModified(propertiesFile)))) {
loadProperties = true;
} else {
// file has stopped existing...
if(!propertiesFileExists) {
fLastModified = -1;
fXalanProperties = null;
} // else, file wasn't modified!
}
} else {
// file has started to exist:
if(propertiesFileExists) {
loadProperties = true;
fLastModified = ss.getLastModified(propertiesFile);
} // else, nothing's changed
}
if(loadProperties) {
// must never have attempted to read xalan.properties
// before (or it's outdeated)
fXalanProperties = new Properties();
fis = ss.getFileInputStream(propertiesFile);
fXalanProperties.load(fis);
}
} catch (Exception x) {
fXalanProperties = null;
fLastModified = -1;
// assert(x instanceof FileNotFoundException
// || x instanceof SecurityException)
// In both cases, ignore and continue w/ next location
}
finally {
// try to close the input stream if one was opened.
if (fis != null) {
try {
fis.close();
}
// Ignore the exception.
catch (IOException exc) {}
}
}
}
if(fXalanProperties != null) {
factoryClassName = fXalanProperties.getProperty(factoryId);
}
} else {
FileInputStream fis = null;
try {
fis = ss.getFileInputStream(new File(propertiesFilename));
Properties props = new Properties();
props.load(fis);
factoryClassName = props.getProperty(factoryId);
} catch (Exception x) {
// assert(x instanceof FileNotFoundException
// || x instanceof SecurityException)
// In both cases, ignore and continue w/ next location
}
finally {
// try to close the input stream if one was opened.
if (fis != null) {
try {
fis.close();
}
// Ignore the exception.
catch (IOException exc) {}
}
}
}
if (factoryClassName != null) {
if (DEBUG) debugPrintln("found in " + propertiesFilename + ", value="
+ factoryClassName);
return factoryClassName;
}
// Try Jar Service Provider Mechanism
return findJarServiceProviderName(factoryId);
} // lookUpFactoryClass(String,String):String
//
// Private static methods
//
/** Prints a message to standard error if debugging is enabled. */
private static void debugPrintln(String msg) {
if (DEBUG) {
System.err.println("JAXP: " + msg);
}
} // debugPrintln(String)
/**
* Figure out which ClassLoader to use. For JDK 1.2 and later use
* the context ClassLoader.
*/
static ClassLoader findClassLoader()
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 context = ss.getContextClassLoader();
ClassLoader system = ss.getSystemClassLoader();
ClassLoader chain = system;
while (true) {
if (context == chain) {
// Assert: we are on JDK 1.1 or we have no Context ClassLoader
// or any Context ClassLoader in chain of system classloader
// (including extension ClassLoader) so extend to widest
// ClassLoader (always look in system ClassLoader if Xalan
// is in boot/extension/system classpath and in current
// ClassLoader otherwise); normal classloaders delegate
// back to system ClassLoader first so this widening doesn't
// change the fact that context ClassLoader will be consulted
ClassLoader current = ObjectFactory.class.getClassLoader();
chain = system;
while (true) {
if (current == chain) {
// Assert: Current ClassLoader in chain of
// boot/extension/system ClassLoaders
return system;
}
if (chain == null) {
break;
}
chain = ss.getParentClassLoader(chain);
}
// Assert: Current ClassLoader not in chain of
// boot/extension/system ClassLoaders
return current;
}
if (chain == null) {
// boot ClassLoader reached
break;
}
// Check for any extension ClassLoaders in chain up to
// boot ClassLoader
chain = ss.getParentClassLoader(chain);
};
// Assert: Context ClassLoader not in chain of
// boot/extension/system ClassLoaders
return context;
} // findClassLoader():ClassLoader
/**
* Create an instance of a class using the specified ClassLoader
*/
static Object newInstance(String className, ClassLoader cl,
boolean doFallback)
throws ConfigurationError
{
// assert(className != null);
try{
Class providerClass = findProviderClass(className, cl, doFallback);
Object instance = providerClass.newInstance();
if (DEBUG) debugPrintln("created new instance of " + providerClass +
" using ClassLoader: " + cl);
return instance;
} catch (ClassNotFoundException x) {
throw new ConfigurationError(
"Provider " + className + " not found", x);
} catch (Exception x) {
throw new ConfigurationError(
"Provider " + className + " could not be instantiated: " + x,
x);
}
}
/**
* Find a Class using the specified ClassLoader
*/
static Class findProviderClass(String className, ClassLoader cl,
boolean doFallback)
throws ClassNotFoundException, ConfigurationError
{
//throw security exception if the calling thread is not allowed to access the
//class. Restrict the access to the package classes as specified in java.security policy.
SecurityManager security = System.getSecurityManager();
try{
if (security != null){
final int lastDot = className.lastIndexOf(".");
String packageName = className;
if (lastDot != -1) packageName = className.substring(0, lastDot);
security.checkPackageAccess(packageName);
}
}catch(SecurityException e){
throw e;
}
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);
} else {
try {
providerClass = cl.loadClass(className);
} catch (ClassNotFoundException x) {
if (doFallback) {
// Fall back to current classloader
ClassLoader current = ObjectFactory.class.getClassLoader();
if (current == null) {
providerClass = Class.forName(className);
} else if (cl != current) {
cl = current;
providerClass = cl.loadClass(className);
} else {
throw x;
}
} else {
throw x;
}
}
}
return providerClass;
}
/**
* Find the name of service provider using Jar Service Provider Mechanism
*
* @return instance of provider class if found or null
*/
private static String findJarServiceProviderName(String factoryId)
{
SecuritySupport ss = SecuritySupport.getInstance();
String serviceId = SERVICES_PATH + factoryId;
InputStream is = null;
// First try the Context ClassLoader
ClassLoader cl = findClassLoader();
is = ss.getResourceAsStream(cl, serviceId);
// If no provider found then try the current ClassLoader
if (is == null) {
ClassLoader current = ObjectFactory.class.getClassLoader();
if (cl != current) {
cl = current;
is = ss.getResourceAsStream(cl, serviceId);
}
}
if (is == null) {
// No provider found
return null;
}
if (DEBUG) debugPrintln("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 {
rd = new BufferedReader(new InputStreamReader(is, "UTF-8"));
} catch (java.io.UnsupportedEncodingException e) {
rd = new BufferedReader(new InputStreamReader(is));
}
String factoryClassName = null;
try {
// XXX Does not handle all possible input as specified by the
// Jar Service Provider specification
factoryClassName = rd.readLine();
} catch (IOException x) {
// No provider found
return null;
}
finally {
try {
// try to close the reader.
rd.close();
}
// Ignore the exception.
catch (IOException exc) {}
}
if (factoryClassName != null &&
! "".equals(factoryClassName)) {
if (DEBUG) debugPrintln("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 factoryClassName;
}
// No provider found
return null;
}
//
// Classes
//
/**
* A configuration error.
*/
static class ConfigurationError
extends Error {
static final long serialVersionUID = -2293620736651286953L;
//
// Data
//
/** Exception. */
private Exception exception;
//
// Constructors
//
/**
* Construct a new instance with the specified detail string and
* exception.
*/
ConfigurationError(String msg, Exception x) {
super(msg);
this.exception = x;
} // <init>(String,Exception)
//
// Public methods
//
/** Returns the exception associated to this error. */
Exception getException() {
return exception;
} // getException():Exception
} // class ConfigurationError
} // class ObjectFactory

View file

@ -1,127 +0,0 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 2002-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: SecuritySupport.java,v 1.2.4.1 2005/09/06 11:28:13 pvedula Exp $
*/
package com.sun.org.apache.xalan.internal.xsltc.runtime;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.Properties;
/**
* This class is duplicated for each Xalan-Java subpackage so keep it in sync.
* It is package private and therefore is not exposed as part of the Xalan-Java
* 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.
*/
static SecuritySupport getInstance() {
return (SecuritySupport)securitySupport;
}
ClassLoader getContextClassLoader() {
return null;
}
ClassLoader getSystemClassLoader() {
return null;
}
ClassLoader getParentClassLoader(ClassLoader cl) {
return null;
}
String getSystemProperty(String propName) {
return System.getProperty(propName);
}
FileInputStream getFileInputStream(File file)
throws FileNotFoundException
{
return new FileInputStream(file);
}
InputStream getResourceAsStream(ClassLoader cl, String name) {
InputStream ris;
if (cl == null) {
ris = ClassLoader.getSystemResourceAsStream(name);
} else {
ris = cl.getResourceAsStream(name);
}
return ris;
}
boolean getFileExists(File f) {
return f.exists();
}
long getLastModified(File f) {
return f.lastModified();
}
}

View file

@ -1,148 +0,0 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 2002-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: SecuritySupport12.java,v 1.2.4.1 2005/09/06 11:31:16 pvedula Exp $
*/
package com.sun.org.apache.xalan.internal.xsltc.runtime;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.util.Properties;
/**
* This class is duplicated for each Xalan-Java subpackage so keep it in sync.
* It is package private and therefore is not exposed as part of the Xalan-Java
* API.
*
* Security related methods that only work on J2SE 1.2 and newer.
*/
class SecuritySupport12 extends SecuritySupport {
ClassLoader getContextClassLoader() {
return (ClassLoader)
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
ClassLoader cl = null;
try {
cl = Thread.currentThread().getContextClassLoader();
} catch (SecurityException ex) { }
return cl;
}
});
}
ClassLoader getSystemClassLoader() {
return (ClassLoader)
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
ClassLoader cl = null;
try {
cl = ClassLoader.getSystemClassLoader();
} catch (SecurityException ex) {}
return cl;
}
});
}
ClassLoader getParentClassLoader(final ClassLoader cl) {
return (ClassLoader)
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
ClassLoader parent = null;
try {
parent = cl.getParent();
} catch (SecurityException ex) {}
// eliminate loops in case of the boot
// ClassLoader returning itself as a parent
return (parent == cl) ? null : parent;
}
});
}
String getSystemProperty(final String propName) {
return (String)
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
return System.getProperty(propName);
}
});
}
FileInputStream getFileInputStream(final File file)
throws FileNotFoundException
{
try {
return (FileInputStream)
AccessController.doPrivileged(new PrivilegedExceptionAction() {
public Object run() throws FileNotFoundException {
return new FileInputStream(file);
}
});
} catch (PrivilegedActionException e) {
throw (FileNotFoundException)e.getException();
}
}
InputStream getResourceAsStream(final ClassLoader cl,
final String name)
{
return (InputStream)
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
InputStream ris;
if (cl == null) {
ris = ClassLoader.getSystemResourceAsStream(name);
} else {
ris = cl.getResourceAsStream(name);
}
return ris;
}
});
}
boolean getFileExists(final File f) {
return ((Boolean)
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
return new Boolean(f.exists());
}
})).booleanValue();
}
long getLastModified(final File f) {
return ((Long)
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
return new Long(f.lastModified());
}
})).longValue();
}
}

View file

@ -72,10 +72,18 @@ public class TransletOutputHandlerFactory {
private ContentHandler _handler = null;
private LexicalHandler _lexHandler = null;
private boolean _useServicesMechanism;
static public TransletOutputHandlerFactory newInstance() {
return new TransletOutputHandlerFactory();
return new TransletOutputHandlerFactory(true);
}
static public TransletOutputHandlerFactory newInstance(boolean useServicesMechanism) {
return new TransletOutputHandlerFactory(useServicesMechanism);
}
public TransletOutputHandlerFactory(boolean useServicesMechanism) {
_useServicesMechanism = useServicesMechanism;
}
public void setOutputType(int outputType) {
_outputType = outputType;
}
@ -188,7 +196,7 @@ public class TransletOutputHandlerFactory {
return result;
case DOM :
_handler = (_node != null) ? new SAX2DOM(_node, _nextSibling) : new SAX2DOM();
_handler = (_node != null) ? new SAX2DOM(_node, _nextSibling, _useServicesMechanism) : new SAX2DOM(_useServicesMechanism);
_lexHandler = (LexicalHandler) _handler;
// falls through
case STAX :

View file

@ -1,663 +0,0 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 2001-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: ObjectFactory.java,v 1.2.4.1 2005/09/12 12:05:22 pvedula Exp $
*/
package com.sun.org.apache.xalan.internal.xsltc.trax;
import java.io.InputStream;
import java.io.IOException;
import java.io.File;
import java.io.FileInputStream;
import java.util.Properties;
import java.io.BufferedReader;
import java.io.InputStreamReader;
/**
* This class is duplicated for each JAXP subpackage so keep it in sync.
* It is package private and therefore is not exposed as part of the JAXP
* API.
* <p>
* This code is designed to implement the JAXP 1.1 spec pluggability
* feature and is designed to run on JDK version 1.1 and
* later, and to compile on JDK 1.2 and onward.
* The code also runs both as part of an unbundled jar file and
* when bundled as part of the JDK.
* <p>
* This class was moved from the <code>javax.xml.parsers.ObjectFactory</code>
* class and modified to be used as a general utility for creating objects
* dynamically.
*
* @version $Id: ObjectFactory.java,v 1.9 2008/04/02 00:41:02 joehw Exp $
*/
class ObjectFactory {
//
// Constants
//
// name of default properties file to look for in JDK's jre/lib directory
private static final String DEFAULT_PROPERTIES_FILENAME =
"xalan.properties";
private static final String SERVICES_PATH = "META-INF/services/";
/** Set to true for debugging */
private static final boolean DEBUG = false;
/** cache the contents of the xalan.properties file.
* Until an attempt has been made to read this file, this will
* be null; if the file does not exist or we encounter some other error
* during the read, this will be empty.
*/
private static Properties fXalanProperties = null;
/***
* Cache the time stamp of the xalan.properties file so
* that we know if it's been modified and can invalidate
* the cache when necessary.
*/
private static long fLastModified = -1;
//
// Public static methods
//
/**
* Finds the implementation Class object in the specified order. The
* specified order is the following:
* <ol>
* <li>query the system property using <code>System.getProperty</code>
* <li>read <code>META-INF/services/<i>factoryId</i></code> file
* <li>use fallback classname
* </ol>
*
* @return instance of factory, never null
*
* @param factoryId Name of the factory to find, same as
* a property name
* @param fallbackClassName Implementation class name, if nothing else
* is found. Use null to mean no fallback.
*
* @exception ObjectFactory.ConfigurationError
*/
static Object createObject(String factoryId, String fallbackClassName)
throws ConfigurationError {
return createObject(factoryId, null, fallbackClassName);
} // createObject(String,String):Object
/**
* Finds the implementation Class object in the specified order. The
* specified order is the following:
* <ol>
* <li>query the system property using <code>System.getProperty</code>
* <li>read <code>$java.home/lib/<i>propertiesFilename</i></code> file
* <li>read <code>META-INF/services/<i>factoryId</i></code> file
* <li>use fallback classname
* </ol>
*
* @return instance of factory, never null
*
* @param factoryId Name of the factory to find, same as
* a property name
* @param propertiesFilename The filename in the $java.home/lib directory
* of the properties file. If none specified,
* ${java.home}/lib/xalan.properties will be used.
* @param fallbackClassName Implementation class name, if nothing else
* is found. Use null to mean no fallback.
*
* @exception ObjectFactory.ConfigurationError
*/
static Object createObject(String factoryId,
String propertiesFilename,
String fallbackClassName)
throws ConfigurationError
{
Class factoryClass = lookUpFactoryClass(factoryId,
propertiesFilename,
fallbackClassName);
if (factoryClass == null) {
throw new ConfigurationError(
"Provider for " + factoryId + " cannot be found", null);
}
try{
Object instance = factoryClass.newInstance();
if (DEBUG) debugPrintln("created new instance of factory " + factoryId);
return instance;
} catch (Exception x) {
throw new ConfigurationError(
"Provider for factory " + factoryId
+ " could not be instantiated: " + x, x);
}
} // createObject(String,String,String):Object
/**
* Finds the implementation Class object in the specified order. The
* specified order is the following:
* <ol>
* <li>query the system property using <code>System.getProperty</code>
* <li>read <code>$java.home/lib/<i>propertiesFilename</i></code> file
* <li>read <code>META-INF/services/<i>factoryId</i></code> file
* <li>use fallback classname
* </ol>
*
* @return Class object of factory, never null
*
* @param factoryId Name of the factory to find, same as
* a property name
* @param propertiesFilename The filename in the $java.home/lib directory
* of the properties file. If none specified,
* ${java.home}/lib/xalan.properties will be used.
* @param fallbackClassName Implementation class name, if nothing else
* is found. Use null to mean no fallback.
*
* @exception ObjectFactory.ConfigurationError
*/
static Class lookUpFactoryClass(String factoryId)
throws ConfigurationError
{
return lookUpFactoryClass(factoryId, null, null);
} // lookUpFactoryClass(String):Class
/**
* Finds the implementation Class object in the specified order. The
* specified order is the following:
* <ol>
* <li>query the system property using <code>System.getProperty</code>
* <li>read <code>$java.home/lib/<i>propertiesFilename</i></code> file
* <li>read <code>META-INF/services/<i>factoryId</i></code> file
* <li>use fallback classname
* </ol>
*
* @return Class object that provides factory service, never null
*
* @param factoryId Name of the factory to find, same as
* a property name
* @param propertiesFilename The filename in the $java.home/lib directory
* of the properties file. If none specified,
* ${java.home}/lib/xalan.properties will be used.
* @param fallbackClassName Implementation class name, if nothing else
* is found. Use null to mean no fallback.
*
* @exception ObjectFactory.ConfigurationError
*/
static Class lookUpFactoryClass(String factoryId,
String propertiesFilename,
String fallbackClassName)
throws ConfigurationError
{
String factoryClassName = lookUpFactoryClassName(factoryId,
propertiesFilename,
fallbackClassName);
ClassLoader cl = findClassLoader();
if (factoryClassName == null) {
factoryClassName = fallbackClassName;
}
// assert(className != null);
try{
Class providerClass = findProviderClass(factoryClassName,
cl,
true);
if (DEBUG) debugPrintln("created new instance of " + providerClass +
" using ClassLoader: " + cl);
return providerClass;
} catch (ClassNotFoundException x) {
throw new ConfigurationError(
"Provider " + factoryClassName + " not found", x);
} catch (Exception x) {
throw new ConfigurationError(
"Provider "+factoryClassName+" could not be instantiated: "+x,
x);
}
} // lookUpFactoryClass(String,String,String):Class
/**
* Finds the name of the required implementation class in the specified
* order. The specified order is the following:
* <ol>
* <li>query the system property using <code>System.getProperty</code>
* <li>read <code>$java.home/lib/<i>propertiesFilename</i></code> file
* <li>read <code>META-INF/services/<i>factoryId</i></code> file
* <li>use fallback classname
* </ol>
*
* @return name of class that provides factory service, never null
*
* @param factoryId Name of the factory to find, same as
* a property name
* @param propertiesFilename The filename in the $java.home/lib directory
* of the properties file. If none specified,
* ${java.home}/lib/xalan.properties will be used.
* @param fallbackClassName Implementation class name, if nothing else
* is found. Use null to mean no fallback.
*
* @exception ObjectFactory.ConfigurationError
*/
static String lookUpFactoryClassName(String factoryId,
String propertiesFilename,
String fallbackClassName)
{
SecuritySupport ss = SecuritySupport.getInstance();
// Use the system property first
try {
String systemProp = ss.getSystemProperty(factoryId);
if (systemProp != null) {
if (DEBUG) debugPrintln("found system property, value=" + systemProp);
return systemProp;
}
} catch (SecurityException se) {
// Ignore and continue w/ next location
}
// Try to read from propertiesFilename, or
// $java.home/lib/xalan.properties
String factoryClassName = null;
// no properties file name specified; use
// $JAVA_HOME/lib/xalan.properties:
if (propertiesFilename == null) {
File propertiesFile = null;
boolean propertiesFileExists = false;
try {
String javah = ss.getSystemProperty("java.home");
propertiesFilename = javah + File.separator +
"lib" + File.separator + DEFAULT_PROPERTIES_FILENAME;
propertiesFile = new File(propertiesFilename);
propertiesFileExists = ss.getFileExists(propertiesFile);
} catch (SecurityException e) {
// try again...
fLastModified = -1;
fXalanProperties = null;
}
synchronized (ObjectFactory.class) {
boolean loadProperties = false;
FileInputStream fis = null;
try {
// file existed last time
if(fLastModified >= 0) {
if(propertiesFileExists &&
(fLastModified < (fLastModified = ss.getLastModified(propertiesFile)))) {
loadProperties = true;
} else {
// file has stopped existing...
if(!propertiesFileExists) {
fLastModified = -1;
fXalanProperties = null;
} // else, file wasn't modified!
}
} else {
// file has started to exist:
if(propertiesFileExists) {
loadProperties = true;
fLastModified = ss.getLastModified(propertiesFile);
} // else, nothing's changed
}
if(loadProperties) {
// must never have attempted to read xalan.properties
// before (or it's outdeated)
fXalanProperties = new Properties();
fis = ss.getFileInputStream(propertiesFile);
fXalanProperties.load(fis);
}
} catch (Exception x) {
fXalanProperties = null;
fLastModified = -1;
// assert(x instanceof FileNotFoundException
// || x instanceof SecurityException)
// In both cases, ignore and continue w/ next location
}
finally {
// try to close the input stream if one was opened.
if (fis != null) {
try {
fis.close();
}
// Ignore the exception.
catch (IOException exc) {}
}
}
}
if(fXalanProperties != null) {
factoryClassName = fXalanProperties.getProperty(factoryId);
}
} else {
FileInputStream fis = null;
try {
fis = ss.getFileInputStream(new File(propertiesFilename));
Properties props = new Properties();
props.load(fis);
factoryClassName = props.getProperty(factoryId);
} catch (Exception x) {
// assert(x instanceof FileNotFoundException
// || x instanceof SecurityException)
// In both cases, ignore and continue w/ next location
}
finally {
// try to close the input stream if one was opened.
if (fis != null) {
try {
fis.close();
}
// Ignore the exception.
catch (IOException exc) {}
}
}
}
if (factoryClassName != null) {
if (DEBUG) debugPrintln("found in " + propertiesFilename + ", value="
+ factoryClassName);
return factoryClassName;
}
// Try Jar Service Provider Mechanism
return findJarServiceProviderName(factoryId);
} // lookUpFactoryClass(String,String):String
//
// Private static methods
//
/** Prints a message to standard error if debugging is enabled. */
private static void debugPrintln(String msg) {
if (DEBUG) {
System.err.println("JAXP: " + msg);
}
} // debugPrintln(String)
/**
* Figure out which ClassLoader to use. For JDK 1.2 and later use
* the context ClassLoader.
*/
static ClassLoader findClassLoader()
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 context = ss.getContextClassLoader();
ClassLoader system = ss.getSystemClassLoader();
ClassLoader chain = system;
while (true) {
if (context == chain) {
// Assert: we are on JDK 1.1 or we have no Context ClassLoader
// or any Context ClassLoader in chain of system classloader
// (including extension ClassLoader) so extend to widest
// ClassLoader (always look in system ClassLoader if Xalan
// is in boot/extension/system classpath and in current
// ClassLoader otherwise); normal classloaders delegate
// back to system ClassLoader first so this widening doesn't
// change the fact that context ClassLoader will be consulted
ClassLoader current = ObjectFactory.class.getClassLoader();
chain = system;
while (true) {
if (current == chain) {
// Assert: Current ClassLoader in chain of
// boot/extension/system ClassLoaders
return system;
}
if (chain == null) {
break;
}
chain = ss.getParentClassLoader(chain);
}
// Assert: Current ClassLoader not in chain of
// boot/extension/system ClassLoaders
return current;
}
if (chain == null) {
// boot ClassLoader reached
break;
}
// Check for any extension ClassLoaders in chain up to
// boot ClassLoader
chain = ss.getParentClassLoader(chain);
};
// Assert: Context ClassLoader not in chain of
// boot/extension/system ClassLoaders
return context;
} // findClassLoader():ClassLoader
/**
* Create an instance of a class using the specified ClassLoader
*/
static Object newInstance(String className, ClassLoader cl,
boolean doFallback)
throws ConfigurationError
{
// assert(className != null);
try{
Class providerClass = findProviderClass(className, cl, doFallback);
Object instance = providerClass.newInstance();
if (DEBUG) debugPrintln("created new instance of " + providerClass +
" using ClassLoader: " + cl);
return instance;
} catch (ClassNotFoundException x) {
throw new ConfigurationError(
"Provider " + className + " not found", x);
} catch (Exception x) {
throw new ConfigurationError(
"Provider " + className + " could not be instantiated: " + x,
x);
}
}
/**
* Find a Class using the specified ClassLoader
*/
static Class findProviderClass(String className, ClassLoader cl,
boolean doFallback)
throws ClassNotFoundException, ConfigurationError
{
//throw security exception if the calling thread is not allowed to access the
//class. Restrict the access to the package classes as specified in java.security policy.
SecurityManager security = System.getSecurityManager();
try{
if (security != null){
final int lastDot = className.lastIndexOf(".");
String packageName = className;
if (lastDot != -1) packageName = className.substring(0, lastDot);
security.checkPackageAccess(packageName);
}
}catch(SecurityException e){
throw e;
}
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);
} else {
try {
providerClass = cl.loadClass(className);
} catch (ClassNotFoundException x) {
if (doFallback) {
// Fall back to current classloader
ClassLoader current = ObjectFactory.class.getClassLoader();
if (current == null) {
providerClass = Class.forName(className);
} else if (cl != current) {
cl = current;
providerClass = cl.loadClass(className);
} else {
throw x;
}
} else {
throw x;
}
}
}
return providerClass;
}
/**
* Find the name of service provider using Jar Service Provider Mechanism
*
* @return instance of provider class if found or null
*/
private static String findJarServiceProviderName(String factoryId)
{
SecuritySupport ss = SecuritySupport.getInstance();
String serviceId = SERVICES_PATH + factoryId;
InputStream is = null;
// First try the Context ClassLoader
ClassLoader cl = findClassLoader();
is = ss.getResourceAsStream(cl, serviceId);
// If no provider found then try the current ClassLoader
if (is == null) {
ClassLoader current = ObjectFactory.class.getClassLoader();
if (cl != current) {
cl = current;
is = ss.getResourceAsStream(cl, serviceId);
}
}
if (is == null) {
// No provider found
return null;
}
if (DEBUG) debugPrintln("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 {
rd = new BufferedReader(new InputStreamReader(is, "UTF-8"));
} catch (java.io.UnsupportedEncodingException e) {
rd = new BufferedReader(new InputStreamReader(is));
}
String factoryClassName = null;
try {
// XXX Does not handle all possible input as specified by the
// Jar Service Provider specification
factoryClassName = rd.readLine();
} catch (IOException x) {
// No provider found
return null;
}
finally {
try {
// try to close the reader.
rd.close();
}
// Ignore the exception.
catch (IOException exc) {}
}
if (factoryClassName != null &&
! "".equals(factoryClassName)) {
if (DEBUG) debugPrintln("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 factoryClassName;
}
// No provider found
return null;
}
//
// Classes
//
/**
* A configuration error.
*/
static class ConfigurationError
extends Error {
static final long serialVersionUID = -1877553852268428278L;
//
// Data
//
/** Exception. */
private Exception exception;
//
// Constructors
//
/**
* Construct a new instance with the specified detail string and
* exception.
*/
ConfigurationError(String msg, Exception x) {
super(msg);
this.exception = x;
} // <init>(String,Exception)
//
// Public methods
//
/** Returns the exception associated to this error. */
Exception getException() {
return exception;
} // getException():Exception
} // class ConfigurationError
} // class ObjectFactory

View file

@ -49,6 +49,7 @@ import org.xml.sax.ext.Locator2;
/**
* @author G. Todd Miller
* @author Sunitha Reddy
* @author Huizhe Wang
*/
public class SAX2DOM implements ContentHandler, LexicalHandler, Constants {
@ -69,27 +70,16 @@ public class SAX2DOM implements ContentHandler, LexicalHandler, Constants {
* synchronization because the Javadoc is not explicit about
* thread safety.
*/
static final DocumentBuilderFactory _factory =
private DocumentBuilderFactory _factory =
DocumentBuilderFactory.newInstance();
static final DocumentBuilder _internalBuilder;
static {
DocumentBuilder tmpBuilder = null;
try {
if (_factory instanceof com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl) {
tmpBuilder = _factory.newDocumentBuilder();
}
} catch(Exception e) {
// It's OK. Will create DocumentBuilder every time
}
_internalBuilder = tmpBuilder;
}
private boolean _internal = true;
public SAX2DOM() throws ParserConfigurationException {
_document = createDocument();
public SAX2DOM(boolean useServicesMachnism) throws ParserConfigurationException {
_document = createDocument(useServicesMachnism);
_root = _document;
}
public SAX2DOM(Node root, Node nextSibling) throws ParserConfigurationException {
public SAX2DOM(Node root, Node nextSibling, boolean useServicesMachnism) throws ParserConfigurationException {
_root = root;
if (root instanceof Document) {
_document = (Document)root;
@ -98,15 +88,15 @@ public class SAX2DOM implements ContentHandler, LexicalHandler, Constants {
_document = root.getOwnerDocument();
}
else {
_document = createDocument();
_document = createDocument(useServicesMachnism);
_root = _document;
}
_nextSibling = nextSibling;
}
public SAX2DOM(Node root) throws ParserConfigurationException {
this(root, null);
public SAX2DOM(Node root, boolean useServicesMachnism) throws ParserConfigurationException {
this(root, null, useServicesMachnism);
}
public Node getDOM() {
@ -318,11 +308,23 @@ public class SAX2DOM implements ContentHandler, LexicalHandler, Constants {
public void startDTD(String name, String publicId, String systemId)
throws SAXException {}
private static Document createDocument() throws ParserConfigurationException {
private Document createDocument(boolean useServicesMachnism) throws ParserConfigurationException {
if (_factory == null) {
if (useServicesMachnism)
_factory = DocumentBuilderFactory.newInstance();
if (!(_factory instanceof com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl)) {
_internal = false;
}
else
_factory = DocumentBuilderFactory.newInstance(
"com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl",
SAX2DOM.class.getClassLoader()
);
}
Document doc;
if (_internalBuilder != null) {
if (_internal) {
//default implementation is thread safe
doc = _internalBuilder.newDocument();
doc = _factory.newDocumentBuilder().newDocument();
} else {
synchronized(SAX2DOM.class) {
doc = _factory.newDocumentBuilder().newDocument();

View file

@ -1,127 +0,0 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 2002-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: SecuritySupport.java,v 1.2.4.1 2005/09/06 12:04:10 pvedula Exp $
*/
package com.sun.org.apache.xalan.internal.xsltc.trax;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.Properties;
/**
* This class is duplicated for each Xalan-Java subpackage so keep it in sync.
* It is package private and therefore is not exposed as part of the Xalan-Java
* 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.
*/
static SecuritySupport getInstance() {
return (SecuritySupport)securitySupport;
}
ClassLoader getContextClassLoader() {
return null;
}
ClassLoader getSystemClassLoader() {
return null;
}
ClassLoader getParentClassLoader(ClassLoader cl) {
return null;
}
String getSystemProperty(String propName) {
return System.getProperty(propName);
}
FileInputStream getFileInputStream(File file)
throws FileNotFoundException
{
return new FileInputStream(file);
}
InputStream getResourceAsStream(ClassLoader cl, String name) {
InputStream ris;
if (cl == null) {
ris = ClassLoader.getSystemResourceAsStream(name);
} else {
ris = cl.getResourceAsStream(name);
}
return ris;
}
boolean getFileExists(File f) {
return f.exists();
}
long getLastModified(File f) {
return f.lastModified();
}
}

View file

@ -1,148 +0,0 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 2002-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: SecuritySupport12.java,v 1.2.4.1 2005/09/06 12:05:26 pvedula Exp $
*/
package com.sun.org.apache.xalan.internal.xsltc.trax;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.util.Properties;
/**
* This class is duplicated for each Xalan-Java subpackage so keep it in sync.
* It is package private and therefore is not exposed as part of the Xalan-Java
* API.
*
* Security related methods that only work on J2SE 1.2 and newer.
*/
class SecuritySupport12 extends SecuritySupport {
ClassLoader getContextClassLoader() {
return (ClassLoader)
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
ClassLoader cl = null;
try {
cl = Thread.currentThread().getContextClassLoader();
} catch (SecurityException ex) { }
return cl;
}
});
}
ClassLoader getSystemClassLoader() {
return (ClassLoader)
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
ClassLoader cl = null;
try {
cl = ClassLoader.getSystemClassLoader();
} catch (SecurityException ex) {}
return cl;
}
});
}
ClassLoader getParentClassLoader(final ClassLoader cl) {
return (ClassLoader)
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
ClassLoader parent = null;
try {
parent = cl.getParent();
} catch (SecurityException ex) {}
// eliminate loops in case of the boot
// ClassLoader returning itself as a parent
return (parent == cl) ? null : parent;
}
});
}
String getSystemProperty(final String propName) {
return (String)
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
return System.getProperty(propName);
}
});
}
FileInputStream getFileInputStream(final File file)
throws FileNotFoundException
{
try {
return (FileInputStream)
AccessController.doPrivileged(new PrivilegedExceptionAction() {
public Object run() throws FileNotFoundException {
return new FileInputStream(file);
}
});
} catch (PrivilegedActionException e) {
throw (FileNotFoundException)e.getException();
}
}
InputStream getResourceAsStream(final ClassLoader cl,
final String name)
{
return (InputStream)
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
InputStream ris;
if (cl == null) {
ris = ClassLoader.getSystemResourceAsStream(name);
} else {
ris = cl.getResourceAsStream(name);
}
return ris;
}
});
}
boolean getFileExists(final File f) {
return ((Boolean)
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
return new Boolean(f.exists());
}
})).booleanValue();
}
long getLastModified(final File f) {
return ((Long)
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
return new Long(f.lastModified());
}
})).longValue();
}
}

View file

@ -43,6 +43,7 @@ import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg;
import com.sun.org.apache.xalan.internal.utils.ObjectFactory;
import org.xml.sax.XMLFilter;
/**
@ -93,7 +94,7 @@ public class SmartTransformerFactoryImpl extends SAXTransformerFactory
try {
Class xalanFactClass = ObjectFactory.findProviderClass(
"com.sun.org.apache.xalan.internal.processor.TransformerFactoryImpl",
ObjectFactory.findClassLoader(), true);
true);
_xalanFactory = (SAXTransformerFactory)
xalanFactClass.newInstance();
}

View file

@ -95,10 +95,15 @@ public class TemplatesHandlerImpl
_tfactory = tfactory;
// Instantiate XSLTC and get reference to parser object
XSLTC xsltc = new XSLTC();
XSLTC xsltc = new XSLTC(tfactory.useServicesMechnism());
if (tfactory.getFeature(XMLConstants.FEATURE_SECURE_PROCESSING))
xsltc.setSecureProcessing(true);
if ("true".equals(tfactory.getAttribute(TransformerFactoryImpl.ENABLE_INLINING)))
xsltc.setTemplateInlining(true);
else
xsltc.setTemplateInlining(false);
_parser = xsltc.getParser();
}
@ -188,7 +193,7 @@ public class TemplatesHandlerImpl
XSLTC xsltc = _parser.getXSLTC();
// Set the translet class name if not already set
String transletName = null;
String transletName;
if (_systemId != null) {
transletName = Util.baseName(_systemId);
}
@ -210,6 +215,11 @@ public class TemplatesHandlerImpl
stylesheet.setSystemId(_systemId);
stylesheet.setParentStylesheet(null);
if (xsltc.getTemplateInlining())
stylesheet.setTemplateInlining(true);
else
stylesheet.setTemplateInlining(false);
// Set a document loader (for xsl:include/import) if defined
if (_uriResolver != null) {
stylesheet.setSourceLoader(this);

View file

@ -42,6 +42,7 @@ import com.sun.org.apache.xalan.internal.xsltc.Translet;
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg;
import com.sun.org.apache.xalan.internal.xsltc.runtime.AbstractTranslet;
import com.sun.org.apache.xalan.internal.xsltc.runtime.Hashtable;
import com.sun.org.apache.xalan.internal.utils.ObjectFactory;
/**
* @author Morten Jorgensen
@ -118,6 +119,8 @@ public final class TemplatesImpl implements Templates, Serializable {
*/
private transient TransformerFactoryImpl _tfactory = null;
private boolean _useServicesMechanism;
static final class TransletClassLoader extends ClassLoader {
TransletClassLoader(ClassLoader parent) {
super(parent);
@ -142,10 +145,7 @@ public final class TemplatesImpl implements Templates, Serializable {
TransformerFactoryImpl tfactory)
{
_bytecodes = bytecodes;
_name = transletName;
_outputProperties = outputProperties;
_indentNumber = indentNumber;
_tfactory = tfactory;
init(transletName, outputProperties, indentNumber, tfactory);
}
/**
@ -156,14 +156,19 @@ public final class TemplatesImpl implements Templates, Serializable {
TransformerFactoryImpl tfactory)
{
_class = transletClasses;
_name = transletName;
_transletIndex = 0;
init(transletName, outputProperties, indentNumber, tfactory);
}
private void init(String transletName,
Properties outputProperties, int indentNumber,
TransformerFactoryImpl tfactory) {
_name = transletName;
_outputProperties = outputProperties;
_indentNumber = indentNumber;
_tfactory = tfactory;
_useServicesMechanism = tfactory.useServicesMechnism();
}
/**
* Need for de-serialization, see readObject().
*/
@ -207,6 +212,12 @@ public final class TemplatesImpl implements Templates, Serializable {
}
}
/**
* Return the state of the services mechanism feature.
*/
public boolean useServicesMechnism() {
return _useServicesMechanism;
}
/**
* Store URIResolver needed for Transformers.
@ -357,6 +368,7 @@ public final class TemplatesImpl implements Templates, Serializable {
AbstractTranslet translet = (AbstractTranslet) _class[_transletIndex].newInstance();
translet.postInitialization();
translet.setTemplates(this);
translet.setServicesMechnism(_useServicesMechanism);
if (_auxClasses != null) {
translet.setAuxiliaryClasses(_auxClasses);
}

View file

@ -55,6 +55,7 @@ public class TrAXFilter extends XMLFilterImpl {
private Templates _templates;
private TransformerImpl _transformer;
private TransformerHandlerImpl _transformerHandler;
private boolean _useServicesMechanism = true;
public TrAXFilter(Templates templates) throws
TransformerConfigurationException
@ -62,6 +63,7 @@ public class TrAXFilter extends XMLFilterImpl {
_templates = templates;
_transformer = (TransformerImpl) templates.newTransformer();
_transformerHandler = new TransformerHandlerImpl(_transformer);
_useServicesMechanism = _transformer.useServicesMechnism();
}
public Transformer getTransformer() {
@ -106,7 +108,7 @@ public class TrAXFilter extends XMLFilterImpl {
try {
if (getParent() == null) {
try {
managedReader = XMLReaderManager.getInstance()
managedReader = XMLReaderManager.getInstance(_useServicesMechanism)
.getXMLReader();
setParent(managedReader);
} catch (SAXException e) {
@ -118,7 +120,7 @@ public class TrAXFilter extends XMLFilterImpl {
getParent().parse(input);
} finally {
if (managedReader != null) {
XMLReaderManager.getInstance().releaseXMLReader(managedReader);
XMLReaderManager.getInstance(_useServicesMechanism).releaseXMLReader(managedReader);
}
}
}

View file

@ -49,6 +49,7 @@ import javax.xml.transform.Templates;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.URIResolver;
import javax.xml.transform.dom.DOMResult;
import javax.xml.transform.dom.DOMSource;
@ -64,11 +65,14 @@ import javax.xml.transform.stax.*;
import com.sun.org.apache.xml.internal.utils.StylesheetPIHandler;
import com.sun.org.apache.xml.internal.utils.StopParseException;
import com.sun.org.apache.xalan.internal.XalanConstants;
import com.sun.org.apache.xalan.internal.xsltc.compiler.Constants;
import com.sun.org.apache.xalan.internal.xsltc.compiler.SourceLoader;
import com.sun.org.apache.xalan.internal.xsltc.compiler.XSLTC;
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg;
import com.sun.org.apache.xalan.internal.xsltc.dom.XSLTCDTMManager;
import com.sun.org.apache.xalan.internal.utils.ObjectFactory;
import com.sun.org.apache.xalan.internal.utils.FactoryImpl;
import org.xml.sax.InputSource;
@ -212,11 +216,28 @@ public class TransformerFactoryImpl
* <p>State of secure mode.</p>
*/
private boolean _isSecureMode = false;
/**
* Indicates whether implementation parts should use
* service loader (or similar).
* Note the default value (false) is the safe option..
*/
private boolean _useServicesMechanism;
/**
* javax.xml.transform.sax.TransformerFactory implementation.
*/
public TransformerFactoryImpl() {
m_DTMManagerClass = XSLTCDTMManager.getDTMManagerClass();
this(true);
}
public static TransformerFactory newTransformerFactoryNoServiceLoader() {
return new TransformerFactoryImpl(false);
}
private TransformerFactoryImpl(boolean useServicesMechanism) {
this.m_DTMManagerClass = XSLTCDTMManager.getDTMManagerClass(useServicesMechanism);
this._useServicesMechanism = useServicesMechanism;
if (System.getSecurityManager() != null) {
_isSecureMode = true;
_isNotSecureProcessing = false;
@ -274,6 +295,12 @@ public class TransformerFactoryImpl
else if (name.equals(AUTO_TRANSLET)) {
return new Boolean(_autoTranslet);
}
else if (name.equals(ENABLE_INLINING)) {
if (_enableInlining)
return Boolean.TRUE;
else
return Boolean.FALSE;
}
// Throw an exception for all other attributes
ErrorMsg err = new ErrorMsg(ErrorMsg.JAXP_INVALID_ATTR_ERR, name);
@ -420,6 +447,11 @@ public class TransformerFactoryImpl
// all done processing feature
return;
}
else if (name.equals(XalanConstants.ORACLE_FEATURE_SERVICE_MECHANISM)) {
//in secure mode, let _useServicesMechanism be determined by the constructor
if (!_isSecureMode)
_useServicesMechanism = value;
}
else {
// unknown feature
ErrorMsg err = new ErrorMsg(ErrorMsg.JAXP_UNSUPPORTED_FEATURE, name);
@ -448,7 +480,8 @@ public class TransformerFactoryImpl
StreamSource.FEATURE,
StreamResult.FEATURE,
SAXTransformerFactory.FEATURE,
SAXTransformerFactory.FEATURE_XMLFILTER
SAXTransformerFactory.FEATURE_XMLFILTER,
XalanConstants.ORACLE_FEATURE_SERVICE_MECHANISM
};
// feature name cannot be null
@ -471,6 +504,12 @@ public class TransformerFactoryImpl
// Feature not supported
return false;
}
/**
* Return the state of the services mechanism feature.
*/
public boolean useServicesMechnism() {
return _useServicesMechanism;
}
/**
* javax.xml.transform.sax.TransformerFactory implementation.
@ -543,7 +582,7 @@ public class TransformerFactoryImpl
isource = SAXSource.sourceToInputSource(source);
baseId = isource.getSystemId();
SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParserFactory factory = FactoryImpl.getSAXFactory(_useServicesMechanism);
factory.setNamespaceAware(true);
if (!_isNotSecureProcessing) {
@ -702,8 +741,7 @@ public class TransformerFactoryImpl
transletName = _packageName + "." + transletName;
try {
final Class clazz = ObjectFactory.findProviderClass(
transletName, ObjectFactory.findClassLoader(), true);
final Class clazz = ObjectFactory.findProviderClass(transletName, true);
resetTransientAttributes();
return new TemplatesImpl(new Class[]{clazz}, transletName, null, _indentNumber, this);
@ -753,9 +791,13 @@ public class TransformerFactoryImpl
}
// Create and initialize a stylesheet compiler
final XSLTC xsltc = new XSLTC();
final XSLTC xsltc = new XSLTC(_useServicesMechanism);
if (_debug) xsltc.setDebug(true);
if (_enableInlining) xsltc.setTemplateInlining(true);
if (_enableInlining)
xsltc.setTemplateInlining(true);
else
xsltc.setTemplateInlining(false);
if (!_isNotSecureProcessing) xsltc.setSecureProcessing(true);
xsltc.init();

View file

@ -23,6 +23,7 @@
package com.sun.org.apache.xalan.internal.xsltc.trax;
import com.sun.org.apache.xalan.internal.utils.FactoryImpl;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
@ -182,7 +183,7 @@ public final class TransformerImpl extends Transformer
/**
* A reference to an object that creates and caches XMLReader objects.
*/
private XMLReaderManager _readerManager = XMLReaderManager.getInstance();
private XMLReaderManager _readerManager;
/**
* A flag indicating whether we use incremental building of the DTM.
@ -200,6 +201,13 @@ public final class TransformerImpl extends Transformer
*/
private boolean _isSecureProcessing = false;
/**
* Indicates whether implementation parts should use
* service loader (or similar).
* Note the default value (false) is the safe option..
*/
private boolean _useServicesMechanism;
/**
* A hashtable to store parameters for the identity transform. These
* are not needed during the transformation, but we must keep track of
@ -251,6 +259,8 @@ public final class TransformerImpl extends Transformer
_propertiesClone = (Properties) _properties.clone();
_indentNumber = indentNumber;
_tfactory = tfactory;
_useServicesMechanism = _tfactory.useServicesMechnism();
_readerManager = XMLReaderManager.getInstance(_useServicesMechanism);
//_isIncremental = tfactory._incremental;
}
@ -267,6 +277,19 @@ public final class TransformerImpl extends Transformer
public void setSecureProcessing(boolean flag) {
_isSecureProcessing = flag;
}
/**
* Return the state of the services mechanism feature.
*/
public boolean useServicesMechnism() {
return _useServicesMechanism;
}
/**
* Set the state of the services mechanism feature.
*/
public void setServicesMechnism(boolean flag) {
_useServicesMechanism = flag;
}
/**
* Returns the translet wrapped inside this Transformer or
@ -347,7 +370,7 @@ public final class TransformerImpl extends Transformer
// Get encoding using getProperty() to use defaults
_encoding = (String) _properties.getProperty(OutputKeys.ENCODING);
_tohFactory = TransletOutputHandlerFactory.newInstance();
_tohFactory = TransletOutputHandlerFactory.newInstance(_useServicesMechanism);
_tohFactory.setEncoding(_encoding);
if (_method != null) {
_tohFactory.setOutputMethod(_method);
@ -435,9 +458,7 @@ public final class TransformerImpl extends Transformer
// the systemId will be URI encoded as a result of File.toURI(),
// it must be decoded for use by URL
try{
Class clazz = ObjectFactory.findProviderClass("java.net.URI", ObjectFactory.findClassLoader(), true);
Constructor construct = clazz.getConstructor(new Class[] {java.lang.String.class} );
URI uri = (URI) construct.newInstance(new Object[]{systemId}) ;
URI uri = new URI(systemId) ;
systemId = "file:";
String host = uri.getHost(); // decoded String
@ -454,10 +475,6 @@ public final class TransformerImpl extends Transformer
systemId += "//" + path;
}
}
catch(ClassNotFoundException e){
// running on J2SE 1.3 which doesn't have URI Class so OK to ignore
//ClassNotFoundException.
}
catch (Exception exception) {
// URI exception which means nothing can be done so OK to ignore
}
@ -524,6 +541,7 @@ public final class TransformerImpl extends Transformer
_dtmManager =
(XSLTCDTMManager)_tfactory.getDTMManagerClass()
.newInstance();
_dtmManager.setServicesMechnism(_useServicesMechanism);
}
dom = (DOM)_dtmManager.getDTM(source, false, wsfilter, true,
false, false, 0, hasIdCall);
@ -695,10 +713,8 @@ public final class TransformerImpl extends Transformer
((SAXSource)source).getXMLReader()==null )||
(source instanceof DOMSource &&
((DOMSource)source).getNode()==null)){
DocumentBuilderFactory builderF =
DocumentBuilderFactory.newInstance();
DocumentBuilder builder =
builderF.newDocumentBuilder();
DocumentBuilderFactory builderF = FactoryImpl.getDOMFactory(_useServicesMechanism);
DocumentBuilder builder = builderF.newDocumentBuilder();
String systemID = source.getSystemId();
source = new DOMSource(builder.newDocument());
@ -974,6 +990,11 @@ public final class TransformerImpl extends Transformer
}
}
}
else if (name.equals(OutputPropertiesFactory.ORACLE_IS_STANDALONE)) {
if (value != null && value.equals("yes")) {
translet._isStandalone = true;
}
}
}
}
@ -1033,6 +1054,11 @@ public final class TransformerImpl extends Transformer
handler.setIndentAmount(Integer.parseInt(value));
}
}
else if (name.equals(OutputPropertiesFactory.ORACLE_IS_STANDALONE)) {
if (value != null && value.equals("yes")) {
handler.setIsStandalone(true);
}
}
else if (name.equals(OutputKeys.CDATA_SECTION_ELEMENTS)) {
if (value != null) {
StringTokenizer e = new StringTokenizer(value);
@ -1146,6 +1172,7 @@ public final class TransformerImpl extends Transformer
name.equals(OutputKeys.OMIT_XML_DECLARATION) ||
name.equals(OutputKeys.STANDALONE) ||
name.equals(OutputKeys.VERSION) ||
name.equals(OutputPropertiesFactory.ORACLE_IS_STANDALONE) ||
name.charAt(0) == '{');
}
@ -1252,7 +1279,7 @@ public final class TransformerImpl extends Transformer
try {
// Argument to document function was: document('');
if (href.length() == 0) {
href = new String(baseURI);
href = baseURI;
}
/*

View file

@ -42,6 +42,7 @@ import javax.xml.transform.stax.StAXResult;
import javax.xml.transform.stax.StAXSource;
import javax.xml.transform.stream.StreamSource;
import com.sun.org.apache.xalan.internal.utils.FactoryImpl;
import com.sun.org.apache.xalan.internal.xsltc.compiler.XSLTC;
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg;
@ -109,8 +110,7 @@ public final class Util {
//Incase there is an exception thrown
// resort to JAXP
SAXParserFactory parserFactory =
SAXParserFactory.newInstance();
SAXParserFactory parserFactory = FactoryImpl.getSAXFactory(xsltc.useServicesMechnism());
parserFactory.setNamespaceAware(true);
if (xsltc.isSecureProcessing()) {

View file

@ -21,7 +21,10 @@ package com.sun.org.apache.xerces.internal.dom;
import com.sun.org.apache.xerces.internal.impl.RevalidationHandler;
import com.sun.org.apache.xerces.internal.parsers.DOMParserImpl;
import com.sun.org.apache.xerces.internal.parsers.DTDConfiguration;
import com.sun.org.apache.xerces.internal.parsers.XIncludeAwareParserConfiguration;
import com.sun.org.apache.xerces.internal.util.XMLChar;
import com.sun.org.apache.xerces.internal.utils.ObjectFactory;
import com.sun.org.apache.xerces.internal.xni.grammars.XMLGrammarDescription;
import com.sun.org.apache.xml.internal.serialize.DOMSerializerImpl;
import org.w3c.dom.DOMException;
@ -49,6 +52,7 @@ import org.w3c.dom.ls.LSSerializer;
*
* @xerces.internal
*
* @version $Id: CoreDOMImplementationImpl.java,v 1.6 2010-11-01 04:39:37 joehw Exp $
* @since PR-DOM-Level-1-19980818.
*/
public class CoreDOMImplementationImpl
@ -114,8 +118,7 @@ public class CoreDOMImplementationImpl
&& (anyVersion || version.equals("3.0"))) {
try {
Class xpathClass = ObjectFactory.findProviderClass(
"com.sun.org.apache.xpath.internal.domapi.XPathEvaluatorImpl",
ObjectFactory.findClassLoader(), true);
"com.sun.org.apache.xpath.internal.domapi.XPathEvaluatorImpl", true);
// Check if the DOM XPath implementation implements
// the interface org.w3c.dom.XPathEvaluator
@ -281,9 +284,7 @@ public class CoreDOMImplementationImpl
if ((feature.equalsIgnoreCase("+XPath"))) {
try {
Class xpathClass = ObjectFactory.findProviderClass(
"com.sun.org.apache.xpath.internal.domapi.XPathEvaluatorImpl",
ObjectFactory.findClassLoader(), true);
"com.sun.org.apache.xpath.internal.domapi.XPathEvaluatorImpl", true);
// Check if the DOM XPath implementation implements
// the interface org.w3c.dom.XPathEvaluator
Class interfaces[] = xpathClass.getInterfaces();
@ -361,14 +362,12 @@ public class CoreDOMImplementationImpl
}
if (schemaType != null
&& schemaType.equals("http://www.w3.org/TR/REC-xml")) {
return new DOMParserImpl(
"com.sun.org.apache.xerces.internal.parsers.DTDConfiguration",
return new DOMParserImpl(new DTDConfiguration(),
schemaType);
}
else {
// create default parser configuration validating against XMLSchemas
return new DOMParserImpl(
"com.sun.org.apache.xerces.internal.parsers.XIncludeAwareParserConfiguration",
return new DOMParserImpl(new XIncludeAwareParserConfiguration(),
schemaType);
}
}

Some files were not shown because too many files have changed in this diff Show more