Class DefaultContentHandler

  • All Implemented Interfaces:
    org.xml.sax.ContentHandler, org.xml.sax.DTDHandler, org.xml.sax.EntityResolver, org.xml.sax.ErrorHandler
    Direct Known Subclasses:
    JavaScriptBundles.JavaScriptBundlesContentHandler

    public abstract class DefaultContentHandler
    extends org.xml.sax.helpers.DefaultHandler
    This class is used as a default base class for an XML ContentHandler. It provides the following features on top of DefaultHandler:
    • It manages the Locator object (capturing it in the setDocumentLocator(Locator) method). It exposes a getCurrentLineNumber() method to return this information.
    • It can format error messages to include file name and line number information. See generateErrorMessage(String).
    • Allows the subclass to report both validation and internal errors. The validationError(String) method is used to report an error condition that indicates invalid XML. The supplied message is formatted, the validation error count is incremented and the resulting message is sent to the supplied MessageRouter.
    • Validation errors are not immediately fatal--XML parsing continues, though upon completion the overall parse fails. In contrast, a call to internalError(String) formats an error message and packages it into a thrown SAXException. Parsing terminates at the point of an internal error.
    Since:
    MicroStrategy Web 8.1.0
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void characters​(char[] ch, int start, int length)
      Callback to indicate that characters have been found.
      protected void clearChars()
      Resets the characters collected.
      void endDocument()
      What to do when the end of document is encountered.
      void endElement​(java.lang.String uri, java.lang.String localName, java.lang.String qName)
      Callback to indicate the end of an XML element.
      java.lang.String generateErrorMessage​(java.lang.String message)
      Formats an error message supplied by the user.
      protected java.lang.String getCharacters()
      Returns the last text area that was encountered.
      protected int getCurrentLineNumber()
      Returns the current line number (if we can determine it) or -1.
      void ignorableWhitespace​(char[] ch, int start, int length)
      Callback when ignorable whitespace has been encountered in an XML document.
      void incrementValidationErrorCount()
      Increment the number of validation errors.
      protected void internalError​(java.lang.String message)
      Throws an internal SAXException error formatted with the supplied error message.
      void resetData()
      Resets all data structures used in the previous parse operation.
      void setDocumentLocator​(org.xml.sax.Locator locator)
      Callback method to record the document locator.
      void setMessageRouter​(MessageRouter messageRouter)
      Specifies the Message Router to use for this parse operation.
      void setSourceLocation​(java.lang.String sourceLocation)
      Specifies the location of the source text being parsed.
      void setXMLReader​(org.xml.sax.XMLReader xmlReader)
      Sets the XML Reader which is being used to parse the XML text.
      void startElement​(java.lang.String uri, java.lang.String localName, java.lang.String qName, org.xml.sax.Attributes attributes)
      Callback invoked when a new element is encountered.
      protected void validationError​(java.lang.String message)
      Reports a validation error.
      • Methods inherited from class org.xml.sax.helpers.DefaultHandler

        endPrefixMapping, error, fatalError, notationDecl, processingInstruction, resolveEntity, skippedEntity, startDocument, startPrefixMapping, unparsedEntityDecl, warning
      • Methods inherited from class java.lang.Object

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

      • locator

        protected org.xml.sax.Locator locator
      • sourceLocation

        protected java.lang.String sourceLocation
      • validationErrorCount

        protected int validationErrorCount
      • xmlReader

        protected org.xml.sax.XMLReader xmlReader
        Since:
        MicroStrategy Web 9.0.0
    • Constructor Detail

      • DefaultContentHandler

        public DefaultContentHandler​(java.lang.String sourceLocation,
                                     MessageRouter msgRouter)
        Default constructor which takes a "location" string (may be null) and a MessageRouter object.
        Parameters:
        sourceLocation - The location of the source being parsed.
        msgRouter - The MessageRouter object to use for reporting errors, warnings.
    • Method Detail

      • generateErrorMessage

        public java.lang.String generateErrorMessage​(java.lang.String message)
        Formats an error message supplied by the user. The error message includes file name and line number information.
        Parameters:
        message - The underlying message to display
        Returns:
        A String containing the full, displayable error message.
      • setSourceLocation

        public void setSourceLocation​(java.lang.String sourceLocation)
        Specifies the location of the source text being parsed.
        Parameters:
        sourceLocation - The source location of the text being parsed.
        Since:
        MicroStrategy Web 9.0.0
      • setMessageRouter

        public void setMessageRouter​(MessageRouter messageRouter)
        Specifies the Message Router to use for this parse operation.
        Parameters:
        messageRouter - The Message Router to use for this parse operation.
        Since:
        MicroStrategy Web 9.0.0
      • setXMLReader

        public void setXMLReader​(org.xml.sax.XMLReader xmlReader)
        Sets the XML Reader which is being used to parse the XML text.
        Parameters:
        xmlReader - The XML Reader which is being used to parse the XML text.
        Since:
        MicroStrategy Web 9.0.0
      • resetData

        public void resetData()
        Resets all data structures used in the previous parse operation. This enables the same instance to be used repeatedly for different XML parse operations. After invoking the caller should call the setMessageRouter(MessageRouter) and setSourceLocation(String) methods to establish the new context.
        Since:
        MicroStrategy Web 9.0.0
      • incrementValidationErrorCount

        public void incrementValidationErrorCount()
        Increment the number of validation errors. This is only to be used by the ErrorHandler object (which reports DTD validation errors).
      • setDocumentLocator

        public void setDocumentLocator​(org.xml.sax.Locator locator)
        Callback method to record the document locator.
        Specified by:
        setDocumentLocator in interface org.xml.sax.ContentHandler
        Overrides:
        setDocumentLocator in class org.xml.sax.helpers.DefaultHandler
        Parameters:
        locator - The Locator object created by the XML Reader.
      • startElement

        public void startElement​(java.lang.String uri,
                                 java.lang.String localName,
                                 java.lang.String qName,
                                 org.xml.sax.Attributes attributes)
                          throws org.xml.sax.SAXException
        Callback invoked when a new element is encountered.
        Specified by:
        startElement in interface org.xml.sax.ContentHandler
        Overrides:
        startElement in class org.xml.sax.helpers.DefaultHandler
        Parameters:
        uri - The URI of the element.
        localName - The local name of the element.
        qName - The qualified name of the element.
        attributes - The attributes associated with the element.
        Throws:
        org.xml.sax.SAXException - If an unexpected element appears in the configuration file.
      • characters

        public void characters​(char[] ch,
                               int start,
                               int length)
                        throws org.xml.sax.SAXException
        Callback to indicate that characters have been found.
        Specified by:
        characters in interface org.xml.sax.ContentHandler
        Overrides:
        characters in class org.xml.sax.helpers.DefaultHandler
        Parameters:
        ch - The character array.
        start - The starting index of the character encountered.
        length - The number of characters seen in this particular callback.
        Throws:
        org.xml.sax.SAXException - If the characters encountered were unexpected or some other internal error.
      • ignorableWhitespace

        public void ignorableWhitespace​(char[] ch,
                                        int start,
                                        int length)
                                 throws org.xml.sax.SAXException
        Callback when ignorable whitespace has been encountered in an XML document.
        Specified by:
        ignorableWhitespace in interface org.xml.sax.ContentHandler
        Overrides:
        ignorableWhitespace in class org.xml.sax.helpers.DefaultHandler
        Parameters:
        ch - The character array.
        start - The starting index of the character encountered.
        length - The number of characters seen in this particular callback.
        Throws:
        org.xml.sax.SAXException - If the characters encountered were unexpected or some other internal error.
      • endElement

        public void endElement​(java.lang.String uri,
                               java.lang.String localName,
                               java.lang.String qName)
                        throws org.xml.sax.SAXException
        Callback to indicate the end of an XML element.
        Specified by:
        endElement in interface org.xml.sax.ContentHandler
        Overrides:
        endElement in class org.xml.sax.helpers.DefaultHandler
        Parameters:
        uri - The URI of the element.
        localName - The local name of the element.
        qName - The qualified name of the element.
        Throws:
        org.xml.sax.SAXException - If an unexpected element was encountered.
      • endDocument

        public void endDocument()
                         throws org.xml.sax.SAXException
        What to do when the end of document is encountered. By default, it will check whether any validation errors have occurred. If so, it throws an exception.
        Specified by:
        endDocument in interface org.xml.sax.ContentHandler
        Overrides:
        endDocument in class org.xml.sax.helpers.DefaultHandler
        Throws:
        org.xml.sax.SAXException - If validation errors have occurred.
      • getCharacters

        protected java.lang.String getCharacters()
        Returns the last text area that was encountered. This includes all characters encountered between the most previous startElement and invocation of endElement.
        Returns:
        The String representation of last text (character) area encountered.
      • clearChars

        protected void clearChars()
        Resets the characters collected. This is normally done when a new element is started.
        Since:
        MicroStrategy Web 9.0.0
      • getCurrentLineNumber

        protected int getCurrentLineNumber()
        Returns the current line number (if we can determine it) or -1.
        Returns:
        The current line number that we are at in the input stream.
      • validationError

        protected void validationError​(java.lang.String message)
        Reports a validation error. The supplied string is formatted and logged (as an error) with the associated MessageRouter.
        Parameters:
        message - The validation error message (used in a call to generateErrorMessage(String)).
      • internalError

        protected void internalError​(java.lang.String message)
                              throws org.xml.sax.SAXException
        Throws an internal SAXException error formatted with the supplied error message.
        Parameters:
        message - The message that contains the internal error.
        Throws:
        org.xml.sax.SAXException - This is used to get out of the current SAX parsing call.