author | dfuchs |
Thu, 25 Jun 2015 20:06:37 +0200 | |
changeset 31287 | d6581a7c221f |
parent 31284 | e9b8469adb9a |
child 31288 | 204ed502eb8a |
permissions | -rw-r--r-- |
12005 | 1 |
/* |
2 |
* Copyright (c) 2005, 2006, Oracle and/or its affiliates. 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. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
24 |
*/ |
|
25 |
||
26 |
package javax.xml.validation; |
|
27 |
||
28 |
import java.io.IOException; |
|
29 |
import java.net.URL; |
|
30 |
import java.security.*; |
|
31 |
import java.io.*; |
|
32 |
import java.util.*; |
|
33 |
||
34 |
/** |
|
35 |
* This class is duplicated for each JAXP subpackage so keep it in sync. |
|
36 |
* It is package private and therefore is not exposed as part of the JAXP |
|
37 |
* API. |
|
38 |
* |
|
39 |
* Security related methods that only work on J2SE 1.2 and newer. |
|
40 |
*/ |
|
41 |
class SecuritySupport { |
|
42 |
||
43 |
||
44 |
ClassLoader getContextClassLoader() { |
|
45 |
return (ClassLoader) |
|
46 |
AccessController.doPrivileged(new PrivilegedAction() { |
|
47 |
public Object run() { |
|
48 |
ClassLoader cl = null; |
|
49 |
//try { |
|
50 |
cl = Thread.currentThread().getContextClassLoader(); |
|
51 |
//} catch (SecurityException ex) { } |
|
52 |
if (cl == null) |
|
53 |
cl = ClassLoader.getSystemClassLoader(); |
|
54 |
return cl; |
|
55 |
} |
|
56 |
}); |
|
57 |
} |
|
58 |
||
59 |
String getSystemProperty(final String propName) { |
|
60 |
return (String) |
|
61 |
AccessController.doPrivileged(new PrivilegedAction() { |
|
62 |
public Object run() { |
|
63 |
return System.getProperty(propName); |
|
64 |
} |
|
65 |
}); |
|
66 |
} |
|
67 |
||
68 |
FileInputStream getFileInputStream(final File file) |
|
69 |
throws FileNotFoundException |
|
70 |
{ |
|
71 |
try { |
|
72 |
return (FileInputStream) |
|
73 |
AccessController.doPrivileged(new PrivilegedExceptionAction() { |
|
74 |
public Object run() throws FileNotFoundException { |
|
75 |
return new FileInputStream(file); |
|
76 |
} |
|
77 |
}); |
|
78 |
} catch (PrivilegedActionException e) { |
|
79 |
throw (FileNotFoundException)e.getException(); |
|
80 |
} |
|
81 |
} |
|
82 |
||
83 |
InputStream getURLInputStream(final URL url) |
|
84 |
throws IOException |
|
85 |
{ |
|
86 |
try { |
|
87 |
return (InputStream) |
|
88 |
AccessController.doPrivileged(new PrivilegedExceptionAction() { |
|
89 |
public Object run() throws IOException { |
|
90 |
return url.openStream(); |
|
91 |
} |
|
92 |
}); |
|
93 |
} catch (PrivilegedActionException e) { |
|
94 |
throw (IOException)e.getException(); |
|
95 |
} |
|
96 |
} |
|
97 |
||
31287
d6581a7c221f
8129880: Cleanup usage of Class.getResource in jaxp
dfuchs
parents:
31284
diff
changeset
|
98 |
// Used for debugging purposes |
d6581a7c221f
8129880: Cleanup usage of Class.getResource in jaxp
dfuchs
parents:
31284
diff
changeset
|
99 |
String getClassSource(Class<?> cls) { |
d6581a7c221f
8129880: Cleanup usage of Class.getResource in jaxp
dfuchs
parents:
31284
diff
changeset
|
100 |
return AccessController.doPrivileged(new PrivilegedAction<String>() { |
d6581a7c221f
8129880: Cleanup usage of Class.getResource in jaxp
dfuchs
parents:
31284
diff
changeset
|
101 |
public String run() { |
d6581a7c221f
8129880: Cleanup usage of Class.getResource in jaxp
dfuchs
parents:
31284
diff
changeset
|
102 |
CodeSource cs = cls.getProtectionDomain().getCodeSource(); |
d6581a7c221f
8129880: Cleanup usage of Class.getResource in jaxp
dfuchs
parents:
31284
diff
changeset
|
103 |
if (cs != null) { |
d6581a7c221f
8129880: Cleanup usage of Class.getResource in jaxp
dfuchs
parents:
31284
diff
changeset
|
104 |
return cs.getLocation().toString(); |
d6581a7c221f
8129880: Cleanup usage of Class.getResource in jaxp
dfuchs
parents:
31284
diff
changeset
|
105 |
} else { |
d6581a7c221f
8129880: Cleanup usage of Class.getResource in jaxp
dfuchs
parents:
31284
diff
changeset
|
106 |
return "(no code source)"; |
d6581a7c221f
8129880: Cleanup usage of Class.getResource in jaxp
dfuchs
parents:
31284
diff
changeset
|
107 |
} |
d6581a7c221f
8129880: Cleanup usage of Class.getResource in jaxp
dfuchs
parents:
31284
diff
changeset
|
108 |
} |
d6581a7c221f
8129880: Cleanup usage of Class.getResource in jaxp
dfuchs
parents:
31284
diff
changeset
|
109 |
}); |
12005 | 110 |
} |
111 |
||
112 |
boolean doesFileExist(final File f) { |
|
31287
d6581a7c221f
8129880: Cleanup usage of Class.getResource in jaxp
dfuchs
parents:
31284
diff
changeset
|
113 |
return ((Boolean) |
12005 | 114 |
AccessController.doPrivileged(new PrivilegedAction() { |
115 |
public Object run() { |
|
116 |
return new Boolean(f.exists()); |
|
117 |
} |
|
118 |
})).booleanValue(); |
|
119 |
} |
|
120 |
||
121 |
} |