Search in sources :

Example 31 with Filter

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

the class MaterialFormController method formOK.

/**
 * @see org.olat.core.gui.components.form.flexible.impl.FormBasicController#formOK(org.olat.core.gui.UserRequest)
 */
@Override
protected void formOK(UserRequest ureq) {
    // trust authors, don't to XSS filtering
    String newHtml = richText.getRawValue();
    // the text fragment is saved in a cdata, remove cdata from movie plugin
    newHtml = newHtml.replace("// <![CDATA[", "").replace("// ]]>", "");
    // Use explicit return which create a P tag if you want a line break.
    if (newHtml.startsWith("<br />") && newHtml.length() > 6)
        newHtml = newHtml.substring(6);
    if (newHtml.endsWith("<br />") && newHtml.length() > 6)
        newHtml = newHtml.substring(0, newHtml.length() - 6);
    // Remove any conditional comments due to strange behavior in test (OLAT-4518)
    Filter conditionalCommentFilter = FilterFactory.getConditionalHtmlCommentsFilter();
    newHtml = conditionalCommentFilter.filter(newHtml);
    // 
    if (htmlContent.equals(newHtml)) {
        // No changes. Cancel editing.
        fireEvent(ureq, Event.CANCELLED_EVENT);
    } else {
        if (isRestrictedEditMode) {
            // In restricted edit mode, if the content has changed, write a memento
            // (by firing the before change event).
            QTIObjectBeforeChangeEvent qobce = new QTIObjectBeforeChangeEvent();
            qobce.init(mat.getId(), htmlContent);
            fireEvent(ureq, qobce);
        }
        // Collect the content of all MatElements in a single text element
        // (text/html) and save it (for Material objects with multiple elements
        // such as images, videos, text, breaks, etc. this can be regarded as
        // "lazy migration" to the new rich text style).
        Mattext textHtml = new Mattext(newHtml);
        // A single text/html element will be left over.
        List<QTIObject> elements = new ArrayList<QTIObject>(1);
        elements.add(textHtml);
        mat.setElements(elements);
        fireEvent(ureq, Event.DONE_EVENT);
    }
}
Also used : Mattext(org.olat.ims.qti.editor.beecom.objects.Mattext) QTIObject(org.olat.ims.qti.editor.beecom.objects.QTIObject) Filter(org.olat.core.util.filter.Filter) ArrayList(java.util.ArrayList)

Example 32 with Filter

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

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)

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