当前位置: 首页>>代码示例>>Java>>正文


Java FormElement类代码示例

本文整理汇总了Java中org.jsoup.nodes.FormElement的典型用法代码示例。如果您正苦于以下问题:Java FormElement类的具体用法?Java FormElement怎么用?Java FormElement使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


FormElement类属于org.jsoup.nodes包,在下文中一共展示了FormElement类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: insertForm

import org.jsoup.nodes.FormElement; //导入依赖的package包/类
FormElement insertForm(Token.StartTag startTag, boolean onStack) {
    Tag tag = Tag.valueOf(startTag.name(), settings);
    FormElement el = new FormElement(tag, baseUri, startTag.attributes);
    setFormElement(el);
    insertNode(el);
    if (onStack)
        stack.add(el);
    return el;
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:10,代码来源:HtmlTreeBuilder.java

示例2: postHtmlFile

import org.jsoup.nodes.FormElement; //导入依赖的package包/类
/**
 * Test fetching a form, and submitting it with a file attached.
 */
@Test
public void postHtmlFile() throws IOException {
    Document index = Jsoup.connect("http://direct.infohound.net/tidy/").get();
    FormElement form = index.select("[name=tidy]").forms().get(0);
    Connection post = form.submit();

    File uploadFile = ParseTest.getFile("/htmltests/google-ipod.html");
    FileInputStream stream = new FileInputStream(uploadFile);
    
    Connection.KeyVal fileData = post.data("_file");
    fileData.value("check.html");
    fileData.inputStream(stream);

    Connection.Response res;
    try {
        res = post.execute();
    } finally {
        stream.close();
    }

    Document out = res.parse();
    assertTrue(out.text().contains("HTML Tidy Complete"));
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:27,代码来源:UrlConnectTest.java

示例3: getFormData

import org.jsoup.nodes.FormElement; //导入依赖的package包/类
/**
 * Give a Document, parse it and return all form data.
 * 
 * @param doc
 * @return null if this Document has more than one form or does not have form
 */
private static Map<String, String> getFormData(Document doc){
	Elements formElements = doc.getElementsByTag("form");
	if(formElements.size() != 1)
		return null;
	List<FormElement> forms = formElements.forms();
	List<KeyVal> data = forms.get(0).formData();
	HashMap<String, String> map = new HashMap<String, String>();
	for(KeyVal kv: data){
		map.put(kv.key(), kv.value());
	}
	return map;
}
 
开发者ID:LesterLyu,项目名称:AcornAPI,代码行数:19,代码来源:Acorn.java

示例4: getFormData

import org.jsoup.nodes.FormElement; //导入依赖的package包/类
/**
 * Give a Document, parse it and return all form data.
 *
 * @param doc
 * @return null if this Document has more than one form or does not have form
 */
private static Map<String, String> getFormData(Document doc){
    Elements formElements = doc.getElementsByTag("form");
    if(formElements.size() != 1)
        return null;
    List<FormElement> forms = formElements.forms();
    List<KeyVal> data = forms.get(0).formData();
    HashMap<String, String> map = new HashMap<String, String>();
    for(KeyVal kv: data){
        map.put(kv.key(), kv.value());
    }
    return map;
}
 
开发者ID:LesterLyu,项目名称:UofT-Timetable,代码行数:19,代码来源:Acorn.java

示例5: createsFormElements

import org.jsoup.nodes.FormElement; //导入依赖的package包/类
@Test public void createsFormElements() {
    String html = "<body><form><input id=1><input id=2></form></body>";
    Document doc = Jsoup.parse(html);
    Element el = doc.select("form").first();

    assertTrue("Is form element", el instanceof FormElement);
    FormElement form = (FormElement) el;
    Elements controls = form.elements();
    assertEquals(2, controls.size());
    assertEquals("1", controls.get(0).id());
    assertEquals("2", controls.get(1).id());
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:13,代码来源:HtmlParserTest.java

示例6: associatedFormControlsWithDisjointForms

import org.jsoup.nodes.FormElement; //导入依赖的package包/类
@Test public void associatedFormControlsWithDisjointForms() {
    // form gets closed, isn't parent of controls
    String html = "<table><tr><form><input type=hidden id=1><td><input type=text id=2></td><tr></table>";
    Document doc = Jsoup.parse(html);
    Element el = doc.select("form").first();

    assertTrue("Is form element", el instanceof FormElement);
    FormElement form = (FormElement) el;
    Elements controls = form.elements();
    assertEquals(2, controls.size());
    assertEquals("1", controls.get(0).id());
    assertEquals("2", controls.get(1).id());

    assertEquals("<table><tbody><tr><form></form><input type=\"hidden\" id=\"1\"><td><input type=\"text\" id=\"2\"></td></tr><tr></tr></tbody></table>", TextUtil.stripNewlines(doc.body().html()));
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:16,代码来源:HtmlParserTest.java

示例7: parseFragment

import org.jsoup.nodes.FormElement; //导入依赖的package包/类
List<Node> parseFragment(String inputFragment, Element context, String baseUri, ParseErrorList errors, ParseSettings settings) {
    // context may be null
    state = HtmlTreeBuilderState.Initial;
    initialiseParse(new StringReader(inputFragment), baseUri, errors, settings);
    contextElement = context;
    fragmentParsing = true;
    Element root = null;

    if (context != null) {
        if (context.ownerDocument() != null) // quirks setup:
            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")))
            tokeniser.transition(TokeniserState.Data); // if scripting enabled, rawtext
        else if (contextTag.equals("plaintext"))
            tokeniser.transition(TokeniserState.Data);
        else
            tokeniser.transition(TokeniserState.Data); // default

        root = new Element(Tag.valueOf("html", settings), baseUri);
        doc.appendChild(root);
        stack.add(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();
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:51,代码来源:HtmlTreeBuilder.java

示例8: getFormElement

import org.jsoup.nodes.FormElement; //导入依赖的package包/类
FormElement getFormElement() {
    return formElement;
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:4,代码来源:HtmlTreeBuilder.java

示例9: setFormElement

import org.jsoup.nodes.FormElement; //导入依赖的package包/类
void setFormElement(FormElement formElement) {
    this.formElement = formElement;
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:4,代码来源:HtmlTreeBuilder.java

示例10: login

import org.jsoup.nodes.FormElement; //导入依赖的package包/类
/**
 * This function logs in the student/ parent with their current credentials to Gradebook Pinnacle.
 * It then records session IDs and expiration time via cookies.
 * Precondition: username and password are both defined.
 *
 * @return a status code (1 for no error, -1 for bad password, and -2 for server error.)
 * @throws IOException if an I/O error occurs while connecting to server.
 */
public int login() throws IOException {
    final URL LOAD_URL = new URL(LOGON);
    final String USERNAME_FIELD = "ctl00$ContentPlaceHolder$Username";
    final String PASSWORD_FIELD = "ctl00$ContentPlaceHolder$Password";

    try {
        // Submitting form data.
        Document html = Jsoup.parse(LOAD_URL, 60000);
        FormElement form = (FormElement) html.getElementsByTag("form").get(0);
        Connection conn = form.submit();

        // Find username and password field.
        Connection.KeyVal usernameField = null;
        Connection.KeyVal passwordField = null;
        for (Connection.KeyVal field : conn.request().data())
            if (field.key().equals(USERNAME_FIELD))
                usernameField = field;
            else if (field.key().equals(PASSWORD_FIELD))
                passwordField = field;

        if (usernameField == null) {
            System.err.println("EXPECTED: Form field for username.");
            return -2;
        }

        if (passwordField == null) {
            System.err.println("EXPECTED: Form field for password.");
            return -2;
        }

        // Submit username and password
        usernameField.value(username);
        passwordField.value(password);
        Connection.Response resp = conn.timeout(60000).execute();

        if (resp.url().equals(LOAD_URL))
            return -1;
        else {
            cookies.putAll(resp.cookies());
            updateExpirationDate();

            students.addAll(Parser.parseStudents(this, resp.body()));
            MULTIPLE_STUDENTS = students.size() > 1;

            loggedIn = true;
            return 1;
        }
    } catch (SocketTimeoutException e) {
        e.printStackTrace();
        return -2;
    }
}
 
开发者ID:yourPISD,项目名称:yourpisd,代码行数:61,代码来源:Session.java


注:本文中的org.jsoup.nodes.FormElement类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。