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

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

Introduction

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

Prototype

public static DateTimeFormatter dateTime() 

Source Link

Document

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

Usage

From source file:com.vityuk.ginger.provider.format.JodaTimeUtils.java

License:Apache License

private static DateTimeFormatter createJodaDateFormatter(FormatType formatType, DateFormatStyle formatStyle) {
    switch (formatType) {
    case TIME://from  w w w.j  a v  a  2  s .c o m
        switch (formatStyle) {
        case SHORT:
            return DateTimeFormat.shortTime();
        case MEDIUM:
            return DateTimeFormat.mediumTime();
        case LONG:
            return DateTimeFormat.longTime();
        case FULL:
            return DateTimeFormat.fullTime();
        case DEFAULT:
            return ISODateTimeFormat.time();
        }
    case DATE:
        switch (formatStyle) {
        case SHORT:
            return DateTimeFormat.shortDate();
        case MEDIUM:
            return DateTimeFormat.mediumDate();
        case LONG:
            return DateTimeFormat.longDate();
        case FULL:
            return DateTimeFormat.fullDate();
        case DEFAULT:
            return ISODateTimeFormat.date();
        }
    case DATETIME:
        switch (formatStyle) {
        case SHORT:
            return DateTimeFormat.shortDateTime();
        case MEDIUM:
            return DateTimeFormat.mediumDateTime();
        case LONG:
            return DateTimeFormat.longDateTime();
        case FULL:
            return DateTimeFormat.fullDateTime();
        case DEFAULT:
            return ISODateTimeFormat.dateTime();
        }
    }

    throw new IllegalArgumentException();
}

From source file:com.whizzosoftware.hobson.dsc.api.command.TimeDateBroadcast.java

License:Open Source License

public String getISO8601String() {
    return ISODateTimeFormat.dateTime().print(dateTime);
}

From source file:com.whizzosoftware.hobson.dsc.DSCSecurityPanelDevice.java

License:Open Source License

@Override
public void onSetVariables(Map<String, Object> values) {
    for (String name : values.keySet()) {
        Object value = values.get(name);
        if (VariableConstants.TIME.equals(name)) {
            try {
                DateTime dateTime = ISODateTimeFormat.dateTime().parseDateTime(value.toString());
                logger.debug("Received set time request: {}", dateTime);
                ((DSCPlugin) getPlugin()).sendSetDateTimeRequest(dateTime);
            } catch (IllegalArgumentException e) {
                logger.error("Ignoring set time request with invalid time: {}", value);
            }// w  w  w  .j  a  va 2  s . c  o  m
        } else if (VariableConstants.ARMED.equals(name)) {
            if ((boolean) value) {
                ((DSCPlugin) getPlugin()).sendArmPartitionRequest(1);
            } else {
                ((DSCPlugin) getPlugin()).sendDisarmPartitionRequest(1);
            }
        }
    }
}

From source file:common.JsonDateSerializer.java

License:Apache License

@Override
public void serialize(Date date, JsonGenerator jGen, SerializerProvider sProv)
        throws IOException, JsonProcessingException {
    DateTime dt = new DateTime(date);
    DateTimeFormatter fmt = ISODateTimeFormat.dateTime();
    jGen.writeString(fmt.print(dt));/*from ww  w  .j ava  2 s  .com*/
}

From source file:cz.cas.lib.proarc.common.workflow.model.TaskParameter.java

License:Open Source License

public String getValue() {
    String value = null;//from ww  w  . j av  a  2s .com
    if (valueType == ValueType.NUMBER) {
        BigDecimal n = getValueNumber();
        value = n == null ? null : n.toPlainString();
    } else if (valueType == ValueType.DATETIME) {
        Timestamp t = getValueDateTime();
        if (t != null) {
            value = ISODateTimeFormat.dateTime().withZoneUTC().print(t.getTime());
        }
    } else if (valueType == ValueType.STRING) {
        value = getValueString();
    } else {
        throw new IllegalStateException("Unsupported type: " + valueType);
    }
    return value;
}

