001: /*
002: * Copyright 2002,2004 The Apache Software Foundation.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package org.cyberneko.pull.parsers;
018:
019: import java.security.*;
020: import java.io.*;
021:
022: /**
023: * This class is duplicated for each JAXP subpackage so keep it in sync.
024: * It is package private and therefore is not exposed as part of the JAXP
025: * API.
026: *
027: * Security related methods that only work on J2SE 1.2 and newer.
028: */
029: class SecuritySupport12 extends SecuritySupport {
030:
031: ClassLoader getContextClassLoader() {
032: return (ClassLoader) AccessController
033: .doPrivileged(new PrivilegedAction() {
034: public Object run() {
035: ClassLoader cl = null;
036: try {
037: cl = Thread.currentThread()
038: .getContextClassLoader();
039: } catch (SecurityException ex) {
040: }
041: return cl;
042: }
043: });
044: }
045:
046: ClassLoader getSystemClassLoader() {
047: return (ClassLoader) AccessController
048: .doPrivileged(new PrivilegedAction() {
049: public Object run() {
050: ClassLoader cl = null;
051: try {
052: cl = ClassLoader.getSystemClassLoader();
053: } catch (SecurityException ex) {
054: }
055: return cl;
056: }
057: });
058: }
059:
060: ClassLoader getParentClassLoader(final ClassLoader cl) {
061: return (ClassLoader) AccessController
062: .doPrivileged(new PrivilegedAction() {
063: public Object run() {
064: ClassLoader parent = null;
065: try {
066: parent = cl.getParent();
067: } catch (SecurityException ex) {
068: }
069:
070: // eliminate loops in case of the boot
071: // ClassLoader returning itself as a parent
072: return (parent == cl) ? null : parent;
073: }
074: });
075: }
076:
077: String getSystemProperty(final String propName) {
078: return (String) AccessController
079: .doPrivileged(new PrivilegedAction() {
080: public Object run() {
081: return System.getProperty(propName);
082: }
083: });
084: }
085:
086: FileInputStream getFileInputStream(final File file)
087: throws FileNotFoundException {
088: try {
089: return (FileInputStream) AccessController
090: .doPrivileged(new PrivilegedExceptionAction() {
091: public Object run()
092: throws FileNotFoundException {
093: return new FileInputStream(file);
094: }
095: });
096: } catch (PrivilegedActionException e) {
097: throw (FileNotFoundException) e.getException();
098: }
099: }
100:
101: InputStream getResourceAsStream(final ClassLoader cl,
102: final String name) {
103: return (InputStream) AccessController
104: .doPrivileged(new PrivilegedAction() {
105: public Object run() {
106: InputStream ris;
107: if (cl == null) {
108: ris = ClassLoader
109: .getSystemResourceAsStream(name);
110: } else {
111: ris = cl.getResourceAsStream(name);
112: }
113: return ris;
114: }
115: });
116: }
117:
118: boolean getFileExists(final File f) {
119: return ((Boolean) AccessController
120: .doPrivileged(new PrivilegedAction() {
121: public Object run() {
122: return new Boolean(f.exists());
123: }
124: })).booleanValue();
125: }
126:
127: long getLastModified(final File f) {
128: return ((Long) AccessController
129: .doPrivileged(new PrivilegedAction() {
130: public Object run() {
131: return new Long(f.lastModified());
132: }
133: })).longValue();
134: }
135:
136: }
|