Java Code Examples for javax.xml.bind.DatatypeConverter#parseDecimal()

The following examples show how to use javax.xml.bind.DatatypeConverter#parseDecimal() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TrovitUtils.java    From OpenEstate-IO with Apache License 2.0 6 votes vote down vote up
/**
 * Read a {@link BigDecimal} value from XML for a number of rooms.
 *
 * @param value XML string
 * @return parsed value or null, if the value is invalid
 */
public static BigDecimal parseRoomsValue(String value) {
    value = StringUtils.trimToNull(value);
    if (value == null) return null;

    final Matcher m = ROOMS_INTERVAL.matcher(value);
    if (m.find()) {
        final int from = Integer.parseInt(m.group(1));
        final int to = Integer.parseInt(m.group(2));
        if ((to - from) != -1) {
            throw new IllegalArgumentException("Can't parse rooms value '" + value + "' because of an invalid interval!");
        }
        return DatatypeConverter.parseDecimal(to + ".5");
    }

    try {
        return DatatypeConverter.parseDecimal(value);
    } catch (NumberFormatException ex) {
        throw new IllegalArgumentException("Can't parse rooms value '" + value + "'!", ex);
    }
}
 
Example 2
Source File: CloverDecimalConvertor.java    From CloverETL-Engine with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static Numeric parseXsdDecimalToNumeric(String value) throws DataConversionException {
    Numeric result = null;
    String valueType = Numeric.class.getName();
    
    try {
        BigDecimal decimal = DatatypeConverter.parseDecimal(value);
        result = DecimalFactory.getDecimal(decimal);
    } catch(Exception e) {
        if (result != null) valueType = result.getClass().getName();
        logger.fatal("Unable to parse xsd:decimal to "+valueType+".",e);
        throw new DataConversionException("Unable to parse xsd:decimal to "+valueType+".", e);
    }
    
    return result;
}
 
Example 3
Source File: TrovitUtils.java    From OpenEstate-IO with Apache License 2.0 5 votes vote down vote up
/**
 * Read a {@link BigDecimal} value from XML for a price.
 *
 * @param value XML string
 * @return parsed value or null, if the value is invalid
 */
public static BigDecimal parsePriceValue(String value) {
    value = StringUtils.trimToNull(value);
    if (value == null) return null;
    try {
        return DatatypeConverter.parseDecimal(value);
    } catch (NumberFormatException ex) {
        throw new IllegalArgumentException("Can't parse price value '" + value + "'!", ex);
    }
}
 
Example 4
Source File: TrovitUtils.java    From OpenEstate-IO with Apache License 2.0 5 votes vote down vote up
/**
 * Read a {@link BigDecimal} value from XML
 * with a valid longitude range.
 *
 * @param value XML string
 * @return parsed value or null, if the value is invalid
 */
public static BigDecimal parseLongitudeValue(String value) {
    try {
        value = StringUtils.trimToNull(value);
        return (value != null) ? DatatypeConverter.parseDecimal(value) : null;
    } catch (NumberFormatException ex) {
        throw new IllegalArgumentException("Can't parse longitude value '" + value + "'!", ex);
    }
}
 
Example 5
Source File: TrovitUtils.java    From OpenEstate-IO with Apache License 2.0 5 votes vote down vote up
/**
 * Read a {@link BigDecimal} value from XML
 * with a valid latitude range.
 *
 * @param value XML string
 * @return parsed value or null, if the value is invalid
 */
public static BigDecimal parseLatitudeValue(String value) {
    try {
        value = StringUtils.trimToNull(value);
        return (value != null) ? DatatypeConverter.parseDecimal(value) : null;
    } catch (NumberFormatException ex) {
        throw new IllegalArgumentException("Can't parse latitude value '" + value + "'!", ex);
    }
}
 
Example 6
Source File: ValueConverter.java    From java-client-api with Apache License 2.0 5 votes vote down vote up
static public BigDecimal StringToBigDecimal(String value) {
  try {
    return (value == null || value.length() == 0) ? null :
          DatatypeConverter.parseDecimal(value);
  } catch(Exception e) {
    throw new IllegalArgumentException("Could not convert to BigDecimal: "+value, e);
  }
}
 
Example 7
Source File: CasaItUtils.java    From OpenEstate-IO with Apache License 2.0 4 votes vote down vote up
public static BigDecimal parseDouble(String value) {
    value = StringUtils.trimToNull(value);
    return (value != null) ? DatatypeConverter.parseDecimal(value) : null;
}
 
Example 8
Source File: ImmobiliareItUtils.java    From OpenEstate-IO with Apache License 2.0 4 votes vote down vote up
public static BigDecimal parseLatitude(String value) {
    value = StringUtils.trimToNull(value);
    return (value != null) ? DatatypeConverter.parseDecimal(value) : null;
}
 
Example 9
Source File: KyeroUtils.java    From OpenEstate-IO with Apache License 2.0 4 votes vote down vote up
public static BigDecimal parseDecimal(String value) {
    value = StringUtils.trimToNull(value);
    return (value != null) ? DatatypeConverter.parseDecimal(value) : null;
}
 
Example 10
Source File: WisItUtils.java    From OpenEstate-IO with Apache License 2.0 4 votes vote down vote up
public static BigDecimal parseDecimal(String value) {
    value = StringUtils.trimToNull(value);
    return (value != null) ? DatatypeConverter.parseDecimal(value) : null;
}
 
