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: * $Id: SecuritySupport.java,v 1.3 2004/02/23 10:29:37 aruny Exp $
018: */
019:
020: package org.apache.xpath.functions;
021:
022: import java.io.File;
023: import java.io.FileInputStream;
024: import java.io.FileNotFoundException;
025: import java.io.InputStream;
026:
027: import java.util.Properties;
028:
029: /**
030: * This class is duplicated for each Xalan-Java subpackage so keep it in sync.
031: * It is package private and therefore is not exposed as part of the Xalan-Java
032: * API.
033: *
034: * Base class with security related methods that work on JDK 1.1.
035: */
036: class SecuritySupport {
037:
038: /*
039: * Make this of type Object so that the verifier won't try to
040: * prove its type, thus possibly trying to load the SecuritySupport12
041: * class.
042: */
043: private static final Object securitySupport;
044:
045: static {
046: SecuritySupport ss = null;
047: try {
048: Class c = Class.forName("java.security.AccessController");
049: // if that worked, we're on 1.2.
050: /*
051: // don't reference the class explicitly so it doesn't
052: // get dragged in accidentally.
053: c = Class.forName("javax.mail.SecuritySupport12");
054: Constructor cons = c.getConstructor(new Class[] { });
055: ss = (SecuritySupport)cons.newInstance(new Object[] { });
056: */
057: /*
058: * Unfortunately, we can't load the class using reflection
059: * because the class is package private. And the class has
060: * to be package private so the APIs aren't exposed to other
061: * code that could use them to circumvent security. Thus,
062: * we accept the risk that the direct reference might fail
063: * on some JDK 1.1 JVMs, even though we would never execute
064: * this code in such a case. Sigh...
065: */
066: ss = new SecuritySupport12();
067: } catch (Exception ex) {
068: // ignore it
069: } finally {
070: if (ss == null)
071: ss = new SecuritySupport();
072: securitySupport = ss;
073: }
074: }
075:
076: /**
077: * Return an appropriate instance of this class, depending on whether
078: * we're on a JDK 1.1 or J2SE 1.2 (or later) system.
079: */
080: static SecuritySupport getInstance() {
081: return (SecuritySupport) securitySupport;
082: }
083:
084: ClassLoader getContextClassLoader() {
085: return null;
086: }
087:
088: ClassLoader getSystemClassLoader() {
089: return null;
090: }
091:
092: ClassLoader getParentClassLoader(ClassLoader cl) {
093: return null;
094: }
095:
096: String getSystemProperty(String propName) {
097: return System.getProperty(propName);
098: }
099:
100: FileInputStream getFileInputStream(File file)
101: throws FileNotFoundException {
102: return new FileInputStream(file);
103: }
104:
105: InputStream getResourceAsStream(ClassLoader cl, String name) {
106: InputStream ris;
107: if (cl == null) {
108: ris = ClassLoader.getSystemResourceAsStream(name);
109: } else {
110: ris = cl.getResourceAsStream(name);
111: }
112: return ris;
113: }
114:
115: boolean getFileExists(File f) {
116: return f.exists();
117: }
118:
119: long getLastModified(File f) {
120: return f.lastModified();
121: }
122: }
|