Search in sources :

Example 11 with StringOutput

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

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 12 with StringOutput

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

the class DefaultXlsTableExporter method createData.

private void createData(final Table table, final int cdcnt, final int rcnt, final OpenXMLWorksheet exportSheet) {
    for (int r = 0; r < rcnt; r++) {
        Row dataRow = exportSheet.newRow();
        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);
            if (StringHelper.containsNonWhitespace(cellValue)) {
                cellValue = StringEscapeUtils.unescapeHtml(cellValue);
                if (cellValue.length() >= 32767) {
                    cellValue = Formatter.truncate(cellValue, 32760);
                }
            }
            dataRow.addCell(c, cellValue, null);
        }
    }
}
Also used : StringOutput(org.olat.core.gui.render.StringOutput) Row(org.olat.core.util.openxml.OpenXMLWorksheet.Row)

Example 13 with StringOutput

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

the class ChoiceTableDataModel method matchRowWithSearchString.

/**
 * Check if the row-value matches with the search-query.
 * @param row
 * @param tableSearchString2
 * @return
 */
private boolean matchRowWithSearchString(final int row, final String tableSearchString2) {
    log.debug("matchRowWithFilter:  row=" + row + " tableFilterString=" + tableSearchString);
    if (!isTableFiltered()) {
        return true;
    }
    // loop over all columns
    TableDataModel unfilteredModel = getUnfilteredTableDataModel();
    Filter htmlFilter = FilterFactory.getHtmlTagsFilter();
    for (int colIndex = getColumnCountFromAllCDs(); colIndex-- > 0; ) {
        ColumnDescriptor cd = getColumnDescriptorFromAllCDs(colIndex);
        int dataColumn = cd.getDataColumn();
        if (dataColumn >= 0 && isColumnDescriptorVisible(cd)) {
            Object value = unfilteredModel.getValueAt(row, dataColumn);
            // When a CustomCellRenderer exist, use this to render cell-value to String
            if (cd instanceof CustomRenderColumnDescriptor) {
                CustomRenderColumnDescriptor cdrd = (CustomRenderColumnDescriptor) cd;
                CustomCellRenderer customCellRenderer = cdrd.getCustomCellRenderer();
                if (customCellRenderer instanceof CustomCssCellRenderer) {
                    // For css renderers only use the hover
                    // text, not the CSS class name and other
                    // HTLM markup
                    CustomCssCellRenderer cssRenderer = (CustomCssCellRenderer) customCellRenderer;
                    value = cssRenderer.getHoverText(value);
                    if (!StringHelper.containsNonWhitespace((String) value)) {
                        continue;
                    }
                } else {
                    StringOutput sb = StringOutputPool.allocStringBuilder(250);
                    customCellRenderer.render(sb, null, value, cdrd.getLocale(), cd.getAlignment(), null);
                    value = StringOutputPool.freePop(sb);
                }
            }
            if (value instanceof String) {
                String valueAsString = (String) value;
                // Remove any HTML markup from the value
                valueAsString = htmlFilter.filter(valueAsString);
                // Finally compare with search value based on a simple lowercase match
                if (valueAsString.toLowerCase().indexOf(tableSearchString2.toLowerCase()) != -1) {
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : Filter(org.olat.core.util.filter.Filter) StringOutput(org.olat.core.gui.render.StringOutput)

Example 14 with StringOutput

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

the class MenuTreeRenderer method appendDragAndDropElement.

private void appendDragAndDropElement(TreeNode node, MenuTree tree, List<DndElement> target, URLBuilder ubu, AJAXFlags flags) {
    String id = node.getIdent();
    boolean drag = tree.isDragEnabled() && ((DnDTreeModel) tree.getTreeModel()).isNodeDraggable(node);
    boolean drop = tree.isDropEnabled() && ((DnDTreeModel) tree.getTreeModel()).isNodeDroppable(node);
    if (drag || drop) {
        DndElement el = new DndElement();
        el.setId(id);
        if (drag) {
            el.setDrag(drag);
        }
        if (drop) {
            el.setDrop(true);
            StringOutput endUrl = new StringOutput(64);
            ubu.buildURI(endUrl, new String[] { COMMAND_ID, NODE_IDENT }, new String[] { COMMAND_TREENODE_DROP, node.getIdent() }, flags.isIframePostEnabled() ? AJAXFlags.MODE_TOBGIFRAME : AJAXFlags.MODE_NORMAL);
            el.setEndUrl(endUrl.toString());
        }
        target.add(el);
    }
}
Also used : StringOutput(org.olat.core.gui.render.StringOutput)

Example 15 with StringOutput

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

the class StaticColumnDescriptor 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)

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