Yeah, I'm really bad for naming bundles.

The new bundle currently provides a new "html5-generator" that will work with 
the existing rewriter.

How it works is that it uses the same rules that web browsers do to determine 
when a tag in a document is one that needs to be handled or if it's part of a 
text area. It then creates an Element object for that given section and passes 
it along when requested. This is a pull based parser with no structural 
validation. It won't re-write your html unless you specifically request it to.

An example generic usage:
Tag.stream(inputStream, "UTF-8").filter(elem -> elem.getType() == 
ElementType.START_TAG).count();

or a more complex one:

stream.map(element -> {
        if (element.containsAttribute("href")) {
            String value = element.getAttributeValue("href");
            if (value != null && value.startsWith("/")) {
                element.setAttribute("href", "http://www.apache.org"; + value);
            }
        }
        if (element.containsAttribute("src")) {
            String value = element.getAttributeValue("src");
            if (value != null && value.startsWith("/")) {
                element.setAttribute("src", "http://www.apache.org"; + value);
            }
        }
        return element;
 }).map(HtmlStreams.TO_HTML).forEach(System.out::print);

Which would parse all of your html, find hrefs and src attributes that are 
relational and rewrite them as full paths, then convert the individual nodes 
back to HTML.

- Jason

Reply via email to