Package org.xwiki.xml.script
Class XMLScriptService
- java.lang.Object
-
- org.xwiki.xml.script.XMLScriptService
-
- All Implemented Interfaces:
org.xwiki.script.service.ScriptService
@Component @Named("xml") @Singleton public class XMLScriptService extends Object implements org.xwiki.script.service.ScriptService
Provides Scripting APIs for handling XML.- Since:
- 2.7M1
- Version:
- $Id: 0a3cc5179f22b576742ed7b20396f54c15af7df3 $
-
-
Constructor Summary
Constructors Constructor Description XMLScriptService()
Default component constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Document
createDOMDocument()
Construct a new (empty) DOM Document and return it.static String
escape(Object content)
Escapes all the XML special characters in aString
using numerical XML entities.static String
escapeForAttributeValue(Object content)
Escapes all the XML special characters in aString
using numerical XML entities, so that the resulting string can safely be used as an XML attribute value.static String
escapeForElementContent(Object content)
Escapes the XML special characters in aString
using numerical XML entities, so that the resulting string can safely be used as an XML text node.Document
parse(byte[] content)
Parse abyte[]
into a DOM Document.Document
parse(InputStream stream)
Parse anInputStream
into a DOM Document.Document
parse(String content)
Parse aString
into a DOM Document.Document
parse(LSInput source)
Parse a DOM Document from a source.String
serialize(Node node)
Serialize a DOM Node into a string, including the XML declaration at the start.String
serialize(Node node, boolean withXmlDeclaration)
Serialize a DOM Node into a string, with an optional XML declaration at the start.String
transform(byte[] xml, byte[] xslt)
Apply an XSLT transformation to a Document, both given as byte arrays.String
transform(String xml, String xslt)
Apply an XSLT transformation to a Document, both given as strings.String
transform(Source xml, Source xslt)
Apply an XSLT transformation to a Document.String
transform(Document xml, Document xslt)
Apply an XSLT transformation to a Document, both given as DOM Documents.static String
unescape(Object content)
Unescape encoded special XML characters.
-
-
-
Method Detail
-
escape
public static String escape(Object content)
Escapes all the XML special characters in aString
using numerical XML entities. Specifically, escapes <, >, ", ' and &.- Parameters:
content
- the text to escape, may benull
- Returns:
- a new escaped
String
,null
ifnull
input
-
escapeForAttributeValue
public static String escapeForAttributeValue(Object content)
Escapes all the XML special characters in aString
using numerical XML entities, so that the resulting string can safely be used as an XML attribute value. Specifically, escapes <, >, ", ' and &.- Parameters:
content
- the text to escape, may benull
- Returns:
- a new escaped
String
,null
ifnull
input
-
escapeForElementContent
public static String escapeForElementContent(Object content)
Escapes the XML special characters in aString
using numerical XML entities, so that the resulting string can safely be used as an XML text node. Specifically, escapes <, >, and &.- Parameters:
content
- the text to escape, may benull
- Returns:
- a new escaped
String
,null
ifnull
input
-
unescape
public static String unescape(Object content)
Unescape encoded special XML characters. Only >, < &, " and ' are unescaped, since they are the only ones that affect the resulting markup.- Parameters:
content
- the text to decode, may benull
- Returns:
- unescaped content,
null
ifnull
input
-
createDOMDocument
public Document createDOMDocument()
Construct a new (empty) DOM Document and return it.- Returns:
- an empty DOM Document
-
parse
public Document parse(LSInput source)
Parse a DOM Document from a source.- Parameters:
source
- the source input to parse- Returns:
- the equivalent DOM Document, or
null
if the parsing failed.
-
parse
public Document parse(byte[] content)
Parse abyte[]
into a DOM Document.- Parameters:
content
- the content to parse- Returns:
- a DOM Document corresponding to the input,
null
if the content can't be parsed successfully
-
parse
public Document parse(String content)
Parse aString
into a DOM Document.- Parameters:
content
- the content to parse- Returns:
- a DOM Document corresponding to the input,
null
if the content can't be parsed successfully
-
parse
public Document parse(InputStream stream)
Parse anInputStream
into a DOM Document.- Parameters:
stream
- the content input to parse- Returns:
- a DOM Document corresponding to the input,
null
if the content can't be parsed successfully
-
serialize
public String serialize(Node node)
Serialize a DOM Node into a string, including the XML declaration at the start.- Parameters:
node
- the node to export- Returns:
- the serialized node, or an empty string if the serialization fails
-
serialize
public String serialize(Node node, boolean withXmlDeclaration)
Serialize a DOM Node into a string, with an optional XML declaration at the start.- Parameters:
node
- the node to exportwithXmlDeclaration
- whether to output the XML declaration or not- Returns:
- the serialized node, or an empty string if the serialization fails or the node is
null
-
transform
public String transform(Source xml, Source xslt)
Apply an XSLT transformation to a Document.- Parameters:
xml
- the document to transformxslt
- the stylesheet to apply- Returns:
- the transformation result, or
null
if an error occurs ornull
xml or xslt input
-
transform
public String transform(Document xml, Document xslt)
Apply an XSLT transformation to a Document, both given as DOM Documents.- Parameters:
xml
- the document to transformxslt
- the stylesheet to apply- Returns:
- the transformation result, or
null
if an error occurs ornull
xml or xslt input
-
transform
public String transform(byte[] xml, byte[] xslt)
Apply an XSLT transformation to a Document, both given as byte arrays.- Parameters:
xml
- the document to transformxslt
- the stylesheet to apply- Returns:
- the transformation result, or
null
if an error occurs ornull
xml or xslt input
-
-