public class HTMLUtils extends Object
| Modifier and Type | Class and Description |
|---|---|
static class |
HTMLUtils.Base64
Deprecated.
Use
Base64Utils |
protected static class |
HTMLUtils.CharStyleToken |
| Modifier and Type | Field and Description |
|---|---|
protected static org.w3c.tidy.Tidy |
tidy |
| Constructor and Description |
|---|
HTMLUtils() |
| Modifier and Type | Method and Description |
|---|---|
static String |
colorToHex(Color color)
Converts a Color to a hex string in the format "#RRGGBB"
|
static String |
createTag(HTML.Tag enclTag,
AttributeSet set,
String innerHTML)
Incloses a chunk of HTML text in the specified tag with the specified
attribs
|
static String |
createTag(HTML.Tag enclTag,
String innerHTML)
Incloses a chunk of HTML text in the specified tag
|
protected static int |
depthFromRoot(Element curElem) |
static AttributeSet |
getCharacterAttributes(JEditorPane editor)
Gets the character attributes at the
JEditorPane's caret position
If there is no selection, the character attributes at caretPos - 1 are
retuned. |
static String |
getElementHTML(Element el,
boolean includeEnclosingTags)
Gets the html of the specified
Element |
static String |
getFontFamily(JEditorPane editor)
Gets the font family name at the
JEditorPane's current caret
position |
static Element |
getListParent(Element elem)
|
static Element |
getNextElement(HTMLDocument doc,
Element el)
Gets the element one position greater than the end of the specified
element
|
protected static Element |
getParaElement(HTMLDocument doc,
int pos) |
static List |
getParagraphElements(JEditorPane editor) |
static Element |
getParent(Element curElem,
HTML.Tag parentTag)
Searches upward for the specified parent for the element.
|
static Element |
getPreviousElement(HTMLDocument doc,
Element el)
Gets the element one position less than the start of the specified
element
|
static HTML.Tag |
getStartTag(String text) |
static Color |
hexToColor(String value)
Convert a "#FFFFFF" hex string to a Color.
|
static void |
insertArbitraryHTML(String rawHtml,
JEditorPane editor)
Inserts an arbitrary chunk of HTML into the JEditorPane at the current
caret position.
|
static void |
insertHTML(String html,
HTML.Tag tag,
JEditorPane editor)
Inserts a string of html into the
JEditorPane's
HTMLDocument at the current caret position. |
static boolean |
isElementEmpty(Element el)
Tests if the element is empty
|
static boolean |
isImplied(Element el)
Tests if an element is an implied paragraph (p-implied)
|
static String |
jEditorPaneizeHTML(String html)
Removes self-closing tags from xhtml for the benifit of
JEditorPane
JEditorpane can't handle empty xhtml containers like <br /> or
<img />, so this method replaces them without the "/" as in
<br>
|
static void |
printAttribs(AttributeSet attr)
Helper method that prints out the contents of an
AttributeSet to
System.err for debugging |
static void |
removeCharacterAttribute(JEditorPane editor,
CSS.Attribute atr,
String val)
Removes a CSS character attribute that has the specified value from the
JEditorPane's current caret position or selection. |
static void |
removeCharacterAttribute(JEditorPane editor,
Object atr)
Removes a single character attribute from the editor's current
position/selection.
|
static void |
removeElement(Element el)
Removes an element from the document that contains it
|
static String |
removeEnclosingTags(Element elem,
String txt)
Removes the enclosing tags from a chunk of HTML text
|
static String |
removeEnclosingTags(HTML.Tag t,
String txt)
Removes the enclosing tags from a chunk of HTML text
|
static void |
setCharacterAttributes(JEditorPane editor,
AttributeSet attrs)
Sets the character attributes for selection of the specified editor
|
static void |
setCharacterAttributes(JEditorPane editor,
AttributeSet attr,
boolean replace)
Sets the character attributes for selection of the specified editor
|
static void |
setFontFamily(JEditorPane editor,
String fontName)
Set's the font family at the
JEditorPane's current caret positon,
or for the current selection (if there is one). |
static Color |
stringToColor(String str)
Convert a color string such as "RED" or "#NNNNNN" or "rgb(r, g, b)" to a
Color.
|
static Map |
tagAttribsToMap(String atts)
Converts an html tag attribute list to a
Map. |
protected static String |
tagClose(HTML.Tag t) |
protected static String |
tagOpen(HTML.Tag enclTag,
AttributeSet set) |
protected static List |
tokenizeCharAttribs(HTMLDocument doc,
int s,
int e)
Tokenizes character attrbutes.
|
protected static String |
xmlToString(Node node) |
public static boolean isImplied(Element el)
el - The elementpublic static String createTag(HTML.Tag enclTag, String innerHTML)
enclTag - the tag to enclose the HTML ininnerHTML - the HTML to be inclosedpublic static String createTag(HTML.Tag enclTag, AttributeSet set, String innerHTML)
enclTag - set - innerHTML - protected static String tagOpen(HTML.Tag enclTag, AttributeSet set)
public static List getParagraphElements(JEditorPane editor)
protected static Element getParaElement(HTMLDocument doc, int pos)
public static Element getParent(Element curElem, HTML.Tag parentTag)
curElem - parentTag - public static boolean isElementEmpty(Element el)
el - public static Element getListParent(Element elem)
elem - public static Element getPreviousElement(HTMLDocument doc, Element el)
doc - el - public static Element getNextElement(HTMLDocument doc, Element el)
doc - el - public static String removeEnclosingTags(Element elem, String txt)
elem - txt - public static String removeEnclosingTags(HTML.Tag t, String txt)
t - txt - public static String getElementHTML(Element el, boolean includeEnclosingTags)
Elementel - includeEnclosingTags - true, if the enclosing tags should be includedpublic static void removeElement(Element el) throws BadLocationException
el - BadLocationExceptionprotected static int depthFromRoot(Element curElem)
public static void insertArbitraryHTML(String rawHtml, JEditorPane editor)
rawHtml - editor - public static void insertHTML(String html, HTML.Tag tag, JEditorPane editor)
JEditorPane's
HTMLDocument at the current caret position.html - tag - editor - public static AttributeSet getCharacterAttributes(JEditorPane editor)
JEditorPane's caret position
If there is no selection, the character attributes at caretPos - 1 are retuned. If there is a slection, the attributes at selectionEnd - 1 are returned
editor - AttributeSet or null, if the editor doesn't have a
StyledDocumentpublic static String getFontFamily(JEditorPane editor)
JEditorPane's current caret
positioneditor - public static void setFontFamily(JEditorPane editor, String fontName)
JEditorPane's current caret positon,
or for the current selection (if there is one).
If the fontName parameter is null, any currently set font family is removed.
editor - fontName - public static void removeCharacterAttribute(JEditorPane editor, CSS.Attribute atr, String val)
JEditorPane's current caret position or selection.
The val parameter is a String even though the actual attribute
value is not. This is because the actual attribute values are not public.
Thus, this method checks the value via the toString() method
editor - atr - val - public static void removeCharacterAttribute(JEditorPane editor, Object atr)
Removes from the editor kit's input attribtues and/or document at the caret position. If there is a selction the attribute is removed from the selected text
editor - atr - protected static List tokenizeCharAttribs(HTMLDocument doc, int s, int e)
doc - s - e - public static void setCharacterAttributes(JEditorPane editor, AttributeSet attr, boolean replace)
editor - attrs - replace - if true, replaces the attrubutespublic static void setCharacterAttributes(JEditorPane editor, AttributeSet attrs)
editor - attrs - public static Map tagAttribsToMap(String atts)
Map. For example, the
String 'href="http://blah.com" target="_self"' becomes name-value pairs:atts - public static String colorToHex(Color color)
public static Color hexToColor(String value)
public static Color stringToColor(String str)
public static String jEditorPaneizeHTML(String html)
JEditorPane
JEditorpane can't handle empty xhtml containers like <br /> or <img />, so this method replaces them without the "/" as in <br>
html - public static void printAttribs(AttributeSet attr)
AttributeSet to
System.err for debuggingattr - Copyright © 2016 Imatia Innovation S.L.. All rights reserved.