use of org.apache.xml.dtm.DTM in project robovm by robovm.
the class FuncLang 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 {
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;
}
use of org.apache.xml.dtm.DTM in project robovm by robovm.
the class FuncLocalPart 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 = 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);
}
use of org.apache.xml.dtm.DTM in project robovm by robovm.
the class FuncNamespace 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 = 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));
}
use of org.apache.xml.dtm.DTM 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.xml.dtm.DTM in project robovm by robovm.
the class FuncSum 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 {
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);
}
Aggregations