本文整理汇总了Java中com.sun.org.apache.xpath.internal.XPathContext类的典型用法代码示例。如果您正苦于以下问题:Java XPathContext类的具体用法?Java XPathContext怎么用?Java XPathContext使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
XPathContext类属于com.sun.org.apache.xpath.internal包,在下文中一共展示了XPathContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: evaluate
import com.sun.org.apache.xpath.internal.XPathContext; //导入依赖的package包/类
/**
* The dyn:evaluate function evaluates a string as an XPath expression and returns
* the resulting value, which might be a boolean, number, string, node set, result
* tree fragment or external object. The sole argument is the string to be evaluated.
* <p>
* If the expression string passed as the second argument is an invalid XPath
* expression (including an empty string), this function returns an empty node set.
* <p>
* You should only use this function if the expression must be constructed dynamically,
* otherwise it is much more efficient to use the expression literally.
*
* @param myContext The ExpressionContext passed by the extension processor
* @param xpathExpr The XPath expression string
*
* @return The evaluation result
*/
public static XObject evaluate(ExpressionContext myContext, String xpathExpr)
throws SAXNotSupportedException
{
if (myContext instanceof XPathContext.XPathExpressionContext)
{
XPathContext xctxt = null;
try
{
xctxt = ((XPathContext.XPathExpressionContext) myContext).getXPathContext();
XPath dynamicXPath = new XPath(xpathExpr, xctxt.getSAXLocator(),
xctxt.getNamespaceContext(),
XPath.SELECT);
return dynamicXPath.execute(xctxt, myContext.getContextNode(),
xctxt.getNamespaceContext());
}
catch (TransformerException e)
{
return new XNodeSet(xctxt.getDTMManager());
}
}
else
throw new SAXNotSupportedException(XSLMessages.createMessage(XSLTErrorResources.ER_INVALID_CONTEXT_PASSED, new Object[]{myContext })); //"Invalid context passed to evaluate "
}
示例2: getArg0AsNumber
import com.sun.org.apache.xpath.internal.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();
}
示例3: rtf
import com.sun.org.apache.xpath.internal.XPathContext; //导入依赖的package包/类
/**
* Cast result object to a result tree fragment.
*
* @param support XPath context to use for the conversion
*
* @return the objec as a result tree fragment.
*/
public int rtf(XPathContext support)
{
int result = rtf();
if (DTM.NULL == result)
{
DTM frag = support.createDocumentFragment();
// %OPT%
frag.appendTextChild(str());
result = frag.getDocument();
}
return result;
}
示例4: execute
import com.sun.org.apache.xpath.internal.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
{
DTMIterator nodes = m_arg0.asIterator(xctxt, xctxt.getCurrentNode());
double sum = 0.0;
int pos;
while (DTM.NULL != (pos = nodes.nextNode()))
{
DTM dtm = nodes.getDTM(pos);
XMLString s = dtm.getStringValue(pos);
if (null != s)
sum += s.toDouble();
}
nodes.detach();
return new XNumber(sum);
}
示例5: setRoot
import com.sun.org.apache.xpath.internal.XPathContext; //导入依赖的package包/类
/**
* Initialize the context values for this expression
* after it is cloned.
*
* @param context The XPath runtime context for this
* transformation.
*/
public void setRoot(int context, Object environment)
{
m_context = context;
XPathContext xctxt = (XPathContext)environment;
m_execContext = xctxt;
m_cdtm = xctxt.getDTM(context);
m_currentContextNode = context; // only if top level?
// Yech, shouldn't have to do this. -sb
if(null == m_prefixResolver)
m_prefixResolver = xctxt.getNamespaceContext();
m_lastFetched = DTM.NULL;
m_foundLast = false;
m_pos = 0;
m_length = -1;
if (m_isTopLevel)
this.m_stackFrame = xctxt.getVarStack().getStackFrame();
// reset();
}
示例6: getCountOfContextNodeList
import com.sun.org.apache.xpath.internal.XPathContext; //导入依赖的package包/类
/**
* Get the position in the current context node list.
*
* @param xctxt non-null reference to XPath runtime context.
*
* @return The number of nodes in the list.
*
* @throws javax.xml.transform.TransformerException
*/
public int getCountOfContextNodeList(XPathContext xctxt)
throws javax.xml.transform.TransformerException
{
// assert(null != m_contextNodeList, "m_contextNodeList must be non-null");
// If we're in a predicate, then this will return non-null.
SubContextList iter = m_isTopLevel ? null : xctxt.getSubContextList();
// System.out.println("iter: "+iter);
if (null != iter)
return iter.getLastPos(xctxt);
DTMIterator cnl = xctxt.getContextNodeList();
int count;
if(null != cnl)
{
count = cnl.getLength();
// System.out.println("count: "+count);
}
else
count = 0;
return count;
}
示例7: execute
import com.sun.org.apache.xpath.internal.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
{
int which = getArg0AsNode(xctxt);
if (DTM.NULL != which)
{
// Note that this is a different value than in previous releases
// of Xalan. It's sensitive to the exact encoding of the node
// handle anyway, so fighting to maintain backward compatability
// really didn't make sense; it may change again as we continue
// to experiment with balancing document and node numbers within
// that value.
return new XString("N" + Integer.toHexString(which).toUpperCase());
}
else
return XString.EMPTYSTRING;
}
示例8: execute
import com.sun.org.apache.xpath.internal.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
{
int context = getArg0AsNode(xctxt);
XObject val;
if (DTM.NULL != context)
{
DTM dtm = xctxt.getDTM(context);
String qname = dtm.getNodeNameX(context);
val = (null == qname) ? XString.EMPTYSTRING : new XString(qname);
}
else
{
val = XString.EMPTYSTRING;
}
return val;
}
示例9: execute
import com.sun.org.apache.xpath.internal.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
{
StringBuffer sb = new StringBuffer();
// Compiler says we must have at least two arguments.
sb.append(m_arg0.execute(xctxt).str());
sb.append(m_arg1.execute(xctxt).str());
if (null != m_arg2)
sb.append(m_arg2.execute(xctxt).str());
if (null != m_args)
{
for (int i = 0; i < m_args.length; i++)
{
sb.append(m_args[i].execute(xctxt).str());
}
}
return new XString(sb.toString());
}
示例10: executeCharsToContentHandler
import com.sun.org.apache.xpath.internal.XPathContext; //导入依赖的package包/类
/**
* Execute an expression in the XPath runtime context, and return the
* result of the expression.
*
*
* @param xctxt The XPath runtime context.
*
* @return The result of the expression in the form of a <code>XObject</code>.
*
* @throws javax.xml.transform.TransformerException if a runtime exception
* occurs.
*/
public void executeCharsToContentHandler(XPathContext xctxt,
ContentHandler handler)
throws javax.xml.transform.TransformerException,
org.xml.sax.SAXException
{
if(Arg0IsNodesetExpr())
{
int node = getArg0AsNode(xctxt);
if(DTM.NULL != node)
{
DTM dtm = xctxt.getDTM(node);
dtm.dispatchCharactersEvents(node, handler, true);
}
}
else
{
XObject obj = execute(xctxt);
obj.dispatchCharactersEvents(handler);
}
}
示例11: getArg0AsString
import com.sun.org.apache.xpath.internal.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();
}
示例12: execute
import com.sun.org.apache.xpath.internal.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
{
// DTMIterator nl = m_arg0.asIterator(xctxt, xctxt.getCurrentNode());
// // We should probably make a function on the iterator for this,
// // as a given implementation could optimize.
// int i = 0;
//
// while (DTM.NULL != nl.nextNode())
// {
// i++;
// }
// nl.detach();
DTMIterator nl = m_arg0.asIterator(xctxt, xctxt.getCurrentNode());
int i = nl.getLength();
nl.detach();
return new XNumber((double) i);
}
示例13: execute
import com.sun.org.apache.xpath.internal.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
{
SubContextList subContextList = xctxt.getCurrentNodeList();
int currentNode = DTM.NULL;
if (null != subContextList) {
if (subContextList instanceof PredicatedNodeTest) {
LocPathIterator iter = ((PredicatedNodeTest)subContextList)
.getLocPathIterator();
currentNode = iter.getCurrentContextNode();
} else if(subContextList instanceof StepPattern) {
throw new RuntimeException(XSLMessages.createMessage(
XSLTErrorResources.ER_PROCESSOR_ERROR,null));
}
} else {
// not predicate => ContextNode == CurrentNode
currentNode = xctxt.getContextNode();
}
return new XNodeSet(currentNode, xctxt.getDTMManager());
}
示例14: executeRelativePathPattern
import com.sun.org.apache.xpath.internal.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 com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NODETEST},
* {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NONE},
* {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NSWILD},
* {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_QNAME}, or
* {@link com.sun.org.apache.xpath.internal.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;
}
示例15: execute
import com.sun.org.apache.xpath.internal.XPathContext; //导入依赖的package包/类
/**
* Test a node to see if it matches the given node test.
*
* @param xctxt XPath runtime context.
*
* @return {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NODETEST},
* {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NONE},
* {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NSWILD},
* {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_QNAME}, or
* {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_OTHER}.
*
* @throws javax.xml.transform.TransformerException
*/
public XObject execute(XPathContext xctxt, int context)
throws javax.xml.transform.TransformerException
{
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();
}
nl.detach();
return score;
}