Package com.microstrategy.utils.xml
Class SAXSupport
- java.lang.Object
 - 
- com.microstrategy.utils.xml.SAXSupport
 
 
- 
public abstract class SAXSupport extends java.lang.ObjectThis is a wrapper around the SAX parser that provides the following services:- Hides the actual parser implementation
 - Maintains the stack of active 
ContentHandlers - Provide set of static helper methods for dealing with XML content
 
This class is not thread-safe.
- Since:
 - MicroStrategy Web 7.3.1 or earlier
 
 
- 
- 
Constructor Summary
Constructors Constructor Description SAXSupport() 
- 
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static booleangetBoolAttribute(org.xml.sax.Attributes attrs, java.lang.String name)This method returns true if specified attribute is present inattrscollection and has value "1".static booleangetBoolAttribute(org.xml.sax.Attributes attrs, java.lang.String name, boolean defaultVal)If specified attribute is present inattrscollection this method will return true if the attribute hase value "1" and false if it has value "0".java.lang.ObjectgetContextObject(java.lang.String key)static javax.xml.parsers.SAXParserFactorygetDefaultFactory()static SAXSupportgetInstance()A factory method that returns newSAXSupportinstance.static SAXSupportgetInstance(java.util.Set<java.lang.String> allowEntityPath)A factory method that returns newSAXSupportinstance.static SAXSupportgetInstance(javax.xml.parsers.SAXParserFactory factory)A factory method that returns newSAXSupportinstance.static SAXSupportgetInstance(javax.xml.parsers.SAXParserFactory factory, java.util.Set<java.lang.String> allowEntityPath)A factory method that returns newSAXSupportinstance.static intgetIntAttribute(java.lang.String tag, org.xml.sax.Attributes attrs, java.lang.String name)This method returns attribute value from theattrscollection converted to the integer.static intgetIntAttribute(java.lang.String tag, org.xml.sax.Attributes attrs, java.lang.String name, int defaultVal)This method returns attribute value from theattrscollection converted to the integer ordefaultValif the attribute does not exist.abstract javax.xml.parsers.SAXParsergetParser()ReturnsSAXParserassociated with this object.static java.lang.StringgetStrAttribute(java.lang.String tag, org.xml.sax.Attributes attrs, java.lang.String name)This method returns attribute value from theattrscollection.static java.lang.StringgetStrAttribute(org.xml.sax.Attributes attrs, java.lang.String name, java.lang.String defaultVal)This method returns attribute value from theattrscollection ordefaultValif the attribute does not exist.abstract org.xml.sax.XMLReadergetXMLReader()static voidinvalidAttrFormat(java.lang.String tag, java.lang.String name, java.lang.String val)ThrowsSAXSupportExceptionexception with "Invalid attribute value format" messagestatic voidmissingAttribute(java.lang.String tag, java.lang.String name)ThrowsSAXSupportExceptionexception with "Missing attribute" messagestatic javax.xml.parsers.SAXParserFactorynewSAXParserFactory()ReturnsSAXParserFactorywith doctype disabled by default to avoid XXE attack.abstract voidparse(java.io.File xmlFile, org.xml.sax.ContentHandler contHandler)Parses XML file using specified content handlerabstract voidparse(java.io.InputStream inputStream, org.xml.sax.ContentHandler contHandler)Parses XML presented byinputStreamusing specified content handlerabstract voidparse(java.lang.String xml, org.xml.sax.ContentHandler contHandler)Parses XML string using specified content handlerabstract voidparse(org.xml.sax.InputSource iSrc, org.xml.sax.ContentHandler contHandler)Parses XML presented byiSrcusing specified content handlerabstract org.xml.sax.ContentHandlerpopContentHandler(java.lang.String uri, java.lang.String local, java.lang.String qName)This method shall be called from the content handler'sendElelmentmethod to reattach the parent content handler to the xmlReader.abstract voidpushContentHandler(AbstractHandler contHandler)This method shall be called from the content handler'sstartElelmentmethod to attach another content handler to the xmlReader.abstract voidpushContentHandler(org.xml.sax.ContentHandler contHandler)This method shall be called from the content handler'sstartElelmentmethod to attach another content handler to the xmlReader.voidputContextObject(java.lang.String key, java.lang.Object value)static voidunexpectedElement(java.lang.String tag, java.lang.String parent)ThrowsSAXSupportExceptionexception with "Unexpected element" messagestatic voidunexpectedEndDocument(java.lang.Object handler)Call this method to report unexpected end of document event.static voidunexpectedEndElement(java.lang.Object handler)Call this method to report unexpected end of element event. 
 - 
 
