Example usage for org.joda.time DateTime withZone

List of usage examples for org.joda.time DateTime withZone

Introduction

In this page you can find the example usage for org.joda.time DateTime withZone.

Prototype

public DateTime withZone(DateTimeZone newZone) 

Source Link

Document

Returns a copy of this datetime with a different time zone, preserving the millisecond instant.

Usage

From source file:de.escidoc.core.aa.business.renderer.VelocityXmlUserGroupRenderer.java

License:Open Source License

/**
 * See Interface for functional description.
 *
 *///from   www  . j av  a 2s. co  m
@Override
public String renderGrant(final RoleGrant grant) throws WebserverSystemException {

    final Map<String, Object> values = new HashMap<String, Object>();

    values.put("isRootGrant", XmlTemplateProviderConstants.TRUE);
    values.put("grantNamespacePrefix", Constants.GRANTS_NS_PREFIX);
    values.put("grantNamespace", Constants.GRANTS_NS_URI);
    values.put(XmlTemplateProviderConstants.ESCIDOC_PROPERTIES_NS_PREFIX, Constants.PROPERTIES_NS_PREFIX);
    values.put(XmlTemplateProviderConstants.ESCIDOC_PROPERTIES_NS, Constants.PROPERTIES_NS_URI);
    values.put(XmlTemplateProviderConstants.ESCIDOC_SREL_NS_PREFIX, Constants.STRUCTURAL_RELATIONS_NS_PREFIX);
    values.put(XmlTemplateProviderConstants.ESCIDOC_SREL_NS, Constants.STRUCTURAL_RELATIONS_NS_URI);
    values.put("grantTitle", grant.getTitle());
    values.put("grantHref", grant.getHref());
    values.put("grantId", grant.getId());
    if (grant.getUserAccountByUserId() != null) {
        values.put("grantUserTitle", grant.getUserAccountByUserId().getName());
        values.put("grantUserHref", grant.getUserAccountByUserId().getHref());
        values.put("grantUserId", grant.getUserAccountByUserId().getId());
    }
    if (grant.getUserGroupByGroupId() != null) {
        values.put("grantGroupTitle", grant.getUserGroupByGroupId().getName());
        values.put("grantGroupHref", grant.getUserGroupByGroupId().getHref());
        values.put("grantGroupId", grant.getUserGroupByGroupId().getId());
    }
    final EscidocRole escidocRole = grant.getEscidocRole();
    values.put("grantRoleTitle", escidocRole.getRoleName());
    final String roleId = escidocRole.getId();
    values.put("grantRoleHref", XmlUtility.getRoleHref(roleId));
    values.put("grantRoleId", roleId);
    values.put("grantObjectRefHref", grant.getObjectHref());
    values.put("grantObjectRefTitle", grant.getObjectTitle());
    values.put("grantObjectRefId", grant.getObjectId());
    DateTime creationDateTime = new DateTime(grant.getCreationDate());
    creationDateTime = creationDateTime.withZone(DateTimeZone.UTC);
    final String creationDate = creationDateTime.toString(Constants.TIMESTAMP_FORMAT);
    values.put("grantCreationDate", creationDate);
    values.put("grantCreatedByTitle", grant.getUserAccountByCreatorId().getName());
    values.put("grantCreatedByHref", grant.getUserAccountByCreatorId().getHref());
    values.put("grantCreatedById", grant.getUserAccountByCreatorId().getId());
    values.put("grantRemark", grant.getGrantRemark());

    final Date revocationDate = grant.getRevocationDate();
    if (revocationDate != null) {
        DateTime revokationDateTime = new DateTime(grant.getRevocationDate());
        revokationDateTime = revokationDateTime.withZone(DateTimeZone.UTC);
        final String revokationDate = revokationDateTime.toString(Constants.TIMESTAMP_FORMAT);
        values.put("grantRevocationDate", revokationDate);
        final UserAccount revokedBy = grant.getUserAccountByRevokerId();
        values.put("grantRevokedByHref", revokedBy.getHref());
        values.put("grantRevokedById", revokedBy.getId());
        values.put("grantRevokedByTitle", revokedBy.getName());
        values.put("grantRevocationRemark", grant.getRevocationRemark());
    }

    addEscidocBaseUrl(values);
    DateTime lmdDateTime = new DateTime(grant.getLastModificationDate());
    lmdDateTime = lmdDateTime.withZone(DateTimeZone.UTC);
    final String lmd = lmdDateTime.toString(Constants.TIMESTAMP_FORMAT);
    values.put("grantLastModificationDate", lmd);

    return getUserGroupXmlProvider().getGrantXml(values);
}

