Example usage for java.text DateFormat FULL

List of usage examples for java.text DateFormat FULL

Introduction

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

Prototype

int FULL

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

Click Source Link

Document

Constant for full style pattern.

Usage

From source file:org.nuxeo.ecm.platform.ui.web.component.seam.UICellExcel.java

/**
 * Converts string value as returned by widget to the target type for an accurate cell format in the XLS/CSV export.
 * <ul>/*from w w w  .j  a v  a2 s .c o  m*/
 * <li>If force type is set to "number", convert value to a double (null if empty).</li>
 * <li>If force type is set to "bool", convert value to a boolean (null if empty).</li>
 * <li>If force type is set to "date", convert value to a date using most frequent date parsers using the short,
 * medium, long and full formats and current locale, trying first with time information and after with only date
 * information. Returns null if date is empty or could not be parsed.</li>
 * </ul>
 *
 * @since 5.6
 */
protected Object convertStringToTargetType(String value, String forceType) {
    if (CellType.number.name().equals(forceType)) {
        if (StringUtils.isBlank(value)) {
            return null;
        }
        return Double.valueOf(value);
    } else if (CellType.date.name().equals(forceType)) {
        if (StringUtils.isBlank(value)) {
            return null;
        }
        Locale locale = FacesContext.getCurrentInstance().getViewRoot().getLocale();
        int[] formats = { DateFormat.SHORT, DateFormat.MEDIUM, DateFormat.LONG, DateFormat.FULL };
        for (int format : formats) {
            try {
                return DateFormat.getDateTimeInstance(format, format, locale).parse(value);
            } catch (ParseException e) {
                // ignore
            }
            try {
                return DateFormat.getDateInstance(format, locale).parse(value);
            } catch (ParseException e) {
                // ignore
            }
        }
        log.warn("Could not convert value to a date instance: " + value);
        return null;
    } else if (CellType.bool.name().equals(forceType)) {
        if (StringUtils.isBlank(value)) {
            return null;
        }
        return Boolean.valueOf(value);
    }
    return value;
}

From source file:org.webguitoolkit.ui.util.export.PDFEvent.java

