Example usage for org.joda.time.format ISODateTimeFormat dateTimeNoMillis

List of usage examples for org.joda.time.format ISODateTimeFormat dateTimeNoMillis

Introduction

In this page you can find the example usage for org.joda.time.format ISODateTimeFormat dateTimeNoMillis.

Prototype

public static DateTimeFormatter dateTimeNoMillis() 

Source Link

Document

Returns a formatter that combines a full date and time without millis, separated by a 'T' (yyyy-MM-dd'T'HH:mm:ssZZ).

Usage

From source file:com.tuplejump.stargate.Dates.java

License:Apache License

/**
 * Parses a joda based pattern, including some named ones (similar to the built in Joda ISO ones).
 *//*from  w w w.ja v  a 2s  .co  m*/
public static FormatDateTimeFormatter forPattern(String input, Locale locale) {
    if (StringUtils.isNotBlank(input)) {
        input = input.trim();
    }
    if (input == null || input.length() == 0) {
        throw new IllegalArgumentException("No date pattern provided");
    }

    DateTimeFormatter formatter;
    if ("basicDate".equals(input) || "basic_date".equals(input)) {
        formatter = ISODateTimeFormat.basicDate();
    } else if ("basicDateTime".equals(input) || "basic_date_time".equals(input)) {
        formatter = ISODateTimeFormat.basicDateTime();
    } else if ("basicDateTimeNoMillis".equals(input) || "basic_date_time_no_millis".equals(input)) {
        formatter = ISODateTimeFormat.basicDateTimeNoMillis();
    } else if ("basicOrdinalDate".equals(input) || "basic_ordinal_date".equals(input)) {
        formatter = ISODateTimeFormat.basicOrdinalDate();
    } else if ("basicOrdinalDateTime".equals(input) || "basic_ordinal_date_time".equals(input)) {
        formatter = ISODateTimeFormat.basicOrdinalDateTime();
    } else if ("basicOrdinalDateTimeNoMillis".equals(input)
            || "basic_ordinal_date_time_no_millis".equals(input)) {
        formatter = ISODateTimeFormat.basicOrdinalDateTimeNoMillis();
    } else if ("basicTime".equals(input) || "basic_time".equals(input)) {
        formatter = ISODateTimeFormat.basicTime();
    } else if ("basicTimeNoMillis".equals(input) || "basic_time_no_millis".equals(input)) {
        formatter = ISODateTimeFormat.basicTimeNoMillis();
    } else if ("basicTTime".equals(input) || "basic_t_Time".equals(input)) {
        formatter = ISODateTimeFormat.basicTTime();
    } else if ("basicTTimeNoMillis".equals(input) || "basic_t_time_no_millis".equals(input)) {
        formatter = ISODateTimeFormat.basicTTimeNoMillis();
    } else if ("basicWeekDate".equals(input) || "basic_week_date".equals(input)) {
        formatter = ISODateTimeFormat.basicWeekDate();
    } else if ("basicWeekDateTime".equals(input) || "basic_week_date_time".equals(input)) {
        formatter = ISODateTimeFormat.basicWeekDateTime();
    } else if ("basicWeekDateTimeNoMillis".equals(input) || "basic_week_date_time_no_millis".equals(input)) {
        formatter = ISODateTimeFormat.basicWeekDateTimeNoMillis();
    } else if ("date".equals(input)) {
        formatter = ISODateTimeFormat.date();
    } else if ("dateHour".equals(input) || "date_hour".equals(input)) {
        formatter = ISODateTimeFormat.dateHour();
    } else if ("dateHourMinute".equals(input) || "date_hour_minute".equals(input)) {
        formatter = ISODateTimeFormat.dateHourMinute();
    } else if ("dateHourMinuteSecond".equals(input) || "date_hour_minute_second".equals(input)) {
        formatter = ISODateTimeFormat.dateHourMinuteSecond();
    } else if ("dateHourMinuteSecondFraction".equals(input)
            || "date_hour_minute_second_fraction".equals(input)) {
        formatter = ISODateTimeFormat.dateHourMinuteSecondFraction();
    } else if ("dateHourMinuteSecondMillis".equals(input) || "date_hour_minute_second_millis".equals(input)) {
        formatter = ISODateTimeFormat.dateHourMinuteSecondMillis();
    } else if ("dateOptionalTime".equals(input) || "date_optional_time".equals(input)) {
        // in this case, we have a separate parser and printer since the dataOptionalTimeParser can't print
        // this sucks we should use the root local by default and not be dependent on the node
        return new FormatDateTimeFormatter(input,
                ISODateTimeFormat.dateOptionalTimeParser().withZone(DateTimeZone.UTC),
                ISODateTimeFormat.dateTime().withZone(DateTimeZone.UTC), locale);
    } else if ("dateTime".equals(input) || "date_time".equals(input)) {
        formatter = ISODateTimeFormat.dateTime();
    } else if ("dateTimeNoMillis".equals(input) || "date_time_no_millis".equals(input)) {
        formatter = ISODateTimeFormat.dateTimeNoMillis();
    } else if ("hour".equals(input)) {
        formatter = ISODateTimeFormat.hour();
    } else if ("hourMinute".equals(input) || "hour_minute".equals(input)) {
        formatter = ISODateTimeFormat.hourMinute();
    } else if ("hourMinuteSecond".equals(input) || "hour_minute_second".equals(input)) {
        formatter = ISODateTimeFormat.hourMinuteSecond();
    } else if ("hourMinuteSecondFraction".equals(input) || "hour_minute_second_fraction".equals(input)) {
        formatter = ISODateTimeFormat.hourMinuteSecondFraction();
    } else if ("hourMinuteSecondMillis".equals(input) || "hour_minute_second_millis".equals(input)) {
        formatter = ISODateTimeFormat.hourMinuteSecondMillis();
    } else if ("ordinalDate".equals(input) || "ordinal_date".equals(input)) {
        formatter = ISODateTimeFormat.ordinalDate();
    } else if ("ordinalDateTime".equals(input) || "ordinal_date_time".equals(input)) {
        formatter = ISODateTimeFormat.ordinalDateTime();
    } else if ("ordinalDateTimeNoMillis".equals(input) || "ordinal_date_time_no_millis".equals(input)) {
        formatter = ISODateTimeFormat.ordinalDateTimeNoMillis();
    } else if ("time".equals(input)) {
        formatter = ISODateTimeFormat.time();
    } else if ("tTime".equals(input) || "t_time".equals(input)) {
        formatter = ISODateTimeFormat.tTime();
    } else if ("tTimeNoMillis".equals(input) || "t_time_no_millis".equals(input)) {
        formatter = ISODateTimeFormat.tTimeNoMillis();
    } else if ("weekDate".equals(input) || "week_date".equals(input)) {
        formatter = ISODateTimeFormat.weekDate();
    } else if ("weekDateTime".equals(input) || "week_date_time".equals(input)) {
        formatter = ISODateTimeFormat.weekDateTime();
    } else if ("weekyear".equals(input) || "week_year".equals(input)) {
        formatter = ISODateTimeFormat.weekyear();
    } else if ("weekyearWeek".equals(input)) {
        formatter = ISODateTimeFormat.weekyearWeek();
    } else if ("year".equals(input)) {
        formatter = ISODateTimeFormat.year();
    } else if ("yearMonth".equals(input) || "year_month".equals(input)) {
        formatter = ISODateTimeFormat.yearMonth();
    } else if ("yearMonthDay".equals(input) || "year_month_day".equals(input)) {
        formatter = ISODateTimeFormat.yearMonthDay();
    } else if (StringUtils.isNotBlank(input) && input.contains("||")) {
        String[] formats = StringUtils.split(input, "||");
        DateTimeParser[] parsers = new DateTimeParser[formats.length];

        if (formats.length == 1) {
            formatter = forPattern(input, locale).parser();
        } else {
            DateTimeFormatter dateTimeFormatter = null;
            for (int i = 0; i < formats.length; i++) {
                FormatDateTimeFormatter currentFormatter = forPattern(formats[i], locale);
                DateTimeFormatter currentParser = currentFormatter.parser();
                if (dateTimeFormatter == null) {
                    dateTimeFormatter = currentFormatter.printer();
                }
                parsers[i] = currentParser.getParser();
            }

            DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder()
                    .append(dateTimeFormatter.withZone(DateTimeZone.UTC).getPrinter(), parsers);
            formatter = builder.toFormatter();
        }
    } else {
        try {

            formatter = DateTimeFormat.forPattern(input);
        } catch (IllegalArgumentException e) {
            throw new IllegalArgumentException("Invalid format: [" + input + "]: " + e.getMessage(), e);
        }
    }

    return new FormatDateTimeFormatter(input, formatter.withZone(DateTimeZone.UTC), locale);
}

