use of org.xwiki.rendering.block.MacroMarkerBlock in project xwiki-platform by xwiki.
the class EmptyXDOMCheckerTest method checkWhenTwoMacroMarkerBlock.
@Test
public void checkWhenTwoMacroMarkerBlock() throws Exception {
List<Block> blocks = Arrays.asList(new MacroMarkerBlock("macro", Collections.emptyMap(), Collections.emptyList(), false), new MacroMarkerBlock("macro2", Collections.emptyMap(), Collections.emptyList(), false));
assertTrue(this.mocker.getComponentUnderTest().check(blocks));
}
use of org.xwiki.rendering.block.MacroMarkerBlock in project xwiki-platform by xwiki.
the class EmptyXDOMCheckerTest method checkWhenSingleMacroMarkerBlock.
@Test
public void checkWhenSingleMacroMarkerBlock() throws Exception {
List<Block> blocks = Collections.singletonList(new MacroMarkerBlock("macro", Collections.emptyMap(), Collections.emptyList(), false));
assertTrue(this.mocker.getComponentUnderTest().check(blocks));
}
use of org.xwiki.rendering.block.MacroMarkerBlock in project xwiki-platform by xwiki.
the class IncludeMacro method checkRecursiveInclusion.
/**
* Protect form recursive inclusion.
*
* @param currrentBlock the child block to check
* @param documentReference the reference of the document being included
* @throws MacroExecutionException recursive inclusion has been found
*/
private void checkRecursiveInclusion(Block currrentBlock, DocumentReference documentReference) throws MacroExecutionException {
// Check for parent context=new macros
Stack<Object> references = this.inclusionsBeingExecuted.get();
if (references != null && references.contains(documentReference)) {
throw new MacroExecutionException("Found recursive inclusion of document [" + documentReference + "]");
}
// Check for parent context=current macros
Block parentBlock = currrentBlock.getParent();
if (parentBlock != null) {
if (parentBlock instanceof MacroMarkerBlock) {
MacroMarkerBlock parentMacro = (MacroMarkerBlock) parentBlock;
if (isRecursive(parentMacro, documentReference)) {
throw new MacroExecutionException("Found recursive inclusion of document [" + documentReference + "]");
}
}
checkRecursiveInclusion(parentBlock, documentReference);
}
}
use of org.xwiki.rendering.block.MacroMarkerBlock in project xwiki-platform by xwiki.
the class NestedScriptMacroValidatorTest method buildContext.
/**
* Build a chain of nested macros ({@link MacroMarkerBlock} blocks) and put them into a macro transformation
* context. The chain will be the only child of a top level XDOM, the last child will be the current
* {@link MacroBlock}.
*
* @param chain list of nested macro names (starting with parent)
* @return an initialized macro transformation context
*/
private MacroTransformationContext buildContext(String... chain) {
MacroTransformationContext context = new MacroTransformationContext();
if (chain == null || chain.length < 1) {
context.setXDOM(new XDOM(new LinkedList<Block>()));
return context;
}
Map<String, String> parameters = new HashMap<String, String>();
MacroBlock child = new MacroBlock(chain[chain.length - 1], parameters, false);
Block current = child;
for (int i = chain.length - 2; i >= 0; i--) {
Block parent = new MacroMarkerBlock(chain[i], parameters, Collections.singletonList(current), false);
current = parent;
}
XDOM root = new XDOM(Collections.singletonList(current));
context.setXDOM(root);
context.setCurrentMacroBlock(child);
return context;
}
use of org.xwiki.rendering.block.MacroMarkerBlock in project xwiki-platform by xwiki.
the class IncludeMacroTest method testIncludeMacroWithRecursiveIncludeContextCurrent.
@Test
public void testIncludeMacroWithRecursiveIncludeContextCurrent() throws Exception {
this.includeMacro.setDocumentAccessBridge(mockSetup.bridge);
final MacroTransformationContext macroContext = createMacroTransformationContext("wiki:space.page", false);
// Add an Include Macro MarkerBlock as a parent of the include Macro block since this is what would have
// happened if an Include macro is included in another Include macro.
final MacroMarkerBlock includeMacroMarker = new MacroMarkerBlock("include", Collections.singletonMap("reference", "space.page"), Collections.<Block>singletonList(macroContext.getCurrentMacroBlock()), false);
getMockery().checking(new Expectations() {
{
allowing(mockDocumentReferenceResolver).resolve("wiki:space.page", macroContext.getCurrentMacroBlock());
will(returnValue(new DocumentReference("wiki", "space", "page")));
allowing(mockDocumentReferenceResolver).resolve("space.page", includeMacroMarker);
will(returnValue(new DocumentReference("wiki", "space", "page")));
}
});
IncludeMacroParameters parameters = new IncludeMacroParameters();
parameters.setReference("wiki:space.page");
parameters.setContext(Context.CURRENT);
try {
this.includeMacro.execute(parameters, null, macroContext);
Assert.fail("The include macro hasn't checked the recursive inclusion");
} catch (MacroExecutionException expected) {
if (!expected.getMessage().startsWith("Found recursive inclusion")) {
throw expected;
}
}
}
Aggregations