Search in sources :

Example 1 with Formatter

use of org.olat.core.util.Formatter in project OpenOLAT by OpenOLAT.

the class SubscriptionListItem method getHTMLContent.

private String getHTMLContent(Locale locale) {
    StringBuilder sb = new StringBuilder();
    Translator trans = Util.createPackageTranslator(ContextualSubscriptionController.class, locale);
    Formatter form = Formatter.getInstance(locale);
    String datePart = trans.translate("subscription.listitem.dateprefix", new String[] { form.formatDateAndTime(date) });
    sb.append("<li>");
    if (iconCssClass != null) {
        sb.append("<i class=\"o_icon o_icon-fw ");
        sb.append(iconCssClass);
        sb.append("\"></i>");
    }
    if (StringHelper.containsNonWhitespace(link)) {
        sb.append("<a href=\"");
        sb.append(link);
        sb.append("\">");
    }
    if (StringHelper.containsNonWhitespace(description)) {
        sb.append(new OWASPAntiSamyXSSFilter().filter(description.trim()));
    }
    if (StringHelper.containsNonWhitespace(link))
        sb.append("</a>");
    sb.append(" <span class='o_nowrap o_date'>").append(datePart.trim()).append("</span>");
    sb.append("</li>");
    return sb.toString();
}
Also used : OWASPAntiSamyXSSFilter(org.olat.core.util.filter.impl.OWASPAntiSamyXSSFilter) Translator(org.olat.core.gui.translator.Translator) Formatter(org.olat.core.util.Formatter)

Example 2 with Formatter

use of org.olat.core.util.Formatter in project OpenOLAT by OpenOLAT.

the class RichTextConfiguration method setInsertDateTimeEnabled.

/**
 * Enable / disable the date and time insert plugin
 *
 * @param insertDateTimeEnabled
 *            true: plugin enabled; false: plugin disabled
 * @param locale
 *            the locale used to format the date and time
 * @param row
 *            The row where to place the plugin buttons
 */
private void setInsertDateTimeEnabled(boolean insertDateTimeEnabled, Locale locale) {
    if (insertDateTimeEnabled) {
        // use date format defined in org.olat.core package
        Formatter formatter = Formatter.getInstance(locale);
        String dateFormat = formatter.getSimpleDatePatternForDate();
        setQuotedConfigValue("insertdatetime_dateformat", dateFormat);
        setNonQuotedConfigValue("insertdatetime_formats", "['" + dateFormat + "','%H:%M:%S']");
    }
}
Also used : Formatter(org.olat.core.util.Formatter)

Example 3 with Formatter

use of org.olat.core.util.Formatter in project OpenOLAT by OpenOLAT.

the class MailListController method reloadModel.

private void reloadModel() {
    List<DBMailLight> mails;
    if (outbox) {
        if (StringHelper.containsNonWhitespace(metaId)) {
            mails = mailManager.getEmailsByMetaId(metaId);
        } else {
            mails = mailManager.getOutbox(getIdentity(), 0, -1, true);
        }
        // strip meta emails
        Set<String> metaIds = new HashSet<>();
        for (Iterator<DBMailLight> it = mails.iterator(); it.hasNext(); ) {
            DBMailLight mail = it.next();
            if (StringHelper.containsNonWhitespace(mail.getMetaId())) {
                if (metaIds.contains(mail.getMetaId())) {
                    it.remove();
                } else {
                    metaIds.add(mail.getMetaId());
                }
            }
        }
    } else {
        mails = mailManager.getInbox(getIdentity(), null, Boolean.TRUE, null, 0, -1);
    }
    // extract contexts
    Map<String, String> bpToContexts = new HashMap<>();
    for (DBMailLight mail : mails) {
        String businessPath = mail.getContext().getBusinessPath();
        if (StringHelper.containsNonWhitespace(businessPath) && !bpToContexts.containsKey(businessPath)) {
            String contextName = contextResolver.getName(businessPath, getLocale());
            if (StringHelper.containsNonWhitespace(contextName)) {
                bpToContexts.put(businessPath, contextName);
            }
        }
    }
    if (!bpToContexts.isEmpty()) {
        List<ShortName> filters = new ArrayList<>();
        Map<String, MailContextShortName> uniqueNames = new HashMap<>();
        ShortName allContextFilter = new MailContextShortName("-");
        filters.add(allContextFilter);
        for (Map.Entry<String, String> entry : bpToContexts.entrySet()) {
            String businessPath = entry.getKey();
            String contextName = entry.getValue();
            if (!uniqueNames.containsKey(contextName)) {
                MailContextShortName cxt = new MailContextShortName(contextName, new HashSet<String>());
                filters.add(cxt);
                uniqueNames.put(contextName, cxt);
            }
            uniqueNames.get(contextName).getBusinessPaths().add(businessPath);
        }
        tableCtr.setFilters(filters, allContextFilter);
    }
    Formatter formatter = Formatter.getInstance(getLocale());
    MailDataModel dataModel = new MailDataModel(mails, bpToContexts, getIdentity(), getTranslator(), formatter, outbox);
    tableCtr.setTableDataModel(dataModel);
}
Also used : HashMap(java.util.HashMap) Formatter(org.olat.core.util.Formatter) ArrayList(java.util.ArrayList) ShortName(org.olat.core.gui.ShortName) DBMailLight(org.olat.core.util.mail.model.DBMailLight) Map(java.util.Map) HashMap(java.util.HashMap) HashSet(java.util.HashSet)

