本文整理汇总了Java中org.apache.xpath.XPathContext.getCurrentNode方法的典型用法代码示例。如果您正苦于以下问题:Java XPathContext.getCurrentNode方法的具体用法?Java XPathContext.getCurrentNode怎么用?Java XPathContext.getCurrentNode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.xpath.XPathContext
的用法示例。
在下文中一共展示了XPathContext.getCurrentNode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: execute
import org.apache.xpath.XPathContext; //导入方法依赖的package包/类
/**
* Generate the EXSLT function return value, and assign it to the variable
* index slot assigned for it in ElemExsltFunction compose().
*
*/
public void execute(TransformerImpl transformer) throws TransformerException
{
XPathContext context = transformer.getXPathContext();
// Verify that result has not already been set by another result
// element. Recursion is allowed: intermediate results are cleared
// in the owner ElemExsltFunction execute().
if (transformer.currentFuncResultSeen()) {
throw new TransformerException("An EXSLT function cannot set more than one result!");
}
int sourceNode = context.getCurrentNode();
// Set the return value;
XObject var = getValue(transformer, sourceNode);
transformer.popCurrentFuncResult();
transformer.pushCurrentFuncResult(var);
}
示例2: executeCharsToContentHandler
import org.apache.xpath.XPathContext; //导入方法依赖的package包/类
/**
* Execute an expression in the XPath runtime context, and return the
* result of the expression.
*
*
* @param xctxt The XPath runtime context.
* @param handler The target content handler.
*
* @return The result of the expression in the form of a <code>XObject</code>.
*
* @throws javax.xml.transform.TransformerException if a runtime exception
* occurs.
* @throws org.xml.sax.SAXException
*/
public void executeCharsToContentHandler(
XPathContext xctxt, org.xml.sax.ContentHandler handler)
throws javax.xml.transform.TransformerException,
org.xml.sax.SAXException
{
LocPathIterator clone = (LocPathIterator)m_clones.getInstance();
int current = xctxt.getCurrentNode();
clone.setRoot(current, xctxt);
int node = clone.nextNode();
DTM dtm = clone.getDTM(node);
clone.detach();
if(node != DTM.NULL)
{
dtm.dispatchCharactersEvents(node, handler, false);
}
}
示例3: getArg0AsString
import org.apache.xpath.XPathContext; //导入方法依赖的package包/类
/**
* Execute the first argument expression that is expected to return a
* string. If the argument is null, then get the string value from the
* current context node.
*
* @param xctxt Runtime XPath context.
*
* @return The string value of the first argument, or the string value of the
* current context node if the first argument is null.
*
* @throws javax.xml.transform.TransformerException if an error occurs while
* executing the argument expression.
*/
protected XMLString getArg0AsString(XPathContext xctxt)
throws javax.xml.transform.TransformerException
{
if(null == m_arg0)
{
int currentNode = xctxt.getCurrentNode();
if(DTM.NULL == currentNode)
return XString.EMPTYSTRING;
else
{
DTM dtm = xctxt.getDTM(currentNode);
return dtm.getStringValue(currentNode);
}
}
else
return m_arg0.execute(xctxt).xstr();
}
示例4: getArg0AsNumber
import org.apache.xpath.XPathContext; //导入方法依赖的package包/类
/**
* Execute the first argument expression that is expected to return a
* number. If the argument is null, then get the number value from the
* current context node.
*
* @param xctxt Runtime XPath context.
*
* @return The number value of the first argument, or the number value of the
* current context node if the first argument is null.
*
* @throws javax.xml.transform.TransformerException if an error occurs while
* executing the argument expression.
*/
protected double getArg0AsNumber(XPathContext xctxt)
throws javax.xml.transform.TransformerException
{
if(null == m_arg0)
{
int currentNode = xctxt.getCurrentNode();
if(DTM.NULL == currentNode)
return 0;
else
{
DTM dtm = xctxt.getDTM(currentNode);
XMLString str = dtm.getStringValue(currentNode);
return str.toDouble();
}
}
else
return m_arg0.execute(xctxt).num();
}
示例5: execute
import org.apache.xpath.XPathContext; //导入方法依赖的package包/类
/**
* Conditionally execute a sub-template.
* The expression is evaluated and the resulting object is converted
* to a boolean as if by a call to the boolean function. If the result
* is true, then the content template is instantiated; otherwise, nothing
* is created.
*
* @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();
int sourceNode = xctxt.getCurrentNode();
if (m_test.bool(xctxt, sourceNode, this)) {
transformer.executeChildTemplates(this, true);
}
}
示例6: execute
import org.apache.xpath.XPathContext; //导入方法依赖的package包/类
/**
* Test a node to see if it matches the given node test.
*
* @param xctxt XPath runtime 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
*/
public XObject execute(XPathContext xctxt)
throws javax.xml.transform.TransformerException
{
int context = xctxt.getCurrentNode();
DTMIterator nl = m_functionExpr.asIterator(xctxt, context);
XNumber score = SCORE_NONE;
if (null != nl)
{
int n;
while (DTM.NULL != (n = nl.nextNode()))
{
score = (n == context) ? SCORE_OTHER : SCORE_NONE;
if (score == SCORE_OTHER)
{
context = n;
break;
}
}
nl.detach();
}
return score;
}
示例7: asNode
import org.apache.xpath.XPathContext; //导入方法依赖的package包/类
/**
* Return the first node out of the nodeset, if this expression is
* a nodeset expression. This is the default implementation for
* nodesets. Derived classes should try and override this and return a
* value without having to do a clone operation.
* @param xctxt The XPath runtime context.
* @return the first node out of the nodeset, or DTM.NULL.
*/
public int asNode(XPathContext xctxt)
throws javax.xml.transform.TransformerException
{
DTMIterator iter = (DTMIterator)m_clones.getInstance();
int current = xctxt.getCurrentNode();
iter.setRoot(current, xctxt);
int next = iter.nextNode();
// m_clones.freeInstance(iter);
iter.detach();
return next;
}
示例8: asNode
import org.apache.xpath.XPathContext; //导入方法依赖的package包/类
/**
* Return the first node out of the nodeset, if this expression is
* a nodeset expression. This is the default implementation for
* nodesets.
* <p>WARNING: Do not mutate this class from this function!</p>
* @param xctxt The XPath runtime context.
* @return the first node out of the nodeset, or DTM.NULL.
*/
public int asNode(XPathContext xctxt)
throws javax.xml.transform.TransformerException
{
int current = xctxt.getCurrentNode();
DTM dtm = xctxt.getDTM(current);
return dtm.getFirstChild(current);
}
示例9: asNode
import org.apache.xpath.XPathContext; //导入方法依赖的package包/类
/**
* Return the first node out of the nodeset, if this expression is
* a nodeset expression. This is the default implementation for
* nodesets.
* <p>WARNING: Do not mutate this class from this function!</p>
* @param xctxt The XPath runtime context.
* @return the first node out of the nodeset, or DTM.NULL.
*/
public int asNode(XPathContext xctxt)
throws javax.xml.transform.TransformerException
{
if(getPredicateCount() > 0)
return super.asNode(xctxt);
int current = xctxt.getCurrentNode();
DTM dtm = xctxt.getDTM(current);
DTMAxisTraverser traverser = dtm.getAxisTraverser(m_axis);
String localName = getLocalName();
String namespace = getNamespace();
int what = m_whatToShow;
// System.out.print(" (DescendantIterator) ");
// System.out.println("what: ");
// NodeTest.debugWhatToShow(what);
if(DTMFilter.SHOW_ALL == what
|| localName == NodeTest.WILD
|| namespace == NodeTest.WILD)
{
return traverser.first(current);
}
else
{
int type = getNodeTypeTest(what);
int extendedType = dtm.getExpandedTypeID(namespace, localName, type);
return traverser.first(current, extendedType);
}
}
示例10: execute
import org.apache.xpath.XPathContext; //导入方法依赖的package包/类
/**
* Execute the function. The function must return
* a valid object.
* @param xctxt The current execution context.
* @return A valid XObject.
*
* @throws javax.xml.transform.TransformerException
*/
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
{
String name = m_arg0.execute(xctxt).str();
int context = xctxt.getCurrentNode();
DTM dtm = xctxt.getDTM(context);
int doc = dtm.getDocument();
String uri = dtm.getUnparsedEntityURI(name);
return new XString(uri);
}
示例11: execute
import org.apache.xpath.XPathContext; //导入方法依赖的package包/类
/**
* Execute the function. The function must return
* a valid object.
* @param xctxt The current execution context.
* @return A valid XObject.
*
* @throws javax.xml.transform.TransformerException
*/
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
{
String lang = m_arg0.execute(xctxt).str();
int parent = xctxt.getCurrentNode();
boolean isLang = false;
DTM dtm = xctxt.getDTM(parent);
while (DTM.NULL != parent)
{
if (DTM.ELEMENT_NODE == dtm.getNodeType(parent))
{
int langAttr = dtm.getAttributeNode(parent, "http://www.w3.org/XML/1998/namespace", "lang");
if (DTM.NULL != langAttr)
{
String langVal = dtm.getNodeValue(langAttr);
// %OPT%
if (langVal.toLowerCase().startsWith(lang.toLowerCase()))
{
int valLen = lang.length();
if ((langVal.length() == valLen)
|| (langVal.charAt(valLen) == '-'))
{
isLang = true;
}
}
break;
}
}
parent = dtm.getParent(parent);
}
return isLang ? XBoolean.S_TRUE : XBoolean.S_FALSE;
}
示例12: execute
import org.apache.xpath.XPathContext; //导入方法依赖的package包/类
/**
* The here function returns a node-set containing the attribute or
* processing instruction node or the parent element of the text node
* that directly bears the XPath expression. This expression results
* in an error if the containing XPath expression does not appear in the
* same XML document against which the XPath expression is being evaluated.
*
* @param xctxt
* @return the xobject
* @throws javax.xml.transform.TransformerException
*/
public XObject execute(XPathContext xctxt) throws TransformerException {
Node xpathOwnerNode = (Node) xctxt.getOwnerObject();
if (xpathOwnerNode == null) {
return null;
}
int xpathOwnerNodeDTM = xctxt.getDTMHandleFromNode(xpathOwnerNode);
int currentNode = xctxt.getCurrentNode();
DTM dtm = xctxt.getDTM(currentNode);
int docContext = dtm.getDocument();
if (DTM.NULL == docContext) {
error(xctxt, XPATHErrorResources.ER_CONTEXT_HAS_NO_OWNERDOC, null);
}
{
// check whether currentNode and the node containing the XPath expression
// are in the same document
Document currentDoc =
XMLUtils.getOwnerDocument(dtm.getNode(currentNode));
Document xpathOwnerDoc = XMLUtils.getOwnerDocument(xpathOwnerNode);
if (currentDoc != xpathOwnerDoc) {
throw new TransformerException(I18n.translate("xpath.funcHere.documentsDiffer"));
}
}
XNodeSet nodes = new XNodeSet(xctxt.getDTMManager());
NodeSetDTM nodeSet = nodes.mutableNodeset();
{
int hereNode = DTM.NULL;
switch (dtm.getNodeType(xpathOwnerNodeDTM)) {
case Node.ATTRIBUTE_NODE :
case Node.PROCESSING_INSTRUCTION_NODE : {
// returns a node-set containing the attribute / processing instruction node
hereNode = xpathOwnerNodeDTM;
nodeSet.addNode(hereNode);
break;
}
case Node.TEXT_NODE : {
// returns a node-set containing the parent element of the
// text node that directly bears the XPath expression
hereNode = dtm.getParent(xpathOwnerNodeDTM);
nodeSet.addNode(hereNode);
break;
}
default :
break;
}
}
/** $todo$ Do I have to do this detach() call? */
nodeSet.detach();
return nodes;
}
示例13: execute
import org.apache.xpath.XPathContext; //导入方法依赖的package包/类
/**
* Execute the xsl:choose transformation.
*
*
* @param transformer non-null reference to the the current transform-time state.
*
* @throws TransformerException
*/
public void execute(TransformerImpl transformer) throws TransformerException
{
boolean found = false;
for (ElemTemplateElement childElem = getFirstChildElem();
childElem != null; childElem = childElem.getNextSiblingElem())
{
int type = childElem.getXSLToken();
if (Constants.ELEMNAME_WHEN == type)
{
found = true;
ElemWhen when = (ElemWhen) childElem;
// must be xsl:when
XPathContext xctxt = transformer.getXPathContext();
int sourceNode = xctxt.getCurrentNode();
// System.err.println("\""+when.getTest().getPatternString()+"\"");
// if(when.getTest().getPatternString().equals("COLLECTION/icuser/ictimezone/LITERAL='GMT +13:00 Pacific/Tongatapu'"))
// System.err.println("Found COLLECTION/icuser/ictimezone/LITERAL");
if (when.getTest().bool(xctxt, sourceNode, when)) {
transformer.executeChildTemplates(when, true);
return;
}
}
else if (Constants.ELEMNAME_OTHERWISE == type)
{
found = true;
// xsl:otherwise
transformer.executeChildTemplates(childElem, true);
return;
}
}
if (!found)
transformer.getMsgMgr().error(
this, XSLTErrorResources.ER_CHOOSE_REQUIRES_WHEN);
}
示例14: 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();
}
}
示例15: execute
import org.apache.xpath.XPathContext; //导入方法依赖的package包/类
/**
* Execute the string expression and copy the text to the
* result tree.
* The required select attribute is an expression; this expression
* is evaluated and the resulting object is converted to a string
* as if by a call to the string function. The string specifies
* the string-value of the created text node. If the string is
* empty, no text node will be created. The created text node will
* be merged with any adjacent text nodes.
* @see <a href="http://www.w3.org/TR/xslt#value-of">value-of in XSLT Specification</a>
*
* @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();
SerializationHandler rth = transformer.getResultTreeHandler();
try
{
// Optimize for "."
xctxt.pushNamespaceContext(this);
int current = xctxt.getCurrentNode();
xctxt.pushCurrentNodeAndExpression(current, current);
if (m_disableOutputEscaping)
rth.processingInstruction(
javax.xml.transform.Result.PI_DISABLE_OUTPUT_ESCAPING, "");
try
{
Expression expr = m_selectExpression.getExpression();
expr.executeCharsToContentHandler(xctxt, rth);
}
finally
{
if (m_disableOutputEscaping)
rth.processingInstruction(
javax.xml.transform.Result.PI_ENABLE_OUTPUT_ESCAPING, "");
xctxt.popNamespaceContext();
xctxt.popCurrentNodeAndExpression();
}
}
catch (SAXException se)
{
throw new TransformerException(se);
}
catch (RuntimeException re) {
TransformerException te = new TransformerException(re);
te.setLocator(this);
throw te;
}
}