public Inclusion(InclusionIntent intent) { super(intent.getScroll() != null ? intent.getScroll() : new Scroll()); this.intent = intent; boolean xhtml = intent.getFile().endsWith(".xhtml"); this.useMagic = !xhtml; try { parser = xhtml ? Wandler.getXHTMLParser() : Wandler.getHTMLParser(); parser.setContentHandler(this); parser.setEntityResolver(new VoidResolver()); } catch (SAXException ex) { throw new RuntimeException("Inclusion failed", ex); } }
public void startTransformedElement(String name, Attributes attributes) { if (ignoreBounds()) return; try { Reader in = getResources().open(intent.getFile()); parser.parse(new InputSource(useMagic ? new MagicReader(in) : in)); } catch (IOException ex) { String message = "Error reading " + intent.getFile(); Logger.getLogger(Inclusion.class.getName()).log(Level.SEVERE, message, ex); } catch (SAXException ex) { int lineNumber = locator != null ? locator.getLineNumber() : -1; String message = "Error parsing " + intent.getFile() + (lineNumber != -1 ? " at line " + lineNumber : ""); Logger.getLogger(Inclusion.class.getName()).log(Level.SEVERE, message, ex); } finally { if (Wandler.dlogLevel >= Wandler.DLOG_LEVEL_1 && intent.getScroll() != null) { intent.getScroll().checkUsed(true); } } }
@Override public String toString() { return "Inclusion(useMagic: " + useMagic + ", file: " + intent.getFile() + ", intent: " + intent + ")"; }