Class SimpleXpathEngine

  • All Implemented Interfaces:
    XMLConstants, XpathEngine, XSLTConstants

    public class SimpleXpathEngine
    extends java.lang.Object
    implements XpathEngine, XSLTConstants
    Simple class for accessing the Nodes matched by an Xpath expression, or evaluating the String value of an Xpath expression. Uses a copy-of or value-of XSL template (as appropriate) to execute the Xpath. This is not an efficient method for accessing XPaths but it is portable across underlying transform implementations. (Yes I know Jaxen is too, but this approach seemed to be the simplest thing that could possibly work...)
    • Constructor Detail

      • SimpleXpathEngine

        public SimpleXpathEngine()
    • Method Detail

      • getXSLTBase

        private java.lang.StringBuilder getXSLTBase()
        What every XSL transform needs
      • getCopyTransformation

        private java.lang.String getCopyTransformation​(java.lang.String select)
        Parameters:
        select - an xpath syntax select expression
        Returns:
        the copy-of transformation
      • getValueTransformation

        private java.lang.String getValueTransformation​(java.lang.String select)
        Parameters:
        select - an xpath syntax select expression
        Returns:
        the value-of transformation
      • performTransform

        private void performTransform​(java.lang.String xslt,
                                      org.w3c.dom.Document document,
                                      javax.xml.transform.Result result)
                               throws javax.xml.transform.TransformerException,
                                      ConfigurationException,
                                      XpathException
        Perform the actual transformation work required
        Parameters:
        xslt -
        document -
        result -
        Throws:
        XpathException
        javax.xml.transform.TransformerException
        ConfigurationException
      • getXPathResultNode

        protected org.w3c.dom.Node getXPathResultNode​(java.lang.String select,
                                                      org.w3c.dom.Document document)
                                               throws ConfigurationException,
                                                      javax.xml.transform.TransformerException,
                                                      XpathException
        Testable method to execute the copy-of transform and return the root node of the resulting Document.
        Parameters:
        select -
        document -
        Returns:
        the root node of the Document created by the copy-of transform.
        Throws:
        ConfigurationException
        javax.xml.transform.TransformerException
        XpathException
      • getXPathResultAsDocument

        protected org.w3c.dom.Document getXPathResultAsDocument​(java.lang.String select,
                                                                org.w3c.dom.Document document)
                                                         throws ConfigurationException,
                                                                javax.xml.transform.TransformerException,
                                                                XpathException
        Execute the copy-of transform and return the resulting Document. Used for XMLTestCase comparison
        Parameters:
        select -
        document -
        Returns:
        the Document created by the copy-of transform.
        Throws:
        ConfigurationException
        javax.xml.transform.TransformerException
        XpathException
      • getNamespaceDeclarations

        private java.lang.String getNamespaceDeclarations()
        returns namespace declarations for all namespaces known to the current context.