org.mycore.common.xml
Class MCRXMLHelper

java.lang.Object
  extended by org.mycore.common.xml.MCRXMLHelper

public class MCRXMLHelper
extends Object

This class provides some static utility methods to deal with XML/DOM elements, nodes etc. The class *must* be considered as "work in progress"! There is plenty left to do.

Version:
$Revision: 15270 $ $Date: 2009-05-25 17:27:57 +0200 (Mon, 25 May 2009) $
Author:
Detlev Degenhardt, Frank Lützenkirchen, Thomas Scheffler (yagee)

Constructor Summary
MCRXMLHelper()
           
 
Method Summary
static boolean deepEqual(Document d1, Document d2)
          checks whether two documents are equal.
static MCRParserInterface getParser()
          Returns the XML Parser as configured in mycore.properties
static Document parseURI(URI uri)
          Parses an XML file from a URI and returns it as DOM.
static Document parseURI(URI uri, boolean valid)
          Parses an XML file from a URI and returns it as DOM.
static Document parseXML(byte[] xml)
          Parses an Byte Array and returns it as DOM.
static Document parseXML(byte[] xml, boolean valid)
          Parses an Byte Array and returns it as DOM.
static Document parseXML(String xml)
          Parses an XML String and returns it as DOM.
static Document parseXML(String xml, boolean valid)
          Parses an XML String and returns it as DOM.
static String removeIllegalChars(String text)
          Removes characters that are illegal in XML text nodes or attribute values.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MCRXMLHelper

public MCRXMLHelper()
Method Detail

getParser

public static MCRParserInterface getParser()
                                    throws MCRException
Returns the XML Parser as configured in mycore.properties

Throws:
MCRException

parseURI

public static Document parseURI(URI uri)
                         throws MCRException
Parses an XML file from a URI and returns it as DOM. Use the validation value from mycore.properties.

Parameters:
uri - the URI of the XML file
Returns:
the XML file as a DOM object
Throws:
MCRException - if XML could not be parsed

parseURI

public static Document parseURI(URI uri,
                                boolean valid)
                         throws MCRException
Parses an XML file from a URI and returns it as DOM. Use the given validation flag.

Parameters:
uri - the URI of the XML file
valid - the validation flag
Returns:
the XML file as a DOM object
Throws:
MCRException - if XML could not be parsed

parseXML

public static Document parseXML(String xml)
                         throws MCRException
Parses an XML String and returns it as DOM. Use the validation value from mycore.properties.

Parameters:
xml - the XML String to be parsed
Returns:
the XML file as a DOM object
Throws:
MCRException - if XML could not be parsed

parseXML

public static Document parseXML(String xml,
                                boolean valid)
                         throws MCRException
Parses an XML String and returns it as DOM. Use the given validation flag.

Parameters:
xml - the XML String to be parsed
valid - the validation flag
Returns:
the XML file as a DOM object
Throws:
MCRException - if XML could not be parsed

parseXML

public static Document parseXML(byte[] xml)
                         throws MCRException
Parses an Byte Array and returns it as DOM. Use the validation value from mycore.properties.

Parameters:
xml - the XML Byte Array to be parsed
Returns:
the XML file as a DOM object
Throws:
MCRException - if XML could not be parsed

parseXML

public static Document parseXML(byte[] xml,
                                boolean valid)
                         throws MCRException
Parses an Byte Array and returns it as DOM. Use the given validation flag.

Parameters:
xml - the XML Byte Array to be parsed
valid - the validation flag
Returns:
the XML file as a DOM object
Throws:
MCRException - if XML could not be parsed

removeIllegalChars

public static String removeIllegalChars(String text)
Removes characters that are illegal in XML text nodes or attribute values.

Parameters:
text - the String that should be used in XML elements or attributes
Returns:
the String with all illegal characters removed

deepEqual

public static boolean deepEqual(Document d1,
                                Document d2)
checks whether two documents are equal. This test performs a deep check across all child components of a Document.

Parameters:
d1 - first Document to compare
d2 - second Document to compare
Returns:
true, if d1 and d2 are deep equal
See Also:
Document.equals(java.lang.Object)