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 468654 2006-10-28 07:09:23Z minchau $
22 package org.apache.xml.serializer;
25 import java.io.FileInputStream;
26 import java.io.FileNotFoundException;
27 import java.io.InputStream;
28 import java.security.AccessController;
29 import java.security.PrivilegedAction;
30 import java.security.PrivilegedActionException;
31 import java.security.PrivilegedExceptionAction;
34 * This class is duplicated for each Xalan-Java subpackage so keep it in sync.
35 * It is package private and therefore is not exposed as part of the Xalan-Java
38 * Security related methods that only work on J2SE 1.2 and newer.
40 class SecuritySupport12 extends SecuritySupport {
42 ClassLoader getContextClassLoader() {
44 AccessController.doPrivileged(new PrivilegedAction() {
46 ClassLoader cl = null;
48 cl = Thread.currentThread().getContextClassLoader();
49 } catch (SecurityException ex) { }
55 ClassLoader getSystemClassLoader() {
57 AccessController.doPrivileged(new PrivilegedAction() {
59 ClassLoader cl = null;
61 cl = ClassLoader.getSystemClassLoader();
62 } catch (SecurityException ex) {}
68 ClassLoader getParentClassLoader(final ClassLoader cl) {
70 AccessController.doPrivileged(new PrivilegedAction() {
72 ClassLoader parent = null;
74 parent = cl.getParent();
75 } catch (SecurityException ex) {}
77 // eliminate loops in case of the boot
78 // ClassLoader returning itself as a parent
79 return (parent == cl) ? null : parent;
84 String getSystemProperty(final String propName) {
86 AccessController.doPrivileged(new PrivilegedAction() {
88 return System.getProperty(propName);
93 FileInputStream getFileInputStream(final File file)
94 throws FileNotFoundException
97 return (FileInputStream)
98 AccessController.doPrivileged(new PrivilegedExceptionAction() {
99 public Object run() throws FileNotFoundException {
100 return new FileInputStream(file);
103 } catch (PrivilegedActionException e) {
104 throw (FileNotFoundException)e.getException();
108 InputStream getResourceAsStream(final ClassLoader cl,
112 AccessController.doPrivileged(new PrivilegedAction() {
113 public Object run() {
116 ris = ClassLoader.getSystemResourceAsStream(name);
118 ris = cl.getResourceAsStream(name);
125 boolean getFileExists(final File f) {
127 AccessController.doPrivileged(new PrivilegedAction() {
128 public Object run() {
129 return new Boolean(f.exists());
134 long getLastModified(final File f) {
136 AccessController.doPrivileged(new PrivilegedAction() {
137 public Object run() {
138 return new Long(f.lastModified());