Package mondrian.tui
Class XmlUtil
- java.lang.Object
-
- mondrian.tui.XmlUtil
-
public class XmlUtil extends java.lang.Object
Some XML parsing, validation and transform utility methods used to valiate XMLA responses.- Author:
- Richard M. Emberson
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
XmlUtil.Resolver
This can be extened to have a map from publicId/systemId to InputSource.static class
XmlUtil.SaxErrorHandler
Error handler plus helper methods.
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
DEFER_NODE_EXPANSION
static java.lang.String
FULL_SCHEMA_VALIDATION_FEATURE_ID
static java.lang.String
LINE_SEP
static java.lang.String
NAMESPACES_FEATURE_ID
static java.lang.String
SCHEMA_LOCATION
static java.lang.String
SCHEMA_VALIDATION_FEATURE_ID
static java.lang.String
SOAP_PREFIX
static java.lang.String
VALIDATION_FEATURE_ID
static java.lang.String
XMLNS
static java.lang.String
XSD_PREFIX
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static org.w3c.dom.Node[]
convertToNodes(org.w3c.dom.xpath.XPathResult xpathResult)
Convert an XPathResult to an array of Nodes.static java.lang.String
convertToString(org.w3c.dom.xpath.XPathResult xpathResult, boolean prettyPrint)
Convert an XPathResult object to String.static org.w3c.dom.Document
createContextDocument(java.lang.String[][] nsArray)
Create a context document for use in performing XPath operations.static java.lang.String
getNamespaceAttributeValue(org.w3c.dom.Document doc)
This is used to get a Document's namespace attribute value.static org.apache.xerces.parsers.DOMParser
getParser(java.lang.String schemaLocationPropertyValue, org.xml.sax.EntityResolver entityResolver, boolean validate)
Get your non-cached DOM parser which can be configured to do schema based validation of the instance Document.static java.lang.String
getSoapXmlaXds2xd(java.lang.String xmlaPrefix)
This is the xslt that can extract the "data" part of a SOAP XMLA response.static java.lang.String
getSoapXmlaXds2xs(java.lang.String xmlaPrefix)
This is the xslt that can extract the "schema" part of a SOAP XMLA response.static javax.xml.transform.TransformerFactory
getTransformerFactory()
static java.lang.String
getXercesVersion()
Get the Xerces version being used.static int[]
getXercesVersionNumbers()
Gets the Xerces version numbers as a three part array of ints where the first element is the major release number, the second is the minor release number, and the third is the patch number.static java.lang.String
getXercesVersionNumberString()
Get the number part of the Xerces Version string.static java.lang.String
getXmlaXds2xd(java.lang.String ns)
This is the xslt that can extract the "data" part of a XMLA response.static java.lang.String
getXmlaXds2xs(java.lang.String ns)
This is the xslt that can extract the "schema" part of a XMLA response.static java.lang.String
makeRootPathInSoapBody()
static java.lang.String
makeRootPathInSoapBody(java.lang.String xmlaPrefix, java.lang.String xsdPrefix)
static java.lang.String
makeSoapPath()
static java.lang.String
makeSoapPath(java.lang.String prefix)
static org.w3c.dom.Document
newDocument(org.w3c.dom.Node firstElement, boolean deepcopy)
static org.w3c.dom.Document
parse(byte[] bytes)
Parse a byte array into a Document (no validation).static org.w3c.dom.Document
parse(java.io.File file)
static org.w3c.dom.Document
parse(java.io.InputStream in)
Parse a stream into a Document (no validation).static org.w3c.dom.Document
parseString(java.lang.String s)
Parse a String into a Document (no validation).static org.w3c.dom.xpath.XPathResult
select(org.w3c.dom.Node contextNode, java.lang.String xpath, org.w3c.dom.Node namespaceNode)
static org.w3c.dom.Node[]
selectAsNodes(org.w3c.dom.Node node, java.lang.String xpath)
static org.w3c.dom.Node[]
selectAsNodes(org.w3c.dom.Node node, java.lang.String xpath, org.w3c.dom.Node namespaceNode)
static java.lang.String
selectAsString(org.w3c.dom.Node node, java.lang.String xpath)
static java.lang.String
selectAsString(org.w3c.dom.Node node, java.lang.String xpath, org.w3c.dom.Node namespaceNode)
static boolean
supportsValidation()
Returns whether the XML parser supports validation.static java.lang.String
toString(org.w3c.dom.Node node, boolean prettyPrint)
Convert a Node to a String.static org.w3c.dom.Node
transform(org.w3c.dom.Document inDoc, java.io.Reader xslReader)
static org.w3c.dom.Node
transform(org.w3c.dom.Document inDoc, java.io.Reader xslReader, java.lang.String[][] namevalueParameters)
Transform a Document and return the transformed Node.static org.w3c.dom.Node
transform(org.w3c.dom.Document inDoc, java.lang.String xslFileName)
static org.w3c.dom.Node
transform(org.w3c.dom.Document inDoc, java.lang.String xslFileName, java.lang.String[][] namevalueParameters)
Transform a Document and return the transformed Node.static void
validate(java.lang.String docStr, java.lang.String schemaLocationPropertyValue, org.xml.sax.EntityResolver resolver)
static void
validate(org.w3c.dom.Document doc, java.lang.String schemaLocationPropertyValue, org.xml.sax.EntityResolver resolver)
-
-
-
Field Detail
-
LINE_SEP
public static final java.lang.String LINE_SEP
-
SOAP_PREFIX
public static final java.lang.String SOAP_PREFIX
- See Also:
- Constant Field Values
-
XSD_PREFIX
public static final java.lang.String XSD_PREFIX
- See Also:
- Constant Field Values
-
XMLNS
public static final java.lang.String XMLNS
- See Also:
- Constant Field Values
-
NAMESPACES_FEATURE_ID
public static final java.lang.String NAMESPACES_FEATURE_ID
- See Also:
- Constant Field Values
-
VALIDATION_FEATURE_ID
public static final java.lang.String VALIDATION_FEATURE_ID
- See Also:
- Constant Field Values
-
SCHEMA_VALIDATION_FEATURE_ID
public static final java.lang.String SCHEMA_VALIDATION_FEATURE_ID
- See Also:
- Constant Field Values
-
FULL_SCHEMA_VALIDATION_FEATURE_ID
public static final java.lang.String FULL_SCHEMA_VALIDATION_FEATURE_ID
- See Also:
- Constant Field Values
-
DEFER_NODE_EXPANSION
public static final java.lang.String DEFER_NODE_EXPANSION
- See Also:
- Constant Field Values
-
SCHEMA_LOCATION
public static final java.lang.String SCHEMA_LOCATION
- See Also:
- Constant Field Values
-
-
Method Detail
-
getSoapXmlaXds2xd
public static final java.lang.String getSoapXmlaXds2xd(java.lang.String xmlaPrefix)
This is the xslt that can extract the "data" part of a SOAP XMLA response.
-
getSoapXmlaXds2xs
public static final java.lang.String getSoapXmlaXds2xs(java.lang.String xmlaPrefix)
This is the xslt that can extract the "schema" part of a SOAP XMLA response.
-
getXmlaXds2xd
public static final java.lang.String getXmlaXds2xd(java.lang.String ns)
This is the xslt that can extract the "data" part of a XMLA response.
-
getXmlaXds2xs
public static final java.lang.String getXmlaXds2xs(java.lang.String ns)
This is the xslt that can extract the "schema" part of a XMLA response.
-
newDocument
public static org.w3c.dom.Document newDocument(org.w3c.dom.Node firstElement, boolean deepcopy)
-
getParser
public static org.apache.xerces.parsers.DOMParser getParser(java.lang.String schemaLocationPropertyValue, org.xml.sax.EntityResolver entityResolver, boolean validate) throws org.xml.sax.SAXNotRecognizedException, org.xml.sax.SAXNotSupportedException
Get your non-cached DOM parser which can be configured to do schema based validation of the instance Document.- Throws:
org.xml.sax.SAXNotRecognizedException
org.xml.sax.SAXNotSupportedException
-
parseString
public static org.w3c.dom.Document parseString(java.lang.String s) throws org.xml.sax.SAXException, java.io.IOException
Parse a String into a Document (no validation).- Throws:
org.xml.sax.SAXException
java.io.IOException
-
parse
public static org.w3c.dom.Document parse(byte[] bytes) throws org.xml.sax.SAXException, java.io.IOException
Parse a byte array into a Document (no validation).- Throws:
org.xml.sax.SAXException
java.io.IOException
-
parse
public static org.w3c.dom.Document parse(java.io.File file) throws org.xml.sax.SAXException, java.io.IOException
- Throws:
org.xml.sax.SAXException
java.io.IOException
-
parse
public static org.w3c.dom.Document parse(java.io.InputStream in) throws org.xml.sax.SAXException, java.io.IOException
Parse a stream into a Document (no validation).- Throws:
org.xml.sax.SAXException
java.io.IOException
-
createContextDocument
public static org.w3c.dom.Document createContextDocument(java.lang.String[][] nsArray) throws org.xml.sax.SAXException, java.io.IOException
Create a context document for use in performing XPath operations. An array of prefix/namespace-urls are provided as input. These namespace-urls should be all of those that will appear in the document against which an xpath is to be applied. Importantly, it is, in fact, each element of the Document that has a default namespace these namespaces MUST have prefix/namespace-urls pairs in the context document and the prefix provided MUST also be used in the xpath. Elements with explicit namespaces don't have to have pairs in the context Document as long as the xpath uses the same prefixes that appear in the target Document.- Throws:
org.xml.sax.SAXException
java.io.IOException
-
makeSoapPath
public static java.lang.String makeSoapPath()
-
makeSoapPath
public static java.lang.String makeSoapPath(java.lang.String prefix)
-
makeRootPathInSoapBody
public static java.lang.String makeRootPathInSoapBody()
-
makeRootPathInSoapBody
public static java.lang.String makeRootPathInSoapBody(java.lang.String xmlaPrefix, java.lang.String xsdPrefix)
-
selectAsString
public static java.lang.String selectAsString(org.w3c.dom.Node node, java.lang.String xpath) throws org.w3c.dom.xpath.XPathException
- Throws:
org.w3c.dom.xpath.XPathException
-
selectAsString
public static java.lang.String selectAsString(org.w3c.dom.Node node, java.lang.String xpath, org.w3c.dom.Node namespaceNode) throws org.w3c.dom.xpath.XPathException
- Throws:
org.w3c.dom.xpath.XPathException
-
selectAsNodes
public static org.w3c.dom.Node[] selectAsNodes(org.w3c.dom.Node node, java.lang.String xpath) throws org.w3c.dom.xpath.XPathException
- Throws:
org.w3c.dom.xpath.XPathException
-
selectAsNodes
public static org.w3c.dom.Node[] selectAsNodes(org.w3c.dom.Node node, java.lang.String xpath, org.w3c.dom.Node namespaceNode) throws org.w3c.dom.xpath.XPathException
- Throws:
org.w3c.dom.xpath.XPathException
-
select
public static org.w3c.dom.xpath.XPathResult select(org.w3c.dom.Node contextNode, java.lang.String xpath, org.w3c.dom.Node namespaceNode) throws org.w3c.dom.xpath.XPathException
- Throws:
org.w3c.dom.xpath.XPathException
-
convertToString
public static java.lang.String convertToString(org.w3c.dom.xpath.XPathResult xpathResult, boolean prettyPrint)
Convert an XPathResult object to String.
-
convertToNodes
public static org.w3c.dom.Node[] convertToNodes(org.w3c.dom.xpath.XPathResult xpathResult)
Convert an XPathResult to an array of Nodes.
-
toString
public static java.lang.String toString(org.w3c.dom.Node node, boolean prettyPrint)
Convert a Node to a String.
-
getXercesVersion
public static java.lang.String getXercesVersion()
Get the Xerces version being used.- Returns:
- Xerces version being used
-
getXercesVersionNumberString
public static java.lang.String getXercesVersionNumberString()
Get the number part of the Xerces Version string.- Returns:
- number part of the Xerces Version string
-
getXercesVersionNumbers
public static int[] getXercesVersionNumbers()
Gets the Xerces version numbers as a three part array of ints where the first element is the major release number, the second is the minor release number, and the third is the patch number.- Returns:
- Xerces version number as int array
-
supportsValidation
public static boolean supportsValidation()
Returns whether the XML parser supports validation.I could not get validation to work with Xerces 2.2 so I put in this check. If you want to test on an earlier version of Xerces simply define the above property: "mondrian.xml.always.attempt.validation", to true.
- Returns:
- whether the XML parser supports validation
-
validate
public static void validate(org.w3c.dom.Document doc, java.lang.String schemaLocationPropertyValue, org.xml.sax.EntityResolver resolver) throws java.io.IOException, org.xml.sax.SAXException
- Throws:
java.io.IOException
org.xml.sax.SAXException
-
validate
public static void validate(java.lang.String docStr, java.lang.String schemaLocationPropertyValue, org.xml.sax.EntityResolver resolver) throws java.io.IOException, org.xml.sax.SAXException
- Throws:
java.io.IOException
org.xml.sax.SAXException
-
getNamespaceAttributeValue
public static java.lang.String getNamespaceAttributeValue(org.w3c.dom.Document doc)
This is used to get a Document's namespace attribute value.
-
getTransformerFactory
public static javax.xml.transform.TransformerFactory getTransformerFactory() throws javax.xml.transform.TransformerFactoryConfigurationError
- Throws:
javax.xml.transform.TransformerFactoryConfigurationError
-
transform
public static org.w3c.dom.Node transform(org.w3c.dom.Document inDoc, java.lang.String xslFileName, java.lang.String[][] namevalueParameters) throws javax.xml.parsers.ParserConfigurationException, org.xml.sax.SAXException, java.io.IOException, javax.xml.transform.TransformerConfigurationException, javax.xml.transform.TransformerException
Transform a Document and return the transformed Node.- Throws:
javax.xml.parsers.ParserConfigurationException
org.xml.sax.SAXException
java.io.IOException
javax.xml.transform.TransformerConfigurationException
javax.xml.transform.TransformerException
-
transform
public static org.w3c.dom.Node transform(org.w3c.dom.Document inDoc, java.lang.String xslFileName) throws javax.xml.parsers.ParserConfigurationException, org.xml.sax.SAXException, java.io.IOException, javax.xml.transform.TransformerConfigurationException, javax.xml.transform.TransformerException
- Throws:
javax.xml.parsers.ParserConfigurationException
org.xml.sax.SAXException
java.io.IOException
javax.xml.transform.TransformerConfigurationException
javax.xml.transform.TransformerException
-
transform
public static org.w3c.dom.Node transform(org.w3c.dom.Document inDoc, java.io.Reader xslReader, java.lang.String[][] namevalueParameters) throws javax.xml.parsers.ParserConfigurationException, org.xml.sax.SAXException, java.io.IOException, javax.xml.transform.TransformerConfigurationException, javax.xml.transform.TransformerException
Transform a Document and return the transformed Node.- Throws:
javax.xml.parsers.ParserConfigurationException
org.xml.sax.SAXException
java.io.IOException
javax.xml.transform.TransformerConfigurationException
javax.xml.transform.TransformerException
-
transform
public static org.w3c.dom.Node transform(org.w3c.dom.Document inDoc, java.io.Reader xslReader) throws javax.xml.parsers.ParserConfigurationException, org.xml.sax.SAXException, java.io.IOException, javax.xml.transform.TransformerConfigurationException, javax.xml.transform.TransformerException
- Throws:
javax.xml.parsers.ParserConfigurationException
org.xml.sax.SAXException
java.io.IOException
javax.xml.transform.TransformerConfigurationException
javax.xml.transform.TransformerException
-
-