Search in sources :

Example 56 with Formatter

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

the class LecturesBlockPDFExport method prepare.

@Override
public void prepare(HttpServletResponse hres) {
    try {
        Formatter formatter = Formatter.getInstance(translator.getLocale());
        String filename = lectureBlock.getTitle() + "_" + formatter.formatDate(lectureBlock.getStartDate()) + "_" + formatter.formatTimeShort(lectureBlock.getStartDate()) + "-" + formatter.formatTimeShort(lectureBlock.getEndDate()) + ".pdf";
        hres.setHeader("Content-Disposition", "attachment; filename*=UTF-8''" + StringHelper.urlEncodeUTF8(filename));
        hres.setHeader("Content-Description", StringHelper.urlEncodeUTF8(filename));
        document.save(hres.getOutputStream());
    } catch (COSVisitorException | IOException e) {
        log.error("", e);
    }
}
Also used : COSVisitorException(org.apache.pdfbox.exceptions.COSVisitorException) Formatter(org.olat.core.util.Formatter) IOException(java.io.IOException)

Example 57 with Formatter

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

the class DropboxController method getConfirmation.

private String getConfirmation(UserRequest ureq, String filename) {
    // grab confirmation-text from bb-config
    String confirmation = config.getStringValue(TACourseNode.CONF_DROPBOX_CONFIRMATION);
    Context c = new VelocityContext();
    Identity identity = ureq.getIdentity();
    c.put("login", identity.getName());
    c.put("first", identity.getUser().getProperty(UserConstants.FIRSTNAME, getLocale()));
    c.put("last", identity.getUser().getProperty(UserConstants.LASTNAME, getLocale()));
    c.put("email", UserManager.getInstance().getUserDisplayEmail(identity, getLocale()));
    c.put("filename", filename);
    Date now = new Date();
    Formatter f = Formatter.getInstance(ureq.getLocale());
    c.put("date", f.formatDate(now));
    c.put("time", f.formatTime(now));
    // update attempts counter for this user: one file - one attempts
    AssessableCourseNode acn = (AssessableCourseNode) node;
    acn.incrementUserAttempts(userCourseEnv, Role.user);
    // log entry for this file
    UserNodeAuditManager am = userCourseEnv.getCourseEnvironment().getAuditManager();
    am.appendToUserNodeLog(node, identity, identity, "FILE UPLOADED: " + filename);
    return VelocityHelper.getInstance().evaluateVTL(confirmation, c);
}
Also used : Context(org.apache.velocity.context.Context) SubscriptionContext(org.olat.core.commons.services.notifications.SubscriptionContext) VelocityContext(org.apache.velocity.VelocityContext) MailContext(org.olat.core.util.mail.MailContext) AssessableCourseNode(org.olat.course.nodes.AssessableCourseNode) UserNodeAuditManager(org.olat.course.auditing.UserNodeAuditManager) VelocityContext(org.apache.velocity.VelocityContext) Formatter(org.olat.core.util.Formatter) Identity(org.olat.core.id.Identity) Date(java.util.Date)

Example 58 with Formatter

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

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)

Example 59 with Formatter

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

the class IQComponentRenderer method buildMenu.

/**
 * Method buildMenu.
 *
 * @return DOCUMENT ME!
 */
