/** * @return the XDOM corresponding to the document's string content. */ public XDOM getXDOM() { if (this.xdom == null) { try { this.xdom = parseContent(getContent()); } catch (XWikiException e) { LOG.error("Failed to parse document content to XDOM", e); } } return this.xdom.clone(); }
XDOM transformedXDOM = xdom.clone();
/** * 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() { XDOM xdom = this.wikimacro.getContent().clone(); // Macro code segment is always parsed into a separate xdom document. Now if this code segment starts with // another macro block, it will always be interpreted as a block macro regardless of the current wiki macro's // context (because as far as the nested macro is concerned, it starts on a new line). This will introduce // unnecessary paragraph elements when the wiki macro is used inline, so we need to force such opening macro // blocks to behave as inline macros if the wiki macro is used inline. if (this.inline) { List<Block> children = xdom.getChildren(); if (!children.isEmpty() && 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; }
@Override public XDOM createView(ResourceReference reference, Map<String, ?> parameters) throws Exception { OfficeDocumentView view; if (reference.getType().equals(ResourceType.ATTACHMENT) || reference.getType().equals(ResourceType.UNKNOWN)) { AttachmentReference attachmentReference = this.attachmentResolver.resolve(reference.getReference()); view = getView(reference, attachmentReference, parameters); } else { view = getView(reference, parameters); } // We have to clone the cached XDOM to protect it from the rendering transformations. For instance, macro // transformations must be executed even when the XDOM is taken from the cache. return view.getXDOM().clone(); }
XDOM transformedBlock = this.xdom.clone();