public void handleMatch(StringBuffer buffer, MatchResult result, FilterContext context) { // Remove the content inside the code macro. It'll be put back in CodeRestoreFilter // We save the content in the Filter context so that it can restored later on. // Important: This filter is called for all code macros on the page before the restore // filter is called. Thus we need to save the removed content for ALL code macros and this // is why we're using a LinkedList inside the CODE_MACRO_CONTENT context key. LinkedList contentList = (LinkedList) context.getRenderContext().get(CODE_MACRO_CONTENT); if (contentList == null) { contentList = new LinkedList(); context.getRenderContext().set(CODE_MACRO_CONTENT, contentList); } contentList.add(result.group(4)); buffer.append(result.group(1)); buffer.append("{code}"); } }
public String render(String content, XWikiDocument contentdoc, XWikiDocument contextdoc, XWikiContext context) { Util util = context.getUtil(); // Remove the content that is inside "{pre}" PreTagSubstitution preTagSubst = new PreTagSubstitution(util, isRemovePre()); content = preTagSubst.substitute(content); RenderContext rcontext = (RenderContext) context.get("rcontext"); if (rcontext == null) { rcontext = new BaseRenderContext(); // This is needed as otherwise some macros throw exceptions rcontext.setParameters(new HashMap()); rcontext.set("xcontext", context); } if (rcontext.getRenderEngine() == null) { XWikiRadeoxRenderEngine radeoxengine = new XWikiRadeoxRenderEngine(this.initialRenderContext, this.filterPipe, context); rcontext.setRenderEngine(radeoxengine); } // If global placeholders are not enabled, then use local placeholders. boolean useLocalPlaceholders = !Utils.arePlaceholdersEnabled(context); if (useLocalPlaceholders) { Utils.enablePlaceholders(context); } String result = rcontext.getRenderEngine().render(content, rcontext); if (useLocalPlaceholders) { result = Utils.replacePlaceholders(result, context); Utils.disablePlaceholders(context); } return preTagSubst.insertNonWikiText(result); }