1 16 17 package org.cyberneko.html; 18 19 import java.security.*; 20 import java.io.*; 21 22 29 class SecuritySupport12 extends SecuritySupport { 30 31 ClassLoader getContextClassLoader() { 32 return (ClassLoader ) 33 AccessController.doPrivileged(new PrivilegedAction() { 34 public Object run() { 35 ClassLoader cl = null; 36 try { 37 cl = Thread.currentThread().getContextClassLoader(); 38 } catch (SecurityException ex) { } 39 return cl; 40 } 41 }); 42 } 43 44 ClassLoader getSystemClassLoader() { 45 return (ClassLoader ) 46 AccessController.doPrivileged(new PrivilegedAction() { 47 public Object run() { 48 ClassLoader cl = null; 49 try { 50 cl = ClassLoader.getSystemClassLoader(); 51 } catch (SecurityException ex) {} 52 return cl; 53 } 54 }); 55 } 56 57 ClassLoader getParentClassLoader(final ClassLoader cl) { 58 return (ClassLoader ) 59 AccessController.doPrivileged(new PrivilegedAction() { 60 public Object run() { 61 ClassLoader parent = null; 62 try { 63 parent = cl.getParent(); 64 } catch (SecurityException ex) {} 65 66 return (parent == cl) ? null : parent; 69 } 70 }); 71 } 72 73 String getSystemProperty(final String propName) { 74 return (String ) 75 AccessController.doPrivileged(new PrivilegedAction() { 76 public Object run() { 77 return System.getProperty(propName); 78 } 79 }); 80 } 81 82 FileInputStream getFileInputStream(final File file) 83 throws FileNotFoundException 84 { 85 try { 86 return (FileInputStream) 87 AccessController.doPrivileged(new PrivilegedExceptionAction() { 88 public Object run() throws FileNotFoundException { 89 return new FileInputStream(file); 90 } 91 }); 92 } catch (PrivilegedActionException e) { 93 throw (FileNotFoundException)e.getException(); 94 } 95 } 96 97 InputStream getResourceAsStream(final ClassLoader cl, 98 final String name) 99 { 100 return (InputStream) 101 AccessController.doPrivileged(new PrivilegedAction() { 102 public Object run() { 103 InputStream ris; 104 if (cl == null) { 105 ris = ClassLoader.getSystemResourceAsStream(name); 106 } else { 107 ris = cl.getResourceAsStream(name); 108 } 109 return ris; 110 } 111 }); 112 } 113 114 boolean getFileExists(final File f) { 115 return ((Boolean ) 116 AccessController.doPrivileged(new PrivilegedAction() { 117 public Object run() { 118 return new Boolean (f.exists()); 119 } 120 })).booleanValue(); 121 } 122 123 long getLastModified(final File f) { 124 return ((Long ) 125 AccessController.doPrivileged(new PrivilegedAction() { 126 public Object run() { 127 return new Long (f.lastModified()); 128 } 129 })).longValue(); 130 } 131 132 } 133 | Popular Tags |