本文整理汇总了Java中org.apache.xpath.XPathContext.getOwnerObject方法的典型用法代码示例。如果您正苦于以下问题:Java XPathContext.getOwnerObject方法的具体用法?Java XPathContext.getOwnerObject怎么用?Java XPathContext.getOwnerObject使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.xpath.XPathContext
的用法示例。
在下文中一共展示了XPathContext.getOwnerObject方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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
{
if (xctxt.isSecureProcessing())
throw new javax.xml.transform.TransformerException(
XPATHMessages.createXPATHMessage(
XPATHErrorResources.ER_EXTENSION_FUNCTION_CANNOT_BE_INVOKED,
new Object[] {toString()}));
XObject result;
Vector argVec = new Vector();
int nArgs = m_argVec.size();
for (int i = 0; i < nArgs; i++)
{
Expression arg = (Expression) m_argVec.elementAt(i);
XObject xobj = arg.execute(xctxt);
/*
* Should cache the arguments for func:function
*/
xobj.allowDetachToRelease(false);
argVec.addElement(xobj);
}
//dml
ExtensionsProvider extProvider = (ExtensionsProvider)xctxt.getOwnerObject();
Object val = extProvider.extFunction(this, argVec);
if (null != val)
{
result = XObject.create(val, xctxt);
}
else
{
result = new XNull();
}
return result;
}
示例2: 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;
}
示例3: 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 prefix;
String namespace;
String methName;
String fullName = m_arg0.execute(xctxt).str();
int indexOfNSSep = fullName.indexOf(':');
if (indexOfNSSep < 0)
{
prefix = "";
namespace = Constants.S_XSLNAMESPACEURL;
methName = fullName;
}
else
{
prefix = fullName.substring(0, indexOfNSSep);
namespace = xctxt.getNamespaceContext().getNamespaceForPrefix(prefix);
if (null == namespace)
return XBoolean.S_FALSE;
methName= fullName.substring(indexOfNSSep + 1);
}
if (namespace.equals(Constants.S_XSLNAMESPACEURL)
|| namespace.equals(Constants.S_BUILTIN_EXTENSIONS_URL))
{
try
{
TransformerImpl transformer = (TransformerImpl) xctxt.getOwnerObject();
return transformer.getStylesheet().getAvailableElements().containsKey(
new QName(namespace, methName))
? XBoolean.S_TRUE : XBoolean.S_FALSE;
}
catch (Exception e)
{
return XBoolean.S_FALSE;
}
}
else
{
//dml
ExtensionsProvider extProvider = (ExtensionsProvider)xctxt.getOwnerObject();
return extProvider.elementAvailable(namespace, methName)
? XBoolean.S_TRUE : XBoolean.S_FALSE;
}
}