Class SaxHandlerImpl

java.lang.Object
org.xml.sax.helpers.DefaultHandler
org.episteme.natural.chemistry.loaders.cml.cmlimpl.SaxHandlerImpl
All Implemented Interfaces:
SaxHandler, ContentHandler, DTDHandler, EntityResolver, ErrorHandler

public class SaxHandlerImpl extends DefaultHandler implements SaxHandler
manages callbacks from SAX2 handler
Since:
1.0
Author:
Silvere Martin-Michiellot, Gemini AI (Google DeepMind)
  • Constructor Details

    • SaxHandlerImpl

      public SaxHandlerImpl(AbstractCMLDocument d, boolean debug)
      Creates a new SaxHandlerImpl object.
      Parameters:
      d - the document to populate
      debug - true to enable debugging output
  • Method Details

    • setIgnoreWhite

      public void setIgnoreWhite(boolean ignoreWhite)
      Sets whether to ignore ignorable whitespace during parsing.
      Specified by:
      setIgnoreWhite in interface SaxHandler
      Parameters:
      ignoreWhite - true to ignore whitespace, false otherwise
    • hasErrors

      public boolean hasErrors()
      Returns true if any errors were encountered during parsing.
      Specified by:
      hasErrors in interface SaxHandler
      Returns:
      true if errors occurred, false otherwise
    • getErrorVector

      public Vector<String> getErrorVector()
      Returns a vector of error messages encountered during parsing.
      Specified by:
      getErrorVector in interface SaxHandler
      Returns:
      a vector of error strings
    • setDebug

      public void setDebug(boolean debug)
      Enables or disables debugging output.
      Parameters:
      debug - true to enable, false to disable
    • getDebug

      public boolean getDebug()
      Returns the current debug status.
      Specified by:
      getDebug in interface SaxHandler
      Returns:
      true if debug is on
    • publish

      public void publish(LogRecord record)
      Publishes a log record. Currently commented out but originally intended to print level and message.
      Parameters:
      record - the log record to publish
    • flush

      public void flush()
      Flushes any buffered output.
    • close

      public void close()
      Closes the handler and releases all resources.
    • debug

      protected void debug(String s)
      Outputs a debug message if debugging is enabled.
      Parameters:
      s - the debug message
    • characters

      public void characters(char[] ch, int start, int length)
      SAX callback for character data.
      Specified by:
      characters in interface ContentHandler
      Overrides:
      characters in class DefaultHandler
      Parameters:
      ch - the character array
      start - the start position
      length - the number of characters
    • endDocument

      public void endDocument()
      SAX callback for the end of the document.
      Specified by:
      endDocument in interface ContentHandler
      Overrides:
      endDocument in class DefaultHandler
    • endElement

      public void endElement(String uri, String localName, String qName)
      SAX callback for the end of an element.
      Specified by:
      endElement in interface ContentHandler
      Overrides:
      endElement in class DefaultHandler
      Parameters:
      uri - the namespace URI
      localName - the local name
      qName - the qualified name
    • error

      public void error(SAXParseException e)
      SAX callback for recoverable parse errors.
      Specified by:
      error in interface ErrorHandler
      Overrides:
      error in class DefaultHandler
      Parameters:
      e - the SAX parse exception
    • fatalError

      public void fatalError(SAXParseException e)
      SAX callback for fatal parse errors.
      Specified by:
      fatalError in interface ErrorHandler
      Overrides:
      fatalError in class DefaultHandler
      Parameters:
      e - the fatal SAX parse exception
    • ignorableWhitespace

      public void ignorableWhitespace(char[] ch, int start, int length)
      SAX callback for ignorable whitespace.
      Specified by:
      ignorableWhitespace in interface ContentHandler
      Overrides:
      ignorableWhitespace in class DefaultHandler
      Parameters:
      ch - the character array
      start - the start position
      length - the number of characters
    • processingInstruction

      public void processingInstruction(String target, String data)
      SAX callback for processing instructions.
      Specified by:
      processingInstruction in interface ContentHandler
      Overrides:
      processingInstruction in class DefaultHandler
      Parameters:
      target - the target string
      data - the data string
    • startDocument

      public void startDocument()
      SAX callback for the start of the document.
      Specified by:
      startDocument in interface ContentHandler
      Overrides:
      startDocument in class DefaultHandler
    • startElement

      public void startElement(String uri, String localName, String qName, Attributes attributes)
      SAX callback for the start of an element.
      Specified by:
      startElement in interface ContentHandler
      Overrides:
      startElement in class DefaultHandler
      Parameters:
      uri - the namespace URI
      localName - the local name
      qName - the qualified name
      attributes - the element attributes
    • startPrefixMapping

      public void startPrefixMapping(String prefix, String uri)
      SAX callback for the start of a prefix mapping.
      Specified by:
      startPrefixMapping in interface ContentHandler
      Overrides:
      startPrefixMapping in class DefaultHandler
      Parameters:
      prefix - the namespace prefix
      uri - the namespace URI
    • unparsedEntityDecl

      public void unparsedEntityDecl(String name, String publicId, String systemId, String notationName)
      SAX callback for unparsed entity declarations.
      Specified by:
      unparsedEntityDecl in interface DTDHandler
      Overrides:
      unparsedEntityDecl in class DefaultHandler
      Parameters:
      name - the entity name
      publicId - the public identifier
      systemId - the system identifier
      notationName - the name of the notation
    • warning

      public void warning(SAXParseException e)
      SAX callback for parse warnings.
      Specified by:
      warning in interface ErrorHandler
      Overrides:
      warning in class DefaultHandler
      Parameters:
      e - the SAX parse warning
    • main

      public static void main(String[] args) throws Exception
      Test main method for parsing experiments.
      Parameters:
      args - command line arguments
      Throws:
      Exception - if a test error occurs