use of org.xwiki.rendering.block.MacroBlock in project xwiki-platform by xwiki.
the class MacroBlockDumperTest method testDumpMacroBlockWithoutSource.
@Test
public void testDumpMacroBlockWithoutSource() throws Exception {
byte[] dump1 = dumper.dump(new MacroBlock("macro", params, "content", false));
byte[] dump2 = dumper.dump(new MacroBlock("macro", params, "content", false));
assertThat(dump1, equalTo(dump2));
dump2 = dumper.dump(new MacroBlock("macro", params, "content", true));
assertThat(dump1, equalTo(dump2));
dump2 = dumper.dump(new MacroBlock("macro2", params, "content", false));
assertThat(dump1, not(equalTo(dump2)));
dump2 = dumper.dump(new MacroBlock("macro", params, false));
assertThat(dump1, not(equalTo(dump2)));
dump2 = dumper.dump(new MacroBlock("macro", params, "content2", false));
assertThat(dump1, not(equalTo(dump2)));
params.put("param", "value");
dump2 = dumper.dump(new MacroBlock("macro", params, "content", false));
assertThat(dump1, not(equalTo(dump2)));
dump1 = dumper.dump(new MacroBlock("macro", params, "content", false));
assertThat(dump1, equalTo(dump2));
params.put("param", "value2");
dump2 = dumper.dump(new MacroBlock("macro", params, "content", false));
assertThat(dump1, not(equalTo(dump2)));
params.clear();
params.put("param2", "value");
dump2 = dumper.dump(new MacroBlock("macro", params, "content", false));
assertThat(dump1, not(equalTo(dump2)));
params.clear();
params.put("param", "value");
params.put("param2", "value2");
dump2 = dumper.dump(new MacroBlock("macro", params, "content", false));
assertThat(dump1, not(equalTo(dump2)));
}
use of org.xwiki.rendering.block.MacroBlock in project xwiki-platform by xwiki.
the class MacroBlockDumperTest method testDumpMacroMarkerBlockWithoutSource.
@Test
public void testDumpMacroMarkerBlockWithoutSource() throws Exception {
byte[] dump1 = dumper.dump(new MacroBlock("macro", params, "content", false));
byte[] dump2 = dumper.dump(new MacroMarkerBlock("macro", params, "content", Collections.<Block>emptyList(), false));
assertThat(dump1, equalTo(dump2));
params.put("param", "value");
params.put("param2", "value2");
dump1 = dumper.dump(new MacroBlock("macro", params, "content", false));
dump2 = dumper.dump(new MacroMarkerBlock("macro", params, "content", Collections.<Block>emptyList(), false));
assertThat(dump1, equalTo(dump2));
}
use of org.xwiki.rendering.block.MacroBlock in project xwiki-platform by xwiki.
the class DefaultWikiMacro method prepareWikiMacroContent.
/**
* Clone and filter wiki macro content depending of the context.
*
* @param context the macro execution context
* @return the cleaned wiki macro content
*/
private XDOM prepareWikiMacroContent(MacroTransformationContext context) {
XDOM xdom = this.content.clone();
// blocks to behave as inline macros if the wiki macro is used inline.
if (context.isInline()) {
List<Block> children = xdom.getChildren();
if (children.size() > 0 && children.get(0) instanceof MacroBlock) {
MacroBlock old = (MacroBlock) children.get(0);
MacroBlock replacement = new MacroBlock(old.getId(), old.getParameters(), old.getContent(), true);
xdom.replaceChild(replacement, old);
}
}
return xdom;
}
use of org.xwiki.rendering.block.MacroBlock in project xwiki-platform by xwiki.
the class VelocityMacroIsolationTest method testVelocityMacroIsolation.
@Test
public void testVelocityMacroIsolation() throws Exception {
String expected = "beginDocument\n" + "beginParagraph\n" + "onSpecialSymbol [#]\n" + "onWord [testMacrosAreLocal]\n" + "onSpecialSymbol [(]\n" + "onSpecialSymbol [)]\n" + "endParagraph\n" + "endDocument";
VelocityMacroParameters params = new VelocityMacroParameters();
MacroTransformationContext context = new MacroTransformationContext();
context.setSyntax(Syntax.XWIKI_2_0);
context.setCurrentMacroBlock(new MacroBlock("velocity", Collections.<String, String>emptyMap(), false));
// Execute the velocity macro in the context of a first page
context.setId("page1");
this.velocityMacro.execute(params, "#macro(testMacrosAreLocal)mymacro#end", context);
// And then in the context of a second independent page
context.setId("page2");
PrintRendererFactory eventRendererFactory = getComponentManager().getInstance(PrintRendererFactory.class, "event/1.0");
assertBlocks(expected, this.velocityMacro.execute(params, "#testMacrosAreLocal()", context), eventRendererFactory);
}
use of org.xwiki.rendering.block.MacroBlock in project xwiki-platform by xwiki.
the class DefaultLinkedResourceHelper method setResourceType.
@Override
public void setResourceType(Block block, ResourceType newResourceType) {
if (block instanceof LinkBlock) {
LinkBlock linkBlock = (LinkBlock) block;
ResourceReference linkReference = linkBlock.getReference();
linkReference.setType(newResourceType);
} else if (block instanceof MacroBlock) {
// N/A yet.
}
}
Aggregations