Package diva.util.xml

Class XmlReader.Handler

  • All Implemented Interfaces:
    XmlHandler
    Enclosing class:
    XmlReader

    public class XmlReader.Handler
    extends java.lang.Object
    implements XmlHandler
    Handler is an inner class that implements the Aelfred XmlHandler interface. It constructs XmlElements and also initializes the current XmlDocument from things like the doctype declaration. In verbose mode, it prints out lots of additional info during the parse.
    • Constructor Summary

      Constructors 
      Constructor Description
      Handler()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected java.lang.String _currentExternalEntity()
      Return the current external entity.
      void attribute​(java.lang.String name, java.lang.String value, boolean specified)
      Handle an attribute assignment that is part of an XML element.
      void charData​(char[] c, int offset, int length)
      Append the given character bytes to the character data of the current XML element.
      void doctypeDecl​(java.lang.String name, java.lang.String publicId, java.lang.String systemId)
      Handle a document type declaration.
      void endDocument()
      End the document.
      void endElement​(java.lang.String name)
      Move up one level in the parse tree.
      void endExternalEntity​(java.lang.String URI)
      Move up one level in the external entity tree.
      void error​(java.lang.String message, java.lang.String sysid, int line, int column)
      Print an error message to the error stream.
      void ignorableWhitespace​(char[] ch, int start, int length)
      Handle ignorable whitespace.
      void processingInstruction​(java.lang.String target, java.lang.String data)
      Handle a processing instruction.
      java.lang.Object resolveEntity​(java.lang.String pubID, java.lang.String sysID)
      Attempt resolve the public ID representing an XML external entity into a valid string url.
      void startDocument()
      Start a document.
      void startElement​(java.lang.String name)
      Start an element.
      void startExternalEntity​(java.lang.String URI)
      Move down one level in the entity tree.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Handler

        public Handler()
    • Method Detail

      • charData

        public void charData​(char[] c,
                             int offset,
                             int length)
                      throws java.lang.Exception
        Append the given character bytes to the character data of the current XML element.
        Specified by:
        charData in interface XmlHandler
        Parameters:
        c - The character data.
        offset - The starting position in the array.
        length - The number of characters available.
        Throws:
        java.lang.Exception - The handler may throw any exception.
      • doctypeDecl

        public void doctypeDecl​(java.lang.String name,
                                java.lang.String publicId,
                                java.lang.String systemId)
                         throws java.lang.Exception
        Handle a document type declaration. This sets the DTD external identifiers in the XmlDocument.
        Specified by:
        doctypeDecl in interface XmlHandler
        Parameters:
        name - The document type name.
        publicId - The public identifier, or null if unspecified.
        systemId - The system identifier, or null if unspecified.
        Throws:
        java.lang.Exception - The handler may throw any exception.
      • endDocument

        public void endDocument()
                         throws java.lang.Exception
        End the document. If we've finished the parse and didn't get back to the root of the parse tree, generate an error.
        Specified by:
        endDocument in interface XmlHandler
        Throws:
        java.lang.Exception - The handler may throw any exception.
        See Also:
        XmlHandler.startDocument()
      • error

        public void error​(java.lang.String message,
                          java.lang.String sysid,
                          int line,
                          int column)
                   throws java.lang.Exception
        Print an error message to the error stream.
        Specified by:
        error in interface XmlHandler
        Parameters:
        message - The error message.
        sysid - The system identifier of the entity that contains the error.
        line - The approximate line number of the error.
        column - The approximate column number of the error.
        Throws:
        java.lang.Exception - The handler may throw any exception.
        See Also:
        XmlException
      • ignorableWhitespace

        public void ignorableWhitespace​(char[] ch,
                                        int start,
                                        int length)
                                 throws java.lang.Exception
        Handle ignorable whitespace.

        The default implementation does nothing.

        Specified by:
        ignorableWhitespace in interface XmlHandler
        Parameters:
        ch - The literal whitespace characters.
        start - The starting position in the array.
        length - The number of whitespace characters available.
        Throws:
        java.lang.Exception - Derived methods may throw exceptions.
        See Also:
        XmlHandler.ignorableWhitespace(char[], int, int)
      • processingInstruction

        public void processingInstruction​(java.lang.String target,
                                          java.lang.String data)
                                   throws java.lang.Exception
        Handle a processing instruction.

        The default implementation does nothing.

        Specified by:
        processingInstruction in interface XmlHandler
        Parameters:
        target - The target (the name at the start of the PI).
        data - The data, if any (the rest of the PI).
        Throws:
        java.lang.Exception - Derived methods may throw exceptions.
        See Also:
        XmlHandler.processingInstruction(java.lang.String, java.lang.String)
      • resolveEntity

        public java.lang.Object resolveEntity​(java.lang.String pubID,
                                              java.lang.String sysID)
                                       throws java.lang.Exception
        Attempt resolve the public ID representing an XML external entity into a valid string url. If the public ID is non-null and matches the public ID of the document and the document has a DTD specified, return that DTD in a reader. Otherwise, non-null public DTD's are looked up in the default resource bundle, diva/resource/Defaults.properties.
        Specified by:
        resolveEntity in interface XmlHandler
        Parameters:
        pubID - The public identifier, or null if none was supplied.
        sysID - The system identifier.
        Returns:
        The replacement system identifier, or null to use the default.
        Throws:
        java.lang.Exception - The handler may throw any exception.
        See Also:
        XmlHandler.startExternalEntity(java.lang.String), XmlHandler.endExternalEntity(java.lang.String)
      • startDocument

        public void startDocument()
        Start a document. This method is called just before the parser attempts to read the first entity (the root of the document). It is guaranteed that this will be the first method called. Initialize the parse tree to contain no elements.
        Specified by:
        startDocument in interface XmlHandler
        See Also:
        XmlHandler.endDocument()
      • _currentExternalEntity

        protected java.lang.String _currentExternalEntity()
        Return the current external entity.
        Returns:
        The current external entity.