equal
deleted
inserted
replaced
31 import java.util.Iterator; |
31 import java.util.Iterator; |
32 import java.util.Properties; |
32 import java.util.Properties; |
33 import java.util.ServiceConfigurationError; |
33 import java.util.ServiceConfigurationError; |
34 import java.util.ServiceLoader; |
34 import java.util.ServiceLoader; |
35 import java.util.function.Supplier; |
35 import java.util.function.Supplier; |
|
36 import jdk.xml.internal.SecuritySupport; |
36 |
37 |
37 /** |
38 /** |
38 * <p>Implements pluggable Parsers.</p> |
39 * <p>Implements pluggable Parsers.</p> |
39 * |
40 * |
40 * <p>This class is duplicated for each JAXP subpackage so keep it in |
41 * <p>This class is duplicated for each JAXP subpackage so keep it in |
59 * Flag indicating if properties from java.home/conf/jaxp.properties |
60 * Flag indicating if properties from java.home/conf/jaxp.properties |
60 * have been cached. |
61 * have been cached. |
61 */ |
62 */ |
62 static volatile boolean firstTime = true; |
63 static volatile boolean firstTime = true; |
63 |
64 |
64 /** |
|
65 * Security support class use to check access control before |
|
66 * getting certain system resources. |
|
67 */ |
|
68 private static final SecuritySupport ss = new SecuritySupport(); |
|
69 |
|
70 // Define system property "jaxp.debug" to get output |
65 // Define system property "jaxp.debug" to get output |
71 static { |
66 static { |
72 // Use try/catch block to support applets, which throws |
67 // Use try/catch block to support applets, which throws |
73 // SecurityException out of this code. |
68 // SecurityException out of this code. |
74 try { |
69 try { |
75 String val = ss.getSystemProperty("jaxp.debug"); |
70 String val = SecuritySupport.getSystemProperty("jaxp.debug"); |
76 // Allow simply setting the prop to turn on debug |
71 // Allow simply setting the prop to turn on debug |
77 debug = val != null && !"false".equals(val); |
72 debug = val != null && !"false".equals(val); |
78 } |
73 } |
79 catch (SecurityException se) { |
74 catch (SecurityException se) { |
80 debug = false; |
75 debug = false; |
104 try { |
99 try { |
105 if (cl == null) { |
100 if (cl == null) { |
106 if (useBSClsLoader) { |
101 if (useBSClsLoader) { |
107 return Class.forName(className, false, FactoryFinder.class.getClassLoader()); |
102 return Class.forName(className, false, FactoryFinder.class.getClassLoader()); |
108 } else { |
103 } else { |
109 cl = ss.getContextClassLoader(); |
104 cl = SecuritySupport.getContextClassLoader(); |
110 if (cl == null) { |
105 if (cl == null) { |
111 throw new ClassNotFoundException(); |
106 throw new ClassNotFoundException(); |
112 } |
107 } |
113 else { |
108 else { |
114 return Class.forName(className, false, cl); |
109 return Class.forName(className, false, cl); |
224 final String factoryId = type.getName(); |
219 final String factoryId = type.getName(); |
225 dPrint(()->"find factoryId =" + factoryId); |
220 dPrint(()->"find factoryId =" + factoryId); |
226 |
221 |
227 // Use the system property first |
222 // Use the system property first |
228 try { |
223 try { |
229 String systemProp = ss.getSystemProperty(factoryId); |
224 String systemProp = SecuritySupport.getSystemProperty(factoryId); |
230 if (systemProp != null) { |
225 if (systemProp != null) { |
231 dPrint(()->"found system property, value=" + systemProp); |
226 dPrint(()->"found system property, value=" + systemProp); |
232 return newInstance(type, systemProp, null, true); |
227 return newInstance(type, systemProp, null, true); |
233 } |
228 } |
234 } |
229 } |
239 // try to read from $java.home/conf/jaxp.properties |
234 // try to read from $java.home/conf/jaxp.properties |
240 try { |
235 try { |
241 if (firstTime) { |
236 if (firstTime) { |
242 synchronized (cacheProps) { |
237 synchronized (cacheProps) { |
243 if (firstTime) { |
238 if (firstTime) { |
244 String configFile = ss.getSystemProperty("java.home") + File.separator + |
239 String configFile = SecuritySupport.getSystemProperty("java.home") + File.separator + |
245 "conf" + File.separator + "jaxp.properties"; |
240 "conf" + File.separator + "jaxp.properties"; |
246 File f = new File(configFile); |
241 File f = new File(configFile); |
247 firstTime = false; |
242 firstTime = false; |
248 if (ss.doesFileExist(f)) { |
243 if (SecuritySupport.doesFileExist(f)) { |
249 dPrint(()->"Read properties file "+f); |
244 dPrint(()->"Read properties file "+f); |
250 cacheProps.load(ss.getFileInputStream(f)); |
245 cacheProps.load(SecuritySupport.getFileInputStream(f)); |
251 } |
246 } |
252 } |
247 } |
253 } |
248 } |
254 } |
249 } |
255 final String factoryClassName = cacheProps.getProperty(factoryId); |
250 final String factoryClassName = cacheProps.getProperty(factoryId); |