public void onEndPage(PdfWriter writer, Document document) {
    TableExportOptions exportOptions = wgtTable.getExportOptions();
    try {//w w w .ja  v  a2 s.  co m
        Rectangle page = document.getPageSize();
        if (exportOptions.isShowDefaultHeader() || StringUtils.isNotEmpty(exportOptions.getHeaderImage())) {
            PdfPTable head = new PdfPTable(3);
            head.getDefaultCell().setBorder(Rectangle.NO_BORDER);
            Paragraph title = new Paragraph(wgtTable.getTitle());
            title.setAlignment(Element.ALIGN_LEFT);
            head.addCell(title);

            Paragraph empty = new Paragraph("");
            head.addCell(empty);
            if (StringUtils.isNotEmpty(exportOptions.getHeaderImage())) {
                try {
                    URL absoluteFileUrl = wgtTable.getPage().getClass()
                            .getResource("/" + exportOptions.getHeaderImage());
                    if (absoluteFileUrl != null) {
                        String path = absoluteFileUrl.getPath();
                        Image jpg = Image.getInstance(path);
                        jpg.scaleAbsoluteHeight(40);
                        jpg.scaleAbsoluteWidth(200);
                        head.addCell(jpg);
                    }
                } catch (Exception e) {
                    logger.error(e.getMessage());
                    Paragraph noImage = new Paragraph("Image not found!");
                    head.addCell(noImage);
                }
            } else {
                head.addCell(empty);
            }
            head.setTotalWidth(page.getWidth() - document.leftMargin() - document.rightMargin());
            head.writeSelectedRows(0, -1, document.leftMargin(),
                    page.getHeight() - document.topMargin() + head.getTotalHeight(), writer.getDirectContent());
        }

        if (exportOptions.isShowDefaultFooter() || StringUtils.isNotEmpty(exportOptions.getFooterText())
                || exportOptions.isShowPageNumber()) {
            PdfPTable foot = new PdfPTable(3);
            String footerText = exportOptions.getFooterText() != null ? exportOptions.getFooterText() : "";

            if (!exportOptions.isShowDefaultFooter()) {
                foot.addCell(new Paragraph(footerText));
                foot.addCell(new Paragraph(""));
            } else {
                foot.getDefaultCell().setBorder(Rectangle.NO_BORDER);
                String leftText = "";
                if (StringUtils.isNotEmpty(exportOptions.getFooterText())) {
                    leftText = exportOptions.getFooterText();
                }
                Paragraph left = new Paragraph(leftText);
                left.setAlignment(Element.ALIGN_LEFT);
                foot.addCell(left);

                DateFormat df = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.MEDIUM,
                        TextService.getLocale());
                Date today = new Date();
                String date = df.format(today);
                Paragraph center = new Paragraph(date);
                center.setAlignment(Element.ALIGN_CENTER);
                foot.addCell(center);
            }

            if (exportOptions.isShowPageNumber()) {
                Paragraph right = new Paragraph(
                        TextService.getString("pdf.page@Page:") + " " + writer.getPageNumber());
                right.setAlignment(Element.ALIGN_LEFT);
                foot.addCell(right);

                foot.setTotalWidth(page.getWidth() - document.leftMargin() - document.rightMargin());
                foot.writeSelectedRows(0, -1, document.leftMargin(), document.bottomMargin(),
                        writer.getDirectContent());
            } else {
                foot.addCell(new Paragraph(""));
            }
        }
    } catch (Exception e) {
        throw new ExceptionConverter(e);
    }
}

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

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

        // SANITY CHECK
        checkEmailAddresses(contactEmailBean);

        Map<String, Object> model = new HashMap<String, Object>();
        String fromEmail = contactEmailBean.getFromEmail();
        String toEmail = contactEmailBean.getToEmail();

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

        MimeMessagePreparatorImpl mimeMessagePreparator = getMimeMessagePreparator(requestData,
                Email.EMAIl_TYPE_CONTACT, model);
        mimeMessagePreparator.setTo(toEmail);
        mimeMessagePreparator.setFrom(fromEmail);
        mimeMessagePreparator.setFromName(coreMessageSource.getMessage("email.common.from_name", locale));
        mimeMessagePreparator.setReplyTo(fromEmail);
        Object[] parameters = { contactEmailBean.getLastname(), contactEmailBean.getFirstname() };
        mimeMessagePreparator
                .setSubject(coreMessageSource.getMessage("email.contact.email_subject", parameters, locale));
        mimeMessagePreparator.setHtmlContent(VelocityEngineUtils.mergeTemplateIntoString(velocityEngine,
                velocityPath + "contact-html-content.vm", model));
        mimeMessagePreparator.setPlainTextContent(VelocityEngineUtils.mergeTemplateIntoString(velocityEngine,
                velocityPath + "contact-text-content.vm", model));

        mimeMessagePreparator.getHtmlContent();

        Email email = new Email();
        email.setType(Email.EMAIl_TYPE_CONTACT);
        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:ru.timakden.yacer2.MainFragment.java

/**
 *  ListView ?   ./*from w  w w .  j a  v a 2s .co m*/
 */
