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 voidcharacters(char[] ch, int start, int length)ContentHandler method to indicate that text content has been identified.voiddoEndElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qName)AbstractHandler method that identifies the closing of a tag.voiddoStartElement(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.voidendDocument()ContentHandler method to indicate the end of the document.java.lang.StringgenerateErrorMessage(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.StringBuffergenerateErrorMessagePrefix()Generate the prefix of a diagnostic message.protected java.lang.StringgenerateInternalError(java.lang.String msg)Generate an error message to reflect an internal parser error.LayoutTaggetLayoutTag()The generatedLayoutTagobject constructed during parsing.LayoutParser.MessageListenergetMessageListener()Returns theLayoutParser.MessageListenerobject used by this parser instance.protected voidinitParserDataStructures()Initialize any parser specific data structures.protected booleanisVersionValid(java.lang.String version)This checks whether the supplied version is valid for this parser implementation.protected voidreleaseParserDataStructures()Release any parser specific data structures.protected voidsendErrorMsg(java.lang.String msg)Send a message to theLayoutParser.MessageListenerobject'sLayoutParser.MessageListener.error(java.lang.String)method.voidsetDocumentLocator(org.xml.sax.Locator locator)ContentHandler method that records the current Locator for this document.voidsetMessageListener(LayoutParser.MessageListener msgListener)Set theLayoutParser.MessageListenerobject to use with this parser instance.voidstartDocument()ContentHandler method that records the start of the XML document.voidvalidationError()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 generatedLayoutTagobject.
-
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 generatedLayoutTagobject. 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.MessageListenerobject used by this parser instance.- Returns:
- msgListener The
LayoutParser.MessageListenerobject.
-
setMessageListener
public void setMessageListener(LayoutParser.MessageListener msgListener)
Set theLayoutParser.MessageListenerobject to use with this parser instance.- Parameters:
msgListener- TheLayoutParser.MessageListenerobject.
-
getLayoutTag
public LayoutTag getLayoutTag()
The generatedLayoutTagobject constructed during parsing.- Returns:
- The
LayoutTagobject.
-
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:
setDocumentLocatorin interfaceorg.xml.sax.ContentHandler- Overrides:
setDocumentLocatorin classorg.xml.sax.helpers.DefaultHandler
-
startDocument
public void startDocument() throws org.xml.sax.SAXExceptionContentHandler method that records the start of the XML document. This implementation calls theinitParserDataStructures()method to initialize any data structures.- Specified by:
startDocumentin interfaceorg.xml.sax.ContentHandler- Overrides:
startDocumentin 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.SAXExceptionAbstracHandler method to process the start of an element. If this is the root element, the version number is checked and if successful, theLayoutTagis recorded. Otherwise, a new generic tag is created (based on thelocalNameof the element). Any attributes associated with the tag are added to theTagobject. The line number of the tag is recorded also in theTagand the currentTagis pushed on the stack (making it the new "current" tag.- Overrides:
doStartElementin 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.SAXExceptionContentHandler method to indicate that text content has been identified. This implementation adds it to the current tag (viaTag.addTextChild(java.lang.String).- Specified by:
charactersin interfaceorg.xml.sax.ContentHandler- Overrides:
charactersin 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.SAXExceptionAbstractHandler method that identifies the closing of a tag. The current implementation pops the current tag off the stack.- Specified by:
doEndElementin classAbstractHandler- Throws:
org.xml.sax.SAXException- Any SAX exception, possibly wrapping another exception
-
endDocument
public void endDocument() throws org.xml.sax.SAXExceptionContentHandler 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:
endDocumentin interfaceorg.xml.sax.ContentHandler- Overrides:
endDocumentin 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.MessageListenerobject'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.
-
-