Package com.microstrategy.web.transform
Class MSTRLayoutParser.ParserContentHandler
- java.lang.Object
-
- org.xml.sax.helpers.DefaultHandler
-
- com.microstrategy.utils.xml.AbstractHandler
-
- com.microstrategy.web.transform.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
-
-
Field Summary
-
Fields inherited from class com.microstrategy.utils.xml.AbstractHandler
buf, depth, parser
-
-
Constructor Summary
Constructors Constructor Description ParserContentHandler(java.lang.String layoutLocation)
The constructor for this class.ParserContentHandler(java.lang.String layoutLocation, LayoutSource layoutSource, LayoutParser layoutParser)
The constructor for this class.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
characters(char[] ch, int start, int length)
ContentHandler method to indicate that text content has been identified.void
doEndElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qName)
AbstractHandler method that identifies the closing of a tag.void
doStartElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qName, org.xml.sax.Attributes atts)
AbstracHandler method to process the start of an element.void
endDocument()
ContentHandler method to indicate the end of the document.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.protected java.lang.StringBuffer
generateErrorMessagePrefix()
Generate the prefix of a diagnostic message.protected java.lang.String
generateInternalError(java.lang.String msg)
Generate an error message to reflect an internal parser error.LayoutTag
getLayoutTag()
The generatedLayoutTag
object constructed during parsing.LayoutParser.MessageListener
getMessageListener()
Returns theLayoutParser.MessageListener
object used by this parser instance.protected void
initParserDataStructures()
Initialize any parser specific data structures.protected boolean
isVersionValid(java.lang.String version)
This checks whether the supplied version is valid for this parser implementation.protected void
releaseParserDataStructures()
Release any parser specific data structures.protected void
sendErrorMsg(java.lang.String msg)
Send a message to theLayoutParser.MessageListener
object'sLayoutParser.MessageListener.error(java.lang.String)
method.void
setDocumentLocator(org.xml.sax.Locator locator)
ContentHandler method that records the current Locator for this document.void
setMessageListener(LayoutParser.MessageListener msgListener)
Set theLayoutParser.MessageListener
object to use with this parser instance.void
startDocument()
ContentHandler method that records the start of the XML document.void
validationError()
Increments the number of validation errors encountered in this parsing.-
Methods inherited from class com.microstrategy.utils.xml.AbstractHandler
clearText, doStartElement, endElement, getFloatValue, getIntValue, getText, popContentHandler, setLogErrors, startElement
-
-
-
-
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 generatedLayoutTag
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 generatedLayoutTag
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
-
getMessageListener
public LayoutParser.MessageListener getMessageListener()
Returns theLayoutParser.MessageListener
object used by this parser instance.- Returns:
- msgListener The
LayoutParser.MessageListener
object.
-
setMessageListener
public void setMessageListener(LayoutParser.MessageListener msgListener)
Set theLayoutParser.MessageListener
object to use with this parser instance.- Parameters:
msgListener
- TheLayoutParser.MessageListener
object.
-
getLayoutTag
public LayoutTag getLayoutTag()
The generatedLayoutTag
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 thegenerateErrorMessage(java.lang.String)
method to include line numbers.- Specified by:
setDocumentLocator
in interfaceorg.xml.sax.ContentHandler
- Overrides:
setDocumentLocator
in classorg.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 theinitParserDataStructures()
method to initialize any data structures.- Specified by:
startDocument
in interfaceorg.xml.sax.ContentHandler
- Overrides:
startDocument
in classorg.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, theLayoutTag
is recorded. Otherwise, a new generic tag is created (based on thelocalName
of the element). Any attributes associated with the tag are added to theTag
object. The line number of the tag is recorded also in theTag
and the currentTag
is pushed on the stack (making it the new "current" tag.- Overrides:
doStartElement
in classAbstractHandler
- 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 (viaTag.addTextChild(java.lang.String)
.- Specified by:
characters
in interfaceorg.xml.sax.ContentHandler
- Overrides:
characters
in classAbstractHandler
- 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 classAbstractHandler
- 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 interfaceorg.xml.sax.ContentHandler
- Overrides:
endDocument
in classAbstractHandler
- 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.
-
sendErrorMsg
protected void sendErrorMsg(java.lang.String msg)
Send a message to theLayoutParser.MessageListener
object'sLayoutParser.MessageListener.error(java.lang.String)
method.- Parameters:
msg
- The message to send.
-
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.
-
-