From source file:com.tuplejump.stargate.lucene.Dates.java

License:Apache License

/**
 * Parses a joda based pattern, including some named ones (similar to the built in Joda ISO ones).
 *///  w  w w  .j a  v  a2  s .c om
public static FormatDateTimeFormatter forPattern(String input, Locale locale) {
    if (StringUtils.isNotBlank(input)) {
        input = input.trim();
    }
    DateTimeFormatter formatter;
    if (input == null || input.length() == 0) {
        formatter = ISODateTimeFormat.yearMonthDay();
    } else if ("basicDate".equals(input) || "basic_date".equals(input)) {
        formatter = ISODateTimeFormat.basicDate();
    } else if ("basicDateTime".equals(input) || "basic_date_time".equals(input)) {
        formatter = ISODateTimeFormat.basicDateTime();
    } else if ("basicDateTimeNoMillis".equals(input) || "basic_date_time_no_millis".equals(input)) {
        formatter = ISODateTimeFormat.basicDateTimeNoMillis();
    } else if ("basicOrdinalDate".equals(input) || "basic_ordinal_date".equals(input)) {
        formatter = ISODateTimeFormat.basicOrdinalDate();
    } else if ("basicOrdinalDateTime".equals(input) || "basic_ordinal_date_time".equals(input)) {
        formatter = ISODateTimeFormat.basicOrdinalDateTime();
    } else if ("basicOrdinalDateTimeNoMillis".equals(input)
            || "basic_ordinal_date_time_no_millis".equals(input)) {
        formatter = ISODateTimeFormat.basicOrdinalDateTimeNoMillis();
    } else if ("basicTime".equals(input) || "basic_time".equals(input)) {
        formatter = ISODateTimeFormat.basicTime();
    } else if ("basicTimeNoMillis".equals(input) || "basic_time_no_millis".equals(input)) {
        formatter = ISODateTimeFormat.basicTimeNoMillis();
    } else if ("basicTTime".equals(input) || "basic_t_Time".equals(input)) {
        formatter = ISODateTimeFormat.basicTTime();
    } else if ("basicTTimeNoMillis".equals(input) || "basic_t_time_no_millis".equals(input)) {
        formatter = ISODateTimeFormat.basicTTimeNoMillis();
    } else if ("basicWeekDate".equals(input) || "basic_week_date".equals(input)) {
        formatter = ISODateTimeFormat.basicWeekDate();
    } else if ("basicWeekDateTime".equals(input) || "basic_week_date_time".equals(input)) {
        formatter = ISODateTimeFormat.basicWeekDateTime();
    } else if ("basicWeekDateTimeNoMillis".equals(input) || "basic_week_date_time_no_millis".equals(input)) {
        formatter = ISODateTimeFormat.basicWeekDateTimeNoMillis();
    } else if ("date".equals(input)) {
        formatter = ISODateTimeFormat.date();
    } else if ("dateHour".equals(input) || "date_hour".equals(input)) {
        formatter = ISODateTimeFormat.dateHour();
    } else if ("dateHourMinute".equals(input) || "date_hour_minute".equals(input)) {
        formatter = ISODateTimeFormat.dateHourMinute();
    } else if ("dateHourMinuteSecond".equals(input) || "date_hour_minute_second".equals(input)) {
        formatter = ISODateTimeFormat.dateHourMinuteSecond();
    } else if ("dateHourMinuteSecondFraction".equals(input)
            || "date_hour_minute_second_fraction".equals(input)) {
        formatter = ISODateTimeFormat.dateHourMinuteSecondFraction();
    } else if ("dateHourMinuteSecondMillis".equals(input) || "date_hour_minute_second_millis".equals(input)) {
        formatter = ISODateTimeFormat.dateHourMinuteSecondMillis();
    } else if ("dateOptionalTime".equals(input) || "date_optional_time".equals(input)) {
        // in this case, we have a separate parser and printer since the dataOptionalTimeParser can't print
        // this sucks we should use the root local by default and not be dependent on the node
        return new FormatDateTimeFormatter(input,
                ISODateTimeFormat.dateOptionalTimeParser().withZone(DateTimeZone.UTC),
                ISODateTimeFormat.dateTime().withZone(DateTimeZone.UTC), locale);
    } else if ("dateTime".equals(input) || "date_time".equals(input)) {
        formatter = ISODateTimeFormat.dateTime();
    } else if ("dateTimeNoMillis".equals(input) || "date_time_no_millis".equals(input)) {
        formatter = ISODateTimeFormat.dateTimeNoMillis();
    } else if ("hour".equals(input)) {
        formatter = ISODateTimeFormat.hour();
    } else if ("hourMinute".equals(input) || "hour_minute".equals(input)) {
        formatter = ISODateTimeFormat.hourMinute();
    } else if ("hourMinuteSecond".equals(input) || "hour_minute_second".equals(input)) {
        formatter = ISODateTimeFormat.hourMinuteSecond();
    } else if ("hourMinuteSecondFraction".equals(input) || "hour_minute_second_fraction".equals(input)) {
        formatter = ISODateTimeFormat.hourMinuteSecondFraction();
    } else if ("hourMinuteSecondMillis".equals(input) || "hour_minute_second_millis".equals(input)) {
        formatter = ISODateTimeFormat.hourMinuteSecondMillis();
    } else if ("ordinalDate".equals(input) || "ordinal_date".equals(input)) {
        formatter = ISODateTimeFormat.ordinalDate();
    } else if ("ordinalDateTime".equals(input) || "ordinal_date_time".equals(input)) {
        formatter = ISODateTimeFormat.ordinalDateTime();
    } else if ("ordinalDateTimeNoMillis".equals(input) || "ordinal_date_time_no_millis".equals(input)) {
        formatter = ISODateTimeFormat.ordinalDateTimeNoMillis();
    } else if ("time".equals(input)) {
        formatter = ISODateTimeFormat.time();
    } else if ("tTime".equals(input) || "t_time".equals(input)) {
        formatter = ISODateTimeFormat.tTime();
    } else if ("tTimeNoMillis".equals(input) || "t_time_no_millis".equals(input)) {
        formatter = ISODateTimeFormat.tTimeNoMillis();
    } else if ("weekDate".equals(input) || "week_date".equals(input)) {
        formatter = ISODateTimeFormat.weekDate();
    } else if ("weekDateTime".equals(input) || "week_date_time".equals(input)) {
        formatter = ISODateTimeFormat.weekDateTime();
    } else if ("weekyear".equals(input) || "week_year".equals(input)) {
        formatter = ISODateTimeFormat.weekyear();
    } else if ("weekyearWeek".equals(input)) {
        formatter = ISODateTimeFormat.weekyearWeek();
    } else if ("year".equals(input)) {
        formatter = ISODateTimeFormat.year();
    } else if ("yearMonth".equals(input) || "year_month".equals(input)) {
        formatter = ISODateTimeFormat.yearMonth();
    } else if ("yearMonthDay".equals(input) || "year_month_day".equals(input)) {
        formatter = ISODateTimeFormat.yearMonthDay();
    } else if (StringUtils.isNotBlank(input) && input.contains("||")) {
        String[] formats = StringUtils.split(input, "||");
        DateTimeParser[] parsers = new DateTimeParser[formats.length];

        if (formats.length == 1) {
            formatter = forPattern(input, locale).parser();
        } else {
            DateTimeFormatter dateTimeFormatter = null;
            for (int i = 0; i < formats.length; i++) {
                FormatDateTimeFormatter currentFormatter = forPattern(formats[i], locale);
                DateTimeFormatter currentParser = currentFormatter.parser();
                if (dateTimeFormatter == null) {
                    dateTimeFormatter = currentFormatter.printer();
                }
                parsers[i] = currentParser.getParser();
            }
            DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder()
                    .append(dateTimeFormatter.withZone(DateTimeZone.UTC).getPrinter(), parsers);
            formatter = builder.toFormatter();
        }
    } else {
        try {

            formatter = DateTimeFormat.forPattern(input);
        } catch (IllegalArgumentException e) {
            throw new IllegalArgumentException("Invalid format: [" + input + "]: " + e.getMessage(), e);
        }
    }

    return new FormatDateTimeFormatter(input, formatter.withZone(DateTimeZone.UTC), locale);
}

