Example usage for javax.xml.bind DatatypeConverter printDouble

List of usage examples for javax.xml.bind DatatypeConverter printDouble

Introduction

In this page you can find the example usage for javax.xml.bind DatatypeConverter printDouble.

Prototype

public static String printDouble(double val) 

Source Link

Document

Converts a double value into a string.

Usage

From source file:Main.java

/**
 * Converts Double into XML-Tag with type xsd:float
 *//*from   w w  w .  ja  v a  2  s .  c  o  m*/
public static String getXMLDouble(final Double value) {
    return DatatypeConverter.printDouble(value);
}

From source file:com.actian.ilabs.dataflow.stringtemplate.runner.RunStringTemplate.java

private String FormatFieldValue(ScalarInputField field) {
    ScalarTokenType type = field.getType();
    String valueString = "";

    if (type.equals(TokenTypeConstant.BOOLEAN)) {
        BooleanInputField boolField = (BooleanInputField) field;
        valueString = DatatypeConverter.printBoolean(boolField.asBoolean());
    } else if (type.equals(TokenTypeConstant.BINARY)) {
        BinaryInputField binField = (BinaryInputField) field;
        valueString = DatatypeConverter.printHexBinary(binField.asBinary());
    } else if (type.equals(TokenTypeConstant.CHAR)) {
        CharInputField charField = (CharInputField) field;
        valueString = charField.toString();
    } else if (type.equals(TokenTypeConstant.DATE)) {
        DateInputField dateField = (DateInputField) field;
        DateFormatter dateFormatter = new DateFormatter("yyyyMMdd");
        dateFormatter.setSource(dateField);
        valueString = dateFormatter.format();
    } else if (type.equals(TokenTypeConstant.DOUBLE)) {
        DoubleInputField doubleField = (DoubleInputField) field;
        valueString = DatatypeConverter.printDouble(doubleField.asDouble());
    } else if (type.equals(TokenTypeConstant.FLOAT)) {
        FloatInputField floatField = (FloatInputField) field;
        valueString = DatatypeConverter.printFloat(floatField.asFloat());
    } else if (type.equals(TokenTypeConstant.INT)) {
        IntInputField intField = (IntInputField) field;
        valueString = DatatypeConverter.printInt(intField.asInt());
    } else if (type.equals(TokenTypeConstant.LONG)) {
        LongInputField longField = (LongInputField) field;
        valueString = DatatypeConverter.printLong(longField.asLong());
    } else if (type.equals(TokenTypeConstant.NUMERIC)) {
        NumericInputField numericField = (NumericInputField) field;
        valueString = DatatypeConverter.printDecimal(numericField.asBigDecimal());
    } else if (type.equals(TokenTypeConstant.STRING)) {
        StringInputField stringField = (StringInputField) field;
        valueString = DatatypeConverter.printString(stringField.asString());
    } else if (type.equals(TokenTypeConstant.TIME)) {
        TimeInputField timeField = (TimeInputField) field;
        TimeFormatter timeFormatter = new TimeFormatter("HHmmss.SSSZ");
        timeFormatter.setSource(timeField);
        valueString = timeFormatter.format();
    } else if (type.equals(TokenTypeConstant.TIMESTAMP)) {
        TimestampInputField timestampField = (TimestampInputField) field;
        TimestampFormatter timestampFormatter = new TimestampFormatter("yyyyMMdd'T'HHmmss.SSSZ");
        timestampFormatter.setSource(timestampField);
        valueString = timestampFormatter.format();
    } else {//from   w  ww.  ja  va  2 s. c om
        valueString = "";
    }

    return valueString;
}

From source file:org.kalypso.service.wps.utils.simulation.WPSSimulationResultEater.java

/**
 * This function will create a LiteralValueType with the given object (String, Integer, Double, Boolean).
 *
 * @param result/*  ww w.j av a2s.  co  m*/
 *          One of the types String, Integer, Double and Boolean.
 * @return A LiteralValueType with the given value.
 */
private LiteralValueType addLiteralValueType(final Object result) {
    String value = ""; //$NON-NLS-1$
    String dataType = ""; //$NON-NLS-1$
    if (result instanceof String) {
        value = DatatypeConverter.printString((String) result);
        dataType = "string"; //$NON-NLS-1$
    } else if (result instanceof Integer) {
        value = DatatypeConverter.printInt(((Integer) result).intValue());
        dataType = "int"; //$NON-NLS-1$
    } else if (result instanceof Double) {
        value = DatatypeConverter.printDouble(((Double) result).doubleValue());
        dataType = "double"; //$NON-NLS-1$
    } else if (result instanceof Boolean) {
        value = DatatypeConverter.printBoolean(((Boolean) result).booleanValue());
        dataType = "boolean"; //$NON-NLS-1$
    } else {
        /* Other types will be ignored. */
        return null;
    }

    /* Build the literal value type. */
    return WPS040ObjectFactoryUtilities.buildLiteralValueType(value, dataType, null);
}

From source file:org.openestate.io.openimmo.converters.OpenImmo_1_2_0.java

/**
 * Downgrade <mieteinnahmen_ist>, <mieteinnahmen_soll> elements
 * to OpenImmo 1.1./*from   w  w w. j  a v  a  2s.  c  o  m*/
 * <p>
 * The "periode" attribute of the &lt;mieteinnahmen_ist&gt; and
 * &lt;mieteinnahmen_soll&gt; elements is not available in version 1.1.
 * <p>
 * Any occurences of these values is removed.
 * <p>
 * The numeric value within the &lt;mieteinnahmen_ist&gt; and
 * &lt;mieteinnahmen_soll&gt; elements is converted according to the value of
 * the "periode" attribute.
 *
 * @param doc OpenImmo document in version 1.2.0
 * @throws JaxenException
 */
protected void downgradeMieteinnahmenElements(Document doc) throws JaxenException {
    List nodes = XmlUtils
            .newXPath(
                    "/io:openimmo/io:anbieter/io:immobilie/io:preise/io:mieteinnahmen_ist[@periode] |"
                            + "/io:openimmo/io:anbieter/io:immobilie/io:preise/io:mieteinnahmen_soll[@periode]",
                    doc)
            .selectNodes(doc);
    for (Object item : nodes) {
        Element node = (Element) item;

        String value = StringUtils.trimToNull(node.getTextContent());
        Double numericValue = null;
        try {
            numericValue = (value != null) ? DatatypeConverter.parseDouble(value) : null;
        } catch (Exception ex) {
            String tagName = node.getTagName();
            LOGGER.warn("Can't parse <" + tagName + ">" + value + "</" + tagName + "> as number!");
            LOGGER.warn("> " + ex.getLocalizedMessage(), ex);
        }

        if (numericValue != null && numericValue > 0) {
            String periode = StringUtils.trimToNull(node.getAttribute("periode"));
            if ("MONAT".equalsIgnoreCase(periode)) {
                node.setTextContent(DatatypeConverter.printDouble(numericValue * 12));
            } else if ("WOCHE".equalsIgnoreCase(periode)) {
                node.setTextContent(DatatypeConverter.printDouble(numericValue * 52));
            } else if ("TAG".equalsIgnoreCase(periode)) {
                node.setTextContent(DatatypeConverter.printDouble(numericValue * 365));
            }
        }

        node.removeAttribute("periode");
    }
}