Search in sources :

Example 26 with Filter

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

the class WordCountTest method testCleanMessage.

@Test
public void testCleanMessage() {
    Filter filter = new QuoteAndTagFilter();
    String text = "<p>&nbsp;</p><div class=\"o_quote_wrapper\"><div class=\"o_quote_author mceNonEditable\">Am 23.11.09 12:29 hat OLAT Administrator geschrieben:</div><blockquote class=\"o_quote\"><p>Quelques mots que je voulais &eacute;crire. Et encore un ou deux.</p></blockquote></div><p>Et une r&eacute;ponse avec citation incorpor&eacute;e</p>";
    String output = filter.filter(text);
    assertTrue("  Et une réponse avec citation incorporée".equals(output));
}
Also used : Filter(org.olat.core.util.filter.Filter) Test(org.junit.Test)

Example 27 with Filter

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

the class PortfolioMapDocument method createDocument.

public static Document createDocument(SearchResourceContext searchResourceContext, PortfolioStructure map) {
    PortfolioMapDocument document = new PortfolioMapDocument();
    if (map instanceof EPAbstractMap) {
        EPAbstractMap abstractMap = (EPAbstractMap) map;
        if (abstractMap.getGroups() != null) {
            List<Identity> identities = policyManager.getOwners(abstractMap);
            StringBuilder authors = new StringBuilder();
            for (Identity identity : identities) {
                if (authors.length() > 0) {
                    authors.append(", ");
                }
                User user = identity.getUser();
                authors.append(user.getProperty(UserConstants.FIRSTNAME, null)).append(' ').append(user.getProperty(UserConstants.LASTNAME, null));
            }
            document.setAuthor(authors.toString());
        }
        document.setCreatedDate(abstractMap.getCreationDate());
    }
    Filter filter = FilterFactory.getHtmlTagAndDescapingFilter();
    document.setTitle(map.getTitle());
    document.setDescription(filter.filter(map.getDescription()));
    StringBuilder sb = new StringBuilder();
    getContent(map, searchResourceContext, sb, filter);
    document.setContent(sb.toString());
    document.setResourceUrl(searchResourceContext.getResourceUrl());
    document.setDocumentType(searchResourceContext.getDocumentType());
    document.setCssIcon("o_ep_icon");
    document.setParentContextType(searchResourceContext.getParentContextType());
    document.setParentContextName(searchResourceContext.getParentContextName());
    if (log.isDebug())
        log.debug(document.toString());
    return document.getLuceneDocument();
}
Also used : EPAbstractMap(org.olat.portfolio.model.structel.EPAbstractMap) User(org.olat.core.id.User) Filter(org.olat.core.util.filter.Filter) Identity(org.olat.core.id.Identity)

Example 28 with Filter

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

the class TextArtefactDetailsController method init.

private void init(UserRequest ureq) {
    String artFulltextContent = ePFMgr.getArtefactFullTextContent(artefact);
    if (!readOnlyMode) {
        // prepare an edit link
        String fulltext = FilterFactory.getHtmlTagAndDescapingFilter().filter(artFulltextContent);
        fulltext = StringHelper.xssScan(fulltext);
        fulltext = Formatter.truncate(fulltext, 50);
        editBtn = LinkFactory.createCustomLink("text.edit.link", "edit", fulltext, Link.NONTRANSLATED, vC, this);
        editBtn.setIconRightCSS("o_icon o_icon_inline_editable");
    } else {
        // register a mapper to deliver uploaded media files
        final VFSContainer artefactFolder = ePFMgr.getArtefactContainer(artefact);
        String mapperBase = registerMapper(ureq, new VFSContainerMapper(artefactFolder));
        Filter urlFilter = FilterFactory.getBaseURLToMediaRelativeURLFilter(mapperBase);
        String wrappedText = urlFilter.filter(artFulltextContent);
        vC.contextPut("text", wrappedText);
    }
}
Also used : VFSContainerMapper(org.olat.core.util.vfs.VFSContainerMapper) Filter(org.olat.core.util.filter.Filter) VFSContainer(org.olat.core.util.vfs.VFSContainer)