public void populateList() {
    DaoSession daoSession = ((YacerApplication) getActivity().getApplicationContext()).getDaoSession();
    ExchangeRateDao exchangeRateDao = daoSession.getExchangeRateDao();

    //  ?  ? ?
    long date = 0;
    try {
        date = exchangeRateDao.queryBuilder().limit(1).distinct().orderDesc(ExchangeRateDao.Properties.Date)
                .unique().getDate();
    } catch (Exception e) {
        Log.e(LOG_TAG, "Error Message: " + e.getMessage(), e);
    }

    //  ?? ?
    String rawSql = ", CURRENCY C WHERE T.DATE = ? AND C._ID = T.CURRENCY_ID ORDER BY C.SORT_ORDER ASC";
    List<ExchangeRate> exchangeRates = exchangeRateDao.queryRawCreate(rawSql, date).list();

    if (exchangeRates.size() == 0) {
        Toast.makeText(getActivity(), R.string.populate_list_failed, Toast.LENGTH_SHORT).show();
    } else {
        AppCompatActivity appCompatActivity = (AppCompatActivity) getActivity();
        ActionBar supportActionBar = appCompatActivity.getSupportActionBar();
        if (supportActionBar != null) {
            //  ??   ? UTC,       UTC
            long dateInMilliseconds = TimeUnit.SECONDS.toMillis(exchangeRates.get(0).getDate());
            DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.FULL);
            dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));

            String dateString = dateFormat.format(new Date(dateInMilliseconds));
            supportActionBar.setSubtitle(dateString);
        }

        RecyclerView recyclerView = (RecyclerView) getActivity().findViewById(R.id.recycler_view);
        recyclerView.setHasFixedSize(true);

        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity());
        recyclerView.setLayoutManager(linearLayoutManager);

        ExchangeRateAdapter exchangeRateAdapter = new ExchangeRateAdapter(exchangeRates, getActivity());
        recyclerView.setAdapter(exchangeRateAdapter);
    }

    if (swipeRefreshLayout.isRefreshing()) {
        swipeRefreshLayout.setRefreshing(false);
    }
}

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

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

        // SANITY CHECK
        checkEmailAddresses(contactEmailBean);

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

        String fromAddress = handleFromAddress(contactEmailBean.getFromAddress(), locale);
        String fromName = handleFromAddress(contactEmailBean.getFromAddress(), locale);
        String toEmail = contactEmailBean.getToEmail();

        MimeMessagePreparatorImpl mimeMessagePreparator = getMimeMessagePreparator(requestData,
                Email.EMAIl_TYPE_CONTACT, model);
        mimeMessagePreparator.setTo(toEmail);
        mimeMessagePreparator.setFrom(fromAddress);
        mimeMessagePreparator.setFromName(fromName);
        mimeMessagePreparator.setReplyTo(fromAddress);
        Object[] parameters = { contactEmailBean.getLastname(), contactEmailBean.getFirstname() };
        mimeMessagePreparator
                .setSubject(coreMessageSource.getMessage("email.contact.email_subject", parameters, locale));
        mimeMessagePreparator.setHtmlContent(VelocityEngineUtils.mergeTemplateIntoString(velocityEngine,
                velocityPath + "contact-html-content.vm", model));
        mimeMessagePreparator.setPlainTextContent(VelocityEngineUtils.mergeTemplateIntoString(velocityEngine,
                velocityPath + "contact-text-content.vm", model));

        mimeMessagePreparator.getHtmlContent();

        Email email = new Email();
        email.setType(Email.EMAIl_TYPE_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;
    }
}

