org.xwiki.xml.internal
Class XMLScriptService

java.lang.Object
  extended by org.xwiki.xml.internal.XMLScriptService
All Implemented Interfaces:
org.xwiki.script.service.ScriptService

@Component
@Named(value="xml")
@Singleton
public class XMLScriptService
extends Object
implements org.xwiki.script.service.ScriptService

Provides Scripting APIs for handling XML.

Since:
2.7M1
Version:
$Id$

Constructor Summary
XMLScriptService()
          Default component constructor.
 
Method Summary
 Document createDOMDocument()
          Construct a new (empty) DOM Document and return it.
static String escape(Object content)
          Escapes all the XML special characters in a String using numerical XML entities.
static String escapeForAttributeValue(Object content)
          Escapes all the XML special characters in a String 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 a String using numerical XML entities, so that the resulting string can safely be used as an XML text node.
 Document parse(byte[] content)
          Parse a byte[] into a DOM Document.
 Document parse(InputStream stream)
          Parse an InputStream into a DOM Document.
 Document parse(LSInput source)
          Parse a DOM Document from a source.
 Document parse(String content)
          Parse a String into a DOM Document.
 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(Document xml, Document xslt)
          Apply an XSLT transformation to a Document, both given as DOM Documents.
 String transform(Source xml, Source xslt)
          Apply an XSLT transformation to a Document.
 String transform(String xml, String xslt)
          Apply an XSLT transformation to a Document, both given as strings.
static String unescape(Object content)
          Unescape encoded special XML characters.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XMLScriptService

public XMLScriptService()
Default component constructor.

Method Detail

escape

public static String escape(Object content)
Escapes all the XML special characters in a String using numerical XML entities. Specifically, escapes <, >, ", ' and &.

Parameters:
content - the text to escape, may be null
Returns:
a new escaped String, null if null input

escapeForAttributeValue

public static String escapeForAttributeValue(Object content)
Escapes all the XML special characters in a String 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 be null
Returns:
a new escaped String, null if null input

escapeForElementContent

public static String escapeForElementContent(Object content)
Escapes the XML special characters in a String 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 be null
Returns:
a new escaped String, null if null 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 be null
Returns:
unescaped content, null if null 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 a byte[] 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 a String 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 an InputStream 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 export
withXmlDeclaration - 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 transform
xslt - the stylesheet to apply
Returns:
the transformation result, or null if an error occurs or null 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 transform
xslt - the stylesheet to apply
Returns:
the transformation result, or null if an error occurs or null 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 transform
xslt - the stylesheet to apply
Returns:
the transformation result, or null if an error occurs or null xml or xslt input

transform

public String transform(String xml,
                        String xslt)
Apply an XSLT transformation to a Document, both given as strings.

Parameters:
xml - the document to transform
xslt - the stylesheet to apply
Returns:
the transformation result, or null if an error occurs or null xml or xslt input


Copyright © 2004-2011 XWiki. All Rights Reserved.