2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
19 * $Id: SecuritySupport12.java 468646 2006-10-28 06:57:58Z minchau $
22 package org.apache.xalan.xslt;
25 import java.io.FileInputStream;
26 import java.io.FileNotFoundException;
27 import java.io.InputStream;
29 import java.security.AccessController;
30 import java.security.PrivilegedAction;
31 import java.security.PrivilegedActionException;
32 import java.security.PrivilegedExceptionAction;
34 import java.util.Properties;
37 * This class is duplicated for each Xalan-Java subpackage so keep it in sync.
38 * It is package private and therefore is not exposed as part of the Xalan-Java
41 * Security related methods that only work on J2SE 1.2 and newer.
43 class SecuritySupport12 extends SecuritySupport {
45 ClassLoader getContextClassLoader() {
47 AccessController.doPrivileged(new PrivilegedAction() {
49 ClassLoader cl = null;
51 cl = Thread.currentThread().getContextClassLoader();
52 } catch (SecurityException ex) { }
58 ClassLoader getSystemClassLoader() {
60 AccessController.doPrivileged(new PrivilegedAction() {
62 ClassLoader cl = null;
64 cl = ClassLoader.getSystemClassLoader();
65 } catch (SecurityException ex) {}
71 ClassLoader getParentClassLoader(final ClassLoader cl) {
73 AccessController.doPrivileged(new PrivilegedAction() {
75 ClassLoader parent = null;
77 parent = cl.getParent();
78 } catch (SecurityException ex) {}
80 // eliminate loops in case of the boot
81 // ClassLoader returning itself as a parent
82 return (parent == cl) ? null : parent;
87 String getSystemProperty(final String propName) {
89 AccessController.doPrivileged(new PrivilegedAction() {
91 return System.getProperty(propName);
96 FileInputStream getFileInputStream(final File file)
97 throws FileNotFoundException
100 return (FileInputStream)
101 AccessController.doPrivileged(new PrivilegedExceptionAction() {
102 public Object run() throws FileNotFoundException {
103 return new FileInputStream(file);
106 } catch (PrivilegedActionException e) {
107 throw (FileNotFoundException)e.getException();
111 InputStream getResourceAsStream(final ClassLoader cl,
115 AccessController.doPrivileged(new PrivilegedAction() {
116 public Object run() {
119 ris = ClassLoader.getSystemResourceAsStream(name);
121 ris = cl.getResourceAsStream(name);
128 boolean getFileExists(final File f) {
130 AccessController.doPrivileged(new PrivilegedAction() {
131 public Object run() {
132 return new Boolean(f.exists());
137 long getLastModified(final File f) {
139 AccessController.doPrivileged(new PrivilegedAction() {
140 public Object run() {
141 return new Long(f.lastModified());