List of usage examples for java.text DateFormat getDateInstance
public static final DateFormat getDateInstance(int style, Locale aLocale)
From source file:org.mifos.framework.util.helpers.DateUtils.java
public static String getDBtoUserFormatShortString(java.util.Date dbDate, Locale userLocale) { // the following line is for 1.1 release and will be removed when date // is localized userLocale = internalLocale;//from w w w .j ava 2 s .c o m SimpleDateFormat format = (SimpleDateFormat) DateFormat.getDateInstance(DateFormat.SHORT, userLocale); return format.format(dbDate); }
From source file:org.freeplane.features.format.FormatController.java
private static SimpleDateFormat createDateFormat(final String datePattern) { final Integer style = getDateStyle(datePattern); if (style != null) return (SimpleDateFormat) DateFormat.getDateInstance(style, FormatUtils.getFormatLocaleFromResources()); else/*from ww w. ja va 2 s .c om*/ return new SimpleDateFormat(datePattern, FormatUtils.getFormatLocaleFromResources()); }
From source file:fr.hoteia.qalingo.core.service.impl.EmailServiceImpl.java
/** * @see fr.hoteia.qalingo.core.service.EmailService#buildAndSaveCustomerNewAccountMail(Localization localization, Customer customer, String velocityPath, CustomerNewAccountConfirmationEmailBean customerNewAccountConfirmationEmailBean) *///from ww w.j av a2s. com public void buildAndSaveCustomerNewAccountMail(final RequestData requestData, final String velocityPath, final CustomerNewAccountConfirmationEmailBean customerNewAccountConfirmationEmailBean) throws Exception { try { final Localization localization = requestData.getLocalization(); 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("currentDate", dateFormatter.format(currentDate)); model.put("customerNewAccountConfirmationEmailBean", customerNewAccountConfirmationEmailBean); model.put("wording", coreMessageSource.loadWording(Email.WORDING_SCOPE_EMAIL, locale)); String fromEmail = customerNewAccountConfirmationEmailBean.getFromEmail(); MimeMessagePreparatorImpl mimeMessagePreparator = getMimeMessagePreparator(requestData, Email.EMAIl_TYPE_NEW_ACCOUNT_CONFIRMATION, model); mimeMessagePreparator.setTo(customerNewAccountConfirmationEmailBean.getToEmail()); mimeMessagePreparator.setFrom(fromEmail); mimeMessagePreparator.setFromName(coreMessageSource.getMessage("email.common.from_name", locale)); mimeMessagePreparator.setReplyTo(fromEmail); Object[] parameters = { customerNewAccountConfirmationEmailBean.getLastname(), customerNewAccountConfirmationEmailBean.getFirstname() }; mimeMessagePreparator.setSubject( coreMessageSource.getMessage("email.new_account.email_subject", parameters, locale)); mimeMessagePreparator.setHtmlContent(VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, velocityPath + "new-account-confirmation-html-content.vm", model)); mimeMessagePreparator.setPlainTextContent(VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, velocityPath + "new-account-confirmation-text-content.vm", model)); Email email = new Email(); email.setType(Email.EMAIl_TYPE_NEW_ACCOUNT_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:gov.opm.scrd.batchprocessing.jobs.BatchProcessingJob.java
/** * Do execution.//from ww w. j a v a 2 s . c om * * @param procMessage The process message. Used to build the mail message. * @return true if execution is successful; false to retry. * @throws BatchProcessingException If major error occurred. * @throes OPMException if there is any error during auditing */ private boolean doExecute(StringBuilder procMessage) throws BatchProcessingException, OPMException { // Reset reset(); Date now = new Date(SysTime.instance.now()); procMessage.append("Service Credit Batch started at "); procMessage.append(DateFormat.getTimeInstance(DateFormat.LONG, Locale.US).format(now)); procMessage.append(" on "); procMessage.append(DateFormat.getDateInstance(DateFormat.LONG, Locale.US).format(now)); procMessage.append(". Batch done at @#$%EndingTime%$#@."); procMessage.append(CRLF).append(CRLF); try { // Initialize the batchProcessUser List<User> list = entityManager.createQuery(JPQL_QUERY_USER_BY_USERNAME, User.class) .setParameter("username", currentUserName).getResultList(); if (list.isEmpty()) { throw new AuthorizationException("Batch process user [" + currentUserName + "] is not found"); } batchProcessUser = list.get(0); // Authorize securityService.authorize(currentUserName, Arrays.asList(new String[] { batchProcessUser.getRole().getName() }), "batchProcessingJob"); } catch (AuthorizationException e) { logger.error("User " + currentUserName + " is not allowed to run the batch service.", e); procMessage.append("User "); procMessage.append(currentUserName); procMessage.append(" is not allowed to run the batch service. "); if (batchProcessUser == null) { procMessage.append("He does not exist. "); } else { procMessage.append("He is in the ").append(batchProcessUser.getRole().getName()) .append(" group instead of the System role. "); } procMessage.append("This is a serious configuration error. Call the Program Manager or DBA. "); notifyByEmail(procMessage.toString(), "Service Credit User Violation", "ERROR"); savePaymentStatusPrint(procMessage.toString()); return false; } catch (OPMException e) { throw new BatchProcessingException("Database error authorizing batch user.", e); } catch (PersistenceException e) { throw new BatchProcessingException("Database error authorizing batch user.", e); } // Initialize today's audit batch initTodayAuditBatch(now); // Is now holiday boolean isNowHoliday = isNowHoliday(now); logger.info("Is today holiday : " + isNowHoliday); batchPhase = BatchPhase.FILE_IMPORT; // Import files if (!importFiles(now, isNowHoliday)) { savePaymentStatusPrint(procMessage.toString()); return false; } // Clean old files File toCleanDirectory = new File(directoryToClean); logger.info("Start cleaning old files in: " + toCleanDirectory); cleanOutOldFiles(toCleanDirectory); logger.info("End cleaning old files in: " + toCleanDirectory); if (!isNowHoliday) { batchPhase = BatchPhase.BILL_PROCESS; logger.info("Start Bill Processing."); boolean noMinorError = true; // Process bills try { entityManager.clear(); billProcessor.processBills(todayAuditBatch.getId(), procMessage, 0, 0, 0, 0, 0); } catch (BillProcessingException e) { throw new BatchProcessingException(e.getMessage(), e); } logger.info("End Bill Processing."); // BatchDailyAccountUpdate logger.info("Start daily account updating."); noMinorError = batchDailyAccountUpdate(procMessage) && noMinorError; logger.info("End daily account updating."); // Make GL files File glFileDirectory = new File(glDirectory); logger.info("Start making GL file: " + glFileDirectory); noMinorError = makeGLFile(glFileDirectory, procMessage, now) && noMinorError; logger.info("End making GL file: " + glFileDirectory); // Notify process email String subject = noMinorError ? "Service Credit Nightly Batch: Good" : "Service Credit Nightly Batch: Warning!"; savePaymentStatusPrint(procMessage.toString()); notifyByEmail(procMessage.toString(), subject, "BillProcessing"); } return true; }
From source file:org.jajuk.util.UtilString.java
/** * Gets the locale date formatter.// w w w .ja va 2 s . c om * * @return locale date FORMATTER instance */ public static DateFormat getLocaleDateFormatter() { // store the dateFormat as ThreadLocal to avoid performance impact via the costly construction if (dateFormat.get() == null) { dateFormat.set(DateFormat.getDateInstance(DateFormat.DEFAULT, Locale.getDefault())); } return dateFormat.get(); }
From source file:fr.paris.lutece.plugins.suggest.utils.SuggestUtils.java
/** * return a timestamp Object which correspond with the string specified in * parameter.//from w ww. j a v a2 s . co m * @param strDate the date who must convert * @param locale the locale * @return a timestamp Object which correspond with the string specified in * parameter. */ public static Timestamp getLastMinute(String strDate, Locale locale) { try { Date date; DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.SHORT, locale); dateFormat.setLenient(false); date = dateFormat.parse(strDate.trim()); Calendar caldate = new GregorianCalendar(); caldate.setTime(date); caldate.set(Calendar.MILLISECOND, 0); caldate.set(Calendar.SECOND, 0); caldate.set(Calendar.HOUR_OF_DAY, caldate.getActualMaximum(Calendar.HOUR_OF_DAY)); caldate.set(Calendar.MINUTE, caldate.getActualMaximum(Calendar.MINUTE)); Timestamp timeStamp = new Timestamp(caldate.getTimeInMillis()); return timeStamp; } catch (ParseException e) { return null; } }
From source file:be.fedict.eidviewer.gui.printing.IDPrintout.java
private void initI18N() { Locale.setDefault(ViewerPrefs.getLocale()); bundle = ResourceBundle.getBundle("be/fedict/eidviewer/gui/resources/IDPrintout"); dateFormat = DateFormat.getDateInstance(DateFormat.LONG, Locale.getDefault()); coatOfArms = ImageUtilities.getImage(IDPrintout.class, ICONS + bundle.getString("coatOfArms")); }
From source file:fr.paris.lutece.plugins.genericalert.service.TaskNotifyReminder.java
/** * Get message text//www.j a va 2 s. co m * @param msg the text message * @param appointment the appointment * @return the text message */ private String getMessageAppointment(String msg, Appointment appointment) { DateFormat formater = DateFormat.getDateInstance(DateFormat.FULL, Locale.FRENCH); SimpleDateFormat formatTime = new SimpleDateFormat("HH:mm"); String strLocation = appointment.getLocation() == null ? StringUtils.EMPTY : appointment.getLocation(); String strText = StringUtils.EMPTY; strText = msg.replace(MARK_FIRST_NAME, appointment.getFirstName()); strText = strText.replace(MARK_LAST_NAME, appointment.getLastName()); strText = strText.replace(MARK_DATE_APP, formater.format(appointment.getDateAppointment())); strText = strText.replace(MARK_TIME_APP, formatTime.format(appointment.getStartAppointment())); strText = strText.replace(MARK_LOCALIZATION, strLocation); strText = strText.replace(MARK_CANCEL_APP, AppointmentApp.getCancelAppointmentUrl(appointment)); return strText; }
From source file:org.hoteia.qalingo.core.service.impl.EmailServiceImpl.java
/** * @see org.hoteia.qalingo.core.service.EmailService#buildAndSaveCustomerNewAccountMail(Localization localization, Customer customer, String velocityPath, CustomerNewAccountConfirmationEmailBean customerNewAccountConfirmationEmailBean) *//*from ww w . j a v a 2 s . c o m*/ public void buildAndSaveCustomerNewAccountMail(final RequestData requestData, final String velocityPath, final CustomerNewAccountConfirmationEmailBean customerNewAccountConfirmationEmailBean) throws Exception { try { 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_CUSTOMER_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(), locale); 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(velocityEngine, velocityPath + "new-account-confirmation-html-content.vm", model)); mimeMessagePreparator.setPlainTextContent(VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, velocityPath + "new-account-confirmation-text-content.vm", model)); Email 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; } }
From source file:com.webbfontaine.valuewebb.model.util.Utils.java
public static String dateToLocaleString(Date date) { String toStringDate;/*from w ww . j ava 2 s. c o m*/ if (date == null) { toStringDate = ""; } else { DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.SHORT, LocaleSelector.instance().getLocale()); toStringDate = dateFormat.format(date); } return toStringDate; }