use of org.xwiki.rendering.renderer.printer.DefaultWikiPrinter in project xwiki-platform by xwiki.
the class DefaultNotificationRSSRenderer method renderNotification.
@Override
public SyndEntry renderNotification(CompositeEvent eventNotification) throws NotificationException {
SyndEntry entry = new SyndEntryImpl();
SyndContent entryDescription = new SyndContentImpl();
// The users contained in the CompositeEvent are already stored in a Set, they are therefore necessarily unique
List<SyndPerson> eventAuthors = new ArrayList<SyndPerson>();
// Convert every author of the CompositeEvent to a SyndPerson and add it to the new entry
for (DocumentReference author : eventNotification.getUsers()) {
SyndPerson person = new SyndPersonImpl();
person.setName(author.getName());
eventAuthors.add(person);
}
entry.setAuthors(eventAuthors);
// Define the GUID of the event
entry.setUri(String.join("-", eventNotification.getEventIds()));
// Set the entry title
entry.setTitle(this.contextualLocalizationManager.getTranslationPlain(eventNotification.getEvents().get(0).getTitle(), eventNotification.getEvents().get(0).getDocumentTitle()));
// Render the description (the main part) of the feed entry
try {
this.scriptContextManager.getCurrentScriptContext().setAttribute(COMPOSITE_EVENT_BUILDING_NAME, eventNotification, ScriptContext.ENGINE_SCOPE);
// Try to get a template associated with the composite event
Template template = this.templateManager.getTemplate(String.format("notification/rss/%s.vm", eventNotification.getType().replaceAll("\\/", ".")));
// If no template is found, fallback on the default one
if (template == null) {
template = this.templateManager.getTemplate("notification/rss/default.vm");
}
XDOM descriptionXDOM = this.templateManager.execute(template);
WikiPrinter printer = new DefaultWikiPrinter();
blockRenderer.render(descriptionXDOM, printer);
// Add the description to the entry
entryDescription.setType("text/html");
entryDescription.setValue(printer.toString());
entry.setDescription(entryDescription);
} catch (Exception e) {
throw new NotificationException(String.format("Unable to render the description of the event [%s].", eventNotification), e);
} finally {
this.scriptContextManager.getCurrentScriptContext().removeAttribute(COMPOSITE_EVENT_BUILDING_NAME, ScriptContext.ENGINE_SCOPE);
}
// Dates are sorted in descending order in a CompositeEvent, the first date is then the most recent one
entry.setUpdatedDate(eventNotification.getDates().get(0));
return entry;
}
use of org.xwiki.rendering.renderer.printer.DefaultWikiPrinter in project xwiki-platform by xwiki.
the class DefaultWikiMacroTest method testExecuteWhenWikiMacroBinding.
@Test
public void testExecuteWhenWikiMacroBinding() throws Exception {
registerWikiMacro("wikimacrobindings", "{{groovy}}" + "print xcontext.macro.doc" + "{{/groovy}}");
Converter converter = getComponentManager().getInstance(Converter.class);
DefaultWikiPrinter printer = new DefaultWikiPrinter();
converter.convert(new StringReader("{{wikimacrobindings param1=\"value2\" param2=\"value2\"/}}"), Syntax.XWIKI_2_0, Syntax.XHTML_1_0, printer);
// Note: We're using XHTML as the output syntax just to make it easy for asserting.
Assert.assertEquals("<p>" + this.wikiMacroDocument.toString() + "</p>", printer.toString());
}
use of org.xwiki.rendering.renderer.printer.DefaultWikiPrinter in project xwiki-platform by xwiki.
the class DefaultWikiMacroTest method testExecuteWhenWikiRequiringPRAfterDropPermission.
@Test
public void testExecuteWhenWikiRequiringPRAfterDropPermission() throws Exception {
registerWikiMacro("wikimacrobindings", "{{groovy}}" + "print xcontext.macro.doc" + "{{/groovy}}");
Converter converter = getComponentManager().getInstance(Converter.class);
DefaultWikiPrinter printer = new DefaultWikiPrinter();
getContext().dropPermissions();
this.wikiMacroDocument.newDocument(getContext()).dropPermissions();
converter.convert(new StringReader("{{wikimacrobindings param1=\"value2\" param2=\"value2\"/}}"), Syntax.XWIKI_2_0, Syntax.XHTML_1_0, printer);
// Note: We're using XHTML as the output syntax just to make it easy for asserting.
Assert.assertEquals("<p>" + this.wikiMacroDocument.toString() + "</p>", printer.toString());
Assert.assertTrue("Wiki macro did not properly restord persmission dropping", getContext().hasDroppedPermissions());
}
use of org.xwiki.rendering.renderer.printer.DefaultWikiPrinter in project xwiki-platform by xwiki.
the class DefaultWikiMacroTest method testExecuteWhenInnerMacro.
/**
* Check that macro used inside wiki macro are executed as part of the document.
*/
@Test
public void testExecuteWhenInnerMacro() throws Exception {
registerWikiMacro("wikimacro1", "{{toc/}}", Syntax.XWIKI_2_0);
getMockery().checking(new Expectations() {
{
DocumentResourceReference reference = new DocumentResourceReference(null);
reference.setAnchor("Hheading");
allowing(mockWikiModel).getDocumentViewURL(reference);
will(returnValue("url"));
}
});
Converter converter = getComponentManager().getInstance(Converter.class);
DefaultWikiPrinter printer = new DefaultWikiPrinter();
converter.convert(new StringReader("= heading\n\n{{wikimacro1 param1=\"value1\" param2=\"value2\"/}}"), Syntax.XWIKI_2_0, Syntax.XHTML_1_0, printer);
// Note: We're using XHTML as the output syntax just to make it easy for asserting.
Assert.assertEquals("<h1 id=\"Hheading\" class=\"wikigeneratedid\"><span>heading</span></h1>" + "<ul><li><span class=\"wikilink\"><a href=\"#Hheading\">heading</a></span></li></ul>", printer.toString());
}
use of org.xwiki.rendering.renderer.printer.DefaultWikiPrinter in project xwiki-platform by xwiki.
the class DefaultWikiMacroTest method testExecuteWhenInlineAndWithMacro.
/**
* When a wiki macro is used in inline mode and its code starts with a macro, that nested macro is made inline. In
* other words, the nested macro should not generate extra paragraph elements.
*/
@Test
public void testExecuteWhenInlineAndWithMacro() throws Exception {
registerWikiMacro("wikimacro1", "This is **bold**", Syntax.XWIKI_2_0);
registerWikiMacro("wikimacro2", "{{wikimacro1 param1=\"v1\" param2=\"v2\"/}}", Syntax.XWIKI_2_0);
Converter converter = getComponentManager().getInstance(Converter.class);
DefaultWikiPrinter printer = new DefaultWikiPrinter();
// Note: We're putting the macro after the "Hello" text to force it as an inline macro.
converter.convert(new StringReader("Hello {{wikimacro2 param1=\"value1\" param2=\"value2\"/}}"), Syntax.XWIKI_2_0, Syntax.XHTML_1_0, printer);
// Note: We're using XHTML as the output syntax just to make it easy for asserting.
Assert.assertEquals("<p>Hello This is <strong>bold</strong></p>", printer.toString());
}
Aggregations