Search in sources :

Example 1 with ExcelMediaResource

use of org.olat.core.gui.media.ExcelMediaResource in project OpenOLAT by OpenOLAT.

the class GroupChoiceForm method downloadResults.

private void downloadResults(UserRequest ureq) {
    int cdcnt = manageTableData.getColumnCount();
    int rcnt = manageTableData.getRowCount();
    StringBuilder sb = new StringBuilder();
    boolean isAdministrativeUser = securityModule.isUserAllowedAdminProps(ureq.getUserSession().getRoles());
    List<UserPropertyHandler> userPropertyHandlers = userManager.getUserPropertyHandlersFor(USER_PROPS_ID, isAdministrativeUser);
    // additional informations
    sb.append(translate("cl.course.title")).append('\t').append(course.getCourseTitle());
    sb.append('\n');
    String listTitle = checklist.getTitle() == null ? "" : checklist.getTitle();
    sb.append(translate("cl.title")).append('\t').append(listTitle);
    sb.append('\n').append('\n');
    // header
    for (int c = 0; c < (cdcnt - 1); c++) {
        // skip last column (action)
        ColumnDescriptor cd = manageChecklistTable.getColumnDescriptor(c);
        String headerKey = cd.getHeaderKey();
        String headerVal = cd.translateHeaderKey() ? translate(headerKey) : headerKey;
        sb.append('\t').append(headerVal);
    }
    sb.append('\n');
    // checkpoint description
    if (isAdministrativeUser) {
        sb.append('\t');
    }
    for (UserPropertyHandler userPropertyHandler : userPropertyHandlers) {
        if (userPropertyHandler == null)
            continue;
        sb.append('\t');
    }
    for (Checkpoint checkpoint : checklist.getCheckpoints()) {
        sb.append('\t').append(checkpoint.getDescription());
    }
    sb.append('\n');
    // data
    for (int r = 0; r < rcnt; r++) {
        for (int c = 0; c < (cdcnt - 1); c++) {
            // skip last column (action)
            ColumnDescriptor cd = manageChecklistTable.getColumnDescriptor(c);
            StringOutput so = new StringOutput();
            cd.renderValue(so, r, null);
            String cellValue = so.toString();
            cellValue = StringHelper.stripLineBreaks(cellValue);
            sb.append('\t').append(cellValue);
        }
        sb.append('\n');
    }
    String res = sb.toString();
    String charset = UserManager.getInstance().getUserCharset(ureq.getIdentity());
    ExcelMediaResource emr = new ExcelMediaResource(res, charset);
    ureq.getDispatchResult().setResultingMediaResource(emr);
}
Also used : DefaultColumnDescriptor(org.olat.core.gui.components.table.DefaultColumnDescriptor) StaticColumnDescriptor(org.olat.core.gui.components.table.StaticColumnDescriptor) ColumnDescriptor(org.olat.core.gui.components.table.ColumnDescriptor) StringOutput(org.olat.core.gui.render.StringOutput) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler) ExcelMediaResource(org.olat.core.gui.media.ExcelMediaResource)

Example 2 with ExcelMediaResource

use of org.olat.core.gui.media.ExcelMediaResource in project openolat by klemens.

the class DefaultCsvTableExporter method export.

/**
 * @see org.olat.core.gui.components.table.TableExporter#export(org.olat.core.gui.components.table.Table)
 */
@Override
public MediaResource export(Table table) {
    Translator translator = table.getTranslator();
    int cdcnt = table.getColumnCount();
    int rcnt = table.getRowCount();
    StringBuilder sb = new StringBuilder();
    createHeader(table, translator, cdcnt, sb);
    sb.append('\n');
    createData(table, cdcnt, rcnt, sb);
    String res = sb.toString();
    // FIXME:FG:6.2:OLAT-3736  a use a charsetprovider interface which can deliver the selected charset of a user
    // String charset = UserManager.getInstance().getUserCharset(ureq.getIdentity());
    // As a temporary workaround use the default charset
    String charset = WebappHelper.getDefaultCharset();
    return new ExcelMediaResource(res, charset);
}
Also used : Translator(org.olat.core.gui.translator.Translator) ExcelMediaResource(org.olat.core.gui.media.ExcelMediaResource)

Example 3 with ExcelMediaResource

use of org.olat.core.gui.media.ExcelMediaResource in project openolat by klemens.

the class GroupChoiceForm method downloadResults.

