/** * Gets the given text content as String if the type is a string base type * @param type * @param result * @return */ protected String convertToString(XQItemType type,XQResultSequence result) throws XQException { boolean skipBaseTypes = shouldSkipBaseType(type); String value = null; if(!skipBaseTypes) { int baseType = type.getBaseType(); if(baseType == XQBASETYPE_STRING) { value = result.getAtomicValue(); } } else if(XQITEMKIND_TEXT == type.getItemKind()) { value = result.getNode().getTextContent(); } else if(XQITEMKIND_ATTRIBUTE == type.getItemKind()) { value = ((Attr)result.getNode()).getValue(); } return value; }
@Override public List<Node> mapResults(XQResultSequence result) { List<Node> results = new ArrayList<Node>(); try { while(result.next()) { XQItemType type = result.getItemType(); if(isNodeType(type)) { Node n = result.getNode(); results.add(n); } } } catch (Exception e) { throw new MessagingException("Caught Exception while mapping the result sequence to string",e); } return results; }
@Override public List<Number> mapResults(XQResultSequence result) { List<Number> results = new ArrayList<Number>(); try { while(result.next()) { XQItemType type = result.getItemType(); Number value = convertToNumber(type, result); if(value == null && isNodeType(type)) { Node n = result.getNode(); String strValue = transformNodeToString(n); if(StringUtils.hasText(strValue)) { if(strValue.indexOf('.') > 0) { value = Double.valueOf(strValue); } else { value = Long.valueOf(strValue); } } } results.add(value); } } catch (Exception e) { throw new MessagingException("Caught Exception while mapping the result sequence to string",e); } return results; }
/** * Checks the data type of the string and converts to boolean if applicable. * The types have to be either boolean or string. For a string value, * the returned value is same as Boolean.valueOf(strValue) * * @param type * @param result * @return */ protected Boolean convertToBoolean(XQItemType type,XQResultSequence result) throws XQException { boolean skipBaseTypes = shouldSkipBaseType(type); Boolean value = null; if(!skipBaseTypes) { if(type.getBaseType() == XQBASETYPE_BOOLEAN) { value = Boolean.valueOf(result.getBoolean()); } else if(type.getBaseType() == XQBASETYPE_STRING) { value = Boolean.valueOf(result.getAtomicValue()); } } else if(XQITEMKIND_TEXT == type.getItemKind()) { String textContent = result.getNode().getTextContent(); value = Boolean.valueOf(textContent); } else if(XQITEMKIND_ATTRIBUTE == type.getItemKind()) { String textContent = ((Attr)result.getNode()).getValue(); value = Boolean.valueOf(textContent); } return value; }
@Override public List<Boolean> mapResults(XQResultSequence result) { List<Boolean> results = new ArrayList<Boolean>(); try { //check for boolean or string type and convert it accordingly, if a node then get it's text //content and convert to boolean while(result.next()) { XQItemType type = result.getItemType(); Boolean value = convertToBoolean(type, result); if(value == null && isNodeType(type)) { Node n = result.getNode(); value = Boolean.valueOf(transformNodeToString(n)); } results.add(value); } } catch (Exception e) { throw new MessagingException("Caught Exception while mapping the result sequence to string",e); } return results; }
if(boolValue == null) { if(isNodeType(type)) { Node n = result.getNode(); value = transformNodeToString(n);