Package com.microstrategy.utils.xml
Class DefaultContentHandler
- java.lang.Object
 - 
- org.xml.sax.helpers.DefaultHandler
 - 
- com.microstrategy.utils.xml.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.DefaultHandlerThis class is used as a default base class for an XML ContentHandler. It provides the following features on top of DefaultHandler:- 
 It manages the 
Locatorobject (capturing it in thesetDocumentLocator(Locator)method). It exposes agetCurrentLineNumber()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 suppliedMessageRouter. - 
 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 thrownSAXException. Parsing terminates at the point of an internal error. 
- Since:
 - MicroStrategy Web 8.1.0
 
 
- 
- 
Field Summary
Fields Modifier and Type Field Description protected org.xml.sax.Locatorlocatorprotected MessageRoutermessageRouterprotected java.lang.StringsourceLocationprotected intvalidationErrorCountprotected org.xml.sax.XMLReaderxmlReader 
- 
Constructor Summary
Constructors Constructor Description DefaultContentHandler(java.lang.String sourceLocation, MessageRouter msgRouter)Default constructor which takes a "location" string (may be null) and aMessageRouterobject. 
- 
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcharacters(char[] ch, int start, int length)Callback to indicate that characters have been found.protected voidclearChars()Resets the characters collected.voidendDocument()What to do when the end of document is encountered.voidendElement(java.lang.String uri, java.lang.String localName, java.lang.String qName)Callback to indicate the end of an XML element.java.lang.StringgenerateErrorMessage(java.lang.String message)Formats an error message supplied by the user.protected java.lang.StringgetCharacters()Returns the last text area that was encountered.protected intgetCurrentLineNumber()Returns the current line number (if we can determine it) or -1.voidignorableWhitespace(char[] ch, int start, int length)Callback when ignorable whitespace has been encountered in an XML document.voidincrementValidationErrorCount()Increment the number of validation errors.protected voidinternalError(java.lang.String message)Throws an internal SAXException error formatted with the supplied error message.voidresetData()Resets all data structures used in the previous parse operation.voidsetDocumentLocator(org.xml.sax.Locator locator)Callback method to record the document locator.voidsetMessageRouter(MessageRouter messageRouter)Specifies the Message Router to use for this parse operation.voidsetSourceLocation(java.lang.String sourceLocation)Specifies the location of the source text being parsed.voidsetXMLReader(org.xml.sax.XMLReader xmlReader)Sets the XML Reader which is being used to parse the XML text.voidstartElement(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 voidvalidationError(java.lang.String message)Reports a validation error. 
 - 
 
- 
- 
Field Detail
- 
locator
protected org.xml.sax.Locator locator
 
- 
messageRouter
protected MessageRouter messageRouter
 
- 
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 aMessageRouterobject.- Parameters:
 sourceLocation- The location of the source being parsed.msgRouter- TheMessageRouterobject 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 thesetMessageRouter(MessageRouter)andsetSourceLocation(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 theErrorHandlerobject (which reports DTD validation errors). 
- 
setDocumentLocator
public void setDocumentLocator(org.xml.sax.Locator locator)
Callback method to record the document locator.- Specified by:
 setDocumentLocatorin interfaceorg.xml.sax.ContentHandler- Overrides:
 setDocumentLocatorin classorg.xml.sax.helpers.DefaultHandler- Parameters:
 locator- TheLocatorobject 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.SAXExceptionCallback invoked when a new element is encountered.- Specified by:
 startElementin interfaceorg.xml.sax.ContentHandler- Overrides:
 startElementin classorg.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.SAXExceptionCallback to indicate that characters have been found.- Specified by:
 charactersin interfaceorg.xml.sax.ContentHandler- Overrides:
 charactersin classorg.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.SAXExceptionCallback when ignorable whitespace has been encountered in an XML document.- Specified by:
 ignorableWhitespacein interfaceorg.xml.sax.ContentHandler- Overrides:
 ignorableWhitespacein classorg.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.SAXExceptionCallback to indicate the end of an XML element.- Specified by:
 endElementin interfaceorg.xml.sax.ContentHandler- Overrides:
 endElementin classorg.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.SAXExceptionWhat 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:
 endDocumentin interfaceorg.xml.sax.ContentHandler- Overrides:
 endDocumentin classorg.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 associatedMessageRouter.- Parameters:
 message- The validation error message (used in a call togenerateErrorMessage(String)).
 
- 
internalError
protected void internalError(java.lang.String message) throws org.xml.sax.SAXExceptionThrows 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.
 
 - 
 
 -