This done now but some Developers, including me, were stuck when we wanted to alter the default DTD used with HTML classes, only because we ignored that such tool exists.
I suggest to add a reference or informations about DTDBuilder tool in the Java Documentation. For example, in the HTML Package Summary :
Package javax.swing.text.html.parser
I can write such comments if you're interested.
I used DTDBuilder to produce an HTML+MathML DTD :
Animated Gif Demo
This report follows a PR, I already send about a DTDBuilder's bug prevented its usage as indivudal tool :
JDK-8265909
* Javax Swing HTML Parser is a driven DTD-HTML parser. If you want to alter our
* DTD used with HTML classes you had to use DTDBuilder, a program to read a DTD
* and produce a compressed representation of it. For details, see
* <a href="https://...">DTDBuilder Tutorial</a>.
Note : It would be simplier, if the default DTD.getDTD(String name) method can integrated the code of the example :
Track first in DTD Table
if exists, have a result
else track in Ressources path
if named DTD exists load it.
else create the default DTD.
Return the result.
/**
Returns a DTD with the specified name. If
a DTD with that name is not referenced in the DTD Table,
track it in the Ressources path as name.bdtd. If exits load and
return it, else a slight one is created and returned. Any uppercase
characters in the name are converted to lowercase.
@param name the name of the DTD
@return the DTD which corresponds to name
@throws IOException if an I/O error occurs
*/
public static DTD getDTD(String name) throws IOException {
name = name.toLowerCase();
DTD dtd = getDtdHash().get(name);
if (dtd == null){
var in = MyHTML.class.getResourceAsStream(dtd.getName() + ".dtdb");
if (in != null) {
dtd.read(new DataInputStream(new BufferedInputStream(in)));
DTD.putDTDHash(dtd.getName(), dtd);
}
dtd = new DTD(name);
}
return dtd;
}
Then the example would be :
DTD myDTD = MDTD.getDTD("my_html32");
Parser parser = new Parser(myDTD);
:interrobang: I don't understant why the present implementation doesn't return null, if the DTD was not found. This could mislead users through the default created DTD, if the named one is no yet referenced in the DTD Table. It would be simplier to return null.
/**
Returns a DTD with the specified name. If
a DTD with that name doesn't referenced in the DTD Table,
track it in the Ressources path as name.bdtd, if exits load and
return it else returns null. Any uppercase
characters in the name are converted to lowercase.
@param name the name of the DTD
@return the DTD which corresponds to name
@throws IOException if an I/O error occurs
*/
public static DTD getDTD(String name) throws IOException {
name = name.toLowerCase();
DTD dtd = getDtdHash().get(name);
if (dtd == null){
var in = MyHTML.class.getResourceAsStream(dtd.getName() + ".dtdb");
if (in != null) {
dtd.read(new DataInputStream(new BufferedInputStream(in)));
DTD.putDTDHash(dtd.getName(), dtd);
}
}
return dtd;
}
----
Id.|Title|Java Bug Data Base|OpenJDK Bug System|Status
----|----|----|----|----
JDK-8289722|Add Reference or Informations About DTDBuilder in Documentation|[Report](https://bugs.java.com/bugdatabase/view_bug.do?bug_id=8289722)|[Details](https://bugs.openjdk.org/browse/JDK-8289722)|:closed_lock_with_key:
JDK-6632959|Swing html parser doesn't know € or ›|[Report](https://bugs.java.com/bugdatabase/view_bug.do?bug_id=6632959)|[Details](https://bugs.openjdk.org/browse/JDK-6632959)|:closed_lock_with_key:
JDK-6849274|ParserTest.java fails with RuntimeException|[Report](https://bugs.java.com/bugdatabase/view_bug.do?bug_id=6849274)|[Details](https://bugs.openjdk.org/browse/JDK-6849274)|:closed_lock_with_key:
JDK-2206322|html32.bdtd file is not built from source; missing html entities|Report|[Details](https://bugs.openjdk.org/browse/JDK-2206322)|:closed_lock_with_key:
JDK-7017699|html32.bdtd file is not built from source; missing html entities|Report|[Details](https://bugs.openjdk.org/browse/JDK-7017699)|:closed_lock_with_key:
JDK-8257733|Move module-specific data from make to respective module (HTMLlat1.sgml, HTMLspecials.sgml, HTMLsymbol.sgml, html32dtd, public.map) |Report|[Détail](https://bugs.openjdk.org/browse/JDK-8257733) [Commits](https://github.com/openjdk/jdk/commit/f8878cb0cc436993ef1222bc13b00b923d91aad1#diff-b5fac4e798dfba8cb789a18d61b4d90405d4db3250d888e44b376f3fdffca6f7)|:closed_lock_with_key:
Tag
HTML4
:arrow_right:
HTML5
\<a>
:heavy_check_mark:
:heavy_check_mark:
\<abbr>
:heavy_check_mark:
ADDRESS
:heavy_check_mark:
:heavy_check_mark:
APPLET
:heavy_check_mark:
AREA
:heavy_check_mark:
:heavy_check_mark:
\<article>
:heavy_check_mark:
\<aside>
:heavy_check_mark:
\<audio>
:heavy_check_mark:
:heavy_check_mark:
B
:heavy_check_mark:
:heavy_check_mark:
BASE
:heavy_check_mark:
:heavy_check_mark:
BASEFONT
:heavy_check_mark:
CSS
\<bdi>
:heavy_check_mark:
\<bdo>
:heavy_check_mark:
BIG
:heavy_check_mark:
CSS
BLOCKQUOTE
:heavy_check_mark:
:heavy_check_mark:
BODY
:heavy_check_mark:
:heavy_check_mark:
BR
:heavy_check_mark:
:heavy_check_mark:
\<button>
:heavy_check_mark:
\<canvas>
:heavy_check_mark:
CAPTION
:heavy_check_mark:
:heavy_check_mark:
CENTER
:heavy_check_mark:
CSS
CITE
:heavy_check_mark:
:heavy_check_mark:
CODE
:heavy_check_mark:
:heavy_check_mark:
\<col>
:heavy_check_mark:
\<colgroup>
:heavy_check_mark:
\<data>
:heavy_check_mark:
\<datalist>
:heavy_check_mark:
DD
:heavy_check_mark:
:heavy_check_mark:
\<details>
:heavy_check_mark:
DFN
:heavy_check_mark:
:heavy_check_mark:
\<dialog>
:heavy_check_mark:
DIR
:heavy_check_mark:
replaced by \<ul>
DIV
:heavy_check_mark:
:heavy_check_mark:
DL
:heavy_check_mark:
:heavy_check_mark:
DT
:heavy_check_mark:
:heavy_check_mark:
EM
:heavy_check_mark:
:heavy_check_mark:
\<embed>
:heavy_check_mark:
\<fieldset>
:heavy_check_mark:
\<figcaption>
:heavy_check_mark:
\<figure>
:heavy_check_mark:
FONT
:heavy_check_mark:
CSS
\<footer>
:heavy_check_mark:
FORM
:heavy_check_mark:
:heavy_check_mark:
FRAME
:heavy_check_mark:
FRAMESET
:heavy_check_mark:
H1
:heavy_check_mark:
:heavy_check_mark:
H2
:heavy_check_mark:
:heavy_check_mark:
H3
:heavy_check_mark:
:heavy_check_mark:
H4
:heavy_check_mark:
:heavy_check_mark:
H5
:heavy_check_mark:
:heavy_check_mark:
H6
:heavy_check_mark:
:heavy_check_mark:
HEAD
:heavy_check_mark:
:heavy_check_mark:
\<header>
:heavy_check_mark:
HR
:heavy_check_mark:
:heavy_check_mark:
HTML
:heavy_check_mark:
:heavy_check_mark:
I
:heavy_check_mark:
:heavy_check_mark:
\<iframe>
:heavy_check_mark:
IMG
:heavy_check_mark:
:heavy_check_mark:
INPUT
:heavy_check_mark:
:heavy_check_mark:
\<ins>
:heavy_check_mark:
ISINDEX
:heavy_check_mark:
KBD
:heavy_check_mark:
:heavy_check_mark:
\<legend>
:heavy_check_mark:
LI
:heavy_check_mark:
:heavy_check_mark:
LINK
:heavy_check_mark:
:heavy_check_mark:
\<main>
:heavy_check_mark:
MAP
:heavy_check_mark:
:heavy_check_mark:
\<mark>
:heavy_check_mark:
\<math>
1
:heavy_check_mark:
:white_small_square: math :arrow_forward: \<mi>
1
:heavy_check_mark:
:white_small_square: math :arrow_forward: \<mn>
1
:heavy_check_mark:
:white_small_square: math :arrow_forward: \<mo>
1
:heavy_check_mark:
:white_small_square: math :arrow_forward: \<mtext>
1
:heavy_check_mark:
:white_small_square: math :arrow_forward: \<mspace>
1
:heavy_check_mark:
:white_small_square: math :arrow_forward: \<ms>
1
:heavy_check_mark:
:white_small_square: math :arrow_forward: \<mrow>
1
:heavy_check_mark:
:white_small_square: math :arrow_forward: \<mfrac>
1
:heavy_check_mark:
:white_small_square: math :arrow_forward: \<msqrt>
1
:heavy_check_mark:
:white_small_square: math :arrow_forward: \<mroot>
1
:heavy_check_mark:
:white_small_square: math :arrow_forward: \<mstyle>
1
:heavy_check_mark:
:white_small_square: math :arrow_forward: \<merror>
1
:heavy_check_mark:
:white_small_square: math :arrow_forward: \<ppadded>
1
:heavy_check_mark:
:white_small_square: math :arrow_forward: \<mphantom>
1
:heavy_check_mark:
:white_small_square: math :arrow_forward: \<mfenced>
1
:heavy_check_mark:
:white_small_square: math :arrow_forward: \<menclose>
1
:heavy_check_mark:
:white_small_square: math :arrow_forward: \<msub>
1
:heavy_check_mark:
:white_small_square: math :arrow_forward: \<msup>
1
:heavy_check_mark:
:white_small_square: math :arrow_forward: \<msubsup>
1
:heavy_check_mark:
:white_small_square: math :arrow_forward: \<munder>
1
:heavy_check_mark:
:white_small_square: math :arrow_forward: \<mover>
1
:heavy_check_mark:
:white_small_square: math :arrow_forward: \<munderover>
1
:heavy_check_mark:
:white_small_square: math :arrow_forward: \<mmultiscripts>
1
:heavy_check_mark:
:white_small_square: math :arrow_forward: \<mtable>
1
:heavy_check_mark:
:white_small_square: math :arrow_forward: \<mlabeledtr>
1
:heavy_check_mark:
:white_small_square: math :arrow_forward: \<mtr>
1
:heavy_check_mark:
:white_small_square: math :arrow_forward: \<mtd>
1
:heavy_check_mark:
:white_small_square: math :arrow_forward: \<maligngroup>
1
:heavy_check_mark:
:white_small_square: math :arrow_forward: \<maglignmark>
1
:heavy_check_mark:
:white_small_square: math :arrow_forward: \<mstack>
1
:heavy_check_mark:
:white_small_square: math :arrow_forward: \<mlongdiv>
1
:heavy_check_mark:
:white_small_square: math :arrow_forward: \<msgroup>
1
:heavy_check_mark:
:white_small_square: math :arrow_forward: \<mscarries>
1
:heavy_check_mark:
:white_small_square: math :arrow_forward: \<msline>
1
:heavy_check_mark:
:white_small_square: math :arrow_forward: \<maction>
WHATWG community HTML Living Standard. The Web Hypertext Application Technology Working Group (WHATWG) is a community of people interested in evolving the web through standards and tests.
The purpose of this issue is about add Reference or Informations about DTDBuilder in Documentation.
This is referenced in Java Bug Database as
This is tracked in JBS as
Javax Swing HTML Parser is a driven DTD-HTML parser.
The aim of JDK-6190716 was to opensourced DTDBuilder. In the Java Bug Database JDK-6190716 : Make dtdbuilder available to public
This done now but some Developers, including me, were stuck when we wanted to alter the default DTD used with HTML classes, only because we ignored that such tool exists.
I suggest to add a reference or informations about DTDBuilder tool in the Java Documentation. For example, in the HTML Package Summary : Package javax.swing.text.html.parser
I can write such comments if you're interested. I used DTDBuilder to produce an HTML+MathML DTD : Animated Gif Demo
This report follows a PR, I already send about a DTDBuilder's bug prevented its usage as indivudal tool : JDK-8265909
Pull Request Branch : https://github.com/scientificware/jdk/tree/scientificware-JDK-8289741-ref-DTDBuilder
Added in Parser
package-info.java
Example of an HTML DTDBuilder Tutorial page.
Also save the 4 data files from https://github.com/openjdk/jdk/tree/master/src/java.desktop/share/data/dtdbuilder
html32.bdtd
is equivalent to the current archived file used by the JDK to produce its default DTD.html32.dtd
file with your favorite text editor and add your modifications.my_html32.dtd
for example.my_html32.bdtd
is the file you had to use now to create your new extended DTD.The code below,
html32
default DTD present in the JDK. ???????]import java.io.BufferedInputStream; import java.io.DataInputStream; import java.io.IOException; import javax.swing.text.html.parser.DTD;
public class MyHTML {
public static DTD getDTD() throws IOException { DTD dtd = DTD.getDTD("my_html32"); if (dtd.elementHash.get("div") == null) { var in = MyHTML.class.getResourceAsStream(dtd.getName() + ".dtdb"); if (in != null) { dtd.read(new DataInputStream(new BufferedInputStream(in))); DTD.putDTDHash(dtd.getName(), dtd); } } return dtd; } }
... DTD myDTD = MyHTML.getDTD(); Parser parser = new Parser(myDTD); ...
name
. Ifname
DTD myDTD = MDTD.getDTD("my_html32"); Parser parser = new Parser(myDTD);
name
. Ifname
WHATWG community HTML Living Standard. The Web Hypertext Application Technology Working Group (WHATWG) is a community of people interested in evolving the web through standards and tests.
HTML5 DTD An experiment on SGML-based syntax for HTML5
sgmljs
OASIS
Which HTML tags are supported in Swing components ?