Example usage for java.text DateFormat getDateInstance

List of usage examples for java.text DateFormat getDateInstance

Introduction

In this page you can find the example usage for java.text DateFormat getDateInstance.

Prototype

public static final DateFormat getDateInstance(int style, Locale aLocale) 

Source Link

Document

Gets the date formatter with the given formatting style for the given locale.

Usage

From source file:org.glom.web.server.libglom.Document.java

private void setNodeTextChildAsValue(final Element element, final DataItem value, final GlomFieldType type) {
    String str = "";

    switch (type) {
    case TYPE_BOOLEAN: {
        str = value.getBoolean() ? "true" : "false";
        break;//from   w  ww . j  a  va  2 s  .  c  o  m
    }
    case TYPE_DATE: {
        // TODO: This is not really the format used by the Glom document:
        final DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.SHORT, Locale.ROOT);
        str = dateFormat.format(value.getDate());
        break;
    }
    case TYPE_IMAGE: {
        str = ""; // TODO
        break;
    }
    case TYPE_NUMERIC: {
        str = getStringForDecimal(value.getNumber());
        break;
    }
    case TYPE_TEXT:
        str = value.getText();
        break;
    case TYPE_TIME:
        str = ""; // TODO
        break;
    default:
        Log.error(documentID, "setNodeTextChildAsValue(): unexpected or invalid field type.");
        break;
    }

    final String escaped = str.replace(QUOTE_FOR_FILE_FORMAT, QUOTE_FOR_FILE_FORMAT + QUOTE_FOR_FILE_FORMAT);
    element.setTextContent(escaped);
}

From source file:org.hoteia.qalingo.core.service.impl.EmailServiceImpl.java

/**
 * @see org.hoteia.qalingo.core.service.EmailService#buildAndSaveNewOrderConfirmationMail(Localization localization, Customer customer, String velocityPath, OrderConfirmationEmailBean orderConfirmationEmailBean)
 *///from  w w w .j a v a  2 s . com
public void buildAndSaveNewOrderConfirmationMail(final RequestData requestData, final Customer customer,
        final String velocityPath, final OrderConfirmationEmailBean orderConfirmationEmailBean)
        throws Exception {
    try {
        final Localization localization = requestData.getMarketAreaLocalization();
        final Locale locale = localization.getLocale();

        // SANITY CHECK
        checkEmailAddresses(orderConfirmationEmailBean);

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

        DateFormat dateFormatter = DateFormat.getDateInstance(DateFormat.FULL, locale);
        java.sql.Timestamp currentDate = new java.sql.Timestamp((new java.util.Date()).getTime());
        model.put(CURRENT_DATE, dateFormatter.format(currentDate));
        model.put(CUSTOMER, customer);
        model.put("orderConfirmationEmailBean", orderConfirmationEmailBean);
        model.put(WORDING, coreMessageSource.loadWording(Email.WORDING_SCOPE_EMAIL, locale));

        String fromAddress = handleFromAddress(orderConfirmationEmailBean.getFromAddress(), locale);
        String fromName = handleFromName(orderConfirmationEmailBean.getFromName(), locale);
        String toEmail = customer.getEmail();

        MimeMessagePreparatorImpl mimeMessagePreparator = getMimeMessagePreparator(requestData,
                Email.EMAIl_TYPE_ORDER_CONFIRMATION, model);
        mimeMessagePreparator.setTo(toEmail);
        mimeMessagePreparator.setFrom(fromAddress);
        mimeMessagePreparator.setFromName(fromName);
        mimeMessagePreparator.setReplyTo(fromAddress);
        Object[] parameters = { customer.getLastname(), customer.getFirstname() };
        mimeMessagePreparator.setSubject(
                coreMessageSource.getMessage("email.order.confirmation_email_subject", parameters, locale));
        mimeMessagePreparator.setHtmlContent(VelocityEngineUtils.mergeTemplateIntoString(velocityEngine,
                velocityPath + "order-confirmation-html-content.vm", model));
        mimeMessagePreparator.setPlainTextContent(VelocityEngineUtils.mergeTemplateIntoString(velocityEngine,
                velocityPath + "order-confirmation-text-content.vm", model));

        Email email = new Email();
        email.setType(Email.EMAIl_TYPE_ORDER_CONFIRMATION);
        email.setStatus(Email.EMAIl_STATUS_PENDING);
        saveOrUpdateEmail(email, mimeMessagePreparator);

    } catch (MailException e) {
        logger.error("Error, can't save the message :", e);
        throw e;
    } catch (VelocityException e) {
        logger.error("Error, can't build the message :", e);
        throw e;
    } catch (IOException e) {
        logger.error("Error, can't serializable the message :", e);
        throw e;
    }
}

