Code example for DefaultHandler

0
     */ 
    public void testExternalEntities() { 
        try { 
            String source =
                "<!DOCTYPE foo SYSTEM \"http://invalid.address/\"><foo/>"; 
            new ParsingContentHandler(new DefaultHandler()).parse(
                    new ByteArrayInputStream(source.getBytes("UTF-8")));
        } catch (Exception e) {
            fail("JCR-1355: XML import should not access external entities");
        } 
    } 
 
    private void assertContains(String haystack, String needle) {
        if (haystack.indexOf(needle) == -1) {
            fail("'" + haystack + "' does not contain '" + needle+ "'");
        } 
    } 
}