use of org.olat.core.util.Formatter in project OpenOLAT by OpenOLAT.
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 OpenOLAT.
the class CertificatePDFFormWorker method fillRepositoryEntry.
private void fillRepositoryEntry(PDAcroForm acroForm) throws IOException {
String title = entry.getDisplayname();
fillField("title", title, acroForm);
String externalRef = entry.getExternalRef();
fillField("externalReference", externalRef, acroForm);
String authors = entry.getAuthors();
fillField("authors", authors, acroForm);
String expenditureOfWorks = entry.getExpenditureOfWork();
fillField("expenditureOfWorks", expenditureOfWorks, acroForm);
String mainLanguage = entry.getMainLanguage();
fillField("mainLanguage", mainLanguage, acroForm);
if (entry.getLifecycle() != null) {
Formatter format = Formatter.getInstance(locale);
Date from = entry.getLifecycle().getValidFrom();
String formattedFrom = format.formatDate(from);
fillField("from", formattedFrom, acroForm);
String formattedFromLong = format.formatDateLong(from);
fillField("fromLong", formattedFromLong, acroForm);
Date to = entry.getLifecycle().getValidTo();
String formattedTo = format.formatDate(to);
fillField("to", formattedTo, acroForm);
String formattedToLong = format.formatDateLong(to);
fillField("toLong", formattedToLong, acroForm);
}
}
use of org.olat.core.util.Formatter in project OpenOLAT by OpenOLAT.
the class PortfolioCourseNodeRunController method initForm.
@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
infosContainer = FormLayoutContainer.createDefaultFormLayout("infos", getTranslator());
formLayout.add(infosContainer);
String assessmentPage = velocity_root + "/assessment_infos.html";
assessmentInfosContainer = FormLayoutContainer.createCustomFormLayout("assessmentInfos", getTranslator(), assessmentPage);
assessmentInfosContainer.setVisible(false);
formLayout.add(assessmentInfosContainer);
VelocityContainer mainVC = ((FormLayoutContainer) formLayout).getFormItemComponent();
if (courseNode.getModuleConfiguration().getBooleanSafe(MSCourseNode.CONFIG_KEY_HAS_SCORE_FIELD, false)) {
HighScoreRunController highScoreCtr = new HighScoreRunController(ureq, getWindowControl(), userCourseEnv, courseNode, this.mainForm);
if (highScoreCtr.isViewHighscore()) {
Component highScoreComponent = highScoreCtr.getInitialComponent();
mainVC.put("highScore", highScoreComponent);
}
}
Object text = config.get(PortfolioCourseNodeConfiguration.NODE_TEXT);
String explanation = (text instanceof String) ? (String) text : "";
if (StringHelper.containsNonWhitespace(explanation)) {
uifactory.addStaticTextElement("explanation.text", explanation, infosContainer);
}
String deadlineconfig = (String) config.get(PortfolioCourseNodeConfiguration.DEADLINE_TYPE);
if (!DeadlineType.none.name().equals(deadlineconfig) && deadlineconfig != null) {
// show deadline-config
String deadLineLabel = "map.deadline." + deadlineconfig + ".label";
String deadLineInfo = "";
if (deadlineconfig.equals(DeadlineType.absolut.name())) {
Formatter f = Formatter.getInstance(getLocale());
deadLineInfo = f.formatDate((Date) config.get(PortfolioCourseNodeConfiguration.DEADLINE_DATE));
} else {
deadLineInfo = getDeadlineRelativeInfo();
}
deadlineDateText = uifactory.addStaticTextElement("deadline", deadLineLabel, deadLineInfo, infosContainer);
}
if (templateMap != null || templateBinder != null) {
updateUI(ureq);
}
}
use of org.olat.core.util.Formatter in project OpenOLAT by OpenOLAT.
the class PortfolioResultDetailsController method initMapsForm.
protected void initMapsForm(FormItemContainer formLayout) {
Formatter formatter = Formatter.getInstance(getLocale());
int count = 0;
for (PortfolioStructureMap map : maps) {
MapElements mapElements = new MapElements();
if (map instanceof EPStructuredMap) {
EPStructuredMap structuredMap = (EPStructuredMap) map;
if (maps.size() > 1 || !structuredMap.getStructuredMapSource().equals(templateMap)) {
String templateTitle = structuredMap.getStructuredMapSource().getTitle();
uifactory.addStaticTextElement("map.template." + count, "map.template", templateTitle, formLayout);
}
String copyDate = "";
if (structuredMap.getCopyDate() != null) {
copyDate = formatter.formatDateAndTime(structuredMap.getCopyDate());
}
uifactory.addStaticTextElement("map.copyDate." + count, "map.copyDate", copyDate, formLayout);
String returnDate = "";
if (structuredMap.getReturnDate() != null) {
returnDate = formatter.formatDateAndTime(structuredMap.getReturnDate());
}
uifactory.addStaticTextElement("map.returnDate." + count, "map.returnDate", returnDate, formLayout);
String deadLine = "";
if (structuredMap.getDeadLine() != null) {
deadLine = formatter.formatDateAndTime(structuredMap.getDeadLine());
}
mapElements.deadlineEl = uifactory.addStaticTextElement("map.deadline." + count, "map.deadline", deadLine, formLayout);
}
FormLayoutContainer buttonsCont = FormLayoutContainer.createButtonLayout("buttons." + count, getTranslator());
buttonsCont.setRootForm(mainForm);
formLayout.add(buttonsCont);
if (map instanceof EPStructuredMap) {
mapElements.changeDeadlineLink = uifactory.addFormLink("map.deadline.change." + count, "map.deadline.change", null, buttonsCont, Link.BUTTON);
mapElements.changeDeadlineLink.setUserObject(map);
}
mapElements.openMapLink = uifactory.addFormLink("open.map." + count, "open.map", null, buttonsCont, Link.BUTTON);
mapElements.openMapLink.setUserObject(map);
count++;
if (count != maps.size()) {
uifactory.addSpacerElement("spacer-" + count, formLayout, false);
}
mapToElements.put(map, mapElements);
}
}
use of org.olat.core.util.Formatter in project OpenOLAT by OpenOLAT.
the class HistoryController method updateChangeLog.
protected void updateChangeLog() {
Date date = dateChooser.getDate();
List<SubscriptionListItem> items = notificationsHandler.getAllItems(binder, secCallback, date, getLocale());
Formatter formatter = Formatter.getInstance(getLocale());
List<SubscriptionListItemWrapper> wrappers = new ArrayList<>(items.size());
for (SubscriptionListItem item : items) {
String dateString = formatter.formatDate(item.getDate());
String linkName = "subscrIL_" + (counter++);
String linkLabel = StringHelper.escapeHtml(item.getDescription());
FormLink link = uifactory.addFormLink(linkName, linkLabel, null, flc, Link.NONTRANSLATED);
link.setUserObject(item.getBusinessPath());
SubscriptionListItemWrapper bundle = new SubscriptionListItemWrapper(linkName, dateString, item.getIconCssClass());
wrappers.add(bundle);
}
flc.contextPut("subscriptionItems", wrappers);
}
Aggregations