From source file:org.libreplan.web.common.Util.java

/**
 * Format specific <code>date</code> using the {@link DateFormat#DEFAULT} format and showing only date without time.
 *///from  w  ww .j av  a 2  s . co  m
public static String formatDate(Date date) {
    return date == null ? ""
            : DateFormat.getDateInstance(DateFormat.DEFAULT, Locales.getCurrent()).format(date);
}

From source file:fr.hoteia.qalingo.core.service.impl.EmailServiceImpl.java

/**
 * @see fr.hoteia.qalingo.core.service.EmailService#buildAndSaveOrderShippedConfirmationMail(Localization localization, Customer customer, String velocityPath, OrderSentConfirmationEmailBean orderSentConfirmationEmailBean)
 */// w w w.j ava 2s  . com
public void buildAndSaveOrderShippedConfirmationMail(final RequestData requestData, final Customer customer,
        final String velocityPath, final OrderSentConfirmationEmailBean orderSentConfirmationEmailBean)
        throws Exception {
    try {
        final Localization localization = requestData.getLocalization();
        final Locale locale = localization.getLocale();

        // SANITY CHECK
        checkEmailAddresses(orderSentConfirmationEmailBean);

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

        DateFormat dateFormatter = DateFormat.getDateInstance(DateFormat.FULL, locale);
        java.sql.Timestamp currentDate = new java.sql.Timestamp((new java.util.Date()).getTime());
        model.put("currentDate", dateFormatter.format(currentDate));
        model.put("customer", customer);
        model.put("orderSentConfirmationEmailBean", orderSentConfirmationEmailBean);
        model.put("wording", coreMessageSource.loadWording(Email.WORDING_SCOPE_EMAIL, locale));

        String fromEmail = orderSentConfirmationEmailBean.getFromEmail();
        MimeMessagePreparatorImpl mimeMessagePreparator = getMimeMessagePreparator(requestData,
                Email.EMAIl_TYPE_ORDER_SHIPPED, model);
        mimeMessagePreparator.setTo(customer.getEmail());
        mimeMessagePreparator.setFrom(fromEmail);
        mimeMessagePreparator.setFromName(coreMessageSource.getMessage("email.common.from_name", locale));
        mimeMessagePreparator.setReplyTo(fromEmail);
        Object[] parameters = { customer.getLastname(), customer.getFirstname() };
        mimeMessagePreparator.setSubject(
                coreMessageSource.getMessage("email.order_shipped.shipped_email_subject", parameters, locale));
        mimeMessagePreparator.setHtmlContent(VelocityEngineUtils.mergeTemplateIntoString(velocityEngine,
                velocityPath + "order-shipped-html-content.vm", model));
        mimeMessagePreparator.setPlainTextContent(VelocityEngineUtils.mergeTemplateIntoString(velocityEngine,
                velocityPath + "order-shipped-text-content.vm", model));

        Email email = new Email();
        email.setType(Email.EMAIl_TYPE_ORDER_SHIPPED);
        email.setStatus(Email.EMAIl_STATUS_PENDING);
        saveOrUpdateEmail(email, mimeMessagePreparator);

    } catch (MailException e) {
        LOG.error("Error, can't save the message :", e);
        throw e;
    } catch (VelocityException e) {
        LOG.error("Error, can't build the message :", e);
        throw e;
    } catch (IOException e) {
        LOG.error("Error, can't serializable the message :", e);
        throw e;
    }
}

