1 7 8 package javax.xml.validation; 9 10 import java.io.IOException ; 11 import java.net.URL ; 12 import java.security.*; 13 import java.net.*; 14 import java.io.*; 15 import java.util.*; 16 17 24 class SecuritySupport { 25 26 27 ClassLoader getContextClassLoader() { 28 return (ClassLoader ) 29 AccessController.doPrivileged(new PrivilegedAction() { 30 public Object run() { 31 ClassLoader cl = null; 32 try { 33 cl = Thread.currentThread().getContextClassLoader(); 34 } catch (SecurityException ex) { } 35 return cl; 36 } 37 }); 38 } 39 40 String getSystemProperty(final String propName) { 41 return (String ) 42 AccessController.doPrivileged(new PrivilegedAction() { 43 public Object run() { 44 return System.getProperty(propName); 45 } 46 }); 47 } 48 49 FileInputStream getFileInputStream(final File file) 50 throws FileNotFoundException 51 { 52 try { 53 return (FileInputStream) 54 AccessController.doPrivileged(new PrivilegedExceptionAction() { 55 public Object run() throws FileNotFoundException { 56 return new FileInputStream(file); 57 } 58 }); 59 } catch (PrivilegedActionException e) { 60 throw (FileNotFoundException)e.getException(); 61 } 62 } 63 64 InputStream getURLInputStream(final URL url) 65 throws IOException 66 { 67 try { 68 return (InputStream) 69 AccessController.doPrivileged(new PrivilegedExceptionAction() { 70 public Object run() throws IOException { 71 return url.openStream(); 72 } 73 }); 74 } catch (PrivilegedActionException e) { 75 throw (IOException )e.getException(); 76 } 77 } 78 79 URL getResourceAsURL(final ClassLoader cl, 80 final String name) 81 { 82 return (URL ) 83 AccessController.doPrivileged(new PrivilegedAction() { 84 public Object run() { 85 URL url; 86 if (cl == null) { 87 url = ClassLoader.getSystemResource(name); 88 } else { 89 url = cl.getResource(name); 90 } 91 return url; 92 } 93 }); 94 } 95 96 Enumeration getResources(final ClassLoader cl, 97 final String name) throws IOException 98 { 99 try{ 100 return (Enumeration) 101 AccessController.doPrivileged(new PrivilegedExceptionAction() { 102 public Object run() throws IOException { 103 Enumeration enumeration; 104 if (cl == null) { 105 enumeration = ClassLoader.getSystemResources(name); 106 } else { 107 enumeration = cl.getResources(name); 108 } 109 return enumeration; 110 } 111 }); 112 }catch(PrivilegedActionException e){ 113 throw (IOException )e.getException(); 114 } 115 } 116 117 InputStream getResourceAsStream(final ClassLoader cl, 118 final String name) 119 { 120 return (InputStream) 121 AccessController.doPrivileged(new PrivilegedAction() { 122 public Object run() { 123 InputStream ris; 124 if (cl == null) { 125 ris = ClassLoader.getSystemResourceAsStream(name); 126 } else { 127 ris = cl.getResourceAsStream(name); 128 } 129 return ris; 130 } 131 }); 132 } 133 134 boolean doesFileExist(final File f) { 135 return ((Boolean ) 136 AccessController.doPrivileged(new PrivilegedAction() { 137 public Object run() { 138 return new Boolean (f.exists()); 139 } 140 })).booleanValue(); 141 } 142 143 } 144 | Popular Tags |