KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > org > apache > xerces > internal > xinclude > SecuritySupport12


1 /*
2  * The Apache Software License, Version 1.1
3  *
4  *
5  * Copyright (c) 2002 The Apache Software Foundation. All rights
6  * reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in
17  * the documentation and/or other materials provided with the
18  * distribution.
19  *
20  * 3. The end-user documentation included with the redistribution,
21  * if any, must include the following acknowledgment:
22  * "This product includes software developed by the
23  * Apache Software Foundation (http://www.apache.org/)."
24  * Alternately, this acknowledgment may appear in the software itself,
25  * if and wherever such third-party acknowledgments normally appear.
26  *
27  * 4. The name "Apache Software Foundation" must not be used to endorse or
28  * promote products derived from this software without prior written
29  * permission. For written permission, please contact apache@apache.org.
30  *
31  * 5. Products derived from this software may not be called "Apache",
32  * nor may "Apache" appear in their name, without prior written
33  * permission of the Apache Software Foundation.
34  *
35  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
36  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
37  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
38  * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
39  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
41  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
42  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
43  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
44  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
45  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
46  * SUCH DAMAGE.
47  * ====================================================================
48  *
49  * This software consists of voluntary contributions made by many
50  * individuals on behalf of the Apache Software Foundation and was
51  * originally based on software copyright (c) 1999-2002, Sun Microsystems,
52  * Inc., http://www.sun.com. For more information on the Apache Software
53  * Foundation, please see <http://www.apache.org/>.
54  */

55
56 package com.sun.org.apache.xerces.internal.xinclude;
57
58 import java.security.*;
59 import java.io.*;
60
61 /**
62  * This class is duplicated for each JAXP subpackage so keep it in sync.
63  * It is package private and therefore is not exposed as part of the JAXP
64  * API.
65  *
66  * Security related methods that only work on J2SE 1.2 and newer.
67  */

68 class SecuritySupport12 extends SecuritySupport {
69
70     ClassLoader JavaDoc getContextClassLoader() {
71     return (ClassLoader JavaDoc)
72         AccessController.doPrivileged(new PrivilegedAction() {
73         public Object JavaDoc run() {
74         ClassLoader JavaDoc cl = null;
75         try {
76             cl = Thread.currentThread().getContextClassLoader();
77         } catch (SecurityException JavaDoc ex) { }
78         return cl;
79         }
80     });
81     }
82
83     ClassLoader JavaDoc getSystemClassLoader() {
84         return (ClassLoader JavaDoc)
85             AccessController.doPrivileged(new PrivilegedAction() {
86                 public Object JavaDoc run() {
87                     ClassLoader JavaDoc cl = null;
88                     try {
89                         cl = ClassLoader.getSystemClassLoader();
90                     } catch (SecurityException JavaDoc ex) {}
91                     return cl;
92                 }
93             });
94     }
95
96     ClassLoader JavaDoc getParentClassLoader(final ClassLoader JavaDoc cl) {
97         return (ClassLoader JavaDoc)
98             AccessController.doPrivileged(new PrivilegedAction() {
99                 public Object JavaDoc run() {
100                     ClassLoader JavaDoc parent = null;
101                     try {
102                         parent = cl.getParent();
103                     } catch (SecurityException JavaDoc ex) {}
104
105                     // eliminate loops in case of the boot
106
// ClassLoader returning itself as a parent
107
return (parent == cl) ? null : parent;
108                 }
109             });
110     }
111
112     String JavaDoc getSystemProperty(final String JavaDoc propName) {
113     return (String JavaDoc)
114             AccessController.doPrivileged(new PrivilegedAction() {
115                 public Object JavaDoc run() {
116                     return System.getProperty(propName);
117                 }
118             });
119     }
120
121     FileInputStream getFileInputStream(final File file)
122         throws FileNotFoundException
123     {
124     try {
125             return (FileInputStream)
126                 AccessController.doPrivileged(new PrivilegedExceptionAction() {
127                     public Object JavaDoc run() throws FileNotFoundException {
128                         return new FileInputStream(file);
129                     }
130                 });
131     } catch (PrivilegedActionException e) {
132         throw (FileNotFoundException)e.getException();
133     }
134     }
135
136     InputStream getResourceAsStream(final ClassLoader JavaDoc cl,
137                                            final String JavaDoc name)
138     {
139         return (InputStream)
140             AccessController.doPrivileged(new PrivilegedAction() {
141                 public Object JavaDoc run() {
142                     InputStream ris;
143                     if (cl == null) {
144                         ris = ClassLoader.getSystemResourceAsStream(name);
145                     } else {
146                         ris = cl.getResourceAsStream(name);
147                     }
148                     return ris;
149                 }
150             });
151     }
152
153     boolean getFileExists(final File f) {
154     return ((Boolean JavaDoc)
155             AccessController.doPrivileged(new PrivilegedAction() {
156                 public Object JavaDoc run() {
157                     return new Boolean JavaDoc(f.exists());
158                 }
159             })).booleanValue();
160     }
161
162     long getLastModified(final File f) {
163     return ((Long JavaDoc)
164             AccessController.doPrivileged(new PrivilegedAction() {
165                 public Object JavaDoc run() {
166                     return new Long JavaDoc(f.lastModified());
167                 }
168             })).longValue();
169     }
170
171 }
172
Popular Tags