From source file:org.hoteia.qalingo.core.service.EmailService.java

/**
 * @throws Exception /*from   w  w  w .  j  av a2 s.com*/
 */
public Email buildAndSaveCustomerResetPasswordConfirmationMail(final RequestData requestData,
        final Customer customer, final String velocityPath,
        final CustomerResetPasswordConfirmationEmailBean customerResetPasswordConfirmationEmailBean)
        throws Exception {
    Email email = null;
    try {
        final String contextNameValue = requestData.getContextNameValue();
        final Localization localization = requestData.getMarketAreaLocalization();
        final Locale locale = localization.getLocale();

        // SANITY CHECK
        checkEmailAddresses(customerResetPasswordConfirmationEmailBean);

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

        DateFormat dateFormatter = DateFormat.getDateInstance(DateFormat.FULL, locale);
        java.sql.Timestamp currentDate = new java.sql.Timestamp((new java.util.Date()).getTime());
        model.put(CURRENT_DATE, dateFormatter.format(currentDate));
        model.put(CUSTOMER, customer);
        model.put("customerResetPasswordConfirmationEmailBean", customerResetPasswordConfirmationEmailBean);
        model.put(WORDING, coreMessageSource.loadWording(Email.WORDING_SCOPE_EMAIL, locale));

        String loginUrl = urlService.generateUrl(FoUrls.LOGIN, requestData);
        model.put("loginUrl", urlService.buildAbsoluteUrl(requestData, loginUrl));

        String fromAddress = handleFromAddress(customerResetPasswordConfirmationEmailBean.getFromAddress(),
                contextNameValue);
        String fromName = handleFromName(customerResetPasswordConfirmationEmailBean.getFromName(), locale);
        String toEmail = customer.getEmail();

        MimeMessagePreparatorImpl mimeMessagePreparator = getMimeMessagePreparator(requestData,
                Email.EMAIl_TYPE_RESET_PASSWORD_CONFIRMATION, model);
        mimeMessagePreparator.setTo(toEmail);
        mimeMessagePreparator.setFrom(fromAddress);
        mimeMessagePreparator.setFromName(fromName);
        mimeMessagePreparator.setReplyTo(fromAddress);
        Object[] parameters = { customer.getLastname(), customer.getFirstname() };
        mimeMessagePreparator.setSubject(coreMessageSource
                .getMessage("email.reset_password_confirmation.email_subject", parameters, locale));
        mimeMessagePreparator.setHtmlContent(VelocityEngineUtils.mergeTemplateIntoString(getVelocityEngine(),
                velocityPath + "reset-password-confirmation-html-content.vm", model));
        mimeMessagePreparator.setPlainTextContent(VelocityEngineUtils.mergeTemplateIntoString(
                getVelocityEngine(), velocityPath + "reset-password-confirmation-text-content.vm", model));

        email = new Email();
        email.setType(Email.EMAIl_TYPE_RESET_PASSWORD_CONFIRMATION);
        email.setStatus(Email.EMAIl_STATUS_PENDING);
        saveOrUpdateEmail(email, mimeMessagePreparator);

    } catch (MailException e) {
        logger.error("Error, can't save the message :", e);
        throw e;
    } catch (VelocityException e) {
        logger.error("Error, can't build the message :", e);
        throw e;
    } catch (IOException e) {
        logger.error("Error, can't serializable the message :", e);
        throw e;
    }
    return email;
}

From source file:org.hoteia.qalingo.core.web.util.RequestUtil.java

public DateFormat getCommonFormatDate(final RequestData requestData, final Integer dateStyle,
        final Integer timeStyle) throws Exception {
    final Locale locale = requestData.getLocale();
    DateFormat formatter;/* ww  w .ja  va 2 s .  c o m*/
    if (timeStyle != null) {
        formatter = DateFormat.getDateTimeInstance(dateStyle, timeStyle, locale);
    } else {
        formatter = DateFormat.getDateInstance(dateStyle, locale);
    }
    return formatter;
}

