use of org.apache.xml.utils.XMLString in project j2objc by google.
the class DOM2DTM method getStringValue.
/**
* Get the string-value of a node as a String object
* (see http://www.w3.org/TR/xpath#data-model
* for the definition of a node's string-value).
*
* @param nodeHandle The node ID.
*
* @return A string object that represents the string-value of the given node.
*/
public XMLString getStringValue(int nodeHandle) {
int type = getNodeType(nodeHandle);
Node node = getNode(nodeHandle);
// directly.
if (DTM.ELEMENT_NODE == type || DTM.DOCUMENT_NODE == type || DTM.DOCUMENT_FRAGMENT_NODE == type) {
FastStringBuffer buf = StringBufferPool.get();
String s;
try {
getNodeData(node, buf);
s = (buf.length() > 0) ? buf.toString() : "";
} finally {
StringBufferPool.free(buf);
}
return m_xstrf.newstr(s);
} else if (TEXT_NODE == type || CDATA_SECTION_NODE == type) {
// If this is a DTM text node, it may be made of multiple DOM text
// nodes -- including navigating into Entity References. DOM2DTM
// records the first node in the sequence and requires that we
// pick up the others when we retrieve the DTM node's value.
//
// %REVIEW% DOM Level 3 is expected to add a "whole text"
// retrieval method which performs this function for us.
FastStringBuffer buf = StringBufferPool.get();
while (node != null) {
buf.append(node.getNodeValue());
node = logicalNextDOMTextNode(node);
}
String s = (buf.length() > 0) ? buf.toString() : "";
StringBufferPool.free(buf);
return m_xstrf.newstr(s);
} else
return m_xstrf.newstr(node.getNodeValue());
}
use of org.apache.xml.utils.XMLString in project j2objc by google.
the class DTMDocumentImpl method getStringValue.
/**
* Get the string-value of a node as a String object
* (see http://www.w3.org/TR/xpath#data-model
* for the definition of a node's string-value).
*
* @param nodeHandle The node ID.
*
* @return A string object that represents the string-value of the given node.
*/
public XMLString getStringValue(int nodeHandle) {
// ###zaj - researching
nodes.readSlot(nodeHandle, gotslot);
int nodetype = gotslot[0] & 0xFF;
String value = null;
switch(nodetype) {
case TEXT_NODE:
case COMMENT_NODE:
case CDATA_SECTION_NODE:
value = m_char.getString(gotslot[2], gotslot[3]);
break;
case PROCESSING_INSTRUCTION_NODE:
case ATTRIBUTE_NODE:
case ELEMENT_NODE:
case ENTITY_REFERENCE_NODE:
default:
break;
}
return m_xsf.newstr(value);
}
use of org.apache.xml.utils.XMLString in project j2objc by google.
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);
}
use of org.apache.xml.utils.XMLString in project j2objc by google.
the class FunctionDef1Arg method getArg0AsNumber.
/**
* 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();
}
use of org.apache.xml.utils.XMLString in project j2objc by google.
the class FuncSubstring 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 {
XMLString s1 = m_arg0.execute(xctxt).xstr();
double start = m_arg1.execute(xctxt).num();
int lenOfS1 = s1.length();
XMLString substr;
if (lenOfS1 <= 0)
return XString.EMPTYSTRING;
else {
int startIndex;
if (Double.isNaN(start)) {
// Double.MIN_VALUE doesn't work with math below
// so just use a big number and hope I never get caught.
start = -1000000;
startIndex = 0;
} else {
start = Math.round(start);
startIndex = (start > 0) ? (int) start - 1 : 0;
}
if (null != m_arg2) {
double len = m_arg2.num(xctxt);
int end = (int) (Math.round(len) + start) - 1;
// Normalize end index.
if (end < 0)
end = 0;
else if (end > lenOfS1)
end = lenOfS1;
if (startIndex > lenOfS1)
startIndex = lenOfS1;
substr = s1.substring(startIndex, end);
} else {
if (startIndex > lenOfS1)
startIndex = lenOfS1;
substr = s1.substring(startIndex);
}
}
// cast semi-safe
return (XString) substr;
}
Aggregations