Object Documents

  • All Implemented Interfaces:

    
    public class Documents
    
                        
    • Constructor Detail

    • Method Detail

      • parse

         final FeaturedDocument parse(String html, String baseURI)

        Parse HTML into a FeaturedDocument. The parser will make a sensible, balanced document tree out of any HTML.

        Parameters:
        html - HTML to parse
        baseURI - The URL where the HTML was retrieved from.
        Returns:

        sane HTML

      • parse

         final FeaturedDocument parse(String html, String baseURI, Parser parser)

        Parse HTML into a FeaturedDocument, using the provided Parser. You can provide an alternate parser, such as a simple XML (non-HTML) parser.

        Parameters:
        html - HTML to parse
        baseURI - The URL where the HTML was retrieved from.
        parser - alternate parser to use.
        Returns:

        sane HTML

      • parse

         final FeaturedDocument parse(String html)

        Parse HTML into a FeaturedDocument. As no base PAGE is specified, absolute URL detection relies on the HTML including a <base href> tag.

        Parameters:
        html - HTML to parse
        Returns:

        sane HTML

      • parse

         final FeaturedDocument parse(File file, String charsetName, String baseURI)

        Parse the contents of a file as HTML.

        Parameters:
        file - file to load HTML from
        charsetName - (optional) character set of file contents.
        baseURI - The URL where the HTML was retrieved from, to resolve relative links against.
        Returns:

        sane HTML

      • parse

         final FeaturedDocument parse(File file, String charsetName)

        Parse the contents of a file as HTML. The location of the file is used as the base PAGE to qualify relative URLs.

        Parameters:
        file - file to load HTML from
        charsetName - (optional) character set of file contents.
        Returns:

        sane HTML

      • parse

         final FeaturedDocument parse(InputStream istream, String charsetName, String baseURI)

        Read an input stream, and parse it to a FeaturedDocument.

        Parameters:
        istream - input stream to read.
        charsetName - (optional) character set of file contents.
        baseURI - The URL where the HTML was retrieved from, to resolve relative links against.
        Returns:

        sane HTML

      • parse

         final FeaturedDocument parse(InputStream istream, String charsetName, String baseURI, Parser parser)

        Read an input stream, and parse it to a FeaturedDocument. You can provide an alternate parser, such as a simple XML (non-HTML) parser.

        Parameters:
        istream - input stream to read.
        charsetName - (optional) character set of file contents.
        baseURI - The URL where the HTML was retrieved from, to resolve relative links against.
        parser - alternate parser to use.
        Returns:

        sane HTML

      • parse

         final FeaturedDocument parse(URL url, Long timeoutMillis)

        Fetch a URL, and parse it as HTML. Provided for compatibility; in most cases use .connect instead.

        The encoding character set is determined by the content-type header or http-equiv meta tag, or falls back to UTF-8.

        Parameters:
        url - URL to fetch (with a GET).
        timeoutMillis - Connection and read timeout, in milliseconds.
        Returns:

        The parsed HTML.

      • parseBodyFragment

         final FeaturedDocument parseBodyFragment(String bodyHtml, String baseURI)

        Parse a fragment of HTML, with the assumption that it forms the body of the HTML.

        Parameters:
        bodyHtml - body HTML fragment
        baseURI - URL to resolve relative URLs against.
        Returns:

        sane HTML document

      • parseBodyFragment

         final FeaturedDocument parseBodyFragment(String bodyHtml)

        Parse a fragment of HTML, with the assumption that it forms the body of the HTML.

        Parameters:
        bodyHtml - body HTML fragment
        Returns:

        sane HTML document