From source file:com.ruesga.rview.tasks.AsyncTextDiffProcessor.java

private void processBlames(List<DiffView.AbstractModel> model) {
    if (mBlames == null) {
        return;//  w w w. j a  v  a  2  s  .  co  m
    }

    final DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT,
            AndroidHelper.getCurrentLocale(mContext));

    if (mBlames.first != null) {
        for (BlameInfo blame : mBlames.first) {
            int start = 0;
            for (RangeInfo range : blame.ranges) {
                Pair<Integer, DiffInfoModel> p = findDiffModelByLine(model, range.start, start, true);
                if (p != null) {
                    start = p.first;
                    String commit = Formatter.toShortenCommit(blame.id);
                    String date = df.format(new Date(blame.time * 1000L)); //Unix time
                    p.second.blameA = mContext.getString(R.string.blame_format, commit, date, blame.author);
                }
            }
        }
    }

    if (mBlames.second != null) {
        for (BlameInfo blame : mBlames.second) {
            int start = 0;
            for (RangeInfo range : blame.ranges) {
                Pair<Integer, DiffInfoModel> p = findDiffModelByLine(model, range.start, start, false);
                if (p != null) {
                    start = p.first;
                    String commit = Formatter.toShortenCommit(blame.id);
                    String date = df.format(new Date(blame.time * 1000L)); //Unix time
                    p.second.blameB = mContext.getString(R.string.blame_format, commit, date, blame.author);
                }
            }
        }
    }
}

From source file:org.hoteia.qalingo.core.service.impl.EmailServiceImpl.java

/**
 * @see org.hoteia.qalingo.core.service.EmailService#buildAndSaveOrderShippedConfirmationMail(Localization localization, Customer customer, String velocityPath, OrderSentConfirmationEmailBean orderSentConfirmationEmailBean)
 *//*from w w  w. j av a  2s  .c  o  m*/
public void buildAndSaveOrderShippedConfirmationMail(final RequestData requestData, final Customer customer,
        final String velocityPath, final OrderSentConfirmationEmailBean orderSentConfirmationEmailBean)
        throws Exception {
    try {
        final Localization localization = requestData.getMarketAreaLocalization();
        final Locale locale = localization.getLocale();

        // SANITY CHECK
        checkEmailAddresses(orderSentConfirmationEmailBean);

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

        DateFormat dateFormatter = DateFormat.getDateInstance(DateFormat.FULL, locale);
        java.sql.Timestamp currentDate = new java.sql.Timestamp((new java.util.Date()).getTime());
        model.put(CURRENT_DATE, dateFormatter.format(currentDate));
        model.put(CUSTOMER, customer);
        model.put("orderSentConfirmationEmailBean", orderSentConfirmationEmailBean);
        model.put(WORDING, coreMessageSource.loadWording(Email.WORDING_SCOPE_EMAIL, locale));

        String fromAddress = handleFromAddress(orderSentConfirmationEmailBean.getFromAddress(), locale);
        String fromName = handleFromName(orderSentConfirmationEmailBean.getFromName(), locale);
        String toEmail = customer.getEmail();

        MimeMessagePreparatorImpl mimeMessagePreparator = getMimeMessagePreparator(requestData,
                Email.EMAIl_TYPE_ORDER_SHIPPED, model);
        mimeMessagePreparator.setTo(toEmail);
        mimeMessagePreparator.setFrom(fromAddress);
        mimeMessagePreparator.setFromName(fromName);
        mimeMessagePreparator.setReplyTo(fromAddress);
        Object[] parameters = { customer.getLastname(), customer.getFirstname() };
        mimeMessagePreparator.setSubject(
                coreMessageSource.getMessage("email.order_shipped.shipped_email_subject", parameters, locale));
        mimeMessagePreparator.setHtmlContent(VelocityEngineUtils.mergeTemplateIntoString(velocityEngine,
                velocityPath + "order-shipped-html-content.vm", model));
        mimeMessagePreparator.setPlainTextContent(VelocityEngineUtils.mergeTemplateIntoString(velocityEngine,
                velocityPath + "order-shipped-text-content.vm", model));

        Email email = new Email();
        email.setType(Email.EMAIl_TYPE_ORDER_SHIPPED);
        email.setStatus(Email.EMAIl_STATUS_PENDING);
        saveOrUpdateEmail(email, mimeMessagePreparator);

    } catch (MailException e) {
        logger.error("Error, can't save the message :", e);
        throw e;
    } catch (VelocityException e) {
        logger.error("Error, can't build the message :", e);
        throw e;
    } catch (IOException e) {
        logger.error("Error, can't serializable the message :", e);
        throw e;
    }
}

