Class Jerry

java.lang.Object
jodd.jerry.Jerry
All Implemented Interfaces:
Iterable<Jerry>

public class Jerry extends Object implements Iterable<Jerry>
Jerry is JQuery in Java.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    private static class 
     
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected final DOMBuilder
     
    private static final String
     
    protected final Node[]
     
    protected final Jerry
     
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Jerry(Jerry parent, List<Node> nodeList)
    Creates child Jerry.
    protected
    Jerry(Jerry parent, Node... nodes)
    Creates child Jerry.
    protected
    Jerry(Jerry parent, Node[] nodes1, Node[] nodes2)
    Creates child Jerry.
    protected
    Jerry(DOMBuilder builder, Node... nodes)
    Creates root Jerry.
  • Method Summary

    Modifier and Type
    Method
    Description
    add(String selector)
    Adds elements to the set of matched elements.
    addClass(String... classNames)
    Adds the specified class(es) to each of the set of matched elements.
    after(String html)
    Inserts content, specified by the parameter, after each element in the set of matched elements.
    append(String html)
    Inserts content, specified by the parameter, to the end of each element in the set of matched elements.
    attr(String name)
    Gets the value of an attribute for the first element in the set of matched elements.
    attr(String name, String value)
    Sets one or more attributes for the set of matched elements.
    before(String html)
    Inserts content, specified by the parameter, before each element in the set of matched elements.
    Gets the immediate children of each element in the set of matched elements.
    Get the children of each element in the set of matched elements, including text and comment nodes.
    Just creates new Jerry runner to separate parser creation and creation of new Jerry instances.
    create(DOMBuilder domBuilder)
    Creates new Jerry runner with provided implementation of DOMBuilder.
    protected NodeSelector
    Creates node selector.
    protected Map<String,String>
    createPropertiesMap(String attrValue, char propertiesDelimiter, char valueDelimiter)
     
    protected Set<String>
    createPropertiesSet(String attrValue, char propertiesDelimiter)
     
    css(String propertyName)
    Gets the value of a style property for the first element in the set of matched elements.
    css(String... css)
    Sets one or more CSS properties for the set of matched elements.
    css(String propertyName, String value)
    Sets one or more CSS properties for the set of matched elements.
    Removes the set of matched elements from the DOM.
    each(JerryFunction function)
    Iterates over a jQuery object, executing a function for each matched element.
    Iterates over a jQuery object, executing a function for each matched element.
    Removes all child nodes of the set of matched elements from the DOM.
    end()
    Ends the most recent filtering operation in the current chain and returns the set of matched elements to its previous state.
    eq(int value)
    Reduces the set of matched elements to the one at the specified index.
    filter(String cssSelectors)
    Reduces the set of matched elements to those that match the selector.
    filter(JerryFunction jerryFunction)
    Reduces the set of matched elements to those that pass the function's test.
    find(String cssSelector)
    Gets the descendants of each element in the current set of matched elements, filtered by a selector.
    Reduces the set of matched elements to the first in the set.
    form(String formCssSelector, JerryFormHandler jerryFormHandler)
    Processes all forms, collects all form parameters and calls back the JerryFormHandler.
    protected String
    generateAttributeValue(Map<String,String> map, char propertiesDelimiter, char valueDelimiter)
     
    protected String
    generateAttributeValue(Set<String> set, char propertiesDelimiter)
     
    get()
    Retrieve all DOM elements matched by this set.
    get(int index)
    Returns node at given index.
    gt(int value)
    Reduces the set of matched elements to the one at an index greater than specified index.
    has(String cssSelectors)
    Reduce the set of matched elements to those that have a descendant that matches the selector or DOM element.
    boolean
    hasClass(String... classNames)
    Determines whether any of the matched elements are assigned the given class.
    Gets the HTML contents of the first element in the set of matched elements.
    html(String html)
    Sets the HTML contents of each element in the set of matched elements.
    htmlAll(boolean setIncluded)
    Gets the combined HTML contents of each element in the set of matched elements, including their descendants.
    int
    index(Node element)
    Searches for a given Node from among the matched elements.
    boolean
    is(String cssSelectors)
    Checks the current matched set of elements against a selector and return true if at least one of these elements matches the given arguments.
    Returns iterator over nodes contained in the Jerry object.
    Reduces the set of matched elements to the last in the set.
    int
    Returns number of nodes in this Jerry.
    lt(int value)
    Reduces the set of matched elements to the one at an index less than specified index.
    Gets the immediately following sibling of each element in the set of matched elements.
    Get all following siblings of each element in the set of matched elements, optionally filtered by a selector.
    not(String cssSelector)
    Removes elements from the set of matched elements.
    static Jerry
    of(char[] content)
    Parses input sequence and creates new Jerry.
    static Jerry
    of(CharSequence content)
    Parses input content and creates new Jerry.
    Gets the parent of each element in the current set of matched elements.
    Insert content, specified by the parameter, to the beginning of each element in the set of matched elements.
    Gets the immediately preceding sibling of each element in the set of matched elements.
    Get all preceding siblings of each element in the set of matched elements, optionally filtered by a selector.
    Removes the set of matched elements from the DOM.
    Removes an attribute from each element in the set of matched elements.
    removeClass(String... classNames)
    Removes a single class, multiple classes, or all classes from each element in the set of matched elements.
    Replace each element in the set of matched elements with the provided new content and return the set of elements that was removed.
    Returns root Jerry.
    s(String cssSelector)
    Selects nodes.
    Gets the siblings of each element in the set of matched elements.
    int
    Returns number of nodes in this Jerry.
    Gets the combined text contents of each element in the set of matched elements, including their descendants.
    text(String text)
    Sets the content of each element in the set of matched elements to the specified text.
    toggleClass(String... classNames)
    Adds or remove one or more classes from each element in the set of matched elements, depending on either the class's presence or the value of the switch argument.
    Remove the parents of the set of matched elements from the DOM, leaving the matched elements (and siblings, if any) in their place.
    wrap(String html)
    Wraps an HTML structure around each element in the set of matched elements.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface Iterable

    forEach, spliterator
  • Field Details

  • Constructor Details

    • Jerry

      protected Jerry(DOMBuilder builder, Node... nodes)
      Creates root Jerry.
    • Jerry

      protected Jerry(Jerry parent, Node... nodes)
      Creates child Jerry.
    • Jerry

      protected Jerry(Jerry parent, Node[] nodes1, Node[] nodes2)
      Creates child Jerry.
    • Jerry

      protected Jerry(Jerry parent, List<Node> nodeList)
      Creates child Jerry.
  • Method Details

    • of

      public static Jerry of(char[] content)
      Parses input sequence and creates new Jerry.
    • of

      public static Jerry of(CharSequence content)
      Parses input content and creates new Jerry.
    • create

      public static JerryParser create()
      Just creates new Jerry runner to separate parser creation and creation of new Jerry instances.
    • create

      public static JerryParser create(DOMBuilder domBuilder)
      Creates new Jerry runner with provided implementation of DOMBuilder.
    • length

      public int length()
      Returns number of nodes in this Jerry.
    • size

      public int size()
      Returns number of nodes in this Jerry.
    • get

      public Node get(int index)
      Returns node at given index. Returns null if index is out of bounds.
    • get

      public Node[] get()
      Retrieve all DOM elements matched by this set. Warning: returned array is not a clone!
    • index

      public int index(Node element)
      Searches for a given Node from among the matched elements.
    • children

      public Jerry children()
      Gets the immediate children of each element in the set of matched elements.
    • contents

      public Jerry contents()
      Get the children of each element in the set of matched elements, including text and comment nodes.
    • parent

      public Jerry parent()
      Gets the parent of each element in the current set of matched elements.
    • siblings

      public Jerry siblings()
      Gets the siblings of each element in the set of matched elements.
    • next

      public Jerry next()
      Gets the immediately following sibling of each element in the set of matched elements.
    • nextAll

      public Jerry nextAll()
      Get all following siblings of each element in the set of matched elements, optionally filtered by a selector.
    • prev

      public Jerry prev()
      Gets the immediately preceding sibling of each element in the set of matched elements.
    • prevAll

      public Jerry prevAll()
      Get all preceding siblings of each element in the set of matched elements, optionally filtered by a selector.
    • find

      public Jerry find(String cssSelector)
      Gets the descendants of each element in the current set of matched elements, filtered by a selector.
    • s

      public Jerry s(String cssSelector)
      Selects nodes.
      See Also:
    • createNodeSelector

      protected NodeSelector createNodeSelector(Node node)
      Creates node selector.
    • each

      public Jerry each(JerryFunction function)
      Iterates over a jQuery object, executing a function for each matched element.
      See Also:
    • eachNode

      public Jerry eachNode(JerryNodeFunction function)
      Iterates over a jQuery object, executing a function for each matched element.
      See Also:
    • add

      public Jerry add(String selector)
      Adds elements to the set of matched elements.
    • end

      public Jerry end()
      Ends the most recent filtering operation in the current chain and returns the set of matched elements to its previous state.
    • not

      public Jerry not(String cssSelector)
      Removes elements from the set of matched elements.
    • root

      public Jerry root()
      Returns root Jerry.
    • first

      public Jerry first()
      Reduces the set of matched elements to the first in the set.
    • last

      public Jerry last()
      Reduces the set of matched elements to the last in the set.
    • eq

      public Jerry eq(int value)
      Reduces the set of matched elements to the one at the specified index.
    • gt

      public Jerry gt(int value)
      Reduces the set of matched elements to the one at an index greater than specified index.
    • lt

      public Jerry lt(int value)
      Reduces the set of matched elements to the one at an index less than specified index.
    • is

      public boolean is(String cssSelectors)
      Checks the current matched set of elements against a selector and return true if at least one of these elements matches the given arguments.
    • filter

      public Jerry filter(String cssSelectors)
      Reduces the set of matched elements to those that match the selector.
    • filter

      public Jerry filter(JerryFunction jerryFunction)
      Reduces the set of matched elements to those that pass the function's test.
    • has

      public Jerry has(String cssSelectors)
      Reduce the set of matched elements to those that have a descendant that matches the selector or DOM element.
    • attr

      public String attr(String name)
      Gets the value of an attribute for the first element in the set of matched elements. Returns null if set is empty.
    • attr

      public Jerry attr(String name, String value)
      Sets one or more attributes for the set of matched elements.
    • removeAttr

      public Jerry removeAttr(String name)
      Removes an attribute from each element in the set of matched elements.
    • css

      public String css(String propertyName)
      Gets the value of a style property for the first element in the set of matched elements. Returns null if set is empty.
    • css

      public Jerry css(String propertyName, String value)
      Sets one or more CSS properties for the set of matched elements. By passing an empty value, that property will be removed. Note that this is different from jQuery, where this means that property will be reset to previous value if existed.
    • css

      public Jerry css(String... css)
      Sets one or more CSS properties for the set of matched elements.
    • addClass

      public Jerry addClass(String... classNames)
      Adds the specified class(es) to each of the set of matched elements.
    • hasClass

      public boolean hasClass(String... classNames)
      Determines whether any of the matched elements are assigned the given class.
    • removeClass

      public Jerry removeClass(String... classNames)
      Removes a single class, multiple classes, or all classes from each element in the set of matched elements.
    • toggleClass

      public Jerry toggleClass(String... classNames)
      Adds or remove one or more classes from each element in the set of matched elements, depending on either the class's presence or the value of the switch argument.
    • text

      public String text()
      Gets the combined text contents of each element in the set of matched elements, including their descendants. Text is HTML decoded for text nodes.
    • text

      public Jerry text(String text)
      Sets the content of each element in the set of matched elements to the specified text.
    • html

      public String html()
      Gets the HTML contents of the first element in the set of matched elements. Content is raw, not HTML decoded.
      See Also:
    • htmlAll

      public String htmlAll(boolean setIncluded)
      Gets the combined HTML contents of each element in the set of matched elements, including their descendants.
      Parameters:
      setIncluded - if true than sets node are included in the output
      See Also:
    • html

      public Jerry html(String html)
      Sets the HTML contents of each element in the set of matched elements.
    • append

      public Jerry append(String html)
      Inserts content, specified by the parameter, to the end of each element in the set of matched elements.
    • prepend

      public Jerry prepend(String html)
      Insert content, specified by the parameter, to the beginning of each element in the set of matched elements.
    • before

      public Jerry before(String html)
      Inserts content, specified by the parameter, before each element in the set of matched elements.
    • after

      public Jerry after(String html)
      Inserts content, specified by the parameter, after each element in the set of matched elements.
    • replaceWith

      public Jerry replaceWith(String html)
      Replace each element in the set of matched elements with the provided new content and return the set of elements that was removed.
    • remove

      public Jerry remove()
      Removes the set of matched elements from the DOM.
    • detach

      public Jerry detach()
      Removes the set of matched elements from the DOM. Identical to remove().
    • empty

      public Jerry empty()
      Removes all child nodes of the set of matched elements from the DOM.
    • wrap

      public Jerry wrap(String html)
      Wraps an HTML structure around each element in the set of matched elements. Returns the original set of elements for chaining purposes.
    • unwrap

      public Jerry unwrap()
      Remove the parents of the set of matched elements from the DOM, leaving the matched elements (and siblings, if any) in their place.
    • iterator

      public Iterator<Jerry> iterator()
      Returns iterator over nodes contained in the Jerry object. Each node is wrapped. Similar to each(JerryFunction).
      Specified by:
      iterator in interface Iterable<Jerry>
    • form

      public Jerry form(String formCssSelector, JerryFormHandler jerryFormHandler)
      Processes all forms, collects all form parameters and calls back the JerryFormHandler.
    • createPropertiesSet

      protected Set<String> createPropertiesSet(String attrValue, char propertiesDelimiter)
    • generateAttributeValue

      protected String generateAttributeValue(Set<String> set, char propertiesDelimiter)
    • createPropertiesMap

      protected Map<String,String> createPropertiesMap(String attrValue, char propertiesDelimiter, char valueDelimiter)
    • generateAttributeValue

      protected String generateAttributeValue(Map<String,String> map, char propertiesDelimiter, char valueDelimiter)