I use the instructions to add my own tag http://java-sl.com/custom_tag_html_kit.html
class MyParserDelegator extends ParserDelegator {
public MyParserDelegator() {
try {
Field f=javax.swing.text.html.parser.ParserDelegator.class.getDeclaredField("dtd");
f.setAccessible(true);
DTD dtd=(DTD)f.get(null);
javax.swing.text.html.parser.Element div=dtd.getElement("div");
dtd.defineElement("button", div.getType(), true, true,div.getContent(),null, null,div.getAttributes());
} catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
}
}
}
Unfortunately it is not working properly:
Can anyone help me?
It works for me using the following (jdk 1.7):
The only change is the key:
"DTD_KEY"
upper case!!I found the key "DTD_KEY" using
I looked at the sources of JDK 7: the
DTD
is no more store in an attributedtd
ofjavax.swing.text.html.parser.ParserDelegator
but insun.awt.AppContext
. Coming from a sun package, AppContext should not be accessed by classes out of the JRE himself. So using the sources ofjavax.swing.text.html.parser.ParserDelegator
, I wroteMyParserDelegator
that load the DTD himself. After that, the custom tag can be added in DTD easily.The code below also contains the other classes from http://java-sl.com/custom_tag_html_kit.html to get a working example.