Example 11
Source File: Is24XmlUtils.java    From OpenEstate-IO with Apache License 2.0 4 votes vote down vote up
public static BigDecimal parsePreisAufAnfrage(String value) {
    value = StringUtils.trimToNull(value);
    return (value != null) ? DatatypeConverter.parseDecimal(value) : null;
}
 
Example 12
Source File: Is24XmlUtils.java    From OpenEstate-IO with Apache License 2.0 4 votes vote down vote up
public static BigDecimal parseZimmeranzahl(String value) {
    value = StringUtils.trimToNull(value);
    return (value != null) ? DatatypeConverter.parseDecimal(value) : null;
}
 
Example 13
Source File: Is24XmlUtils.java    From OpenEstate-IO with Apache License 2.0 4 votes vote down vote up
public static BigDecimal parseZahl152(String value) {
    value = StringUtils.trimToNull(value);
    return (value != null) ? DatatypeConverter.parseDecimal(value) : null;
}
 
Example 14
Source File: Is24XmlUtils.java    From OpenEstate-IO with Apache License 2.0 4 votes vote down vote up
public static BigDecimal parseZahl102(String value) {
    value = StringUtils.trimToNull(value);
    return (value != null) ? DatatypeConverter.parseDecimal(value) : null;
}
 
Example 15
Source File: Is24XmlUtils.java    From OpenEstate-IO with Apache License 2.0 4 votes vote down vote up
public static BigDecimal parseZahl72(String value) {
    value = StringUtils.trimToNull(value);
    return (value != null) ? DatatypeConverter.parseDecimal(value) : null;
}
 
Example 16
Source File: Is24XmlUtils.java    From OpenEstate-IO with Apache License 2.0 4 votes vote down vote up
public static BigDecimal parseZahl62(String value) {
    value = StringUtils.trimToNull(value);
    return (value != null) ? DatatypeConverter.parseDecimal(value) : null;
}
 
Example 17
Source File: ImmobiliareItUtils.java    From OpenEstate-IO with Apache License 2.0 4 votes vote down vote up
public static BigDecimal parseLongitude(String value) {
    value = StringUtils.trimToNull(value);
    return (value != null) ? DatatypeConverter.parseDecimal(value) : null;
}
 
Example 18
Source File: Is24XmlUtils.java    From OpenEstate-IO with Apache License 2.0 4 votes vote down vote up
public static BigDecimal parseZahl42(String value) {
    value = StringUtils.trimToNull(value);
    return (value != null) ? DatatypeConverter.parseDecimal(value) : null;
}
 
Example 19
Source File: Is24XmlUtils.java    From OpenEstate-IO with Apache License 2.0 4 votes vote down vote up
public static BigDecimal parseZahl32(String value) {
    value = StringUtils.trimToNull(value);
    return (value != null) ? DatatypeConverter.parseDecimal(value) : null;
}
 
Example 20
Source File: ValueConverter.java    From java-client-api with Apache License 2.0 4 votes vote down vote up
static public Object convertToJava(String type, String value) {
  if ("xs:anySimpleType".equals(type))
    return DatatypeConverter.parseAnySimpleType(value);
  if ("xs:base64Binary".equals(type))
    return DatatypeConverter.parseBase64Binary(value);
  if ("xs:boolean".equals(type)) return StringToBoolean(value);
  if ("xs:byte".equals(type))
    return DatatypeConverter.parseByte(value);
  if ("xs:date".equals(type))
    return DatatypeConverter.parseDate(value);
  if ("xs:dateTime".equals(type))
    return DatatypeConverter.parseDateTime(value);
  if ("xs:dayTimeDuration".equals(type))
    return Utilities.getDatatypeFactory().newDurationDayTime(value);
  if ("xs:decimal".equals(type))
    return DatatypeConverter.parseDecimal(value);
  if ("xs:double".equals(type)) return StringToDouble(value);
  if ("xs:duration".equals(type))
    return Utilities.getDatatypeFactory().newDuration(value);
  if ("xs:float".equals(type)) return StringToFloat(value);
  if ("xs:int".equals(type)) return StringToInteger(value);
  if ("xs:integer".equals(type))
    return DatatypeConverter.parseInteger(value);
  if ("xs:long".equals(type)) return StringToLong(value);
  if ("xs:short".equals(type))
    return DatatypeConverter.parseShort(value);
  if ("xs:string".equals(type))
    return DatatypeConverter.parseString(value);
  if ("xs:time".equals(type))
    return DatatypeConverter.parseTime(value);
  if ("xs:unsignedInt".equals(type))
    return DatatypeConverter.parseUnsignedInt(value);
  if ("xs:unsignedLong".equals(type)) {
    BigInteger bi = DatatypeConverter.parseInteger(value);
    if (bi.compareTo(MAX_UNSIGNED_LONG) < 0) {
      return bi.longValue();
    } else {
      return bi;
    }
  } if ("xs:unsignedShort".equals(type))
    return DatatypeConverter.parseUnsignedShort(value);
  if ("xs:yearMonthDuration".equals(type))
    return Utilities.getDatatypeFactory().newDurationYearMonth(value);
  return value;
}