Hypirinha is a Java library for generating HTML. Hypirinha follows the fluent interface style, whereby several method calls can be chained together as single statement to achieve the desired result.
Example
import static org.hypirinha.html.AttributeFactory.*;
import static org.hypirinha.html.ElementFactory.*;
import org.hypirinha.html.elements.*;
import org.hypirinha.html.output.PrintAdapter;
public class HelloWorldCommandLine {
public static void main(String[] args) {
Html html = html();
html.head().link(rel("stylesheet"), href("styles.css"));
html.body().p(classs("greeting")).text("Hello World");
new PrintAdapter().print(html, System.out);
}
}produces on stdout:
<html>
<head>
<link rel="stylesheet" href="styles.css"></link>
</head>
<body>
<p class="greeting">Hello World</p>
</body>
</html>Hypirinha is statically typed; it defines classes for every element type and every attribute type that exist in HTML. Methods for creating and combining elements are constrained by these classes so that it is hard to generate HTML that has an invalid structure. Also, any document fragment is a Java object with a well-known type and so can be stored as a variable or passed as a parameter. This means that it is easy use standard Java constructs for iteration and method invocation while generating HTML.
Please see the basic Tutorial for a closer look at the API.