From source file:com.xebia.devradar.GitHubFetcher.java

License:Apache License

private Event transformCommitToEvent(GithubCommitDTO githubCommitDTO) {
    DateTime dateTime = ISODateTimeFormat.dateTimeNoMillis().parseDateTime(githubCommitDTO.committed_date);
    return new Event(dateTime.getMillis(), githubCommitDTO.committer.name, githubCommitDTO.message,
            githubCommitDTO.committer.email);
}

From source file:controllers.logic.ResultParser.java

License:Open Source License

private void initElementHandlers() {
    elementHandlers = new Hashtable<String, ResultElementHandler>();
    elementHandlers.put(OPEN_ROSA_INSTANCE_ID, new ResultElementHandler() {

        public void handleElement(ResultParser parser, Element element) {
            result.resultId = element.getText(0);
        }//  w  w w  .ja va  2  s .  c  o  m
    });

    elementHandlers.put(OPEN_ROSA_TIME_START, new ResultElementHandler() {

        public void handleElement(ResultParser parser, Element element) {
            result.startTime = ISODateTimeFormat.dateTimeNoMillis().parseDateTime(element.getText(0)).toDate();
        }
    });

    elementHandlers.put(OPEN_ROSA_TIME_FINISH, new ResultElementHandler() {

        @Override
        public void handleElement(ResultParser parser, Element element) {
            result.endTime = ISODateTimeFormat.dateTimeNoMillis().parseDateTime(element.getText(0)).toDate();
        }
    });

    elementHandlers.put(OPEN_ROSA_GEOSTAMP, new ResultElementHandler() {

        public void handleElement(ResultParser parser, Element element) {
            String[] coordinates = element.getText(0).split(" ");
            result.latitude = coordinates[0];
            result.longitude = coordinates[1];
        }
    });

}

