package org.webchecker.forms;

import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;

import java.net.URL;

/**
 * Module for manipulating HTML forms from <a href="https://github.com/macajind/WebChecker" target="_blank">Web Checker</a> library.
 * It is designed as singleton, which can only have open one HTML page at time,
 * but it returns instances of {@link Form}s and you can change pages at your wish.
 * So in the end, you can have prepared any number of {@link Form}s you like,
 * even from different web pages, and manipulate them as you please.
 *
 * @author Tunik
 * @version 1.0
 */
public final class Forms {

    private static Forms instance = null;
    private Document document = null;

    private Forms() {
        //Exists only to defeat instantiation.
    }

    /**
     * Method for getting singleton instance of module {@link Forms}, which you need to work with this module.
     *
     * @return singleton instance of module {@link Forms}
     */
    public static Forms getInstance() {
        if (instance == null) {
            instance = new Forms();
        }
        return instance;
    }

    /**
     * Should create {@link Document} instance from given url parameter and open it.
     *
     * @param url
     */
    public void openDocument(URL url) {
    }

    /**
     * Open {@link Document} in singleton instance of module {@link Forms}.
     * If {@link Document} parameter is {@code null}, its like no document was opened.
     *
     * @param document {@link Document} to be opened in singleton instance of module {@link Forms}
     */
    public void openDocument(Document document) {
        this.document = document;
    }

    /**
     * Close currently open {@link Document} in singleton instance of module {@link Forms}.
     */
    public void closeDocument() {
        this.document = null;
    }

    /**
     * Should select form element by identifier from currently opened page/document and return it.
     * What happens when document is null?
     * What happens when no element is found?
     * What happens if found element is not form?
     * What happens when it finds more then 1 element, which match the identifier?
     *
     * @param identifier
     * @return
     */
    public Form selectForm(String identifier) {
        return null;
    }

    /**
     * Support method for verification of form element.
     */
    private Boolean isElementForm(Element element) {
        return false;
    }
}

@@ -24,16 +24,40 @@
 forms;%0A%0A
+import org.jsoup.Jsoup;%0A
 import o
@@ -114,16 +114,83 @@
 ement;%0A%0A
+import java.io.IOException;%0Aimport java.net.MalformedURLException;%0A
 import j
@@ -1339,56 +1339,215 @@
  url
-%0A     */%0A    public void openDocument(URL url) %7B
+ of page which you want to open%0A     * @throws IOException in case of bad format url%0A     */%0A    public void openDocument(URL url) throws IOException %7B%0A        document = Jsoup.connect(url.toString()).get();
 %0A   
@@ -2221,29 +2221,16 @@
     * Wh
-at happens wh
 en docum
@@ -2244,138 +2244,356 @@
 null
-?%0A     * What happens when no element is found?%0A     * What happens if found element is not form?%0A     * What happens when it find
+ application will throw %7B@link java.lang.NullPointerException%7D%0A     * When application doesn't found any element, application will return %7B@literal null%7D%0A     * When found element is not form, application will try found another matching element, but if at page isn't any matching element application return %7B@literal null%7D%0A     * When on the page i
 s mo
@@ -2604,17 +2604,19 @@
 hen 
-1
+one
  element
 , wh
@@ -2615,140 +2615,669 @@
 ment
-, which match the identifier?%0A     *%0A     * @param identifier%0A     * @return%0A     */%0A    public Form selectForm(String identifier) %7B
+s with same identifier, application will select first matching form element%0A     *%0A     * @param identifier is CSS selector %7B@link String%7D. For more information's about CSS selectors visit this %3Ca href='http://www.w3schools.com/cssref/css_selectors.asp'%3Epage%3C/a%3E%0A     * @return new instance of %7B@link Form%7D, which contains elements of found form and url page of %7B@link Document%7D%0A     */%0A    public Form selectForm(String identifier) throws MalformedURLException %7B%0A        for(Element element : document.select(identifier)) %7B%0A            if (isElementForm(element)) %7B%0A                return new Form(element, new URL(document.baseUri()));%0A            %7D%0A        %7D
 %0A   
@@ -3445,13 +3445,35 @@
 urn 
-false
+element.tagName() == %22form%22
 ;%0A  

Update of file Forms