org.knime.core.node.config
Class XMLContentHandler

java.lang.Object
  extended by org.xml.sax.helpers.DefaultHandler
      extended by org.knime.core.node.config.XMLContentHandler
All Implemented Interfaces:
ContentHandler, DTDHandler, EntityResolver, ErrorHandler

 class XMLContentHandler
extends DefaultHandler

Utility class to handle SAX events while parsing the xml file.

Author:
wiswedel, University of Konstanz

Constructor Summary
XMLContentHandler(Config config, String fileName)
          Creates new instance.
 
Method Summary
(package private) static void asXML(Config c, ContentHandler handler)
          Utility method that writes the given config object to a content handler.
 void characters(char[] ch, int start, int length)
          
 void endElement(String uri, String localName, String qName)
          
 void error(SAXParseException e)
          
(package private) static String escape(String s)
          Escapes all forbidden XML characters so that we can save them nevertheless.
 void fatalError(SAXParseException e)
          
 InputSource resolveEntity(String publicId, String systemId)
          
 void startElement(String uri, String localName, String qName, Attributes attributes)
          
(package private) static String unescape(String s)
          Unescapes all forbidden XML characters that were previous escaped by escape(String).
 void warning(SAXParseException e)
          
 
Methods inherited from class org.xml.sax.helpers.DefaultHandler
endDocument, endPrefixMapping, ignorableWhitespace, notationDecl, processingInstruction, setDocumentLocator, skippedEntity, startDocument, startPrefixMapping, unparsedEntityDecl
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XMLContentHandler

XMLContentHandler(Config config,
                  String fileName)
Creates new instance.

Parameters:
config - The config object as root of the xml tree, this class adds sub-entrys to this root node.
fileName - The file name for eventual error messages.
Method Detail

characters

public void characters(char[] ch,
                       int start,
                       int length)
                throws SAXException

Specified by:
characters in interface ContentHandler
Overrides:
characters in class DefaultHandler
Throws:
SAXException

endElement

public void endElement(String uri,
                       String localName,
                       String qName)
                throws SAXException

Specified by:
endElement in interface ContentHandler
Overrides:
endElement in class DefaultHandler
Throws:
SAXException

error

public void error(SAXParseException e)
           throws SAXException

Specified by:
error in interface ErrorHandler
Overrides:
error in class DefaultHandler
Throws:
SAXException

warning

public void warning(SAXParseException e)
             throws SAXException

Specified by:
warning in interface ErrorHandler
Overrides:
warning in class DefaultHandler
Throws:
SAXException

fatalError

public void fatalError(SAXParseException e)
                throws SAXException

Specified by:
fatalError in interface ErrorHandler
Overrides:
fatalError in class DefaultHandler
Throws:
SAXException

startElement

public void startElement(String uri,
                         String localName,
                         String qName,
                         Attributes attributes)
                  throws SAXException

Specified by:
startElement in interface ContentHandler
Overrides:
startElement in class DefaultHandler
Throws:
SAXException

resolveEntity

public InputSource resolveEntity(String publicId,
                                 String systemId)
                          throws IOException,
                                 SAXException

Specified by:
resolveEntity in interface EntityResolver
Overrides:
resolveEntity in class DefaultHandler
Throws:
IOException
SAXException

asXML

static void asXML(Config c,
                  ContentHandler handler)
           throws SAXException
Utility method that writes the given config object to a content handler. The content handler will take care to write to a file.

Parameters:
c - The config to write, must not be null.
handler - To write to.
Throws:
SAXException - If that fails.

escape

static final String escape(String s)
Escapes all forbidden XML characters so that we can save them nevertheless. They are escaped as "%%ddddd", with ddddd being their decimal Unicode.

Parameters:
s - the string to escape
Returns:
the escaped string

unescape

static final String unescape(String s)
Unescapes all forbidden XML characters that were previous escaped by escape(String). Must pay attention to handle not escaped strings for backward compatibility (it will not correctly handle them, they still are unescaped, but it must not fail on those strings).

Parameters:
s - the escaped string
Returns:
the unescaped string


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.