From source file:de.escidoc.core.aa.business.renderer.VelocityXmlUserGroupRenderer.java

License:Open Source License

/**
 * See Interface for functional description.
 *
 * @see de.escidoc.core.aa.business.renderer.interfaces.UserGroupRendererInterface
 *      #renderResources(de.escidoc.core.aa.business.UserGroup)
 *//*from  w ww. j  av  a 2  s .c o  m*/
@Override
public String renderResources(final UserGroup userGroup) throws WebserverSystemException {
    final Map<String, Object> values = new HashMap<String, Object>();

    values.put("isRootResources", XmlTemplateProviderConstants.TRUE);
    addResourcesValues(userGroup, values);
    addCommonValues(values);
    DateTime lmdDateTime = new DateTime(userGroup.getLastModificationDate());
    lmdDateTime = lmdDateTime.withZone(DateTimeZone.UTC);
    final String lmd = lmdDateTime.toString(Constants.TIMESTAMP_FORMAT);
    values.put("userGroupLastModificationDate", lmd);

    return getUserGroupXmlProvider().getResourcesXml(values);
}

From source file:de.escidoc.core.common.util.xml.XmlUtility.java

License:Open Source License

/**
 * Adds a new element to the provided {@code XMLStreamWriter} object containing a date value.
 *
 * @param writer         The {@code XMLStreamWriter} object to add the element to.
 * @param elementName    The name of the new element.
 * @param elementContent The {@code Date} that shall be set as the value of the new element.
 * @param namespaceUri   The namespace URI of the new element.
 * @param createEmpty    Flag indicating if a an empty element shall be created if the provided data is
 *                       {@code null} ( {@code true} ), or if the element shall not be created (
 *                       {@code false} ).
 * @throws XMLStreamException Thrown in case of an xml stream error.
 *//*from  w  w  w.  j ava2  s  . c  om*/
public static void addElement(final XMLStreamWriter writer, final String elementName,
        final DateTime elementContent, final String namespaceUri, final boolean createEmpty)
        throws XMLStreamException {

    if (elementContent == null) {
        if (createEmpty) {
            writer.writeEmptyElement(namespaceUri, elementName);
        }
    } else {
        writer.writeStartElement(namespaceUri, elementName);
        writer.writeCharacters(elementContent.withZone(DateTimeZone.UTC).toString(Constants.TIMESTAMP_FORMAT));
        writer.writeEndElement();
    }
}

From source file:de.escidoc.core.common.util.xml.XmlUtility.java

License:Open Source License

/**
 * Adds the "last-modification-date" attribute to the provided {@code XMLStreamWriter}.<br> The value of the
 * attribute is set to the value of the provided date.<br> If no date is provided, nothing is added.
 *
 * @param writer       The {@code XMLStreamWriter} object to add the attribute to.
 * @param modifiedDate The date to set as the last modified date.
 * @throws XMLStreamException Thrown in case of an xml stream error.
 *///from   w  ww  .j a v  a 2s. c om
public static void addLastModificationDateAttribute(final XMLStreamWriter writer, final DateTime modifiedDate)
        throws XMLStreamException {

    if (modifiedDate == null) {
        return;
    }

    writer.writeAttribute("last-modification-date",
            modifiedDate.withZone(DateTimeZone.UTC).toString(Constants.TIMESTAMP_FORMAT));
}

From source file:de.escidoc.core.sm.business.renderer.VelocityXmlAggregationDefinitionRenderer.java

License:Open Source License

/**
 * Adds the values of the {@link AggregationDefinition} to the provided {@link Map}.
 *
 * @param aggregationDefinition The {@link AggregationDefinition}.
 * @param values                The {@link Map} to add the values to.
 * @throws SystemException Thrown in case of an internal error.
 *//*from   w  w  w  . j a  v  a  2  s.c o  m*/
