use of org.apache.xpath.objects.XObject in project robovm by robovm.
the class JAXPVariableStack method getVariableOrParam.
public XObject getVariableOrParam(XPathContext xctxt, QName qname) throws TransformerException, IllegalArgumentException {
if (qname == null) {
//JAXP 1.3 spec says that if variable name is null then
// we need to through IllegalArgumentException
String fmsg = XSLMessages.createXPATHMessage(XPATHErrorResources.ER_ARG_CANNOT_BE_NULL, new Object[] { "Variable qname" });
throw new IllegalArgumentException(fmsg);
}
javax.xml.namespace.QName name = new javax.xml.namespace.QName(qname.getNamespace(), qname.getLocalPart());
Object varValue = resolver.resolveVariable(name);
if (varValue == null) {
String fmsg = XSLMessages.createXPATHMessage(XPATHErrorResources.ER_RESOLVE_VARIABLE_RETURNS_NULL, new Object[] { name.toString() });
throw new TransformerException(fmsg);
}
return XObject.create(varValue, xctxt);
}
use of org.apache.xpath.objects.XObject in project robovm by robovm.
the class FuncId method execute.
/**
* 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 = xctxt.getCurrentNode();
DTM dtm = xctxt.getDTM(context);
int docContext = dtm.getDocument();
if (DTM.NULL == docContext)
error(xctxt, XPATHErrorResources.ER_CONTEXT_HAS_NO_OWNERDOC, null);
XObject arg = m_arg0.execute(xctxt);
int argType = arg.getType();
XNodeSet nodes = new XNodeSet(xctxt.getDTMManager());
NodeSetDTM nodeSet = nodes.mutableNodeset();
if (XObject.CLASS_NODESET == argType) {
DTMIterator ni = arg.iter();
StringVector usedrefs = null;
int pos = ni.nextNode();
while (DTM.NULL != pos) {
DTM ndtm = ni.getDTM(pos);
String refval = ndtm.getStringValue(pos).toString();
pos = ni.nextNode();
usedrefs = getNodesByID(xctxt, docContext, refval, usedrefs, nodeSet, DTM.NULL != pos);
}
// ni.detach();
} else if (XObject.CLASS_NULL == argType) {
return nodes;
} else {
String refval = arg.str();
getNodesByID(xctxt, docContext, refval, null, nodeSet, false);
}
return nodes;
}
use of org.apache.xpath.objects.XObject in project robovm by robovm.
the class FuncNormalizeSpace method executeCharsToContentHandler.
/**
* 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);
}
}
use of org.apache.xpath.objects.XObject in project robovm by robovm.
the class MatchPatternIterator method acceptNode.
/**
* Test whether a specified node is visible in the logical view of a
* TreeWalker or NodeIterator. This function will be called by the
* implementation of TreeWalker and NodeIterator; it is not intended to
* be called directly from user code.
* @param n The node to check to see if it passes the filter or not.
* @return a constant to determine whether the node is accepted,
* rejected, or skipped, as defined above .
*/
public short acceptNode(int n, XPathContext xctxt) {
try {
xctxt.pushCurrentNode(n);
xctxt.pushIteratorRoot(m_context);
if (DEBUG) {
System.out.println("traverser: " + m_traverser);
System.out.print("node: " + n);
System.out.println(", " + m_cdtm.getNodeName(n));
// if(m_cdtm.getNodeName(n).equals("near-east"))
System.out.println("pattern: " + m_pattern.toString());
m_pattern.debugWhatToShow(m_pattern.getWhatToShow());
}
XObject score = m_pattern.execute(xctxt);
if (DEBUG) {
// System.out.println("analysis: "+Integer.toBinaryString(m_analysis));
System.out.println("score: " + score);
System.out.println("skip: " + (score == NodeTest.SCORE_NONE));
}
// System.out.println("\n::acceptNode - score: "+score.num()+"::");
return (score == NodeTest.SCORE_NONE) ? DTMIterator.FILTER_SKIP : DTMIterator.FILTER_ACCEPT;
} catch (javax.xml.transform.TransformerException se) {
// TODO: Fix this.
throw new RuntimeException(se.getMessage());
} finally {
xctxt.popCurrentNode();
xctxt.popIteratorRoot();
}
}
use of org.apache.xpath.objects.XObject in project freemarker by apache.
the class XalanXPathSupport method executeQuery.
/* " + ERRMSG_RECOMMEND_JAXEN;*/
public synchronized TemplateModel executeQuery(Object context, String xpathQuery) throws TemplateModelException {
if (!(context instanceof Node)) {
if (context != null) {
if (isNodeList(context)) {
int cnt = ((List) context).size();
if (cnt != 0) {
throw new TemplateModelException("Cannot perform an XPath query against a node set of " + cnt + " nodes. Expecting a single node.");
} else {
throw new TemplateModelException(ERRMSG_EMPTY_NODE_SET);
}
} else {
throw new TemplateModelException("Cannot perform an XPath query against a " + context.getClass().getName() + ". Expecting a single org.w3c.dom.Node.");
}
} else {
throw new TemplateModelException(ERRMSG_EMPTY_NODE_SET);
}
}
Node node = (Node) context;
try {
XPath xpath = new XPath(xpathQuery, null, customPrefixResolver, XPath.SELECT, null);
int ctxtNode = xpathContext.getDTMHandleFromNode(node);
XObject xresult = xpath.execute(xpathContext, ctxtNode, customPrefixResolver);
if (xresult instanceof XNodeSet) {
NodeListModel result = new NodeListModel(node);
result.xpathSupport = this;
NodeIterator nodeIterator = xresult.nodeset();
Node n;
do {
n = nodeIterator.nextNode();
if (n != null) {
result.add(n);
}
} while (n != null);
return result.size() == 1 ? result.get(0) : result;
}
if (xresult instanceof XBoolean) {
return ((XBoolean) xresult).bool() ? TemplateBooleanModel.TRUE : TemplateBooleanModel.FALSE;
}
if (xresult instanceof XNull) {
return null;
}
if (xresult instanceof XString) {
return new SimpleScalar(xresult.toString());
}
if (xresult instanceof XNumber) {
return new SimpleNumber(Double.valueOf(((XNumber) xresult).num()));
}
throw new TemplateModelException("Cannot deal with type: " + xresult.getClass().getName());
} catch (TransformerException te) {
throw new TemplateModelException(te);
}
}
Aggregations