KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > cyberneko > html > SecuritySupport


1 /*
2  * Copyright 2002,2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.cyberneko.html;
18
19 import java.io.*;
20
21 /**
22  * This class is duplicated for each JAXP subpackage so keep it in sync.
23  * It is package private and therefore is not exposed as part of the JAXP
24  * API.
25  *
26  * Base class with security related methods that work on JDK 1.1.
27  */

28 class SecuritySupport {
29
30     /*
31      * Make this of type Object so that the verifier won't try to
32      * prove its type, thus possibly trying to load the SecuritySupport12
33      * class.
34      */

35     private static final Object JavaDoc securitySupport;
36
37     static {
38     SecuritySupport ss = null;
39     try {
40         Class JavaDoc c = Class.forName("java.security.AccessController");
41         // if that worked, we're on 1.2.
42
/*
43         // don't reference the class explicitly so it doesn't
44         // get dragged in accidentally.
45         c = Class.forName("javax.mail.SecuritySupport12");
46         Constructor cons = c.getConstructor(new Class[] { });
47         ss = (SecuritySupport)cons.newInstance(new Object[] { });
48         */

49         /*
50          * Unfortunately, we can't load the class using reflection
51          * because the class is package private. And the class has
52          * to be package private so the APIs aren't exposed to other
53          * code that could use them to circumvent security. Thus,
54          * we accept the risk that the direct reference might fail
55          * on some JDK 1.1 JVMs, even though we would never execute
56          * this code in such a case. Sigh...
57          */

58         ss = new SecuritySupport12();
59     } catch (Exception JavaDoc ex) {
60         // ignore it
61
} finally {
62         if (ss == null)
63         ss = new SecuritySupport();
64         securitySupport = ss;
65     }
66     }
67
68     /**
69      * Return an appropriate instance of this class, depending on whether
70      * we're on a JDK 1.1 or J2SE 1.2 (or later) system.
71      */

72     static SecuritySupport getInstance() {
73     return (SecuritySupport)securitySupport;
74     }
75
76     ClassLoader JavaDoc getContextClassLoader() {
77     return null;
78     }
79
80     ClassLoader JavaDoc getSystemClassLoader() {
81         return null;
82     }
83
84     ClassLoader JavaDoc getParentClassLoader(ClassLoader JavaDoc cl) {
85         return null;
86     }
87
88     String JavaDoc getSystemProperty(String JavaDoc propName) {
89         return System.getProperty(propName);
90     }
91
92     FileInputStream getFileInputStream(File file)
93         throws FileNotFoundException
94     {
95         return new FileInputStream(file);
96     }
97
98     InputStream getResourceAsStream(ClassLoader JavaDoc cl, String JavaDoc name) {
99         InputStream ris;
100         if (cl == null) {
101             ris = ClassLoader.getSystemResourceAsStream(name);
102         } else {
103             ris = cl.getResourceAsStream(name);
104         }
105         return ris;
106     }
107
108     boolean getFileExists(File f) {
109         return f.exists();
110     }
111
112     long getLastModified(File f) {
113         return f.lastModified();
114     }
115 }
116
Popular Tags