private static void addAggregationDefinitionValues(final AggregationDefinition aggregationDefinition,
        final Map<String, Object> values) {
    DateTime createDateTime = new DateTime(aggregationDefinition.getCreationDate());
    createDateTime = createDateTime.withZone(DateTimeZone.UTC);
    final String create = createDateTime.toString(Constants.TIMESTAMP_FORMAT);
    values.put("aggregationDefinitionCreationDate", create);
    values.put("aggregationDefinitionCreatedById", aggregationDefinition.getCreatorId());
    values.put("aggregationDefinitionCreatedByTitle", "user " + aggregationDefinition.getCreatorId());
    values.put("aggregationDefinitionCreatedByHref",
            XmlUtility.getUserAccountHref(aggregationDefinition.getCreatorId()));
    values.put("aggregationDefinitionId", aggregationDefinition.getId());
    values.put("aggregationDefinitionName", aggregationDefinition.getName());
    values.put("aggregationDefinitionHref",
            XmlUtility.getAggregationDefinitionHref(aggregationDefinition.getId()));
    values.put("aggregationDefinitionScopeId", aggregationDefinition.getScope().getId());
    values.put("aggregationDefinitionScopeTitle", aggregationDefinition.getScope().getName());
    values.put("aggregationDefinitionScopeHref",
            XmlUtility.getScopeHref(aggregationDefinition.getScope().getId()));
    addAggregationTableValues(aggregationDefinition.getAggregationTables(), values);
    addStatisticDataSelectorValues(aggregationDefinition.getAggregationStatisticDataSelectors(), values);
}

From source file:de.escidoc.core.sm.business.renderer.VelocityXmlReportDefinitionRenderer.java

License:Open Source License

/**
 * Adds the values of the {@link ReportDefinition} to the provided {@link Map}.
 *
 * @param reportDefinition The {@link ReportDefinition}.
 * @param values           The {@link Map} to add the values to.
 * @throws SystemException Thrown in case of an internal error.
 */// w ww.j a va2 s  .  c  o m
private static void addReportDefinitionValues(final ReportDefinition reportDefinition,
        final Map<String, Object> values) {
    DateTime createDateTime = new DateTime(reportDefinition.getCreationDate());
    createDateTime = createDateTime.withZone(DateTimeZone.UTC);
    final String create = createDateTime.toString(Constants.TIMESTAMP_FORMAT);
    DateTime lmdDateTime = new DateTime(reportDefinition.getLastModificationDate());
    lmdDateTime = lmdDateTime.withZone(DateTimeZone.UTC);
    final String lmd = lmdDateTime.toString(Constants.TIMESTAMP_FORMAT);

    values.put("reportDefinitionCreationDate", create);
    values.put("reportDefinitionCreatedById", reportDefinition.getCreatorId());
    values.put("reportDefinitionCreatedByTitle", "user " + reportDefinition.getCreatorId());
    values.put("reportDefinitionCreatedByHref", XmlUtility.getUserAccountHref(reportDefinition.getCreatorId()));
    values.put("reportDefinitionLastModificationDate", lmd);
    values.put("reportDefinitionModifiedById", reportDefinition.getModifiedById());
    values.put("reportDefinitionModifiedByTitle", "user " + reportDefinition.getModifiedById());
    values.put("reportDefinitionModifiedByHref",
            XmlUtility.getUserAccountHref(reportDefinition.getModifiedById()));
    values.put("reportDefinitionId", reportDefinition.getId());
    values.put("reportDefinitionName", reportDefinition.getName());
    values.put("reportDefinitionHref", XmlUtility.getReportDefinitionHref(reportDefinition.getId()));
    values.put("reportDefinitionScopeId", reportDefinition.getScope().getId());
    values.put("reportDefinitionScopeTitle", reportDefinition.getScope().getName());
    values.put("reportDefinitionScopeHref", XmlUtility.getScopeHref(reportDefinition.getScope().getId()));
    values.put("reportDefinitionSql", reportDefinition.getSql());
    addReportDefinitionRoleValues(reportDefinition.getReportDefinitionRoles(), values);
}

From source file:de.escidoc.core.sm.business.renderer.VelocityXmlReportRenderer.java

License:Open Source License

/**
 * Adds the values of the database-query to the provided {@link Map}.
 *
 * @param dbResult The dbResult./*www.  j  a va  2s . c  om*/
 * @param values   The {@link Map} to add the values to.
 * @throws SystemException Thrown in case of an internal error.
 */