From source file:ddf.metrics.plugin.webconsole.MetricsWebConsolePlugin.java

License:Open Source License

private static String urlEncodeDate(DateTime date) throws UnsupportedEncodingException {
    return URLEncoder.encode(date.toString(ISODateTimeFormat.dateTimeNoMillis()), CharEncoding.UTF_8);
}

From source file:ddf.metrics.reporting.internal.rest.MetricsEndpoint.java

License:Open Source License

/**
 * Parse date in ISO8601 format into seconds since Unix epoch.
 *
 * @param date//from www .  j  a  v  a  2  s.c  o  m
 * @return
 */
protected long parseDate(String date) {
    DateTimeFormatter dateFormatter = ISODateTimeFormat.dateTimeNoMillis();
    Date formattedDate = dateFormatter.parseDateTime(date).toDate();

    return formattedDate.getTime() / 1000;
}

From source file:edu.internet2.middleware.shibboleth.idp.StatusServlet.java

License:Open Source License

/** {@inheritDoc} */
public void init(ServletConfig config) throws ServletException {
    super.init(config);

    allowedIPs = new LazyList<IPRange>();

    String cidrBlocks = DatatypeHelper.safeTrimOrNullString(config.getInitParameter(IP_PARAM_NAME));
    if (cidrBlocks != null) {
        for (String cidrBlock : cidrBlocks.split(" ")) {
            allowedIPs.add(IPRange.parseCIDRBlock(cidrBlock));
        }/*from   www . ja  va  2s .com*/
    }

    dateFormat = ISODateTimeFormat.dateTimeNoMillis();
    startTime = new DateTime(ISOChronology.getInstanceUTC());
    attributeResolver = HttpServletHelper.getAttributeResolver(config.getServletContext());
    rpConfigManager = HttpServletHelper.getRelyingPartyConfirmationManager(config.getServletContext());
}

