src/java.xml/share/classes/javax/xml/xpath/XPathFactoryFinder.java
changeset 47312 d4f959806fe9
parent 47216 71c04702a3d5
child 47359 e1a6c0168741
equal deleted inserted replaced
47311:ff631a3cadbc 47312:d4f959806fe9
    34 import java.security.PrivilegedAction;
    34 import java.security.PrivilegedAction;
    35 import java.util.Properties;
    35 import java.util.Properties;
    36 import java.util.ServiceConfigurationError;
    36 import java.util.ServiceConfigurationError;
    37 import java.util.ServiceLoader;
    37 import java.util.ServiceLoader;
    38 import java.util.function.Supplier;
    38 import java.util.function.Supplier;
       
    39 import jdk.xml.internal.SecuritySupport;
    39 
    40 
    40 /**
    41 /**
    41  * Implementation of {@link XPathFactory#newInstance(String)}.
    42  * Implementation of {@link XPathFactory#newInstance(String)}.
    42  *
    43  *
    43  * @author <a href="Kohsuke.Kawaguchi@Sun.com">Kohsuke Kawaguchi</a>
    44  * @author <a href="Kohsuke.Kawaguchi@Sun.com">Kohsuke Kawaguchi</a>
    44  * @since 1.5
    45  * @since 1.5
    45  */
    46  */
    46 class XPathFactoryFinder  {
    47 class XPathFactoryFinder  {
    47     private static final String DEFAULT_PACKAGE = "com.sun.org.apache.xpath.internal";
    48     private static final String DEFAULT_PACKAGE = "com.sun.org.apache.xpath.internal";
    48 
    49 
    49     private static final SecuritySupport ss = new SecuritySupport() ;
       
    50     /** debug support code. */
    50     /** debug support code. */
    51     private static boolean debug = false;
    51     private static boolean debug = false;
    52     static {
    52     static {
    53         // Use try/catch block to support applets
    53         // Use try/catch block to support applets
    54         try {
    54         try {
    55             debug = ss.getSystemProperty("jaxp.debug") != null;
    55             debug = SecuritySupport.getSystemProperty("jaxp.debug") != null;
    56         } catch (Exception unused) {
    56         } catch (Exception unused) {
    57             debug = false;
    57             debug = false;
    58         }
    58         }
    59     }
    59     }
    60 
    60 
   101         }
   101         }
   102     }
   102     }
   103 
   103 
   104     private void debugDisplayClassLoader() {
   104     private void debugDisplayClassLoader() {
   105         try {
   105         try {
   106             if( classLoader == ss.getContextClassLoader() ) {
   106             if( classLoader == SecuritySupport.getContextClassLoader() ) {
   107                 debugPrintln(() -> "using thread context class loader ("+classLoader+") for search");
   107                 debugPrintln(() -> "using thread context class loader ("+classLoader+") for search");
   108                 return;
   108                 return;
   109             }
   109             }
   110         } catch( Throwable unused ) {
   110         } catch( Throwable unused ) {
   111              // getContextClassLoader() undefined in JDK1.1
   111              // getContextClassLoader() undefined in JDK1.1
   157         String propertyName = SERVICE_CLASS.getName() + ":" + uri;
   157         String propertyName = SERVICE_CLASS.getName() + ":" + uri;
   158 
   158 
   159         // system property look up
   159         // system property look up
   160         try {
   160         try {
   161             debugPrintln(()->"Looking up system property '"+propertyName+"'" );
   161             debugPrintln(()->"Looking up system property '"+propertyName+"'" );
   162             String r = ss.getSystemProperty(propertyName);
   162             String r = SecuritySupport.getSystemProperty(propertyName);
   163             if(r!=null) {
   163             if(r!=null) {
   164                 debugPrintln(()->"The value is '"+r+"'");
   164                 debugPrintln(()->"The value is '"+r+"'");
   165                 xpathFactory = createInstance(r, true);
   165                 xpathFactory = createInstance(r, true);
   166                 if (xpathFactory != null) {
   166                 if (xpathFactory != null) {
   167                     return xpathFactory;
   167                     return xpathFactory;
   173                 debugPrintln(()->"failed to look up system property '"+propertyName+"'" );
   173                 debugPrintln(()->"failed to look up system property '"+propertyName+"'" );
   174                 t.printStackTrace();
   174                 t.printStackTrace();
   175             }
   175             }
   176         }
   176         }
   177 
   177 
   178         String javah = ss.getSystemProperty( "java.home" );
   178         String javah = SecuritySupport.getSystemProperty( "java.home" );
   179         String configFile = javah + File.separator +
   179         String configFile = javah + File.separator +
   180         "conf" + File.separator + "jaxp.properties";
   180         "conf" + File.separator + "jaxp.properties";
   181 
   181 
   182         // try to read from $java.home/conf/jaxp.properties
   182         // try to read from $java.home/conf/jaxp.properties
   183         try {
   183         try {
   184             if(firstTime){
   184             if(firstTime){
   185                 synchronized(cacheProps){
   185                 synchronized(cacheProps){
   186                     if(firstTime){
   186                     if(firstTime){
   187                         File f=new File( configFile );
   187                         File f=new File( configFile );
   188                         firstTime = false;
   188                         firstTime = false;
   189                         if(ss.doesFileExist(f)){
   189                         if(SecuritySupport.doesFileExist(f)){
   190                             debugPrintln(()->"Read properties file " + f);
   190                             debugPrintln(()->"Read properties file " + f);
   191                             cacheProps.load(ss.getFileInputStream(f));
   191                             cacheProps.load(SecuritySupport.getFileInputStream(f));
   192                         }
   192                         }
   193                     }
   193                     }
   194                 }
   194                 }
   195             }
   195             }
   196             final String factoryClassName = cacheProps.getProperty(propertyName);
   196             final String factoryClassName = cacheProps.getProperty(propertyName);
   405 
   405 
   406     private static final Class<XPathFactory> SERVICE_CLASS = XPathFactory.class;
   406     private static final Class<XPathFactory> SERVICE_CLASS = XPathFactory.class;
   407 
   407 
   408     // Used for debugging purposes
   408     // Used for debugging purposes
   409     private static String which( Class<?> clazz ) {
   409     private static String which( Class<?> clazz ) {
   410         return ss.getClassSource(clazz);
   410         return SecuritySupport.getClassSource(clazz);
   411     }
   411     }
   412 
   412 
   413 }
   413 }