Package mondrian.tui
Class XmlUtil
- java.lang.Object
-
- mondrian.tui.XmlUtil
-
public class XmlUtil extends 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 classXmlUtil.ResolverThis can be extened to have a map from publicId/systemId to InputSource.static classXmlUtil.SaxErrorHandlerError handler plus helper methods.
-
Field Summary
Fields Modifier and Type Field Description static StringDEFER_NODE_EXPANSIONstatic StringFULL_SCHEMA_VALIDATION_FEATURE_IDstatic StringLINE_SEPstatic StringNAMESPACES_FEATURE_IDstatic StringSCHEMA_LOCATIONstatic StringSCHEMA_VALIDATION_FEATURE_IDstatic StringSOAP_PREFIXstatic StringVALIDATION_FEATURE_IDstatic StringXMLNSstatic StringXSD_PREFIX
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Node[]convertToNodes(XPathResult xpathResult)Convert an XPathResult to an array of Nodes.static StringconvertToString(XPathResult xpathResult, boolean prettyPrint)Convert an XPathResult object to String.static DocumentcreateContextDocument(String[][] nsArray)Create a context document for use in performing XPath operations.static StringgetNamespaceAttributeValue(Document doc)This is used to get a Document's namespace attribute value.static org.apache.xerces.parsers.DOMParsergetParser(String schemaLocationPropertyValue, EntityResolver entityResolver, boolean validate)Get your non-cached DOM parser which can be configured to do schema based validation of the instance Document.static StringgetSoapXmlaXds2xd(String xmlaPrefix)This is the xslt that can extract the "data" part of a SOAP XMLA response.static StringgetSoapXmlaXds2xs(String xmlaPrefix)This is the xslt that can extract the "schema" part of a SOAP XMLA response.static TransformerFactorygetTransformerFactory()static StringgetXercesVersion()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 StringgetXercesVersionNumberString()Get the number part of the Xerces Version string.static StringgetXmlaXds2xd(String ns)This is the xslt that can extract the "data" part of a XMLA response.static StringgetXmlaXds2xs(String ns)This is the xslt that can extract the "schema" part of a XMLA response.static StringmakeRootPathInSoapBody()static StringmakeRootPathInSoapBody(String xmlaPrefix, String xsdPrefix)static StringmakeSoapPath()static StringmakeSoapPath(String prefix)static DocumentnewDocument(Node firstElement, boolean deepcopy)static Documentparse(byte[] bytes)Parse a byte array into a Document (no validation).static Documentparse(File file)static Documentparse(InputStream in)Parse a stream into a Document (no validation).static DocumentparseString(String s)Parse a String into a Document (no validation).static XPathResultselect(Node contextNode, String xpath, Node namespaceNode)static Node[]selectAsNodes(Node node, String xpath)static Node[]selectAsNodes(Node node, String xpath, Node namespaceNode)static StringselectAsString(Node node, String xpath)static StringselectAsString(Node node, String xpath, Node namespaceNode)static booleansupportsValidation()Returns whether the XML parser supports validation.static StringtoString(Node node, boolean prettyPrint)Convert a Node to a String.static Nodetransform(Document inDoc, Reader xslReader)static Nodetransform(Document inDoc, Reader xslReader, String[][] namevalueParameters)Transform a Document and return the transformed Node.static Nodetransform(Document inDoc, String xslFileName)static Nodetransform(Document inDoc, String xslFileName, String[][] namevalueParameters)Transform a Document and return the transformed Node.static voidvalidate(String docStr, String schemaLocationPropertyValue, EntityResolver resolver)static voidvalidate(Document doc, String schemaLocationPropertyValue, EntityResolver resolver)
-
-
-
Field Detail
-
LINE_SEP
public static final String LINE_SEP
-
SOAP_PREFIX
public static final String SOAP_PREFIX
- See Also:
- Constant Field Values
-
XSD_PREFIX
public static final String XSD_PREFIX
- See Also:
- Constant Field Values
-
XMLNS
public static final String XMLNS
- See Also:
- Constant Field Values
-
NAMESPACES_FEATURE_ID
public static final String NAMESPACES_FEATURE_ID
- See Also:
- Constant Field Values
-
VALIDATION_FEATURE_ID
public static final String VALIDATION_FEATURE_ID
- See Also:
- Constant Field Values
-
SCHEMA_VALIDATION_FEATURE_ID
public static final String SCHEMA_VALIDATION_FEATURE_ID
- See Also:
- Constant Field Values
-
FULL_SCHEMA_VALIDATION_FEATURE_ID
public static final String FULL_SCHEMA_VALIDATION_FEATURE_ID
- See Also:
- Constant Field Values
-
DEFER_NODE_EXPANSION
public static final String DEFER_NODE_EXPANSION
- See Also:
- Constant Field Values
-
SCHEMA_LOCATION
public static final String SCHEMA_LOCATION
- See Also:
- Constant Field Values
-
-
Method Detail
-
getSoapXmlaXds2xd
public static final String getSoapXmlaXds2xd(String xmlaPrefix)
This is the xslt that can extract the "data" part of a SOAP XMLA response.
-
getSoapXmlaXds2xs
public static final String getSoapXmlaXds2xs(String xmlaPrefix)
This is the xslt that can extract the "schema" part of a SOAP XMLA response.
-
getXmlaXds2xd
public static final String getXmlaXds2xd(String ns)
This is the xslt that can extract the "data" part of a XMLA response.
-
getXmlaXds2xs
public static final String getXmlaXds2xs(String ns)
This is the xslt that can extract the "schema" part of a XMLA response.
-
getParser
public static org.apache.xerces.parsers.DOMParser getParser(String schemaLocationPropertyValue, EntityResolver entityResolver, boolean validate) throws SAXNotRecognizedException, SAXNotSupportedException
Get your non-cached DOM parser which can be configured to do schema based validation of the instance Document.
-
parseString
public static Document parseString(String s) throws SAXException, IOException
Parse a String into a Document (no validation).- Throws:
SAXExceptionIOException
-
parse
public static Document parse(byte[] bytes) throws SAXException, IOException
Parse a byte array into a Document (no validation).- Throws:
SAXExceptionIOException
-
parse
public static Document parse(File file) throws SAXException, IOException
- Throws:
SAXExceptionIOException
-
parse
public static Document parse(InputStream in) throws SAXException, IOException
Parse a stream into a Document (no validation).- Throws:
SAXExceptionIOException
-
createContextDocument
public static Document createContextDocument(String[][] nsArray) throws SAXException, 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:
SAXExceptionIOException
-
makeSoapPath
public static String makeSoapPath()
-
makeRootPathInSoapBody
public static String makeRootPathInSoapBody()
-
makeRootPathInSoapBody
public static String makeRootPathInSoapBody(String xmlaPrefix, String xsdPrefix)
-
selectAsString
public static String selectAsString(Node node, String xpath) throws XPathException
- Throws:
XPathException
-
selectAsString
public static String selectAsString(Node node, String xpath, Node namespaceNode) throws XPathException
- Throws:
XPathException
-
selectAsNodes
public static Node[] selectAsNodes(Node node, String xpath) throws XPathException
- Throws:
XPathException
-
selectAsNodes
public static Node[] selectAsNodes(Node node, String xpath, Node namespaceNode) throws XPathException
- Throws:
XPathException
-
select
public static XPathResult select(Node contextNode, String xpath, Node namespaceNode) throws XPathException
- Throws:
XPathException
-
convertToString
public static String convertToString(XPathResult xpathResult, boolean prettyPrint)
Convert an XPathResult object to String.
-
convertToNodes
public static Node[] convertToNodes(XPathResult xpathResult)
Convert an XPathResult to an array of Nodes.
-
getXercesVersion
public static String getXercesVersion()
Get the Xerces version being used.- Returns:
- Xerces version being used
-
getXercesVersionNumberString
public static 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(Document doc, String schemaLocationPropertyValue, EntityResolver resolver) throws IOException, SAXException
- Throws:
IOExceptionSAXException
-
validate
public static void validate(String docStr, String schemaLocationPropertyValue, EntityResolver resolver) throws IOException, SAXException
- Throws:
IOExceptionSAXException
-
getNamespaceAttributeValue
public static String getNamespaceAttributeValue(Document doc)
This is used to get a Document's namespace attribute value.
-
getTransformerFactory
public static TransformerFactory getTransformerFactory() throws TransformerFactoryConfigurationError
-
transform
public static Node transform(Document inDoc, String xslFileName, String[][] namevalueParameters) throws ParserConfigurationException, SAXException, IOException, TransformerConfigurationException, TransformerException
Transform a Document and return the transformed Node.
-
transform
public static Node transform(Document inDoc, String xslFileName) throws ParserConfigurationException, SAXException, IOException, TransformerConfigurationException, TransformerException
-
transform
public static Node transform(Document inDoc, Reader xslReader, String[][] namevalueParameters) throws ParserConfigurationException, SAXException, IOException, TransformerConfigurationException, TransformerException
Transform a Document and return the transformed Node.
-
transform
public static Node transform(Document inDoc, Reader xslReader) throws ParserConfigurationException, SAXException, IOException, TransformerConfigurationException, TransformerException
-
-