Package com.microstrategy.utils.xml
Class XMLUtils
- java.lang.Object
-
- com.microstrategy.utils.xml.XMLUtils
-
public class XMLUtils extends java.lang.ObjectThis class provides additional utilities that can be applied to the XML.- Since:
- MicroStrategy Web 7.3.1 or earlier
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classXMLUtils.DefaultEntityResolverstatic classXMLUtils.EnumDoctypeAllowance
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringFEATURE_DISALLOW_DOCTYPE_DECLstatic java.lang.StringFEATURE_EXTERNAL_GENERAL_ENTITIESstatic java.lang.StringFEATURE_EXTERNAL_PARAMETER_ENTITIESstatic java.lang.StringFEATURE_LOAD_EXTERNAL_DTD
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static booleanallowDoctype()Indicates whether the doctype is allowed or not.static voidappendResolvedSessionId(java.lang.String sessionID, XMLBuilder builder)static java.lang.StringcompareNodes(org.w3c.dom.Node base, org.w3c.dom.Node other, boolean ignoreTextNodes)This method compares twoNodeinstances (including all their attributes and children) and returns a string with the differences between them.static java.lang.StringencodeXMLAttribute(java.lang.String strToEncode)Replaces HTML unfriendly characters with their escaped equivalents.static java.lang.StringescapeString(java.lang.String s)Given a String containing markup, escape the markup so it can be put into xml as normal text.static java.lang.StringformatXML(java.lang.String xmlIn)This constructs a nicely formatted XML document, typically used for printing in a user readable format.static XMLUtils.EnumDoctypeAllowancegetDoctypePolicy()static java.lang.StringgetResolvedSessionId(java.lang.String sessionID)Deprecated.static booleanisValidGUID(java.lang.String str)Check whether the string is a valid GUIDstatic booleanisValidNodeKey(java.lang.String str)Check whether the string is a valid Nodekey, a loose check on whether it is consists of alphabet or digits.static booleanisValidXML(java.lang.String str)Equivalent toparseValidateXML(String, DefaultHandler)with null for theDefaultHandlerparameter.static java.lang.StringloadXMLFile(java.lang.String name)Load XML from a file.static javax.xml.parsers.DocumentBuilderFactorynewDocumentBuilderFactory()ReturnsDocumentBuilderFactorywith doctype disabled by default to avoid XXE attack.static javax.xml.parsers.DocumentBuilderFactorynewDocumentBuilderFactory(ParserParameters parameters)Instantiate an instance ofDocumentBuilderFactorybased on the given parameters.static XMLUtilsnewInstance()static java.lang.StringnodeValue(org.w3c.dom.Node contextNode)This method returns the "naive" node value of a node, that is, the concatenation of node values from all its child nodes.static org.w3c.dom.Documentparse(java.io.File f, ParserParameters parameters)static org.w3c.dom.Documentparse(java.io.InputStream stream, ParserParameters parameters)static org.w3c.dom.Documentparse(java.lang.String xmlString, ParserParameters parameters)static org.w3c.dom.Documentparse(org.xml.sax.InputSource source, ParserParameters parameters)static org.w3c.dom.DocumentparseFile(java.lang.String uri)static booleanparseValidateXML(java.lang.String str, org.xml.sax.helpers.DefaultHandler handler)Returns whether the given string is valid XML.static java.lang.StringprocessElement(int level, org.w3c.dom.Node objXmlElem)ProcessElement method returns a string with tabs and newlines inserted in the appropriate spots.voidtransform(org.w3c.dom.Node xmlDoc, javax.xml.transform.Result outputTarget)Transform the XML source to a Result.voidtransform(org.w3c.dom.Node xmlDoc, javax.xml.transform.Result outputTarget, TransformerParameters transformerParameters)Transform the XML source to a Result.voidtransform(org.w3c.dom.Node xmlDoc, org.w3c.dom.Node xslDoc, javax.xml.transform.Result outputTarget)Transform the XML source to a Result.voidtransform(org.w3c.dom.Node xmlDoc, org.w3c.dom.Node xslDoc, javax.xml.transform.Result outputTarget, TransformerParameters transformerParameters)Transform the XML source to a Result, the transformer behavior can be configured through thetransformerParametersparameter.
-
-
-
Field Detail
-
FEATURE_DISALLOW_DOCTYPE_DECL
public static final java.lang.String FEATURE_DISALLOW_DOCTYPE_DECL
- See Also:
- Constant Field Values
-
FEATURE_EXTERNAL_GENERAL_ENTITIES
public static final java.lang.String FEATURE_EXTERNAL_GENERAL_ENTITIES
- See Also:
- Constant Field Values
-
FEATURE_EXTERNAL_PARAMETER_ENTITIES
public static final java.lang.String FEATURE_EXTERNAL_PARAMETER_ENTITIES
- See Also:
- Constant Field Values
-
FEATURE_LOAD_EXTERNAL_DTD
public static final java.lang.String FEATURE_LOAD_EXTERNAL_DTD
- See Also:
- Constant Field Values
-
-
Method Detail
-
newInstance
public static XMLUtils newInstance()
-
getDoctypePolicy
public static XMLUtils.EnumDoctypeAllowance getDoctypePolicy()
-
allowDoctype
public static boolean allowDoctype()
Indicates whether the doctype is allowed or not.
-
newDocumentBuilderFactory
public static javax.xml.parsers.DocumentBuilderFactory newDocumentBuilderFactory()
ReturnsDocumentBuilderFactorywith doctype disabled by default to avoid XXE attack.- Returns:
DocumentBuilderFactory
-
newDocumentBuilderFactory
public static javax.xml.parsers.DocumentBuilderFactory newDocumentBuilderFactory(ParserParameters parameters)
Instantiate an instance ofDocumentBuilderFactorybased on the given parameters.- Parameters:
parameters- TheParserParametersclass with the parameter values- Returns:
- The
DocumentBuilderFactoryinstance.
-
parse
public static org.w3c.dom.Document parse(java.lang.String xmlString, ParserParameters parameters) throws XMLSupportException- Throws:
XMLSupportException
-
parse
public static org.w3c.dom.Document parse(java.io.InputStream stream, ParserParameters parameters) throws XMLSupportException- Throws:
XMLSupportException
-
parse
public static org.w3c.dom.Document parse(java.io.File f, ParserParameters parameters) throws XMLSupportException- Throws:
XMLSupportException
-
parse
public static org.w3c.dom.Document parse(org.xml.sax.InputSource source, ParserParameters parameters) throws XMLSupportException- Throws:
XMLSupportException
-
parseFile
public static org.w3c.dom.Document parseFile(java.lang.String uri) throws org.xml.sax.SAXException, java.io.IOException, javax.xml.parsers.ParserConfigurationException- Throws:
org.xml.sax.SAXExceptionjava.io.IOExceptionjavax.xml.parsers.ParserConfigurationException
-
transform
public void transform(org.w3c.dom.Node xmlDoc, javax.xml.transform.Result outputTarget) throws javax.xml.transform.TransformerConfigurationException, javax.xml.transform.TransformerExceptionTransform the XML source to a Result.- Parameters:
xmlDoc- The XML document to transformoutputTarget- The Result of transforming the source.- Throws:
javax.xml.transform.TransformerConfigurationExceptionjavax.xml.transform.TransformerException
-
transform
public void transform(org.w3c.dom.Node xmlDoc, javax.xml.transform.Result outputTarget, TransformerParameters transformerParameters) throws javax.xml.transform.TransformerConfigurationException, javax.xml.transform.TransformerExceptionTransform the XML source to a Result.- Parameters:
xmlDoc- The XML document to transformoutputTarget- The Result of transforming the source.transformerParameters- The transformer parameters- Throws:
javax.xml.transform.TransformerConfigurationExceptionjavax.xml.transform.TransformerException
-
transform
public void transform(org.w3c.dom.Node xmlDoc, org.w3c.dom.Node xslDoc, javax.xml.transform.Result outputTarget) throws javax.xml.transform.TransformerConfigurationException, javax.xml.transform.TransformerExceptionTransform the XML source to a Result.- Parameters:
xmlDoc- The XML document to transformxslDoc- The XSLT document used to create TransformeroutputTarget- The Result of transforming the source.- Throws:
javax.xml.transform.TransformerConfigurationExceptionjavax.xml.transform.TransformerException
-
transform
public void transform(org.w3c.dom.Node xmlDoc, org.w3c.dom.Node xslDoc, javax.xml.transform.Result outputTarget, TransformerParameters transformerParameters) throws javax.xml.transform.TransformerConfigurationException, javax.xml.transform.TransformerExceptionTransform the XML source to a Result, the transformer behavior can be configured through thetransformerParametersparameter.- Parameters:
xmlDoc- The XML document to transformxslDoc- The XSLT document used to create TransformeroutputTarget- The Result of transforming the source.transformerParameters- The transformer parameters- Throws:
javax.xml.transform.TransformerConfigurationExceptionjavax.xml.transform.TransformerException
-
encodeXMLAttribute
public static java.lang.String encodeXMLAttribute(java.lang.String strToEncode)
Replaces HTML unfriendly characters with their escaped equivalents. Used to store XML string inside hidden input fields or other HTML attribute- Parameters:
strToEncode- the source string to encode.- Returns:
- The encoded string.
-
processElement
public static java.lang.String processElement(int level, org.w3c.dom.Node objXmlElem) throws XMLSupportExceptionProcessElement method returns a string with tabs and newlines inserted in the appropriate spots.- Parameters:
level- int, level from which we want to processobjXmlElem- Node, node we want to process- Returns:
- The String, with adequate format
- Throws:
XMLSupportException- Signals an error when parsing the XML.
-
escapeString
public static java.lang.String escapeString(java.lang.String s)
Given a String containing markup, escape the markup so it can be put into xml as normal text.- Parameters:
s- String to escape- Returns:
- The escaped string.
-
formatXML
public static java.lang.String formatXML(java.lang.String xmlIn) throws XMLSupportExceptionThis constructs a nicely formatted XML document, typically used for printing in a user readable format.
- Parameters:
xmlIn- The xml string to be formatted.- Returns:
- The nicely formatted XML String.
- Throws:
XMLSupportException- Signals an error when format the XML.
-
loadXMLFile
public static java.lang.String loadXMLFile(java.lang.String name) throws java.io.IOExceptionLoad XML from a file.- Parameters:
name- The path to the file.- Returns:
- The XML string in the file.
- Throws:
java.io.IOException- When error occurs during retrieving the XML from the file.- Since:
- MicroStrategy Web 8.0.0
-
compareNodes
public static java.lang.String compareNodes(org.w3c.dom.Node base, org.w3c.dom.Node other, boolean ignoreTextNodes)This method compares twoNodeinstances (including all their attributes and children) and returns a string with the differences between them. If the nodes are equal, it returnsnull.- Parameters:
base- The base node to compare.other- The other node to compare.ignoreTextNodes- iftrue, this method only compare Element child nodes, that is, all text nodes are ignored.- Returns:
- A description of the nodes differences;
nullif equal. - Since:
- MicroStrategy Web 9.0.0
-
nodeValue
public static java.lang.String nodeValue(org.w3c.dom.Node contextNode)
This method returns the "naive" node value of a node, that is, the concatenation of node values from all its child nodes.- Since:
- MicroStrategy Web 9.0.0
-
parseValidateXML
public static boolean parseValidateXML(java.lang.String str, org.xml.sax.helpers.DefaultHandler handler)Returns whether the given string is valid XML. The supplied parser is also used to parse the string.- Parameters:
str- string to checkhandler- handler attempt parsing with, if null, an emptyDefaultHandleris used- Returns:
- whether string is XML, false if any exception occurs during parsing
- Since:
- MicroStrategy Web 9.0.0
-
isValidXML
public static boolean isValidXML(java.lang.String str)
Equivalent toparseValidateXML(String, DefaultHandler)with null for theDefaultHandlerparameter.- Parameters:
str- string to check- Returns:
- whether the string is XML
- Since:
- MicroStrategy Web 9.0.0
-
isValidGUID
public static boolean isValidGUID(java.lang.String str)
Check whether the string is a valid GUID- Parameters:
str- string to check- Returns:
- whether the string is a valid GUID
-
isValidNodeKey
public static boolean isValidNodeKey(java.lang.String str)
Check whether the string is a valid Nodekey, a loose check on whether it is consists of alphabet or digits.- Parameters:
str- string to check- Returns:
- whether the string is a valid Nodekey
-
appendResolvedSessionId
public static void appendResolvedSessionId(java.lang.String sessionID, XMLBuilder builder)- Parameters:
sessionID-builder-
-
getResolvedSessionId
@Deprecated public static java.lang.String getResolvedSessionId(java.lang.String sessionID)
Deprecated.
-
-