Search in sources :

Example 91 with StringOutput

use of org.olat.core.gui.render.StringOutput in project openolat by klemens.

the class TableListProvider method getResult.

@Override
public void getResult(String searchValue, ListReceiver receiver) {
    Filter htmlFilter = FilterFactory.getHtmlTagsFilter();
    Set<String> searchEntries = new TreeSet<String>();
    int entryCounter = 1;
    // loop over whole data-model
    TableDataModel<?> unfilteredModel = table.getUnfilteredTableDataModel();
    int rowCount = unfilteredModel.getRowCount();
    int colCount = table.getColumnCountFromAllCDs();
    a_a: for (int colIndex = 0; colIndex < colCount; colIndex++) {
        ColumnDescriptor cd = table.getColumnDescriptorFromAllCDs(colIndex);
        int dataColumn = cd.getDataColumn();
        if (dataColumn >= 0 && table.isColumnDescriptorVisible(cd)) {
            for (int rowIndex = 0; rowIndex < rowCount; rowIndex++) {
                Object obj = unfilteredModel.getValueAt(rowIndex, dataColumn);
                // When a CustomCellRenderer exist, use this to render cell-value to String
                if (cd instanceof CustomRenderColumnDescriptor) {
                    CustomRenderColumnDescriptor crcd = (CustomRenderColumnDescriptor) cd;
                    CustomCellRenderer customCellRenderer = crcd.getCustomCellRenderer();
                    if (customCellRenderer instanceof CustomCssCellRenderer) {
                        // For css renderers only use the hover
                        // text, not the CSS class name and other
                        // markup
                        CustomCssCellRenderer cssRenderer = (CustomCssCellRenderer) customCellRenderer;
                        obj = cssRenderer.getHoverText(obj);
                        if (!StringHelper.containsNonWhitespace((String) obj)) {
                            continue;
                        }
                    } else {
                        StringOutput sb = StringOutputPool.allocStringBuilder(250);
                        customCellRenderer.render(sb, null, obj, crcd.getLocale(), cd.getAlignment(), null);
                        obj = StringOutputPool.freePop(sb);
                    }
                }
                if (obj instanceof String) {
                    String valueString = (String) obj;
                    // Remove any HTML markup from the value
                    valueString = htmlFilter.filter(valueString);
                    // Finally compare with search value based on a simple lowercase match
                    if (valueString.toLowerCase().indexOf(searchValue.toLowerCase()) != -1) {
                        if (searchEntries.add(valueString)) {
                            // Add to receiver list same entries only once
                            if (searchEntries.size() == 1) {
                                // before first entry, add searchValue. But add only when one search match
                                receiver.addEntry(searchValue, searchValue);
                            }
                            // limit the number of entries
                            if (entryCounter++ > MAX_TABLE_SEARCH_RESULT_ENTRIES) {
                                receiver.addEntry("...", "...");
                                break a_a;
                            }
                            receiver.addEntry(valueString, valueString);
                        }
                    }
                }
            }
        }
    }
}
Also used : Filter(org.olat.core.util.filter.Filter) TreeSet(java.util.TreeSet) StringOutput(org.olat.core.gui.render.StringOutput)

Example 92 with StringOutput

use of org.olat.core.gui.render.StringOutput in project openolat by klemens.

the class TableRenderer method appendSingleDataRow.

private void appendSingleDataRow(final Renderer renderer, final StringOutput target, final URLBuilder ubu, Table table, final boolean iframePostEnabled, final int cols, final int i, final int currentPosInModel, final boolean isMark) {
    String cssClass;
    for (int j = 0; j < cols; j++) {
        ColumnDescriptor cd = table.getColumnDescriptor(j);
        int alignment = cd.getAlignment();
        cssClass = (alignment == ColumnDescriptor.ALIGNMENT_LEFT ? "text-left" : (alignment == ColumnDescriptor.ALIGNMENT_RIGHT ? "text-right" : "text-center"));
        target.append("<td class=\"").append(cssClass);
        if (isMark) {
            target.append(" o_table_marked");
        }
        target.append("\">");
        String action = cd.getAction(i);
        if (action != null) {
            StringOutput so = new StringOutput(100);
            cd.renderValue(so, i, renderer);
            appendSingleDataRowActionColumn(target, ubu, table, iframePostEnabled, i, currentPosInModel, j, cd, action, so.toString());
        } else {
            cd.renderValue(target, i, renderer);
        }
        target.append("</td>");
    }
}
Also used : StringOutput(org.olat.core.gui.render.StringOutput)

Example 93 with StringOutput

use of org.olat.core.gui.render.StringOutput in project openolat by klemens.

the class BooleanColumnDescriptor method toString.

public String toString(final int rowid) {
    StringOutput sb = new StringOutput();
    renderValue(sb, rowid, null);
    return sb.toString();
}
Also used : StringOutput(org.olat.core.gui.render.StringOutput)

Example 94 with StringOutput

use of org.olat.core.gui.render.StringOutput in project openolat by klemens.

the class CustomRenderColumnDescriptor method toString.

public String toString(final int rowid) {
    StringOutput sb = new StringOutput();
    renderValue(sb, rowid, null);
    return sb.toString();
}
Also used : StringOutput(org.olat.core.gui.render.StringOutput)

Example 95 with StringOutput

use of org.olat.core.gui.render.StringOutput in project openolat by klemens.

the class DefaultCsvTableExporter method createData.

private void createData(final Table table, final int cdcnt, final int rcnt, final StringBuilder sb) {
    for (int r = 0; r < rcnt; r++) {
        for (int c = 0; c < cdcnt; c++) {
            ColumnDescriptor cd = table.getColumnDescriptor(c);
            if (cd instanceof StaticColumnDescriptor) {
                // ignore static column descriptors - of no value in excel download!
                continue;
            }
            StringOutput so = new StringOutput();
            cd.renderValue(so, r, null);
            String cellValue = so.toString();
            cellValue = StringHelper.stripLineBreaks(cellValue);
            cellValue = FilterFactory.getHtmlTagsFilter().filter(cellValue);
            sb.append('\t').append(cellValue);
        }
        sb.append('\n');
    }
}
Also used : StringOutput(org.olat.core.gui.render.StringOutput)

Aggregations

StringOutput (org.olat.core.gui.render.StringOutput)188 IOException (java.io.IOException)48 URLBuilder (org.olat.core.gui.render.URLBuilder)30 Renderer (org.olat.core.gui.render.Renderer)26 Block (uk.ac.ed.ph.jqtiplus.node.content.basic.Block)24 RenderResult (org.olat.core.gui.render.RenderResult)22 Component (org.olat.core.gui.components.Component)10 Translator (org.olat.core.gui.translator.Translator)10 Locale (java.util.Locale)8 Window (org.olat.core.gui.components.Window)8 Form (org.olat.core.gui.components.form.flexible.impl.Form)8 VelocityRenderDecorator (org.olat.core.gui.render.velocity.VelocityRenderDecorator)8 ArrayList (java.util.ArrayList)6 StreamResult (javax.xml.transform.stream.StreamResult)6 Test (org.junit.Test)6 GlobalSettings (org.olat.core.gui.GlobalSettings)6 ComponentRenderer (org.olat.core.gui.components.ComponentRenderer)6 DefaultColumnDescriptor (org.olat.core.gui.components.table.DefaultColumnDescriptor)6 OLATRuntimeException (org.olat.core.logging.OLATRuntimeException)6 Matcher (java.util.regex.Matcher)5