本文整理汇总了Java中org.apache.xpath.XPathContext.getDTM方法的典型用法代码示例。如果您正苦于以下问题:Java XPathContext.getDTM方法的具体用法?Java XPathContext.getDTM怎么用?Java XPathContext.getDTM使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.xpath.XPathContext
的用法示例。
在下文中一共展示了XPathContext.getDTM方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: shouldStripWhiteSpace
import org.apache.xpath.XPathContext; //导入方法依赖的package包/类
/**
* Get information about whether or not an element should strip whitespace.
* @see <a href="http://www.w3.org/TR/xslt#strip">strip in XSLT Specification</a>
*
* @param support The XPath runtime state.
* @param targetElement Element to check
*
* @return true if the whitespace should be stripped.
*
* @throws TransformerException
*/
public boolean shouldStripWhiteSpace(
XPathContext support, int targetElement) throws TransformerException
{
if (null != m_whiteSpaceInfoList)
{
while(DTM.NULL != targetElement)
{
DTM dtm = support.getDTM(targetElement);
WhiteSpaceInfo info = (WhiteSpaceInfo) m_whiteSpaceInfoList.getTemplate(support,
targetElement, null, false, dtm);
if(null != info)
return info.getShouldStripSpace();
int parent = dtm.getParent(targetElement);
if(DTM.NULL != parent && DTM.ELEMENT_NODE == dtm.getNodeType(parent))
targetElement = parent;
else
targetElement = DTM.NULL;
}
}
return false;
}
示例2: TransformerHandlerImpl
import org.apache.xpath.XPathContext; //导入方法依赖的package包/类
/**
* Construct a TransformerHandlerImpl.
*
* @param transformer Non-null reference to the Xalan transformer impl.
* @param doFragment True if the result should be a document fragement.
* @param baseSystemID The system ID to use as the base for relative URLs.
*/
public TransformerHandlerImpl(TransformerImpl transformer,
boolean doFragment, String baseSystemID)
{
super();
m_transformer = transformer;
m_baseSystemID = baseSystemID;
XPathContext xctxt = transformer.getXPathContext();
DTM dtm = xctxt.getDTM(null, true, transformer, true, true);
m_dtm = dtm;
dtm.setDocumentBaseURI(baseSystemID);
m_contentHandler = dtm.getContentHandler();
m_dtdHandler = dtm.getDTDHandler();
m_entityResolver = dtm.getEntityResolver();
m_errorHandler = dtm.getErrorHandler();
m_lexicalHandler = dtm.getLexicalHandler();
m_incremental = transformer.getIncremental();
m_optimizer = transformer.getOptimize();
m_source_location = transformer.getSource_location();
}
示例3: 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.
*
* @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);
}
}
示例4: setRoot
import org.apache.xpath.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();
}
示例5: 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
{
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;
}
示例6: 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();
}
示例7: 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();
}
示例8: outputResultTreeFragment
import org.apache.xpath.XPathContext; //导入方法依赖的package包/类
/**
* Given a result tree fragment, walk the tree and
* output it to the SerializationHandler.
*
* @param obj Result tree fragment object
* @param support XPath context for the result tree fragment
*
* @throws org.xml.sax.SAXException
*/
public static void outputResultTreeFragment(
SerializationHandler handler,
XObject obj,
XPathContext support)
throws org.xml.sax.SAXException
{
int doc = obj.rtf();
DTM dtm = support.getDTM(doc);
if (null != dtm)
{
for (int n = dtm.getFirstChild(doc);
DTM.NULL != n;
n = dtm.getNextSibling(n))
{
handler.flushPending();
// I think. . . . This used to have a (true) arg
// to flush prefixes, will that cause problems ???
if (dtm.getNodeType(n) == DTM.ELEMENT_NODE
&& dtm.getNamespaceURI(n) == null)
handler.startPrefixMapping("", "");
dtm.dispatchToEvents(n, handler);
}
}
}
示例9: findAncestor
import org.apache.xpath.XPathContext; //导入方法依赖的package包/类
/**
* Given a 'from' pattern (ala xsl:number), a match pattern
* and a context, find the first ancestor that matches the
* pattern (including the context handed in).
*
* @param xctxt The XPath runtime state for this.
* @param fromMatchPattern The ancestor must match this pattern.
* @param countMatchPattern The ancestor must also match this pattern.
* @param context The node that "." expresses.
* @param namespaceContext The context in which namespaces in the
* queries are supposed to be expanded.
*
* @return the first ancestor that matches the given pattern
*
* @throws javax.xml.transform.TransformerException
*/
int findAncestor(
XPathContext xctxt, XPath fromMatchPattern, XPath countMatchPattern,
int context, ElemNumber namespaceContext)
throws javax.xml.transform.TransformerException
{
DTM dtm = xctxt.getDTM(context);
while (DTM.NULL != context)
{
if (null != fromMatchPattern)
{
if (fromMatchPattern.getMatchScore(xctxt, context)
!= XPath.MATCH_SCORE_NONE)
{
//context = null;
break;
}
}
if (null != countMatchPattern)
{
if (countMatchPattern.getMatchScore(xctxt, context)
!= XPath.MATCH_SCORE_NONE)
{
break;
}
}
context = dtm.getParent(context);
}
return context;
}
示例10: getPreviouslyCounted
import org.apache.xpath.XPathContext; //导入方法依赖的package包/类
/**
* Try and find a node that was previously counted. If found,
* return a positive integer that corresponds to the count.
*
* @param support The XPath context to use
* @param node The node to be counted.
*
* @return The count of the node, or -1 if not found.
*/
int getPreviouslyCounted(XPathContext support, int node)
{
int n = m_countNodes.size();
m_countResult = 0;
for (int i = n - 1; i >= 0; i--)
{
int countedNode = m_countNodes.elementAt(i);
if (node == countedNode)
{
// Since the list is in backwards order, the count is
// how many are in the rest of the list.
m_countResult = i + 1 + m_countNodesStartCount;
break;
}
DTM dtm = support.getDTM(countedNode);
// Try to see if the given node falls after the counted node...
// if it does, don't keep searching backwards.
if (dtm.isNodeAfter(countedNode, node))
break;
}
return m_countResult;
}
示例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
{
int context = getArg0AsNode(xctxt);
String s;
if(context != DTM.NULL)
{
DTM dtm = xctxt.getDTM(context);
int t = dtm.getNodeType(context);
if(t == DTM.ELEMENT_NODE)
{
s = dtm.getNamespaceURI(context);
}
else if(t == DTM.ATTRIBUTE_NODE)
{
// This function always returns an empty string for namespace nodes.
// We check for those here. Fix inspired by Davanum Srinivas.
s = dtm.getNodeName(context);
if(s.startsWith("xmlns:") || s.equals("xmlns"))
return XString.EMPTYSTRING;
s = dtm.getNamespaceURI(context);
}
else
return XString.EMPTYSTRING;
}
else
return XString.EMPTYSTRING;
return ((null == s) ? XString.EMPTYSTRING : new XString(s));
}
示例12: 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
{
int whereNode = getArg0AsNode(xctxt);
String fileLocation = null;
if (DTM.NULL != whereNode)
{
DTM dtm = xctxt.getDTM(whereNode);
// %REVIEW%
if (DTM.DOCUMENT_FRAGMENT_NODE == dtm.getNodeType(whereNode))
{
whereNode = dtm.getFirstChild(whereNode);
}
if (DTM.NULL != whereNode)
{
fileLocation = dtm.getDocumentBaseURI();
// int owner = dtm.getDocument();
// fileLocation = xctxt.getSourceTreeManager().findURIFromDoc(owner);
}
}
return new XString((null != fileLocation) ? fileLocation : "");
}
示例13: 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);
}
示例14: 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;
}
示例15: 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
{
int context = getArg0AsNode(xctxt);
if(DTM.NULL == context)
return XString.EMPTYSTRING;
DTM dtm = xctxt.getDTM(context);
String s = (context != DTM.NULL) ? dtm.getLocalName(context) : "";
if(s.startsWith("#") || s.equals("xmlns"))
return XString.EMPTYSTRING;
return new XString(s);
}