Package org.joox

Class JOOX

java.lang.Object
org.joox.JOOX

public final class JOOX extends Object
Author:
Lukas Eder
  • Constructor Details

    • JOOX

      public JOOX()
  • Method Details

    • $

      public static Match $()
      Wrap a new empty document
    • $

      public static Match $(Object object)
      Wrap a JAXB-marshallable element in a jOOX Match element set
      See Also:
    • $

      public static Match $(String name)
      Create a new DOM element in an independent document
    • $

      public static Match $(String name, String content)
      Create a new DOM element in an independent document
    • $

      public static Match $(String name, Element... content)
      Create a new DOM element in an independent document

      The added content is cloned into the new document

    • $

      public static Match $(String name, Match... content)
      Create a new DOM element in an independent document

      The added content is cloned into the new document

    • $

      public static Match $(Document document)
      Wrap a DOM document in a jOOX Match element set
    • $

      public static Match $(Element element)
      Wrap a DOM element in a jOOX Match element set
    • $

      public static Match $(Node node)
      Wrap a DOM Node in a jOOX Match element set

      Supported node types are

      If the supplied Node is of any other type, then an empty Match is created
    • $

      public static Match $(NodeList list)
      Wrap a DOM NodeList in a jOOX Match element set

      If the supplied NodeList is empty or null, then an empty Match is created

    • $

      public static Match $(Context context)
      Convenience method for calling $(context.element())
    • $

      public static Match $(Match match)
      Convenience method for calling $(match)
    • $

      public static Match $(URL url) throws SAXException, IOException
      Convenience method for calling $(url.openStream())
      Throws:
      SAXException
      IOException
    • $

      public static Match $(URI uri) throws SAXException, IOException
      Convenience method for calling $(new File(uri))
      Throws:
      SAXException
      IOException
    • $

      public static Match $(File file) throws SAXException, IOException
      Read a DOM document from a file into a Match element set
      Throws:
      IOException
      SAXException
    • $

      public static Match $(Path path) throws SAXException, IOException
      Read a DOM document from a file into a Match element set
      Throws:
      IOException
      SAXException
    • $

      public static Match $(InputStream stream) throws SAXException, IOException
      Read a DOM document from a stream into a Match element set
      Throws:
      IOException
      SAXException
    • $

      public static Match $(Reader reader) throws SAXException, IOException
      Read a DOM document from a reader into a Match element set
      Throws:
      IOException
      SAXException
    • $

      public static Match $(InputSource source) throws SAXException, IOException
      Read a DOM document from a file into a Match element set
      Throws:
      IOException
      SAXException
    • none

      public static FastFilter none()
      A filter that always returns false
    • all

      public static FastFilter all()
      A filter that always returns true
    • even

      public static FastFilter even()
      A filter that returns true on all even iteration indexes (starting with 0!)
    • odd

      public static FastFilter odd()
      A filter that returns true on all odd iteration indexes (starting with 0!)
    • leaf

      public static FastFilter leaf()
      A filter that returns true on leaf elements
    • at

      public static FastFilter at(int... indexes)
      A filter that returns true on elements at given iteration indexes
    • selector

      public static Filter selector(String selector)
      A filter that returns all elements matched by a given selector.

      In most cases, this is the same as calling tag(String). In Match.find(String), the following CSS-style selector syntax elements are also supported:

      Selector pattern meaning
      * any element
      E an element of type E
      E[foo] an E element with a "foo" attribute
      E[foo="bar"] an E element whose "foo" attribute value is exactly equal to "bar"
      E[foo~="bar"] an E element whose "foo" attribute value is a list of whitespace-separated values, one of which is exactly equal to "bar"
      E[foo^="bar"] an E element whose "foo" attribute value begins exactly with the string "bar"
      E[foo$="bar"] an E element whose "foo" attribute value ends exactly with the string "bar"
      E[foo*="bar"] an E element whose "foo" attribute value contains the substring "bar"
      E[foo|="en"] an E element whose "foo" attribute has a hyphen-separated list of values beginning (from the left) with "en"
      E:root an E element, root of the document
      E:first-child an E element, first child of its parent
      E:last-child an E element, last child of its parent
      E:only-child an E element, only child of its parent
      E:empty an E element that has no children (including text nodes)
      E#myid an E element with ID equal to "myid".
      E F an F element descendant of an E element
      E > F an F element child of an E element
      E + F an F element immediately preceded by an E element
      E ~ F an F element preceded by an E element

      Note that due to the presence of pseudo selectors, such as :root, :empty, etc, namespaces are not supported in selectors. Use jOOX's XPath functionality provided in Match.xpath(String) along with Match.namespaces(java.util.Map) if your XML document contains namespaces

      See Also:
    • tag

      public static FastFilter tag(String tagName)
      A filter that returns all elements with a given tag name

      This is the same as calling tag(tagName, true)

      See Also:
    • tag

      public static FastFilter tag(String tagName, boolean ignoreNamespace)
      A filter that returns all elements with a given tag name

      This method allows for specifying whether namespace prefixes should be ignored. This is particularly useful in DOM Level 1 documents, which are namespace-unaware. In those methods Document.getElementsByTagNameNS(String, String) will not work, as elements do not contain any localName.

      Parameters:
      tagName - The tag name to match. Use * as a special tag name to match all tag names
      ignoreNamespace - Whether namespace prefixes can be ignored. When set to true, then the namespace prefix is ignored. When set to false, then tagName must include the actual namespace prefix.
    • namespacePrefix

      public static FastFilter namespacePrefix(String namespacePrefix)
      A filter that returns all elements with a given namespace prefix

      null and the empty string are treated equally to indicate that no namespace prefix should be present.

    • namespaceURI

      public static FastFilter namespaceURI(String namespaceURI)
      A filter that returns all elements with a given namespace URI

      null and the empty string are treated equally to indicate that no namespace URI should be present.

      This only works if the underlying document is namespace-aware

    • matchText

      public static FastFilter matchText(String regex)
      A filter that returns all elements whose text content matches a given regex
      See Also:
    • matchAttr

      public static FastFilter matchAttr(String name, String valueRegex)
      A filter that returns all elements whose text content matches a given regex
      See Also:
    • matchTag

      public static FastFilter matchTag(String regex)
      A filter that returns all elements whose tag name matches a given regex

      This is the same as calling matchTag(regex, true)

      See Also:
    • matchTag

      public static FastFilter matchTag(String regex, boolean ignoreNamespace)
      A filter that returns all elements whose tag name matches a given regex

      This method allows for specifying whether namespace prefixes should be ignored. This is particularly useful in DOM Level 1 documents, which are namespace-unaware. In those methods Document.getElementsByTagNameNS(String, String) will not work, as elements do not contain any localName.

      Parameters:
      regex - The regular expression to use for matching tag names.
      ignoreNamespace - Whether namespace prefixes can be ignored. When set to true, then the namespace prefix is ignored. When set to false, then regex must also match potential namespace prefixes.
      See Also:
    • attr

      public static FastFilter attr(String name)
      A filter that returns all elements with a given attribute
    • attr

      public static FastFilter attr(String name, String value)
      A filter that returns all elements with a given attribute being set to a given value
    • attr

      public static FastFilter attr(String name, String... values)
      A filter that returns all elements with a given attribute being set to a given value
    • and

      public static Filter and(Filter... filters)
      Combine filters
    • or

      public static Filter or(Filter... filters)
      Combine filters
    • not

      public static Filter not(Filter filter)
      Inverse a filter
    • ids

      public static FastFilter ids(String... ids)
      Create a filter matching id attributes
    • content

      public static Content content(String value)
      Get a constant content that returns the same value for all elements.
    • content

      public static Content content(Object value)
      Get a constant content that returns a marshalled, JAXB-annotated value for all elements.
      See Also:
    • ids

      public static Mapper<String> ids()
      Create a mapper that returns all id attributes
    • attrs

      public static Mapper<String> attrs(String attributeName)
      Create a mapper that returns all attributes with a given name
    • paths

      public static Mapper<String> paths()
      Create a mapper that returns all paths to given elements
    • chain

      public static Each chain(Each... each)
      Chain several instances of Each into a single one.

      The resulting chained Each produces a new Each that can be used in the Match.each(Each) method. I.e. every node in a set of matched nodes will be passed to every chained Each, sequentially.

    • chain

      public static Each chain(Iterable<? extends Each> each)
      Chain several instances of Each into a single one.

      The resulting chained Each produces a new Each that can be used in the Match.each(Each) method. I.e. every node in a set of matched nodes will be passed to every chained Each, sequentially.

    • iterable

      public static Iterable<Element> iterable(NodeList elements)
      Wrap a NodeList into an Iterable
    • iterator

      public static Iterator<Element> iterator(NodeList elements)
      Wrap a NodeList into an Iterator
    • list

      public static List<Element> list(NodeList elements)
      Wrap a NodeList into an List
    • builder

      public static DocumentBuilder builder()
      Get a namespace-aware document builder
    • convert

      public static <T> T convert(String value, Class<T> type)
      Convert a string value to any of these types:
      • String: The conversion has no effect
      • Byte: Numeric conversion. NaN will return null
      • Short: Numeric conversion. NaN will return null
      • Integer: Numeric conversion. NaN will return null
      • Long: Numeric conversion. NaN will return null
      • Float: Numeric conversion. NaN will return null
      • Double: Numeric conversion. NaN will return null
      • BigDecimal: Numeric conversion. NaN will return null
      • BigInteger: Numeric conversion. NaN will return null
      • Boolean: Boolean conversion. Boolean values for true are any of these case-insensitive strings:
        • 1
        • y
        • yes
        • true
        • on
        • enabled
        Boolean values for false are any of these case-insensitive strings:
        • 0
        • n
        • no
        • false
        • off
        • disabled
      • Primitive types: Numeric or boolean conversion, except that null and illegal values will result in 0 or false
      • Date: Datetime conversion.
      • Calendar: Datetime conversion.
      • GregorianCalendar: Datetime conversion.
      • Timestamp: Datetime conversion. Possible patterns for datetime conversion are
        • yyyy: Only the year is parsed
        • yyyy[-/]MM: Year and month are parsed. Separator characters are optional
        • yyyy[-/]MM[-/]dd: Date is parsed. Separator characters are optional
        • dd[-/.]MM[-/.]yyyy: Date is parsed. Separator characters are mandatory
        • yyyy[-/]MM[-/]dd[T ]HH: Date and hour are parsed. Separator characters are optional
        • yyyy[-/]MM[-/]dd[T ]HH[:]mm: Date and time are parsed. Separator characters are optional
        • yyyy[-/]MM[-/]dd[T ]HH[:]mm[:]ss: Date and time are parsed. Separator characters are optional
        • yyyy[-/]MM[-/]dd[T ]HH[:]mm[:]ss.SSS: Date and time are parsed. Separator characters are optional
      • Date: Date conversion. Possible patterns for date conversion are
        • yyyy: Only the year is parsed
        • yyyy[-/]MM: Year and month are parsed. Separator characters are optional
        • yyyy[-/]MM[-/]dd: Date is parsed. Separator characters are optional
        • dd[-/.]MM[-/.]yyyy: Date is parsed. Separator characters are mandatory
      • Time: Time conversion. Possible patterns for time conversion are
        • HH: Hour is parsed. Separator characters are optional
        • HH[:]mm: Hour and minute are parsed. Separator characters are optional
        • HH[:]mm[:]ss: Time is parsed. Separator characters are optional
      • Any of the above as array. Arrays of any type are split by any whitespace character, comma or semi-colon. String literals may be delimited by quotes as well.

      All other values evaluate to null

    • convert

      public static <T> List<T> convert(List<String> values, Class<T> type)
      Convert several values
      See Also: