Search in sources :

Example 1 with Node

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;
}
Also used : Element(com.smartandroid.sa.tag.nodes.Element) Node(com.smartandroid.sa.tag.nodes.Node) Document(com.smartandroid.sa.tag.nodes.Document)

Example 2 with Node

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();
        }
    }
}
Also used : Node(com.smartandroid.sa.tag.nodes.Node)

Example 3 with Node

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.
}
Also used : DataNode(com.smartandroid.sa.tag.nodes.DataNode) DataNode(com.smartandroid.sa.tag.nodes.DataNode) TextNode(com.smartandroid.sa.tag.nodes.TextNode) Node(com.smartandroid.sa.tag.nodes.Node) TextNode(com.smartandroid.sa.tag.nodes.TextNode)

Example 4 with Node

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);
}
Also used : Comment(com.smartandroid.sa.tag.nodes.Comment) TextNode(com.smartandroid.sa.tag.nodes.TextNode) Node(com.smartandroid.sa.tag.nodes.Node) XmlDeclaration(com.smartandroid.sa.tag.nodes.XmlDeclaration)

Example 5 with Node

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);
}
Also used : TextNode(com.smartandroid.sa.tag.nodes.TextNode) Node(com.smartandroid.sa.tag.nodes.Node) TextNode(com.smartandroid.sa.tag.nodes.TextNode)

Aggregations

Node (com.smartandroid.sa.tag.nodes.Node)5 TextNode (com.smartandroid.sa.tag.nodes.TextNode)3 Comment (com.smartandroid.sa.tag.nodes.Comment)1 DataNode (com.smartandroid.sa.tag.nodes.DataNode)1 Document (com.smartandroid.sa.tag.nodes.Document)1 Element (com.smartandroid.sa.tag.nodes.Element)1 XmlDeclaration (com.smartandroid.sa.tag.nodes.XmlDeclaration)1