List of usage examples for java.text DateFormat getDateInstance
public static final DateFormat getDateInstance(int style, Locale aLocale)
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, AbandonedShoppingCartEmailBean abandonedShoppingCartEmailBean) *//* ww w.j a v a 2s . com*/ public void buildAndSaveAbandonedShoppingCartMail(final RequestData requestData, final Customer customer, final String velocityPath, final AbandonedShoppingCartEmailBean abandonedShoppingCartEmailBean) throws Exception { try { final Localization localization = requestData.getMarketAreaLocalization(); 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(CURRENT_DATE, dateFormatter.format(currentDate)); model.put(CUSTOMER, customer); model.put("abandonedShoppingCartEmailBean", abandonedShoppingCartEmailBean); model.put(WORDING, coreMessageSource.loadWording(Email.WORDING_SCOPE_EMAIL, locale)); String fromAddress = handleFromAddress(abandonedShoppingCartEmailBean.getFromAddress(), locale); String fromName = handleFromName(abandonedShoppingCartEmailBean.getFromName(), locale); String toEmail = customer.getEmail(); MimeMessagePreparatorImpl mimeMessagePreparator = getMimeMessagePreparator(requestData, Email.EMAIl_TYPE_ABANDONED_SHOPPING_CART, model); mimeMessagePreparator.setTo(toEmail); mimeMessagePreparator.setFrom(fromAddress); mimeMessagePreparator.setFromName(fromName); mimeMessagePreparator.setReplyTo(fromAddress); 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) { 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:com.rogchen.common.xml.UtilDateTime.java
/** * Returns an initialized DateFormat object. * * @param dateFormat optional format string * @param tz/* w w w . j a va 2 s . com*/ * @param locale can be null if dateFormat is not null * @return DateFormat object */ public static DateFormat toDateFormat(String dateFormat, TimeZone tz, Locale locale) { DateFormat df = null; if (dateFormat == null) { df = DateFormat.getDateInstance(DateFormat.SHORT, locale); } else { df = new SimpleDateFormat(dateFormat); } df.setTimeZone(tz); return df; }
From source file:org.hoteia.qalingo.core.service.EmailService.java
/** * @throws Exception // ww w. j a va 2 s .co m */ public Email buildAndSaveUserForgottenPasswordMail(final RequestData requestData, final User user, final String velocityPath, final UserForgottenPasswordEmailBean userForgottenPasswordEmailBean) throws Exception { Email email = null; try { final String contextNameValue = requestData.getContextNameValue(); final Localization localization = requestData.getMarketAreaLocalization(); final Locale locale = localization.getLocale(); // SANITY CHECK checkEmailAddresses(userForgottenPasswordEmailBean); 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, user); model.put("userForgottenPasswordEmailBean", userForgottenPasswordEmailBean); 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(user.getEmail(), Constants.ANSI)); urlParams.put(RequestConstants.REQUEST_PARAMETER_PASSWORD_RESET_TOKEN, userForgottenPasswordEmailBean.getToken()); String resetPasswordUrl = backofficeUrlService.generateUrl(BoUrls.RESET_PASSWORD, requestData, urlParams); model.put("activeChangePasswordUrl", backofficeUrlService.buildAbsoluteUrl(requestData, resetPasswordUrl)); String canceResetPasswordUrl = backofficeUrlService.generateUrl(BoUrls.CANCEL_RESET_PASSWORD, requestData, urlParams); model.put("cancelChangePasswordUrl", backofficeUrlService.buildAbsoluteUrl(requestData, canceResetPasswordUrl)); model.put("userForgottenPasswordEmailBean", userForgottenPasswordEmailBean); String fromAddress = handleFromAddress(userForgottenPasswordEmailBean.getFromAddress(), contextNameValue); String fromName = handleFromName(userForgottenPasswordEmailBean.getFromName(), locale); String toEmail = user.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 = { user.getLastname(), user.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:ca.oson.json.Oson.java
public Oson setDateFormat(int style, Locale locale) { options.setDateFormat(DateFormat.getDateInstance(style, locale)); reset();/*from ww w . ja va 2 s . com*/ return this; }
From source file:ca.oson.json.Oson.java
public <T> Oson setDateFormat(Class<T> type, int style, Locale locale) { cMap(type).setDateFormat(DateFormat.getDateInstance(style, locale)); reset();/*from w w w .jav a 2 s .c o m*/ return this; }
From source file:com.aurel.track.prop.LoginBL.java
private static String getLocaleDatePattern(Locale locale) { DateFormat guiDateFormat = DateFormat.getDateInstance(DateFormat.SHORT, locale); // GUI calendar date format: 4 digits year String s = ((SimpleDateFormat) guiDateFormat).toPattern(); // be sure the format is short s = s.replaceAll("dd", "d"); s = s.replaceAll("MM", "M"); s = s.replaceAll("YYYY", "YY"); s = s.replaceAll("yyyy", "yy"); // replace the format to be dd.MM.yyyy s = s.replaceAll("d", "dd"); s = s.replaceAll("M", "MM"); s = s.replaceAll("YY", "YYYY"); s = s.replaceAll("yy", "yyyy");// most imoportant: 4 digits year return s;//from ww w. j av a2s . co m }
From source file:org.hoteia.qalingo.core.service.EmailService.java
/** * @throws Exception //from ww w . ja v a 2 s .co m */ public Email buildAndSaveUserResetPasswordConfirmationMail(final RequestData requestData, final User user, final String velocityPath, final UserResetPasswordConfirmationEmailBean userResetPasswordConfirmationEmailBean) throws Exception { Email email = null; try { final String contextNameValue = requestData.getContextNameValue(); final Localization localization = requestData.getMarketAreaLocalization(); final Locale locale = localization.getLocale(); // SANITY CHECK checkEmailAddresses(userResetPasswordConfirmationEmailBean); 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, user); model.put("userResetPasswordConfirmationEmailBean", userResetPasswordConfirmationEmailBean); model.put(WORDING, coreMessageSource.loadWording(Email.WORDING_SCOPE_EMAIL, locale)); String loginUrl = backofficeUrlService.generateUrl(BoUrls.LOGIN, requestData); model.put("loginUrl", backofficeUrlService.buildAbsoluteUrl(requestData, loginUrl)); String fromAddress = handleFromAddress(userResetPasswordConfirmationEmailBean.getFromAddress(), contextNameValue); String fromName = handleFromName(userResetPasswordConfirmationEmailBean.getFromName(), locale); String toEmail = user.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 = { user.getLastname(), user.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.jivesoftware.community.util.StringUtils.java
public static String getShortDateFormat(Date date, Locale locale) { if (date == null) return ""; DateFormat shortDateFormat;//from w ww . j a va 2s .c o m if (locale != null) shortDateFormat = DateFormat.getDateInstance(3, locale); else shortDateFormat = DateFormat.getDateInstance(3); return shortDateFormat.format(date); }
From source file:org.hoteia.qalingo.core.service.EmailService.java
/** * @throws Exception //from w w w . j a v a 2 s . co m */ public Email buildAndSaveNewOrderB2CConfirmationMail(final RequestData requestData, final Customer customer, final String velocityPath, final OrderConfirmationEmailBean orderConfirmationEmailBean) throws Exception { Email email = null; try { final String contextNameValue = requestData.getContextNameValue(); 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(), contextNameValue); 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.customer_new_order.confirmation_email_subject", parameters, locale)); mimeMessagePreparator.setHtmlContent(VelocityEngineUtils.mergeTemplateIntoString(getVelocityEngine(), velocityPath + "order-confirmation-html-content.vm", model)); mimeMessagePreparator.setPlainTextContent(VelocityEngineUtils.mergeTemplateIntoString( getVelocityEngine(), velocityPath + "order-confirmation-text-content.vm", model)); 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; } return email; }
From source file:it.fub.jardin.server.DbUtils.java
/** * @param fieldName/*from w ww . j av a2 s . c o m*/ * @param result * @return ritorna la Foreign Key per il campo il cui nome passato come * parametro, se esiste. Se non esiste, ritorna una stringa vuota. * @throws SQLException */ // private List<BaseModelData> getForeignKeyInfoForAResultset(String // resultsetName) // throws SQLException { // return dbProperties.getForeignKeys(resultsetName); // } public User getUser(final Credentials credentials) throws VisibleException { String username = credentials.getUsername(); String password = credentials.getPassword(); ResultSet result; Connection connection; try { connection = this.dbConnectionHandler.getConn(); } catch (HiddenException e) { JardinLogger.error(username, "Errore SQL: impossibile connettersi al db"); throw new VisibleException(e.getLocalizedMessage()); } String query = "SELECT u.id, u.name, u.surname, u.email, u.office, " + "u.telephone, u.status AS userstatus, u.lastlogintime, " + "u.logincount, g.id AS groupid, g.name AS groupname " + "FROM " + T_USER + " u JOIN " + T_GROUP + " g ON g.id = u.id_group " + "WHERE username = ? and password = PASSWORD(?) and u.status='1'"; PreparedStatement ps; try { ps = connection.prepareStatement(query); ps.setString(1, username); ps.setString(2, password); } catch (SQLException e) { throw new VisibleException("Errore nella query " + "per la verifica di username e password"); } try { JardinLogger.info(username, "LOGIN: tentativo di login utente " + credentials.getUsername()); result = ps.executeQuery(); } catch (SQLException e) { e.printStackTrace(); JardinLogger.error(username, "Errore SQL: Errore durante l'interrogazione su database"); throw new VisibleException("Errore durante l'interrogazione su database"); } int rows = 0; try { while (result.next()) { rows++; if (rows > 1) { throw new VisibleException( "Errore nel database degli utenti: " + "due account con username e password uguali"); } /* Creazione dell'utente con i dati del database */ int uid = result.getInt("id"); int gid = result.getInt("groupid"); String name = result.getString("name"); String surname = result.getString("surname"); String group = result.getString("groupname"); String email = result.getString("email"); String office = result.getString("office"); String telephone = result.getString("telephone"); int status = result.getInt("userstatus"); int login = result.getInt("logincount"); JardinLogger.info(username, "login successfull!"); // String lastlogintime = result.getString("lastlogintime"); DateFormat df = DateFormat.getDateInstance(DateFormat.FULL, Locale.getDefault()); String last = df.format(new Date()); /* Carica le preferenze dell'utente */ List<ResultsetImproved> resultsets = this.getUserResultsetImproved(uid, gid); List<Message> messages = new ArrayList<Message>(); this.updateLoginCount(uid, ++login); User user = new User(uid, gid, new Credentials(username, password), name, surname, group, email, office, telephone, status, login, last, resultsets, messages); this.user = user; return user; } } catch (Exception e) { // Log.warn("Errore SQL", e); throw new VisibleException("Errore di accesso " + "al risultato dell'interrogazione su database"); } finally { try { this.dbConnectionHandler.closeConn(connection); } catch (HiddenException e) { // TODO Auto-generated catch block e.printStackTrace(); } } throw new VisibleException("Errore di accesso: username o password errati"); }