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> </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 écrire. Et encore un ou deux.</p></blockquote></div><p>Et une réponse avec citation incorporée</p>";
String output = filter.filter(text);
assertTrue(" Et une réponse avec citation incorporée".equals(output));
}
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();
}
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);
}
}
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>");
}
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);
}
Aggregations