use of org.apache.xml.utils.XMLString in project j2objc by google.
the class XString method toDouble.
/**
* Convert a string to a double -- Allowed input is in fixed
* notation ddd.fff.
*
* @return A double value representation of the string, or return Double.NaN
* if the string can not be converted.
*/
public double toDouble() {
/* XMLCharacterRecognizer.isWhiteSpace(char c) methods treats the following
* characters as white space characters.
* ht - horizontal tab, nl - newline , cr - carriage return and sp - space
* trim() methods by default also takes care of these white space characters
* So trim() method is used to remove leading and trailing white spaces.
*/
XMLString s = trim();
double result = Double.NaN;
for (int i = 0; i < s.length(); i++) {
char c = s.charAt(i);
if (c != '-' && c != '.' && (c < 0X30 || c > 0x39)) {
// then return NaN because something is wrong.
return result;
}
}
try {
result = Double.parseDouble(s.toString());
} catch (NumberFormatException e) {
}
return result;
}
use of org.apache.xml.utils.XMLString in project robovm by robovm.
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 robovm by robovm.
the class KeyTable method getRefsTable.
/**
* @return lazy initialized refs table associating evaluation of key function
* with a XNodeSet
*/
private Hashtable getRefsTable() {
if (m_refsTable == null) {
// initial capacity set to a prime number to improve hash performance
m_refsTable = new Hashtable(89);
KeyIterator ki = (KeyIterator) (m_keyNodes).getContainedIter();
XPathContext xctxt = ki.getXPathContext();
Vector keyDecls = getKeyDeclarations();
int nKeyDecls = keyDecls.size();
int currentNode;
m_keyNodes.reset();
while (DTM.NULL != (currentNode = m_keyNodes.nextNode())) {
try {
for (int keyDeclIdx = 0; keyDeclIdx < nKeyDecls; keyDeclIdx++) {
KeyDeclaration keyDeclaration = (KeyDeclaration) keyDecls.elementAt(keyDeclIdx);
XObject xuse = keyDeclaration.getUse().execute(xctxt, currentNode, ki.getPrefixResolver());
if (xuse.getType() != xuse.CLASS_NODESET) {
XMLString exprResult = xuse.xstr();
addValueInRefsTable(xctxt, exprResult, currentNode);
} else {
DTMIterator i = ((XNodeSet) xuse).iterRaw();
int currentNodeInUseClause;
while (DTM.NULL != (currentNodeInUseClause = i.nextNode())) {
DTM dtm = xctxt.getDTM(currentNodeInUseClause);
XMLString exprResult = dtm.getStringValue(currentNodeInUseClause);
addValueInRefsTable(xctxt, exprResult, currentNode);
}
}
}
} catch (TransformerException te) {
throw new WrappedRuntimeException(te);
}
}
}
return m_refsTable;
}
use of org.apache.xml.utils.XMLString in project robovm by robovm.
the class FuncKey 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 {
// TransformerImpl transformer = (TransformerImpl)xctxt;
TransformerImpl transformer = (TransformerImpl) xctxt.getOwnerObject();
XNodeSet nodes = null;
int context = xctxt.getCurrentNode();
DTM dtm = xctxt.getDTM(context);
int docContext = dtm.getDocumentRoot(context);
if (DTM.NULL == docContext) {
// path.error(context, XPATHErrorResources.ER_CONTEXT_HAS_NO_OWNERDOC); //"context does not have an owner document!");
}
String xkeyname = getArg0().execute(xctxt).str();
QName keyname = new QName(xkeyname, xctxt.getNamespaceContext());
XObject arg = getArg1().execute(xctxt);
boolean argIsNodeSetDTM = (XObject.CLASS_NODESET == arg.getType());
KeyManager kmgr = transformer.getKeyManager();
// Don't bother with nodeset logic if the thing is only one node.
if (argIsNodeSetDTM) {
XNodeSet ns = (XNodeSet) arg;
ns.setShouldCacheNodes(true);
int len = ns.getLength();
if (len <= 1)
argIsNodeSetDTM = false;
}
if (argIsNodeSetDTM) {
Hashtable usedrefs = null;
DTMIterator ni = arg.iter();
int pos;
UnionPathIterator upi = new UnionPathIterator();
upi.exprSetParent(this);
while (DTM.NULL != (pos = ni.nextNode())) {
dtm = xctxt.getDTM(pos);
XMLString ref = dtm.getStringValue(pos);
if (null == ref)
continue;
if (null == usedrefs)
usedrefs = new Hashtable();
if (usedrefs.get(ref) != null) {
// We already have 'em.
continue;
} else {
// ISTRUE being used as a dummy value.
usedrefs.put(ref, ISTRUE);
}
XNodeSet nl = kmgr.getNodeSetDTMByKey(xctxt, docContext, keyname, ref, xctxt.getNamespaceContext());
nl.setRoot(xctxt.getCurrentNode(), xctxt);
// try
// {
upi.addIterator(nl);
// }
// catch(CloneNotSupportedException cnse)
// {
// // will never happen.
// }
//mnodeset.addNodesInDocOrder(nl, xctxt); needed??
}
int current = xctxt.getCurrentNode();
upi.setRoot(current, xctxt);
nodes = new XNodeSet(upi);
} else {
XMLString ref = arg.xstr();
nodes = kmgr.getNodeSetDTMByKey(xctxt, docContext, keyname, ref, xctxt.getNamespaceContext());
nodes.setRoot(xctxt.getCurrentNode(), xctxt);
}
return nodes;
}
use of org.apache.xml.utils.XMLString in project robovm by robovm.
the class XString method toDouble.
/**
* Convert a string to a double -- Allowed input is in fixed
* notation ddd.fff.
*
* @return A double value representation of the string, or return Double.NaN
* if the string can not be converted.
*/
public double toDouble() {
/* XMLCharacterRecognizer.isWhiteSpace(char c) methods treats the following
* characters as white space characters.
* ht - horizontal tab, nl - newline , cr - carriage return and sp - space
* trim() methods by default also takes care of these white space characters
* So trim() method is used to remove leading and trailing white spaces.
*/
XMLString s = trim();
double result = Double.NaN;
for (int i = 0; i < s.length(); i++) {
char c = s.charAt(i);
if (c != '-' && c != '.' && (c < 0X30 || c > 0x39)) {
// then return NaN because something is wrong.
return result;
}
}
try {
result = Double.parseDouble(s.toString());
} catch (NumberFormatException e) {
}
return result;
}
Aggregations