Package com.microstrategy.utils.xml
Class XMLUtils
- java.lang.Object
-
- com.microstrategy.utils.xml.XMLUtils
-
public class XMLUtils extends java.lang.Object
This 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 class
XMLUtils.DefaultEntityResolver
static class
XMLUtils.EnumDoctypeAllowance
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
FEATURE_DISALLOW_DOCTYPE_DECL
static java.lang.String
FEATURE_EXTERNAL_GENERAL_ENTITIES
static java.lang.String
FEATURE_EXTERNAL_PARAMETER_ENTITIES
static java.lang.String
FEATURE_LOAD_EXTERNAL_DTD
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static boolean
allowDoctype()
Indicates whether the doctype is allowed or not.static void
appendResolvedSessionId(java.lang.String sessionID, XMLBuilder builder)
static java.lang.String
compareNodes(org.w3c.dom.Node base, org.w3c.dom.Node other, boolean ignoreTextNodes)
This method compares twoNode
instances (including all their attributes and children) and returns a string with the differences between them.static java.lang.String
encodeXMLAttribute(java.lang.String strToEncode)
Replaces HTML unfriendly characters with their escaped equivalents.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.static java.lang.String
formatXML(java.lang.String xmlIn)
This constructs a nicely formatted XML document, typically used for printing in a user readable format.static XMLUtils.EnumDoctypeAllowance
getDoctypePolicy()
static java.lang.String
getResolvedSessionId(java.lang.String sessionID)
Deprecated.static boolean
isValidGUID(java.lang.String str)
Check whether the string is a valid GUIDstatic 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.static boolean
isValidXML(java.lang.String str)
Equivalent toparseValidateXML(String, DefaultHandler)
with null for theDefaultHandler
parameter.static java.lang.String
loadXMLFile(java.lang.String name)
Load XML from a file.static javax.xml.parsers.DocumentBuilderFactory
newDocumentBuilderFactory()
ReturnsDocumentBuilderFactory
with doctype disabled by default to avoid XXE attack.static javax.xml.parsers.DocumentBuilderFactory
newDocumentBuilderFactory(ParserParameters parameters)
Instantiate an instance ofDocumentBuilderFactory
based on the given parameters.static XMLUtils
newInstance()
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.static org.w3c.dom.Document
parse(java.io.File f, ParserParameters parameters)
static org.w3c.dom.Document
parse(java.io.InputStream stream, ParserParameters parameters)
static org.w3c.dom.Document
parse(java.lang.String xmlString, ParserParameters parameters)
static org.w3c.dom.Document
parse(org.xml.sax.InputSource source, ParserParameters parameters)
static org.w3c.dom.Document
parseFile(java.lang.String uri)
static boolean
parseValidateXML(java.lang.String str, org.xml.sax.helpers.DefaultHandler handler)
Returns whether the given string is valid XML.static java.lang.String
processElement(int level, org.w3c.dom.Node objXmlElem)
ProcessElement method returns a string with tabs and newlines inserted in the appropriate spots.void
transform(org.w3c.dom.Node xmlDoc, javax.xml.transform.Result outputTarget)
Transform the XML source to a Result.void
transform(org.w3c.dom.Node xmlDoc, javax.xml.transform.Result outputTarget, TransformerParameters transformerParameters)
Transform the XML source to a Result.void
transform(org.w3c.dom.Node xmlDoc, org.w3c.dom.Node xslDoc, javax.xml.transform.Result outputTarget)
Transform the XML source to a Result.void
transform(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 thetransformerParameters
parameter.
-
-
-
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()
ReturnsDocumentBuilderFactory
with doctype disabled by default to avoid XXE attack.- Returns:
DocumentBuilderFactory
-
newDocumentBuilderFactory
public static javax.xml.parsers.DocumentBuilderFactory newDocumentBuilderFactory(ParserParameters parameters)
Instantiate an instance ofDocumentBuilderFactory
based on the given parameters.- Parameters:
parameters
- TheParserParameters
class with the parameter values- Returns:
- The
DocumentBuilderFactory
instance.
-
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.SAXException
java.io.IOException
javax.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.TransformerException
Transform the XML source to a Result.- Parameters:
xmlDoc
- The XML document to transformoutputTarget
- The Result of transforming the source.- Throws:
javax.xml.transform.TransformerConfigurationException
javax.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.TransformerException
Transform 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.TransformerConfigurationException
javax.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.TransformerException
Transform 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.TransformerConfigurationException
javax.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.TransformerException
Transform the XML source to a Result, the transformer behavior can be configured through thetransformerParameters
parameter.- 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.TransformerConfigurationException
javax.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 XMLSupportException
ProcessElement 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 XMLSupportException
This 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.IOException
Load 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 twoNode
instances (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;
null
if 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 emptyDefaultHandler
is 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 theDefaultHandler
parameter.- 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.
-
-