Search in sources :

Example 31 with Formatter

use of org.olat.core.util.Formatter in project openolat by klemens.

the class TextFlexiCellRenderer method render.

/**
 * Render Date type with Formatter depending on locale. Render all other types with toString.
 * @param target
 * @param cellValue
 * @param translator
 */
@Override
public void render(Renderer renderer, StringOutput target, Object cellValue, int row, FlexiTableComponent source, URLBuilder ubu, Translator translator) {
    if (cellValue instanceof Date) {
        Formatter formatter = Formatter.getInstance(translator.getLocale());
        target.append(formatter.formatDateAndTime((Date) cellValue));
    } else if (cellValue instanceof String) {
        String str = (String) cellValue;
        if (escapeHtml != null) {
            switch(escapeHtml) {
                case antisamy:
                    target.append(new OWASPAntiSamyXSSFilter().filter(str));
                    break;
                case html:
                    StringHelper.escapeHtml(target, str);
                    break;
                case none:
                    target.append(str);
                    break;
            }
        } else {
            StringHelper.escapeHtml(target, str);
        }
    } else if (cellValue instanceof Date) {
        Formatter formatter = Formatter.getInstance(translator.getLocale());
        String date = formatter.formatDateAndTime((Date) cellValue);
        target.append(date);
    } else if (cellValue instanceof Boolean) {
        Boolean bool = (Boolean) cellValue;
        if (bool.booleanValue()) {
            target.append("<input type='checkbox' value='' checked='checked' disabled='disabled' />");
        } else {
            target.append("<input type='checkbox' value='' disabled='disabled' />");
        }
    } else if (cellValue != null) {
        target.append(cellValue.toString());
    }
}
Also used : OWASPAntiSamyXSSFilter(org.olat.core.util.filter.impl.OWASPAntiSamyXSSFilter) Formatter(org.olat.core.util.Formatter) Date(java.util.Date)

Example 32 with Formatter

use of org.olat.core.util.Formatter in project openolat by klemens.

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 33 with Formatter

use of org.olat.core.util.Formatter in project openolat by klemens.

the class CertificatePhantomWorker method fillRepositoryEntry.

private void fillRepositoryEntry(VelocityContext context) {
    String title = entry.getDisplayname();
    context.put("title", title);
    String description = entry.getDescription();
    context.put("description", description);
    String requirements = entry.getRequirements();
    context.put("requirements", requirements);
    String objectives = entry.getObjectives();
    context.put("objectives", objectives);
    String credits = entry.getCredits();
    context.put("credits", credits);
    String externalRef = entry.getExternalRef();
    context.put("externalReference", externalRef);
    String authors = entry.getAuthors();
    context.put("authors", authors);
    String expenditureOfWorks = entry.getExpenditureOfWork();
    context.put("expenditureOfWorks", expenditureOfWorks);
    String mainLanguage = entry.getMainLanguage();
    context.put("mainLanguage", mainLanguage);
    if (entry.getLifecycle() != null) {
        Formatter format = Formatter.getInstance(locale);
        Date from = entry.getLifecycle().getValidFrom();
        String formattedFrom = format.formatDate(from);
        context.put("from", formattedFrom);
        String formattedFromLong = format.formatDateLong(from);
        context.put("fromLong", formattedFromLong);
        Date to = entry.getLifecycle().getValidTo();
        String formattedTo = format.formatDate(to);
        context.put("to", formattedTo);
        String formattedToLong = format.formatDateLong(to);
        context.put("toLong", formattedToLong);
    }
}
Also used : Formatter(org.olat.core.util.Formatter) Date(java.util.Date)

Example 34 with Formatter

use of org.olat.core.util.Formatter in project openolat by klemens.

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)

Example 35 with Formatter

use of org.olat.core.util.Formatter in project openolat by klemens.

the class GTAMailTemplate method putVariablesInMailContext.

@Override
public void putVariablesInMailContext(VelocityContext context, Identity recipient) {
    Locale locale = translator.getLocale();
    // compatibility with the old TA
    context.put("login", identity.getName());
    context.put("first", identity.getUser().getProperty(UserConstants.FIRSTNAME, locale));
    context.put("firstName", identity.getUser().getProperty(UserConstants.FIRSTNAME, locale));
    context.put("last", identity.getUser().getProperty(UserConstants.LASTNAME, locale));
    context.put("lastName", identity.getUser().getProperty(UserConstants.LASTNAME, locale));
    context.put("email", UserManager.getInstance().getUserDisplayEmail(identity, locale));
    context.put("numberOfFiles", files == null ? "0" : Integer.toString(files.length));
    if (files != null && files.length > 0) {
        StringBuilder sb = new StringBuilder();
        for (File file : files) {
            if (sb.length() > 0)
                sb.append(", ");
            sb.append(file.getName());
        }
        context.put("filename", sb.toString());
    } else {
        context.put("filename", translator.translate("submission.nofile"));
    }
    Date now = new Date();
    Formatter f = Formatter.getInstance(locale);
    context.put("date", f.formatDate(now));
    context.put("time", f.formatTime(now));
}
Also used : Locale(java.util.Locale) Formatter(org.olat.core.util.Formatter) File(java.io.File) Date(java.util.Date)

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