Package com.crawljax.forms
Class FormInputValueHelper
- java.lang.Object
-
- com.crawljax.forms.FormInputValueHelper
-
public final class FormInputValueHelper extends Object
Singleton helper class for FormHandler.
-
-
Field Summary
Fields Modifier and Type Field Description private static intEMPTYprivate CrawlRules.FormFillModeformFillModeprivate Map<Identification,FormInput>formInputsprivate static StringFORMS_JSON_FILEprivate static FormInputValueHelperinstanceprivate static org.slf4j.LoggerLOGGER
-
Constructor Summary
Constructors Modifier Constructor Description privateFormInputValueHelper(InputSpecification inputSpecification, CrawlRules.FormFillMode formFillMode)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddTrainingInput(Identification identification, FormInput input)Add the training data to the form input map.static List<FormInput>deserializeFormInputs(File dir)Serializes form inputs and writes the data to the output directory to be used by future non-training crawls.private FormInputformInputMatchingNode(Node element)return the list of FormInputs that match this elementNodegetBelongingNode(FormInput input, Document dom)List<CandidateElement>getCandidateElementsForInputs(EmbeddedBrowser browser, Element sourceElement, EventableCondition eventableCondition)private StringgetElementType(Node node)private FormInputgetFormInput(EmbeddedBrowser browser, Node element, int indexValue)FormInputgetFormInput(Identification identification)Get the form input for the DOM element.private FormInput.InputTypegetFormInputType(Node node)FormInputgetFormInputWithIndexValue(EmbeddedBrowser browser, Node element, int indexValue)private IdentificationgetIdentification(Node element)static FormInputValueHelpergetInstance(InputSpecification inputSpecification, CrawlRules.FormFillMode formFillMode)Creates or returns the instance of the helper class.private intgetMaxNumberOfValues(List<FormInput> fieldNames)static voidreset()Removes the instance so another must be built.static voidserializeFormInputs(File dir)Serializes form inputs and writes the data to the output directory to be used by future non-training crawls.
-
-
-
Field Detail
-
LOGGER
private static final org.slf4j.Logger LOGGER
-
FORMS_JSON_FILE
private static final String FORMS_JSON_FILE
- See Also:
- Constant Field Values
-
EMPTY
private static final int EMPTY
- See Also:
- Constant Field Values
-
instance
private static FormInputValueHelper instance
-
formInputs
private final Map<Identification,FormInput> formInputs
-
formFillMode
private final CrawlRules.FormFillMode formFillMode
-
-
Constructor Detail
-
FormInputValueHelper
private FormInputValueHelper(InputSpecification inputSpecification, CrawlRules.FormFillMode formFillMode)
- Parameters:
inputSpecification- the input specification.formFillMode- if random data should be used on the input fields.
-
-
Method Detail
-
getInstance
public static FormInputValueHelper getInstance(InputSpecification inputSpecification, CrawlRules.FormFillMode formFillMode)
Creates or returns the instance of the helper class.- Parameters:
inputSpecification- the input specification.formFillMode- if random data should be used on the input fields.- Returns:
- The singleton instance.
-
reset
public static void reset()
Removes the instance so another must be built. Used only to reset the state in between JUnit tests.
-
serializeFormInputs
public static void serializeFormInputs(File dir)
Serializes form inputs and writes the data to the output directory to be used by future non-training crawls.- Parameters:
dir- The output directory for the form input data.
-
deserializeFormInputs
public static List<FormInput> deserializeFormInputs(File dir)
Serializes form inputs and writes the data to the output directory to be used by future non-training crawls.- Parameters:
dir- The output directory for the form input data.- Returns:
- The list of inputs
-
getCandidateElementsForInputs
public List<CandidateElement> getCandidateElementsForInputs(EmbeddedBrowser browser, Element sourceElement, EventableCondition eventableCondition)
- Parameters:
browser- the browser instancesourceElement- the form elementseventableCondition- the belonging eventable condition for sourceElement- Returns:
- a list with Candidate elements for the inputs
-
getBelongingNode
public Node getBelongingNode(FormInput input, Document dom) throws XPathExpressionException
- Parameters:
input- the form inputdom- the document- Returns:
- returns the belonging node to input in dom
- Throws:
XPathExpressionException- if a failure is occurred.
-
getIdentification
private Identification getIdentification(Node element)
- Parameters:
element-- Returns:
- returns the id of the element if set, else the name. If none found, returns xpath
-
addTrainingInput
public void addTrainingInput(Identification identification, FormInput input)
Add the training data to the form input map.- Parameters:
identification- The identifier.input- The form input.
-
getFormInput
public FormInput getFormInput(Identification identification)
Get the form input for the DOM element.- Parameters:
identification- specifies a DOM element- Returns:
- the form input for the DOM element.
-
getFormInputWithIndexValue
public FormInput getFormInputWithIndexValue(EmbeddedBrowser browser, Node element, int indexValue)
- Parameters:
browser- the current browser instanceelement- the element in the DOMindexValue- the i-th specified value. if i>#values, first value is used- Returns:
- the specified value with index indexValue for the belonging elements
-
getFormInput
private FormInput getFormInput(EmbeddedBrowser browser, Node element, int indexValue)
-
formInputMatchingNode
private FormInput formInputMatchingNode(Node element)
return the list of FormInputs that match this element- Parameters:
element-- Returns:
-
getFormInputType
private FormInput.InputType getFormInputType(Node node)
-
-