You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by gn...@apache.org on 2008/10/23 13:47:20 UTC
svn commit: r707355 [1/2] - in /servicemix/smx4/specs/trunk: ./
jaxp-api-1.3/ jaxp-api-1.3/src/ jaxp-api-1.3/src/main/
jaxp-api-1.3/src/main/java/ jaxp-api-1.3/src/main/java/javax/
jaxp-api-1.3/src/main/java/javax/xml/ jaxp-api-1.3/src/main/java/javax/...
Author: gnodet
Date: Thu Oct 23 04:47:18 2008
New Revision: 707355
URL: http://svn.apache.org/viewvc?rev=707355&view=rev
Log:
SMX4KNL-123: Add JAXP 1.3 API to the specs
Added:
servicemix/smx4/specs/trunk/jaxp-api-1.3/ (with props)
servicemix/smx4/specs/trunk/jaxp-api-1.3/pom.xml
servicemix/smx4/specs/trunk/jaxp-api-1.3/src/
servicemix/smx4/specs/trunk/jaxp-api-1.3/src/main/
servicemix/smx4/specs/trunk/jaxp-api-1.3/src/main/java/
servicemix/smx4/specs/trunk/jaxp-api-1.3/src/main/java/javax/
servicemix/smx4/specs/trunk/jaxp-api-1.3/src/main/java/javax/xml/
servicemix/smx4/specs/trunk/jaxp-api-1.3/src/main/java/javax/xml/datatype/
servicemix/smx4/specs/trunk/jaxp-api-1.3/src/main/java/javax/xml/datatype/FactoryFinder.java
servicemix/smx4/specs/trunk/jaxp-api-1.3/src/main/java/javax/xml/datatype/SecuritySupport.java
servicemix/smx4/specs/trunk/jaxp-api-1.3/src/main/java/javax/xml/parsers/
servicemix/smx4/specs/trunk/jaxp-api-1.3/src/main/java/javax/xml/parsers/FactoryFinder.java
servicemix/smx4/specs/trunk/jaxp-api-1.3/src/main/java/javax/xml/parsers/ScuritySupport.java
servicemix/smx4/specs/trunk/jaxp-api-1.3/src/main/java/javax/xml/transform/
servicemix/smx4/specs/trunk/jaxp-api-1.3/src/main/java/javax/xml/transform/FactoryFinder.java
servicemix/smx4/specs/trunk/jaxp-api-1.3/src/main/java/javax/xml/transform/SecuritySupport.java
servicemix/smx4/specs/trunk/jaxp-api-1.3/src/main/java/javax/xml/validation/
servicemix/smx4/specs/trunk/jaxp-api-1.3/src/main/java/javax/xml/validation/SchemaFactoryFinder.java
servicemix/smx4/specs/trunk/jaxp-api-1.3/src/main/java/javax/xml/validation/SecuritySupport.java
servicemix/smx4/specs/trunk/jaxp-api-1.3/src/main/java/javax/xml/xpath/
servicemix/smx4/specs/trunk/jaxp-api-1.3/src/main/java/javax/xml/xpath/SecuritySupport.java
servicemix/smx4/specs/trunk/jaxp-api-1.3/src/main/java/javax/xml/xpath/XPathFactoryFinder.java
servicemix/smx4/specs/trunk/jaxp-api-1.3/src/main/java/org/
servicemix/smx4/specs/trunk/jaxp-api-1.3/src/main/java/org/w3c/
servicemix/smx4/specs/trunk/jaxp-api-1.3/src/main/java/org/w3c/dom/
servicemix/smx4/specs/trunk/jaxp-api-1.3/src/main/java/org/w3c/dom/html/
servicemix/smx4/specs/trunk/jaxp-api-1.3/src/main/java/org/w3c/dom/html/HTMLDOMImplementation.java
servicemix/smx4/specs/trunk/jaxp-api-1.3/src/main/java/org/xml/
servicemix/smx4/specs/trunk/jaxp-api-1.3/src/main/java/org/xml/sax/
servicemix/smx4/specs/trunk/jaxp-api-1.3/src/main/java/org/xml/sax/helpers/
servicemix/smx4/specs/trunk/jaxp-api-1.3/src/main/java/org/xml/sax/helpers/XMLReaderFactory.java
Modified:
servicemix/smx4/specs/trunk/pom.xml
Propchange: servicemix/smx4/specs/trunk/jaxp-api-1.3/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Thu Oct 23 04:47:18 2008
@@ -0,0 +1,9 @@
+target
+*.iml
+*.ipr
+*.iws
+.classpath
+.project
+.settings
+
+
Added: servicemix/smx4/specs/trunk/jaxp-api-1.3/pom.xml
URL: http://svn.apache.org/viewvc/servicemix/smx4/specs/trunk/jaxp-api-1.3/pom.xml?rev=707355&view=auto
==============================================================================
--- servicemix/smx4/specs/trunk/jaxp-api-1.3/pom.xml (added)
+++ servicemix/smx4/specs/trunk/jaxp-api-1.3/pom.xml Thu Oct 23 04:47:18 2008
@@ -0,0 +1,174 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+ -->
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.servicemix.specs</groupId>
+ <artifactId>specs</artifactId>
+ <version>1.2-SNAPSHOT</version>
+ </parent>
+
+ <groupId>org.apache.servicemix.specs</groupId>
+ <artifactId>org.apache.servicemix.specs.jaxp-api-1.3</artifactId>
+ <packaging>bundle</packaging>
+ <version>1.2-SNAPSHOT</version>
+ <name>Apache ServiceMix Specs :: JAXP API 1.3</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.servicemix.specs</groupId>
+ <artifactId>org.apache.servicemix.specs.locator</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>xml-apis</groupId>
+ <artifactId>xml-apis</artifactId>
+ <version>1.3.04</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <configuration>
+ <instructions>
+ <Bundle-SymbolicName>${pom.artifactId}</Bundle-SymbolicName>
+ <Export-Package>
+ javax.xml*;version=1.3;-split-package:=merge-first,
+ org.w3c.dom*;version=1.0;-split-package:=merge-first,
+ org.xml.sax*;version=2.0.2;-split-package:=merge-first,
+ </Export-Package>
+ <Import-Package>
+ *
+ </Import-Package>
+ <Private-Package>org.apache.servicemix.specs.locator;-split-package:=merge-first</Private-Package>
+ <Bundle-Activator>org.apache.servicemix.specs.locator.Activator</Bundle-Activator>
+ <Implementation-Title>Apache ServiceMix</Implementation-Title>
+ <Implementation-Version>${project.version}</Implementation-Version>
+ </instructions>
+ <unpackBundle>true</unpackBundle>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-shade-plugin</artifactId>
+ <executions>
+ <execution>
+ <phase>package</phase>
+ <goals>
+ <goal>shade</goal>
+ </goals>
+ <configuration>
+ <artifactSet>
+ <includes>
+ <include>org.apache.servicemix.specs:org.apache.servicemix.specs.locator</include>
+ </includes>
+ </artifactSet>
+ <filters>
+ <filter>
+ <artifact>${project.groupId}:${project.artifactId}</artifact>
+ <excludes>
+ <exclude>org/apache/servicemix/**</exclude>
+ </excludes>
+ </filter>
+ </filters>
+ <createSourcesJar>${createSourcesJar}</createSourcesJar>
+ <promoteTransitiveDependencies>true</promoteTransitiveDependencies>
+ <createDependencyReducedPom>true</createDependencyReducedPom>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+
+ <profiles>
+ <profile>
+ <id>deploy</id>
+ <properties>
+ <createSourcesJar>true</createSourcesJar>
+ </properties>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-source-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>attach-sources</id>
+ <phase>process-classes</phase>
+ <goals>
+ <goal>jar</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-dependency-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>unpack-sources</id>
+ <phase>generate-sources</phase>
+ <goals>
+ <goal>unpack</goal>
+ </goals>
+ <configuration>
+ <artifactItems>
+ <artifactItem>
+ <groupId>org.apache.servicemix.specs</groupId>
+ <artifactId>org.apache.servicemix.specs.locator</artifactId>
+ <classifier>sources</classifier>
+ </artifactItem>
+ </artifactItems>
+ <outputDirectory>${project.build.directory}/sources</outputDirectory>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>package</id>
+ <phase>package</phase>
+ <goals>
+ <goal>jar</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <minmemory>128m</minmemory>
+ <maxmemory>512m</maxmemory>
+ <sourcepath>${project.build.directory}/sources</sourcepath>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ </profiles>
+
+</project>
Added: servicemix/smx4/specs/trunk/jaxp-api-1.3/src/main/java/javax/xml/datatype/FactoryFinder.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/specs/trunk/jaxp-api-1.3/src/main/java/javax/xml/datatype/FactoryFinder.java?rev=707355&view=auto
==============================================================================
--- servicemix/smx4/specs/trunk/jaxp-api-1.3/src/main/java/javax/xml/datatype/FactoryFinder.java (added)
+++ servicemix/smx4/specs/trunk/jaxp-api-1.3/src/main/java/javax/xml/datatype/FactoryFinder.java Thu Oct 23 04:47:18 2008
@@ -0,0 +1,396 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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: FactoryFinder.java 446598 2006-09-15 12:55:40Z jeremias $
+
+package javax.xml.datatype;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.URL;
+import java.util.Properties;
+
+/**
+ * <p>Implement pluggabile Datatypes.</p>
+ *
+ * <p>This class is duplicated for each JAXP subpackage so keep it in
+ * sync. It is package private for secure class loading.</p>
+ *
+ * @author <a href="mailto:Jeff.Suttor@Sun.com">Jeff Suttor</a>
+ * @version $Revision: 446598 $, $Date: 2006-09-15 08:55:40 -0400 (Fri, 15 Sep 2006) $
+ * @since 1.5
+ */
+final class FactoryFinder {
+
+ /**
+ * <p>Name of class to display in output messages.</p>
+ */
+ private static final String CLASS_NAME = "javax.xml.datatype.FactoryFinder";
+
+ /**
+ * <p>Debug flag to trace loading process.</p>
+ */
+ private static boolean debug = false;
+
+ /**
+ * <p>Cache properties for performance.</p>
+ */
+ private static Properties cacheProps = new Properties();
+
+ /**
+ * <p>First time requires initialization overhead.</p>
+ */
+ private static boolean firstTime = true;
+
+ /**
+ * Default columns per line.
+ */
+ private static final int DEFAULT_LINE_LENGTH = 80;
+
+ /**
+ * <p>Check to see if debugging enabled by property.</p>
+ *
+ * <p>Use try/catch block to support applets, which throws
+ * SecurityException out of this code.</p>
+ *
+ */
+ static {
+ try {
+ String val = SecuritySupport.getSystemProperty("jaxp.debug");
+ // Allow simply setting the prop to turn on debug
+ debug = val != null && (! "false".equals(val));
+ } catch (Exception x) {
+ debug = false;
+ }
+ }
+
+ private FactoryFinder() {}
+
+ /**
+ * <p>Output debugging messages.</p>
+ *
+ * @param msg <code>String</code> to print to <code>stderr</code>.
+ */
+ private static void debugPrintln(String msg) {
+ if (debug) {
+ System.err.println(
+ CLASS_NAME
+ + ":"
+ + msg);
+ }
+ }
+
+ /**
+ * <p>Find the appropriate <code>ClassLoader</code> to use.</p>
+ *
+ * <p>The context ClassLoader is prefered.</p>
+ *
+ * @return <code>ClassLoader</code> to use.
+ *
+ * @throws ConfigurationError If a valid <code>ClassLoader</code> cannot be identified.
+ */
+ private static ClassLoader findClassLoader()
+ throws ConfigurationError {
+ ClassLoader classLoader;
+
+ // Figure out which ClassLoader to use for loading the provider
+ // class. If there is a Context ClassLoader then use it.
+
+ classLoader = SecuritySupport.getContextClassLoader();
+
+ if (debug) debugPrintln(
+ "Using context class loader: "
+ + classLoader);
+
+ if (classLoader == null) {
+ // if we have no Context ClassLoader
+ // so use the current ClassLoader
+ classLoader = FactoryFinder.class.getClassLoader();
+ if (debug) debugPrintln(
+ "Using the class loader of FactoryFinder: "
+ + classLoader);
+ }
+
+ return classLoader;
+ }
+
+ /**
+ * <p>Create an instance of a class using the specified ClassLoader.</p>
+ *
+ * @param className Name of class to create.
+ * @param classLoader ClassLoader to use to create named class.
+ *
+ * @return New instance of specified class created using the specified ClassLoader.
+ *
+ * @throws ConfigurationError If class could not be created.
+ */
+ private static Object newInstance(
+ String className,
+ ClassLoader classLoader)
+ throws ConfigurationError {
+
+ try {
+ Class spiClass;
+ if (classLoader == null) {
+ spiClass = Class.forName(className);
+ } else {
+ spiClass = classLoader.loadClass(className);
+ }
+
+ if (debug) {
+ debugPrintln("Loaded " + className + " from " + which(spiClass));
+ }
+
+ return spiClass.newInstance();
+ } catch (ClassNotFoundException x) {
+ throw new ConfigurationError(
+ "Provider " + className + " not found", x);
+ } catch (Exception x) {
+ throw new ConfigurationError(
+ "Provider " + className + " could not be instantiated: " + x,
+ x);
+ }
+ }
+
+ /**
+ * Finds the implementation Class object in the specified order. Main
+ * entry point.
+ * Package private so this code can be shared.
+ *
+ * @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.
+ *
+ * @return Class Object of factory, never null
+ *
+ * @throws ConfigurationError If Class cannot be found.
+ */
+ static Object find(String factoryId, String fallbackClassName)
+ throws ConfigurationError {
+
+ ClassLoader classLoader = findClassLoader();
+
+ try {
+ // If we are deployed into an OSGi environment, leverage it
+ Class spiClass = org.apache.servicemix.specs.locator.OsgiLocator.locate(factoryId);
+ if (spiClass != null) {
+ return spiClass.newInstance();
+ }
+ } catch (Throwable e) {
+ }
+
+ // Use the system property first
+ try {
+ String systemProp = SecuritySupport.getSystemProperty(factoryId);
+ if (systemProp != null) {
+ if (debug) debugPrintln("found " + systemProp + " in the system property " + factoryId);
+ return newInstance(systemProp, classLoader);
+ }
+ } catch (SecurityException se) {
+ ; // NOP, explicitly ignore SecurityException
+ }
+
+ // try to read from $java.home/lib/jaxp.properties
+ try {
+ String javah = SecuritySupport.getSystemProperty("java.home");
+ String configFile = javah + File.separator + "lib" + File.separator + "jaxp.properties";
+ String factoryClassName = null;
+ if (firstTime) {
+ synchronized (cacheProps) {
+ if (firstTime) {
+ File f = new File(configFile);
+ firstTime = false;
+ if (SecuritySupport.doesFileExist(f)) {
+ if (debug) debugPrintln("Read properties file " + f);
+ cacheProps.load(SecuritySupport.getFileInputStream(f));
+ }
+ }
+ }
+ }
+ factoryClassName = cacheProps.getProperty(factoryId);
+ if (debug) debugPrintln("found " + factoryClassName + " in $java.home/jaxp.properties");
+
+ if (factoryClassName != null) {
+ return newInstance(factoryClassName, classLoader);
+ }
+ } catch (Exception ex) {
+ if (debug) {
+ ex.printStackTrace();
+ }
+ }
+
+ // Try Jar Service Provider Mechanism
+ Object provider = findJarServiceProvider(factoryId);
+ if (provider != null) {
+ return provider;
+ }
+
+ if (fallbackClassName == null) {
+ throw new ConfigurationError(
+ "Provider for " + factoryId + " cannot be found", null);
+ }
+
+ if (debug) debugPrintln("loaded from fallback value: " + fallbackClassName);
+ return newInstance(fallbackClassName, classLoader);
+ }
+
+ /*
+ * Try to find provider using Jar Service Provider Mechanism
+ *
+ * @return instance of provider class if found or null
+ */
+ private static Object findJarServiceProvider(String factoryId)
+ throws ConfigurationError
+ {
+
+ String serviceId = "META-INF/services/" + factoryId;
+ InputStream is = null;
+
+ // First try the Context ClassLoader
+ ClassLoader cl = SecuritySupport.getContextClassLoader();
+ if (cl != null) {
+ is = SecuritySupport.getResourceAsStream(cl, serviceId);
+
+ // If no provider found then try the current ClassLoader
+ if (is == null) {
+ cl = FactoryFinder.class.getClassLoader();
+ is = SecuritySupport.getResourceAsStream(cl, serviceId);
+ }
+ } else {
+ // No Context ClassLoader, try the current
+ // ClassLoader
+ cl = FactoryFinder.class.getClassLoader();
+ is = SecuritySupport.getResourceAsStream(cl, serviceId);
+ }
+
+ if (is == null) {
+ // No provider found
+ return null;
+ }
+
+ if (debug) debugPrintln("found jar resource=" + serviceId +
+ " using ClassLoader: " + cl);
+
+ BufferedReader rd;
+ try {
+ rd = new BufferedReader(new InputStreamReader(is, "UTF-8"), DEFAULT_LINE_LENGTH);
+ } catch (java.io.UnsupportedEncodingException e) {
+ rd = new BufferedReader(new InputStreamReader(is), DEFAULT_LINE_LENGTH);
+ }
+
+ 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);
+
+ return newInstance(factoryClassName, cl);
+ }
+
+ // No provider found
+ return null;
+ }
+
+ /**
+ * <p>Configuration Error.</p>
+ */
+ static class ConfigurationError extends Error {
+
+ private static final long serialVersionUID = -3644413026244211347L;
+
+ /**
+ * <p>Exception that caused the error.</p>
+ */
+ private Exception exception;
+
+ /**
+ * <p>Construct a new instance with the specified detail string and
+ * exception.</p>
+ *
+ * @param msg Detail message for this error.
+ * @param x Exception that caused the error.
+ */
+ ConfigurationError(String msg, Exception x) {
+ super(msg);
+ this.exception = x;
+ }
+
+ /**
+ * <p>Get the Exception that caused the error.</p>
+ *
+ * @return Exception that caused the error.
+ */
+ Exception getException() {
+ return exception;
+ }
+ }
+
+
+
+ /**
+ * Returns the location where the given Class is loaded from.
+ *
+ * @param clazz Class to find load location.
+ *
+ * @return Location where class would be loaded from.
+ */
+ private static String which(Class clazz) {
+ try {
+ String classnameAsResource = clazz.getName().replace('.', '/') + ".class";
+
+ ClassLoader loader = clazz.getClassLoader();
+
+ URL it;
+
+ if (loader != null) {
+ it = loader.getResource(classnameAsResource);
+ } else {
+ it = ClassLoader.getSystemResource(classnameAsResource);
+ }
+
+ if (it != null) {
+ return it.toString();
+ }
+ } catch (Throwable t) {
+ // work defensively.
+ if (debug) {
+ t.printStackTrace();
+ }
+ }
+ return "unknown location";
+ }
+}
Added: servicemix/smx4/specs/trunk/jaxp-api-1.3/src/main/java/javax/xml/datatype/SecuritySupport.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/specs/trunk/jaxp-api-1.3/src/main/java/javax/xml/datatype/SecuritySupport.java?rev=707355&view=auto
==============================================================================
--- servicemix/smx4/specs/trunk/jaxp-api-1.3/src/main/java/javax/xml/datatype/SecuritySupport.java (added)
+++ servicemix/smx4/specs/trunk/jaxp-api-1.3/src/main/java/javax/xml/datatype/SecuritySupport.java Thu Oct 23 04:47:18 2008
@@ -0,0 +1,105 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 446598 2006-09-15 12:55:40Z jeremias $
+
+package javax.xml.datatype;
+
+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;
+
+/**
+ * This class is duplicated for each JAXP subpackage so keep it in sync.
+ * It is package private and therefore is not exposed as part of the JAXP
+ * API.
+ *
+ * Security related methods that only work on J2SE 1.2 and newer.
+ */
+final class SecuritySupport {
+
+ private SecuritySupport() {}
+
+ static ClassLoader getContextClassLoader() {
+ return (ClassLoader)
+ AccessController.doPrivileged(new PrivilegedAction() {
+ public Object run() {
+ ClassLoader cl = null;
+ try {
+ cl = Thread.currentThread().getContextClassLoader();
+ } catch (SecurityException ex) { }
+ return cl;
+ }
+ });
+ }
+
+ static String getSystemProperty(final String propName) {
+ return (String)
+ AccessController.doPrivileged(new PrivilegedAction() {
+ public Object run() {
+ return System.getProperty(propName);
+ }
+ });
+ }
+
+ static 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();
+ }
+ }
+
+ static 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;
+ }
+ });
+ }
+
+ static boolean doesFileExist(final File f) {
+ return ((Boolean)
+ AccessController.doPrivileged(new PrivilegedAction() {
+ public Object run() {
+ return f.exists() ? Boolean.TRUE : Boolean.FALSE;
+ }
+ })).booleanValue();
+ }
+
+}
Added: servicemix/smx4/specs/trunk/jaxp-api-1.3/src/main/java/javax/xml/parsers/FactoryFinder.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/specs/trunk/jaxp-api-1.3/src/main/java/javax/xml/parsers/FactoryFinder.java?rev=707355&view=auto
==============================================================================
--- servicemix/smx4/specs/trunk/jaxp-api-1.3/src/main/java/javax/xml/parsers/FactoryFinder.java (added)
+++ servicemix/smx4/specs/trunk/jaxp-api-1.3/src/main/java/javax/xml/parsers/FactoryFinder.java Thu Oct 23 04:47:18 2008
@@ -0,0 +1,338 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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: FactoryFinder.java 446598 2006-09-15 12:55:40Z jeremias $
+
+package javax.xml.parsers;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.Properties;
+
+/**
+ * This class is duplicated for each JAXP subpackage so keep it in
+ * sync. It is package private.
+ *
+ * This code is designed to implement the JAXP 1.1 spec pluggability
+ * feature and is designed to run on JDK version 1.1 and later including
+ * JVMs that perform early linking like the Microsoft JVM in IE 5. Note
+ * however that it must be compiled on a JDK version 1.2 or later system
+ * since it calls Thread#getContextClassLoader(). The code also runs both
+ * as part of an unbundled jar file and when bundled as part of the JDK.
+ */
+final class FactoryFinder {
+
+ /** Temp debug code - this will be removed after we test everything
+ */
+ private static boolean debug = false;
+ static Properties cacheProps= new Properties();
+ static boolean firstTime = true;
+
+ /**
+ * Default columns per line.
+ */
+ private static final int DEFAULT_LINE_LENGTH = 80;
+
+ // Define system property "jaxp.debug" to get output
+ static {
+ // Use try/catch block to support applets, which throws
+ // SecurityException out of this code.
+ try {
+ String val = SecuritySupport.getSystemProperty("jaxp.debug");
+ // Allow simply setting the prop to turn on debug
+ debug = val != null && (! "false".equals(val));
+ } catch (SecurityException se) {
+ debug = false;
+ }
+ }
+
+ private FactoryFinder() {}
+
+ private static void dPrint(String msg) {
+ if (debug) {
+ System.err.println("JAXP: " + msg);
+ }
+ }
+
+ /**
+ * Create an instance of a class using the specified ClassLoader and
+ * optionally fall back to the current ClassLoader if not found.
+ *
+ * @param className Name of the concrete class corresponding to the
+ * service provider
+ *
+ * @param cl ClassLoader to use to load the class, null means to use
+ * the bootstrap ClassLoader
+ *
+ * @param doFallback true if the current ClassLoader should be tried as
+ * a fallback if the class is not found using cl
+ */
+ private static Object newInstance(String className, ClassLoader cl,
+ boolean doFallback)
+ throws ConfigurationError
+ {
+ // assert(className != null);
+
+ try {
+ Class providerClass;
+ if (cl == null) {
+ // If classloader is null Use the bootstrap ClassLoader.
+ // 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
+ cl = FactoryFinder.class.getClassLoader();
+ if (cl != null) {
+ providerClass = cl.loadClass(className);
+ }
+ else {
+ providerClass = Class.forName(className);
+ }
+ } else {
+ throw x;
+ }
+ }
+ }
+
+ Object instance = providerClass.newInstance();
+ if (debug) dPrint("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);
+ }
+ }
+
+ /**
+ * Finds the implementation Class object in the specified order. Main
+ * entry point.
+ * @return Class object of factory, never null
+ *
+ * @param factoryId Name of the factory to find, same as
+ * a property name
+ * @param fallbackClassName Implementation class name, if nothing else
+ * is found. Use null to mean no fallback.
+ *
+ * Package private so this code can be shared.
+ */
+ static Object find(String factoryId, String fallbackClassName)
+ throws ConfigurationError
+ {
+
+ // Figure out which ClassLoader to use for loading the provider
+ // class. If there is a Context ClassLoader then use it.
+
+ ClassLoader classLoader = SecuritySupport.getContextClassLoader();
+
+ if (classLoader == null) {
+ // if we have no Context ClassLoader
+ // so use the current ClassLoader
+ classLoader = FactoryFinder.class.getClassLoader();
+ }
+
+ if (debug) dPrint("find factoryId =" + factoryId);
+
+ try {
+ // If we are deployed into an OSGi environment, leverage it
+ Class spiClass = org.apache.servicemix.specs.locator.OsgiLocator.locate(factoryId);
+ if (spiClass != null) {
+ return spiClass.newInstance();
+ }
+ } catch (Throwable e) {
+ }
+
+ // Use the system property first
+ try {
+ String systemProp = SecuritySupport.getSystemProperty(factoryId);
+ if( systemProp!=null) {
+ if (debug) dPrint("found system property, value=" + systemProp);
+ return newInstance(systemProp, classLoader, true );
+ }
+ } catch (SecurityException se) {
+ //if first option fails due to any reason we should try next option in the
+ //look up algorithm.
+ }
+
+ // try to read from $java.home/lib/jaxp.properties
+ try {
+ String javah = SecuritySupport.getSystemProperty("java.home");
+ String configFile = javah + File.separator +
+ "lib" + File.separator + "jaxp.properties";
+ String factoryClassName = null;
+ if(firstTime){
+ synchronized(cacheProps){
+ if(firstTime){
+ File f=new File( configFile );
+ firstTime = false;
+ if(SecuritySupport.doesFileExist(f)){
+ if (debug) dPrint("Read properties file "+f);
+ //cacheProps.load( new FileInputStream(f));
+ cacheProps.load(SecuritySupport.getFileInputStream(f));
+ }
+ }
+ }
+ }
+ factoryClassName = cacheProps.getProperty(factoryId);
+
+ if(factoryClassName != null){
+ if (debug) dPrint("found in $java.home/jaxp.properties, value=" + factoryClassName);
+ return newInstance(factoryClassName, classLoader, true);
+ }
+ } catch(Exception ex ) {
+ if( debug ) ex.printStackTrace();
+ }
+
+ // Try Jar Service Provider Mechanism
+ Object provider = findJarServiceProvider(factoryId);
+ if (provider != null) {
+ return provider;
+ }
+ if (fallbackClassName == null) {
+ throw new ConfigurationError(
+ "Provider for " + factoryId + " cannot be found", null);
+ }
+
+ if (debug) dPrint("loaded from fallback value: " + fallbackClassName);
+ return newInstance(fallbackClassName, classLoader, true);
+ }
+
+ /*
+ * Try to find provider using Jar Service Provider Mechanism
+ *
+ * @return instance of provider class if found or null
+ */
+ private static Object findJarServiceProvider(String factoryId)
+ throws ConfigurationError
+ {
+
+ String serviceId = "META-INF/services/" + factoryId;
+ InputStream is = null;
+
+ // First try the Context ClassLoader
+ ClassLoader cl = SecuritySupport.getContextClassLoader();
+ if (cl != null) {
+ is = SecuritySupport.getResourceAsStream(cl, serviceId);
+
+ // If no provider found then try the current ClassLoader
+ if (is == null) {
+ cl = FactoryFinder.class.getClassLoader();
+ is = SecuritySupport.getResourceAsStream(cl, serviceId);
+ }
+ } else {
+ // No Context ClassLoader, try the current
+ // ClassLoader
+ cl = FactoryFinder.class.getClassLoader();
+ is = SecuritySupport.getResourceAsStream(cl, serviceId);
+ }
+
+ if (is == null) {
+ // No provider found
+ return null;
+ }
+
+ if (debug) dPrint("found jar resource=" + serviceId +
+ " using ClassLoader: " + cl);
+
+ // Read the service provider name in UTF-8 as specified in
+ // the jar spec. Unfortunately this fails in Microsoft
+ // VJ++, which does not implement the UTF-8
+ // encoding. Theoretically, we should simply let it fail in
+ // that case, since the JVM is obviously broken if it
+ // doesn't support such a basic standard. But since there
+ // are still some users attempting to use VJ++ for
+ // development, we have dropped in a fallback which makes a
+ // second attempt using the platform's default encoding. In
+ // VJ++ this is apparently ASCII, which is a subset of
+ // UTF-8... and since the strings we'll be reading here are
+ // also primarily limited to the 7-bit ASCII range (at
+ // least, in English versions), this should work well
+ // enough to keep us on the air until we're ready to
+ // officially decommit from VJ++. [Edited comment from
+ // jkesselm]
+ BufferedReader rd;
+ try {
+ rd = new BufferedReader(new InputStreamReader(is, "UTF-8"), DEFAULT_LINE_LENGTH);
+ } catch (java.io.UnsupportedEncodingException e) {
+ rd = new BufferedReader(new InputStreamReader(is), DEFAULT_LINE_LENGTH);
+ }
+
+ 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) dPrint("found in resource, value="
+ + factoryClassName);
+
+ // Note: here we do not want to fall back to the current
+ // ClassLoader because we want to avoid the case where the
+ // resource file was found using one ClassLoader and the
+ // provider class was instantiated using a different one.
+ return newInstance(factoryClassName, cl, false);
+ }
+
+ // No provider found
+ return null;
+ }
+
+ static class ConfigurationError extends Error {
+ private Exception exception;
+
+ /**
+ * Construct a new instance with the specified detail string and
+ * exception.
+ */
+ ConfigurationError(String msg, Exception x) {
+ super(msg);
+ this.exception = x;
+ }
+
+ Exception getException() {
+ return exception;
+ }
+ }
+
+}
Added: servicemix/smx4/specs/trunk/jaxp-api-1.3/src/main/java/javax/xml/parsers/ScuritySupport.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/specs/trunk/jaxp-api-1.3/src/main/java/javax/xml/parsers/ScuritySupport.java?rev=707355&view=auto
==============================================================================
--- servicemix/smx4/specs/trunk/jaxp-api-1.3/src/main/java/javax/xml/parsers/ScuritySupport.java (added)
+++ servicemix/smx4/specs/trunk/jaxp-api-1.3/src/main/java/javax/xml/parsers/ScuritySupport.java Thu Oct 23 04:47:18 2008
@@ -0,0 +1,105 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.24.1 2005/03/29 23:25:08 jsuttor Exp $
+
+package javax.xml.parsers;
+
+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;
+
+/**
+ * This class is duplicated for each JAXP subpackage so keep it in sync.
+ * It is package private and therefore is not exposed as part of the JAXP
+ * API.
+ *
+ * Security related methods that only work on J2SE 1.2 and newer.
+ */
+final class SecuritySupport {
+
+ private SecuritySupport() {}
+
+ static ClassLoader getContextClassLoader() {
+ return (ClassLoader)
+ AccessController.doPrivileged(new PrivilegedAction() {
+ public Object run() {
+ ClassLoader cl = null;
+ try {
+ cl = Thread.currentThread().getContextClassLoader();
+ } catch (SecurityException ex) { }
+ return cl;
+ }
+ });
+ }
+
+ static String getSystemProperty(final String propName) {
+ return (String)
+ AccessController.doPrivileged(new PrivilegedAction() {
+ public Object run() {
+ return System.getProperty(propName);
+ }
+ });
+ }
+
+ static 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();
+ }
+ }
+
+ static 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;
+ }
+ });
+ }
+
+ static boolean doesFileExist(final File f) {
+ return ((Boolean)
+ AccessController.doPrivileged(new PrivilegedAction() {
+ public Object run() {
+ return f.exists() ? Boolean.TRUE : Boolean.FALSE;
+ }
+ })).booleanValue();
+ }
+
+}
Added: servicemix/smx4/specs/trunk/jaxp-api-1.3/src/main/java/javax/xml/transform/FactoryFinder.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/specs/trunk/jaxp-api-1.3/src/main/java/javax/xml/transform/FactoryFinder.java?rev=707355&view=auto
==============================================================================
--- servicemix/smx4/specs/trunk/jaxp-api-1.3/src/main/java/javax/xml/transform/FactoryFinder.java (added)
+++ servicemix/smx4/specs/trunk/jaxp-api-1.3/src/main/java/javax/xml/transform/FactoryFinder.java Thu Oct 23 04:47:18 2008
@@ -0,0 +1,338 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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: FactoryFinder.java 446598 2006-09-15 12:55:40Z jeremias $
+
+package javax.xml.transform;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.Properties;
+
+/**
+ * This class is duplicated for each JAXP subpackage so keep it in
+ * sync. It is package private.
+ *
+ * This code is designed to implement the JAXP 1.1 spec pluggability
+ * feature and is designed to run on JDK version 1.1 and later including
+ * JVMs that perform early linking like the Microsoft JVM in IE 5. Note
+ * however that it must be compiled on a JDK version 1.2 or later system
+ * since it calls Thread#getContextClassLoader(). The code also runs both
+ * as part of an unbundled jar file and when bundled as part of the JDK.
+ */
+final class FactoryFinder {
+
+ /** Temp debug code - this will be removed after we test everything
+ */
+ private static boolean debug = false;
+ static Properties cacheProps= new Properties();
+ static boolean firstTime = true;
+
+ /**
+ * Default columns per line.
+ */
+ private static final int DEFAULT_LINE_LENGTH = 80;
+
+ // Define system property "jaxp.debug" to get output
+ static {
+ // Use try/catch block to support applets, which throws
+ // SecurityException out of this code.
+ try {
+ String val = SecuritySupport.getSystemProperty("jaxp.debug");
+ // Allow simply setting the prop to turn on debug
+ debug = val != null && (! "false".equals(val));
+ } catch (SecurityException se) {
+ debug = false;
+ }
+ }
+
+ private FactoryFinder() {}
+
+ private static void dPrint(String msg) {
+ if (debug) {
+ System.err.println("JAXP: " + msg);
+ }
+ }
+
+ /**
+ * Create an instance of a class using the specified ClassLoader and
+ * optionally fall back to the current ClassLoader if not found.
+ *
+ * @param className Name of the concrete class corresponding to the
+ * service provider
+ *
+ * @param cl ClassLoader to use to load the class, null means to use
+ * the bootstrap ClassLoader
+ *
+ * @param doFallback true if the current ClassLoader should be tried as
+ * a fallback if the class is not found using cl
+ */
+ private static Object newInstance(String className, ClassLoader cl,
+ boolean doFallback)
+ throws ConfigurationError
+ {
+ // assert(className != null);
+
+ try {
+ Class providerClass;
+ if (cl == null) {
+ // If classloader is null Use the bootstrap ClassLoader.
+ // 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
+ cl = FactoryFinder.class.getClassLoader();
+ if (cl != null) {
+ providerClass = cl.loadClass(className);
+ }
+ else {
+ providerClass = Class.forName(className);
+ }
+ } else {
+ throw x;
+ }
+ }
+ }
+
+ Object instance = providerClass.newInstance();
+ if (debug) dPrint("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);
+ }
+ }
+
+ /**
+ * Finds the implementation Class object in the specified order. Main
+ * entry point.
+ * @return Class object of factory, never null
+ *
+ * @param factoryId Name of the factory to find, same as
+ * a property name
+ * @param fallbackClassName Implementation class name, if nothing else
+ * is found. Use null to mean no fallback.
+ *
+ * Package private so this code can be shared.
+ */
+ static Object find(String factoryId, String fallbackClassName)
+ throws ConfigurationError
+ {
+
+ // Figure out which ClassLoader to use for loading the provider
+ // class. If there is a Context ClassLoader then use it.
+
+ ClassLoader classLoader = SecuritySupport.getContextClassLoader();
+
+ if (classLoader == null) {
+ // if we have no Context ClassLoader
+ // so use the current ClassLoader
+ classLoader = FactoryFinder.class.getClassLoader();
+ }
+
+ if (debug) dPrint("find factoryId =" + factoryId);
+
+ try {
+ // If we are deployed into an OSGi environment, leverage it
+ Class spiClass = org.apache.servicemix.specs.locator.OsgiLocator.locate(factoryId);
+ if (spiClass != null) {
+ return spiClass.newInstance();
+ }
+ } catch (Throwable e) {
+ }
+
+ // Use the system property first
+ try {
+ String systemProp = SecuritySupport.getSystemProperty(factoryId);
+ if( systemProp!=null) {
+ if (debug) dPrint("found system property, value=" + systemProp);
+ return newInstance(systemProp, classLoader, true );
+ }
+ } catch (SecurityException se) {
+ //if first option fails due to any reason we should try next option in the
+ //look up algorithm.
+ }
+
+ // try to read from $java.home/lib/jaxp.properties
+ try {
+ String javah = SecuritySupport.getSystemProperty("java.home");
+ String configFile = javah + File.separator +
+ "lib" + File.separator + "jaxp.properties";
+ String factoryClassName = null;
+ if(firstTime){
+ synchronized(cacheProps){
+ if(firstTime){
+ File f=new File( configFile );
+ firstTime = false;
+ if(SecuritySupport.doesFileExist(f)){
+ if (debug) dPrint("Read properties file "+f);
+ //cacheProps.load( new FileInputStream(f));
+ cacheProps.load(SecuritySupport.getFileInputStream(f));
+ }
+ }
+ }
+ }
+ factoryClassName = cacheProps.getProperty(factoryId);
+
+ if(factoryClassName != null){
+ if (debug) dPrint("found in $java.home/jaxp.properties, value=" + factoryClassName);
+ return newInstance(factoryClassName, classLoader, true);
+ }
+ } catch(Exception ex ) {
+ if( debug ) ex.printStackTrace();
+ }
+
+ // Try Jar Service Provider Mechanism
+ Object provider = findJarServiceProvider(factoryId);
+ if (provider != null) {
+ return provider;
+ }
+ if (fallbackClassName == null) {
+ throw new ConfigurationError(
+ "Provider for " + factoryId + " cannot be found", null);
+ }
+
+ if (debug) dPrint("loaded from fallback value: " + fallbackClassName);
+ return newInstance(fallbackClassName, classLoader, true);
+ }
+
+ /*
+ * Try to find provider using Jar Service Provider Mechanism
+ *
+ * @return instance of provider class if found or null
+ */
+ private static Object findJarServiceProvider(String factoryId)
+ throws ConfigurationError
+ {
+
+ String serviceId = "META-INF/services/" + factoryId;
+ InputStream is = null;
+
+ // First try the Context ClassLoader
+ ClassLoader cl = SecuritySupport.getContextClassLoader();
+ if (cl != null) {
+ is = SecuritySupport.getResourceAsStream(cl, serviceId);
+
+ // If no provider found then try the current ClassLoader
+ if (is == null) {
+ cl = FactoryFinder.class.getClassLoader();
+ is = SecuritySupport.getResourceAsStream(cl, serviceId);
+ }
+ } else {
+ // No Context ClassLoader, try the current
+ // ClassLoader
+ cl = FactoryFinder.class.getClassLoader();
+ is = SecuritySupport.getResourceAsStream(cl, serviceId);
+ }
+
+ if (is == null) {
+ // No provider found
+ return null;
+ }
+
+ if (debug) dPrint("found jar resource=" + serviceId +
+ " using ClassLoader: " + cl);
+
+ // Read the service provider name in UTF-8 as specified in
+ // the jar spec. Unfortunately this fails in Microsoft
+ // VJ++, which does not implement the UTF-8
+ // encoding. Theoretically, we should simply let it fail in
+ // that case, since the JVM is obviously broken if it
+ // doesn't support such a basic standard. But since there
+ // are still some users attempting to use VJ++ for
+ // development, we have dropped in a fallback which makes a
+ // second attempt using the platform's default encoding. In
+ // VJ++ this is apparently ASCII, which is a subset of
+ // UTF-8... and since the strings we'll be reading here are
+ // also primarily limited to the 7-bit ASCII range (at
+ // least, in English versions), this should work well
+ // enough to keep us on the air until we're ready to
+ // officially decommit from VJ++. [Edited comment from
+ // jkesselm]
+ BufferedReader rd;
+ try {
+ rd = new BufferedReader(new InputStreamReader(is, "UTF-8"), DEFAULT_LINE_LENGTH);
+ } catch (java.io.UnsupportedEncodingException e) {
+ rd = new BufferedReader(new InputStreamReader(is), DEFAULT_LINE_LENGTH);
+ }
+
+ 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) dPrint("found in resource, value="
+ + factoryClassName);
+
+ // Note: here we do not want to fall back to the current
+ // ClassLoader because we want to avoid the case where the
+ // resource file was found using one ClassLoader and the
+ // provider class was instantiated using a different one.
+ return newInstance(factoryClassName, cl, false);
+ }
+
+ // No provider found
+ return null;
+ }
+
+ static class ConfigurationError extends Error {
+ private Exception exception;
+
+ /**
+ * Construct a new instance with the specified detail string and
+ * exception.
+ */
+ ConfigurationError(String msg, Exception x) {
+ super(msg);
+ this.exception = x;
+ }
+
+ Exception getException() {
+ return exception;
+ }
+ }
+
+}
Added: servicemix/smx4/specs/trunk/jaxp-api-1.3/src/main/java/javax/xml/transform/SecuritySupport.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/specs/trunk/jaxp-api-1.3/src/main/java/javax/xml/transform/SecuritySupport.java?rev=707355&view=auto
==============================================================================
--- servicemix/smx4/specs/trunk/jaxp-api-1.3/src/main/java/javax/xml/transform/SecuritySupport.java (added)
+++ servicemix/smx4/specs/trunk/jaxp-api-1.3/src/main/java/javax/xml/transform/SecuritySupport.java Thu Oct 23 04:47:18 2008
@@ -0,0 +1,105 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.24.1 2005/03/29 23:32:22 jsuttor Exp $
+
+package javax.xml.transform;
+
+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;
+
+/**
+ * This class is duplicated for each JAXP subpackage so keep it in sync.
+ * It is package private and therefore is not exposed as part of the JAXP
+ * API.
+ *
+ * Security related methods that only work on J2SE 1.2 and newer.
+ */
+final class SecuritySupport {
+
+ private SecuritySupport() {}
+
+ static ClassLoader getContextClassLoader() {
+ return (ClassLoader)
+ AccessController.doPrivileged(new PrivilegedAction() {
+ public Object run() {
+ ClassLoader cl = null;
+ try {
+ cl = Thread.currentThread().getContextClassLoader();
+ } catch (SecurityException ex) { }
+ return cl;
+ }
+ });
+ }
+
+ static String getSystemProperty(final String propName) {
+ return (String)
+ AccessController.doPrivileged(new PrivilegedAction() {
+ public Object run() {
+ return System.getProperty(propName);
+ }
+ });
+ }
+
+ static 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();
+ }
+ }
+
+ static 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;
+ }
+ });
+ }
+
+ static boolean doesFileExist(final File f) {
+ return ((Boolean)
+ AccessController.doPrivileged(new PrivilegedAction() {
+ public Object run() {
+ return f.exists() ? Boolean.TRUE : Boolean.FALSE;
+ }
+ })).booleanValue();
+ }
+
+}
Added: servicemix/smx4/specs/trunk/jaxp-api-1.3/src/main/java/javax/xml/validation/SchemaFactoryFinder.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/specs/trunk/jaxp-api-1.3/src/main/java/javax/xml/validation/SchemaFactoryFinder.java?rev=707355&view=auto
==============================================================================
--- servicemix/smx4/specs/trunk/jaxp-api-1.3/src/main/java/javax/xml/validation/SchemaFactoryFinder.java (added)
+++ servicemix/smx4/specs/trunk/jaxp-api-1.3/src/main/java/javax/xml/validation/SchemaFactoryFinder.java Thu Oct 23 04:47:18 2008
@@ -0,0 +1,471 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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: SchemaFactoryFinder.java 446598 2006-09-15 12:55:40Z jeremias $
+
+package javax.xml.validation;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+import java.util.Properties;
+
+/**
+ * Implementation of {@link SchemaFactory#newInstance(String)}.
+ *
+ * @author <a href="Kohsuke.Kawaguchi@Sun.com">Kohsuke Kawaguchi</a>
+ * @version $Revision: 446598 $, $Date: 2006-09-15 08:55:40 -0400 (Fri, 15 Sep 2006) $
+ * @since 1.5
+ */
+final class SchemaFactoryFinder {
+
+ /** debug support code. */
+ private static boolean debug = false;
+
+ /**
+ * <p>Cache properties for performance.</p>
+ */
+ private static Properties cacheProps = new Properties();
+
+ /**
+ * <p>First time requires initialization overhead.</p>
+ */
+ private static boolean firstTime = true;
+
+ /**
+ * Default columns per line.
+ */
+ private static final int DEFAULT_LINE_LENGTH = 80;
+
+ static {
+ // Use try/catch block to support applets
+ try {
+ String val = SecuritySupport.getSystemProperty("jaxp.debug");
+ // Allow simply setting the prop to turn on debug
+ debug = val != null && (! "false".equals(val));
+ } catch (Exception _) {
+ debug = false;
+ }
+ }
+
+ /**
+ * <p>Conditional debug printing.</p>
+ *
+ * @param msg to print
+ */
+ private static void debugPrintln(String msg) {
+ if (debug) {
+ System.err.println("JAXP: " + msg);
+ }
+ }
+
+ /**
+ * <p><code>ClassLoader</code> to use to find <code>SchemaFactory</code>.</p>
+ */
+ private final ClassLoader classLoader;
+
+ /**
+ * <p>Constructor that specifies <code>ClassLoader</code> to use
+ * to find <code>SchemaFactory</code>.</p>
+ *
+ * @param loader
+ * to be used to load resource, {@link SchemaFactory}, and
+ * {@link SchemaFactoryLoader} implementations during
+ * the resolution process.
+ * If this parameter is null, the default system class loader
+ * will be used.
+ */
+ public SchemaFactoryFinder(ClassLoader loader) {
+ this.classLoader = loader;
+ if( debug ) {
+ debugDisplayClassLoader();
+ }
+ }
+
+ private void debugDisplayClassLoader() {
+ try {
+ if( classLoader == SecuritySupport.getContextClassLoader() ) {
+ debugPrintln("using thread context class loader ("+classLoader+") for search");
+ return;
+ }
+ } catch( Throwable _ ) {
+ ; // getContextClassLoader() undefined in JDK1.1
+ }
+
+ if( classLoader==ClassLoader.getSystemClassLoader() ) {
+ debugPrintln("using system class loader ("+classLoader+") for search");
+ return;
+ }
+
+ debugPrintln("using class loader ("+classLoader+") for search");
+ }
+
+ /**
+ * <p>Creates a new {@link SchemaFactory} object for the specified
+ * schema language.</p>
+ *
+ * @param schemaLanguage
+ * See {@link SchemaFactory Schema Language} table in <code>SchemaFactory</code>
+ * for the list of available schema languages.
+ *
+ * @return <code>null</code> if the callee fails to create one.
+ *
+ * @throws NullPointerException
+ * If the <tt>schemaLanguage</tt> parameter is null.
+ */
+ public SchemaFactory newFactory(String schemaLanguage) {
+ if(schemaLanguage==null) throw new NullPointerException();
+ SchemaFactory f = _newFactory(schemaLanguage);
+ if (debug) {
+ if (f != null) {
+ debugPrintln("factory '" + f.getClass().getName() + "' was found for " + schemaLanguage);
+ } else {
+ debugPrintln("unable to find a factory for " + schemaLanguage);
+ }
+ }
+ return f;
+ }
+
+ /**
+ * <p>Lookup a <code>SchemaFactory</code> for the given <code>schemaLanguage</code>.</p>
+ *
+ * @param schemaLanguage Schema language to lookup <code>SchemaFactory</code> for.
+ *
+ * @return <code>SchemaFactory</code> for the given <code>schemaLanguage</code>.
+ */
+ private SchemaFactory _newFactory(String schemaLanguage) {
+ SchemaFactory sf;
+ String propertyName = SERVICE_CLASS.getName() + ":" + schemaLanguage;
+
+ try {
+ // If we are deployed into an OSGi environment, leverage it
+ Class spiClass = org.apache.servicemix.specs.locator.OsgiLocator.locate(SERVICE_CLASS.getName());
+ if (spiClass != null) {
+ return (SchemaFactory) spiClass.newInstance();
+ }
+ } catch (Throwable e) {
+ }
+
+ // system property look up
+ try {
+ if (debug) debugPrintln("Looking up system property '"+propertyName+"'" );
+ String r = SecuritySupport.getSystemProperty(propertyName);
+ if (r != null) {
+ if (debug) debugPrintln("The value is '"+r+"'");
+ sf = createInstance(r);
+ if(sf!=null) return sf;
+ }
+ else if (debug) {
+ debugPrintln("The property is undefined.");
+ }
+ } catch( Throwable t ) {
+ if( debug ) {
+ debugPrintln("failed to look up system property '"+propertyName+"'" );
+ t.printStackTrace();
+ }
+ }
+
+ String javah = SecuritySupport.getSystemProperty( "java.home" );
+ String configFile = javah + File.separator +
+ "lib" + File.separator + "jaxp.properties";
+
+ String factoryClassName = null ;
+
+ // try to read from $java.home/lib/jaxp.properties
+ try {
+ if(firstTime){
+ synchronized(cacheProps){
+ if(firstTime){
+ File f=new File( configFile );
+ firstTime = false;
+ if(SecuritySupport.doesFileExist(f)){
+ if (debug) debugPrintln("Read properties file " + f);
+ cacheProps.load(SecuritySupport.getFileInputStream(f));
+ }
+ }
+ }
+ }
+ factoryClassName = cacheProps.getProperty(propertyName);
+ if (debug) debugPrintln("found " + factoryClassName + " in $java.home/jaxp.properties");
+
+ if (factoryClassName != null) {
+ sf = createInstance(factoryClassName);
+ if(sf != null){
+ return sf;
+ }
+ }
+ } catch (Exception ex) {
+ if (debug) {
+ ex.printStackTrace();
+ }
+ }
+
+ /**
+ // try to read from $java.home/lib/jaxp.properties
+ try {
+ String javah = ss.getSystemProperty( "java.home" );
+ String configFile = javah + File.separator +
+ "lib" + File.separator + "jaxp.properties";
+ File f = new File( configFile );
+ if( ss.doesFileExist(f)) {
+ sf = loadFromProperty(
+ propertyName,f.getAbsolutePath(), new FileInputStream(f));
+ if(sf!=null) return sf;
+ } else {
+ debugPrintln("Tried to read "+ f.getAbsolutePath()+", but it doesn't exist.");
+ }
+ } catch(Throwable e) {
+ if( debug ) {
+ debugPrintln("failed to read $java.home/lib/jaxp.properties");
+ e.printStackTrace();
+ }
+ }
+ */
+
+ // try META-INF/services files
+ Iterator sitr = createServiceFileIterator();
+ while(sitr.hasNext()) {
+ URL resource = (URL)sitr.next();
+ if (debug) debugPrintln("looking into " + resource);
+ try {
+ sf = loadFromServicesFile(schemaLanguage,resource.toExternalForm(),SecuritySupport.getURLInputStream(resource));
+ if(sf!=null) return sf;
+ } catch(IOException e) {
+ if( debug ) {
+ debugPrintln("failed to read "+resource);
+ e.printStackTrace();
+ }
+ }
+ }
+
+ // platform default
+ if (schemaLanguage.equals("http://www.w3.org/2001/XMLSchema")) {
+ if (debug) debugPrintln("attempting to use the platform default XML Schema validator");
+ return createInstance("org.apache.xerces.jaxp.validation.XMLSchemaFactory");
+ }
+
+ if (debug) debugPrintln("all things were tried, but none was found. bailing out.");
+ return null;
+ }
+
+ /**
+ * <p>Creates an instance of the specified and returns it.</p>
+ *
+ * @param className
+ * fully qualified class name to be instanciated.
+ *
+ * @return null
+ * if it fails. Error messages will be printed by this method.
+ */
+ private SchemaFactory createInstance( String className ) {
+ try {
+ if (debug) debugPrintln("instanciating "+className);
+ Class clazz;
+ if( classLoader!=null )
+ clazz = classLoader.loadClass(className);
+ else
+ clazz = Class.forName(className);
+ if(debug) debugPrintln("loaded it from "+which(clazz));
+ Object o = clazz.newInstance();
+
+ if( o instanceof SchemaFactory )
+ return (SchemaFactory)o;
+
+ if (debug) debugPrintln(className+" is not assignable to "+SERVICE_CLASS.getName());
+ } catch( Throwable t ) {
+ debugPrintln("failed to instanciate "+className);
+ if(debug) t.printStackTrace();
+ }
+ return null;
+ }
+
+ /** Iterator that lazily computes one value and returns it. */
+ private static abstract class SingleIterator implements Iterator {
+ private boolean seen = false;
+
+ public final void remove() { throw new UnsupportedOperationException(); }
+ public final boolean hasNext() { return !seen; }
+ public final Object next() {
+ if(seen) throw new NoSuchElementException();
+ seen = true;
+ return value();
+ }
+
+ protected abstract Object value();
+ }
+
+ /**
+ * Returns an {@link Iterator} that enumerates all
+ * the META-INF/services files that we care.
+ */
+ private Iterator createServiceFileIterator() {
+ if (classLoader == null) {
+ return new SingleIterator() {
+ protected Object value() {
+ ClassLoader classLoader = SchemaFactoryFinder.class.getClassLoader();
+ //return (ClassLoader.getSystemResource( SERVICE_ID ));
+ return SecuritySupport.getResourceAsURL(classLoader, SERVICE_ID);
+ }
+ };
+ } else {
+ try {
+ //final Enumeration e = classLoader.getResources(SERVICE_ID);
+ final Enumeration e = SecuritySupport.getResources(classLoader, SERVICE_ID);
+ if(debug && !e.hasMoreElements()) {
+ debugPrintln("no "+SERVICE_ID+" file was found");
+ }
+
+ // wrap it into an Iterator.
+ return new Iterator() {
+ public void remove() {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean hasNext() {
+ return e.hasMoreElements();
+ }
+
+ public Object next() {
+ return e.nextElement();
+ }
+ };
+ } catch (IOException e) {
+ if (debug) {
+ debugPrintln("failed to enumerate resources "+SERVICE_ID);
+ e.printStackTrace();
+ }
+ return new ArrayList().iterator(); // empty iterator
+ }
+ }
+ }
+
+ /** Searches for a SchemaFactory for a given schema language in a META-INF/services file. */
+ private SchemaFactory loadFromServicesFile(String schemaLanguage, String resourceName, InputStream in) {
+
+ if (debug) debugPrintln("Reading "+resourceName );
+
+ // 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(in, "UTF-8"), DEFAULT_LINE_LENGTH);
+ } catch (java.io.UnsupportedEncodingException e) {
+ rd = new BufferedReader(new InputStreamReader(in), DEFAULT_LINE_LENGTH);
+ }
+
+ String factoryClassName = null;
+ SchemaFactory resultFactory = null;
+ // See spec for provider-configuration files: http://java.sun.com/j2se/1.5.0/docs/guide/jar/jar.html#Provider%20Configuration%20File
+ while (true) {
+ try {
+ factoryClassName = rd.readLine();
+ } catch (IOException x) {
+ // No provider found
+ break;
+ }
+ if (factoryClassName != null) {
+ // Ignore comments in the provider-configuration file
+ int hashIndex = factoryClassName.indexOf('#');
+ if (hashIndex != -1) {
+ factoryClassName = factoryClassName.substring(0, hashIndex);
+ }
+
+ // Ignore leading and trailing whitespace
+ factoryClassName = factoryClassName.trim();
+
+ // If there's no text left or if this was a blank line, go to the next one.
+ if (factoryClassName.length() == 0) {
+ continue;
+ }
+
+ try {
+ // Found the right SchemaFactory if its isSchemaLanguageSupported(schemaLanguage) method returns true.
+ SchemaFactory foundFactory = (SchemaFactory) createInstance(factoryClassName);
+ if (foundFactory.isSchemaLanguageSupported(schemaLanguage)) {
+ resultFactory = foundFactory;
+ break;
+ }
+ }
+ catch (Exception e) {}
+ }
+ else {
+ break;
+ }
+ }
+
+ try {
+ // try to close the reader.
+ rd.close();
+ }
+ // Ignore the exception.
+ catch (IOException exc) {}
+
+ return resultFactory;
+ }
+
+ private static final Class SERVICE_CLASS = SchemaFactory.class;
+ private static final String SERVICE_ID = "META-INF/services/" + SERVICE_CLASS.getName();
+
+
+
+ private static String which( Class clazz ) {
+ return which( clazz.getName(), clazz.getClassLoader() );
+ }
+
+ /**
+ * <p>Search the specified classloader for the given classname.</p>
+ *
+ * @param classname the fully qualified name of the class to search for
+ * @param loader the classloader to search
+ *
+ * @return the source location of the resource, or null if it wasn't found
+ */
+ private static String which(String classname, ClassLoader loader) {
+
+ String classnameAsResource = classname.replace('.', '/') + ".class";
+
+ if( loader==null ) loader = ClassLoader.getSystemClassLoader();
+
+ //URL it = loader.getResource(classnameAsResource);
+ URL it = SecuritySupport.getResourceAsURL(loader, classnameAsResource);
+ if (it != null) {
+ return it.toString();
+ } else {
+ return null;
+ }
+ }
+}
Added: servicemix/smx4/specs/trunk/jaxp-api-1.3/src/main/java/javax/xml/validation/SecuritySupport.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/specs/trunk/jaxp-api-1.3/src/main/java/javax/xml/validation/SecuritySupport.java?rev=707355&view=auto
==============================================================================
--- servicemix/smx4/specs/trunk/jaxp-api-1.3/src/main/java/javax/xml/validation/SecuritySupport.java (added)
+++ servicemix/smx4/specs/trunk/jaxp-api-1.3/src/main/java/javax/xml/validation/SecuritySupport.java Thu Oct 23 04:47:18 2008
@@ -0,0 +1,160 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 446598 2006-09-15 12:55:40Z jeremias $
+
+package javax.xml.validation;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
+import java.util.Enumeration;
+
+/**
+ * This class is duplicated for each JAXP subpackage so keep it in sync.
+ * It is package private and therefore is not exposed as part of the JAXP
+ * API.
+ *
+ * Security related methods that only work on J2SE 1.2 and newer.
+ */
+final class SecuritySupport {
+
+ private SecuritySupport() {}
+
+ static ClassLoader getContextClassLoader() {
+ return (ClassLoader)
+ AccessController.doPrivileged(new PrivilegedAction() {
+ public Object run() {
+ ClassLoader cl = null;
+ try {
+ cl = Thread.currentThread().getContextClassLoader();
+ } catch (SecurityException ex) { }
+ return cl;
+ }
+ });
+ }
+
+ static String getSystemProperty(final String propName) {
+ return (String)
+ AccessController.doPrivileged(new PrivilegedAction() {
+ public Object run() {
+ return System.getProperty(propName);
+ }
+ });
+ }
+
+ static 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();
+ }
+ }
+
+ static InputStream getURLInputStream(final URL url)
+ throws IOException
+ {
+ try {
+ return (InputStream)
+ AccessController.doPrivileged(new PrivilegedExceptionAction() {
+ public Object run() throws IOException {
+ return url.openStream();
+ }
+ });
+ } catch (PrivilegedActionException e) {
+ throw (IOException)e.getException();
+ }
+ }
+
+ static URL getResourceAsURL(final ClassLoader cl,
+ final String name)
+ {
+ return (URL)
+ AccessController.doPrivileged(new PrivilegedAction() {
+ public Object run() {
+ URL url;
+ if (cl == null) {
+ url = ClassLoader.getSystemResource(name);
+ } else {
+ url = cl.getSystemResource(name);
+ }
+ return url;
+ }
+ });
+ }
+
+ static Enumeration getResources(final ClassLoader cl,
+ final String name) throws IOException
+ {
+ try{
+ return (Enumeration)
+ AccessController.doPrivileged(new PrivilegedExceptionAction() {
+ public Object run() throws IOException{
+ Enumeration enumeration;
+ if (cl == null) {
+ enumeration = ClassLoader.getSystemResources(name);
+ } else {
+ enumeration = cl.getSystemResources(name);
+ }
+ return enumeration;
+ }
+ });
+ }catch(PrivilegedActionException e){
+ throw (IOException)e.getException();
+ }
+ }
+
+ static 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;
+ }
+ });
+ }
+
+ static boolean doesFileExist(final File f) {
+ return ((Boolean)
+ AccessController.doPrivileged(new PrivilegedAction() {
+ public Object run() {
+ return f.exists() ? Boolean.TRUE : Boolean.FALSE;
+ }
+ })).booleanValue();
+ }
+
+}