From source file:ddf.catalog.services.xsltlistener.XsltResponseQueueTransformer.java

License:Open Source License

@Override
public ddf.catalog.data.BinaryContent transform(SourceResponse upstreamResponse,
        Map<String, Serializable> arguments) throws CatalogTransformerException {

    LOGGER.debug("Transforming ResponseQueue with XSLT tranformer");

    long grandTotal = -1;

    try {/*from  w  w  w. j  a  v  a 2 s  .  co m*/
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

        factory.setNamespaceAware(true);
        DocumentBuilder builder = factory.newDocumentBuilder();

        Document doc = builder.newDocument();

        Node resultsElement = doc.appendChild(createElement(doc, XML_RESULTS_NAMESPACE, "results", null));

        // TODO use streaming XSLT, not DOM
        List<Result> results = upstreamResponse.getResults();
        grandTotal = upstreamResponse.getHits();

        for (Result result : results) {
            Metacard metacard = result.getMetacard();
            String thisMetacard = metacard.getMetadata();
            if (metacard != null && thisMetacard != null) {
                Element metacardElement = createElement(doc, XML_RESULTS_NAMESPACE, "metacard", null);
                if (metacard.getId() != null) {
                    metacardElement
                            .appendChild(createElement(doc, XML_RESULTS_NAMESPACE, "id", metacard.getId()));
                }
                if (metacard.getMetacardType().toString() != null) {
                    metacardElement.appendChild(createElement(doc, XML_RESULTS_NAMESPACE, "type",
                            metacard.getMetacardType().getName()));
                }
                if (metacard.getTitle() != null) {
                    metacardElement.appendChild(
                            createElement(doc, XML_RESULTS_NAMESPACE, "title", metacard.getTitle()));
                }
                if (result.getRelevanceScore() != null) {
                    metacardElement.appendChild(createElement(doc, XML_RESULTS_NAMESPACE, "score",
                            result.getRelevanceScore().toString()));
                }
                if (result.getDistanceInMeters() != null) {
                    metacardElement.appendChild(createElement(doc, XML_RESULTS_NAMESPACE, "distance",
                            result.getDistanceInMeters().toString()));
                }
                if (metacard.getSourceId() != null) {
                    metacardElement.appendChild(
                            createElement(doc, XML_RESULTS_NAMESPACE, "site", metacard.getSourceId()));
                }
                if (metacard.getContentTypeName() != null) {
                    String contentType = metacard.getContentTypeName();
                    Element typeElement = createElement(doc, XML_RESULTS_NAMESPACE, "content-type",
                            contentType);
                    // TODO revisit what to put in the qualifier
                    typeElement.setAttribute("qualifier", "content-type");
                    metacardElement.appendChild(typeElement);
                }
                if (metacard.getResourceURI() != null) {
                    try {
                        metacardElement.appendChild(createElement(doc, XML_RESULTS_NAMESPACE, "product",
                                metacard.getResourceURI().toString()));
                    } catch (DOMException e) {
                        LOGGER.warn(" Unable to create resource uri element", e);
                    }
                }
                if (metacard.getThumbnail() != null) {
                    metacardElement.appendChild(createElement(doc, XML_RESULTS_NAMESPACE, "thumbnail",
                            Base64.encodeBase64String(metacard.getThumbnail())));
                    try {
                        String mimeType = URLConnection
                                .guessContentTypeFromStream(new ByteArrayInputStream(metacard.getThumbnail()));
                        metacardElement
                                .appendChild(createElement(doc, XML_RESULTS_NAMESPACE, "t_mimetype", mimeType));
                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        metacardElement.appendChild(
                                createElement(doc, XML_RESULTS_NAMESPACE, "t_mimetype", "image/png"));
                    }
                }
                DateTimeFormatter fmt = ISODateTimeFormat.dateTime();
                if (metacard.getCreatedDate() != null) {
                    metacardElement.appendChild(createElement(doc, XML_RESULTS_NAMESPACE, "created",
                            fmt.print(metacard.getCreatedDate().getTime())));
                }
                // looking at the date last modified
                if (metacard.getModifiedDate() != null) {
                    metacardElement.appendChild(createElement(doc, XML_RESULTS_NAMESPACE, "updated",
                            fmt.print(metacard.getModifiedDate().getTime())));
                }
                if (metacard.getEffectiveDate() != null) {
                    metacardElement.appendChild(createElement(doc, XML_RESULTS_NAMESPACE, "effective",
                            fmt.print(metacard.getEffectiveDate().getTime())));
                }
                if (metacard.getLocation() != null) {
                    metacardElement.appendChild(
                            createElement(doc, XML_RESULTS_NAMESPACE, "location", metacard.getLocation()));
                }
                Element documentElement = doc.createElementNS(XML_RESULTS_NAMESPACE, "document");
                metacardElement.appendChild(documentElement);
                resultsElement.appendChild(metacardElement);

                Node importedNode = doc.importNode(new XPathHelper(thisMetacard).getDocument().getFirstChild(),
                        true);
                documentElement.appendChild(importedNode);
            } else {
                LOGGER.debug("Null content/document returned to XSLT ResponseQueueTransformer");
                continue;
            }
        }

        if (LOGGER.isDebugEnabled()) {
            DOMImplementationLS domImplementation = (DOMImplementationLS) doc.getImplementation();
            LSSerializer lsSerializer = domImplementation.createLSSerializer();
            LOGGER.debug("Generated XML input for transform: " + lsSerializer.writeToString(doc));
        }

        LOGGER.debug("Starting responsequeue xslt transform.");

        Transformer transformer;

        Map<String, Object> mergedMap = new HashMap<String, Object>();
        mergedMap.put(GRAND_TOTAL, grandTotal);
        if (arguments != null) {
            mergedMap.putAll(arguments);
        }

        BinaryContent resultContent;
        StreamResult resultOutput = null;
        Source source = new DOMSource(doc);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        resultOutput = new StreamResult(baos);

        try {
            transformer = templates.newTransformer();
        } catch (TransformerConfigurationException tce) {
            throw new CatalogTransformerException("Could not perform Xslt transform: " + tce.getException(),
                    tce.getCause());
        }

        if (mergedMap != null && !mergedMap.isEmpty()) {
            for (Map.Entry<String, Object> entry : mergedMap.entrySet()) {
                if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug(
                            "Adding parameter to transform {" + entry.getKey() + ":" + entry.getValue() + "}");
                }
                transformer.setParameter(entry.getKey(), entry.getValue());
            }
        }

        try {
            transformer.transform(source, resultOutput);
            byte[] bytes = baos.toByteArray();
            LOGGER.debug("Transform complete.");
            resultContent = new XsltTransformedContent(bytes, mimeType);
        } catch (TransformerException te) {
            LOGGER.error("Could not perform Xslt transform: " + te.getException(), te.getCause());
            throw new CatalogTransformerException("Could not perform Xslt transform: " + te.getException(),
                    te.getCause());
        } finally {
            // transformer.reset();
            // don't need to do that unless we are putting it back into a
            // pool -- which we should do, but that can wait until later.
        }

        return resultContent;
    } catch (ParserConfigurationException e) {
        LOGGER.warn("Error creating new document: " + e.getMessage(), e.getCause());
        throw new CatalogTransformerException("Error merging entries to xml feed.", e);
    }
}