From source file:google.registry.xml.XmlTestUtils.java

License:Open Source License

/**
 * Deeply explore the object and normalize values so that things we consider equal compare so.
 * The return value consists of two parts: the updated key and the value. The value is
 * straightforward enough: it is the rendering of the subtree to be attached at the current point.
 * The key is more complicated, because of namespaces. When an XML element specifies namespaces
 * using xmlns attributes, those namespaces apply to the element as well as all of its
 * descendants. That means that, when prefixing the element name with the full namespace path,
 * as required to do proper comparison, the element name depends on its children. When looping
 * through a JSONObject map, we can't just recursively generate the value and store it using the
 * key. We may have to update the key as well, to get the namespaces correct. A returned key of
 * null indicates that we should use the existing key. A non-null key indicates that we should
 * replace the existing key./*from www  . ja v  a2s  .  c o m*/
 *
 * @param elementName the name under which the current subtree was found, or null if the current
 *     subtree's name is nonexistent or irrelevant
 * @param obj the current subtree
 * @param path the (non-namespaced) element path used for ignoredPaths purposes
 * @param ignoredPaths the set of paths whose values should be set to IGNORED
 * @param nsMap the inherited namespace identifier-to-URI map
 * @return the key under which the rendered subtree should be stored (or null), and the rendered
 *     subtree
 */