- 
- 
Method Detail
- 
newSAXParserFactory
public static javax.xml.parsers.SAXParserFactory newSAXParserFactory()
ReturnsSAXParserFactorywith doctype disabled by default to avoid XXE attack.- Returns:
 SAXParserFactory
 
- 
getParser
public abstract javax.xml.parsers.SAXParser getParser()
ReturnsSAXParserassociated with this object. Please usegetXMLReader()instead of this method as some application servers will create aXMLReaderwith eachSAXParser.getXMLReader()invocation.- Returns:
 SAXParserassociated with this object.
 
- 
getXMLReader
public abstract org.xml.sax.XMLReader getXMLReader()
- Returns:
 - return the underlying 
XMLReaderinstance - Since:
 - MicroStrategy Web 9.0.1
 
 
- 
getContextObject
public java.lang.Object getContextObject(java.lang.String key)
- Since:
 - MicroStrategy Web 8.0.0
 
 
- 
putContextObject
public void putContextObject(java.lang.String key, java.lang.Object value)- Since:
 - MicroStrategy Web 8.0.0
 
 
- 
parse
public abstract void parse(java.lang.String xml, org.xml.sax.ContentHandler contHandler) throws org.xml.sax.SAXExceptionParses XML string using specified content handler- Parameters:
 xml- XML stringcontHandler- a content handler- Throws:
 org.xml.sax.SAXException- if something is wrong with the input xml
 
- 
parse
public abstract void parse(java.io.File xmlFile, org.xml.sax.ContentHandler contHandler) throws org.xml.sax.SAXException, java.io.IOExceptionParses XML file using specified content handler- Parameters:
 xmlFile- XML filecontHandler- a content handler- Throws:
 org.xml.sax.SAXException- if something is wrong with the input xmljava.io.IOException- if there are problems with input file
 
- 
parse
public abstract void parse(java.io.InputStream inputStream, org.xml.sax.ContentHandler contHandler) throws org.xml.sax.SAXException, java.io.IOExceptionParses XML presented byinputStreamusing specified content handler- Parameters:
 inputStream- Input Stream presenting XML documentcontHandler- a content handler- Throws:
 org.xml.sax.SAXException- if something is wrong with the input xmljava.io.IOException- if there are problems with input source
 
- 
parse
public abstract void parse(org.xml.sax.InputSource iSrc, org.xml.sax.ContentHandler contHandler) throws org.xml.sax.SAXException, java.io.IOExceptionParses XML presented byiSrcusing specified content handler- Parameters:
 iSrc- input source presenting XML documentcontHandler- a content handler- Throws:
 org.xml.sax.SAXException- if something is wrong with the input xmljava.io.IOException- if there are problems with input source
 
- 
pushContentHandler
public abstract void pushContentHandler(AbstractHandler contHandler)
This method shall be called from the content handler'sstartElelmentmethod to attach another content handler to the xmlReader. It detaches the current content handler from the xmlReader and pushes it into the stack, then attaches theto the xmlReader. It also sets contHandler.parserattribute tothis.- Parameters:
 contHandler- a new content handler
 
- 
pushContentHandler
public abstract void pushContentHandler(org.xml.sax.ContentHandler contHandler)
This method shall be called from the content handler'sstartElelmentmethod to attach another content handler to the xmlReader. It detaches the current content handler from the xmlReader and pushes it into the stack, then attaches theto the xmlReader. - Parameters:
 contHandler- a new content handler- Throws:
 java.lang.IllegalStateException- if this method is called before the parse method was called.
 
