Ignore:
Timestamp:
2018-06-08T22:43:20+02:00 (6 years ago)
Author:
Don-vip
Message:

add new XmlUtils class with more "safe factories" methods

Location:
trunk/src/org/openstreetmap/josm/data
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/imagery/GetCapabilitiesParseHelper.java

    r13828 r13901  
    99
    1010import javax.xml.namespace.QName;
    11 import javax.xml.stream.XMLInputFactory;
    1211import javax.xml.stream.XMLStreamException;
    1312import javax.xml.stream.XMLStreamReader;
    1413
    1514import org.openstreetmap.josm.tools.Utils;
     15import org.openstreetmap.josm.tools.XmlUtils;
    1616
    1717/**
     
    8282     */
    8383    public static XMLStreamReader getReader(InputStream in) throws XMLStreamException {
    84         XMLInputFactory factory = XMLInputFactory.newInstance();
    85         // do not try to load external entities, nor validate the XML
    86         factory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, Boolean.FALSE);
    87         factory.setProperty(XMLInputFactory.IS_VALIDATING, Boolean.FALSE);
    88         factory.setProperty(XMLInputFactory.SUPPORT_DTD, Boolean.FALSE);
    89         return factory.createXMLStreamReader(in);
     84        return XmlUtils.newSafeXMLInputFactory().createXMLStreamReader(in);
    9085    }
    9186
  • trunk/src/org/openstreetmap/josm/data/preferences/PreferencesReader.java

    r13715 r13901  
    2121
    2222import javax.xml.XMLConstants;
    23 import javax.xml.stream.XMLInputFactory;
    2423import javax.xml.stream.XMLStreamConstants;
    2524import javax.xml.stream.XMLStreamException;
     
    3736import org.openstreetmap.josm.spi.preferences.StringSetting;
    3837import org.openstreetmap.josm.tools.Logging;
    39 import org.openstreetmap.josm.tools.Utils;
     38import org.openstreetmap.josm.tools.XmlUtils;
    4039import org.xml.sax.SAXException;
    4140
     
    9796    public static void validateXML(Reader in) throws IOException, SAXException {
    9897        try (CachedFile cf = new CachedFile("resource://data/preferences.xsd"); InputStream xsdStream = cf.getInputStream()) {
    99             Schema schema = Utils.newXmlSchemaFactory().newSchema(new StreamSource(xsdStream));
     98            Schema schema = XmlUtils.newXmlSchemaFactory().newSchema(new StreamSource(xsdStream));
    10099            Validator validator = schema.newValidator();
    101100            validator.validate(new StreamSource(in));
     
    127126    public void parse() throws XMLStreamException, IOException {
    128127        if (reader != null) {
    129             this.parser = XMLInputFactory.newInstance().createXMLStreamReader(reader);
     128            this.parser = XmlUtils.newSafeXMLInputFactory().createXMLStreamReader(reader);
    130129            doParse();
    131130        } else {
    132131            try (BufferedReader in = Files.newBufferedReader(file.toPath(), StandardCharsets.UTF_8)) {
    133                 this.parser = XMLInputFactory.newInstance().createXMLStreamReader(in);
     132                this.parser = XmlUtils.newSafeXMLInputFactory().createXMLStreamReader(in);
    134133                doParse();
    135134            }
Note: See TracChangeset for help on using the changeset viewer.