29 // and by David Brownell |
29 // and by David Brownell |
30 // NO WARRANTY! This class is in the Public Domain. |
30 // NO WARRANTY! This class is in the Public Domain. |
31 // $Id: XMLReaderFactory.java,v 1.2.2.1 2005/07/31 22:48:08 jeffsuttor Exp $ |
31 // $Id: XMLReaderFactory.java,v 1.2.2.1 2005/07/31 22:48:08 jeffsuttor Exp $ |
32 |
32 |
33 package org.xml.sax.helpers; |
33 package org.xml.sax.helpers; |
|
34 |
34 import java.io.BufferedReader; |
35 import java.io.BufferedReader; |
35 import java.io.IOException; |
36 import java.io.IOException; |
36 import java.io.InputStream; |
37 import java.io.InputStream; |
37 import java.io.InputStreamReader; |
38 import java.io.InputStreamReader; |
38 import java.security.AccessController; |
39 import java.security.AccessController; |
39 import java.security.PrivilegedAction; |
40 import java.security.PrivilegedAction; |
40 import java.util.Iterator; |
41 import java.util.Iterator; |
41 import java.util.Objects; |
42 import java.util.Objects; |
42 import java.util.ServiceConfigurationError; |
43 import java.util.ServiceConfigurationError; |
43 import java.util.ServiceLoader; |
44 import java.util.ServiceLoader; |
|
45 import jdk.xml.internal.SecuritySupport; |
44 import org.xml.sax.SAXException; |
46 import org.xml.sax.SAXException; |
45 import org.xml.sax.XMLReader; |
47 import org.xml.sax.XMLReader; |
46 |
48 |
47 |
49 |
48 /** |
50 /** |
92 private XMLReaderFactory () |
94 private XMLReaderFactory () |
93 { |
95 { |
94 } |
96 } |
95 |
97 |
96 private static final String property = "org.xml.sax.driver"; |
98 private static final String property = "org.xml.sax.driver"; |
97 private static final SecuritySupport ss = new SecuritySupport(); |
|
98 |
99 |
99 /** |
100 /** |
100 * Obtains a new instance of a {@link org.xml.sax.XMLReader}. |
101 * Obtains a new instance of a {@link org.xml.sax.XMLReader}. |
101 * This method uses the following ordered lookup procedure to find and load |
102 * This method uses the following ordered lookup procedure to find and load |
102 * the {@link org.xml.sax.XMLReader} implementation class: |
103 * the {@link org.xml.sax.XMLReader} implementation class: |
136 */ |
137 */ |
137 public static XMLReader createXMLReader () |
138 public static XMLReader createXMLReader () |
138 throws SAXException |
139 throws SAXException |
139 { |
140 { |
140 String className = null; |
141 String className = null; |
141 ClassLoader cl = ss.getClassLoader(); |
142 ClassLoader cl = SecuritySupport.getClassLoader(); |
142 |
143 |
143 // 1. try the JVM-instance-wide system property |
144 // 1. try the JVM-instance-wide system property |
144 try { |
145 try { |
145 className = ss.getSystemProperty(property); |
146 className = SecuritySupport.getSystemProperty(property); |
146 } |
147 } |
147 catch (RuntimeException e) { /* continue searching */ } |
148 catch (RuntimeException e) { /* continue searching */ } |
148 |
149 |
149 // 2. try the ServiceLoader |
150 // 2. try the ServiceLoader |
150 if (className == null) { |
151 if (className == null) { |
185 * @see #createXMLReader() |
186 * @see #createXMLReader() |
186 */ |
187 */ |
187 public static XMLReader createXMLReader (String className) |
188 public static XMLReader createXMLReader (String className) |
188 throws SAXException |
189 throws SAXException |
189 { |
190 { |
190 return loadClass (ss.getClassLoader(), className); |
191 return loadClass (SecuritySupport.getClassLoader(), className); |
191 } |
192 } |
192 |
193 |
193 private static XMLReader loadClass (ClassLoader loader, String className) |
194 private static XMLReader loadClass (ClassLoader loader, String className) |
194 throws SAXException |
195 throws SAXException |
195 { |
196 { |
222 String service = "META-INF/services/" + property; |
223 String service = "META-INF/services/" + property; |
223 InputStream in; |
224 InputStream in; |
224 BufferedReader reader; |
225 BufferedReader reader; |
225 |
226 |
226 try { |
227 try { |
227 in = ss.getResourceAsStream(cl, service); |
228 in = SecuritySupport.getResourceAsStream(cl, service); |
228 |
229 |
229 // If no provider found then try the current ClassLoader |
230 // If no provider found then try the current ClassLoader |
230 if (in == null) { |
231 if (in == null) { |
231 in = ss.getResourceAsStream(null, service); |
232 in = SecuritySupport.getResourceAsStream(null, service); |
232 } |
233 } |
233 |
234 |
234 if (in != null) { |
235 if (in != null) { |
235 reader = new BufferedReader (new InputStreamReader (in, "UTF8")); |
236 reader = new BufferedReader (new InputStreamReader (in, "UTF8")); |
236 clsFromJar = reader.readLine (); |
237 clsFromJar = reader.readLine (); |