- 
popContentHandler
public abstract org.xml.sax.ContentHandler popContentHandler(java.lang.String uri, java.lang.String local, java.lang.String qName) throws org.xml.sax.SAXException, java.lang.IllegalStateExceptionThis method shall be called from the content handler'sendElelmentmethod to reattach the parent content handler to the xmlReader. Detaches the current content handler from the xmlReader. Pop's from the stack a "parent" content handler, and attaches it to the xmlReader.The
endElementmethod is called on the new content handler before attaching it to the xmlReader. It is done to allow it to adjust it's level count properly and to do other actions, if any.- Parameters:
 uri- The Namespace URI, or the empty string if the element has no Namespace URI or if Namespace processing is not being performed.local- The local name (without prefix), or the empty string if Namespace processing is not being performed.qName- The qualified name (with prefix), or the empty string if qualified names are not available.- Returns:
 - an old content handler
 - Throws:
 java.lang.IllegalStateException- if the handler stack is emptyorg.xml.sax.SAXException- can be thrown from theendElementmethod
 
- 
getInstance
public static SAXSupport getInstance() throws org.xml.sax.SAXException, XMLSupportRuntimeException
A factory method that returns newSAXSupportinstance. The default factory will be used to create theSAXParserassociated with the instance.- Returns:
 - new 
SAXSupportinstance. - Throws:
 XMLSupportRuntimeException- if a parser cannot be created which satisfies the requested configuration.org.xml.sax.SAXException- If error occurs during create the parser or the xml reader.
 
- 
getInstance
public static SAXSupport getInstance(java.util.Set<java.lang.String> allowEntityPath) throws org.xml.sax.SAXException, XMLSupportRuntimeException
A factory method that returns newSAXSupportinstance. The default factory will be used to create theSAXParserassociated with the instance.- Parameters:
 allowEntityPath- a set that includes the paths which are allowed to be used in external entities.- Returns:
 - new 
SAXSupportinstance. - Throws:
 XMLSupportRuntimeException- if a parser cannot be created which satisfies the requested configuration.org.xml.sax.SAXException- If error occurs during create the parser or the xml reader.
 
- 
getInstance
public static SAXSupport getInstance(javax.xml.parsers.SAXParserFactory factory) throws org.xml.sax.SAXException, XMLSupportRuntimeException
A factory method that returns newSAXSupportinstance.- Parameters:
 factory- a factory that shall be used to createSAXParserassociated with the instance.- Returns:
 - new 
SAXSupportinstance. - Throws:
 XMLSupportRuntimeException- if a parser cannot be created which satisfies the requested configuration.org.xml.sax.SAXException- If error occurs during create the parser or the xml reader.
 
- 
getInstance
public static SAXSupport getInstance(javax.xml.parsers.SAXParserFactory factory, java.util.Set<java.lang.String> allowEntityPath) throws org.xml.sax.SAXException, XMLSupportRuntimeException
A factory method that returns newSAXSupportinstance.- Parameters:
 factory- a factory that shall be used to createSAXParserassociated with the instance.allowEntityPath- a set that includes the paths which are allowed to be used in external entities.- Returns:
 - new 
SAXSupportinstance. - Throws:
 XMLSupportRuntimeException- if a parser cannot be created which satisfies the requested configuration.org.xml.sax.SAXException- If error occurs during create the parser or the xml reader.
 
- 
getDefaultFactory
public static javax.xml.parsers.SAXParserFactory getDefaultFactory()
- Returns:
 - default 
SAXParserFactory 
 
- 
unexpectedEndDocument
public static void unexpectedEndDocument(java.lang.Object handler) throws java.lang.IllegalStateExceptionCall this method to report unexpected end of document event. Normally it shall be used in theendDocumentmethods of inner event handlers.- Parameters:
 handler- the handler that detected the error- Throws:
 java.lang.IllegalStateException- If the handler does not support endDocument() method.
 
- 
unexpectedEndElement
public static void unexpectedEndElement(java.lang.Object handler) throws java.lang.IllegalStateExceptionCall this method to report unexpected end of element event. Normally it shall be called from theendElementmethods if the level count goes below zero.- Parameters:
 handler- the handler that detected the error- Throws:
 java.lang.IllegalStateException- If the handler does not support endElement() method.
 
