Search in sources :

Example 1 with FormElement

use of com.smartandroid.sa.tag.nodes.FormElement 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)

Example 2 with FormElement

use of com.smartandroid.sa.tag.nodes.FormElement in project SmartAndroidSource by jaychou2012.

the class HtmlTreeBuilder method insertForm.

FormElement insertForm(Token.StartTag startTag, boolean onStack) {
    Tag tag = Tag.valueOf(startTag.name());
    FormElement el = new FormElement(tag, baseUri, startTag.attributes);
    setFormElement(el);
    insertNode(el);
    if (onStack)
        stack.add(el);
    return el;
}
Also used : FormElement(com.smartandroid.sa.tag.nodes.FormElement)

Aggregations

FormElement (com.smartandroid.sa.tag.nodes.FormElement)2 Element (com.smartandroid.sa.tag.nodes.Element)1 Elements (com.smartandroid.sa.tag.select.Elements)1