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