List of utility methods to do Swing HTML
String | htmlToPlain(String html) html To Plain HTMLEditorKit htmlParser = new HTMLEditorKit(); Document document = htmlParser.createDefaultDocument(); try { htmlParser.read(new ByteArrayInputStream(html.getBytes()), document, 0); String plain = document.getText(0, document.getLength()); return plain; } catch (Exception e) { throw new RuntimeException("Error converting HTML to plain text", e); ... |
boolean | isUnderline(Element element) is Underline return containsAttribute(element, CSS.Attribute.TEXT_DECORATION, "underline"); |
StyleSheet | loadStyleSheet(URL url) Loads a set of rules that have been specified in terms of CSS1 grammar. BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream())); StyleSheet ss = new StyleSheet(); ss.loadRules(reader, null); return ss; |
StyleSheet | makeStyleSheet(String name) make Style Sheet try { StyleSheet sheet = new StyleSheet(); Reader reader = new InputStreamReader(System.class.getResourceAsStream("/css/" + name + ".css")); sheet.loadRules(reader, null); reader.close(); return sheet; } catch (Exception ex) { ex.printStackTrace(); ... |
HTML.Tag | nameOf(Element element) name Of return (HTML.Tag) element.getAttributes().getAttribute(AttributeSet.NameAttribute);
|
String | plainToHtml(String plain) plain To Html DefaultEditorKit plainParser = new DefaultEditorKit(); Document document = plainParser.createDefaultDocument(); try { plainParser.read(new ByteArrayInputStream(plain.getBytes()), document, 0); String html = document.getText(0, document.getLength()); return html; } catch (Exception e) { throw new RuntimeException("Error converting plain text to HTML", e); ... |
String | rtfToBody(String rtf) rtf To Body String html = rtfToHtml(new StringReader(rtf)); if (html.contains("<body")) { html = BODY_PATTERN.matcher(html).replaceAll("$1"); return html; |
String | rtfToHtml(Reader rtf) rtf To Html JEditorPane p = new JEditorPane(); p.setContentType("text/rtf"); EditorKit kitRtf = p.getEditorKitForContentType("text/rtf"); try { kitRtf.read(rtf, p.getDocument(), 0); kitRtf = null; EditorKit kitHtml = p.getEditorKitForContentType("text/html"); Writer writer = new StringWriter(); ... |
String | rtfToHtml(String rtf) rtf To Html return rtfToHtml(new StringReader(rtf)); |
String | stripHTML(String html) strip HTML try { final StringBuilder builder = new StringBuilder(); new ParserDelegator().parse(new StringReader(html), new HTMLEditorKit.ParserCallback() { @Override public void handleText(char[] text, int pos) { builder.append(text); @Override ... |