Example usage for java.text DateFormat FULL

List of usage examples for java.text DateFormat FULL

Introduction

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

Prototype

int FULL

To view the source code for java.text DateFormat FULL.

Click Source Link

Document

Constant for full style pattern.

Usage

From source file:me.ryanhamshire.PopulationDensity.DataStore.java

private void loadPlayerDataFromFile(String source, String dest) {
    //load player data into memory
    File playerFile = new File(playerDataFolderPath + File.separator + source);

    BufferedReader inStream = null;
    try {//from  w w w.  ja  v  a  2  s  .  com
        PlayerData playerData = new PlayerData();
        inStream = new BufferedReader(new FileReader(playerFile.getAbsolutePath()));

        //first line is home region coordinates
        String homeRegionCoordinatesString = inStream.readLine();

        //second line is date of last disconnection
        String lastDisconnectedString = inStream.readLine();

        //third line is login priority
        String rankString = inStream.readLine();

        //convert string representation of home coordinates to a proper object
        RegionCoordinates homeRegionCoordinates = new RegionCoordinates(homeRegionCoordinatesString);
        playerData.homeRegion = homeRegionCoordinates;

        //parse the last disconnect date string
        try {
            DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL,
                    Locale.ROOT);
            Date lastDisconnect = dateFormat.parse(lastDisconnectedString);
            playerData.lastDisconnect = lastDisconnect;
        } catch (Exception e) {
            playerData.lastDisconnect = Calendar.getInstance().getTime();
        }

        //parse priority string
        if (rankString == null || rankString.isEmpty()) {
            playerData.loginPriority = 0;
        } else {
            try {
                playerData.loginPriority = Integer.parseInt(rankString);
            } catch (Exception e) {
                playerData.loginPriority = 0;
            }
        }

        //shove into memory for quick access
        this.playerNameToPlayerDataMap.put(dest, playerData);
    }

    //if the file isn't found, just don't do anything (probably a new-to-server player)
    catch (FileNotFoundException e) {
        return;
    }

    //if there's any problem with the file's content, log an error message and skip it
    catch (Exception e) {
        PopulationDensity.AddLogEntry("Unable to load data for player \"" + source + "\": " + e.getMessage());
    }

    try {
        if (inStream != null)
            inStream.close();
    } catch (IOException exception) {
    }
}

From source file:org.apache.click.servlet.MockRequest.java

/**
 * Get the given header as a date./*from   w  ww  .  ja va 2s.  c o m*/
 *
 * @param name The header name
 * @return The date, or -1 if header not found
 * @throws IllegalArgumentException If the header cannot be converted
 */
public long getDateHeader(final String name) throws IllegalArgumentException {
    String value = getHeader(name);
    if (value == null) {
        return -1;
    }

    DateFormat df = DateFormat.getDateInstance(DateFormat.FULL);
    try {
        return df.parse(value).getTime();
    } catch (ParseException e) {
        throw new IllegalArgumentException("Can't convert header to date " + name + ": " + value);
    }
}

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

/**
 * @see fr.hoteia.qalingo.core.service.EmailService#saveAndBuildNewsletterUnsubscriptionConfirmationMail(Localization localization, Customer customer, String velocityPath, NewsletterEmailBean newsletterEmailBean)
 *//*from w w  w  .  ja v  a  2s  .co m*/
