Java Utililty Methods Swing HTML

List of utility methods to do Swing HTML

Description

The list of methods to do Swing HTML are organized into topic(s).

Method

voidaddToContentModels(DTD dtd, Element existing, Element alt)
Add element to a DTD.
for (Enumeration<Element> els = dtd.elementHash.elements(); els.hasMoreElements();) {
    ContentModel c = ((Element) els.nextElement()).content;
    if (c != null)
        add(c, existing, alt);
booleancontainsAttribute(Element element, Object name, Object value)
contains Attribute
if (element == null) {
    return false;
Object attribute = element.getAttributes().getAttribute(name);
if (attribute == null) {
    return containsAttribute(element.getParentElement(), name, value);
return value.equals(attribute.toString());
...
ElementfindElementDown(final String name, final Element parent)
find the first occurrence of an Element in the element tree below a given Element
Element foundElement = null;
final ElementIterator eli = new ElementIterator(parent);
Element thisElement = eli.first();
while (thisElement != null && foundElement == null) {
    if (thisElement.getName().equalsIgnoreCase(name)) {
        foundElement = thisElement;
    thisElement = eli.next();
...
ElementfindElementUp(final String name1, final String name2, final Element start)
find the first occurrence of an Element in the element tree above a given Element
Element elem = start;
while (elem != null
        && !(elem.getName().equalsIgnoreCase(name1) || elem.getName().equalsIgnoreCase(name2))) {
    elem = elem.getParentElement();
return elem;
ElementfindLinkElementUp(Element elem)
find the next link attribute from a given element upwards through the element hierarchy
Element e = null;
Object linkAttr = null;
Object href = null;
while ((elem != null) && (linkAttr == null)) {
    e = elem;
    linkAttr = elem.getAttributes().getAttribute(HTML.Tag.A);
    if (linkAttr != null) {
        href = ((AttributeSet) linkAttr).getAttribute(HTML.Attribute.HREF);
...
ObjectfindLinkUp(Element elem)
find the next link attribute from a given element upwards through the element hierarchy
Object linkAttr = null; 
Object href = null;
while ((elem != null) && (linkAttr == null)) {
    linkAttr = elem.getAttributes().getAttribute(HTML.Tag.A);
    if (linkAttr != null) {
        href = ((AttributeSet) linkAttr).getAttribute(HTML.Attribute.HREF);
    elem = elem.getParentElement();
...
StringgetHTMLFromXML(String xml, URL xsl)
Converts an XML file to a formatted HTML output via an XSLT definition.
try {
    Source xmlDoc = new StreamSource(new StringReader(xml));
    Source xslDoc = new StreamSource(xsl.openStream());
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    TransformerFactory tFactory = TransformerFactory.newInstance();
    Transformer transformer = tFactory.newTransformer(xslDoc);
    transformer.transform(xmlDoc, new StreamResult(baos));
    String html = baos.toString(StandardCharsets.UTF_8.name());
...
ListgetImgs(final String html)
get Imgs
final List<String> imgs = new LinkedList<String>();
if (null == html || html.isEmpty()) {
    return imgs;
final Reader r = new StringReader(html);
ParserDelegator pd = new ParserDelegator();
pd.parse(r, new HTMLEditorKit.ParserCallback() {
    public void handleSimpleTag(Tag t, MutableAttributeSet a, int pos) {
...
intgetRowIndex(final Element cell)
get the row index for a given table cell
final Element thisRow = cell.getParentElement();
final Element table = thisRow.getParentElement();
int index = 0;
final int count = table.getElementCount();
Element elem = table.getElement(index);
while (!elem.equals(thisRow) && index < count) {
    elem = table.getElement(++index);
return index;
booleanhasClass(AttributeSet attr, String className)
has Class
String classValue = (String) attr.getAttribute(Attribute.CLASS);
if (classValue == null) {
    return false;
String[] classNames = classValue.split(" ");
for (String c : classNames) {
    if (c.equals(className)) {
        return true;
...