pt.jcodeutil.core.xml
Class XMLUtils

java.lang.Object
  |
  +--pt.jcodeutil.core.xml.XMLUtils

public abstract class XMLUtils
extends java.lang.Object

Title: XMLUtils

Description: Provide some utilities for XML Manipulation.

Version:
1.0
Author:
Marco Samuel (samuelbb@sapo.pt)

Constructor Summary
XMLUtils()
           
 
Method Summary
static java.lang.String getElementText(org.w3c.dom.Element element)
          Return the text inside an Element.
static org.w3c.dom.Document newDocument()
          Create an empty Document.
static org.w3c.dom.Document parse(java.io.File file)
          Parse a File into a XML Tree Document.
static org.w3c.dom.Document parse(org.xml.sax.InputSource in)
          Parse an InputSource into a XML Tree Document.
static org.w3c.dom.Document parse(java.io.InputStream in)
          Parse an InputStream into a XML Tree Document.
static org.w3c.dom.Document parse(java.io.Reader in)
          Parse a Reader into a XML Tree Document.
static org.w3c.dom.Document parse(java.lang.String xml)
          Parse the contents of a String containing XML data into a XML Tree Document.
static org.w3c.dom.Document parse(java.net.URL url)
          Parse the contents of a URL into a XML Tree Document.
static java.lang.String printDocument(org.w3c.dom.Document d)
          Converts the DOM Tree into a pretty String.
static org.w3c.dom.Document transform(org.w3c.dom.Document xml, org.w3c.dom.Document xsl)
          Execute a XML Transformation and return the result as a XML Tree Document.
static void transform(java.io.InputStream xml, java.io.InputStream xsl, java.io.OutputStream result)
          Execute a XSL transformation.
static void transform(java.io.Reader xml, java.io.Reader xsl, java.io.Writer result)
          Execute a XSL transformation.
static void transform(java.io.Reader xml, java.io.Reader xsl, java.io.Writer result, java.util.Map parameters)
          This method transforms a XML Document using a XSL.
static java.lang.String transform(java.lang.String xml, java.lang.String xsl)
          Execute a XSL transformation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XMLUtils

public XMLUtils()
Method Detail

printDocument

public static java.lang.String printDocument(org.w3c.dom.Document d)
                                      throws java.io.IOException
Converts the DOM Tree into a pretty String.
Parameters:
d - document to be converted
Returns:
a String representing the DOM Tree
Throws:
java.io.IOException -  

parse

public static final org.w3c.dom.Document parse(org.xml.sax.InputSource in)
                                        throws javax.xml.parsers.ParserConfigurationException,
                                               java.io.IOException,
                                               org.xml.sax.SAXException
Parse an InputSource into a XML Tree Document.
Parameters:
in - - the Source to be Parsed.
Returns:
a XML Tree Document.

parse

public static final org.w3c.dom.Document parse(java.io.InputStream in)
                                        throws javax.xml.parsers.ParserConfigurationException,
                                               java.io.IOException,
                                               org.xml.sax.SAXException
Parse an InputStream into a XML Tree Document.
Parameters:
in - - the InputStream to be parsed.
Returns:
a XML Tree Document.

parse

public static final org.w3c.dom.Document parse(java.io.Reader in)
                                        throws javax.xml.parsers.ParserConfigurationException,
                                               java.io.IOException,
                                               org.xml.sax.SAXException
Parse a Reader into a XML Tree Document.
Parameters:
in - - the Reader to be parsed.
Returns:
a XML Tree Document.

parse

public static final org.w3c.dom.Document parse(java.io.File file)
                                        throws javax.xml.parsers.ParserConfigurationException,
                                               java.io.IOException,
                                               org.xml.sax.SAXException
Parse a File into a XML Tree Document.
Parameters:
file - - File to be parsed.
Returns:
a XML Tree Document.

parse

public static final org.w3c.dom.Document parse(java.net.URL url)
                                        throws javax.xml.parsers.ParserConfigurationException,
                                               java.io.IOException,
                                               org.xml.sax.SAXException
Parse the contents of a URL into a XML Tree Document.
Parameters:
url - - URL to be parsed.
Returns:
a XML Tree Document.

parse

public static final org.w3c.dom.Document parse(java.lang.String xml)
                                        throws javax.xml.parsers.ParserConfigurationException,
                                               java.io.IOException,
                                               org.xml.sax.SAXException
Parse the contents of a String containing XML data into a XML Tree Document.
Parameters:
xml - - String to be parsed.
Returns:
a XML Tree Document.

newDocument

public static final org.w3c.dom.Document newDocument()
                                              throws javax.xml.parsers.ParserConfigurationException
Create an empty Document.
Returns:
an empty Document.

getElementText

public static final java.lang.String getElementText(org.w3c.dom.Element element)
Return the text inside an Element. If the Element doesn't have a Text inside, then return null.
Parameters:
element - - the element to be scanned to retrieve the text.
Returns:
text encountered inside the element or null.

transform

public static final void transform(java.io.Reader xml,
                                   java.io.Reader xsl,
                                   java.io.Writer result)
                            throws java.io.IOException,
                                   pt.jcodeutil.core.xml.TransformerException
Execute a XSL transformation.
Parameters:
xml - - xml tree to be transformed.
xsl - - xsl to be applied in the transformation.
result - - the result of the transformation.

transform

public static final void transform(java.io.Reader xml,
                                   java.io.Reader xsl,
                                   java.io.Writer result,
                                   java.util.Map parameters)
                            throws java.io.IOException,
                                   pt.jcodeutil.core.xml.TransformerException
This method transforms a XML Document using a XSL.
Parameters:
xml - the XML tree to be transformed.
xsl - the XSL to be applied in the transformation.
result - the result of the transformation
parameters - a map of parameters for the transformer
Throws:
java.io.IOException -  
pt.jcodeutil.core.xml.TransformerException -  

transform

public static final void transform(java.io.InputStream xml,
                                   java.io.InputStream xsl,
                                   java.io.OutputStream result)
                            throws java.io.IOException,
                                   pt.jcodeutil.core.xml.TransformerException
Execute a XSL transformation.
Parameters:
xml - - xml tree to be transformed.
xsl - - xsl to be applied in the transformation.
result - - the result of the transformation.

transform

public static final java.lang.String transform(java.lang.String xml,
                                               java.lang.String xsl)
                                        throws java.io.IOException,
                                               pt.jcodeutil.core.xml.TransformerException
Execute a XSL transformation. The result is returned as a String.
Parameters:
xml - - xml tree to be transformed (in String format).
xsl - - xsl to be applied in the transformation (in String format).
Returns:
the result of the transformation in String format.

transform

public static final org.w3c.dom.Document transform(org.w3c.dom.Document xml,
                                                   org.w3c.dom.Document xsl)
                                            throws java.io.IOException,
                                                   pt.jcodeutil.core.xml.TransformerException,
                                                   javax.xml.parsers.ParserConfigurationException
Execute a XML Transformation and return the result as a XML Tree Document.
Parameters:
xml - document to be transformed.
xsl - xsl to be applied in the transformation.