Changeset 10404 in josm for trunk/src/org/openstreetmap/josm/tools
- Timestamp:
- 2016-06-16T19:10:53+02:00 (7 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/tools
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
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.