From source file:securify.ububble.securify.fragments.Payment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View view = inflater.inflate(R.layout.fragment_payment, container, false);
    ButterKnife.inject(this, view);
    SharedPreferences settings = getActivity().getSharedPreferences("pref", 0);
    userId = settings.getString(Constantes.USER_ID, "");

    finder = new TextFinder(getActivity());

    for (int element : botones) {
        view.findViewById(element).setOnClickListener(this);
    }//from www .  j  a  va 2 s.co  m

    bp = new BillingProcessor(getActivity(), LICENSEKEY, new BillingProcessor.IBillingHandler() {
        JSONObject json = null;

        @Override
        public void onProductPurchased(String s, TransactionDetails transactionDetails) {
            if (transactionDetails.productId.equals(finder.getText(OPC.ID_SUBSCRIPTION_ANNUAL))) {
                try {
                    Calendar calendario = Calendar.getInstance();
                    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                    json = new JSONObject(transactionDetails.purchaseInfo.responseData);
                    txtRegalaronSecurify.setText(json.getInt("purchaseTime"));
                    RequestParams params = new RequestParams();
                    params.put("transaction_id", json.getString("orderId"));
                    params.put("amount", 23.99);
                    params.put("currency", "USD");
                    calendario.setTime(new Date(json.getLong("purchaseTime")));
                    String s_date = format.format(calendario.getTime());
                    calendario.add(Calendar.MONTH, 1);
                    String e_date = format.format(calendario.getTime());
                    params.put("d_start", s_date);
                    params.put("d_end", e_date);
                    params.put("type", 2);
                    params.put("hash", new ConvertToMD5(23.99 + userId + json.getString("orderId") + "USD" + 2
                            + Constantes.AMX_SECRET + e_date + s_date));
                    params.put("user_app_billing", contentPrincipal.userEmail);
                    Client.post("users/" + userId + "/p", null, new JsonHttpResponseHandler() {
                        @Override
                        public void onSuccess(int statusCode, Header[] headers, JSONObject response) {

                        }
                    }, getActivity());
                } catch (JSONException e) {
                }
            } else if (transactionDetails.productId.equals(finder.getText(OPC.ID_SUBSCRIPTION_MENSUAL))) {
                txtRegalaronSecurify.setText(transactionDetails.purchaseInfo.responseData);
            } else if (transactionDetails.productId.equals(finder.getText(OPC.ID_SUBSCRIPTION_TRAVELER))) {
                txtRegalaronSecurify.setText(transactionDetails.purchaseInfo.responseData);
            }
        }

        @Override
        public void onPurchaseHistoryRestored() {
        }

        @Override
        public void onBillingError(int i, Throwable throwable) {
            showToast("onBillingError: " + Integer.toString(i));
        }

        @Override
        public void onBillingInitialized() {
            readyToPurchase = true;
        }
    });
    Client.get("users/" + userId + "/state", null, new JsonHttpResponseHandler() {
        @Override
        public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
            try {
                userActive = response.getBoolean("user_active");
                remainingDays = response.getInt("remaining_days");
                Client.get("users/" + userId, null, new JsonHttpResponseHandler() {
                    JSONObject json = null;
                    Calendar calendario = Calendar.getInstance();
                    DateFormat formato = DateFormat.getDateInstance(DateFormat.FULL);

                    @Override
                    public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
                        try {
                            name = response.getString("name");
                            if (remainingDays < 0) {
                                txtRegalaronSecurify.setText(
                                        String.format(finder.getText(OPC.TXT_SUSCRIPCION_CADUCADA), name));
                            } else if (remainingDays > 0) {
                                String texto = remainingDays > 1
                                        ? String.format(finder.getText(OPC.TXT_FREE_TRIALMODE_MORE), name,
                                                remainingDays + "")
                                        : String.format(finder.getText(OPC.TXT_FREE_TRIALMODE_SIMPLE), name,
                                                remainingDays + "");
                                txtRegalaronSecurify.setText(texto);
                                view.findViewById(R.id.btn_pagar_anual).setOnClickListener(null);
                            } else if (bp.isSubscribed(finder.getText(OPC.ID_SUBSCRIPTION_ANNUAL))) {
                                json = new JSONObject(bp.getSubscriptionTransactionDetails(
                                        finder.getText(OPC.ID_SUBSCRIPTION_ANNUAL)).purchaseInfo.responseData);
                                calendario.setTime(new Date(json.getLong("purchaseTime")));
                                calendario.add(Calendar.MONTH, 1);
                                if (calendario.compareTo(Calendar.getInstance()) >= 0) {
                                    txtRegalaronSecurify
                                            .setText(String.format(finder.getText(OPC.TXT_SUSCRIPCION_CADUCAR),
                                                    formato.format(calendario.getTime())));
                                }
                            } else if (bp.isSubscribed(finder.getText(OPC.ID_SUBSCRIPTION_MENSUAL))) {
                                json = new JSONObject(bp.getSubscriptionTransactionDetails(
                                        finder.getText(OPC.ID_SUBSCRIPTION_MENSUAL)).purchaseInfo.responseData);
                                txtRegalaronSecurify.setText(bp.getSubscriptionTransactionDetails(
                                        finder.getText(OPC.ID_SUBSCRIPTION_MENSUAL)).purchaseInfo.responseData);
                            } else if (bp.isSubscribed(finder.getText(OPC.ID_SUBSCRIPTION_TRAVELER))) {
                                json = new JSONObject(bp.getSubscriptionTransactionDetails(finder
                                        .getText(OPC.ID_SUBSCRIPTION_TRAVELER)).purchaseInfo.responseData);
                                txtRegalaronSecurify.setText(bp.getSubscriptionTransactionDetails(finder
                                        .getText(OPC.ID_SUBSCRIPTION_TRAVELER)).purchaseInfo.responseData);
                            }
                        } catch (JSONException e) {
                        }
                    }
                }, getActivity());
            } catch (JSONException e) {
            }
        }
    }, getActivity());

    txtRegalaronSecurify.setVisibility(View.VISIBLE);

    return view;
}

