Search in sources :

Example 11 with Filter

use of org.olat.core.util.filter.Filter in project openolat by klemens.

the class FeedViewHelper method getItemDescriptionForBrowser.

/**
 * Get the item description with media file paths that are dispatchable by
 * a FeedMediaDispatcher.
 *
 * @param item
 * @return
 */
public String getItemDescriptionForBrowser(Item item) {
    String itemDescription = "";
    if (item != null) {
        String description = item.getDescription();
        if (description != null) {
            if (item.getFeed().isExternal()) {
                // Apply xss filter for security reasons. Only necessary for external
                // feeds (e.g. to not let them execute JS code in our OLAT environment)
                Filter xssFilter = FilterFactory.getXSSFilter(description.length() + 1);
                itemDescription = xssFilter.filter(description);
            } else {
                // Add relative media base to media elements to display internal media
                // files
                String basePath = baseUri + "/" + item.getGuid();
                Filter mediaUrlFilter = FilterFactory.getBaseURLToMediaRelativeURLFilter(basePath);
                itemDescription = mediaUrlFilter.filter(description);
            }
        }
        itemDescription = Formatter.formatLatexFormulas(itemDescription);
    }
    return itemDescription;
}
Also used : Filter(org.olat.core.util.filter.Filter)

Example 12 with Filter

use of org.olat.core.util.filter.Filter in project openolat by klemens.

the class EPAbstractHandler method getIndexerDocument.

@Override
public OlatDocument getIndexerDocument(SearchResourceContext searchResourceContext, AbstractArtefact artefact, EPFrontendManager ePFManager) {
    OlatDocument document = new OlatDocument();
    Identity author = artefact.getAuthor();
    if (author != null) {
        document.setAuthor(author.getName());
    }
    Filter filter = FilterFactory.getHtmlTagAndDescapingFilter();
    document.setCreatedDate(artefact.getCreationDate());
    document.setTitle(filter.filter(artefact.getTitle()));
    document.setDescription(filter.filter(artefact.getDescription()));
    document.setResourceUrl(searchResourceContext.getResourceUrl());
    document.setDocumentType(searchResourceContext.getDocumentType());
    document.setCssIcon(artefact.getIcon());
    document.setParentContextType(searchResourceContext.getParentContextType());
    document.setParentContextName(searchResourceContext.getParentContextName());
    StringBuilder sb = new StringBuilder();
    if (artefact.getReflexion() != null) {
        sb.append(artefact.getReflexion()).append(' ');
    }
    getContent(artefact, sb, searchResourceContext, ePFManager);
    document.setContent(sb.toString());
    return document;
}
Also used : OlatDocument(org.olat.search.model.OlatDocument) Filter(org.olat.core.util.filter.Filter) Identity(org.olat.core.id.Identity)

Example 13 with Filter

use of org.olat.core.util.filter.Filter in project openolat by klemens.

the class RichTextElementImpl method getValue.

/**
 * @see org.olat.core.gui.components.form.flexible.impl.elements.AbstractTextElement#getValue()
 * The returned value is XSS save and
 * does not contain executable JavaScript code. If you want to get the raw
 * user data use the getRawValue() method.
 */
@Override
public String getValue() {
    String val = getRawValue();
    Filter xssFilter = FilterFactory.getXSSFilter(val.length() + 1);
    return xssFilter.filter(val);
}
Also used : Filter(org.olat.core.util.filter.Filter)

Example 14 with Filter

use of org.olat.core.util.filter.Filter in project openolat by klemens.

the class ResultsBuilder method recurseMattextForMediaURLFiltering.

private void recurseMattextForMediaURLFiltering(String baseUrl, Element el) {
    @SuppressWarnings("unchecked") List<Element> children = el.elements();
    for (int i = children.size(); i-- > 0; ) {
        Element child = children.get(i);
        recurseMattextForMediaURLFiltering(baseUrl, child);
        String name = child.getName();
        if ("mattext".equals(name)) {
            Object cdata = child.getData();
            if (cdata instanceof String) {
                String content = (String) cdata;
                Filter urlFilter = FilterFactory.getBaseURLToMediaRelativeURLFilter(baseUrl);
                String withBaseUrl = urlFilter.filter(content);
                if (!content.equals(withBaseUrl)) {
                    child.setText(withBaseUrl);
                }
            }
        }
    }
}
Also used : Filter(org.olat.core.util.filter.Filter) Element(org.dom4j.Element)

Example 15 with Filter

use of org.olat.core.util.filter.Filter in project openolat by klemens.

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)

Aggregations

Filter (org.olat.core.util.filter.Filter)32 StringOutput (org.olat.core.gui.render.StringOutput)4 Identity (org.olat.core.id.Identity)4 VFSContainer (org.olat.core.util.vfs.VFSContainer)4 Mattext (org.olat.ims.qti.editor.beecom.objects.Mattext)4 OlatDocument (org.olat.search.model.OlatDocument)4 XStream (com.thoughtworks.xstream.XStream)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 TreeSet (java.util.TreeSet)2 Element (org.dom4j.Element)2 Test (org.junit.Test)2 GlossaryItemManager (org.olat.core.commons.modules.glossary.GlossaryItemManager)2 WindowControl (org.olat.core.gui.control.WindowControl)2 User (org.olat.core.id.User)2 VFSContainerMapper (org.olat.core.util.vfs.VFSContainerMapper)2 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)2 ChoiceQuestion (org.olat.ims.qti.editor.beecom.objects.ChoiceQuestion)2 Control (org.olat.ims.qti.editor.beecom.objects.Control)2 Duration (org.olat.ims.qti.editor.beecom.objects.Duration)2