Example 4 with Formatter

use of org.olat.core.util.Formatter in project OpenOLAT by OpenOLAT.

the class CertificatePDFFormWorker method fillCertificationInfos.

private void fillCertificationInfos(PDAcroForm acroForm) throws IOException {
    Formatter format = Formatter.getInstance(locale);
    if (dateCertification == null) {
        fillField("dateCertification", "", acroForm);
    } else {
        String formattedDateCertification = format.formatDate(dateCertification);
        fillField("dateCertification", formattedDateCertification, acroForm);
        String formattedDateCertificationLong = format.formatDateLong(dateCertification);
        fillField("dateCertificationLong", formattedDateCertificationLong, acroForm);
    }
    if (dateFirstCertification == null) {
        fillField("dateFirstCertification", "", acroForm);
    } else {
        String formattedDateFirstCertification = format.formatDate(dateFirstCertification);
        fillField("dateFirstCertification", formattedDateFirstCertification, acroForm);
        String formattedDateFirstCertificationLong = format.formatDate(dateFirstCertification);
        fillField("dateFirstCertificationLong", formattedDateFirstCertificationLong, acroForm);
    }
    if (dateNextRecertification == null) {
        fillField("dateNextRecertification", "", acroForm);
    } else {
        String formattedDateNextRecertification = format.formatDate(dateNextRecertification);
        fillField("dateNextRecertification", formattedDateNextRecertification, acroForm);
        String formattedDateNextRecertificationLong = format.formatDateLong(dateNextRecertification);
        fillField("dateNextRecertificationLong", formattedDateNextRecertificationLong, acroForm);
    }
}
Also used : Formatter(org.olat.core.util.Formatter)

Example 5 with Formatter

use of org.olat.core.util.Formatter in project OpenOLAT by OpenOLAT.

the class CertificatePhantomWorker method fillCertificationInfos.

private void fillCertificationInfos(VelocityContext context) {
    Formatter format = Formatter.getInstance(locale);
    context.put("dateFormatter", format);
    if (dateCertification == null) {
        context.put("dateCertification", "");
    } else {
        String formattedDateCertification = format.formatDate(dateCertification);
        context.put("dateCertification", formattedDateCertification);
        String formattedDateCertificationLong = format.formatDateLong(dateCertification);
        context.put("dateCertificationLong", formattedDateCertificationLong);
        context.put("dateCertificationRaw", dateCertification);
    }
    if (dateFirstCertification == null) {
        context.put("dateFirstCertification", "");
    } else {
        String formattedDateFirstCertification = format.formatDate(dateFirstCertification);
        context.put("dateFirstCertification", formattedDateFirstCertification);
        String formattedDateFirstCertificationLong = format.formatDate(dateFirstCertification);
        context.put("dateFirstCertificationLong", formattedDateFirstCertificationLong);
        context.put("dateFirstCertificationRaw", dateFirstCertification);
    }
    if (dateNextRecertification == null) {
        context.put("dateNextRecertification", "");
    } else {
        String formattedDateNextRecertification = format.formatDate(dateNextRecertification);
        context.put("dateNextRecertification", formattedDateNextRecertification);
        String formattedDateNextRecertificationLong = format.formatDateLong(dateNextRecertification);
        context.put("dateNextRecertificationLong", formattedDateNextRecertificationLong);
        context.put("dateNextRecertificationRaw", dateNextRecertification);
    }
}
Also used : Formatter(org.olat.core.util.Formatter)

Aggregations

Formatter (org.olat.core.util.Formatter)80 Date (java.util.Date)30 ArrayList (java.util.ArrayList)12 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)12 IOException (java.io.IOException)6 SubscriptionListItem (org.olat.core.commons.services.notifications.model.SubscriptionListItem)6 FormLink (org.olat.core.gui.components.form.flexible.elements.FormLink)6 Identity (org.olat.core.id.Identity)6 Translator (org.olat.core.gui.translator.Translator)5 UserPropertyHandler (org.olat.user.propertyhandlers.UserPropertyHandler)5 File (java.io.File)4 Calendar (java.util.Calendar)4 HashMap (java.util.HashMap)4 COSVisitorException (org.apache.pdfbox.exceptions.COSVisitorException)4 Row (org.olat.core.util.openxml.OpenXMLWorksheet.Row)4 OWASPAntiSamyXSSFilter (org.olat.core.util.filter.impl.OWASPAntiSamyXSSFilter)3 HashSet (java.util.HashSet)2 Map (java.util.Map)2 VelocityContext (org.apache.velocity.VelocityContext)2 Context (org.apache.velocity.context.Context)2