From source file:ddf.catalog.source.opensearch.impl.OpenSearchParserImpl.java

License:Open Source License

@Override
public void populateTemporal(WebClient client, TemporalFilter temporal, List<String> parameters) {
    DateTimeFormatter fmt = ISODateTimeFormat.dateTime();
    String start = "";
    String end = "";
    String name = "";
    if (temporal != null) {
        long startLng = (temporal.getStartDate() != null) ? temporal.getStartDate().getTime() : 0;
        start = fmt.print(startLng);/*w ww. j a  va2s .c  o  m*/
        long endLng = (temporal.getEndDate() != null) ? temporal.getEndDate().getTime()
                : System.currentTimeMillis();
        end = fmt.print(endLng);
    }
    checkAndReplace(client, start, TIME_START, parameters);
    checkAndReplace(client, end, TIME_END, parameters);
    checkAndReplace(client, name, TIME_NAME, parameters);
}

From source file:ddf.catalog.source.opensearch.OpenSearchSiteUtil.java

License:Open Source License

/**
 * Fills in the opensearch query URL with temporal information (Start, End, and Name). Currently
 * name is empty due to incompatibility with endpoints.
 *
 * @param client/*  w w w  .  ja v a2 s.co  m*/
 *            OpenSearch URL to populate
 * @param temporal
 *            TemporalCriteria that contains temporal data
 */