public void saveAndBuildNewsletterUnsubscriptionConfirmationMail(final RequestData requestData,
        final String velocityPath, final NewsletterEmailBean newsletterEmailBean) throws Exception {
    try {
        final Localization localization = requestData.getLocalization();
        final Locale locale = localization.getLocale();

        // SANITY CHECK
        checkEmailAddresses(newsletterEmailBean);

        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("newsletterEmailBean", newsletterEmailBean);
        model.put("wording", coreMessageSource.loadWording(Email.WORDING_SCOPE_EMAIL, locale));

        Map<String, String> urlParams = new HashMap<String, String>();
        urlParams.put(RequestConstants.REQUEST_PARAMETER_NEWSLETTER_EMAIL,
                URLEncoder.encode(newsletterEmailBean.getToEmail(), Constants.ANSI));
        String subscribeUrl = urlService.generateUrl(FoUrls.NEWSLETTER_REGISTER, requestData, urlParams);
        model.put("subscribeUrl", urlService.buildAbsoluteUrl(requestData, subscribeUrl));

        String unsubscribeUrl = urlService.generateUrl(FoUrls.NEWSLETTER_UNREGISTER, requestData, urlParams);
        String fullUnsubscribeUrl = urlService.buildAbsoluteUrl(requestData, unsubscribeUrl);

        model.put("unsubscribeUrlOrEmail", fullUnsubscribeUrl);

        String fromEmail = newsletterEmailBean.getFromEmail();
        MimeMessagePreparatorImpl mimeMessagePreparator = getMimeMessagePreparator(requestData,
                Email.EMAIl_TYPE_NEWSLETTER_SUBSCRIPTION, model);
        mimeMessagePreparator.setUnsubscribeUrlOrEmail(fullUnsubscribeUrl);
        mimeMessagePreparator.setTo(newsletterEmailBean.getToEmail());
        mimeMessagePreparator.setFrom(fromEmail);
        mimeMessagePreparator.setFromName(coreMessageSource.getMessage("email.common.from_name", locale));
        mimeMessagePreparator.setReplyTo(fromEmail);
        Object[] parameters = {};
        mimeMessagePreparator.setSubject(coreMessageSource
                .getMessage("email.newsletter_unsubscription.email_subject", parameters, locale));
        mimeMessagePreparator.setHtmlContent(VelocityEngineUtils.mergeTemplateIntoString(velocityEngine,
                velocityPath + "newsletter-unsubscription-confirmation-html-content.vm", model));
        mimeMessagePreparator.setPlainTextContent(VelocityEngineUtils.mergeTemplateIntoString(velocityEngine,
                velocityPath + "newsletter-unsubscription-confirmation-text-content.vm", model));

        Email email = new Email();
        email.setType(Email.EMAIl_TYPE_NEWSLETTER_SUBSCRIPTION);
        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.apache.wicket.protocol.http.mock.MockHttpServletRequest.java

/**
 * Get the given header as a date.//w w w. ja va2s.com
 * 
 * @param name
 *            The header name
 * @return The date, or -1 if header not found
 * @throws IllegalArgumentException
 *             If the header cannot be converted
 */
@Override
public long getDateHeader(final String name) throws IllegalArgumentException {
    String value = getHeader(name);
    if (value == null) {
        return -1;
    }

    DateFormat df = DateFormat.getDateInstance(DateFormat.FULL);
    try {
        return df.parse(value).getTime();
    } catch (ParseException e) {
        throw new IllegalArgumentException("Can't convert header to date " + name + ": " + value);
    }
}

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

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

        // SANITY CHECK
        checkEmailAddresses(newsletterEmailBean);

        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("newsletterEmailBean", newsletterEmailBean);
        model.put(WORDING, coreMessageSource.loadWording(Email.WORDING_SCOPE_EMAIL, locale));

        Map<String, String> urlParams = new HashMap<String, String>();
        urlParams.put(RequestConstants.REQUEST_PARAMETER_NEWSLETTER_EMAIL,
                URLEncoder.encode(newsletterEmailBean.getToEmail(), Constants.ANSI));
        String subscribeUrl = urlService.generateUrl(FoUrls.NEWSLETTER_REGISTER, requestData, urlParams);
        model.put("subscribeUrl", urlService.buildAbsoluteUrl(requestData, subscribeUrl));

        String unsubscribeUrl = urlService.generateUrl(FoUrls.NEWSLETTER_UNREGISTER, requestData, urlParams);
        String fullUnsubscribeUrl = urlService.buildAbsoluteUrl(requestData, unsubscribeUrl);

        model.put("unsubscribeUrlOrEmail", fullUnsubscribeUrl);

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

        MimeMessagePreparatorImpl mimeMessagePreparator = getMimeMessagePreparator(requestData,
                Email.EMAIl_TYPE_NEWSLETTER_SUBSCRIPTION, model);
        //           mimeMessagePreparator.setUnsubscribeUrlOrEmail(fullUnsubscribeUrl);
        mimeMessagePreparator.setTo(toEmail);
        mimeMessagePreparator.setFrom(fromAddress);
        mimeMessagePreparator.setFromName(fromName);
        mimeMessagePreparator.setReplyTo(fromAddress);
        Object[] parameters = {};
        mimeMessagePreparator.setSubject(coreMessageSource
                .getMessage("email.newsletter_unsubscription.email_subject", parameters, locale));
        mimeMessagePreparator.setHtmlContent(VelocityEngineUtils.mergeTemplateIntoString(velocityEngine,
                velocityPath + "newsletter-unsubscription-confirmation-html-content.vm", model));
        mimeMessagePreparator.setPlainTextContent(VelocityEngineUtils.mergeTemplateIntoString(velocityEngine,
                velocityPath + "newsletter-unsubscription-confirmation-text-content.vm", model));

        Email email = new Email();
        email.setType(Email.EMAIl_TYPE_NEWSLETTER_SUBSCRIPTION);
        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.sakaiproject.assignment2.logic.impl.ScheduledNotificationImpl.java

private String htmlContent(Assignment2 a) {
    String newline = "<br />\n";

    String context = a.getContextId();

    Site site = externalLogic.getSite(context);
    if (site == null) {
        throw new IllegalArgumentException("There was a problem retrieving "
                + "the site associated with this submission. No notifications sent.");
    }//from   w  w w  .j a v a  2s  . c  o  m

    String siteTitle = site.getTitle();
    String siteId = site.getId();

    StringBuilder content = new StringBuilder();
    // site title and id
    content.append(assignmentBundleLogic.getString("noti.site.title") + " " + siteTitle + newline);
    content.append(assignmentBundleLogic.getString("noti.site.id") + " " + siteId + newline + newline);
    // assignment title and due date
    content.append(assignmentBundleLogic.getString("noti.assignment") + " " + a.getTitle() + newline);

    DateFormat df = externalLogic.getDateFormat(null, DateFormat.FULL, assignmentBundleLogic.getLocale(), true);
    String dueDateDisplay = assignmentBundleLogic.getString("noti.assignment.no_due_date");
    if (a.getDueDate() != null) {
        dueDateDisplay = df.format(a.getDueDate());
        content.append(assignmentBundleLogic.getString("noti.assignment.duedate") + " " + dueDateDisplay
                + newline + newline);
    }

    return content.toString();
}

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

/**
 * @throws Exception /* w  ww  .j  a  va 2s.  co m*/
 */
public Email buildAndSaveNewsletterSubscriptionConfirmationMail(final RequestData requestData,
        final String velocityPath, final NewsletterEmailBean newsletterEmailBean) throws Exception {
    Email email = null;
    try {
        final String contextNameValue = requestData.getContextNameValue();
        final MarketArea marketArea = requestData.getMarketArea();
        final Localization localization = requestData.getMarketAreaLocalization();
        final Locale locale = localization.getLocale();

        // SANITY CHECK
        checkEmailAddresses(newsletterEmailBean);

        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("newsletterEmailBean", newsletterEmailBean);
        model.put(WORDING, coreMessageSource.loadWording(Email.WORDING_SCOPE_EMAIL, locale));

        Map<String, String> urlParams = new HashMap<String, String>();
        urlParams.put(RequestConstants.REQUEST_PARAMETER_NEWSLETTER_EMAIL,
                URLEncoder.encode(newsletterEmailBean.getToEmail(), Constants.ANSI));
        urlParams.put(RequestConstants.REQUEST_PARAMETER_MARKET_AREA_CODE, marketArea.getCode());
        String unsubscribeUrl = urlService.generateUrl(FoUrls.NEWSLETTER_UNREGISTER, requestData, urlParams);
        String fullUnsubscribeUrl = urlService.buildAbsoluteUrl(requestData, unsubscribeUrl);

        model.put("unsubscribeUrlOrEmail", fullUnsubscribeUrl);

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

        MimeMessagePreparatorImpl mimeMessagePreparator = getMimeMessagePreparator(requestData,
                Email.EMAIl_TYPE_NEWSLETTER_SUBSCRIPTION, model);
        mimeMessagePreparator.setUnsubscribeUrlOrEmail(fullUnsubscribeUrl);
        mimeMessagePreparator.setTo(toEmail);
        mimeMessagePreparator.setFrom(fromAddress);
        mimeMessagePreparator.setFromName(fromName);
        mimeMessagePreparator.setReplyTo(fromAddress);
        Object[] parameters = {};
        mimeMessagePreparator.setSubject(coreMessageSource
                .getMessage("email.newsletter_subscription.email_subject", parameters, locale));
        mimeMessagePreparator.setHtmlContent(VelocityEngineUtils.mergeTemplateIntoString(getVelocityEngine(),
                velocityPath + "newsletter-subscription-confirmation-html-content.vm", model));
        mimeMessagePreparator
                .setPlainTextContent(VelocityEngineUtils.mergeTemplateIntoString(getVelocityEngine(),
                        velocityPath + "newsletter-subscription-confirmation-text-content.vm", model));

        email = new Email();
        email.setType(Email.EMAIl_TYPE_NEWSLETTER_SUBSCRIPTION);
        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.linagora.linshare.core.notifications.service.impl.MailBuildingServiceImpl.java

/**
 * Old and ugly code, to be removed./*from  w w w .  j  a v a2s  .  co  m*/
 */

private String formatActivationDate(Account account, UploadRequest uploadRequest) {
    Locale locale = account.getJavaExternalMailLocale();
    DateFormat formatter = DateFormat.getDateInstance(DateFormat.FULL, locale);
    return formatter.format(uploadRequest.getActivationDate().getTime());
}

From source file:desmoj.extensions.grafic.util.Plotter.java

/**
 * configure domainAxis (label, timeZone, locale, tick labels)
 * of time-series chart//  w  w w. j a va2 s  .  c  o  m
 * @param dateAxis
 */
private void configureDomainAxis(DateAxis dateAxis) {
    if (this.begin != null)
        dateAxis.setMinimumDate(this.begin);
    if (this.end != null)
        dateAxis.setMaximumDate(this.end);
    dateAxis.setTimeZone(this.timeZone);

    Date dateMin = dateAxis.getMinimumDate();
    Date dateMax = dateAxis.getMaximumDate();
    //DateFormat formatter = new SimpleDateFormat("d.MM.yyyy HH:mm:ss.SSS");;
    DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.MEDIUM, locale);
    String label = "Time: " + formatter.format(dateMin) + " .. " + formatter.format(dateMax);
    formatter = new SimpleDateFormat("z");
    label += " " + formatter.format(dateMax);
    dateAxis.setLabel(label);

    TimeInstant max = new TimeInstant(dateMax);
    TimeInstant min = new TimeInstant(dateMin);
    TimeSpan diff = TimeOperations.diff(max, min);

    if (TimeSpan.isLongerOrEqual(diff, new TimeSpan(1, TimeUnit.DAYS)))
        formatter = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, locale);
    else if (TimeSpan.isLongerOrEqual(diff, new TimeSpan(1, TimeUnit.HOURS)))
        formatter = DateFormat.getTimeInstance(DateFormat.SHORT, locale);
    else if (TimeSpan.isLongerOrEqual(diff, new TimeSpan(1, TimeUnit.MINUTES)))
        formatter = DateFormat.getTimeInstance(DateFormat.MEDIUM, locale);
    else
        formatter = new SimpleDateFormat("HH:mm:ss.SSS");
    dateAxis.setDateFormatOverride(formatter);
    dateAxis.setVerticalTickLabels(true);
}

From source file:org.linagora.linshare.core.notifications.service.impl.MailBuildingServiceImpl.java

private String formatExpirationDate(Account account, UploadRequest uploadRequest) {
    if (uploadRequest.getExpiryDate() != null) {
        Locale locale = account.getJavaExternalMailLocale();
        DateFormat formatter = DateFormat.getDateInstance(DateFormat.FULL, locale);
        return formatter.format(uploadRequest.getExpiryDate().getTime());
    }/*from w w  w .j  a va2  s .co  m*/
    return "";
}