private static void addDataValues(final Collection dbResult, final Map<String, Object> values) {
    final Collection<List<HashMap<String, Object>>> recordsList = new ArrayList<List<HashMap<String, Object>>>();
    if (dbResult != null && !dbResult.isEmpty()) {
        // Iterate records from database
        for (final Object aDbResult : dbResult) {
            final List<HashMap<String, Object>> recordFieldList = new ArrayList<HashMap<String, Object>>();
            final Map map = (Map) aDbResult;
            // iterate all fields of one record
            for (final Object o : map.keySet()) {
                final String fieldname = (String) o;
                // depending on the fieldtype,
                // write stringvalue, datevalue or decimalvalue-element
                if (map.get(fieldname) != null) {
                    final HashMap<String, Object> recordFieldMap = new HashMap<String, Object>();
                    recordFieldMap.put("fieldname", fieldname);
                    final String classname = map.get(fieldname).getClass().getSimpleName();
                    if ("BigDecimal".equals(classname)) {
                        recordFieldMap.put("decimalvalue", map.get(fieldname).toString());
                    } else if ("Timestamp".equals(classname)) {
                        DateTime dateTime = new DateTime(map.get(fieldname));
                        dateTime = dateTime.withZone(DateTimeZone.UTC);
                        final String dateString = dateTime.toString(Constants.TIMESTAMP_FORMAT);
                        recordFieldMap.put("datevalue", dateString);
                    } else {
                        recordFieldMap.put("stringvalue", map.get(fieldname));
                    }

                    // Add field to record
                    recordFieldList.add(recordFieldMap);
                }
            }

            // add record to recordsVm
            if (!recordFieldList.isEmpty()) {
                recordsList.add(recordFieldList);
            }
        }
    }
    values.put("records", recordsList);
}

From source file:de.escidoc.core.sm.business.renderer.VelocityXmlScopeRenderer.java

License:Open Source License

/**
 * Adds the values of the {@link Scope} to the provided {@link Map}.
 *
 * @param scope  The {@link Scope}./*w  w w.j a v a  2s.c  om*/
 * @param values The {@link Map} to add the values to.
 * @throws SystemException Thrown in case of an internal error.
 */
private static void addScopeValues(final Scope scope, final Map<String, Object> values) {
    DateTime createDateTime = new DateTime(scope.getCreationDate());
    createDateTime = createDateTime.withZone(DateTimeZone.UTC);
    final String create = createDateTime.toString(Constants.TIMESTAMP_FORMAT);
    DateTime lmdDateTime = new DateTime(scope.getLastModificationDate());
    lmdDateTime = lmdDateTime.withZone(DateTimeZone.UTC);
    final String lmd = lmdDateTime.toString(Constants.TIMESTAMP_FORMAT);

    values.put("scopeCreationDate", create);
    values.put("scopeCreatedById", scope.getCreatorId());
    values.put("scopeCreatedByTitle", "user " + scope.getCreatorId());
    values.put("scopeCreatedByHref", XmlUtility.getUserAccountHref(scope.getCreatorId()));
    values.put("scopeLastModificationDate", lmd);
    values.put("scopeModifiedById", scope.getModifiedById());
    values.put("scopeModifiedByTitle", "user " + scope.getModifiedById());
    values.put("scopeModifiedByHref", XmlUtility.getUserAccountHref(scope.getModifiedById()));
    values.put("scopeId", scope.getId());
    values.put("scopeName", scope.getName());
    values.put("scopeHref", XmlUtility.getScopeHref(scope.getId()));
    values.put("scopeType", scope.getScopeType());
}

From source file:de.kuschku.libquassel.primitives.serializers.DateTimeSerializer.java

License:Open Source License

@NonNull
@Override/*w ww .j a v  a 2s.  c om*/
public DateTime deserialize(@NonNull final ByteBuffer buffer) throws IOException {
    final long julianDay = IntSerializer.get().deserialize(buffer);
    final int millisSinceMidnight = IntSerializer.get().deserialize(buffer);

    final short zone = ByteSerializer.get().deserialize(buffer);

    if (millisSinceMidnight == 0x73007300 && julianDay == 0x50006100 || millisSinceMidnight == -1
            || julianDay == -1)
        return new DateTime(0);

    if ((zone & 0xfffffff0) > 0) {
        throw new IllegalArgumentException(
                "Deserialization of timezones except for local and UTC is not supported: " + zone);
    }

    DateTime time = new DateTime(DateTimeUtils.fromJulianDay(julianDay));
    time = time.millisOfDay().setCopy(millisSinceMidnight);
    if (zone == 0)
        time = time.withZone(DateTimeZone.getDefault());
    else
        time = time.withZone(DateTimeZone.UTC);

    return time;
}

From source file:divconq.util.TimeUtil.java

License:Open Source License

/**
 * Format date and time in Long format/* w w w. j av  a 2s. c om*/
 * 
 * @param at datetime to format
 * @param zone which timezone to use
 * @param locale which locale to use 
 * @return formatted datetime
 */
static public String fmtDateTimeLong(DateTime at, String zone, String locale) {
    if (at == null)
        return null;

    return TimeUtil.fmtDateTimeLong(at.withZone(TimeUtil.selectZone(zone)), locale);
}