|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.atlanticbb.tantlinger.ui.text.HTMLUtils
public class HTMLUtils
A collection of static convenience methods for working with HTML, HTMLDocuments, AttributeSets and Elements from HTML documents.
Constructor Summary | |
---|---|
HTMLUtils()
|
Method Summary | |
---|---|
static java.lang.String |
colorToHex(java.awt.Color color)
Converts a Color to a hex string in the format "#RRGGBB" |
static java.lang.String |
createTag(javax.swing.text.html.HTML.Tag enclTag,
javax.swing.text.AttributeSet set,
java.lang.String innerHTML)
Incloses a chunk of HTML text in the specified tag with the specified attribs |
static java.lang.String |
createTag(javax.swing.text.html.HTML.Tag enclTag,
java.lang.String innerHTML)
Incloses a chunk of HTML text in the specified tag |
static javax.swing.text.AttributeSet |
getCharacterAttributes(javax.swing.JEditorPane editor)
Gets the character attributes at the JEditorPane 's caret position |
static java.lang.String |
getElementHTML(javax.swing.text.Element el,
boolean includeEnclosingTags)
Gets the html of the specified Element |
static java.lang.String |
getFontFamily(javax.swing.JEditorPane editor)
Gets the font family name at the JEditorPane 's current caret position |
static javax.swing.text.Element |
getListParent(javax.swing.text.Element elem)
Searches for a list Element that is the parent of the specified Element . |
static javax.swing.text.Element |
getNextElement(javax.swing.text.html.HTMLDocument doc,
javax.swing.text.Element el)
Gets the element one position greater than the end of the specified element |
static java.util.List |
getParagraphElements(javax.swing.JEditorPane editor)
|
static javax.swing.text.Element |
getParent(javax.swing.text.Element curElem,
javax.swing.text.html.HTML.Tag parentTag)
Searches upward for the specified parent for the element. |
static javax.swing.text.Element |
getPreviousElement(javax.swing.text.html.HTMLDocument doc,
javax.swing.text.Element el)
Gets the element one position less than the start of the specified element |
static javax.swing.text.html.HTML.Tag |
getStartTag(java.lang.String text)
|
static java.awt.Color |
hexToColor(java.lang.String value)
Convert a "#FFFFFF" hex string to a Color. |
static void |
insertArbitraryHTML(java.lang.String rawHtml,
javax.swing.JEditorPane editor)
Inserts an arbitrary chunk of HTML into the JEditorPane at the current caret position. |
static void |
insertHTML(java.lang.String html,
javax.swing.text.html.HTML.Tag tag,
javax.swing.JEditorPane editor)
Inserts a string of html into the JEditorPane 's HTMLDocument
at the current caret position. |
static boolean |
isElementEmpty(javax.swing.text.Element el)
Tests if the element is empty |
static boolean |
isImplied(javax.swing.text.Element el)
Tests if an element is an implied paragraph (p-implied) |
static java.lang.String |
jEditorPaneizeHTML(java.lang.String html)
Removes self-closing tags from xhtml for the benifit of JEditorPane |
static void |
printAttribs(javax.swing.text.AttributeSet attr)
Helper method that prints out the contents of an AttributeSet to System.err
for debugging |
static void |
removeCharacterAttribute(javax.swing.JEditorPane editor,
javax.swing.text.html.CSS.Attribute atr,
java.lang.String val)
Removes a CSS character attribute that has the specified value from the JEditorPane 's current caret position
or selection. |
static void |
removeCharacterAttribute(javax.swing.JEditorPane editor,
java.lang.Object atr)
Removes a single character attribute from the editor's current position/selection. |
static void |
removeElement(javax.swing.text.Element el)
Removes an element from the document that contains it |
static java.lang.String |
removeEnclosingTags(javax.swing.text.Element elem,
java.lang.String txt)
Removes the enclosing tags from a chunk of HTML text |
static java.lang.String |
removeEnclosingTags(javax.swing.text.html.HTML.Tag t,
java.lang.String txt)
Removes the enclosing tags from a chunk of HTML text |
static void |
setCharacterAttributes(javax.swing.JEditorPane editor,
javax.swing.text.AttributeSet attrs)
Sets the character attributes for selection of the specified editor |
static void |
setCharacterAttributes(javax.swing.JEditorPane editor,
javax.swing.text.AttributeSet attr,
boolean replace)
Sets the character attributes for selection of the specified editor |
static void |
setFontFamily(javax.swing.JEditorPane editor,
java.lang.String fontName)
Set's the font family at the JEditorPane 's current caret positon, or
for the current selection (if there is one). |
static java.awt.Color |
stringToColor(java.lang.String str)
Convert a color string such as "RED" or "#NNNNNN" or "rgb(r, g, b)" to a Color. |
static java.util.Map |
tagAttribsToMap(java.lang.String atts)
Converts an html tag attribute list to a Map . |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public HTMLUtils()
Method Detail |
---|
public static boolean isImplied(javax.swing.text.Element el)
el
- The element
public static java.lang.String createTag(javax.swing.text.html.HTML.Tag enclTag, java.lang.String innerHTML)
enclTag
- the tag to enclose the HTML ininnerHTML
- the HTML to be inclosed
public static java.lang.String createTag(javax.swing.text.html.HTML.Tag enclTag, javax.swing.text.AttributeSet set, java.lang.String innerHTML)
enclTag
- set
- innerHTML
-
public static java.util.List getParagraphElements(javax.swing.JEditorPane editor)
public static javax.swing.text.Element getParent(javax.swing.text.Element curElem, javax.swing.text.html.HTML.Tag parentTag)
curElem
- parentTag
-
public static boolean isElementEmpty(javax.swing.text.Element el)
el
-
public static javax.swing.text.Element getListParent(javax.swing.text.Element elem)
Element
that is the parent of the specified Element
.
elem
-
public static javax.swing.text.Element getPreviousElement(javax.swing.text.html.HTMLDocument doc, javax.swing.text.Element el)
doc
- el
-
public static javax.swing.text.Element getNextElement(javax.swing.text.html.HTMLDocument doc, javax.swing.text.Element el)
doc
- el
-
public static java.lang.String removeEnclosingTags(javax.swing.text.Element elem, java.lang.String txt)
elem
- txt
-
public static java.lang.String removeEnclosingTags(javax.swing.text.html.HTML.Tag t, java.lang.String txt)
t
- txt
-
public static java.lang.String getElementHTML(javax.swing.text.Element el, boolean includeEnclosingTags)
Element
el
- includeEnclosingTags
- true, if the enclosing tags should be included
public static void removeElement(javax.swing.text.Element el) throws javax.swing.text.BadLocationException
el
-
javax.swing.text.BadLocationException
public static javax.swing.text.html.HTML.Tag getStartTag(java.lang.String text)
public static void insertArbitraryHTML(java.lang.String rawHtml, javax.swing.JEditorPane editor)
rawHtml
- editor
- public static void insertHTML(java.lang.String html, javax.swing.text.html.HTML.Tag tag, javax.swing.JEditorPane editor)
JEditorPane
's HTMLDocument
at the current caret position.
html
- tag
- editor
- public static javax.swing.text.AttributeSet getCharacterAttributes(javax.swing.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 StyledDocument
public static java.lang.String getFontFamily(javax.swing.JEditorPane editor)
JEditorPane
's current caret position
editor
-
public static void setFontFamily(javax.swing.JEditorPane editor, java.lang.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(javax.swing.JEditorPane editor, javax.swing.text.html.CSS.Attribute atr, java.lang.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(javax.swing.JEditorPane editor, java.lang.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
- public static void setCharacterAttributes(javax.swing.JEditorPane editor, javax.swing.text.AttributeSet attr, boolean replace)
editor
- attrs
- replace
- if true, replaces the attrubutespublic static void setCharacterAttributes(javax.swing.JEditorPane editor, javax.swing.text.AttributeSet attrs)
editor
- attrs
- public static java.util.Map tagAttribsToMap(java.lang.String atts)
Map
.
For example, the String 'href="http://blah.com" target="_self"' becomes
name-value pairs:
atts
-
public static java.lang.String colorToHex(java.awt.Color color)
public static java.awt.Color hexToColor(java.lang.String value)
public static java.awt.Color stringToColor(java.lang.String str)
public static java.lang.String jEditorPaneizeHTML(java.lang.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(javax.swing.text.AttributeSet attr)
AttributeSet
to System.err
for debugging
attr
-
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |