Class MSTRLayoutParser.ParserContentHandler

  • All Implemented Interfaces:
    org.xml.sax.ContentHandler, org.xml.sax.DTDHandler, org.xml.sax.EntityResolver, org.xml.sax.ErrorHandler
    Enclosing class:
    MSTRLayoutParser

    protected static class MSTRLayoutParser.ParserContentHandler
    extends AbstractHandler
    This is the default implementation of the ContentHandler to use parse the layout XML.
    Since:
    MicroStrategy Web 8.0.0
    • Constructor Detail

      • ParserContentHandler

        public ParserContentHandler​(java.lang.String layoutLocation)
        The constructor for this class. It stores away the layout location so that it can a) use it for error and warning messages and b) store it in the generated LayoutTag object.
      • ParserContentHandler

        public ParserContentHandler​(java.lang.String layoutLocation,
                                    LayoutSource layoutSource,
                                    LayoutParser layoutParser)
        The constructor for this class. It stores away the layout location so that it can a) use it for error and warning messages and b) store it in the generated LayoutTag object. It also stores the layoutSource and layoutParser information so the include tag can use them to load the external layout files.
        Since:
        MicroStrategy Web 8.0.2
    • Method Detail

      • getLayoutTag

        public LayoutTag getLayoutTag()
        The generated LayoutTag object constructed during parsing.
        Returns:
        The LayoutTag object.
      • validationError

        public void validationError()
        Increments the number of validation errors encountered in this parsing.
      • generateErrorMessage

        public java.lang.String generateErrorMessage​(java.lang.String msg)
        Generate a standard error message which includes the layout location (the source of the layout), the line number and the innermost enclosing element.
        Parameters:
        msg - The message to include in the standard message.
        Returns:
        A formatted string containing context information.
      • setDocumentLocator

        public void setDocumentLocator​(org.xml.sax.Locator locator)
        ContentHandler method that records the current Locator for this document. It is used by the generateErrorMessage(java.lang.String) method to include line numbers.
        Specified by:
        setDocumentLocator in interface org.xml.sax.ContentHandler
        Overrides:
        setDocumentLocator in class org.xml.sax.helpers.DefaultHandler
      • startDocument

        public void startDocument()
                           throws org.xml.sax.SAXException
        ContentHandler method that records the start of the XML document. This implementation calls the initParserDataStructures() method to initialize any data structures.
        Specified by:
        startDocument in interface org.xml.sax.ContentHandler
        Overrides:
        startDocument in class org.xml.sax.helpers.DefaultHandler
        Throws:
        org.xml.sax.SAXException
      • doStartElement

        public void doStartElement​(java.lang.String namespaceURI,
                                   java.lang.String localName,
                                   java.lang.String qName,
                                   org.xml.sax.Attributes atts)
                            throws org.xml.sax.SAXException
        AbstracHandler method to process the start of an element. If this is the root element, the version number is checked and if successful, the LayoutTag is recorded. Otherwise, a new generic tag is created (based on the localName of the element). Any attributes associated with the tag are added to the Tag object. The line number of the tag is recorded also in the Tag and the current Tag is pushed on the stack (making it the new "current" tag.
        Overrides:
        doStartElement in class AbstractHandler
        Throws:
        org.xml.sax.SAXException - Any SAX exception, possibly wrapping another exception
      • characters

        public void characters​(char[] ch,
                               int start,
                               int length)
                        throws org.xml.sax.SAXException
        ContentHandler method to indicate that text content has been identified. This implementation adds it to the current tag (via Tag.addTextChild(java.lang.String).
        Specified by:
        characters in interface org.xml.sax.ContentHandler
        Overrides:
        characters in class AbstractHandler
        Parameters:
        ch - The characters.
        start - The start position in the character array.
        length - The number of characters to use from the character array.
        Throws:
        org.xml.sax.SAXException - Any SAX exception, possibly wrapping another exception.
        See Also:
        ContentHandler.characters(char[], int, int)
      • doEndElement

        public void doEndElement​(java.lang.String namespaceURI,
                                 java.lang.String localName,
                                 java.lang.String qName)
                          throws org.xml.sax.SAXException
        AbstractHandler method that identifies the closing of a tag. The current implementation pops the current tag off the stack.
        Specified by:
        doEndElement in class AbstractHandler
        Throws:
        org.xml.sax.SAXException - Any SAX exception, possibly wrapping another exception
      • endDocument

        public void endDocument()
                         throws org.xml.sax.SAXException
        ContentHandler method to indicate the end of the document. This implementation checks that there are no tags still open. If there were validation errors, then a SAXException is raised. Regardless of whether either of these occur, a call is made to release all parser data structures (releaseParserDataStructures()).
        Specified by:
        endDocument in interface org.xml.sax.ContentHandler
        Overrides:
        endDocument in class AbstractHandler
        Throws:
        org.xml.sax.SAXException - Any SAX exception, possibly wrapping another exception.
        See Also:
        ContentHandler.endDocument()
      • isVersionValid

        protected boolean isVersionValid​(java.lang.String version)
        This checks whether the supplied version is valid for this parser implementation.
        Parameters:
        version - The version strinig on the layout tag.
        Returns:
        True if the parser should continue.
      • initParserDataStructures

        protected void initParserDataStructures()
        Initialize any parser specific data structures.
      • releaseParserDataStructures

        protected void releaseParserDataStructures()
        Release any parser specific data structures.
      • generateInternalError

        protected java.lang.String generateInternalError​(java.lang.String msg)
        Generate an error message to reflect an internal parser error.
        Parameters:
        msg - The message to send.
        Returns:
        An appropriately formatted internal error message.
      • generateErrorMessagePrefix

        protected java.lang.StringBuffer generateErrorMessagePrefix()
        Generate the prefix of a diagnostic message. The current message begins with context information such as the layout location (if present), line number information, and current enclosing tag.
        Returns:
        error message prefix.