- 
getStrAttribute
public static java.lang.String getStrAttribute(java.lang.String tag, org.xml.sax.Attributes attrs, java.lang.String name) throws SAXSupportExceptionThis method returns attribute value from theattrscollection. It will throwWebSAXExceptionif the attribute does not exist. Use this method for mandatory attributes.- Parameters:
 tag- element's tag name. Used in the diagnostic message.attrs- attribute collectionname- attribute name- Returns:
 - attribute value
 - Throws:
 SAXSupportException- if attribute does not exists in the collection
 
- 
getStrAttribute
public static java.lang.String getStrAttribute(org.xml.sax.Attributes attrs, java.lang.String name, java.lang.String defaultVal)This method returns attribute value from theattrscollection ordefaultValif the attribute does not exist. Use this method for optional attributes.- Parameters:
 attrs- attribute collectionname- attribute namedefaultVal- default value to be used if the attribute does not exist- Returns:
 - attribute value
 
 
- 
getIntAttribute
public static int getIntAttribute(java.lang.String tag, org.xml.sax.Attributes attrs, java.lang.String name) throws SAXSupportExceptionThis method returns attribute value from theattrscollection converted to the integer. It will throwSAXSupportExceptionif the attribute does not exist. Use this method for mandatory attributes.- Parameters:
 tag- element's tag name. Used in the diagnostic message.attrs- attribute collectionname- attribute name- Returns:
 - attribute value
 - Throws:
 SAXSupportException- if attribute does not exists in the collection or if its value is not an integer
 
- 
getIntAttribute
public static int getIntAttribute(java.lang.String tag, org.xml.sax.Attributes attrs, java.lang.String name, int defaultVal) throws SAXSupportExceptionThis method returns attribute value from theattrscollection converted to the integer ordefaultValif the attribute does not exist. Use this method for optional attributes.- Parameters:
 tag- element's tag name. Used in the diagnostic message.attrs- attribute collectionname- attribute namedefaultVal- default value to be used if the attribute does not exist- Returns:
 - attribute value
 - Throws:
 SAXSupportException- if attribute value is not an integer
 
- 
getBoolAttribute
public static boolean getBoolAttribute(org.xml.sax.Attributes attrs, java.lang.String name) throws SAXSupportExceptionThis method returns true if specified attribute is present inattrscollection and has value "1". It returns false if the attribute is absent or if it has value "0". It will throwSAXSupportExceptionin any other case.Use this method for boolean attributes that can be present with both "1" and "0" values
- Parameters:
 attrs- attribute collectionname- attribute name- Returns:
 - true or false.
 - Throws:
 SAXSupportException- if attribute value is not "0" or "1"
 
- 
getBoolAttribute
public static boolean getBoolAttribute(org.xml.sax.Attributes attrs, java.lang.String name, boolean defaultVal) throws SAXSupportExceptionIf specified attribute is present inattrscollection this method will return true if the attribute hase value "1" and false if it has value "0". If the attribute is absent then the method will returndefaultVal.- Parameters:
 attrs- attribute collectionname- attribute namedefaultVal- a default value- Returns:
 - true or false.
 - Throws:
 SAXSupportException- if attribute value is not "0" or "1"
 
- 
missingAttribute
public static void missingAttribute(java.lang.String tag, java.lang.String name) throws SAXSupportExceptionThrowsSAXSupportExceptionexception with "Missing attribute" message- Parameters:
 tag- tag namename- attribute name- Throws:
 SAXSupportException- exception with "Missing attribute" message.
 
- 
invalidAttrFormat
public static void invalidAttrFormat(java.lang.String tag, java.lang.String name, java.lang.String val) throws SAXSupportExceptionThrowsSAXSupportExceptionexception with "Invalid attribute value format" message- Parameters:
 tag- tag namename- attribute nameval- value- Throws:
 SAXSupportException- exception with "Invalid attribute value format" message
 
- 
unexpectedElement
public static void unexpectedElement(java.lang.String tag, java.lang.String parent) throws SAXSupportExceptionThrowsSAXSupportExceptionexception with "Unexpected element" message- Parameters:
 tag- tag nameparent- parent tag name- Throws:
 SAXSupportException- exception with "Unexpected element" message
 
 - 
 
 -