Package org.xwiki.xml.html
Class HTMLUtils
- java.lang.Object
-
- org.xwiki.xml.html.HTMLUtils
-
public final class HTMLUtils extends Object
HTML Utility methods.- Since:
- 1.8.3
- Version:
- $Id: 9d2ba75196077f72f8f8ab44b1741e2d241b1791 $
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
HTMLUtils.XWikiXMLOutputter
JDOM's XMLOutputter class converts reserved XML character (&
) into its entity format&
.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean
containsElementText(CharSequence content)
Same logic asescapeElementText(String)
but only indicates if there is something to escape.static String
escapeElementText(String content)
Escapes HTML special characters in aString
using numerical HTML entities, so that the resulting string can safely be used as an HTML content text value.static void
stripFirstElementInside(Document document, String parentTagName, String elementTagName)
Remove the first element inside a parent element and copy the element's children in the parent.static void
stripHTMLEnvelope(Document document)
Strip the HTML envelope if it exists.static String
toString(Document document)
static String
toString(Document document, boolean omitDeclaration, boolean omitDoctype)
-
-
-
Method Detail
-
toString
public static String toString(Document document)
- Parameters:
document
- the W3C Document to transform into a String- Returns:
- the XML as a String
-
toString
public static String toString(Document document, boolean omitDeclaration, boolean omitDoctype)
- Parameters:
document
- the W3C Document to transform into a StringomitDeclaration
- whether the XML declaration should be printed or notomitDoctype
- whether the document type should be printed or not- Returns:
- the XML as a String
-
stripHTMLEnvelope
public static void stripHTMLEnvelope(Document document)
Strip the HTML envelope if it exists. Precisely this means removing the head tag and move all tags in the body tag directly under the html element. This is useful for example if you wish to insert an HTML fragment into an existing HTML page.- Parameters:
document
- the w3c Document to strip
-
stripFirstElementInside
public static void stripFirstElementInside(Document document, String parentTagName, String elementTagName)
Remove the first element inside a parent element and copy the element's children in the parent.- Parameters:
document
- the w3c document from which to remove the top level paragraphparentTagName
- the name of the parent tag to look underelementTagName
- the name of the first element to remove
-
escapeElementText
public static String escapeElementText(String content)
Escapes HTML special characters in aString
using numerical HTML entities, so that the resulting string can safely be used as an HTML content text value. For instance,Jim & John
will be escaped and can thus be put inside a HTML tag, such as thep
tag, as in<p>Jim & John</p>
. Specifically, escapes < to<
, and & to&
.- Parameters:
content
- the text to escape, may benull
.- Returns:
- a new escaped
String
,null
ifnull
input - Since:
- 12.8RC1, 12.6.3, 11.10.11
-
containsElementText
public static boolean containsElementText(CharSequence content)
Same logic asescapeElementText(String)
but only indicates if there is something to escape.- Parameters:
content
- the content to parse- Returns:
- true if the passed content contains content that can be interpreted as HTML syntax
- Since:
- 12.10, 12.6.5
- See Also:
escapeElementText(String)
-
-