private void downloadResults(UserRequest ureq) {
    int cdcnt = manageTableData.getColumnCount();
    int rcnt = manageTableData.getRowCount();
    StringBuilder sb = new StringBuilder();
    boolean isAdministrativeUser = securityModule.isUserAllowedAdminProps(ureq.getUserSession().getRoles());
    List<UserPropertyHandler> userPropertyHandlers = userManager.getUserPropertyHandlersFor(USER_PROPS_ID, isAdministrativeUser);
    // additional informations
    sb.append(translate("cl.course.title")).append('\t').append(course.getCourseTitle());
    sb.append('\n');
    String listTitle = checklist.getTitle() == null ? "" : checklist.getTitle();
    sb.append(translate("cl.title")).append('\t').append(listTitle);
    sb.append('\n').append('\n');
    // header
    for (int c = 0; c < (cdcnt - 1); c++) {
        // skip last column (action)
        ColumnDescriptor cd = manageChecklistTable.getColumnDescriptor(c);
        String headerKey = cd.getHeaderKey();
        String headerVal = cd.translateHeaderKey() ? translate(headerKey) : headerKey;
        sb.append('\t').append(headerVal);
    }
    sb.append('\n');
    // checkpoint description
    if (isAdministrativeUser) {
        sb.append('\t');
    }
    for (UserPropertyHandler userPropertyHandler : userPropertyHandlers) {
        if (userPropertyHandler == null)
            continue;
        sb.append('\t');
    }
    for (Checkpoint checkpoint : checklist.getCheckpoints()) {
        sb.append('\t').append(checkpoint.getDescription());
    }
    sb.append('\n');
    // data
    for (int r = 0; r < rcnt; r++) {
        for (int c = 0; c < (cdcnt - 1); c++) {
            // skip last column (action)
            ColumnDescriptor cd = manageChecklistTable.getColumnDescriptor(c);
            StringOutput so = new StringOutput();
            cd.renderValue(so, r, null);
            String cellValue = so.toString();
            cellValue = StringHelper.stripLineBreaks(cellValue);
            sb.append('\t').append(cellValue);
        }
        sb.append('\n');
    }
    String res = sb.toString();
    String charset = UserManager.getInstance().getUserCharset(ureq.getIdentity());
    ExcelMediaResource emr = new ExcelMediaResource(res, charset);
    ureq.getDispatchResult().setResultingMediaResource(emr);
}
Also used : DefaultColumnDescriptor(org.olat.core.gui.components.table.DefaultColumnDescriptor) StaticColumnDescriptor(org.olat.core.gui.components.table.StaticColumnDescriptor) ColumnDescriptor(org.olat.core.gui.components.table.ColumnDescriptor) StringOutput(org.olat.core.gui.render.StringOutput) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler) ExcelMediaResource(org.olat.core.gui.media.ExcelMediaResource)

Example 4 with ExcelMediaResource

use of org.olat.core.gui.media.ExcelMediaResource in project OpenOLAT by OpenOLAT.

the class DefaultCsvTableExporter method export.

/**
 * @see org.olat.core.gui.components.table.TableExporter#export(org.olat.core.gui.components.table.Table)
 */
@Override
public MediaResource export(Table table) {
    Translator translator = table.getTranslator();
    int cdcnt = table.getColumnCount();
    int rcnt = table.getRowCount();
    StringBuilder sb = new StringBuilder();
    createHeader(table, translator, cdcnt, sb);
    sb.append('\n');
    createData(table, cdcnt, rcnt, sb);
    String res = sb.toString();
    // FIXME:FG:6.2:OLAT-3736  a use a charsetprovider interface which can deliver the selected charset of a user
    // String charset = UserManager.getInstance().getUserCharset(ureq.getIdentity());
    // As a temporary workaround use the default charset
    String charset = WebappHelper.getDefaultCharset();
    return new ExcelMediaResource(res, charset);
}
Also used : Translator(org.olat.core.gui.translator.Translator) ExcelMediaResource(org.olat.core.gui.media.ExcelMediaResource)

Aggregations

ExcelMediaResource (org.olat.core.gui.media.ExcelMediaResource)4 ColumnDescriptor (org.olat.core.gui.components.table.ColumnDescriptor)2 DefaultColumnDescriptor (org.olat.core.gui.components.table.DefaultColumnDescriptor)2 StaticColumnDescriptor (org.olat.core.gui.components.table.StaticColumnDescriptor)2 StringOutput (org.olat.core.gui.render.StringOutput)2 Translator (org.olat.core.gui.translator.Translator)2 UserPropertyHandler (org.olat.user.propertyhandlers.UserPropertyHandler)2