Search in sources :

Example 21 with Filter

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

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

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

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

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

the class GlossaryManagerImpl method getIndexerDocument.

/**
 * Creates a lucene index document for this glossary
 *
 * @param repositoryEntry
 * @param searchResourceContext
 * @return Document the index document
 */
@Override
public Document getIndexerDocument(RepositoryEntry repositoryEntry, SearchResourceContext searchResourceContext) {
    GlossaryItemManager gIMgr = GlossaryItemManager.getInstance();
    VFSContainer glossaryFolder = getGlossaryRootFolder(repositoryEntry.getOlatResource());
    VFSLeaf glossaryFile = gIMgr.getGlossaryFile(glossaryFolder);
    if (glossaryFile == null) {
        return null;
    }
    String glossaryContent = gIMgr.getGlossaryContent(glossaryFolder);
    // strip all html tags
    Filter htmlTagsFilter = FilterFactory.getHtmlTagsFilter();
    glossaryContent = htmlTagsFilter.filter(glossaryContent);
    // create standard olat index document with this data
    OlatDocument glossaryDocument = new OlatDocument();
    if (repositoryEntry.getInitialAuthor() != null) {
        glossaryDocument.setAuthor(repositoryEntry.getInitialAuthor());
    }
    if (repositoryEntry.getDisplayname() != null) {
        glossaryDocument.setTitle(repositoryEntry.getDisplayname());
    }
    if (repositoryEntry.getDescription() != null) {
        glossaryDocument.setDescription(htmlTagsFilter.filter(repositoryEntry.getDescription()));
    }
    glossaryDocument.setContent(glossaryContent);
    glossaryDocument.setCreatedDate(repositoryEntry.getCreationDate());
    glossaryDocument.setLastChange(new Date(glossaryFile.getLastModified()));
    glossaryDocument.setResourceUrl(searchResourceContext.getResourceUrl());
    glossaryDocument.setDocumentType(searchResourceContext.getDocumentType());
    glossaryDocument.setCssIcon("o_FileResource-GLOSSARY_icon");
    return glossaryDocument.getLuceneDocument();
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) OlatDocument(org.olat.search.model.OlatDocument) Filter(org.olat.core.util.filter.Filter) VFSContainer(org.olat.core.util.vfs.VFSContainer) GlossaryItemManager(org.olat.core.commons.modules.glossary.GlossaryItemManager) Date(java.util.Date)

Example 24 with Filter

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

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

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

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