Search in sources :

Example 6 with Elements

use of com.smartandroid.sa.tag.select.Elements in project SmartAndroidSource by jaychou2012.

the class HtmlTreeBuilder method parseFragment.

List<Node> parseFragment(String inputFragment, Element context, String baseUri, ParseErrorList errors) {
    // context may be null
    state = HtmlTreeBuilderState.Initial;
    initialiseParse(inputFragment, baseUri, errors);
    contextElement = context;
    fragmentParsing = true;
    Element root = null;
    if (context != null) {
        if (// quirks setup:
        context.ownerDocument() != null)
            doc.quirksMode(context.ownerDocument().quirksMode());
        // initialise the tokeniser state:
        String contextTag = context.tagName();
        if (StringUtil.in(contextTag, "title", "textarea"))
            tokeniser.transition(TokeniserState.Rcdata);
        else if (StringUtil.in(contextTag, "iframe", "noembed", "noframes", "style", "xmp"))
            tokeniser.transition(TokeniserState.Rawtext);
        else if (contextTag.equals("script"))
            tokeniser.transition(TokeniserState.ScriptData);
        else if (contextTag.equals(("noscript")))
            // if scripting
            tokeniser.transition(TokeniserState.Data);
        else // enabled, rawtext
        if (contextTag.equals("plaintext"))
            tokeniser.transition(TokeniserState.Data);
        else
            // default
            tokeniser.transition(TokeniserState.Data);
        root = new Element(Tag.valueOf("html"), baseUri);
        doc.appendChild(root);
        stack.push(root);
        resetInsertionMode();
        // setup form element to nearest form on context (up ancestor
        // chain). ensures form controls are associated
        // with form correctly
        Elements contextChain = context.parents();
        contextChain.add(0, context);
        for (Element parent : contextChain) {
            if (parent instanceof FormElement) {
                formElement = (FormElement) parent;
                break;
            }
        }
    }
    runParser();
    if (context != null)
        return root.childNodes();
    else
        return doc.childNodes();
}
Also used : FormElement(com.smartandroid.sa.tag.nodes.FormElement) Element(com.smartandroid.sa.tag.nodes.Element) Elements(com.smartandroid.sa.tag.select.Elements) FormElement(com.smartandroid.sa.tag.nodes.FormElement)

Aggregations

Elements (com.smartandroid.sa.tag.select.Elements)6 Element (com.smartandroid.sa.tag.nodes.Element)2 Document (com.smartandroid.sa.tag.nodes.Document)1 FormElement (com.smartandroid.sa.tag.nodes.FormElement)1 Evaluator (com.smartandroid.sa.tag.select.Evaluator)1 ArrayList (java.util.ArrayList)1