本文整理汇总了Java中com.sun.org.apache.xpath.internal.XPathContext.getDTMManager方法的典型用法代码示例。如果您正苦于以下问题:Java XPathContext.getDTMManager方法的具体用法?Java XPathContext.getDTMManager怎么用?Java XPathContext.getDTMManager使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sun.org.apache.xpath.internal.XPathContext
的用法示例。
在下文中一共展示了XPathContext.getDTMManager方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: setRoot
import com.sun.org.apache.xpath.internal.XPathContext; //导入方法依赖的package包/类
/**
* @see DTMIterator#setRoot(int, Object)
*/
public void setRoot(int nodeHandle, Object environment)
{
// If root is DTM.NULL, then something's wrong with the context
if (nodeHandle == DTM.NULL)
{
throw new RuntimeException("Unable to evaluate expression using " +
"this context");
}
if(null != m_iter)
{
XPathContext xctxt = (XPathContext)environment;
m_dtmMgr = xctxt.getDTMManager();
m_iter.setRoot(nodeHandle, environment);
if(!m_iter.isDocOrdered())
{
if(!hasCache())
setShouldCacheNodes(true);
runTo(-1);
m_next=0;
}
}
else
assertion(false, "Can not setRoot on a non-iterated NodeSequence!");
}
示例3: 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());
}
示例4: XNodeSetForDOM
import com.sun.org.apache.xpath.internal.XPathContext; //导入方法依赖的package包/类
public XNodeSetForDOM(NodeList nodeList, XPathContext xctxt)
{
m_dtmMgr = xctxt.getDTMManager();
m_origObj = nodeList;
// JKESS 20020514: Longer-term solution is to force
// folks to request length through an accessor, so we can defer this
// retrieval... but that requires an API change.
// m_obj=new com.sun.org.apache.xpath.internal.NodeSetDTM(nodeList, xctxt);
com.sun.org.apache.xpath.internal.NodeSetDTM nsdtm=new com.sun.org.apache.xpath.internal.NodeSetDTM(nodeList, xctxt);
m_last=nsdtm.getLength();
setObject(nsdtm);
}
示例5: execute
import com.sun.org.apache.xpath.internal.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
*/
@Override
public XObject execute(XPathContext xctxt)
throws javax.xml.transform.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;
}
示例6: execute
import com.sun.org.apache.xpath.internal.XPathContext; //导入方法依赖的package包/类
@Override
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 (docContext == DTM.NULL) {
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 = getOwnerDocument(dtm.getNode(currentNode));
Document xpathOwnerDoc = getOwnerDocument(xpathOwnerNode);
if (currentDoc != xpathOwnerDoc) {
throw new TransformerException("Owner documents differ");
}
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;
}