Search in sources :

Example 1 with Filter

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

the class CSVToQuestionConverter method createMattext.

private Mattext createMattext(String text) {
    // text is already in a CDATA
    text = text.replace("// <![CDATA[", "").replace("// ]]>", "");
    // Use explicit return which create a P tag if you want a line break.
    if (text.startsWith("<br />") && text.length() > 6)
        text = text.substring(6);
    if (text.endsWith("<br />") && text.length() > 6)
        text = text.substring(0, text.length() - 6);
    // Remove any conditional comments due to strange behavior in test (OLAT-4518)
    Filter conditionalCommentFilter = FilterFactory.getConditionalHtmlCommentsFilter();
    text = conditionalCommentFilter.filter(text);
    Mattext mattext = new Mattext(text);
    return mattext;
}
Also used : Mattext(org.olat.ims.qti.editor.beecom.objects.Mattext) Filter(org.olat.core.util.filter.Filter)

Example 2 with Filter

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

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 3 with Filter

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

the class FeedViewHelper method getItemContentForBrowser.

/**
 * The item content with media file paths that are dispatchable by
 * a FeedMediaDispatcher.
 *
 * @param item
 * @return
 */
public String getItemContentForBrowser(Item item) {
    String itemContent = "";
    if (item != null) {
        String content = item.getContent();
        if (content != 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(content.length() + 1);
                itemContent = xssFilter.filter(content);
            } else {
                // Add relative media base to media elements to display internal media
                // files
                String basePath = baseUri + "/" + item.getGuid();
                Filter mediaUrlFilter = FilterFactory.getBaseURLToMediaRelativeURLFilter(basePath);
                itemContent = mediaUrlFilter.filter(content);
            }
        }
    }
    return itemContent;
}
Also used : Filter(org.olat.core.util.filter.Filter)

Example 4 with Filter

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

the class BlogArtefactHandler method getContent.

@Override
protected void getContent(AbstractArtefact artefact, StringBuilder sb, SearchResourceContext context, EPFrontendManager ePFManager) {
    String content = ePFManager.getArtefactFullTextContent(artefact);
    if (content != null) {
        try {
            XStream xstream = XStreamHelper.createXStreamInstance();
            xstream.alias("item", ItemImpl.class);
            ItemImpl item = (ItemImpl) xstream.fromXML(content);
            String mapperBaseURL = "";
            Filter mediaUrlFilter = FilterFactory.getBaseURLToMediaRelativeURLFilter(mapperBaseURL);
            sb.append(mediaUrlFilter.filter(item.getDescription())).append(" ").append(mediaUrlFilter.filter(item.getContent()));
        } catch (Exception e) {
            log.warn("Cannot read an artefact of type blog while indexing", e);
        }
    }
}
Also used : Filter(org.olat.core.util.filter.Filter) XStream(com.thoughtworks.xstream.XStream) ItemImpl(org.olat.modules.webFeed.model.ItemImpl)

Example 5 with Filter

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

the class Mattext method render.

/**
 * @see org.olat.ims.qti.container.qtielements.QTIElement#render(StringBuilder, RenderInstructions)
 */
@Override
public void render(StringBuilder buffer, RenderInstructions ri) {
    buffer.append("<span class=\"o_qti_item_mattext\">");
    // Add static media base URI to render media elements inline
    Filter urlFilter = FilterFactory.getBaseURLToMediaRelativeURLFilter((String) ri.get(RenderInstructions.KEY_STATICS_PATH));
    String withBaseUrl = urlFilter.filter(content);
    // Add latex fomulas formatter
    withBaseUrl = Formatter.formatLatexFormulas(withBaseUrl);
    // 
    buffer.append(withBaseUrl);
    buffer.append("</span>");
}
Also used : Filter(org.olat.core.util.filter.Filter)

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