- Timestamp:
- 2018-05-08T12:37:26+02:00 (7 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/preferences/PreferencesReader.java
r12881 r13715 27 27 import javax.xml.transform.stream.StreamSource; 28 28 import javax.xml.validation.Schema; 29 import javax.xml.validation.SchemaFactory;30 29 import javax.xml.validation.Validator; 31 30 32 31 import org.openstreetmap.josm.io.CachedFile; 33 32 import org.openstreetmap.josm.io.XmlStreamParsingException; 34 import org.openstreetmap.josm.spi.preferences.Setting;35 33 import org.openstreetmap.josm.spi.preferences.ListListSetting; 36 34 import org.openstreetmap.josm.spi.preferences.ListSetting; 37 35 import org.openstreetmap.josm.spi.preferences.MapListSetting; 36 import org.openstreetmap.josm.spi.preferences.Setting; 38 37 import org.openstreetmap.josm.spi.preferences.StringSetting; 39 38 import org.openstreetmap.josm.tools.Logging; 39 import org.openstreetmap.josm.tools.Utils; 40 40 import org.xml.sax.SAXException; 41 41 … … 97 97 public static void validateXML(Reader in) throws IOException, SAXException { 98 98 try (CachedFile cf = new CachedFile("resource://data/preferences.xsd"); InputStream xsdStream = cf.getInputStream()) { 99 Schema schema = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI).newSchema(new StreamSource(xsdStream));99 Schema schema = Utils.newXmlSchemaFactory().newSchema(new StreamSource(xsdStream)); 100 100 Validator validator = schema.newValidator(); 101 101 validator.validate(new StreamSource(in)); -
trunk/src/org/openstreetmap/josm/tools/Utils.java
r13649 r13715 48 48 import java.util.Locale; 49 49 import java.util.Optional; 50 import java.util.ServiceConfigurationError; 50 51 import java.util.concurrent.ExecutionException; 51 52 import java.util.concurrent.Executor; … … 71 72 import javax.xml.parsers.SAXParser; 72 73 import javax.xml.parsers.SAXParserFactory; 74 import javax.xml.validation.SchemaFactory; 73 75 74 76 import org.openstreetmap.josm.spi.preferences.Config; … … 1327 1329 } 1328 1330 return null; 1331 } 1332 1333 /** 1334 * Returns the W3C XML Schema factory implementation. Robust method dealing with ContextClassLoader problems. 1335 * @return the W3C XML Schema factory implementation 1336 * @since 13715 1337 */ 1338 public static SchemaFactory newXmlSchemaFactory() { 1339 try { 1340 return SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); 1341 } catch (ServiceConfigurationError e) { 1342 Logging.debug(e); 1343 // Can happen with icedtea-web. Use workaround from https://issues.apache.org/jira/browse/GERONIMO-6185 1344 Thread currentThread = Thread.currentThread(); 1345 ClassLoader old = currentThread.getContextClassLoader(); 1346 currentThread.setContextClassLoader(null); 1347 try { 1348 return SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); 1349 } finally { 1350 currentThread.setContextClassLoader(old); 1351 } 1352 } 1329 1353 } 1330 1354 -
trunk/src/org/openstreetmap/josm/tools/XmlObjectParser.java
r12624 r13715 18 18 import java.util.Stack; 19 19 20 import javax.xml.XMLConstants;21 20 import javax.xml.parsers.ParserConfigurationException; 22 21 import javax.xml.transform.stream.StreamSource; … … 286 285 */ 287 286 public Iterable<Object> startWithValidation(final Reader in, String namespace, String schemaSource) throws SAXException { 288 SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);287 SchemaFactory factory = Utils.newXmlSchemaFactory(); 289 288 try (CachedFile cf = new CachedFile(schemaSource); InputStream mis = cf.getInputStream()) { 290 289 Schema schema = factory.newSchema(new StreamSource(mis));
Note:
See TracChangeset
for help on using the changeset viewer.