private StringOutput buildMenu(IQComponent comp, Translator translator, Renderer r, URLBuilder ubu) {
    StringOutput sb = new StringOutput();
    AssessmentInstance ai = comp.getAssessmentInstance();
    AssessmentContext ac = ai.getAssessmentContext();
    boolean renderSectionTitlesOnly = comp.getMenuDisplayConf().isRenderSectionsOnly();
    sb.append("<div id=\"o_qti_menu\">");
    sb.append("<h4>");
    sb.append(StringHelper.escapeHtml(ac.getTitle()));
    sb.append("</h4>");
    sb.append("<table border=0 width=\"100%\">");
    // append assessment navigation
    Formatter formatter = Formatter.getInstance(translator.getLocale());
    int scnt = ac.getSectionContextCount();
    for (int i = 0; i < scnt; i++) {
        SectionContext sc = ac.getSectionContext(i);
        boolean clickable = (ai.isSectionPage() && sc.isOpen()) || (!ai.isSectionPage());
        clickable = clickable && !ai.isClosed();
        clickable = clickable && ai.isMenu();
        sb.append("<tr>");
        sb.append(addSectionLink(r, ubu, formatter, sc, i, clickable, ac.getCurrentSectionContextPos() == i, ai.isSectionPage()));
        sb.append("</tr>");
        if (!renderSectionTitlesOnly) {
            // not only sections, but render questions to
            int icnt = sc.getItemContextCount();
            for (int j = 0; j < icnt; j++) {
                ItemContext itc = sc.getItemContext(j);
                clickable = !ai.isSectionPage() && sc.isOpen() && itc.isOpen();
                clickable = clickable && !ai.isClosed();
                clickable = clickable && ai.isMenu();
                sb.append("<tr>");
                sb.append(addItemLink(r, ubu, formatter, ai, itc, i, j, clickable, (ac.getCurrentSectionContextPos() == i && sc.getCurrentItemContextPos() == j), !ai.isSurvey()));
                sb.append("</tr>");
            }
        }
    }
    sb.append("</table>");
    sb.append("</div>");
    return sb;
}
Also used : SectionContext(org.olat.ims.qti.container.SectionContext) AssessmentContext(org.olat.ims.qti.container.AssessmentContext) ItemContext(org.olat.ims.qti.container.ItemContext) Formatter(org.olat.core.util.Formatter) AssessmentInstance(org.olat.ims.qti.process.AssessmentInstance) StringOutput(org.olat.core.gui.render.StringOutput) Hint(org.olat.ims.qti.container.qtielements.Hint)

Example 60 with Formatter

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

the class TeacherRollCallController method initForm.