public static void populateTemporal(WebClient client, TemporalFilter temporal, List<String> parameters) {
    DateTimeFormatter fmt = ISODateTimeFormat.dateTime();
    String start = "";
    String end = "";
    String name = "";
    if (temporal != null) {
        long startLng = (temporal.getStartDate() != null) ? temporal.getStartDate().getTime() : 0;
        start = fmt.print(startLng);
        long endLng = (temporal.getEndDate() != null) ? temporal.getEndDate().getTime()
                : System.currentTimeMillis();
        end = fmt.print(endLng);
    }
    checkAndReplace(client, start, TIME_START, parameters);
    checkAndReplace(client, end, TIME_END, parameters);
    checkAndReplace(client, name, TIME_NAME, parameters);
}

From source file:de.escidoc.core.om.business.fedora.item.ItemHandlerRetrieve.java

License:Open Source License

/**
 * Gets the representation of the virtual resource {@code parents} of an item/container.
 *
 * @param itemId//from w  w  w . jav a2  s .c om
 * @return Returns the XML representation of the virtual resource {@code parents} of an container.
 * @throws de.escidoc.core.common.exceptions.system.WebserverSystemException
 * @throws de.escidoc.core.common.exceptions.system.TripleStoreSystemException
 */
public String renderParents(final String itemId) throws WebserverSystemException, TripleStoreSystemException {

    final Map<String, Object> values = new HashMap<String, Object>();
    addXlinkValues(values);
    addStructuralRelationsValues(values);
    values.put("isRootParents", XmlTemplateProviderConstants.TRUE);
    values.put(XmlTemplateProviderConstants.VAR_LAST_MODIFICATION_DATE,
            ISODateTimeFormat.dateTime().withZone(DateTimeZone.UTC).print(System.currentTimeMillis()));
    addParentsValues(values, itemId);
    addParentsNamespaceValues(values);
    return ItemXmlProvider.getInstance().getParentsXml(values);
}

From source file:de.escidoc.core.om.business.renderer.VelocityXmlContainerRenderer.java

License:Open Source License

/**
 * Gets the representation of the virtual resource {@code parents} of an item/container.
 *
 * @param containerId The Container.//from ww w .ja  va 2  s. c  om
 * @return Returns the XML representation of the virtual resource {@code parents} of an container.
 */
@Override
public String renderParents(final String containerId)
        throws WebserverSystemException, TripleStoreSystemException {

    final Map<String, Object> values = new HashMap<String, Object>();
    VelocityXmlCommonRenderer.addXlinkValues(values);
    VelocityXmlCommonRenderer.addStructuralRelationsValues(values);
    values.put(XmlTemplateProviderConstants.VAR_LAST_MODIFICATION_DATE,
            ISODateTimeFormat.dateTime().withZone(DateTimeZone.UTC).print(System.currentTimeMillis()));
    values.put("isRootParents", XmlTemplateProviderConstants.TRUE);
    addParentsValues(containerId, values);
    VelocityXmlCommonRenderer.addParentsNamespaceValues(values);
    return ContainerXmlProvider.getInstance().getParentsXml(values);
}