Class XPathRewriterBase
java.lang.Object
de.wwu.scdh.annotation.selection.rewriter.XPathRewriterBase
- Direct Known Subclasses:
XPathNormalizer,XPathRefinedByRFC5147CharSchemeBackwardMapper,XPathRefinedByRFC5147CharSchemeForwardMapper,XPathRefinedByRFC5147CharSchemeToTextBackwardMapper,XPathRefinedByRFC5147CharSchemeToTextForwardMapper
This class provides methods common to normalizers and mappers, that
operate on XPath selectors refined by RFC5147 character schemes.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionXPathRewriterBase(net.sf.saxon.s9api.XPathCompiler xPathCompiler, String xpath) Make a newXPathNormalizerfor aDOMResource. -
Method Summary
Modifier and TypeMethodDescriptionprotected final org.apache.commons.lang3.tuple.Pair<net.sf.saxon.s9api.XdmNode, Integer> getDeepTextNodeAtPositionStepOverEnd(S9ApiResource<? extends net.sf.saxon.s9api.XdmValue> resource, String xpath, int position) This is an implementation of the normalization step 1 for the modeMode.DEEP_NODE_STEP_OVER_END.protected final org.apache.commons.lang3.tuple.Pair<net.sf.saxon.s9api.XdmNode, Integer> getDeepTextNodeAtPositionStopAtEnd(S9ApiResource<? extends net.sf.saxon.s9api.XdmValue> resource, String xpath, int position) This is an implementation of the normalization step 1 for the modeMode.DEEP_NODE_STOP_AT_END.protected static intgetDepth(net.sf.saxon.s9api.XdmNode node) A utility method that gets the depth of a node by counting its ancestors.protected static intA utility method that gets the depth of a node of a pair of node and position like used in this module.getDescendantTextNodesWithPosition(net.sf.saxon.s9api.XdmNode fragment, int position) Helper method used by implementations of normalization stage 1, that search deep text nodes.protected final org.apache.commons.lang3.tuple.Pair<net.sf.saxon.s9api.XdmNode, Integer> getFirstNodeAtPosition(S9ApiResource<? extends net.sf.saxon.s9api.XdmValue> resource, String xpath, int position) The implementation of step 1 of the normalization algorithm in modeMode.FIRST.protected final org.apache.commons.lang3.tuple.Pair<net.sf.saxon.s9api.XdmNode, Integer> getFirstOfDeepestNodesAtPosition(S9ApiResource<? extends net.sf.saxon.s9api.XdmValue> resource, String xpath, int position) The implementation of step 1 of the normalization algorithm in modeMode.FIRST_OF_DEEPEST_NODES.protected final org.apache.commons.lang3.tuple.Pair<net.sf.saxon.s9api.XdmNode, Integer> getLastOfDeepestNodesAtPosition(S9ApiResource<? extends net.sf.saxon.s9api.XdmValue> resource, String xpath, int position) The implementation of step 1 of the normalization algorithm in modeMode.LAST_OF_DEEPEST_NODES.protected final net.sf.saxon.s9api.XdmNodegetNode(DOMResource resource, String xpath) Get the node from the DOM resource given by the XPath passed as argument.protected final net.sf.saxon.s9api.XdmNodegetNode(XdmValueResource resource, String xpath) Get the node from the XDM value resource given by the XPath passed as argument.protected final net.sf.saxon.s9api.XdmNodeGet the node from the DOM resource given by the XPath passed as argument.protected final org.apache.commons.lang3.tuple.Pair<net.sf.saxon.s9api.XdmNode, Integer> getSecondNodeAtPosition(S9ApiResource<? extends net.sf.saxon.s9api.XdmValue> resource, String xpath, int position) The implementation of step 1 of the normalization algorithm in modeMode.SECOND.protected org.apache.commons.lang3.tuple.Pair<net.sf.saxon.s9api.XdmNode, Integer> getTextNodeAtPosition(S9ApiResource<? extends net.sf.saxon.s9api.XdmValue> resource, String xpath, int position, Mode mode) This method run the first stage of the normalization process.getTextNodesWithPosition(net.sf.saxon.s9api.XdmNode fragment, int position) Helper method used by implementations of normalization stage 1, that search deep text nodes.getXPath()Returns the XPath the mapper instance was configured with.protected StringpathExpressionWithXPath(String xpath, net.sf.saxon.s9api.XdmNode node, boolean escaped) Get the path to theXdmNodegiven as parameter by using the provided XPath for generating a path expression.protected intposInNormalizedNode(net.sf.saxon.s9api.XdmNode textNode, int pos, net.sf.saxon.s9api.XdmNode fragment) Get the new position value based on the old one and the fragment selected by the normalized XPath.static StringpostProcForwardPaths(String xpath, RewriterConfig config) static StringreplaceEmptyNamespace(String xpath) static StringreplaceTextLeaf(String xpath) static StringreplaceTextLeaf(String xpath, RewriterConfig config) static StringreplaceTraceTextLeaf(String xpath) protected org.apache.commons.lang3.tuple.Pair<net.sf.saxon.s9api.XdmNode, Integer> reportNotFound(String xpath, int position) Report that the position is not found inside the selected fragment.protected StringA utility function for un-escaping XPaths.
-
Field Details
-
TRACE_TEXT_LEAF
-
TEXT_LEAF
-
EMPTY_NAMESPACE
-
xPathCompiler
protected final net.sf.saxon.s9api.XPathCompiler xPathCompiler -
xpath
-
-
Constructor Details
-
XPathRewriterBase
Make a newXPathNormalizerfor aDOMResource.
-
-
Method Details
-
replaceTraceTextLeaf
-
replaceEmptyNamespace
-
postProcForwardPaths
-
replaceTextLeaf
-
replaceTextLeaf
-
getXPath
Returns the XPath the mapper instance was configured with. -
getTextNodeAtPosition
protected org.apache.commons.lang3.tuple.Pair<net.sf.saxon.s9api.XdmNode,Integer> getTextNodeAtPosition(S9ApiResource<? extends net.sf.saxon.s9api.XdmValue> resource, String xpath, int position, Mode mode) throws SelectorException This method run the first stage of the normalization process. It gets the node where the pair of XPath and position of a character-scheme-refined XPath selector points to. Either this node is a text node, or the selector is invalid in the context of the current document. In general, the resulting position is not the same as the input position.There are several algorithms for this first stage of the normalization process and their return values differ for corner cases. The algorithm is selected by the
modeargument. SeeModefor possible values.A
SelectorExceptionis thrown if the xpath does not select exactly one node or if the position is not inside the fragment (subtree) selected by the xpath.- Parameters:
resource- theDOMResourceon the base of which the normalization is donexpath- the XPath part of the XPath selectorposition- the position following the character scheme of RFC5147mode- a normalization algorithm selected fromMode- Returns:
- a pair of node and position
- Throws:
SelectorException- if the XPath does not select exactly one node
-
getFirstNodeAtPosition
protected final org.apache.commons.lang3.tuple.Pair<net.sf.saxon.s9api.XdmNode,Integer> getFirstNodeAtPosition(S9ApiResource<? extends net.sf.saxon.s9api.XdmValue> resource, String xpath, int position) throws SelectorException The implementation of step 1 of the normalization algorithm in modeMode.FIRST.- Throws:
SelectorException
-
getSecondNodeAtPosition
protected final org.apache.commons.lang3.tuple.Pair<net.sf.saxon.s9api.XdmNode,Integer> getSecondNodeAtPosition(S9ApiResource<? extends net.sf.saxon.s9api.XdmValue> resource, String xpath, int position) throws SelectorException The implementation of step 1 of the normalization algorithm in modeMode.SECOND.- Throws:
SelectorException
-
getFirstOfDeepestNodesAtPosition
protected final org.apache.commons.lang3.tuple.Pair<net.sf.saxon.s9api.XdmNode,Integer> getFirstOfDeepestNodesAtPosition(S9ApiResource<? extends net.sf.saxon.s9api.XdmValue> resource, String xpath, int position) throws SelectorException The implementation of step 1 of the normalization algorithm in modeMode.FIRST_OF_DEEPEST_NODES.- Throws:
SelectorException
-
getLastOfDeepestNodesAtPosition
protected final org.apache.commons.lang3.tuple.Pair<net.sf.saxon.s9api.XdmNode,Integer> getLastOfDeepestNodesAtPosition(S9ApiResource<? extends net.sf.saxon.s9api.XdmValue> resource, String xpath, int position) throws SelectorException The implementation of step 1 of the normalization algorithm in modeMode.LAST_OF_DEEPEST_NODES.- Throws:
SelectorException
-
getDeepTextNodeAtPositionStopAtEnd
protected final org.apache.commons.lang3.tuple.Pair<net.sf.saxon.s9api.XdmNode,Integer> getDeepTextNodeAtPositionStopAtEnd(S9ApiResource<? extends net.sf.saxon.s9api.XdmValue> resource, String xpath, int position) throws SelectorException This is an implementation of the normalization step 1 for the modeMode.DEEP_NODE_STOP_AT_END.- Parameters:
resource- theDOMResourceon the base of which the normalization is donexpath- the XPath part of the XPath selectorposition- the position following the character scheme of RFC5147- Returns:
- a pair of node and position
- Throws:
SelectorException- if xpath does not evaluate to one node
-
getDeepTextNodeAtPositionStepOverEnd
protected final org.apache.commons.lang3.tuple.Pair<net.sf.saxon.s9api.XdmNode,Integer> getDeepTextNodeAtPositionStepOverEnd(S9ApiResource<? extends net.sf.saxon.s9api.XdmValue> resource, String xpath, int position) throws SelectorException This is an implementation of the normalization step 1 for the modeMode.DEEP_NODE_STEP_OVER_END.- Parameters:
resource- theDOMResourceon the base of which the normalization is donexpath- the XPath part of the XPath selectorposition- the position following the character scheme of RFC5147- Returns:
- a pair of node and position
- Throws:
SelectorException- if xpath does not get one node
-
getNode
protected final net.sf.saxon.s9api.XdmNode getNode(DOMResource resource, String xpath) throws SelectorException Get the node from the DOM resource given by the XPath passed as argument. If the XPath does not evaluate to a single node, this method raises anSelectorException.- Parameters:
resource- theDOMResourceon the base of which the normalization is donexpath- the XPath asString- Returns:
- an
XdmNodewhich the XPath points to - Throws:
SelectorException
-
getNode
protected final net.sf.saxon.s9api.XdmNode getNode(XdmValueResource resource, String xpath) throws SelectorException Get the node from the XDM value resource given by the XPath passed as argument. If the XPath does not evaluate to a single node, this method raises anSelectorException.- Parameters:
resource- theXdmValueResourceon the base of which the normalization is donexpath- the XPath asString- Returns:
- an
XdmNodewhich the XPath points to - Throws:
SelectorException
-
getNode
protected final net.sf.saxon.s9api.XdmNode getNode(net.sf.saxon.s9api.XdmValue value, String xpath) throws SelectorException Get the node from the DOM resource given by the XPath passed as argument. If the XPath does not evaluate to a single node, this method raises anSelectorException.- Throws:
SelectorException
-
getDescendantTextNodesWithPosition
protected final List<org.apache.commons.lang3.tuple.Pair<net.sf.saxon.s9api.XdmNode,Integer>> getDescendantTextNodesWithPosition(net.sf.saxon.s9api.XdmNode fragment, int position) Helper method used by implementations of normalization stage 1, that search deep text nodes. This return a list of all pairs of a node and a position, that contain the character scheme position inside a given fragment.This method collects all candidates in case of referential ambiguity. See
Mode.- Parameters:
fragment- asXdmNodeinside aDOMResourceposition- the RFC 5147 character scheme position inside the fragment
-
getTextNodesWithPosition
protected final List<org.apache.commons.lang3.tuple.Pair<net.sf.saxon.s9api.XdmNode,Integer>> getTextNodesWithPosition(net.sf.saxon.s9api.XdmNode fragment, int position) Helper method used by implementations of normalization stage 1, that search deep text nodes. This return a list of all pairs of a node and a position, that contain the character scheme position inside a given fragment, or in the first text node before or after it.This method collects all candidates in case of referential ambiguity. See
Mode.- Parameters:
fragment- asXdmNodeinside aDOMResourceposition- the RFC 5147 character scheme position inside the fragment
-
posInNormalizedNode
protected int posInNormalizedNode(net.sf.saxon.s9api.XdmNode textNode, int pos, net.sf.saxon.s9api.XdmNode fragment) throws SelectorException Get the new position value based on the old one and the fragment selected by the normalized XPath.- Parameters:
textNode- the text node asXdmNodegotten from step 1pos- the position gotten form step 1fragment- theXdmNodeselected by the XPath resulting from step 2- Returns:
- the position from step 2
- Throws:
SelectorException
-
reportNotFound
protected org.apache.commons.lang3.tuple.Pair<net.sf.saxon.s9api.XdmNode,Integer> reportNotFound(String xpath, int position) throws SelectorException Report that the position is not found inside the selected fragment.- Parameters:
xpath- XPath expression selecting a fragment from aDOMResourceposition- the character scheme position inside the fragment- Throws:
SelectorException
-
getDepth
protected static int getDepth(net.sf.saxon.s9api.XdmNode node) A utility method that gets the depth of a node by counting its ancestors. -
getDepth
protected static int getDepth(org.apache.commons.lang3.tuple.Pair<net.sf.saxon.s9api.XdmNode, Integer> pair) A utility method that gets the depth of a node of a pair of node and position like used in this module. -
unespace
A utility function for un-escaping XPaths. -
pathExpressionWithXPath
protected String pathExpressionWithXPath(String xpath, net.sf.saxon.s9api.XdmNode node, boolean escaped) throws SelectorException Get the path to theXdmNodegiven as parameter by using the provided XPath for generating a path expression.This is typically used in step 2 of normalization.
- Parameters:
xpath- the XPath for generating a path expression, e.g., fn:xpath()node- theXdmNodefor which to generate the path expressionescaped- whether the generated path expression is to be escaped- Throws:
SelectorException
-