Search in sources :

Example 46 with Formatter

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());
    }
}
Also used : OWASPAntiSamyXSSFilter(org.olat.core.util.filter.impl.OWASPAntiSamyXSSFilter) Formatter(org.olat.core.util.Formatter) Date(java.util.Date)

Example 47 with Formatter

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);
    }
}
Also used : Formatter(org.olat.core.util.Formatter) Date(java.util.Date)

Example 48 with Formatter

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);
    }
}
Also used : Formatter(org.olat.core.util.Formatter) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) HighScoreRunController(org.olat.course.highscore.ui.HighScoreRunController) Component(org.olat.core.gui.components.Component) Date(java.util.Date) VelocityContainer(org.olat.core.gui.components.velocity.VelocityContainer)

Example 49 with Formatter

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);
    }
}
Also used : PortfolioStructureMap(org.olat.portfolio.model.structel.PortfolioStructureMap) EPStructuredMap(org.olat.portfolio.model.structel.EPStructuredMap) Formatter(org.olat.core.util.Formatter) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)

Example 50 with Formatter

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);
}
Also used : SubscriptionListItem(org.olat.core.commons.services.notifications.model.SubscriptionListItem) Formatter(org.olat.core.util.Formatter) ArrayList(java.util.ArrayList) FormLink(org.olat.core.gui.components.form.flexible.elements.FormLink) 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