/** * Constructor with default node factory and given XML violation policy. * @param xmlPolicy the policy */ public HtmlBuilder(XmlViolationPolicy xmlPolicy) { this(new SimpleNodeFactory(), xmlPolicy); }
/** * @see nu.validator.htmlparser.impl.TreeBuilder#start() */ @Override protected void start(boolean fragment) throws SAXException { document = nodeFactory.makeDocument(); cachedTableIndex = -1; cachedTable = null; }
@Override protected Element createElement(String ns, String name, HtmlAttributes attributes) throws SAXException { try { Element rv = nodeFactory.makeElement(name, ns); for (int i = 0; i < attributes.getLength(); i++) { rv.addAttribute(nodeFactory.makeAttribute( attributes.getLocalName(i), attributes.getURI(i), attributes.getValue(i), attributes.getType(i) == "ID" ? Attribute.Type.ID : Attribute.Type.CDATA)); } return rv; } catch (XMLException e) { fatal(e); throw new RuntimeException("Unreachable"); } }
@Override protected void appendComment(Element parent, String comment) throws SAXException { try { parent.appendChild(nodeFactory.makeComment(comment)); } catch (XMLException e) { fatal(e); } }
@Override protected void appendCharacters(Element parent, String text) throws SAXException { try { int childCount = parent.getChildCount(); Node lastChild; if (childCount != 0 && ((lastChild = parent.getChild(childCount - 1)) instanceof Text)) { Text lastAsText = (Text) lastChild; lastAsText.setValue(lastAsText.getValue() + text); return; } parent.appendChild(nodeFactory.makeText(text)); } catch (XMLException e) { fatal(e); } }
@Override protected void addAttributesToElement(Element element, HtmlAttributes attributes) throws SAXException { try { for (int i = 0; i < attributes.getLength(); i++) { String localName = attributes.getLocalName(i); String uri = attributes.getURI(i); if (element.getAttribute(localName, uri) == null) { element.addAttribute(nodeFactory.makeAttribute(localName, uri, attributes.getValue(i), attributes.getType(i) == "ID" ? Attribute.Type.ID : Attribute.Type.CDATA)); } } } catch (XMLException e) { fatal(e); } }
@Override protected Element createElement(String ns, String name, HtmlAttributes attributes, Element intendedParent) throws SAXException { try { Element rv = nodeFactory.makeElement(name, ns); for (int i = 0; i < attributes.getLength(); i++) { rv.addAttribute(nodeFactory.makeAttribute( attributes.getLocalNameNoBoundsCheck(i), attributes.getURINoBoundsCheck(i), attributes.getValueNoBoundsCheck(i), attributes.getTypeNoBoundsCheck(i) == "ID" ? Attribute.Type.ID : Attribute.Type.CDATA)); } return rv; } catch (XMLException e) { fatal(e); throw new RuntimeException("Unreachable"); } }
@Override protected void appendComment(Element parent, String comment) throws SAXException { try { parent.appendChild(nodeFactory.makeComment(comment)); } catch (XMLException e) { fatal(e); } }
@Override protected void appendCharacters(Element parent, String text) throws SAXException { try { int childCount = parent.getChildCount(); Node lastChild; if (childCount != 0 && ((lastChild = parent.getChild(childCount - 1)) instanceof Text)) { Text lastAsText = (Text) lastChild; lastAsText.setValue(lastAsText.getValue() + text); return; } parent.appendChild(nodeFactory.makeText(text)); } catch (XMLException e) { fatal(e); } }
@Override protected void addAttributesToElement(Element element, HtmlAttributes attributes) throws SAXException { try { for (int i = 0; i < attributes.getLength(); i++) { String localName = attributes.getLocalNameNoBoundsCheck(i); String uri = attributes.getURINoBoundsCheck(i); if (element.getAttribute(localName, uri) == null) { element.addAttribute(nodeFactory.makeAttribute( localName, uri, attributes.getValueNoBoundsCheck(i), attributes.getTypeNoBoundsCheck(i) == "ID" ? Attribute.Type.ID : Attribute.Type.CDATA)); } } } catch (XMLException e) { fatal(e); } }
@Override protected Element createElement(String ns, String name, HtmlAttributes attributes, Element intendedParent) throws SAXException { try { Element rv = nodeFactory.makeElement(name, ns); for (int i = 0; i < attributes.getLength(); i++) { rv.addAttribute(nodeFactory.makeAttribute( attributes.getLocalNameNoBoundsCheck(i), attributes.getURINoBoundsCheck(i), attributes.getValueNoBoundsCheck(i), attributes.getTypeNoBoundsCheck(i) == "ID" ? Attribute.Type.ID : Attribute.Type.CDATA)); } return rv; } catch (XMLException e) { fatal(e); throw new RuntimeException("Unreachable"); } }
@Override protected void appendComment(Element parent, String comment) throws SAXException { try { parent.appendChild(nodeFactory.makeComment(comment)); } catch (XMLException e) { fatal(e); } }
/** * Constructor with default node factory and given XML violation policy. * @param xmlPolicy the policy */ public HtmlBuilder(XmlViolationPolicy xmlPolicy) { this(new SimpleNodeFactory(), xmlPolicy); }
@Override protected void appendCharacters(Element parent, String text) throws SAXException { try { int childCount = parent.getChildCount(); Node lastChild; if (childCount != 0 && ((lastChild = parent.getChild(childCount - 1)) instanceof Text)) { Text lastAsText = (Text) lastChild; lastAsText.setValue(lastAsText.getValue() + text); return; } parent.appendChild(nodeFactory.makeText(text)); } catch (XMLException e) { fatal(e); } }
/** * @see nu.validator.htmlparser.impl.TreeBuilder#start() */ @Override protected void start(boolean fragment) throws SAXException { document = nodeFactory.makeDocument(); cachedTableIndex = -1; cachedTable = null; }
@Override protected void addAttributesToElement(Element element, HtmlAttributes attributes) throws SAXException { try { for (int i = 0; i < attributes.getLength(); i++) { String localName = attributes.getLocalNameNoBoundsCheck(i); String uri = attributes.getURINoBoundsCheck(i); if (element.getAttribute(localName, uri) == null) { element.addAttribute(nodeFactory.makeAttribute( localName, uri, attributes.getValueNoBoundsCheck(i), attributes.getTypeNoBoundsCheck(i) == "ID" ? Attribute.Type.ID : Attribute.Type.CDATA)); } } } catch (XMLException e) { fatal(e); } }
/** * @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 = nodeFactory.makeElement(name, ns, form); for (int i = 0; i < attributes.getLength(); i++) { rv.addAttribute(nodeFactory.makeAttribute( attributes.getLocalName(i), attributes.getURI(i), attributes.getValue(i), attributes.getType(i) == "ID" ? Attribute.Type.ID : Attribute.Type.CDATA)); } return rv; } catch (XMLException e) { fatal(e); throw new RuntimeException("Unreachable"); } }
@Override protected void appendCommentToDocument(String comment) throws SAXException { try { Element root = document.getRootElement(); if ("http://www.xom.nu/fakeRoot".equals(root.getNamespaceURI())) { document.insertChild(nodeFactory.makeComment(comment), document.indexOf(root)); } else { document.appendChild(nodeFactory.makeComment(comment)); } } catch (XMLException e) { fatal(e); } }
/** * Constructor with default node factory and given XML violation policy. * @param xmlPolicy the policy */ public HtmlBuilder(XmlViolationPolicy xmlPolicy) { this(new SimpleNodeFactory(), xmlPolicy); }