use of com.smartandroid.sa.tag.nodes.Node in project SmartAndroidSource by jaychou2012.
the class Parser method parseBodyFragment.
/**
* Parse a fragment of HTML into the {@code body} of a Document.
*
* @param bodyHtml
* fragment of HTML
* @param baseUri
* base URI of document (i.e. original fetch location), for
* resolving relative URLs.
*
* @return Document, with empty head, and HTML parsed into body
*/
public static Document parseBodyFragment(String bodyHtml, String baseUri) {
Document doc = Document.createShell(baseUri);
Element body = doc.body();
List<Node> nodeList = parseFragment(bodyHtml, body, baseUri);
// the node
Node[] nodes = nodeList.toArray(new Node[nodeList.size()]);
// re-parented
for (Node node : nodes) {
body.appendChild(node);
}
return doc;
}
use of com.smartandroid.sa.tag.nodes.Node in project SmartAndroidSource by jaychou2012.
the class NodeTraversor method traverse.
/**
* Start a depth-first traverse of the root and all of its descendants.
*
* @param root
* the root node point to traverse.
*/
public void traverse(Node root) {
Node node = root;
int depth = 0;
while (node != null) {
visitor.head(node, depth);
if (node.childNodeSize() > 0) {
node = node.childNode(0);
depth++;
} else {
while (node.nextSibling() == null && depth > 0) {
visitor.tail(node, depth);
node = node.parentNode();
depth--;
}
visitor.tail(node, depth);
if (node == root)
break;
node = node.nextSibling();
}
}
}
use of com.smartandroid.sa.tag.nodes.Node in project SmartAndroidSource by jaychou2012.
the class HtmlTreeBuilder method insert.
void insert(Token.Character characterToken) {
Node node;
// characters in script and style go in as datanodes, not text nodes
String tagName = currentElement().tagName();
if (tagName.equals("script") || tagName.equals("style"))
node = new DataNode(characterToken.getData(), baseUri);
else
node = new TextNode(characterToken.getData(), baseUri);
// doesn't use insertNode, because
currentElement().appendChild(node);
// we don't foster these; and will
// always have a stack.
}
use of com.smartandroid.sa.tag.nodes.Node in project SmartAndroidSource by jaychou2012.
the class XmlTreeBuilder method insert.
void insert(Token.Comment commentToken) {
Comment comment = new Comment(commentToken.getData(), baseUri);
Node insert = comment;
if (commentToken.bogus) {
// xml declarations are emitted as bogus
// comments (which is right for html, but
// not xml)
String data = comment.getData();
if (data.length() > 1 && (data.startsWith("!") || data.startsWith("?"))) {
String declaration = data.substring(1);
insert = new XmlDeclaration(declaration, comment.baseUri(), data.startsWith("!"));
}
}
insertNode(insert);
}
use of com.smartandroid.sa.tag.nodes.Node in project SmartAndroidSource by jaychou2012.
the class XmlTreeBuilder method insert.
void insert(Token.Character characterToken) {
Node node = new TextNode(characterToken.getData(), baseUri);
insertNode(node);
}
Aggregations