@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    if (formLayout instanceof FormLayoutContainer) {
        FormLayoutContainer layoutCont = (FormLayoutContainer) formLayout;
        StringBuilder sb = new StringBuilder();
        List<Identity> teachers = lectureService.getTeachers(lectureBlock);
        for (Identity teacher : teachers) {
            if (sb.length() > 0)
                sb.append(", ");
            sb.append(StringHelper.escapeHtml(userManager.getUserDisplayName(teacher)));
        }
        Formatter formatter = Formatter.getInstance(getLocale());
        String date = formatter.formatDate(lectureBlock.getStartDate());
        String startTime = formatter.formatTimeShort(lectureBlock.getStartDate());
        String endTime = formatter.formatTimeShort(lectureBlock.getEndDate());
        String[] args = new String[] { // {0}
        lectureBlock.getTitle(), // {1}
        sb.toString(), // {2}
        date, // {3}
        startTime, // {4}
        endTime };
        layoutCont.contextPut("date", date);
        layoutCont.contextPut("startTime", startTime);
        layoutCont.contextPut("endTime", endTime);
        layoutCont.contextPut("dateAndTime", translate("lecture.block.dateAndTime", args));
        layoutCont.contextPut("teachers", sb.toString());
        layoutCont.contextPut("lectureBlockTitle", StringHelper.escapeHtml(lectureBlock.getTitle()));
        layoutCont.contextPut("lectureBlockExternalId", StringHelper.escapeHtml(lectureBlock.getExternalId()));
        StringBuilder description = Formatter.stripTabsAndReturns(Formatter.formatURLsAsLinks(lectureBlock.getDescription()));
        layoutCont.contextPut("lectureBlockDescription", StringHelper.xssScan(description));
        StringBuilder preparation = Formatter.stripTabsAndReturns(Formatter.formatURLsAsLinks(lectureBlock.getPreparation()));
        layoutCont.contextPut("lectureBlockPreparation", StringHelper.xssScan(preparation));
        layoutCont.contextPut("lectureBlockLocation", StringHelper.escapeHtml(lectureBlock.getLocation()));
        layoutCont.contextPut("lectureBlock", lectureBlock);
        layoutCont.contextPut("lectureBlockOptional", !lectureBlock.isCompulsory());
        layoutCont.setFormTitle(translate("lecture.block", args));
        layoutCont.setFormDescription(StringHelper.escapeJavaScript(lectureBlock.getDescription()));
    }
    // table
    FlexiTableSortOptions options = new FlexiTableSortOptions();
    FlexiTableColumnModel columnsModel = FlexiTableDataModelFactory.createFlexiTableColumnModel();
    if (isAdministrativeUser) {
        columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(RollCols.username));
        options.setDefaultOrderBy(new SortKey(RollCols.username.sortKey(), true));
    }
    int colPos = USER_PROPS_OFFSET;
    for (UserPropertyHandler userPropertyHandler : userPropertyHandlers) {
        if (userPropertyHandler == null)
            continue;
        String propName = userPropertyHandler.getName();
        boolean visible = userManager.isMandatoryUserProperty(USER_PROPS_ID, userPropertyHandler);
        FlexiColumnModel col = new DefaultFlexiColumnModel(visible, userPropertyHandler.i18nColumnDescriptorLabelKey(), colPos, true, propName);
        columnsModel.addFlexiColumnModel(col);
        colPos++;
        if (!options.hasDefaultOrderBy()) {
            options.setDefaultOrderBy(new SortKey(propName, true));
        } else if (UserConstants.LASTNAME.equals(propName)) {
            options.setDefaultOrderBy(new SortKey(propName, true));
        }
    }
    if (lectureBlock.isCompulsory()) {
        columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(RollCols.status));
        for (int i = 0; i < numOfLectures; i++) {
            DefaultFlexiColumnModel col = new DefaultFlexiColumnModel("table.header.lecture." + (i + 1), i + CHECKBOX_OFFSET, true, "lecture." + (i + 1));
            col.setAlwaysVisible(true);
            columnsModel.addFlexiColumnModel(col);
        }
        // all button
        DefaultFlexiColumnModel allCol = new DefaultFlexiColumnModel("all", RollCols.all.ordinal(), "all", new BooleanCellRenderer(new StaticFlexiCellRenderer(translate("all"), "all", null, null, translate("all.desc")), null));
        allCol.setAlwaysVisible(true);
        columnsModel.addFlexiColumnModel(allCol);
        if (secCallback.canViewAuthorizedAbsences() || secCallback.canEditAuthorizedAbsences()) {
            DefaultFlexiColumnModel authorizedCol = new DefaultFlexiColumnModel(RollCols.authorizedAbsence);
            authorizedCol.setAlwaysVisible(true);
            columnsModel.addFlexiColumnModel(authorizedCol);
        }
    }
    columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(RollCols.comment));
    tableModel = new TeacherRollCallDataModel(columnsModel, secCallback, getLocale());
    tableEl = uifactory.addTableElement(getWindowControl(), "table", tableModel, 20, false, getTranslator(), formLayout);
    tableEl.setCustomizeColumns(true);
    tableEl.setSortSettings(options);
    tableEl.setAndLoadPersistedPreferences(ureq, "teacher-roll-call");
    // buttons
    uifactory.addFormCancelButton("cancel", formLayout, ureq, getWindowControl());
    quickSaveButton = uifactory.addFormSubmitButton("save", "save.temporary", formLayout);
    quickSaveButton.setElementCssClass("o_sel_lecture_quick_save");
    closeLectureBlocksButton = uifactory.addFormLink("close.lecture.blocks", formLayout, Link.BUTTON);
    closeLectureBlocksButton.setElementCssClass("o_sel_lecture_close");
    if (lectureModule.isStatusCancelledEnabled()) {
        cancelLectureBlockButton = uifactory.addFormLink("cancel.lecture.blocks", formLayout, Link.BUTTON);
    }
    reopenButton = uifactory.addFormLink("reopen.lecture.blocks", formLayout, Link.BUTTON);
    reopenButton.setElementCssClass("o_sel_lecture_reopen");
    updateUI();
}
Also used : FlexiTableSortOptions(org.olat.core.gui.components.form.flexible.elements.FlexiTableSortOptions) Formatter(org.olat.core.util.Formatter) DefaultFlexiColumnModel(org.olat.core.gui.components.form.flexible.impl.elements.table.DefaultFlexiColumnModel) FlexiColumnModel(org.olat.core.gui.components.form.flexible.impl.elements.table.FlexiColumnModel) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) SortKey(org.olat.core.commons.persistence.SortKey) StaticFlexiCellRenderer(org.olat.core.gui.components.form.flexible.impl.elements.table.StaticFlexiCellRenderer) BooleanCellRenderer(org.olat.core.gui.components.form.flexible.impl.elements.table.BooleanCellRenderer) FlexiTableColumnModel(org.olat.core.gui.components.form.flexible.impl.elements.table.FlexiTableColumnModel) Identity(org.olat.core.id.Identity) DefaultFlexiColumnModel(org.olat.core.gui.components.form.flexible.impl.elements.table.DefaultFlexiColumnModel) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler)

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