use of nu.xom.XMLException in project htmlparser by validator.
the class XOMTreeBuilder method appendCharacters.
@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);
}
}
use of nu.xom.XMLException in project htmlparser by validator.
the class XOMTreeBuilder method insertFosterParentedCharacters.
@Override
protected void insertFosterParentedCharacters(String text, Element table, Element stackParent) throws SAXException {
try {
Node parent = table.getParent();
if (parent != null) {
// always an element if not null
Element parentAsElt = (Element) parent;
int tableIndex = indexOfTable(table, parentAsElt);
Node prevSibling;
if (tableIndex != 0 && ((prevSibling = parentAsElt.getChild(tableIndex - 1)) instanceof Text)) {
Text prevAsText = (Text) prevSibling;
prevAsText.setValue(prevAsText.getValue() + text);
return;
}
parentAsElt.insertChild(nodeFactory.makeText(text), tableIndex);
cachedTableIndex++;
return;
}
int childCount = stackParent.getChildCount();
Node lastChild;
if (childCount != 0 && ((lastChild = stackParent.getChild(childCount - 1)) instanceof Text)) {
Text lastAsText = (Text) lastChild;
lastAsText.setValue(lastAsText.getValue() + text);
return;
}
stackParent.appendChild(nodeFactory.makeText(text));
} catch (XMLException e) {
fatal(e);
}
}
use of nu.xom.XMLException in project htmlparser by validator.
the class XOMTreeBuilder method insertFosterParentedChild.
@Override
protected void insertFosterParentedChild(Element child, Element table, Element stackParent) throws SAXException {
try {
Node parent = table.getParent();
if (parent != null) {
// always an element if not null
((ParentNode) parent).insertChild(child, indexOfTable(table, stackParent));
cachedTableIndex++;
} else {
stackParent.appendChild(child);
}
} catch (XMLException e) {
fatal(e);
}
}
use of nu.xom.XMLException in project htmlparser by validator.
the class XOMTreeBuilder method createHtmlElementSetAsRoot.
@Override
protected Element createHtmlElementSetAsRoot(HtmlAttributes attributes) throws SAXException {
try {
Element rv = nodeFactory.makeElement("html", "http://www.w3.org/1999/xhtml");
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));
}
document.setRootElement(rv);
return rv;
} catch (XMLException e) {
fatal(e);
throw new RuntimeException("Unreachable");
}
}
use of nu.xom.XMLException in project htmlparser by validator.
the class XOMTreeBuilder method createAndInsertFosterParentedElement.
@Override
protected Element createAndInsertFosterParentedElement(String ns, String name, HtmlAttributes attributes, Element table, Element stackParent) throws SAXException {
try {
Node parent = table.getParent();
Element child = createElement(ns, name, attributes, parent != null ? (Element) parent : stackParent);
if (parent != null) {
// always an element if not null
((ParentNode) parent).insertChild(child, indexOfTable(table, stackParent));
cachedTableIndex++;
} else {
stackParent.appendChild(child);
}
return child;
} catch (XMLException e) {
fatal(e);
throw new RuntimeException("Unreachable");
}
}
Aggregations