本文整理汇总了Java中org.apache.xpath.XPathContext.popCurrentNode方法的典型用法代码示例。如果您正苦于以下问题:Java XPathContext.popCurrentNode方法的具体用法?Java XPathContext.popCurrentNode怎么用?Java XPathContext.popCurrentNode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.xpath.XPathContext
的用法示例。
在下文中一共展示了XPathContext.popCurrentNode方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: executeChildTemplates
import org.apache.xpath.XPathContext; //导入方法依赖的package包/类
/**
* Execute each of the children of a template element. This method
* is only for extension use.
*
* @param elem The ElemTemplateElement that contains the children
* that should execute.
* NEEDSDOC @param context
* @param mode The current mode.
* @param handler The ContentHandler to where the result events
* should be fed.
*
* @throws TransformerException
* @xsl.usage advanced
*/
public void executeChildTemplates(
ElemTemplateElement elem, org.w3c.dom.Node context, QName mode, ContentHandler handler)
throws TransformerException
{
XPathContext xctxt = m_xcontext;
try
{
if(null != mode)
pushMode(mode);
xctxt.pushCurrentNode(xctxt.getDTMHandleFromNode(context));
executeChildTemplates(elem, handler);
}
finally
{
xctxt.popCurrentNode();
// I'm not sure where or why this was here. It is clearly in
// error though, without a corresponding pushMode().
if (null != mode)
popMode();
}
}
示例2: getMatchScore
import org.apache.xpath.XPathContext; //导入方法依赖的package包/类
/**
* Get the match score of the given node.
*
* @param xctxt The XPath runtime context.
* @param context The node to be tested.
*
* @return {@link org.apache.xpath.patterns.NodeTest#SCORE_NODETEST},
* {@link org.apache.xpath.patterns.NodeTest#SCORE_NONE},
* {@link org.apache.xpath.patterns.NodeTest#SCORE_NSWILD},
* {@link org.apache.xpath.patterns.NodeTest#SCORE_QNAME}, or
* {@link org.apache.xpath.patterns.NodeTest#SCORE_OTHER}.
*
* @throws javax.xml.transform.TransformerException
*/
public double getMatchScore(XPathContext xctxt, int context)
throws javax.xml.transform.TransformerException
{
xctxt.pushCurrentNode(context);
xctxt.pushCurrentExpressionNode(context);
try
{
XObject score = execute(xctxt);
return score.num();
}
finally
{
xctxt.popCurrentNode();
xctxt.popCurrentExpressionNode();
}
// return XPath.MATCH_SCORE_NONE;
}
示例3: executeRelativePathPattern
import org.apache.xpath.XPathContext; //导入方法依赖的package包/类
/**
* Execute the match pattern step relative to another step.
*
*
* @param xctxt The XPath runtime context.
* @param dtm The DTM of the current node.
* @param currentNode The current node context.
*
* @return {@link org.apache.xpath.patterns.NodeTest#SCORE_NODETEST},
* {@link org.apache.xpath.patterns.NodeTest#SCORE_NONE},
* {@link org.apache.xpath.patterns.NodeTest#SCORE_NSWILD},
* {@link org.apache.xpath.patterns.NodeTest#SCORE_QNAME}, or
* {@link org.apache.xpath.patterns.NodeTest#SCORE_OTHER}.
*
* @throws javax.xml.transform.TransformerException
*/
protected final XObject executeRelativePathPattern(
XPathContext xctxt, DTM dtm, int currentNode)
throws javax.xml.transform.TransformerException
{
XObject score = NodeTest.SCORE_NONE;
int context = currentNode;
DTMAxisTraverser traverser;
traverser = dtm.getAxisTraverser(m_axis);
for (int relative = traverser.first(context); DTM.NULL != relative;
relative = traverser.next(context, relative))
{
try
{
xctxt.pushCurrentNode(relative);
score = execute(xctxt);
if (score != NodeTest.SCORE_NONE)
break;
}
finally
{
xctxt.popCurrentNode();
}
}
return score;
}
示例4: acceptNode
import org.apache.xpath.XPathContext; //导入方法依赖的package包/类
/**
* Test whether a specified node is visible in the logical view of a
* TreeWalker or NodeIterator. This function will be called by the
* implementation of TreeWalker and NodeIterator; it is not intended to
* be called directly from user code.
* @param n The node to check to see if it passes the filter or not.
* @return a constant to determine whether the node is accepted,
* rejected, or skipped, as defined above .
*/
public short acceptNode(int n)
{
XPathContext xctxt = getXPathContext();
try
{
xctxt.pushCurrentNode(n);
for (int i = 0; i < m_nodeTests.length; i++)
{
PredicatedNodeTest pnt = m_nodeTests[i];
XObject score = pnt.execute(xctxt, n);
if (score != NodeTest.SCORE_NONE)
{
// Note that we are assuming there are no positional predicates!
if (pnt.getPredicateCount() > 0)
{
if (pnt.executePredicates(n, xctxt))
return DTMIterator.FILTER_ACCEPT;
}
else
return DTMIterator.FILTER_ACCEPT;
}
}
}
catch (javax.xml.transform.TransformerException se)
{
// TODO: Fix this.
throw new RuntimeException(se.getMessage());
}
finally
{
xctxt.popCurrentNode();
}
return DTMIterator.FILTER_SKIP;
}
示例5: acceptNode
import org.apache.xpath.XPathContext; //导入方法依赖的package包/类
/**
* Test whether a specified node is visible in the logical view of a
* TreeWalker or NodeIterator. This function will be called by the
* implementation of TreeWalker and NodeIterator; it is not intended to
* be called directly from user code.
* @param n The node to check to see if it passes the filter or not.
* @return a constant to determine whether the node is accepted,
* rejected, or skipped, as defined above .
*/
public short acceptNode(int n)
{
XPathContext xctxt = m_lpi.getXPathContext();
try
{
xctxt.pushCurrentNode(n);
XObject score = execute(xctxt, n);
// System.out.println("\n::acceptNode - score: "+score.num()+"::");
if (score != NodeTest.SCORE_NONE)
{
if (getPredicateCount() > 0)
{
countProximityPosition(0);
if (!executePredicates(n, xctxt))
return DTMIterator.FILTER_SKIP;
}
return DTMIterator.FILTER_ACCEPT;
}
}
catch (javax.xml.transform.TransformerException se)
{
// TODO: Fix this.
throw new RuntimeException(se.getMessage());
}
finally
{
xctxt.popCurrentNode();
}
return DTMIterator.FILTER_SKIP;
}
示例6: execute
import org.apache.xpath.XPathContext; //导入方法依赖的package包/类
/**
* The xsl:copy element provides an easy way of copying the current node.
* Executing this function creates a copy of the current node into the
* result tree.
* <p>The namespace nodes of the current node are automatically
* copied as well, but the attributes and children of the node are not
* automatically copied. The content of the xsl:copy element is a
* template for the attributes and children of the created node;
* the content is instantiated only for nodes of types that can have
* attributes or children (i.e. root nodes and element nodes).</p>
* <p>The root node is treated specially because the root node of the
* result tree is created implicitly. When the current node is the
* root node, xsl:copy will not create a root node, but will just use
* the content template.</p>
*
* @param transformer non-null reference to the the current transform-time state.
*
* @throws TransformerException
*/
public void execute(
TransformerImpl transformer)
throws TransformerException
{
XPathContext xctxt = transformer.getXPathContext();
try
{
int sourceNode = xctxt.getCurrentNode();
xctxt.pushCurrentNode(sourceNode);
DTM dtm = xctxt.getDTM(sourceNode);
short nodeType = dtm.getNodeType(sourceNode);
if ((DTM.DOCUMENT_NODE != nodeType) && (DTM.DOCUMENT_FRAGMENT_NODE != nodeType))
{
SerializationHandler rthandler = transformer.getSerializationHandler();
// TODO: Process the use-attribute-sets stuff
ClonerToResultTree.cloneToResultTree(sourceNode, nodeType, dtm,
rthandler, false);
if (DTM.ELEMENT_NODE == nodeType)
{
super.execute(transformer);
SerializerUtils.processNSDecls(rthandler, sourceNode, nodeType, dtm);
transformer.executeChildTemplates(this, true);
String ns = dtm.getNamespaceURI(sourceNode);
String localName = dtm.getLocalName(sourceNode);
transformer.getResultTreeHandler().endElement(ns, localName,
dtm.getNodeName(sourceNode));
}
}
else
{
super.execute(transformer);
transformer.executeChildTemplates(this, true);
}
}
catch(org.xml.sax.SAXException se)
{
throw new TransformerException(se);
}
finally
{
xctxt.popCurrentNode();
}
}
示例7: startNode
import org.apache.xpath.XPathContext; //导入方法依赖的package包/类
/**
* Start traversal of the tree at the given node
*
*
* @param node Starting node for traversal
*
* @throws TransformerException
*/
protected void startNode(int node) throws org.xml.sax.SAXException
{
XPathContext xcntxt = m_transformer.getXPathContext();
try
{
if (DTM.ELEMENT_NODE == m_dtm.getNodeType(node))
{
xcntxt.pushCurrentNode(node);
if(m_startNode != node)
{
super.startNode(node);
}
else
{
String elemName = m_dtm.getNodeName(node);
String localName = m_dtm.getLocalName(node);
String namespace = m_dtm.getNamespaceURI(node);
//xcntxt.pushCurrentNode(node);
// SAX-like call to allow adding attributes afterwards
m_handler.startElement(namespace, localName, elemName);
boolean hasNSDecls = false;
DTM dtm = m_dtm;
for (int ns = dtm.getFirstNamespaceNode(node, true);
DTM.NULL != ns; ns = dtm.getNextNamespaceNode(node, ns, true))
{
SerializerUtils.ensureNamespaceDeclDeclared(m_handler,dtm, ns);
}
for (int attr = dtm.getFirstAttribute(node);
DTM.NULL != attr; attr = dtm.getNextAttribute(attr))
{
SerializerUtils.addAttribute(m_handler, attr);
}
}
}
else
{
xcntxt.pushCurrentNode(node);
super.startNode(node);
xcntxt.popCurrentNode();
}
}
catch(javax.xml.transform.TransformerException te)
{
throw new org.xml.sax.SAXException(te);
}
}
示例8: getProximityPosition
import org.apache.xpath.XPathContext; //导入方法依赖的package包/类
/**
* Get the current sub-context position. In order to do the
* reverse axes count, for the moment this re-searches the axes
* up to the predicate. An optimization on this is to cache
* the nodes searched, but, for the moment, this case is probably
* rare enough that the added complexity isn't worth it.
*
* @param predicateIndex The predicate index of the proximity position.
*
* @return The pridicate index, or -1.
*/
protected int getProximityPosition(int predicateIndex)
{
if(!isReverseAxes())
return super.getProximityPosition(predicateIndex);
// A negative predicate index seems to occur with
// (preceding-sibling::*|following-sibling::*)/ancestor::*[position()]/*[position()]
// -sb
if(predicateIndex < 0)
return -1;
if (m_proximityPositions[predicateIndex] <= 0)
{
XPathContext xctxt = getXPathContext();
try
{
OneStepIterator clone = (OneStepIterator) this.clone();
int root = getRoot();
xctxt.pushCurrentNode(root);
clone.setRoot(root, xctxt);
// clone.setPredicateCount(predicateIndex);
clone.m_predCount = predicateIndex;
// Count 'em all
int count = 1;
int next;
while (DTM.NULL != (next = clone.nextNode()))
{
count++;
}
m_proximityPositions[predicateIndex] += count;
}
catch (CloneNotSupportedException cnse)
{
// can't happen
}
finally
{
xctxt.popCurrentNode();
}
}
return m_proximityPositions[predicateIndex];
}
示例9: getLength
import org.apache.xpath.XPathContext; //导入方法依赖的package包/类
/**
* The number of nodes in the list. The range of valid child node indices
* is 0 to <code>length-1</code> inclusive.
*
* @return The number of nodes in the list, always greater or equal to zero.
*/
public int getLength()
{
if(!isReverseAxes())
return super.getLength();
// Tell if this is being called from within a predicate.
boolean isPredicateTest = (this == m_execContext.getSubContextList());
// And get how many total predicates are part of this step.
int predCount = getPredicateCount();
// If we have already calculated the length, and the current predicate
// is the first predicate, then return the length. We don't cache
// the anything but the length of the list to the first predicate.
if (-1 != m_length && isPredicateTest && m_predicateIndex < 1)
return m_length;
int count = 0;
XPathContext xctxt = getXPathContext();
try
{
OneStepIterator clone = (OneStepIterator) this.cloneWithReset();
int root = getRoot();
xctxt.pushCurrentNode(root);
clone.setRoot(root, xctxt);
clone.m_predCount = m_predicateIndex;
int next;
while (DTM.NULL != (next = clone.nextNode()))
{
count++;
}
}
catch (CloneNotSupportedException cnse)
{
// can't happen
}
finally
{
xctxt.popCurrentNode();
}
if (isPredicateTest && m_predicateIndex < 1)
m_length = count;
return count;
}
示例10: acceptNode
import org.apache.xpath.XPathContext; //导入方法依赖的package包/类
/**
* Test whether a specified node is visible in the logical view of a
* TreeWalker or NodeIterator. This function will be called by the
* implementation of TreeWalker and NodeIterator; it is not intended to
* be called directly from user code.
* @param n The node to check to see if it passes the filter or not.
* @return a constant to determine whether the node is accepted,
* rejected, or skipped, as defined above .
*/
public short acceptNode(int n, XPathContext xctxt)
{
try
{
xctxt.pushCurrentNode(n);
xctxt.pushIteratorRoot(m_context);
if(DEBUG)
{
System.out.println("traverser: "+m_traverser);
System.out.print("node: "+n);
System.out.println(", "+m_cdtm.getNodeName(n));
// if(m_cdtm.getNodeName(n).equals("near-east"))
System.out.println("pattern: "+m_pattern.toString());
m_pattern.debugWhatToShow(m_pattern.getWhatToShow());
}
XObject score = m_pattern.execute(xctxt);
if(DEBUG)
{
// System.out.println("analysis: "+Integer.toBinaryString(m_analysis));
System.out.println("score: "+score);
System.out.println("skip: "+(score == NodeTest.SCORE_NONE));
}
// System.out.println("\n::acceptNode - score: "+score.num()+"::");
return (score == NodeTest.SCORE_NONE) ? DTMIterator.FILTER_SKIP
: DTMIterator.FILTER_ACCEPT;
}
catch (javax.xml.transform.TransformerException se)
{
// TODO: Fix this.
throw new RuntimeException(se.getMessage());
}
finally
{
xctxt.popCurrentNode();
xctxt.popIteratorRoot();
}
}
示例11: executeFilterExpr
import org.apache.xpath.XPathContext; //导入方法依赖的package包/类
/**
* Execute the expression. Meant for reuse by other FilterExpr iterators
* that are not derived from this object.
*/
public static XNodeSet executeFilterExpr(int context, XPathContext xctxt,
PrefixResolver prefixResolver,
boolean isTopLevel,
int stackFrame,
Expression expr )
throws org.apache.xml.utils.WrappedRuntimeException
{
PrefixResolver savedResolver = xctxt.getNamespaceContext();
XNodeSet result = null;
try
{
xctxt.pushCurrentNode(context);
xctxt.setNamespaceContext(prefixResolver);
// The setRoot operation can take place with a reset operation,
// and so we may not be in the context of LocPathIterator#nextNode,
// so we have to set up the variable context, execute the expression,
// and then restore the variable context.
if (isTopLevel)
{
// System.out.println("calling m_expr.execute(getXPathContext())");
VariableStack vars = xctxt.getVarStack();
// These three statements need to be combined into one operation.
int savedStart = vars.getStackFrame();
vars.setStackFrame(stackFrame);
result = (org.apache.xpath.objects.XNodeSet) expr.execute(xctxt);
result.setShouldCacheNodes(true);
// These two statements need to be combined into one operation.
vars.setStackFrame(savedStart);
}
else
result = (org.apache.xpath.objects.XNodeSet) expr.execute(xctxt);
}
catch (javax.xml.transform.TransformerException se)
{
// TODO: Fix...
throw new org.apache.xml.utils.WrappedRuntimeException(se);
}
finally
{
xctxt.popCurrentNode();
xctxt.setNamespaceContext(savedResolver);
}
return result;
}