List of usage examples for java.text DateFormat FULL
int FULL
To view the source code for java.text DateFormat FULL.
Click Source Link
From source file:fr.hoteia.qalingo.core.service.impl.EmailServiceImpl.java
/** * @see fr.hoteia.qalingo.core.service.EmailService#saveAndBuildNewsletterSubscriptionnConfirmationMail(Localization localization, Customer customer, String velocityPath, NewsletterEmailBean newsletterEmailBean) */// ww w.java2 s.com public void saveAndBuildNewsletterSubscriptionnConfirmationMail(final RequestData requestData, final String velocityPath, final NewsletterEmailBean newsletterEmailBean) throws Exception { try { final MarketArea marketArea = requestData.getMarketArea(); 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)); 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 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_subscription.email_subject", parameters, locale)); mimeMessagePreparator.setHtmlContent(VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, velocityPath + "newsletter-subscription-confirmation-html-content.vm", model)); mimeMessagePreparator.setPlainTextContent(VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, velocityPath + "newsletter-subscription-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:uk.ac.cam.caret.sakai.rwiki.component.service.impl.SiteEmailNotificationRWiki.java
private MessageContent getMessageContent(Event event) { MessageContent messageContent = new MessageContent(); // get the content & properties Reference ref = entityManager.newReference(event.getResource()); ResourceProperties props = ref.getProperties(); // get the function // String function = event.getEvent(); // use either the configured site, or if not configured, the site // (context) of the resource String siteId = (getSite() != null) ? getSite() : getSiteId(ref.getContext()); try {//from ww w . ja v a 2 s.com Site site = siteService.getSite(siteId); messageContent.title = site.getTitle(); } catch (IdUnusedException e) { messageContent.title = siteId; } // get the URL and resource name. // StringBuffer buf = new StringBuffer(); messageContent.url = ref.getUrl() + "html"; //$NON-NLS-1$ String pageName = props.getProperty(RWikiEntity.RP_NAME); String realm = props.getProperty(RWikiEntity.RP_REALM); messageContent.localName = NameHelper.localizeName(pageName, realm); String userId = props.getProperty(RWikiEntity.RP_USER); try { User u = userDirectoryService.getUser(userId); messageContent.user = u.getDisplayId(); } catch (UserNotDefinedException e) { messageContent.user = userId; } Date date = new Date(Long.parseLong(props.getProperty(RWikiEntity.RP_VERSION))); messageContent.moddate = DateFormat.getDateInstance(DateFormat.FULL, rl.getLocale()).format(date); try { RWikiEntity rwe = (RWikiEntity) rwikiObjectService.getEntity(ref); RWikiObject rwikiObject = rwe.getRWikiObject(); String pageSpace = NameHelper.localizeSpace(pageName, realm); ComponentPageLinkRenderImpl cplr = new ComponentPageLinkRenderImpl(pageSpace, true); messageContent.contentHTML = renderService.renderPage(rwikiObject, pageSpace, cplr); messageContent.content = DigestHtml.digest(messageContent.contentHTML); } catch (Exception ex) { } return messageContent; }
From source file:org.sakaiproject.assignment2.logic.impl.ScheduledNotificationImpl.java
private String htmlContent(AssignmentSubmission s) { String newline = "<br />\n"; Assignment2 a = s.getAssignment();//from w w w. j av a 2s . co m 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."); } StringBuilder content = new StringBuilder(); // format the date display DateFormat df = externalLogic.getDateFormat(null, DateFormat.FULL, assignmentBundleLogic.getLocale(), true); // site title and id content.append(assignmentBundleLogic.getString("noti.site.title") + " " + site.getTitle() + newline); content.append(assignmentBundleLogic.getString("noti.site.id") + " " + site.getId() + newline + newline); // assignment title and due date content.append(assignmentBundleLogic.getString("noti.assignment") + " " + a.getTitle() + newline); String dueDateDisplay = assignmentBundleLogic.getString("noti.assignment.no_due_date"); if (a.getDueDate() != null) { dueDateDisplay = df.format(a.getDueDate()); } content.append(assignmentBundleLogic.getString("noti.assignment.due_date") + " " + dueDateDisplay + newline + newline); // submitter name and id AssignmentSubmissionVersion curSubVers = s.getCurrentSubmissionVersion(); String submitterId = curSubVers.getCreatedBy(); User submitter = externalLogic.getUser(submitterId); String submitterDisplay = assignmentBundleLogic.getFormattedMessage("noti.submit.student_display", new String[] { submitter.getDisplayName(), submitter.getDisplayId() }); content.append( assignmentBundleLogic.getString("noti.student") + " " + submitterDisplay + newline + newline); // submission and version ids content.append(assignmentBundleLogic.getString("noti.submit.id") + " " + s.getId() + newline); content.append(assignmentBundleLogic.getString("noti.submit.version_id") + " " + s.getCurrentSubmissionVersion().getId() + newline); // submit time String submitDateDisplay = ""; if (curSubVers.getSubmittedDate() != null) { submitDateDisplay = df.format(curSubVers.getSubmittedDate()); } content.append( assignmentBundleLogic.getString("noti.submit.time") + " " + submitDateDisplay + newline + newline); // submit text String text = StringUtil.trimToNull(curSubVers.getSubmittedText()); if (text != null) { content.append(assignmentBundleLogic.getString("noti.submit.text") + newline + Validator.escapeHtmlFormattedText(text) + newline + newline); } // attachment if any Set<SubmissionAttachment> attachments = curSubVers.getSubmissionAttachSet(); if (attachments != null && attachments.size() > 0) { content.append(assignmentBundleLogic.getString("noti.submit.attachments") + newline); for (SubmissionAttachment attachment : attachments) { String ref = attachment.getAttachmentReference(); AttachmentInformation attach = contentLogic.getAttachmentInformation(ref); if (attach != null) { String resourceLengthDisplay = assignmentBundleLogic.getFormattedMessage( "noti.submit.attach_size_display", new Object[] { attach.getContentLength() }); content.append(attach.getDisplayName() + " " + resourceLengthDisplay + newline); } } } return content.toString(); }
From source file:org.hoteia.qalingo.core.service.impl.EmailServiceImpl.java
/** * @see org.hoteia.qalingo.core.service.EmailService#saveAndBuildNewsletterSubscriptionnConfirmationMail(Localization localization, Customer customer, String velocityPath, NewsletterEmailBean newsletterEmailBean) *//*from w w w . ja v a 2 s .com*/ public void saveAndBuildNewsletterSubscriptionnConfirmationMail(final RequestData requestData, final String velocityPath, final NewsletterEmailBean newsletterEmailBean) throws Exception { try { 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(), 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_subscription.email_subject", parameters, locale)); mimeMessagePreparator.setHtmlContent(VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, velocityPath + "newsletter-subscription-confirmation-html-content.vm", model)); mimeMessagePreparator.setPlainTextContent(VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, velocityPath + "newsletter-subscription-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.lunarray.model.descriptor.util.DateFormatUtil.java
/** * Resolves the time format.//from w ww .j av a 2s . c om * * @param locale * The (optional) locale. * @return The format. */ private DateFormat resolveTimeFormat(final Locale locale) { DateFormat defaultValue; if (CheckUtil.isNull(locale)) { defaultValue = DateFormat.getTimeInstance(DateFormat.FULL); } else { defaultValue = DateFormat.getTimeInstance(DateFormat.FULL, locale); } return this.resolve(DateFormatUtil.DEFAULT_TIME_KEY, defaultValue, locale); }
From source file:org.totschnig.myexpenses.dialog.TransactionDetailFragment.java
public void fillData(Transaction o) { final FragmentActivity ctx = getActivity(); mLayout.findViewById(R.id.progress).setVisibility(View.GONE); mTransaction = o;/*from ww w .java2 s . c om*/ if (mTransaction == null) { TextView error = (TextView) mLayout.findViewById(R.id.error); error.setVisibility(View.VISIBLE); error.setText(R.string.transaction_deleted); return; } boolean doShowPicture = false; if (mTransaction.getPictureUri() != null) { doShowPicture = true; if (mTransaction.getPictureUri().getScheme().equals("file")) { if (!new File(mTransaction.getPictureUri().getPath()).exists()) { Toast.makeText(getActivity(), R.string.image_deleted, Toast.LENGTH_SHORT).show(); doShowPicture = false; } } } AlertDialog dlg = (AlertDialog) getDialog(); if (dlg != null) { Button btn = dlg.getButton(AlertDialog.BUTTON_POSITIVE); if (btn != null) { if (mTransaction.crStatus != Transaction.CrStatus.VOID) { btn.setEnabled(true); } else { btn.setVisibility(View.GONE); } } btn = dlg.getButton(AlertDialog.BUTTON_NEUTRAL); if (btn != null) { btn.setVisibility(doShowPicture ? View.VISIBLE : View.GONE); } } mLayout.findViewById(R.id.Table).setVisibility(View.VISIBLE); int title; boolean type = mTransaction.getAmount().getAmountMinor() > 0 ? ExpenseEdit.INCOME : ExpenseEdit.EXPENSE; if (mTransaction instanceof SplitTransaction) { mLayout.findViewById(R.id.SplitContainer).setVisibility(View.VISIBLE); //TODO: refactor duplicated code with SplitPartList title = R.string.split_transaction; View emptyView = mLayout.findViewById(R.id.empty); ListView lv = (ListView) mLayout.findViewById(R.id.list); // Create an array to specify the fields we want to display in the list String[] from = new String[] { KEY_LABEL_MAIN, KEY_AMOUNT }; // and an array of the fields we want to bind those fields to int[] to = new int[] { R.id.category, R.id.amount }; // Now create a simple cursor adapter and set it to display mAdapter = new SplitPartAdapter(ctx, R.layout.split_part_row, null, from, to, 0, mTransaction.getAmount().getCurrency()); lv.setAdapter(mAdapter); lv.setEmptyView(emptyView); LoaderManager manager = getLoaderManager(); if (manager.getLoader(SPLIT_PART_CURSOR) != null && !manager.getLoader(SPLIT_PART_CURSOR).isReset()) { manager.restartLoader(SPLIT_PART_CURSOR, null, this); } else { manager.initLoader(SPLIT_PART_CURSOR, null, this); } } else { if (mTransaction instanceof Transfer) { title = R.string.transfer; ((TextView) mLayout.findViewById(R.id.AccountLabel)).setText(R.string.transfer_from_account); ((TextView) mLayout.findViewById(R.id.CategoryLabel)).setText(R.string.transfer_to_account); } else { title = type ? R.string.income : R.string.expense; } } String amountText; String accountLabel = Account.getInstanceFromDb(mTransaction.accountId).label; if (mTransaction instanceof Transfer) { ((TextView) mLayout.findViewById(R.id.Account)).setText(type ? mTransaction.label : accountLabel); ((TextView) mLayout.findViewById(R.id.Category)).setText(type ? accountLabel : mTransaction.label); if (((Transfer) mTransaction).isSameCurrency()) { amountText = formatCurrencyAbs(mTransaction.getAmount()); } else { String self = formatCurrencyAbs(mTransaction.getAmount()); String other = formatCurrencyAbs(mTransaction.getTransferAmount()); amountText = type == ExpenseEdit.EXPENSE ? (self + " => " + other) : (other + " => " + self); } } else { ((TextView) mLayout.findViewById(R.id.Account)).setText(accountLabel); if ((mTransaction.getCatId() != null && mTransaction.getCatId() > 0)) { ((TextView) mLayout.findViewById(R.id.Category)).setText(mTransaction.label); } else { mLayout.findViewById(R.id.CategoryRow).setVisibility(View.GONE); } amountText = formatCurrencyAbs(mTransaction.getAmount()); } //noinspection SetTextI18n ((TextView) mLayout.findViewById(R.id.Date)) .setText(DateFormat.getDateInstance(DateFormat.FULL).format(mTransaction.getDate()) + " " + DateFormat.getTimeInstance(DateFormat.SHORT).format(mTransaction.getDate())); ((TextView) mLayout.findViewById(R.id.Amount)).setText(amountText); if (!mTransaction.comment.equals("")) { ((TextView) mLayout.findViewById(R.id.Comment)).setText(mTransaction.comment); } else { mLayout.findViewById(R.id.CommentRow).setVisibility(View.GONE); } if (!mTransaction.referenceNumber.equals("")) { ((TextView) mLayout.findViewById(R.id.Number)).setText(mTransaction.referenceNumber); } else { mLayout.findViewById(R.id.NumberRow).setVisibility(View.GONE); } if (!mTransaction.payee.equals("")) { ((TextView) mLayout.findViewById(R.id.Payee)).setText(mTransaction.payee); ((TextView) mLayout.findViewById(R.id.PayeeLabel)).setText(type ? R.string.payer : R.string.payee); } else { mLayout.findViewById(R.id.PayeeRow).setVisibility(View.GONE); } if (mTransaction.methodId != null) { ((TextView) mLayout.findViewById(R.id.Method)) .setText(PaymentMethod.getInstanceFromDb(mTransaction.methodId).getLabel()); } else { mLayout.findViewById(R.id.MethodRow).setVisibility(View.GONE); } if (Account.getInstanceFromDb(mTransaction.accountId).type.equals(AccountType.CASH)) { mLayout.findViewById(R.id.StatusRow).setVisibility(View.GONE); } else { TextView tv = (TextView) mLayout.findViewById(R.id.Status); tv.setBackgroundColor(mTransaction.crStatus.color); tv.setText(mTransaction.crStatus.toString()); } if (mTransaction.originTemplate == null) { mLayout.findViewById(R.id.PlannerRow).setVisibility(View.GONE); } else { ((TextView) mLayout.findViewById(R.id.Plan)) .setText(mTransaction.originTemplate.getPlan() == null ? getString(R.string.plan_event_deleted) : Plan.prettyTimeInfo(getActivity(), mTransaction.originTemplate.getPlan().rrule, mTransaction.originTemplate.getPlan().dtstart)); } dlg.setTitle(title); if (doShowPicture) { ImageView image = ((ImageView) dlg.getWindow().findViewById(android.R.id.icon)); image.setVisibility(View.VISIBLE); image.setScaleType(ImageView.ScaleType.CENTER_CROP); Picasso.with(ctx).load(mTransaction.getPictureUri()).fit().into(image); } }
From source file:hudson.scm.CVSSCM.java
private void configureDate(ArgumentListBuilder cmd, Date date) { // #192 if (isTag)/*from ww w. j ava 2s .c o m*/ return; // don't use the -D option. DateFormat df = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL, Locale.US); df.setTimeZone(TimeZone.getTimeZone("UTC")); // #209 cmd.add("-D", df.format(date)); }
From source file:DDTDate.java
/** * This function will populate the varsMap with new copies of values related to display format of date & time stamps. * Those values are based on the class (static) date variable that is currently in use. * Those values can later be used in verification of UI elements that are date-originated but may change in time (say, today's date, month, year - etc.) * The base date that is used is Locale dependent (currently, the local is assumed to be that of the workstation running the software.) * When relevant, values are provided in various styles (SHORT, MEDIUM, LONG, FULL) - not all date elements have all those versions available. * The purpose of this 'exercise' is to set up the facility for the user to verify any component of date / time stamps independently of one another or 'traditional' formatting. * * The variables maintained here are formatted with a prefix to distinguish them from other, user defined variables. * * @TODO: enable Locale modifications (at present the test machine's locale is considered and within a test session only one locale can be tested) * @param varsMap//from w w w .j a va 2s .c o m */ private void maintainDateProperties(Hashtable<String, Object> varsMap) throws Exception { String prefix = "$"; try { // Build formatting objects for each of the output styles DateFormat shortStyleFormatter = DateFormat.getDateInstance(DateFormat.SHORT); DateFormat mediumStyleFormatter = DateFormat.getDateInstance(DateFormat.MEDIUM); DateFormat longStyleFormatter = DateFormat.getDateInstance(DateFormat.LONG); DateFormat fullStyleFormatter = DateFormat.getDateInstance(DateFormat.FULL); // Use a dedicated variable to hold values of formatting results to facilitate debugging // @TODO (maybe) when done debugging - convert to inline calls to maintainDateProperty ... String formatValue; // Examples reflect time around midnight of February 6 2014 - actual values DO NOT include quotes (added here for readability) MutableDateTime theReferenceDate = getReferenceDate(); //getReferenceDateAdjustedForTimeZone(); // Default Date using DDTSettings pattern. formatValue = new SimpleDateFormat(defaultDateFormat()).format(theReferenceDate.toDate()); maintainDateProperty(prefix + "defaultDate", formatValue, varsMap); // Short Date - '2/6/14' formatValue = shortStyleFormatter.format(theReferenceDate.toDate()); maintainDateProperty(prefix + "shortDate", formatValue, varsMap); // Medium Date - 'Feb 6, 2014' formatValue = mediumStyleFormatter.format(theReferenceDate.toDate()); maintainDateProperty(prefix + "mediumDate", formatValue, varsMap); // Long Date - 'February 6, 2014' formatValue = longStyleFormatter.format(theReferenceDate.toDate()); maintainDateProperty(prefix + "longDate", formatValue, varsMap); // Full Date 'Thursday, February 6, 2014' formatValue = fullStyleFormatter.format(theReferenceDate.toDate()); maintainDateProperty(prefix + "fullDate", formatValue, varsMap); // hours : minutes : seconds : milliseconds (broken to separate components) - formatValue = theReferenceDate.toString("hh:mm:ss:SSS"); if (formatValue.toString().contains(":")) { String[] hms = split(formatValue.toString(), ":"); if (hms.length > 3) { // Hours - '12' formatValue = hms[0]; maintainDateProperty(prefix + "hours", formatValue, varsMap); // Minutes - '02' formatValue = hms[1]; maintainDateProperty(prefix + "minutes", formatValue, varsMap); // Seconds - '08' formatValue = hms[2]; maintainDateProperty(prefix + "seconds", formatValue, varsMap); // Milliseconds - '324' formatValue = hms[3]; maintainDateProperty(prefix + "milliseconds", formatValue, varsMap); // Hours in 24 hours format - '23' formatValue = theReferenceDate.toString("HH"); maintainDateProperty(prefix + "hours24", formatValue, varsMap); } else setException("Failed to format reference date to four time units!"); } else { setException("Failed to format reference date to its time units!"); } // hours : minutes : seconds (default timestamp) - '12:34:56' formatValue = theReferenceDate.toString("hh:mm:ss"); maintainDateProperty(prefix + "timeStamp", formatValue, varsMap); // Short Year - '14' formatValue = theReferenceDate.toString("yy"); maintainDateProperty(prefix + "shortYear", formatValue, varsMap); // Long Year - '2014' formatValue = theReferenceDate.toString("yyyy"); maintainDateProperty(prefix + "longYear", formatValue, varsMap); // Short Month - '2' formatValue = theReferenceDate.toString("M"); maintainDateProperty(prefix + "shortMonth", formatValue, varsMap); // Padded Month - '02' formatValue = theReferenceDate.toString("MM"); maintainDateProperty(prefix + "paddedMonth", formatValue, varsMap); // Short Month Name - 'Feb' formatValue = theReferenceDate.toString("MMM"); maintainDateProperty(prefix + "shortMonthName", formatValue, varsMap); // Long Month Name - 'February' formatValue = theReferenceDate.toString("MMMM"); maintainDateProperty(prefix + "longMonthName", formatValue, varsMap); // Week in Year - '2014' (the year in which this week falls) formatValue = String.valueOf(theReferenceDate.getWeekyear()); maintainDateProperty(prefix + "weekYear", formatValue, varsMap); // Short Day in date stamp - '6' formatValue = theReferenceDate.toString("d"); maintainDateProperty(prefix + "shortDay", formatValue, varsMap); // Padded Day in date stamp - possibly with leading 0 - '06' formatValue = theReferenceDate.toString("dd"); maintainDateProperty(prefix + "paddedDay", formatValue, varsMap); // Day of Year - '37' formatValue = theReferenceDate.toString("D"); maintainDateProperty(prefix + "yearDay", formatValue, varsMap); // Short Day Name - 'Thu' formatValue = theReferenceDate.toString("E"); maintainDateProperty(prefix + "shortDayName", formatValue, varsMap); // Long Day Name - 'Thursday' DateTime dt = new DateTime(theReferenceDate.toDate()); DateTime.Property dowDTP = dt.dayOfWeek(); formatValue = dowDTP.getAsText(); maintainDateProperty(prefix + "longDayName", formatValue, varsMap); // AM/PM - 'AM' formatValue = theReferenceDate.toString("a"); maintainDateProperty(prefix + "ampm", formatValue, varsMap); // Era - (BC/AD) formatValue = theReferenceDate.toString("G"); maintainDateProperty(prefix + "era", formatValue, varsMap); // Time Zone - 'EST' formatValue = theReferenceDate.toString("zzz"); maintainDateProperty(prefix + "zone", formatValue, varsMap); addComment( "Date variables replenished for date: " + fullStyleFormatter.format(theReferenceDate.toDate())); addComment(theReferenceDate.toString()); System.out.println(getComments()); } catch (Exception e) { setException(e); } }
From source file:org.hoteia.qalingo.core.service.EmailService.java
/** * @throws Exception /*w ww .j av a 2s. c om*/ */ public Email buildAndSaveRetailerContactMail(final RequestData requestData, final Customer customer, final String velocityPath, final RetailerContactEmailBean retailerContactEmailBean) throws Exception { Email email = null; try { final String contextNameValue = requestData.getContextNameValue(); final Localization localization = requestData.getMarketAreaLocalization(); final Locale locale = localization.getLocale(); // SANITY CHECK checkEmailAddresses(retailerContactEmailBean); 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("retailerContactEmailBean", retailerContactEmailBean); model.put(WORDING, coreMessageSource.loadWording(Email.WORDING_SCOPE_EMAIL, locale)); String fromAddress = handleFromAddress(retailerContactEmailBean.getFromAddress(), contextNameValue); String fromName = handleFromName(retailerContactEmailBean.getFromName(), locale); String toEmail = retailerContactEmailBean.getToEmail(); MimeMessagePreparatorImpl mimeMessagePreparator = getMimeMessagePreparator(requestData, Email.EMAIl_TYPE_RETAILER_CONTACT, model); mimeMessagePreparator.setTo(toEmail); mimeMessagePreparator.setFrom(fromAddress); mimeMessagePreparator.setFromName(fromName); mimeMessagePreparator.setReplyTo(fromAddress); Object[] parameters = { retailerContactEmailBean.getLastname(), retailerContactEmailBean.getFirstname() }; mimeMessagePreparator.setSubject( coreMessageSource.getMessage("email.retailer_contact.email_subject", parameters, locale)); mimeMessagePreparator.setHtmlContent(VelocityEngineUtils.mergeTemplateIntoString(getVelocityEngine(), velocityPath + "retailer-contact-html-content.vm", model)); mimeMessagePreparator.setPlainTextContent(VelocityEngineUtils.mergeTemplateIntoString( getVelocityEngine(), velocityPath + "retailer-contact-text-content.vm", model)); email = new Email(); email.setType(Email.EMAIl_TYPE_RETAILER_CONTACT); 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.agiso.tempel.Tempel.java
/** * /*w ww . java 2s . c o m*/ * * @param properties * @throws Exception */ private Map<String, Object> addRuntimeProperties(Map<String, Object> properties) throws Exception { Map<String, Object> props = new HashMap<String, Object>(); // Okrelanie lokalizacji daty/czasu uywanej do wypenienia paramtrw szablonw // zawierajcych dat/czas w formatach DateFormat.SHORT, .MEDIUM, .LONG i .FULL: Locale date_locale; if (properties.containsKey(UP_DATE_LOCALE)) { date_locale = LocaleUtils.toLocale((String) properties.get(UP_DATE_LOCALE)); Locale.setDefault(date_locale); } else { date_locale = Locale.getDefault(); } TimeZone time_zone; if (properties.containsKey(UP_TIME_ZONE)) { time_zone = TimeZone.getTimeZone((String) properties.get(UP_DATE_LOCALE)); TimeZone.setDefault(time_zone); } else { time_zone = TimeZone.getDefault(); } // Wyznaczanie daty, na podstawie ktrej zostan wypenione parametry szablonw // przechowujce dat/czas w formatach DateFormat.SHORT, .MEDIUM, .LONG i .FULL. // Odbywa si w oparciu o wartoci parametrw 'date_format' i 'date'. Parametr // 'date_format' definiuje format uywany do parsowania acucha reprezentujcego // dat okrelon parametrem 'date'. Parametr 'date_format' moe nie by okrelony. // W takiej sytuacji uyty jest format DateFormat.LONG aktywnej lokalizacji (tj. // systemowej, ktra moe by przedefiniowana przez parametr 'date_locale'), ktry // moe by przedefiniowany przez parametry 'date_format_long' i 'time_format_long': Calendar calendar = Calendar.getInstance(date_locale); if (properties.containsKey(RP_DATE)) { String date_string = (String) properties.get(RP_DATE); if (properties.containsKey(RP_DATE_FORMAT)) { String date_format = (String) properties.get(RP_DATE_FORMAT); DateFormat formatter = new SimpleDateFormat(date_format); formatter.setTimeZone(time_zone); calendar.setTime(formatter.parse(date_string)); } else if (properties.containsKey(UP_DATE_FORMAT_LONG) && properties.containsKey(UP_TIME_FORMAT_LONG)) { // TODO: Zaoenie, e format data-czas jest zoony z acucha daty i czasu rozdzelonych spacj: // 'UP_DATE_FORMAT_LONG UP_TIME_FORMAT_LONG' DateFormat formatter = new SimpleDateFormat((String) properties.get(UP_DATE_FORMAT_LONG) + " " + (String) properties.get(UP_TIME_FORMAT_LONG), date_locale); formatter.setTimeZone(time_zone); calendar.setTime(formatter.parse(date_string)); } else { DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, date_locale); formatter.setTimeZone(time_zone); calendar.setTime(formatter.parse(date_string)); } } // Jeli nie okrelono, wypenianie parametrw przechowujcych poszczeglne // skadniki daty, tj. rok, miesic i dzie: if (!properties.containsKey(TP_YEAR)) { props.put(TP_YEAR, calendar.get(Calendar.YEAR)); } if (!properties.containsKey(TP_MONTH)) { props.put(TP_MONTH, calendar.get(Calendar.MONTH)); } if (!properties.containsKey(TP_DAY)) { props.put(TP_DAY, calendar.get(Calendar.DAY_OF_MONTH)); } // Jeli nie okrelono, wypenianie parametrw przechowujcych dat i czas w // formatach SHORT, MEDIUM, LONG i FULL (na podstawie wyznaczonej lokalizacji): Date date = calendar.getTime(); if (!properties.containsKey(TP_DATE_SHORT)) { DateFormat formatter; if (properties.containsKey(UP_DATE_FORMAT_SHORT)) { formatter = new SimpleDateFormat((String) properties.get(UP_DATE_FORMAT_SHORT), date_locale); } else { formatter = DateFormat.getDateInstance(DateFormat.SHORT, date_locale); } formatter.setTimeZone(time_zone); props.put(TP_DATE_SHORT, formatter.format(date)); } if (!properties.containsKey(TP_DATE_MEDIUM)) { DateFormat formatter; if (properties.containsKey(UP_DATE_FORMAT_MEDIUM)) { formatter = new SimpleDateFormat((String) properties.get(UP_DATE_FORMAT_MEDIUM), date_locale); } else { formatter = DateFormat.getDateInstance(DateFormat.MEDIUM, date_locale); } formatter.setTimeZone(time_zone); props.put(TP_DATE_MEDIUM, formatter.format(date)); } if (!properties.containsKey(TP_DATE_LONG)) { DateFormat formatter; if (properties.containsKey(UP_DATE_FORMAT_LONG)) { formatter = new SimpleDateFormat((String) properties.get(UP_DATE_FORMAT_LONG), date_locale); } else { formatter = DateFormat.getDateInstance(DateFormat.LONG, date_locale); } formatter.setTimeZone(time_zone); props.put(TP_DATE_LONG, formatter.format(date)); } if (!properties.containsKey(TP_DATE_FULL)) { DateFormat formatter; if (properties.containsKey(UP_DATE_FORMAT_FULL)) { formatter = new SimpleDateFormat((String) properties.get(UP_DATE_FORMAT_FULL), date_locale); } else { formatter = DateFormat.getDateInstance(DateFormat.FULL, date_locale); } formatter.setTimeZone(time_zone); props.put(TP_DATE_FULL, formatter.format(date)); } if (!properties.containsKey(TP_TIME_SHORT)) { DateFormat formatter; if (properties.containsKey(UP_TIME_FORMAT_SHORT)) { formatter = new SimpleDateFormat((String) properties.get(UP_TIME_FORMAT_SHORT), date_locale); } else { formatter = DateFormat.getTimeInstance(DateFormat.SHORT, date_locale); } formatter.setTimeZone(time_zone); props.put(TP_TIME_SHORT, formatter.format(date)); } if (!properties.containsKey(TP_TIME_MEDIUM)) { DateFormat formatter; if (properties.containsKey(UP_TIME_FORMAT_MEDIUM)) { formatter = new SimpleDateFormat((String) properties.get(UP_TIME_FORMAT_MEDIUM), date_locale); } else { formatter = DateFormat.getTimeInstance(DateFormat.MEDIUM, date_locale); } formatter.setTimeZone(time_zone); props.put(TP_TIME_MEDIUM, formatter.format(date)); } if (!properties.containsKey(TP_TIME_LONG)) { DateFormat formatter; if (properties.containsKey(UP_TIME_FORMAT_LONG)) { formatter = new SimpleDateFormat((String) properties.get(UP_TIME_FORMAT_LONG), date_locale); } else { formatter = DateFormat.getTimeInstance(DateFormat.LONG, date_locale); } formatter.setTimeZone(time_zone); props.put(TP_TIME_LONG, formatter.format(date)); } if (!properties.containsKey(TP_TIME_FULL)) { DateFormat formatter; if (properties.containsKey(UP_TIME_FORMAT_FULL)) { formatter = new SimpleDateFormat((String) properties.get(UP_TIME_FORMAT_FULL), date_locale); } else { formatter = DateFormat.getTimeInstance(DateFormat.FULL, date_locale); } formatter.setTimeZone(time_zone); props.put(TP_TIME_FULL, formatter.format(date)); } return props; }