Example usage for javax.swing.text.html HTML getAllAttributeKeys

List of usage examples for javax.swing.text.html HTML getAllAttributeKeys

Introduction

In this page you can find the example usage for javax.swing.text.html HTML getAllAttributeKeys.

Prototype

public static Attribute[] getAllAttributeKeys() 

Source Link

Document

Returns the set of HTML attributes recognized.

Usage

From source file:Main.java

public static void main(String[] args) {

    HTML.Tag[] tags = HTML.getAllTags();
    HTML.Attribute[] attrs = HTML.getAllAttributeKeys();

    System.out.println("HTML Tags:");
    for (int i = 0; i < tags.length - 1; i++) {
        System.out.print(tags[i] + ", ");
        if ((i % 8) == 7) {
            System.out.println("");
        }//from w ww . ja  v  a 2  s .  c  o m
    }
    System.out.println(tags[tags.length - 1]);

    System.out.println("\n\nHTML Attributes:");
    for (int i = 0; i < attrs.length - 1; i++) {
        System.out.print(attrs[i] + ", ");
        if ((i % 8) == 7) {
            System.out.println("");
        }
    }
    System.out.println(attrs[attrs.length - 1]);
}

From source file:fr.aliasource.webmail.formatting.htmlcleaner.AbstractHTMLCleaner.java

private String convert(String html, AttachmentManager am, Map<String, String> attachments) {

    String cleanHtml = html;//from   ww w  .ja  va 2 s .  com

    ElementRemover er = new ElementRemover();

    Attribute[] attr = HTML.getAllAttributeKeys();
    Set<String> allowedAttributes = new HashSet<String>();
    for (int i = 0; i < attr.length; i++) {
        if (!removedAttributes.contains(attr[i].toString().toLowerCase())) {
            allowedAttributes.add(attr[i].toString());
        }
    }

    Tag[] tags = HTML.getAllTags();
    for (int i = 0; i < tags.length; i++) {
        if (!removedElements.contains(tags[i].toString())) {
            er.acceptElement(tags[i].toString(),
                    allowedAttributes.toArray(new String[allowedAttributes.size()]));
        }
    }

    for (String s : removedElements) {
        er.removeElement(s);
    }

    StringWriter sw = new StringWriter();

    XMLDocumentFilter[] filters = { er, new Writer(sw, "UTF-8") };

    XMLParserConfiguration xpc = new HTMLConfiguration();
    xpc.setProperty("http://cyberneko.org/html/properties/filters", filters);
    xpc.setProperty("http://cyberneko.org/html/properties/names/elems", "lower");

    XMLInputSource xis = new XMLInputSource(null, null, null, new StringReader(html), null);

    try {
        xpc.parse(xis);
        cleanHtml = sw.toString();
    } catch (Exception e) {
        logger.error(e.getMessage());
    }

    // all links open in other tab
    cleanHtml = cleanHtml.replace("<a ", "<a target=\"_blank\" ");

    // Replace cid:images by attachment url
    if (attachments != null) {
        for (String aId : attachments.keySet()) {
            Map<String, String> meta = am.getMetadata(aId);
            if (meta.get("content-id") != null) {
                String cid = "cid:" + meta.get("content-id").substring(1, meta.get("content-id").length() - 1);
                cleanHtml = cleanHtml.replace(cid, "download/" + aId + "/" + meta.get("filename"));
            }
        }
    }

    return cleanHtml;
}