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: SecuritySupport.java,v 1.2 2009/12/10 03:18:39 matthewoliver Exp $
22
package org.apache.xml.dtm.ref;
25
import java.io.FileInputStream;
26
import java.io.FileNotFoundException;
27
import java.io.InputStream;
29
import java.util.Properties;
32
* This class is duplicated for each Xalan-Java subpackage so keep it in sync.
33
* It is package private and therefore is not exposed as part of the Xalan-Java
36
* Base class with security related methods that work on JDK 1.1.
38
class SecuritySupport {
41
* Make this of type Object so that the verifier won't try to
42
* prove its type, thus possibly trying to load the SecuritySupport12
45
private static final Object securitySupport;
48
SecuritySupport ss = null;
50
Class c = Class.forName("java.security.AccessController");
51
// if that worked, we're on 1.2.
53
// don't reference the class explicitly so it doesn't
54
// get dragged in accidentally.
55
c = Class.forName("javax.mail.SecuritySupport12");
56
Constructor cons = c.getConstructor(new Class[] { });
57
ss = (SecuritySupport)cons.newInstance(new Object[] { });
60
* Unfortunately, we can't load the class using reflection
61
* because the class is package private. And the class has
62
* to be package private so the APIs aren't exposed to other
63
* code that could use them to circumvent security. Thus,
64
* we accept the risk that the direct reference might fail
65
* on some JDK 1.1 JVMs, even though we would never execute
66
* this code in such a case. Sigh...
68
ss = new SecuritySupport12();
69
} catch (Exception ex) {
73
ss = new SecuritySupport();
79
* Return an appropriate instance of this class, depending on whether
80
* we're on a JDK 1.1 or J2SE 1.2 (or later) system.
82
static SecuritySupport getInstance() {
83
return (SecuritySupport)securitySupport;
86
ClassLoader getContextClassLoader() {
90
ClassLoader getSystemClassLoader() {
94
ClassLoader getParentClassLoader(ClassLoader cl) {
98
String getSystemProperty(String propName) {
99
return System.getProperty(propName);
102
FileInputStream getFileInputStream(File file)
103
throws FileNotFoundException
105
return new FileInputStream(file);
108
InputStream getResourceAsStream(ClassLoader cl, String name) {
111
ris = ClassLoader.getSystemResourceAsStream(name);
113
ris = cl.getResourceAsStream(name);
118
boolean getFileExists(File f) {
122
long getLastModified(File f) {
123
return f.lastModified();