From source file:DateTimeEditor.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent evt) {
            System.exit(0);//from   w w  w.j a v a  2s.c om
        }
    });

    JPanel panel = new JPanel(new BorderLayout());
    panel.setBorder(new EmptyBorder(5, 5, 5, 5));
    frame.setContentPane(panel);
    final DateTimeEditor field = new DateTimeEditor(DateTimeEditor.DATETIME, DateFormat.FULL);
    panel.add(field, "North");

    JPanel buttonBox = new JPanel(new GridLayout(2, 2));
    JButton showDateButton = new JButton("Show Date");
    buttonBox.add(showDateButton);

    final JComboBox timeDateChoice = new JComboBox();
    timeDateChoice.addItem("Time");
    timeDateChoice.addItem("Date");
    timeDateChoice.addItem("Date/Time");
    timeDateChoice.setSelectedIndex(2);
    timeDateChoice.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            field.setTimeOrDateType(timeDateChoice.getSelectedIndex());
        }
    });
    buttonBox.add(timeDateChoice);

    JButton toggleButton = new JButton("Toggle Enable");
    buttonBox.add(toggleButton);
    showDateButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            System.out.println(field.getDate());
        }
    });
    toggleButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            field.setEnabled(!field.isEnabled());
        }
    });
    panel.add(buttonBox, "South");

    final JComboBox lengthStyleChoice = new JComboBox();
    lengthStyleChoice.addItem("Full");
    lengthStyleChoice.addItem("Long");
    lengthStyleChoice.addItem("Medium");
    lengthStyleChoice.addItem("Short");
    lengthStyleChoice.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            field.setLengthStyle(lengthStyleChoice.getSelectedIndex());
        }
    });
    buttonBox.add(lengthStyleChoice);

    frame.pack();
    Dimension dim = frame.getToolkit().getScreenSize();
    frame.setLocation(dim.width / 2 - frame.getWidth() / 2, dim.height / 2 - frame.getHeight() / 2);
    frame.show();
}

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

/**
 * @throws Exception /*from w  ww .  ja va  2  s  .c o  m*/
 */
