Search in sources :

Example 16 with MacroBlock

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)));
}
Also used : MacroBlock(org.xwiki.rendering.block.MacroBlock) Test(org.junit.Test)

Example 17 with MacroBlock

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));
}
Also used : MacroMarkerBlock(org.xwiki.rendering.block.MacroMarkerBlock) MacroBlock(org.xwiki.rendering.block.MacroBlock) WordBlock(org.xwiki.rendering.block.WordBlock) Block(org.xwiki.rendering.block.Block) MacroMarkerBlock(org.xwiki.rendering.block.MacroMarkerBlock) MacroBlock(org.xwiki.rendering.block.MacroBlock) Test(org.junit.Test)

Example 18 with MacroBlock

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;
}
Also used : XDOM(org.xwiki.rendering.block.XDOM) Block(org.xwiki.rendering.block.Block) MacroMarkerBlock(org.xwiki.rendering.block.MacroMarkerBlock) MetaDataBlock(org.xwiki.rendering.block.MetaDataBlock) MacroBlock(org.xwiki.rendering.block.MacroBlock) ParagraphBlock(org.xwiki.rendering.block.ParagraphBlock) MacroBlock(org.xwiki.rendering.block.MacroBlock)

Example 19 with MacroBlock

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);
}
Also used : MacroTransformationContext(org.xwiki.rendering.transformation.MacroTransformationContext) PrintRendererFactory(org.xwiki.rendering.renderer.PrintRendererFactory) MacroBlock(org.xwiki.rendering.block.MacroBlock) Test(org.junit.Test)

Example 20 with MacroBlock

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.
    }
}
Also used : LinkBlock(org.xwiki.rendering.block.LinkBlock) ResourceReference(org.xwiki.rendering.listener.reference.ResourceReference) MacroBlock(org.xwiki.rendering.block.MacroBlock)

Aggregations

MacroBlock (org.xwiki.rendering.block.MacroBlock)30 Test (org.junit.Test)14 MacroTransformationContext (org.xwiki.rendering.transformation.MacroTransformationContext)13 XDOM (org.xwiki.rendering.block.XDOM)12 DocumentReference (org.xwiki.model.reference.DocumentReference)9 Block (org.xwiki.rendering.block.Block)8 LinkBlock (org.xwiki.rendering.block.LinkBlock)7 MacroMarkerBlock (org.xwiki.rendering.block.MacroMarkerBlock)7 ResourceReference (org.xwiki.rendering.listener.reference.ResourceReference)7 HashMap (java.util.HashMap)5 DocumentAccessBridge (org.xwiki.bridge.DocumentAccessBridge)5 DocumentModelBridge (org.xwiki.bridge.DocumentModelBridge)4 MetaData (org.xwiki.rendering.listener.MetaData)4 ContextMacroParameters (org.xwiki.rendering.macro.context.ContextMacroParameters)4 MetaDataBlock (org.xwiki.rendering.block.MetaDataBlock)3 WordBlock (org.xwiki.rendering.block.WordBlock)3 MacroContentParser (org.xwiki.rendering.macro.MacroContentParser)3 MacroExecutionException (org.xwiki.rendering.macro.MacroExecutionException)3 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)2 ToString (org.suigeneris.jrcs.util.ToString)2