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());
}
}
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);
}
}
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);
}
}
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);
}
}
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));
}
Aggregations