org.knime.core.xml
Class XMLProperties

java.lang.Object
  extended by org.knime.core.xml.XMLProperties
All Implemented Interfaces:
ErrorHandler
Direct Known Subclasses:
XMLPropsReader

public class XMLProperties
extends Object
implements ErrorHandler

XML properties class that gets an xml URL and dtd file path as input to initialize the xml org.w3c.dom.Document which can be accessed to get parts of the document tree. The class always throws a DOMException, if the Document does not match the query element/attribute combination. Any error during parsing will throw a SAXParseException. Note, so far this class only returns node elements of type org.w3c.dom.Node#ELEMENT_NODE.

Author:
Thomas Gabriel, University of Konstanz

Constructor Summary
XMLProperties(URL xmlURL, URL dtdURL)
          Initializes a new xml properties object by parsing the xmlURL which internally represents a xml Document.
 
Method Summary
 void error(SAXParseException spe)
          
 void fatalError(SAXParseException spe)
          
 String getAttributeValue(Node elementNode, String attName)
          Returns the attribute value for a xml element and attribute name.
 String getAttributeValue(String elementName, String attName, boolean required)
          Returns the attribute value for a xml element and attribute name.
 Node getNodeElement(String elementName, boolean required)
          Returns a Node from the document which can be associated with the elementName argument which must be of type Node#ELEMENT_NODE.
 void warning(SAXParseException spe)
          
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XMLProperties

public XMLProperties(URL xmlURL,
                     URL dtdURL)
              throws IOException,
                     SAXException,
                     ParserConfigurationException
Initializes a new xml properties object by parsing the xmlURL which internally represents a xml Document.

Parameters:
xmlURL - URL where to find the XML file.
dtdURL - The DTD's URL used to parse the given xml file.
Throws:
IOException - If XML URL not valid.
SAXException - Parser exception caused by the DocumentBuilder.
ParserConfigurationException - Parser configuration exception.
IllegalArgumentException - If xml URL is null.
Method Detail

warning

public void warning(SAXParseException spe)
             throws SAXException

Specified by:
warning in interface ErrorHandler
Throws:
SAXException

error

public void error(SAXParseException spe)
           throws SAXException

Specified by:
error in interface ErrorHandler
Throws:
SAXException

fatalError

public void fatalError(SAXParseException spe)
                throws SAXException

Specified by:
fatalError in interface ErrorHandler
Throws:
SAXException

getNodeElement

public final Node getNodeElement(String elementName,
                                 boolean required)
Returns a Node from the document which can be associated with the elementName argument which must be of type Node#ELEMENT_NODE.

Parameters:
elementName - xml element name to search for.
required - true if node element is required in xml file, otherwise false.
Returns:
Node for element name.
Throws:
DOMException - If element is not in xml file but is required to be.
IllegalArgumentException - If element name is null.

getAttributeValue

public final String getAttributeValue(String elementName,
                                      String attName,
                                      boolean required)
Returns the attribute value for a xml element and attribute name.

Parameters:
elementName - element name to look for specified attribute.
attName - xml attribute name to search for.
required - true if element must be specified in xml file, otherwise false.
Returns:
attribute value at element and for attribute specified if available, otherwise null.
Throws:
DOMException - if element is not in xml file but is required to be.
IllegalArgumentException - if one of the arguments is null.

getAttributeValue

public final String getAttributeValue(Node elementNode,
                                      String attName)
Returns the attribute value for a xml element and attribute name.

Parameters:
elementNode - The element node to look for specified attribute.
attName - The xml attribute name to search for.
Returns:
attribute value at element and for attribute specified if available, otherwise null.
Throws:
IllegalArgumentException - If one of the arguments is null.
DOMException - If element with attribute name is not in xml file.


Copyright, 2003 - 2010. All rights reserved.
University of Konstanz, Germany.
Chair for Bioinformatics and Information Mining, Prof. Dr. Michael R. Berthold.
You may not modify, publish, transmit, transfer or sell, reproduce, create derivative works from, distribute, perform, display, or in any way exploit any of the content, in whole or in part, except as otherwise expressly permitted in writing by the copyright owner or as specified in the license file distributed with this product.