/** * 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; }
/** * 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; }
value = Double.valueOf(result.getAtomicValue()); String strValue = result.getAtomicValue(); value = convertStringToNumber(strValue);