|
1 /* |
|
2 * Copyright 2004-2006 Sun Microsystems, Inc. All Rights Reserved. |
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 * |
|
5 * This code is free software; you can redistribute it and/or modify it |
|
6 * under the terms of the GNU General Public License version 2 only, as |
|
7 * published by the Free Software Foundation. Sun designates this |
|
8 * particular file as subject to the "Classpath" exception as provided |
|
9 * by Sun in the LICENSE file that accompanied this code. |
|
10 * |
|
11 * This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 * version 2 for more details (a copy is included in the LICENSE file that |
|
15 * accompanied this code). |
|
16 * |
|
17 * You should have received a copy of the GNU General Public License version |
|
18 * 2 along with this work; if not, write to the Free Software Foundation, |
|
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 * |
|
21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
22 * CA 95054 USA or visit www.sun.com if you need additional information or |
|
23 * have any questions. |
|
24 */ |
|
25 |
|
26 package javax.xml.parsers; |
|
27 |
|
28 import java.security.*; |
|
29 import java.net.*; |
|
30 import java.io.*; |
|
31 import java.util.*; |
|
32 |
|
33 /** |
|
34 * This class is duplicated for each JAXP subpackage so keep it in sync. |
|
35 * It is package private and therefore is not exposed as part of the JAXP |
|
36 * API. |
|
37 * |
|
38 * Security related methods that only work on J2SE 1.2 and newer. |
|
39 */ |
|
40 class SecuritySupport { |
|
41 |
|
42 |
|
43 ClassLoader getContextClassLoader() throws SecurityException{ |
|
44 return (ClassLoader) |
|
45 AccessController.doPrivileged(new PrivilegedAction() { |
|
46 public Object run() { |
|
47 ClassLoader cl = null; |
|
48 //try { |
|
49 cl = Thread.currentThread().getContextClassLoader(); |
|
50 //} catch (SecurityException ex) { } |
|
51 |
|
52 if (cl == null) |
|
53 cl = ClassLoader.getSystemClassLoader(); |
|
54 |
|
55 return cl; |
|
56 } |
|
57 }); |
|
58 } |
|
59 |
|
60 String getSystemProperty(final String propName) { |
|
61 return (String) |
|
62 AccessController.doPrivileged(new PrivilegedAction() { |
|
63 public Object run() { |
|
64 return System.getProperty(propName); |
|
65 } |
|
66 }); |
|
67 } |
|
68 |
|
69 FileInputStream getFileInputStream(final File file) |
|
70 throws FileNotFoundException |
|
71 { |
|
72 try { |
|
73 return (FileInputStream) |
|
74 AccessController.doPrivileged(new PrivilegedExceptionAction() { |
|
75 public Object run() throws FileNotFoundException { |
|
76 return new FileInputStream(file); |
|
77 } |
|
78 }); |
|
79 } catch (PrivilegedActionException e) { |
|
80 throw (FileNotFoundException)e.getException(); |
|
81 } |
|
82 } |
|
83 |
|
84 InputStream getResourceAsStream(final ClassLoader cl, |
|
85 final String name) |
|
86 { |
|
87 return (InputStream) |
|
88 AccessController.doPrivileged(new PrivilegedAction() { |
|
89 public Object run() { |
|
90 InputStream ris; |
|
91 if (cl == null) { |
|
92 ris = ClassLoader.getSystemResourceAsStream(name); |
|
93 } else { |
|
94 ris = cl.getResourceAsStream(name); |
|
95 } |
|
96 return ris; |
|
97 } |
|
98 }); |
|
99 } |
|
100 |
|
101 boolean doesFileExist(final File f) { |
|
102 return ((Boolean) |
|
103 AccessController.doPrivileged(new PrivilegedAction() { |
|
104 public Object run() { |
|
105 return new Boolean(f.exists()); |
|
106 } |
|
107 })).booleanValue(); |
|
108 } |
|
109 |
|
110 } |