Changeset 10404 in josm for trunk/src/org
- Timestamp:
- 2016-06-16T19:10:53+02:00 (8 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/CustomConfigurator.java
r10378 r10404 35 35 import javax.swing.SwingUtilities; 36 36 import javax.xml.parsers.DocumentBuilder; 37 import javax.xml.parsers.DocumentBuilderFactory;38 37 import javax.xml.parsers.ParserConfigurationException; 39 38 import javax.xml.stream.XMLStreamException; … … 269 268 try { 270 269 String toXML = Main.pref.toXML(true); 271 InputStream is = new ByteArrayInputStream(toXML.getBytes(StandardCharsets.UTF_8)); 272 DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); 273 builderFactory.setValidating(false); 274 builderFactory.setNamespaceAware(false); 275 DocumentBuilder builder = builderFactory.newDocumentBuilder(); 276 document = builder.parse(is); 270 DocumentBuilder builder = Utils.newSafeDOMBuilder(); 271 document = builder.parse(new ByteArrayInputStream(toXML.getBytes(StandardCharsets.UTF_8))); 277 272 exportDocument = builder.newDocument(); 278 273 root = document.getDocumentElement(); … … 465 460 public void openAndReadXML(InputStream is) { 466 461 try { 467 DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); 468 builderFactory.setValidating(false); 469 builderFactory.setNamespaceAware(true); 470 DocumentBuilder builder = builderFactory.newDocumentBuilder(); 471 Document document = builder.parse(is); 462 Document document = Utils.parseSafeDOM(is); 472 463 synchronized (CustomConfigurator.class) { 473 464 processXML(document); -
trunk/src/org/openstreetmap/josm/gui/oauth/TestAccessTokenTask.java
r10173 r10404 10 10 11 11 import javax.swing.JOptionPane; 12 import javax.xml.parsers.DocumentBuilderFactory;13 12 import javax.xml.parsers.ParserConfigurationException; 14 13 … … 26 25 import org.openstreetmap.josm.tools.CheckParameterUtil; 27 26 import org.openstreetmap.josm.tools.HttpClient; 27 import org.openstreetmap.josm.tools.Utils; 28 28 import org.openstreetmap.josm.tools.XmlParsingException; 29 29 import org.w3c.dom.Document; … … 124 124 throw new OsmApiException(connection.getResponse().getResponseCode(), 125 125 connection.getResponse().getHeaderField("Error"), null); 126 Document d = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(connection.getResponse().getContent());126 Document d = Utils.parseSafeDOM(connection.getResponse().getContent()); 127 127 return OsmServerUserInfoReader.buildFromXML(d); 128 128 } catch (SAXException | ParserConfigurationException e) { -
trunk/src/org/openstreetmap/josm/io/OsmServerUserInfoReader.java
r10212 r10404 9 9 import java.util.List; 10 10 11 import javax.xml.parsers.DocumentBuilderFactory;12 11 import javax.xml.parsers.ParserConfigurationException; 13 12 import javax.xml.xpath.XPath; … … 20 19 import org.openstreetmap.josm.data.osm.UserInfo; 21 20 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 21 import org.openstreetmap.josm.tools.Utils; 22 22 import org.openstreetmap.josm.tools.XmlParsingException; 23 23 import org.openstreetmap.josm.tools.date.DateUtils; … … 175 175 monitor.indeterminateSubTask(tr("Reading user info ...")); 176 176 try (InputStream in = getInputStream("user/details", monitor.createSubTaskMonitor(1, true), reason)) { 177 return buildFromXML( 178 DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(in) 179 ); 177 return buildFromXML(Utils.parseSafeDOM(in)); 180 178 } 181 179 } catch (OsmTransferException e) { -
trunk/src/org/openstreetmap/josm/io/imagery/WMSImagery.java
r10216 r10404 18 18 import javax.imageio.ImageIO; 19 19 import javax.xml.parsers.DocumentBuilder; 20 import javax.xml.parsers.DocumentBuilderFactory;21 20 import javax.xml.parsers.ParserConfigurationException; 22 21 … … 152 151 153 152 try { 154 DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); 155 builderFactory.setValidating(false); 156 builderFactory.setNamespaceAware(true); 157 DocumentBuilder builder = builderFactory.newDocumentBuilder(); 153 DocumentBuilder builder = Utils.newSafeDOMBuilder(); 158 154 builder.setEntityResolver(new EntityResolver() { 159 155 @Override -
trunk/src/org/openstreetmap/josm/io/session/SessionReader.java
r10208 r10404 29 29 import javax.swing.JOptionPane; 30 30 import javax.swing.SwingUtilities; 31 import javax.xml.parsers.DocumentBuilder;32 import javax.xml.parsers.DocumentBuilderFactory;33 31 import javax.xml.parsers.ParserConfigurationException; 34 32 … … 633 631 634 632 try { 635 DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); 636 builderFactory.setValidating(false); 637 builderFactory.setNamespaceAware(true); 638 DocumentBuilder builder = builderFactory.newDocumentBuilder(); 639 Document document = builder.parse(josIS); 640 parseJos(document, progressMonitor); 633 parseJos(Utils.parseSafeDOM(josIS), progressMonitor); 641 634 } catch (SAXException e) { 642 635 throw new IllegalDataException(e); -
trunk/src/org/openstreetmap/josm/io/session/SessionWriter.java
r10212 r10404 19 19 20 20 import javax.xml.parsers.DocumentBuilder; 21 import javax.xml.parsers.DocumentBuilderFactory;22 21 import javax.xml.parsers.ParserConfigurationException; 23 22 import javax.xml.transform.OutputKeys; … … 201 200 */ 202 201 public Document createJosDocument() throws IOException { 203 DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();204 builderFactory.setValidating(false);205 builderFactory.setNamespaceAware(true);206 202 DocumentBuilder builder = null; 207 203 try { 208 builder = builderFactory.newDocumentBuilder();204 builder = Utils.newSafeDOMBuilder(); 209 205 } catch (ParserConfigurationException e) { 210 throw new RuntimeException(e);206 throw new IOException(e); 211 207 } 212 208 Document doc = builder.newDocument(); -
trunk/src/org/openstreetmap/josm/tools/Utils.java
r10315 r10404 64 64 65 65 import javax.xml.XMLConstants; 66 import javax.xml.parsers.DocumentBuilder; 67 import javax.xml.parsers.DocumentBuilderFactory; 66 68 import javax.xml.parsers.ParserConfigurationException; 67 69 import javax.xml.parsers.SAXParser; … … 70 72 import org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream; 71 73 import org.openstreetmap.josm.Main; 74 import org.w3c.dom.Document; 72 75 import org.xml.sax.InputSource; 73 76 import org.xml.sax.SAXException; … … 1408 1411 } 1409 1412 return null; 1413 } 1414 1415 /** 1416 * Returns a new secure DOM builder, supporting XML namespaces. 1417 * @return a new secure DOM builder, supporting XML namespaces 1418 * @throws ParserConfigurationException if a parser cannot be created which satisfies the requested configuration. 1419 * @throws ParserConfigurationException if a parser cannot be created which satisfies the requested configuration. 1420 * @since 10404 1421 */ 1422 public static DocumentBuilder newSafeDOMBuilder() throws ParserConfigurationException { 1423 DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); 1424 builderFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); 1425 builderFactory.setNamespaceAware(true); 1426 builderFactory.setValidating(false); 1427 return builderFactory.newDocumentBuilder(); 1428 } 1429 1430 /** 1431 * Parse the content given {@link InputStream} as XML. 1432 * This method uses a secure DOM builder, supporting XML namespaces. 1433 * 1434 * @param is The InputStream containing the content to be parsed. 1435 * @return the result DOM document 1436 * @throws ParserConfigurationException if a parser cannot be created which satisfies the requested configuration. 1437 * @throws IOException if any IO errors occur. 1438 * @throws SAXException for SAX errors. 1439 * @since 10404 1440 */ 1441 public static Document parseSafeDOM(InputStream is) throws ParserConfigurationException, IOException, SAXException { 1442 long start = System.currentTimeMillis(); 1443 if (Main.isDebugEnabled()) { 1444 Main.debug("Starting DOM parsing of " + is); 1445 } 1446 Document result = newSafeDOMBuilder().parse(is); 1447 if (Main.isDebugEnabled()) { 1448 Main.debug("DOM parsing done in " + getDurationString(System.currentTimeMillis() - start)); 1449 } 1450 return result; 1410 1451 } 1411 1452 -
trunk/src/org/openstreetmap/josm/tools/bugreport/BugReportSender.java
r10067 r10404 18 18 import javax.swing.JPanel; 19 19 import javax.swing.SwingUtilities; 20 import javax.xml.parsers.DocumentBuilder;21 import javax.xml.parsers.DocumentBuilderFactory;22 20 import javax.xml.parsers.ParserConfigurationException; 23 21 import javax.xml.xpath.XPath; … … 100 98 101 99 try (InputStream in = connection.getContent()) { 102 DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); 103 Document document = builder.parse(in); 104 return retrieveDebugToken(document); 100 return retrieveDebugToken(Utils.parseSafeDOM(in)); 105 101 } 106 102 } catch (IOException | SAXException | ParserConfigurationException | XPathExpressionException t) {
Note:
See TracChangeset
for help on using the changeset viewer.