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:org.hoteia.qalingo.core.service.impl.EmailServiceImpl.java
/** * @throws Exception /*from w ww .j a v a2s . co m*/ * @see org.hoteia.qalingo.core.service.EmailService#buildAndSaveCustomerForgottenPasswordMail(Localization localization, Customer customer, String velocityPath, CustomerForgottenPasswordEmailBean customerForgottenPasswordEmailBean) */ public void buildAndSaveCustomerForgottenPasswordMail(final RequestData requestData, final Customer customer, final String velocityPath, final CustomerForgottenPasswordEmailBean customerForgottenPasswordEmailBean) throws Exception { try { final Localization localization = requestData.getMarketAreaLocalization(); final Locale locale = localization.getLocale(); // SANITY CHECK checkEmailAddresses(customerForgottenPasswordEmailBean); 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("customerForgottenPasswordEmailBean", customerForgottenPasswordEmailBean); model.put(WORDING, coreMessageSource.loadWording(Email.WORDING_SCOPE_EMAIL, locale)); Map<String, String> urlParams = new HashMap<String, String>(); urlParams.put(RequestConstants.REQUEST_PARAMETER_PASSWORD_RESET_EMAIL, URLEncoder.encode(customer.getEmail(), Constants.ANSI)); urlParams.put(RequestConstants.REQUEST_PARAMETER_PASSWORD_RESET_TOKEN, customerForgottenPasswordEmailBean.getToken()); String resetPasswordUrl = urlService.generateUrl(FoUrls.RESET_PASSWORD, requestData, urlParams); model.put("activeChangePasswordUrl", urlService.buildAbsoluteUrl(requestData, resetPasswordUrl)); String canceResetPasswordUrl = urlService.generateUrl(FoUrls.CANCEL_RESET_PASSWORD, requestData, urlParams); model.put("cancelChangePasswordUrl", urlService.buildAbsoluteUrl(requestData, canceResetPasswordUrl)); model.put("customerForgottenPasswordEmailBean", customerForgottenPasswordEmailBean); String fromAddress = handleFromAddress(customerForgottenPasswordEmailBean.getFromAddress(), locale); String fromName = handleFromName(customerForgottenPasswordEmailBean.getFromName(), locale); String toEmail = customer.getEmail(); MimeMessagePreparatorImpl mimeMessagePreparator = getMimeMessagePreparator(requestData, Email.EMAIl_TYPE_FORGOTTEN_PASSWORD, model); mimeMessagePreparator.setTo(toEmail); mimeMessagePreparator.setFrom(fromAddress); mimeMessagePreparator.setFromName(fromName); mimeMessagePreparator.setReplyTo(fromAddress); Object[] parameters = { customer.getLastname(), customer.getFirstname() }; mimeMessagePreparator.setSubject( coreMessageSource.getMessage("email.forgotten_password.email_subject", parameters, locale)); mimeMessagePreparator.setHtmlContent(VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, velocityPath + "forgotten-password-html-content.vm", model)); mimeMessagePreparator.setPlainTextContent(VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, velocityPath + "forgotten-password-text-content.vm", model)); Email email = new Email(); email.setType(Email.EMAIl_TYPE_FORGOTTEN_PASSWORD); 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.hoteia.qalingo.core.service.EmailService.java
/** * @throws Exception /*ww w. ja v a2s .c o m*/ */ public Email buildAndSaveCustomerNewAccountMail(final RequestData requestData, final String velocityPath, final CustomerNewAccountConfirmationEmailBean customerNewAccountConfirmationEmailBean) throws Exception { Email email = null; try { final String contextNameValue = requestData.getContextNameValue(); final Localization localization = requestData.getMarketAreaLocalization(); final Locale locale = localization.getLocale(); // SANITY CHECK checkEmailAddresses(customerNewAccountConfirmationEmailBean); 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("customerNewAccountConfirmationEmailBean", customerNewAccountConfirmationEmailBean); 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(customerNewAccountConfirmationEmailBean.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("newCustomerValidationUrl", urlService.buildAbsoluteUrl(requestData, resetPasswordUrl)); String fromAddress = handleFromAddress(customerNewAccountConfirmationEmailBean.getFromAddress(), contextNameValue); String fromName = handleFromName(customerNewAccountConfirmationEmailBean.getFromName(), locale); String toEmail = customerNewAccountConfirmationEmailBean.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 = { customerNewAccountConfirmationEmailBean.getLastname(), customerNewAccountConfirmationEmailBean.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; }
From source file:net.sf.jasperreports.engine.fill.DefaultChartTheme.java
/** * Sets all the axis formatting options. This includes the colors and fonts to use on * the axis as well as the color to use when drawing the axis line. * * @param axis the axis to format/*from ww w . j a va 2 s .com*/ * @param labelFont the font to use for the axis label * @param labelColor the color of the axis label * @param tickLabelFont the font to use for each tick mark value label * @param tickLabelColor the color of each tick mark value label * @param tickLabelMask formatting mask for the label. If the axis is a NumberAxis then * the mask should be <code>java.text.DecimalFormat</code> mask, and * if it is a DateAxis then the mask should be a * <code>java.text.SimpleDateFormat</code> mask. * @param verticalTickLabels flag to draw tick labels at 90 degrees * @param lineColor color to use when drawing the axis line and any tick marks */ protected void configureAxis(Axis axis, JRFont labelFont, Color labelColor, JRFont tickLabelFont, Color tickLabelColor, String tickLabelMask, Boolean verticalTickLabels, Color lineColor, boolean isRangeAxis, Comparable<?> axisMinValue, Comparable<?> axisMaxValue) { axis.setLabelFont(fontUtil.getAwtFont(getFont(labelFont), getLocale())); axis.setTickLabelFont(fontUtil.getAwtFont(getFont(tickLabelFont), getLocale())); if (labelColor != null) { axis.setLabelPaint(labelColor); } if (tickLabelColor != null) { axis.setTickLabelPaint(tickLabelColor); } if (lineColor != null) { axis.setAxisLinePaint(lineColor); axis.setTickMarkPaint(lineColor); } TimeZone timeZone = chartContext.getTimeZone(); if (axis instanceof DateAxis && timeZone != null) { // used when no mask is set ((DateAxis) axis).setTimeZone(timeZone); } // FIXME use locale for formats if (tickLabelMask != null) { if (axis instanceof NumberAxis) { NumberFormat fmt = NumberFormat.getInstance(getLocale()); if (fmt instanceof DecimalFormat) { ((DecimalFormat) fmt).applyPattern(tickLabelMask); } ((NumberAxis) axis).setNumberFormatOverride(fmt); } else if (axis instanceof DateAxis) { DateFormat fmt; if (tickLabelMask.equals("SHORT") || tickLabelMask.equals("DateFormat.SHORT")) { fmt = DateFormat.getDateInstance(DateFormat.SHORT, getLocale()); } else if (tickLabelMask.equals("MEDIUM") || tickLabelMask.equals("DateFormat.MEDIUM")) { fmt = DateFormat.getDateInstance(DateFormat.MEDIUM, getLocale()); } else if (tickLabelMask.equals("LONG") || tickLabelMask.equals("DateFormat.LONG")) { fmt = DateFormat.getDateInstance(DateFormat.LONG, getLocale()); } else if (tickLabelMask.equals("FULL") || tickLabelMask.equals("DateFormat.FULL")) { fmt = DateFormat.getDateInstance(DateFormat.FULL, getLocale()); } else { fmt = new SimpleDateFormat(tickLabelMask, getLocale()); } if (timeZone != null) { fmt.setTimeZone(timeZone); } ((DateAxis) axis).setDateFormatOverride(fmt); } // ignore mask for other axis types. } if (verticalTickLabels != null && axis instanceof ValueAxis) { ((ValueAxis) axis).setVerticalTickLabels(verticalTickLabels); } setAxisBounds(axis, isRangeAxis, axisMinValue, axisMaxValue); }
From source file:fr.hoteia.qalingo.core.service.impl.EmailServiceImpl.java
/** * @see fr.hoteia.qalingo.core.service.EmailService#buildAndSaveCustomerResetPasswordConfirmationMail(Localization localization, Customer customer, String velocityPath, CustomerResetPasswordConfirmationEmailBean customerResetPasswordConfirmationEmailBean) *//*from ww w . j av a 2s. co m*/ public void buildAndSaveCustomerResetPasswordConfirmationMail(final RequestData requestData, final Customer customer, final String velocityPath, final CustomerResetPasswordConfirmationEmailBean customerResetPasswordConfirmationEmailBean) throws Exception { try { final Localization localization = requestData.getLocalization(); 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("currentDate", dateFormatter.format(currentDate)); model.put("customer", customer); model.put("customerResetPasswordConfirmationEmailBean", customerResetPasswordConfirmationEmailBean); model.put("wording", coreMessageSource.loadWording(Email.WORDING_SCOPE_EMAIL, locale)); String fromEmail = customerResetPasswordConfirmationEmailBean.getFromEmail(); MimeMessagePreparatorImpl mimeMessagePreparator = getMimeMessagePreparator(requestData, Email.EMAIl_TYPE_RESET_PASSWORD_CONFIRMATION, 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.reset_password_confirmation.email_subject", parameters, locale)); mimeMessagePreparator.setHtmlContent(VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, velocityPath + "reset-password-confirmation-html-content.vm", model)); mimeMessagePreparator.setPlainTextContent(VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, velocityPath + "reset-password-confirmation-text-content.vm", model)); Email email = new Email(); email.setType(Email.EMAIl_TYPE_RESET_PASSWORD_CONFIRMATION); 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:DDTDate.java
/** * Creates the output the user indicated in the input (outputType component) subject to the requested style (outputStyle) component * @return//from ww w. jav a2s.c o m */ private String createOutput() { String result = ""; try { // If needed, adjust the reference date by the number and type of units specified - as per the time zone if (getUnits() != 0) { //setReferenceDate(getReferenceDateAdjustedForTimeZone()); getReferenceDate().add(getDurationType(), getUnits()); } // Create date formatters to be used for all varieties - the corresponding date variables are always set for convenience purposes DateFormat shortFormatter = DateFormat.getDateInstance(DateFormat.SHORT); DateFormat mediumFormatter = DateFormat.getDateInstance(DateFormat.MEDIUM); DateFormat longFormatter = DateFormat.getDateInstance(DateFormat.LONG); DateFormat fullFormatter = DateFormat.getDateInstance(DateFormat.FULL); // Build the specific formatter specified DateFormat formatter = null; switch (getOutputStyle().toLowerCase()) { case "medium": { formatter = mediumFormatter; break; } case "long": { formatter = longFormatter; break; } case "full": { formatter = fullFormatter; break; } default: formatter = shortFormatter; } // output style switch // construct the specified result - one at a time MutableDateTime theReferenceDate = getReferenceDate(); //getReferenceDateAdjustedForTimeZone(); switch (getOutputType().toLowerCase()) { case "date": { result = formatter.format(theReferenceDate.toDate()); break; } case "time": { switch (getOutputStyle().toLowerCase()) { case "short": { result = theReferenceDate.toString("hh:mm:ss"); break; } default: result = theReferenceDate.toString("hh:mm:ss.SSS"); } break; } // separate time components case "hour": case "minute": case "second": case "hour24": { String tmp = theReferenceDate.toString("hh:mm:ss"); if (tmp.toString().contains(":")) { String[] hms = split(tmp.toString(), ":"); if (hms.length > 2) { switch (getOutputType().toLowerCase()) { case "hour": { // Hour - '12' result = hms[0]; break; } case "minute": { // Minutes - '34' result = hms[1]; break; } case "second": { // Second - '56' result = hms[2]; break; } case "hour24": { // Hour - '23' result = theReferenceDate.toString("HH"); break; } default: result = hms[0]; } // switch for individual time component } // three parts of time components } // timestamp contains separator ":" break; } // Hours, Minutes, Seconds case "year": { switch (getOutputStyle().toLowerCase()) { case "short": { result = theReferenceDate.toString("yy"); break; } default: result = theReferenceDate.toString("yyyy"); } break; } case "month": { switch (getOutputStyle().toLowerCase()) { case "short": { result = theReferenceDate.toString("M"); break; } case "medium": { // padded with 0 result = theReferenceDate.toString("MM"); break; } case "long": { // short name 'Feb' result = theReferenceDate.toString("MMM"); break; } default: // Full name 'September' result = theReferenceDate.toString("MMMM"); } break; } case "day": { switch (getOutputStyle().toLowerCase()) { case "short": { result = theReferenceDate.toString("d"); break; } case "medium": { result = theReferenceDate.toString("dd"); break; } default: result = theReferenceDate.toString("dd"); } } case "doy": { result = theReferenceDate.toString("D"); break; } case "dow": { switch (getOutputStyle().toLowerCase()) { case "short": { result = theReferenceDate.toString("E"); break; } case "medium": { DateTime dt = new DateTime(theReferenceDate.toDate()); DateTime.Property dowDTP = dt.dayOfWeek(); result = dowDTP.getAsText(); break; } default: result = theReferenceDate.toString("E"); } break; } // day of week case "zone": { result = theReferenceDate.toString("zzz"); break; } case "era": { result = theReferenceDate.toString("G"); break; } case "ampm": { result = theReferenceDate.toString("a"); break; } default: { setException("Invalid Output Unit - cannot set output"); } // Create full date variables for the short, medium, long, full styles } // output type switch } // try constructing result catch (Exception e) { setException(e); } finally { return result; } }
From source file:org.sakaiproject.portal.util.ErrorReporter.java
@SuppressWarnings("rawtypes") private String requestDisplay(HttpServletRequest request) { ResourceBundle rb = rbDefault; StringBuilder sb = new StringBuilder(); try {//from w w w . ja va 2 s.c o m sb.append(rb.getString("bugreport.request")).append("\n"); sb.append(rb.getString("bugreport.request.authtype")).append(request.getAuthType()).append("\n"); sb.append(rb.getString("bugreport.request.charencoding")).append(request.getCharacterEncoding()) .append("\n"); sb.append(rb.getString("bugreport.request.contentlength")).append(request.getContentLength()) .append("\n"); sb.append(rb.getString("bugreport.request.contenttype")).append(request.getContentType()).append("\n"); sb.append(rb.getString("bugreport.request.contextpath")).append(request.getContextPath()).append("\n"); sb.append(rb.getString("bugreport.request.localaddr")).append(request.getLocalAddr()).append("\n"); sb.append(rb.getString("bugreport.request.localname")).append(request.getLocalName()).append("\n"); sb.append(rb.getString("bugreport.request.localport")).append(request.getLocalPort()).append("\n"); sb.append(rb.getString("bugreport.request.method")).append(request.getMethod()).append("\n"); sb.append(rb.getString("bugreport.request.pathinfo")).append(request.getPathInfo()).append("\n"); sb.append(rb.getString("bugreport.request.protocol")).append(request.getProtocol()).append("\n"); sb.append(rb.getString("bugreport.request.querystring")).append(request.getQueryString()).append("\n"); sb.append(rb.getString("bugreport.request.remoteaddr")).append(request.getRemoteAddr()).append("\n"); sb.append(rb.getString("bugreport.request.remotehost")).append(request.getRemoteHost()).append("\n"); sb.append(rb.getString("bugreport.request.remoteport")).append(request.getRemotePort()).append("\n"); sb.append(rb.getString("bugreport.request.requesturl")).append(request.getRequestURL()).append("\n"); sb.append(rb.getString("bugreport.request.scheme")).append(request.getScheme()).append("\n"); sb.append(rb.getString("bugreport.request.servername")).append(request.getServerName()).append("\n"); sb.append(rb.getString("bugreport.request.headers")).append("\n"); for (Enumeration e = request.getHeaderNames(); e.hasMoreElements();) { String headerName = (String) e.nextElement(); boolean censor = (censoredHeaders.get(headerName) != null); for (Enumeration he = request.getHeaders(headerName); he.hasMoreElements();) { String headerValue = (String) he.nextElement(); sb.append(rb.getString("bugreport.request.header")).append(headerName).append(":") .append(censor ? "---censored---" : headerValue).append("\n"); } } sb.append(rb.getString("bugreport.request.parameters")).append("\n"); for (Enumeration e = request.getParameterNames(); e.hasMoreElements();) { String parameterName = (String) e.nextElement(); boolean censor = (censoredParameters.get(parameterName) != null); String[] paramvalues = request.getParameterValues(parameterName); for (int i = 0; i < paramvalues.length; i++) { sb.append(rb.getString("bugreport.request.parameter")).append(parameterName).append(":") .append(i).append(":").append(censor ? "----censored----" : paramvalues[i]) .append("\n"); } } sb.append(rb.getString("bugreport.request.attributes")).append("\n"); for (Enumeration e = request.getAttributeNames(); e.hasMoreElements();) { String attributeName = (String) e.nextElement(); Object attribute = request.getAttribute(attributeName); boolean censor = (censoredAttributes.get(attributeName) != null); sb.append(rb.getString("bugreport.request.attribute")).append(attributeName).append(":") .append(censor ? "----censored----" : attribute).append("\n"); } HttpSession session = request.getSession(false); if (session != null) { DateFormat serverLocaleDateFormat = DateFormat.getDateInstance(DateFormat.FULL, Locale.getDefault()); sb.append(rb.getString("bugreport.session")).append("\n"); sb.append(rb.getString("bugreport.session.creation")).append(session.getCreationTime()) .append("\n"); sb.append(rb.getString("bugreport.session.lastaccess")).append(session.getLastAccessedTime()) .append("\n"); sb.append(rb.getString("bugreport.session.creationdatetime")) .append(serverLocaleDateFormat.format(session.getCreationTime())).append("\n"); sb.append(rb.getString("bugreport.session.lastaccessdatetime")) .append(serverLocaleDateFormat.format(session.getLastAccessedTime())).append("\n"); sb.append(rb.getString("bugreport.session.maxinactive")).append(session.getMaxInactiveInterval()) .append("\n"); sb.append(rb.getString("bugreport.session.attributes")).append("\n"); for (Enumeration e = session.getAttributeNames(); e.hasMoreElements();) { String attributeName = (String) e.nextElement(); Object attribute = session.getAttribute(attributeName); boolean censor = (censoredAttributes.get(attributeName) != null); sb.append(rb.getString("bugreport.session.attribute")).append(attributeName).append(":") .append(censor ? "----censored----" : attribute).append("\n"); } } } catch (Exception ex) { M_log.error("Failed to generate request display", ex); sb.append("Error " + ex.getMessage()); } return sb.toString(); }
From source file:org.hoteia.qalingo.core.service.impl.EmailServiceImpl.java
/** * @see org.hoteia.qalingo.core.service.EmailService#buildAndSaveCustomerResetPasswordConfirmationMail(Localization localization, Customer customer, String velocityPath, CustomerResetPasswordConfirmationEmailBean customerResetPasswordConfirmationEmailBean) *///from w w w .j a v a 2s . c o m public void buildAndSaveCustomerResetPasswordConfirmationMail(final RequestData requestData, final Customer customer, final String velocityPath, final CustomerResetPasswordConfirmationEmailBean customerResetPasswordConfirmationEmailBean) throws Exception { try { 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(), locale); 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(velocityEngine, velocityPath + "reset-password-confirmation-html-content.vm", model)); mimeMessagePreparator.setPlainTextContent(VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, velocityPath + "reset-password-confirmation-text-content.vm", model)); Email 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; } }
From source file:org.hoteia.qalingo.core.service.EmailService.java
/** * @throws Exception /*from w ww . j a v a 2 s . co m*/ */ public Email buildAndSaveCustomerForgottenPasswordMail(final RequestData requestData, final Customer customer, final String velocityPath, final CustomerForgottenPasswordEmailBean customerForgottenPasswordEmailBean) throws Exception { Email email = null; try { final String contextNameValue = requestData.getContextNameValue(); final Localization localization = requestData.getMarketAreaLocalization(); final Locale locale = localization.getLocale(); // SANITY CHECK checkEmailAddresses(customerForgottenPasswordEmailBean); 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("customerForgottenPasswordEmailBean", customerForgottenPasswordEmailBean); model.put(WORDING, coreMessageSource.loadWording(Email.WORDING_SCOPE_EMAIL, locale)); Map<String, String> urlParams = new HashMap<String, String>(); urlParams.put(RequestConstants.REQUEST_PARAMETER_PASSWORD_RESET_EMAIL, URLEncoder.encode(customer.getEmail(), Constants.ANSI)); urlParams.put(RequestConstants.REQUEST_PARAMETER_PASSWORD_RESET_TOKEN, customerForgottenPasswordEmailBean.getToken()); String resetPasswordUrl = urlService.generateUrl(FoUrls.RESET_PASSWORD, requestData, urlParams); model.put("activeChangePasswordUrl", urlService.buildAbsoluteUrl(requestData, resetPasswordUrl)); String canceResetPasswordUrl = urlService.generateUrl(FoUrls.CANCEL_RESET_PASSWORD, requestData, urlParams); model.put("cancelChangePasswordUrl", urlService.buildAbsoluteUrl(requestData, canceResetPasswordUrl)); String fromAddress = handleFromAddress(customerForgottenPasswordEmailBean.getFromAddress(), contextNameValue); String fromName = handleFromName(customerForgottenPasswordEmailBean.getFromName(), locale); String toEmail = customer.getEmail(); MimeMessagePreparatorImpl mimeMessagePreparator = getMimeMessagePreparator(requestData, Email.EMAIl_TYPE_FORGOTTEN_PASSWORD, model); mimeMessagePreparator.setTo(toEmail); mimeMessagePreparator.setFrom(fromAddress); mimeMessagePreparator.setFromName(fromName); mimeMessagePreparator.setReplyTo(fromAddress); Object[] parameters = { customer.getLastname(), customer.getFirstname() }; mimeMessagePreparator.setSubject( coreMessageSource.getMessage("email.forgotten_password.email_subject", parameters, locale)); mimeMessagePreparator.setHtmlContent(VelocityEngineUtils.mergeTemplateIntoString(getVelocityEngine(), velocityPath + "forgotten-password-html-content.vm", model)); mimeMessagePreparator.setPlainTextContent(VelocityEngineUtils.mergeTemplateIntoString( getVelocityEngine(), velocityPath + "forgotten-password-text-content.vm", model)); email = new Email(); email.setType(Email.EMAIl_TYPE_FORGOTTEN_PASSWORD); 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:fr.hoteia.qalingo.core.service.impl.EmailServiceImpl.java
/** * @see fr.hoteia.qalingo.core.service.EmailService#buildAndSaveNewOrderConfirmationMail(Localization localization, Customer customer, String velocityPath, OrderConfirmationEmailBean orderConfirmationEmailBean) *//* w w w .java 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.getLocalization(); 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("currentDate", dateFormatter.format(currentDate)); model.put("customer", customer); model.put("orderConfirmationEmailBean", orderConfirmationEmailBean); model.put("wording", coreMessageSource.loadWording(Email.WORDING_SCOPE_EMAIL, locale)); String fromEmail = orderConfirmationEmailBean.getFromEmail(); MimeMessagePreparatorImpl mimeMessagePreparator = getMimeMessagePreparator(requestData, Email.EMAIl_TYPE_ORDER_CONFIRMATION, 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.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) { 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.impl.EmailServiceImpl.java
/** * @see org.hoteia.qalingo.core.service.EmailService#buildAndSaveNewOrderConfirmationMail(Localization localization, Customer customer, String velocityPath, OrderConfirmationEmailBean orderConfirmationEmailBean) *//*from w ww . j a v a 2 s . co m*/ 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; } }