001: /*
002: * The Apache Software License, Version 1.1
003: *
004: *
005: * Copyright (c) 2002 The Apache Software Foundation. All rights
006: * reserved.
007: *
008: * Redistribution and use in source and binary forms, with or without
009: * modification, are permitted provided that the following conditions
010: * are met:
011: *
012: * 1. Redistributions of source code must retain the above copyright
013: * notice, this list of conditions and the following disclaimer.
014: *
015: * 2. Redistributions in binary form must reproduce the above copyright
016: * notice, this list of conditions and the following disclaimer in
017: * the documentation and/or other materials provided with the
018: * distribution.
019: *
020: * 3. The end-user documentation included with the redistribution,
021: * if any, must include the following acknowledgment:
022: * "This product includes software developed by the
023: * Apache Software Foundation (http://www.apache.org/)."
024: * Alternately, this acknowledgment may appear in the software itself,
025: * if and wherever such third-party acknowledgments normally appear.
026: *
027: * 4. The name "Apache Software Foundation" must not be used to endorse or
028: * promote products derived from this software without prior written
029: * permission. For written permission, please contact apache@apache.org.
030: *
031: * 5. Products derived from this software may not be called "Apache",
032: * nor may "Apache" appear in their name, without prior written
033: * permission of the Apache Software Foundation.
034: *
035: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
036: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
037: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
038: * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
039: * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
040: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
041: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
042: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
043: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
044: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
045: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
046: * SUCH DAMAGE.
047: * ====================================================================
048: *
049: * This software consists of voluntary contributions made by many
050: * individuals on behalf of the Apache Software Foundation and was
051: * originally based on software copyright (c) 1999-2002, Sun Microsystems,
052: * Inc., http://www.sun.com. For more information on the Apache Software
053: * Foundation, please see <http://www.apache.org/>.
054: */
055:
056: package com.sun.xml.stream.xerces.util;
057:
058: import java.io.*;
059: import java.security.*;
060:
061: /**
062: * This class is duplicated for each JAXP subpackage so keep it in sync.
063: * It is package private and therefore is not exposed as part of the JAXP
064: * API.
065: *
066: * Security related methods that only work on J2SE 1.2 and newer.
067: */
068: class SecuritySupport12 extends SecuritySupport {
069:
070: public ClassLoader getContextClassLoader() {
071: return (ClassLoader) AccessController
072: .doPrivileged(new PrivilegedAction() {
073: public Object run() {
074: ClassLoader cl = null;
075: try {
076: cl = Thread.currentThread()
077: .getContextClassLoader();
078: } catch (SecurityException ex) {
079: }
080: return cl;
081: }
082: });
083: }
084:
085: public String getSystemProperty(final String propName) {
086: return (String) AccessController
087: .doPrivileged(new PrivilegedAction() {
088: public Object run() {
089: return System.getProperty(propName);
090: }
091: });
092: }
093:
094: public FileInputStream getFileInputStream(final File file)
095: throws FileNotFoundException {
096: try {
097: return (FileInputStream) AccessController
098: .doPrivileged(new PrivilegedExceptionAction() {
099: public Object run()
100: throws FileNotFoundException {
101: return new FileInputStream(file);
102: }
103: });
104: } catch (PrivilegedActionException e) {
105: throw (FileNotFoundException) e.getException();
106: }
107: }
108:
109: public InputStream getResourceAsStream(final ClassLoader cl,
110: final String name) {
111: return (InputStream) AccessController
112: .doPrivileged(new PrivilegedAction() {
113: public Object run() {
114: InputStream ris;
115: if (cl == null) {
116: ris = ClassLoader
117: .getSystemResourceAsStream(name);
118: } else {
119: ris = cl.getResourceAsStream(name);
120: }
121: return ris;
122: }
123: });
124: }
125: }
|