From source file:fr.hoteia.qalingo.core.service.impl.EmailServiceImpl.java

/**
 * @see fr.hoteia.qalingo.core.service.EmailService#buildAndSaveOrderShippedConfirmationMail(Localization localization, Customer customer, String velocityPath, AbandonedShoppingCartEmailBean abandonedShoppingCartEmailBean)
 *//* w w  w .j av a2  s. co  m*/
public void buildAndSaveAbandonedShoppingCartMail(final RequestData requestData, final Customer customer,
        final String velocityPath, final AbandonedShoppingCartEmailBean abandonedShoppingCartEmailBean)
        throws Exception {
    try {
        final Localization localization = requestData.getLocalization();
        final Locale locale = localization.getLocale();

        // SANITY CHECK
        checkEmailAddresses(abandonedShoppingCartEmailBean);

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

        DateFormat dateFormatter = DateFormat.getDateInstance(DateFormat.FULL, locale);
        java.sql.Timestamp currentDate = new java.sql.Timestamp((new java.util.Date()).getTime());
        model.put("currentDate", dateFormatter.format(currentDate));
        model.put("customer", customer);
        model.put("abandonedShoppingCartEmailBean", abandonedShoppingCartEmailBean);
        model.put("wording", coreMessageSource.loadWording(Email.WORDING_SCOPE_EMAIL, locale));

        String fromEmail = abandonedShoppingCartEmailBean.getFromEmail();
        MimeMessagePreparatorImpl mimeMessagePreparator = getMimeMessagePreparator(requestData,
                Email.EMAIl_TYPE_ABANDONED_SHOPPING_CART, model);
        mimeMessagePreparator.setTo(customer.getEmail());
        mimeMessagePreparator.setFrom(fromEmail);
        mimeMessagePreparator.setFromName(coreMessageSource.getMessage("email.common.from_name", locale));
        mimeMessagePreparator.setReplyTo(fromEmail);
        Object[] parameters = { customer.getLastname(), customer.getFirstname() };
        mimeMessagePreparator.setSubject(coreMessageSource
                .getMessage("email.abandoned_shopping_cart.email_subject", parameters, locale));
        mimeMessagePreparator.setHtmlContent(VelocityEngineUtils.mergeTemplateIntoString(velocityEngine,
                velocityPath + "abandoned-shopping-cart-html-content.vm", model));
        mimeMessagePreparator.setPlainTextContent(VelocityEngineUtils.mergeTemplateIntoString(velocityEngine,
                velocityPath + "abandoned-shopping-cart-text-content.vm", model));

        Email email = new Email();
        email.setType(Email.EMAIl_TYPE_ABANDONED_SHOPPING_CART);
        email.setStatus(Email.EMAIl_STATUS_PENDING);
        saveOrUpdateEmail(email, mimeMessagePreparator);

    } catch (MailException e) {
        LOG.error("Error, can't save the message :", e);
        throw e;
    } catch (VelocityException e) {
        LOG.error("Error, can't build the message :", e);
        throw e;
    } catch (IOException e) {
        LOG.error("Error, can't serializable the message :", e);
        throw e;
    }
}