private static Map.Entry<String, Object> normalize(@Nullable String elementName, Object obj,
        @Nullable String path, Set<String> ignoredPaths, Map<String, String> nsMap) throws Exception {
    if (obj instanceof JSONObject) {
        JSONObject jsonObject = (JSONObject) obj;
        Map<String, Object> map = new HashMap<>();
        String[] names = JSONObject.getNames(jsonObject);
        if (names != null) {
            // Separate all elements and keys into namespace specifications, which we must process
            // first, and everything else.
            ImmutableList.Builder<String> namespacesBuilder = new ImmutableList.Builder<>();
            ImmutableList.Builder<String> othersBuilder = new ImmutableList.Builder<>();
            for (String key : names) {
                (key.startsWith("xmlns") ? namespacesBuilder : othersBuilder).add(key);
            }
            // First, handle all namespace specifications, updating our ns-to-URI map. Use a HashMap
            // rather than an ImmutableMap.Builder so that we can override existing map entries.
            HashMap<String, String> newNsMap = new HashMap<>();
            newNsMap.putAll(nsMap);
            for (String key : namespacesBuilder.build()) {
                // Parse the attribute name, of the form xmlns:nsid, and extract the namespace identifier.
                // If there's no colon, we are setting the default namespace.
                List<String> components = Splitter.on(':').splitToList(key);
                String ns = (components.size() >= 2) ? components.get(1) : "";
                newNsMap.put(ns, jsonObject.get(key).toString());
            }
            nsMap = ImmutableMap.copyOf(newNsMap);
            // Now, handle the non-namespace items, recursively transforming the map and mapping all
            // namespaces to the full URI for proper comparison.
            for (String key : othersBuilder.build()) {
                String simpleKey = Iterables.getLast(Splitter.on(':').split(key));
                String newPath = (path == null) ? simpleKey : (path + "." + simpleKey);
                String mappedKey;
                Object value;
                if (ignoredPaths.contains(newPath)) {
                    mappedKey = null;
                    // Set ignored fields to a value that will compare equal.
                    value = "IGNORED";
                } else {
                    Map.Entry<String, Object> simpleEntry = normalize(key, jsonObject.get(key), newPath,
                            ignoredPaths, nsMap);
                    mappedKey = simpleEntry.getKey();
                    value = simpleEntry.getValue();
                }
                if (mappedKey == null) {
                    // Note that this does not follow the XML rules exactly. I read somewhere that attribute
                    // names, unlike element names, never use the default namespace. But after
                    // JSONification, we cannot distinguish between attributes and child elements, so we
                    // apply the default namespace to everything. Hopefully that will not cause a problem.
                    mappedKey = key.equals("content") ? key : mapName(key, nsMap, true);
                }
                map.put(mappedKey, value);
            }
        }
        // Map the namespace of the element name of the map we are normalizing.
        elementName = mapName(elementName, nsMap, true);
        // If a node has both text content and attributes, the text content will end up under a key
        // called "content". If that's the only thing left (which will only happen if there was an
        // "xmlns:*" key that we removed), treat the node as just text and recurse.
        if (map.size() == 1 && map.containsKey("content")) {
            return new AbstractMap.SimpleEntry<>(elementName,
                    normalize(null, jsonObject.get("content"), path, ignoredPaths, nsMap).getValue());
        }
        // The conversion to JSON converts <a/> into "" and the semantically equivalent <a></a> into
        // an empty map, so normalize that here.
        return new AbstractMap.SimpleEntry<>(elementName, map.isEmpty() ? "" : map);
    }
    if (obj instanceof JSONArray) {
        // Another problem resulting from JSONification: If the array contains elements whose names
        // are the same before URI expansion, but different after URI expansion, because they use
        // xmlns attribute that define the namespaces differently, we will screw up. Again, hopefully
        // that doesn't happen much. The reverse is also true: If the array contains names that are
        // different before URI expansion, but the same after, we may have a problem, because the
        // elements will wind up in different JSONArrays as a result of JSONification. We wave our
        // hands and just assume that the URI expansion of the first element holds for all others.
        Set<Object> set = new HashSet<>();
        String mappedKey = null;
        for (int i = 0; i < ((JSONArray) obj).length(); ++i) {
            Map.Entry<String, Object> simpleEntry = normalize(null, ((JSONArray) obj).get(i), path,
                    ignoredPaths, nsMap);
            if (i == 0) {
                mappedKey = simpleEntry.getKey();
            }
            set.add(simpleEntry.getValue());
        }
        return new AbstractMap.SimpleEntry<String, Object>(mappedKey, set);
    }
    if (obj instanceof Number) {
        return new AbstractMap.SimpleEntry<String, Object>(null, obj.toString());
    }
    if (obj instanceof Boolean) {
        return new AbstractMap.SimpleEntry<String, Object>(null, ((Boolean) obj) ? "1" : "0");
    }
    if (obj instanceof String) {
        // Turn stringified booleans into integers. Both are acceptable as xml boolean values, but
        // we use "true" and "false" whereas the samples use "1" and "0".
        if (obj.equals("true")) {
            return new AbstractMap.SimpleEntry<String, Object>(null, "1");
        }
        if (obj.equals("false")) {
            return new AbstractMap.SimpleEntry<String, Object>(null, "0");
        }
        String string = obj.toString();
        // We use a slightly different datetime format (both legal) than the samples, so normalize
        // both into Datetime objects.
        try {
            return new AbstractMap.SimpleEntry<String, Object>(null,
                    ISODateTimeFormat.dateTime().parseDateTime(string).toDateTime(UTC));
        } catch (IllegalArgumentException e) {
            // It wasn't a DateTime.
        }
        try {
            return new AbstractMap.SimpleEntry<String, Object>(null,
                    ISODateTimeFormat.dateTimeNoMillis().parseDateTime(string).toDateTime(UTC));
        } catch (IllegalArgumentException e) {
            // It wasn't a DateTime.
        }
        try {
            if (!InternetDomainName.isValid(string)) {
                // It's not a domain name, but it is an InetAddress. Ergo, it's an ip address.
                return new AbstractMap.SimpleEntry<String, Object>(null, InetAddresses.forString(string));
            }
        } catch (IllegalArgumentException e) {
            // Not an ip address.
        }
        return new AbstractMap.SimpleEntry<String, Object>(null, string);
    }
    return new AbstractMap.SimpleEntry<>(null, checkNotNull(obj));
}

From source file:hudson.plugins.collabnet.orchestrate.DefaultBuildToJSON.java

License:Apache License

/**
 * Converts the standard timestamp from Java format to EventQ's format.
 *
 *
 * @param time the time to convert//from ww w  . j  a va 2s. c om
 * @return the formatted time
 */
public String convertTime(Date time) {
    DateTimeFormatter dateTimeFormatter = ISODateTimeFormat.dateTimeNoMillis().withZone(DateTimeZone.UTC);
    return dateTimeFormatter.print(time.getTime());
}

From source file:io.apiman.manager.api.core.metrics.AbstractMetricsAccessor.java

License:Apache License

/**
 * @param date
 */
protected static String formatDate(DateTime date) {
    return ISODateTimeFormat.dateTimeNoMillis().print(date);
}