@Test public void executeWhenSameIdAndDifferentContent() throws Exception { String expected = "beginDocument\n" + "beginMacroMarkerStandalone [velocity] [] [$var]\n" + "beginParagraph\n" + "onWord [content]\n" + "endParagraph\n" + "endMacroMarkerStandalone [velocity] [] [$var]\n" + "endDocument"; CacheMacroParameters params = new CacheMacroParameters(); params.setId("uniqueid"); MacroTransformationContext context = createMacroTransformationContext(); VelocityManager velocityManager = getComponentManager().getInstance(VelocityManager.class); StringWriter writer = new StringWriter(); velocityManager.getVelocityEngine().evaluate(velocityManager.getVelocityContext(), writer, "template", "#set ($var = 'content')"); List<Block> result = this.cacheMacro.execute(params, "{{velocity}}$var{{/velocity}}", context); assertBlocks(expected, result, this.rendererFactory); result = this.cacheMacro.execute(params, "whatever here...", context); assertBlocks(expected, result, this.rendererFactory); }
@Override public List<Block> execute(CacheMacroParameters parameters, String content, MacroTransformationContext context) throws MacroExecutionException { String cacheKey; if (parameters.getId() != null) { WikiPrinter printer = new DefaultWikiPrinter(); this.plainTextBlockRenderer.render(this.contentParser.parse(parameters.getId(), context, true, false), printer); cacheKey = printer.toString(); } else { cacheKey = content; } Cache<List<Block>> contentCache = getContentCache(parameters.getTimeToLive(), parameters.getMaxEntries()); List<Block> result = contentCache.get(cacheKey); if (result == null) { result = this.contentParser.parse(content, context, true, context.isInline()).getChildren(); contentCache.set(cacheKey, result); } return result; }
CacheMacro extends AbstractMacro<CacheMacroParameters> { @Override public List<Block> execute(CacheMacroParameters parameters, String content, MacroTransformationContext context) throws MacroExecutionException { String cacheKey; if (parameters.getId() != null) { WikiPrinter printer = new DefaultWikiPrinter(); this.plainTextBlockRenderer.render(this.contentParser.parse(parameters.getId(), context, true, false), printer); cacheKey = printer.toString(); } else { cacheKey = content; } Cache<List<Block>> contentCache = getContentCache(parameters.getTimeToLive(), parameters.getMaxEntries()); List<Block> result = contentCache.get(cacheKey); if (result == null) { result = this.contentParser.parse(content, context, true, context.isInline()).getChildren(); contentCache.set(cacheKey, result); } return result; } }
CacheMacro extends AbstractMacro<CacheMacroParameters> { @Override public List<Block> execute(CacheMacroParameters parameters, String content, MacroTransformationContext context) throws MacroExecutionException { String cacheKey; if (parameters.getId() != null) { WikiPrinter printer = new DefaultWikiPrinter(); this.plainTextBlockRenderer.render(this.contentParser.parse(parameters.getId(), context, true, false), printer); cacheKey = printer.toString(); } else { cacheKey = content; } Cache<List<Block>> contentCache = getContentCache(parameters.getTimeToLive(), parameters.getMaxEntries()); List<Block> result = contentCache.get(cacheKey); if (result == null) { result = this.contentParser.parse(content, context, true, context.isInline()).getChildren(); contentCache.set(cacheKey, result); } return result; } CacheMacro(); }
CacheMacro extends AbstractMacro<CacheMacroParameters> { @Override public List<Block> execute(CacheMacroParameters parameters, String content, MacroTransformationContext context) throws MacroExecutionException { String cacheKey; if (parameters.getId() != null) { WikiPrinter printer = new DefaultWikiPrinter(); this.plainTextBlockRenderer.render(this.contentParser.parse(parameters.getId(), context, true, false), printer); cacheKey = printer.toString(); } else { cacheKey = content; } Cache<List<Block>> contentCache = getContentCache(parameters.getTimeToLive(), parameters.getMaxEntries()); List<Block> result = contentCache.get(cacheKey); if (result == null) { result = this.contentParser.parse(content, context, true, context.isInline()).getChildren(); contentCache.set(cacheKey, result); } return result; } CacheMacro(); @Override boolean supportsInlineMode(); @Override List<Block> execute(CacheMacroParameters parameters, String content, MacroTransformationContext context); }
CacheMacro extends AbstractMacro<CacheMacroParameters> { @Override public List<Block> execute(CacheMacroParameters parameters, String content, MacroTransformationContext context) throws MacroExecutionException { String cacheKey; if (parameters.getId() != null) { WikiPrinter printer = new DefaultWikiPrinter(); this.plainTextBlockRenderer.render(this.contentParser.parse(parameters.getId(), context, true, false), printer); cacheKey = printer.toString(); } else { cacheKey = content; } Cache<List<Block>> contentCache = getContentCache(parameters.getTimeToLive(), parameters.getMaxEntries()); List<Block> result = contentCache.get(cacheKey); if (result == null) { result = this.contentParser.parse(content, context, true, context.isInline()).getChildren(); contentCache.set(cacheKey, result); } return result; } CacheMacro(); @Override boolean supportsInlineMode(); @Override List<Block> execute(CacheMacroParameters parameters, String content, MacroTransformationContext context);  }