From source file:org.hoteia.qalingo.core.service.EmailService.java

/**
 * @throws Exception /*from w  w  w.  j a v a 2s  .co  m*/
 */
public Email buildAndSaveUserNewAccountMail(final RequestData requestData, final String velocityPath,
        final UserNewAccountConfirmationEmailBean userNewAccountConfirmationEmailBean) throws Exception {
    Email email = null;
    try {
        final String contextNameValue = requestData.getContextNameValue();
        final Localization localization = requestData.getMarketAreaLocalization();
        final Locale locale = localization.getLocale();

        // SANITY CHECK
        checkEmailAddresses(userNewAccountConfirmationEmailBean);

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

        DateFormat dateFormatter = DateFormat.getDateInstance(DateFormat.FULL, locale);
        java.sql.Timestamp currentDate = new java.sql.Timestamp((new java.util.Date()).getTime());
        model.put(CURRENT_DATE, dateFormatter.format(currentDate));
        model.put("userNewAccountConfirmationEmailBean", userNewAccountConfirmationEmailBean);
        model.put(WORDING, coreMessageSource.loadWording(Email.WORDING_SCOPE_EMAIL, locale));

        Map<String, String> urlParams = new HashMap<String, String>();
        urlParams.put(RequestConstants.REQUEST_PARAMETER_NEW_CUSTOMER_VALIDATION_EMAIL,
                URLEncoder.encode(userNewAccountConfirmationEmailBean.getEmail(), Constants.ANSI));
        urlParams.put(RequestConstants.REQUEST_PARAMETER_NEW_ACCOUNT_VALIDATION_TOKEN,
                UUID.randomUUID().toString());
        String resetPasswordUrl = urlService.generateUrl(FoUrls.CUSTOMER_NEW_ACCOUNT_VALIDATION, requestData,
                urlParams);
        model.put("newUserValidationUrl", urlService.buildAbsoluteUrl(requestData, resetPasswordUrl));

        String fromAddress = handleFromAddress(userNewAccountConfirmationEmailBean.getFromAddress(),
                contextNameValue);
        String fromName = handleFromName(userNewAccountConfirmationEmailBean.getFromName(), locale);
        String toEmail = userNewAccountConfirmationEmailBean.getToEmail();

        MimeMessagePreparatorImpl mimeMessagePreparator = getMimeMessagePreparator(requestData,
                Email.EMAIl_TYPE_NEW_ACCOUNT_CONFIRMATION, model);
        mimeMessagePreparator.setTo(toEmail);
        mimeMessagePreparator.setFrom(fromAddress);
        mimeMessagePreparator.setFromName(fromName);
        mimeMessagePreparator.setReplyTo(fromAddress);
        Object[] parameters = { userNewAccountConfirmationEmailBean.getLastname(),
                userNewAccountConfirmationEmailBean.getFirstname() };
        mimeMessagePreparator.setSubject(
                coreMessageSource.getMessage("email.new_account.email_subject", parameters, locale));
        mimeMessagePreparator.setHtmlContent(VelocityEngineUtils.mergeTemplateIntoString(getVelocityEngine(),
                velocityPath + "new-account-confirmation-html-content.vm", model));
        mimeMessagePreparator.setPlainTextContent(VelocityEngineUtils.mergeTemplateIntoString(
                getVelocityEngine(), velocityPath + "new-account-confirmation-text-content.vm", model));

        email = new Email();
        email.setType(Email.EMAIl_TYPE_NEW_ACCOUNT_CONFIRMATION);
        email.setStatus(Email.EMAIl_STATUS_PENDING);
        saveOrUpdateEmail(email, mimeMessagePreparator);

    } catch (MailException e) {
        logger.error("Error, can't save the message :", e);
        throw e;
    } catch (VelocityException e) {
        logger.error("Error, can't build the message :", e);
        throw e;
    } catch (IOException e) {
        logger.error("Error, can't serializable the message :", e);
        throw e;
    }
    return email;
}