@Test public void testIgnore() throws Exception { Parser p = new MockParser(OVER_DEFAULT); ContentHandler handler = new BasicContentHandlerFactory(BasicContentHandlerFactory.HANDLER_TYPE.IGNORE, -1).getNewContentHandler(); assertTrue(handler instanceof DefaultHandler); p.parse(null, handler, null, null); assertContains("org.xml.sax.helpers.DefaultHandler", handler.toString()); p = new MockParser(100); handler = new BasicContentHandlerFactory(BasicContentHandlerFactory.HANDLER_TYPE.IGNORE, 5).getNewContentHandler(); assertTrue(handler instanceof DefaultHandler); p.parse(null, handler, null, null); assertContains("org.xml.sax.helpers.DefaultHandler", handler.toString()); }
@Override public ContentHandler getNewContentHandler() { if (type == HANDLER_TYPE.BODY) { return new BodyContentHandler(writeLimit); } else if (type == HANDLER_TYPE.IGNORE) { return new DefaultHandler(); } if (writeLimit > -1) { switch(type) { case TEXT: return new WriteOutContentHandler(new ToTextContentHandler(), writeLimit); case HTML: return new WriteOutContentHandler(new ToHTMLContentHandler(), writeLimit); case XML: return new WriteOutContentHandler(new ToXMLContentHandler(), writeLimit); default: return new WriteOutContentHandler(new ToTextContentHandler(), writeLimit); } } else { switch (type) { case TEXT: return new ToTextContentHandler(); case HTML: return new ToHTMLContentHandler(); case XML: return new ToXMLContentHandler(); default: return new ToTextContentHandler(); } } }
BasicContentHandlerFactory implements ContentHandlerFactory { @Override public ContentHandler getNewContentHandler() { if (type == HANDLER_TYPE.BODY) { return new BodyContentHandler(writeLimit); } else if (type == HANDLER_TYPE.IGNORE) { return new DefaultHandler(); } if (writeLimit > -1) { switch(type) { case TEXT: return new WriteOutContentHandler(new ToTextContentHandler(), writeLimit); case HTML: return new WriteOutContentHandler(new ToHTMLContentHandler(), writeLimit); case XML: return new WriteOutContentHandler(new ToXMLContentHandler(), writeLimit); default: return new WriteOutContentHandler(new ToTextContentHandler(), writeLimit); } } else { switch (type) { case TEXT: return new ToTextContentHandler(); case HTML: return new ToHTMLContentHandler(); case XML: return new ToXMLContentHandler(); default: return new ToTextContentHandler(); } } } }
BasicContentHandlerFactory implements ContentHandlerFactory { @Override public ContentHandler getNewContentHandler() { if (type == HANDLER_TYPE.BODY) { return new BodyContentHandler(writeLimit); } else if (type == HANDLER_TYPE.IGNORE) { return new DefaultHandler(); } if (writeLimit > -1) { switch(type) { case TEXT: return new WriteOutContentHandler(new ToTextContentHandler(), writeLimit); case HTML: return new WriteOutContentHandler(new ToHTMLContentHandler(), writeLimit); case XML: return new WriteOutContentHandler(new ToXMLContentHandler(), writeLimit); default: return new WriteOutContentHandler(new ToTextContentHandler(), writeLimit); } } else { switch (type) { case TEXT: return new ToTextContentHandler(); case HTML: return new ToHTMLContentHandler(); case XML: return new ToXMLContentHandler(); default: return new ToTextContentHandler(); } } } BasicContentHandlerFactory(HANDLER_TYPE type, int writeLimit); }
BasicContentHandlerFactory implements ContentHandlerFactory { @Override public ContentHandler getNewContentHandler() { if (type == HANDLER_TYPE.BODY) { return new BodyContentHandler(writeLimit); } else if (type == HANDLER_TYPE.IGNORE) { return new DefaultHandler(); } if (writeLimit > -1) { switch(type) { case TEXT: return new WriteOutContentHandler(new ToTextContentHandler(), writeLimit); case HTML: return new WriteOutContentHandler(new ToHTMLContentHandler(), writeLimit); case XML: return new WriteOutContentHandler(new ToXMLContentHandler(), writeLimit); default: return new WriteOutContentHandler(new ToTextContentHandler(), writeLimit); } } else { switch (type) { case TEXT: return new ToTextContentHandler(); case HTML: return new ToHTMLContentHandler(); case XML: return new ToXMLContentHandler(); default: return new ToTextContentHandler(); } } } BasicContentHandlerFactory(HANDLER_TYPE type, int writeLimit); static HANDLER_TYPE parseHandlerType(String handlerTypeName, HANDLER_TYPE defaultType); @Override ContentHandler getNewContentHandler(); @Override ContentHandler getNewContentHandler(OutputStream os, String encoding); @Override ContentHandler getNewContentHandler(OutputStream os, Charset charset); HANDLER_TYPE getType(); }
BasicContentHandlerFactory implements ContentHandlerFactory { @Override public ContentHandler getNewContentHandler() { if (type == HANDLER_TYPE.BODY) { return new BodyContentHandler(writeLimit); } else if (type == HANDLER_TYPE.IGNORE) { return new DefaultHandler(); } if (writeLimit > -1) { switch(type) { case TEXT: return new WriteOutContentHandler(new ToTextContentHandler(), writeLimit); case HTML: return new WriteOutContentHandler(new ToHTMLContentHandler(), writeLimit); case XML: return new WriteOutContentHandler(new ToXMLContentHandler(), writeLimit); default: return new WriteOutContentHandler(new ToTextContentHandler(), writeLimit); } } else { switch (type) { case TEXT: return new ToTextContentHandler(); case HTML: return new ToHTMLContentHandler(); case XML: return new ToXMLContentHandler(); default: return new ToTextContentHandler(); } } } BasicContentHandlerFactory(HANDLER_TYPE type, int writeLimit); static HANDLER_TYPE parseHandlerType(String handlerTypeName, HANDLER_TYPE defaultType); @Override ContentHandler getNewContentHandler(); @Override ContentHandler getNewContentHandler(OutputStream os, String encoding); @Override ContentHandler getNewContentHandler(OutputStream os, Charset charset); HANDLER_TYPE getType();  }