@Test public void testDocumentBuilderFactory() throws IOException, SAXException, ParserConfigurationException { DocumentBuilder builder = SafeXml.newdocumentBuilderFactory().newDocumentBuilder(); Document doc = builder.parse(xmlDocument); assertThat(doc.getElementsByTagName("foo").item(0).getTextContent(), not(containsString("bar"))); }
public static DocumentBuilderFactory newdocumentBuilderFactory() throws ParserConfigurationException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setFeature(APACHE_DISALLOW_DOCTYPE_DECL, false); factory.setFeature(APACHE_LOAD_EXTERNAL_DTD, false); factory.setFeature(XML_EXTERNAL_GENERAL_ENTITIES, false); factory.setFeature(XML_EXTERNAL_PARAMETER_ENTITIES, false); factory.setXIncludeAware(false); factory.setExpandEntityReferences(false); return factory; }
SafeXml { public static DocumentBuilderFactory newdocumentBuilderFactory() throws ParserConfigurationException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setFeature(APACHE_DISALLOW_DOCTYPE_DECL, false); factory.setFeature(APACHE_LOAD_EXTERNAL_DTD, false); factory.setFeature(XML_EXTERNAL_GENERAL_ENTITIES, false); factory.setFeature(XML_EXTERNAL_PARAMETER_ENTITIES, false); factory.setXIncludeAware(false); factory.setExpandEntityReferences(false); return factory; } }
SafeXml { public static DocumentBuilderFactory newdocumentBuilderFactory() throws ParserConfigurationException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setFeature(APACHE_DISALLOW_DOCTYPE_DECL, false); factory.setFeature(APACHE_LOAD_EXTERNAL_DTD, false); factory.setFeature(XML_EXTERNAL_GENERAL_ENTITIES, false); factory.setFeature(XML_EXTERNAL_PARAMETER_ENTITIES, false); factory.setXIncludeAware(false); factory.setExpandEntityReferences(false); return factory; } private  SafeXml(); }
SafeXml { public static DocumentBuilderFactory newdocumentBuilderFactory() throws ParserConfigurationException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setFeature(APACHE_DISALLOW_DOCTYPE_DECL, false); factory.setFeature(APACHE_LOAD_EXTERNAL_DTD, false); factory.setFeature(XML_EXTERNAL_GENERAL_ENTITIES, false); factory.setFeature(XML_EXTERNAL_PARAMETER_ENTITIES, false); factory.setXIncludeAware(false); factory.setExpandEntityReferences(false); return factory; } private  SafeXml(); static XMLInputFactory newXmlInputFactory(); static DocumentBuilderFactory newdocumentBuilderFactory(); static DocumentBuilderFactory newStrictDocumentBuilderFactory(); static TransformerFactory newTransformerFactory(); static SAXTransformerFactory newSaxTransformerFactory(); static SAXParserFactory newSaxParserFactory(); static SAXParserFactory newStrictSaxParserFactory(); }
SafeXml { public static DocumentBuilderFactory newdocumentBuilderFactory() throws ParserConfigurationException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setFeature(APACHE_DISALLOW_DOCTYPE_DECL, false); factory.setFeature(APACHE_LOAD_EXTERNAL_DTD, false); factory.setFeature(XML_EXTERNAL_GENERAL_ENTITIES, false); factory.setFeature(XML_EXTERNAL_PARAMETER_ENTITIES, false); factory.setXIncludeAware(false); factory.setExpandEntityReferences(false); return factory; } private  SafeXml(); static XMLInputFactory newXmlInputFactory(); static DocumentBuilderFactory newdocumentBuilderFactory(); static DocumentBuilderFactory newStrictDocumentBuilderFactory(); static TransformerFactory newTransformerFactory(); static SAXTransformerFactory newSaxTransformerFactory(); static SAXParserFactory newSaxParserFactory(); static SAXParserFactory newStrictSaxParserFactory();  }