public Email buildAndSaveAdminNotification(final RequestData requestData, final String velocityPath,
        final AdminNotificationEmailBean adminNotificationEmailBean) throws Exception {
    Email email = null;
    try {
        final String contextNameValue = requestData.getContextNameValue();
        final Localization localization = requestData.getMarketAreaLocalization();
        final Locale locale = localization.getLocale();

        // SANITY CHECK
        checkEmailAddresses(adminNotificationEmailBean);

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

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

        MimeMessagePreparatorImpl mimeMessagePreparator = getMimeMessagePreparator(requestData,
                Email.EMAIl_TYPE_ADMIN_NOTIFICATION, model);
        mimeMessagePreparator.setTo(toEmail);
        mimeMessagePreparator.setFrom(fromAddress);
        mimeMessagePreparator.setFromName(fromName);
        mimeMessagePreparator.setReplyTo(fromAddress);
        mimeMessagePreparator.setSubject(adminNotificationEmailBean.getSubject());
        mimeMessagePreparator.setHtmlContent(VelocityEngineUtils.mergeTemplateIntoString(getVelocityEngine(),
                velocityPath + "admin-notification-html-content.vm", model));
        mimeMessagePreparator.setPlainTextContent(VelocityEngineUtils.mergeTemplateIntoString(
                getVelocityEngine(), velocityPath + "admin-notification-text-content.vm", model));

        email = new Email();
        email.setType(Email.EMAIl_TYPE_ADMIN_NOTIFICATION);
        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.web4thejob.web.panel.DefaultSessionInfoPanel.java

private void prepareContent() {
    grid.getRows().getChildren().clear();

    Row row = new Row();
    row.setParent(grid.getRows());/*from  ww w. j a v  a2s  .  c  o m*/
    Label label = new Label(L10N_LABEL_USER_LOCALE.toString());
    label.setParent(row);
    label = new Label(CoreUtil.getUserLocale().toString());
    label.setParent(row);

    if (ContextUtil.getSessionContext().getSecurityContext().isAdministrator()) {
        row = new Row();
        row.setParent(grid.getRows());
        label = new Label(L10N_LABEL_SERVER_LOCALE.toString());
        label.setParent(row);
        label = new Label(Locale.getDefault().toString());
        label.setParent(row);

        row = new Row();
        row.setParent(grid.getRows());
        label = new Label(L10N_LABEL_SERVER_CHARSET.toString());
        label.setParent(row);
        label = new Label(Charset.defaultCharset().toString());
        label.setParent(row);
    }

    row = new Row();
    row.setParent(grid.getRows());
    label = new Label(L10N_LABEL_REMOTE_ADDRESS.toString());
    label.setParent(row);
    label = new Label(Executions.getCurrent().getServerName() + ":" + Executions.getCurrent().getServerPort());
    label.setParent(row);

    row = new Row();
    row.setParent(grid.getRows());
    label = new Label(L10N_LABEL_LOCAL_ADDRESS.toString());
    label.setParent(row);
    label = new Label(Executions.getCurrent().getLocalAddr() + ":" + Executions.getCurrent().getLocalPort());
    label.setParent(row);

    row = new Row();
    row.setParent(grid.getRows());
    label = new Label(L10N_LABEL_CLIENT_TYPE.toString());
    label.setParent(row);
    label = new Label(Executions.getCurrent().getUserAgent());
    label.setParent(row);

    row = new Row();
    row.setParent(grid.getRows());
    label = new Label(L10N_LABEL_DEVICE_TYPE.toString());
    label.setParent(row);
    label = new Label(Executions.getCurrent().getSession().getDeviceType());
    label.setParent(row);

    final ClientInfoEvent info = ContextUtil.getSessionContext().getAttribute(ATTRIB_CLIENT_INFO);
    if (info != null) {
        row = new Row();
        row.setParent(grid.getRows());
        label = new Label(L10N_LABEL_SCREEN_RESOLUTION.toString());
        label.setParent(row);
        label = new Label(info.getScreenWidth() + "x" + info.getScreenHeight() + " px");
        label.setParent(row);

        row = new Row();
        row.setParent(grid.getRows());
        label = new Label(L10N_LABEL_COLOR_DEPTH.toString());
        label.setParent(row);
        label = new Label(String.valueOf(info.getColorDepth()) + "-bit");
        label.setParent(row);
    }

    DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL,
            CoreUtil.getUserLocale());

    if (Executions.getCurrent().getSession().getNativeSession() instanceof HttpSession) {
        HttpSession session = (HttpSession) Executions.getCurrent().getSession().getNativeSession();

        row = new Row();
        row.setParent(grid.getRows());
        label = new Label(L10N_LABEL_SESSION_TIMEOUT.toString());
        label.setParent(row);
        label = new Label(String.valueOf(session.getMaxInactiveInterval() / 60) + "'");
        label.setParent(row);

        row = new Row();
        row.setParent(grid.getRows());
        label = new Label(L10N_LABEL_SESSION_CREATE_TIME.toString());
        label.setParent(row);
        label = new Label(formatter.format(new Date(session.getCreationTime())));
        label.setParent(row);

        row = new Row();
        row.setParent(grid.getRows());
        label = new Label(L10N_LABEL_SESSION_ACCESSED_TIME.toString());
        label.setParent(row);
        label = new Label(formatter.format(new Date(session.getLastAccessedTime())));
        label.setParent(row);
    }

}

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

/**
 * @see fr.hoteia.qalingo.core.service.EmailService#buildAndSaveRetailerContactMail(Localization localization, Customer customer, String velocityPath, RetailerContactEmailBean retailerContactEmailBean)
 *//*from   w  ww. j ava 2s  .  co m*/
public void buildAndSaveRetailerContactMail(final RequestData requestData, final Customer customer,
        final String velocityPath, final RetailerContactEmailBean retailerContactEmailBean) throws Exception {
    try {
        final Localization localization = requestData.getLocalization();
        final Locale locale = localization.getLocale();

        // SANITY CHECK
        checkEmailAddresses(retailerContactEmailBean);

        Map<String, Object> model = new HashMap<String, Object>();
        String fromEmail = retailerContactEmailBean.getFromEmail();
        String toEmail = retailerContactEmailBean.getToEmail();

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

        MimeMessagePreparatorImpl mimeMessagePreparator = getMimeMessagePreparator(requestData,
                Email.EMAIl_TYPE_RETAILER_CONTACT, model);
        mimeMessagePreparator.setTo(toEmail);
        mimeMessagePreparator.setFrom(fromEmail);
        mimeMessagePreparator.setFromName(coreMessageSource.getMessage("email.common.from_name", locale));
        mimeMessagePreparator.setReplyTo(fromEmail);
        Object[] parameters = { retailerContactEmailBean.getLastname(),
                retailerContactEmailBean.getFirstname() };
        mimeMessagePreparator.setSubject(
                coreMessageSource.getMessage("email.retailer_contact.email_subject", parameters, locale));
        mimeMessagePreparator.setHtmlContent(VelocityEngineUtils.mergeTemplateIntoString(velocityEngine,
                velocityPath + "retailer-contact-html-content.vm", model));
        mimeMessagePreparator.setPlainTextContent(VelocityEngineUtils.mergeTemplateIntoString(velocityEngine,
                velocityPath + "retailer-contact-text-content.vm", model));

        Email email = new Email();
        email.setType(Email.EMAIl_TYPE_RETAILER_CONTACT);
        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;
    }
}