KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > xml > sax > helpers > SecuritySupport12


1 /*
2  * Copyright 2002-2005 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.xml.sax.helpers;
18
19 import java.io.File JavaDoc;
20 import java.io.FileInputStream JavaDoc;
21 import java.io.FileNotFoundException JavaDoc;
22 import java.io.InputStream JavaDoc;
23 import java.security.AccessController JavaDoc;
24 import java.security.PrivilegedAction JavaDoc;
25 import java.security.PrivilegedActionException JavaDoc;
26 import java.security.PrivilegedExceptionAction JavaDoc;
27
28 /**
29  * This class is duplicated for each JAXP subpackage so keep it in sync.
30  * It is package private and therefore is not exposed as part of the JAXP
31  * API.
32  *
33  * Security related methods that only work on J2SE 1.2 and newer.
34  */

35 class SecuritySupport12 extends SecuritySupport JavaDoc {
36
37     public ClassLoader JavaDoc getContextClassLoader() {
38     return (ClassLoader JavaDoc)
39         AccessController.doPrivileged(new PrivilegedAction JavaDoc() {
40         public Object JavaDoc run() {
41         ClassLoader JavaDoc cl = null;
42         try {
43             cl = Thread.currentThread().getContextClassLoader();
44         } catch (SecurityException JavaDoc ex) { }
45         return cl;
46         }
47     });
48     }
49
50     public String JavaDoc getSystemProperty(final String JavaDoc propName) {
51     return (String JavaDoc)
52             AccessController.doPrivileged(new PrivilegedAction JavaDoc() {
53                 public Object JavaDoc run() {
54                     return System.getProperty(propName);
55                 }
56             });
57     }
58
59     public FileInputStream JavaDoc getFileInputStream(final File JavaDoc file)
60         throws FileNotFoundException JavaDoc
61     {
62     try {
63             return (FileInputStream JavaDoc)
64                 AccessController.doPrivileged(new PrivilegedExceptionAction JavaDoc() {
65                     public Object JavaDoc run() throws FileNotFoundException JavaDoc {
66                         return new FileInputStream JavaDoc(file);
67                     }
68                 });
69     } catch (PrivilegedActionException JavaDoc e) {
70         throw (FileNotFoundException JavaDoc)e.getException();
71     }
72     }
73
74     public InputStream JavaDoc getResourceAsStream(final ClassLoader JavaDoc cl,
75                                            final String JavaDoc name)
76     {
77         return (InputStream JavaDoc)
78             AccessController.doPrivileged(new PrivilegedAction JavaDoc() {
79                 public Object JavaDoc run() {
80                     InputStream JavaDoc ris;
81                     if (cl == null) {
82                         ris = ClassLoader.getSystemResourceAsStream(name);
83                     } else {
84                         ris = cl.getResourceAsStream(name);
85                     }
86                     return ris;
87                 }
88             });
89     }
90 }
91
Popular Tags