Home | History | Annotate | Download | only in xslt
      1 /*
      2  * Licensed to the Apache Software Foundation (ASF) under one
      3  * or more contributor license agreements. See the NOTICE file
      4  * distributed with this work for additional information
      5  * regarding copyright ownership. The ASF licenses this file
      6  * to you under the Apache License, Version 2.0 (the  "License");
      7  * you may not use this file except in compliance with the License.
      8  * You may obtain a copy of the License at
      9  *
     10  *     http://www.apache.org/licenses/LICENSE-2.0
     11  *
     12  * Unless required by applicable law or agreed to in writing, software
     13  * distributed under the License is distributed on an "AS IS" BASIS,
     14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     15  * See the License for the specific language governing permissions and
     16  * limitations under the License.
     17  */
     18 /*
     19  * $Id: SecuritySupport.java 468646 2006-10-28 06:57:58Z minchau $
     20  */
     21 
     22 package org.apache.xalan.xslt;
     23 
     24 import java.io.File;
     25 import java.io.FileInputStream;
     26 import java.io.FileNotFoundException;
     27 import java.io.InputStream;
     28 
     29 import java.util.Properties;
     30 
     31 /**
     32  * This class is duplicated for each Xalan-Java subpackage so keep it in sync.
     33  * It is package private and therefore is not exposed as part of the Xalan-Java
     34  * API.
     35  *
     36  * Base class with security related methods that work on JDK 1.1.
     37  */
     38 class SecuritySupport {
     39 
     40     /*
     41      * Make this of type Object so that the verifier won't try to
     42      * prove its type, thus possibly trying to load the SecuritySupport12
     43      * class.
     44      */
     45     private static final Object securitySupport;
     46 
     47     static {
     48 	SecuritySupport ss = null;
     49 	try {
     50 	    Class c = Class.forName("java.security.AccessController");
     51 	    // if that worked, we're on 1.2.
     52 	    /*
     53 	    // don't reference the class explicitly so it doesn't
     54 	    // get dragged in accidentally.
     55 	    c = Class.forName("javax.mail.SecuritySupport12");
     56 	    Constructor cons = c.getConstructor(new Class[] { });
     57 	    ss = (SecuritySupport)cons.newInstance(new Object[] { });
     58 	    */
     59 	    /*
     60 	     * Unfortunately, we can't load the class using reflection
     61 	     * because the class is package private.  And the class has
     62 	     * to be package private so the APIs aren't exposed to other
     63 	     * code that could use them to circumvent security.  Thus,
     64 	     * we accept the risk that the direct reference might fail
     65 	     * on some JDK 1.1 JVMs, even though we would never execute
     66 	     * this code in such a case.  Sigh...
     67 	     */
     68 	    ss = new SecuritySupport12();
     69 	} catch (Exception ex) {
     70 	    // ignore it
     71 	} finally {
     72 	    if (ss == null)
     73 		ss = new SecuritySupport();
     74 	    securitySupport = ss;
     75 	}
     76     }
     77 
     78     /**
     79      * Return an appropriate instance of this class, depending on whether
     80      * we're on a JDK 1.1 or J2SE 1.2 (or later) system.
     81      */
     82     static SecuritySupport getInstance() {
     83 	return (SecuritySupport)securitySupport;
     84     }
     85 
     86     ClassLoader getContextClassLoader() {
     87 	return null;
     88     }
     89 
     90     ClassLoader getSystemClassLoader() {
     91         return null;
     92     }
     93 
     94     ClassLoader getParentClassLoader(ClassLoader cl) {
     95         return null;
     96     }
     97 
     98     String getSystemProperty(String propName) {
     99         return System.getProperty(propName);
    100     }
    101 
    102     FileInputStream getFileInputStream(File file)
    103         throws FileNotFoundException
    104     {
    105         return new FileInputStream(file);
    106     }
    107 
    108     InputStream getResourceAsStream(ClassLoader cl, String name) {
    109         InputStream ris;
    110         if (cl == null) {
    111             ris = ClassLoader.getSystemResourceAsStream(name);
    112         } else {
    113             ris = cl.getResourceAsStream(name);
    114         }
    115         return ris;
    116     }
    117 
    118     boolean getFileExists(File f) {
    119         return f.exists();
    120     }
    121 
    122     long getLastModified(File f) {
    123         return f.lastModified();
    124     }
    125 }
    126