/** * @see nu.validator.htmlparser.impl.TreeBuilder#createElement(String, * java.lang.String, org.xml.sax.Attributes, java.lang.Object) */ @Override protected Element createElement(String ns, String name, HtmlAttributes attributes, Element form) throws SAXException { try { Element rv = createElement(ns, name, attributes); rv.setUserData("nu.validator.form-pointer", form, null); return rv; } catch (DOMException e) { fatal(e); return null; } }
/** * Parses a document from a SAX <code>InputSource</code>. * @param is the source * @return the doc * @throws SAXException if stuff goes wrong * @throws IOException if IO goes wrong * @see javax.xml.parsers.DocumentBuilder#parse(org.xml.sax.InputSource) */ @Override public Document parse(InputSource is) throws SAXException, IOException { treeBuilder.setFragmentContext(null); tokenize(is); return treeBuilder.getDocument(); }
/** * Parses a document fragment from a SAX <code>InputSource</code>. * @param is the source * @param context the context element name * @return the doc * @throws SAXException if stuff goes wrong * @throws IOException if IO goes wrong */ public DocumentFragment parseFragment(InputSource is, String context) throws IOException, SAXException { treeBuilder.setFragmentContext(context.intern()); tokenize(is); return treeBuilder.getDocumentFragment(); }
/** * This class wraps different tree builders depending on configuration. This * method does the work of hiding this from the user of the class. */ private void lazyInit() { if (driver == null) { this.driver = new Driver(newTokenizer(treeBuilder, false)); this.driver.setErrorHandler(errorHandler); this.driver.setTransitionHandler(transitionHandler); this.treeBuilder.setErrorHandler(treeBuilderErrorHandler); this.driver.setCheckingNormalization(checkingNormalization); this.driver.setCommentPolicy(commentPolicy); this.driver.setContentNonXmlCharPolicy(contentNonXmlCharPolicy); this.driver.setContentSpacePolicy(contentSpacePolicy); this.driver.setHtml4ModeCompatibleWithXhtml1Schemata(html4ModeCompatibleWithXhtml1Schemata); this.driver.setMappingLangToXmlLang(mappingLangToXmlLang); this.driver.setXmlnsPolicy(xmlnsPolicy); this.driver.setHeuristics(heuristics); for (CharacterHandler characterHandler : characterHandlers) { this.driver.addCharacterHandler(characterHandler); } this.treeBuilder.setDoctypeExpectation(doctypeExpectation); this.treeBuilder.setDocumentModeHandler(documentModeHandler); this.treeBuilder.setScriptingEnabled(scriptingEnabled); this.treeBuilder.setReportingDoctype(reportingDoctype); this.treeBuilder.setNamePolicy(namePolicy); } }
/** * * @see nu.validator.htmlparser.impl.TreeBuilder#appendElement(java.lang.Object, * java.lang.Object) */ @Override protected void appendElement(Element child, Element newParent) throws SAXException { try { newParent.appendChild(child); } catch (DOMException e) { fatal(e); } }
/** * Sets whether comment nodes appear in the tree. * @param ignoreComments <code>true</code> to ignore comments * @see nu.validator.htmlparser.impl.TreeBuilder#setIgnoringComments(boolean) */ public void setIgnoringComments(boolean ignoreComments) { treeBuilder.setIgnoringComments(ignoreComments); }
/** * Sets the error handler. * @param errorHandler the handler * @see javax.xml.parsers.DocumentBuilder#setErrorHandler(org.xml.sax.ErrorHandler) */ @Override public void setErrorHandler(ErrorHandler errorHandler) { treeBuilder.setErrorHandler(errorHandler); if (driver != null) { driver.setErrorHandler(errorHandler); } }
/** * The policy for non-NCName element and attribute names. * @param namePolicy * @see nu.validator.htmlparser.impl.Tokenizer#setNamePolicy(nu.validator.htmlparser.common.XmlViolationPolicy) */ public void setNamePolicy(XmlViolationPolicy namePolicy) { this.namePolicy = namePolicy; if (driver != null) { driver.setNamePolicy(namePolicy); treeBuilder.setNamePolicy(namePolicy); } }
/** * Instantiates the document builder with a specific DOM * implementation and XML violation policy. * * @param implementation * the DOM implementation * @param xmlPolicy the policy */ public HtmlDocumentBuilder(DOMImplementation implementation, XmlViolationPolicy xmlPolicy) { this.implementation = implementation; this.treeBuilder = new DOMTreeBuilder(implementation); this.driver = null; setXmlPolicy(xmlPolicy); }
/** * This class wraps different tree builders depending on configuration. This * method does the work of hiding this from the user of the class. */ private void lazyInit() { if (driver == null) { this.driver = new Driver(newTokenizer(treeBuilder, false)); this.driver.setErrorHandler(errorHandler); this.driver.setTransitionHandler(transitionHandler); this.treeBuilder.setErrorHandler(treeBuilderErrorHandler); this.driver.setCheckingNormalization(checkingNormalization); this.driver.setCommentPolicy(commentPolicy); this.driver.setContentNonXmlCharPolicy(contentNonXmlCharPolicy); this.driver.setContentSpacePolicy(contentSpacePolicy); this.driver.setMappingLangToXmlLang(mappingLangToXmlLang); this.driver.setXmlnsPolicy(xmlnsPolicy); this.driver.setHeuristics(heuristics); for (CharacterHandler characterHandler : characterHandlers) { this.driver.addCharacterHandler(characterHandler); } this.treeBuilder.setDocumentModeHandler(documentModeHandler); this.treeBuilder.setScriptingEnabled(scriptingEnabled); this.treeBuilder.setReportingDoctype(reportingDoctype); this.treeBuilder.setNamePolicy(namePolicy); } }
/** * * @see nu.validator.htmlparser.impl.TreeBuilder#appendElement(java.lang.Object, * java.lang.Object) */ @Override protected void appendElement(Element child, Element newParent) throws SAXException { try { newParent.appendChild(child); } catch (DOMException e) { fatal(e); } }
/** * Sets whether comment nodes appear in the tree. * @param ignoreComments <code>true</code> to ignore comments * @see nu.validator.htmlparser.impl.TreeBuilder#setIgnoringComments(boolean) */ public void setIgnoringComments(boolean ignoreComments) { treeBuilder.setIgnoringComments(ignoreComments); }
/** * Sets the error handler. * @param errorHandler the handler * @see javax.xml.parsers.DocumentBuilder#setErrorHandler(org.xml.sax.ErrorHandler) */ @Override public void setErrorHandler(ErrorHandler errorHandler) { treeBuilder.setErrorHandler(errorHandler); if (driver != null) { driver.setErrorHandler(errorHandler); } }
/** * The policy for non-NCName element and attribute names. * @param namePolicy * @see nu.validator.htmlparser.impl.Tokenizer#setNamePolicy(nu.validator.htmlparser.common.XmlViolationPolicy) */ public void setNamePolicy(XmlViolationPolicy namePolicy) { this.namePolicy = namePolicy; if (driver != null) { driver.setNamePolicy(namePolicy); treeBuilder.setNamePolicy(namePolicy); } }
/** * Instantiates the document builder with a specific DOM * implementation and XML violation policy. * * @param implementation * the DOM implementation * @param xmlPolicy the policy */ public HtmlDocumentBuilder(DOMImplementation implementation, XmlViolationPolicy xmlPolicy) { this.implementation = implementation; this.treeBuilder = new DOMTreeBuilder(implementation); this.driver = null; setXmlPolicy(xmlPolicy); }
/** * This class wraps different tree builders depending on configuration. This * method does the work of hiding this from the user of the class. */ private void lazyInit() { if (driver == null) { this.driver = new Driver(newTokenizer(treeBuilder, false)); this.driver.setErrorHandler(errorHandler); this.driver.setTransitionHandler(transitionHandler); this.treeBuilder.setErrorHandler(treeBuilderErrorHandler); this.driver.setCheckingNormalization(checkingNormalization); this.driver.setCommentPolicy(commentPolicy); this.driver.setContentNonXmlCharPolicy(contentNonXmlCharPolicy); this.driver.setContentSpacePolicy(contentSpacePolicy); this.driver.setMappingLangToXmlLang(mappingLangToXmlLang); this.driver.setXmlnsPolicy(xmlnsPolicy); this.driver.setHeuristics(heuristics); for (CharacterHandler characterHandler : characterHandlers) { this.driver.addCharacterHandler(characterHandler); } this.treeBuilder.setDocumentModeHandler(documentModeHandler); this.treeBuilder.setScriptingEnabled(scriptingEnabled); this.treeBuilder.setReportingDoctype(reportingDoctype); this.treeBuilder.setNamePolicy(namePolicy); } }
/** * * @see nu.validator.htmlparser.impl.TreeBuilder#appendElement(java.lang.Object, * java.lang.Object) */ @Override protected void appendElement(Element child, Element newParent) throws SAXException { try { newParent.appendChild(child); } catch (DOMException e) { fatal(e); } }
/** * Parses a document fragment from a SAX <code>InputSource</code> with * an HTML element as the fragment context. * @param is the source * @param context the context element name (HTML namespace assumed) * @return the document fragment * @throws SAXException if stuff goes wrong * @throws IOException if IO goes wrong */ public DocumentFragment parseFragment(InputSource is, String context) throws IOException, SAXException { treeBuilder.setFragmentContext(context.intern()); tokenize(is); return treeBuilder.getDocumentFragment(); }
/** * @see nu.validator.htmlparser.impl.TreeBuilder#createElement(String, * java.lang.String, org.xml.sax.Attributes, java.lang.Object) */ @Override protected Element createElement(String ns, String name, HtmlAttributes attributes, Element form, Element intendedParent) throws SAXException { try { Element rv = createElement(ns, name, attributes, intendedParent); rv.setUserData("nu.validator.form-pointer", form, null); return rv; } catch (DOMException e) { fatal(e); return null; } }
/** * Parses a document from a SAX <code>InputSource</code>. * @param is the source * @return the doc * @throws SAXException if stuff goes wrong * @throws IOException if IO goes wrong * @see javax.xml.parsers.DocumentBuilder#parse(org.xml.sax.InputSource) */ @Override public Document parse(InputSource is) throws SAXException, IOException { treeBuilder.setFragmentContext(null); tokenize(is); return treeBuilder.getDocument(); }