Home » xml-commons-external-1.4.01-src » org.xml » sax » helpers » [javadoc | source]

    1   /*
    2    * Licensed to the Apache Software Foundation (ASF) under one or more
    3    * contributor license agreements.  See the NOTICE file distributed with
    4    * this work for additional information regarding copyright ownership.
    5    * The ASF licenses this file to You under the Apache License, Version 2.0
    6    * (the "License"); you may not use this file except in compliance with
    7    * the License.  You may obtain a copy of the License at
    8    *
    9    *     http://www.apache.org/licenses/LICENSE-2.0
   10    *
   11    * Unless required by applicable law or agreed to in writing, software
   12    * distributed under the License is distributed on an "AS IS" BASIS,
   13    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   14    * See the License for the specific language governing permissions and
   15    * limitations under the License.
   16    */
   17   
   18   package org.xml.sax.helpers;
   19   
   20   import java.io.File;
   21   import java.io.FileInputStream;
   22   import java.io.FileNotFoundException;
   23   import java.io.InputStream;
   24   import java.security.AccessController;
   25   import java.security.PrivilegedAction;
   26   import java.security.PrivilegedActionException;
   27   import java.security.PrivilegedExceptionAction;
   28   
   29   /**
   30    * This class is duplicated for each JAXP subpackage so keep it in sync.
   31    * It is package private and therefore is not exposed as part of the JAXP
   32    * API.
   33    *
   34    * Security related methods that only work on J2SE 1.2 and newer.
   35    */
   36   final class SecuritySupport {
   37       
   38       private SecuritySupport() {}
   39   
   40       static ClassLoader getContextClassLoader() {
   41   	return (ClassLoader)
   42   		AccessController.doPrivileged(new PrivilegedAction() {
   43   	    public Object run() {
   44   		ClassLoader cl = null;
   45   		try {
   46   		    cl = Thread.currentThread().getContextClassLoader();
   47   		} catch (SecurityException ex) { }
   48   		return cl;
   49   	    }
   50   	});
   51       }
   52   
   53       static String getSystemProperty(final String propName) {
   54   	return (String)
   55               AccessController.doPrivileged(new PrivilegedAction() {
   56                   public Object run() {
   57                       return System.getProperty(propName);
   58                   }
   59               });
   60       }
   61   
   62       static FileInputStream getFileInputStream(final File file)
   63           throws FileNotFoundException
   64       {
   65   	try {
   66               return (FileInputStream)
   67                   AccessController.doPrivileged(new PrivilegedExceptionAction() {
   68                       public Object run() throws FileNotFoundException {
   69                           return new FileInputStream(file);
   70                       }
   71                   });
   72   	} catch (PrivilegedActionException e) {
   73   	    throw (FileNotFoundException)e.getException();
   74   	}
   75       }
   76   
   77       static InputStream getResourceAsStream(final ClassLoader cl,
   78                                              final String name)
   79       {
   80           return (InputStream)
   81               AccessController.doPrivileged(new PrivilegedAction() {
   82                   public Object run() {
   83                       InputStream ris;
   84                       if (cl == null) {
   85                           ris = ClassLoader.getSystemResourceAsStream(name);
   86                       } else {
   87                           ris = cl.getResourceAsStream(name);
   88                       }
   89                       return ris;
   90                   }
   91               });
   92       }
   93   }

Home » xml-commons-external-1.4.01-src » org.xml » sax » helpers » [javadoc | source]