3

Our test harness needs to generate HTML tags (for img, table, br, audio, video ..) for testing a certain module. We are looking for java libraries which can generate HTML5 compliant code.

There is a thread which already discusses this, but not sure if they support HTML5

Community
  • 1
  • 1
user339108
  • 12,613
  • 33
  • 81
  • 112

3 Answers3

2

There are several available:

Thariama
  • 50,002
  • 13
  • 138
  • 166
1

Html5 is supported by the Summer library released by Asual.

http://www.asual.com/blog/summer/2010/10/01/introducing-summer-the-html5-library-for-java.html

They say there isn't much documentation... so implementation might not be great until it is widely accepted into the Java programming community.

1

Have a look at j2html and webfirmframework based on HTML5 (my favourate one). There are many if you google you will get a lot of opensource libs.

Sample code of webfirmframework :

Div div = new Div(null) {{
    new Img(this,
        new Src("pic_mountain.jpg"),
        new Alt("Mountain View"),
        new Style("width:304px;height:228px;"));
    new Br(this);
    new Audio(this,
        new Controls()) {{
        new Source(this,
            new Src("horse.ogg"),
            new Type("audio/ogg"));
        new Source(this,
            new Src("horse.mp3"),
            new Type("audio/mpeg"));
        new NoTag(this, " Your browser does not support the audio element. ");
    }};
}};

System.out.println(div.toHtmlString());

prints

<div>
    <img src="pic_mountain.jpg" alt="Mountain View" style="width:304px;height:228px;"><br/>
    <audio controls>
       <source src="horse.ogg" type="audio/ogg"></source>
       <source src="horse.mp3" type="audio/mpeg"></source>
       Your browser does not support the audio element. 
    </audio>
</div>

You can also use this tool to convert HTML5 to Java/Kotlin code.

j2html sample code :

body(
    h1("Heading!").withClass("example"),
    img().withSrc("img/hello.png")
).render();

becomes

<body>
    <h1 class="example">Heading!</h1>
    <img src="img/hello.png">
</body>
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/low-quality-posts/16736506) – jwenting Jul 17 '17 at 13:24
  • @jwenting I have added needful code samples – Alberico Durante Jul 17 '17 at 13:38