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