Example 29 with Filter

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

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)

Example 30 with Filter

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

the class ItemMetadataFormController method formOK.

/**
 * @see org.olat.core.gui.components.form.flexible.impl.FormBasicController#formOK(org.olat.core.gui.UserRequest)
 */
protected void formOK(UserRequest ureq) {
    // Fire Change Event
    String newTitle = title.getValue();
    String oldTitle = item.getTitle();
    boolean hasTitleChange = newTitle != null && !newTitle.equals(oldTitle);
    // trust authors, don't do XSS filtering
    String newObjectives = desc.getRawValue();
    // Remove any conditional comments due to strange behavior in test (OLAT-4518)
    Filter conditionalCommentFilter = FilterFactory.getConditionalHtmlCommentsFilter();
    newObjectives = conditionalCommentFilter.filter(newObjectives);
    String oldObjectives = item.getObjectives();
    boolean hasObjectivesChange = newObjectives != null && !newObjectives.equals(oldObjectives);
    NodeBeforeChangeEvent nce = new NodeBeforeChangeEvent();
    if (hasTitleChange) {
        nce.setNewTitle(newTitle);
    }
    if (hasObjectivesChange) {
        nce.setNewObjectives(newObjectives);
    }
    if (hasTitleChange || hasObjectivesChange) {
        // create a memento first
        nce.setItemIdent(item.getIdent());
        nce.setQuestionIdent(item.getQuestion().getQuestion().getId());
        fireEvent(ureq, nce);
    }
    // Update item
    item.setTitle(newTitle);
    // trust authors, don't to XSS filtering
    item.setObjectives(newObjectives);
    Question q = item.getQuestion();
    if (layout != null && q instanceof ChoiceQuestion) {
        ((ChoiceQuestion) q).setFlowLabelClass("h".equals(layout.getSelectedKey()) ? ChoiceQuestion.BLOCK : ChoiceQuestion.LIST);
    }
    if (!isSurvey && !isRestrictedEditMode) {
        q.setShuffle(shuffle.getSelected() == 0);
        Control itemControl = item.getItemcontrols().get(0);
        itemControl.setFeedback(itemControl.getFeedback() == Control.CTRL_UNDEF ? Control.CTRL_NO : itemControl.getFeedback());
        itemControl.setHint(showHints.getSelected() == 0 ? Control.CTRL_YES : Control.CTRL_NO);
        itemControl.setSolution(showSolution.getSelected() == 0 ? Control.CTRL_YES : Control.CTRL_NO);
        String hintRawValue = hint.getRawValue();
        // trust authors, don't to XSS filtering
        q.setHintText(conditionalCommentFilter.filter(hintRawValue));
        String solutionRawValue = solution.getRawValue();
        // trust authors, don't to XSS filtering
        q.setSolutionText(conditionalCommentFilter.filter(solutionRawValue));
        if (limitTime.getSelectedKey().equals("y")) {
            item.setDuration(new Duration(1000 * timeSec.getIntValue() + 1000 * 60 * timeMin.getIntValue()));
        } else {
            item.setDuration(null);
        }
        if (limitAttempts.getSelectedKey().equals("y")) {
            item.setMaxattempts(attempts.getIntValue());
        } else {
            item.setMaxattempts(0);
        }
    }
    fireEvent(ureq, Event.DONE_EVENT);
}
Also used : WindowControl(org.olat.core.gui.control.WindowControl) Control(org.olat.ims.qti.editor.beecom.objects.Control) Filter(org.olat.core.util.filter.Filter) ChoiceQuestion(org.olat.ims.qti.editor.beecom.objects.ChoiceQuestion) Question(org.olat.ims.qti.editor.beecom.objects.Question) ChoiceQuestion(org.olat.ims.qti.editor.beecom.objects.ChoiceQuestion) Duration(org.olat.ims.qti.editor.beecom.objects.Duration)

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