public XDOM getXDOM() { return new XDOM(generateListFromStack(), this.idGenerator); }
public XDOM getXDOM() { return new XDOM(generateListFromStack()); }
@Override public XDOM parse(Reader source) throws ParseException { Reader pushBackReader = getPushBackReader(source); if (pushBackReader != null) { return super.parse(pushBackReader); } else { return new XDOM(Collections.emptyList()); } }
@Override public XDOM parse(Reader source) throws ParseException { return new XDOM(highlight(getSyntaxId(), source)); }
@Override public XDOM parse(String content, MacroTransformationContext macroContext, boolean transform, MetaData metadata, boolean inline) throws MacroExecutionException { // If the content is empty return an empty list if (StringUtils.isEmpty(content)) { return new XDOM(Collections.<Block>emptyList(), metadata != null ? metadata : MetaData.EMPTY); } Syntax syntax = getCurrentSyntax(macroContext); // If there's no syntax specified in the Transformation throw an error if (syntax == null) { throw new MacroExecutionException("Invalid Transformation: missing Syntax"); } return createXDOM(content, macroContext, transform, metadata, inline, syntax); }
/** * @param blocks the Blocks to assert * @param factory the Renderer Factory to use to serialize the passed Block * @return The serialized block. * @since 4.2M1 */ private static String render(List<Block> blocks, PrintRendererFactory factory) { // Assert the result by parsing it through the EventsRenderer to generate easily // assertable events. XDOM dom = new XDOM(blocks); WikiPrinter printer = new DefaultWikiPrinter(); PrintRenderer eventRenderer = factory.createRenderer(printer); dom.traverse(eventRenderer); return printer.toString(); }
@Override public String getContent() { // Keep the macro content synchronized with the child blocks. WikiPrinter printer = new DefaultWikiPrinter(); XDOM xdom; // We need the begin/endDocument events so we wrap the child blocks in a XDOM block. if (getChildren().size() == 1 && getChildren().get(0) instanceof XDOM) { xdom = (XDOM) getChildren().get(0); } else { xdom = new XDOM(getChildren()); } getContentRenderer().render(xdom, printer); return printer.toString(); }
/** * Return the content of a section. * * @param sectionNumber the index (+1) of the section in the list of all sections in the document. * @return the content of a section or null if the section can't be found. * @throws XWikiException error when trying to extract section content */ public String getContentOfSection(int sectionNumber) throws XWikiException { String content = null; if (is10Syntax()) { content = getContentOfSection10(sectionNumber); } else { List<HeaderBlock> headers = getFilteredHeaders(); if (headers.size() >= sectionNumber) { SectionBlock section = headers.get(sectionNumber - 1).getSection(); content = renderXDOM(new XDOM(Collections.<Block> singletonList(section)), getSyntax()); } } return content; }
/** * @return the sections in the current document * @throws XWikiException */ public List<DocumentSection> getSections() throws XWikiException { if (is10Syntax()) { return getSections10(); } else { List<DocumentSection> splitSections = new ArrayList<DocumentSection>(); List<HeaderBlock> headers = getFilteredHeaders(); int sectionNumber = 1; for (HeaderBlock header : headers) { // put -1 as index since there is no way to get the position of the header in the source int documentSectionIndex = -1; // Need to do the same thing than 1.0 content here String documentSectionLevel = StringUtils.repeat("1.", header.getLevel().getAsInt() - 1) + "1"; DocumentSection docSection = new DocumentSection(sectionNumber++, documentSectionIndex, documentSectionLevel, renderXDOM(new XDOM(header.getChildren()), getSyntax())); splitSections.add(docSection); } return splitSections; } }
XDOM xdom = new XDOM(clonedHeaderBlock.getChildren());
public String extractTitle() { String title = ""; try { if (is10Syntax()) { title = extractTitle10(); } else { List<HeaderBlock> blocks = getXDOM().getChildrenByType(HeaderBlock.class, true); if (blocks.size() > 0) { HeaderBlock header = blocks.get(0); if (header.getLevel().compareTo(HeaderLevel.LEVEL2) <= 0) { XDOM headerXDOM = new XDOM(Collections.<Block> singletonList(header)); // transform TransformationContext context = new TransformationContext(headerXDOM, getSyntax()); Utils.getComponent(TransformationManager.class).performTransformations(headerXDOM, context); // render Block headerBlock = headerXDOM.getChildren().get(0); if (headerBlock instanceof HeaderBlock) { title = renderXDOM(new XDOM(headerBlock.getChildren()), Syntax.XHTML_1_0); } } } } } catch (Exception e) { // Don't stop when there's a problem rendering the title. } return title; }
if (splittingCriterion.shouldSplit(block, depth)) { XDOM xdom = new XDOM(block.getChildren()); String newDocumentName = namingCriterion.getDocumentName(xdom); WikiDocument newDoc = new WikiDocument(newDocumentName, xdom, parentDoc);
xdom = (XDOM) rootBlock; } else { xdom = new XDOM(Collections.singletonList(rootBlock));
private void runTestInternal() throws Throwable { WikiPrinter printer = new DefaultWikiPrinter(); if (!this.streaming) { Parser parser = getComponentManager().lookup(Parser.class, this.parserId); XDOM xdom = parser.parse(new StringReader(this.input)); if (this.runTransformations) { SyntaxFactory syntaxFactory = getComponentManager().lookup(SyntaxFactory.class); TransformationManager transformationManager = getComponentManager().lookup(TransformationManager.class); TransformationContext txContext = new TransformationContext(xdom, syntaxFactory.createSyntaxFromIdString(this.parserId)); transformationManager.performTransformations(xdom, txContext); } BlockRenderer renderer = getComponentManager().lookup(BlockRenderer.class, this.targetSyntaxId); // remove source syntax from XDOM metadata Map<String, Object> metadataMap = new HashMap<String, Object>(xdom.getMetaData().getMetaData()); metadataMap.remove(MetaData.SYNTAX); xdom = new XDOM(xdom.getChildren(), new MetaData(metadataMap)); renderer.render(xdom, printer); } else { StreamParser parser = getComponentManager().lookup(StreamParser.class, this.parserId); PrintRendererFactory printRendererFactory = getComponentManager().lookup(PrintRendererFactory.class, this.targetSyntaxId); // remove source syntax from begin/endDocument metadata WrappingListener listener = new SyntaxWrappingListener(); listener.setWrappedListener(printRendererFactory.createRenderer(printer)); parser.parse(new StringReader(this.input), listener); } assertEquals(this.expected, printer.toString()); }
if ("verbatim".equals(syntaxId)) xdom = new XDOM(new ArrayList<Block>()); xdom.addChild(new VerbatimBlock(s, false));
/** * Get the content to display (either the entire document content or the content of a specific section). * * @param document the source document * @param parameters the display parameters * @return the content as an XDOM tree */ private XDOM getContent(DocumentModelBridge document, final DocumentDisplayerParameters parameters) { XDOM content = parameters.isContentTranslated() ? getTranslatedContent(document) : document.getXDOM(); if (parameters.getSectionId() != null) { HeaderBlock headerBlock = content.getFirstBlock(new CompositeBlockMatcher(new ClassBlockMatcher(HeaderBlock.class), new BlockMatcher() { @Override public boolean match(Block block) { return ((HeaderBlock) block).getId().equals(parameters.getSectionId()); } }), Block.Axes.DESCENDANT); if (headerBlock == null) { throw new RuntimeException("Cannot find section [" + parameters.getSectionId() + "] in document [" + this.defaultEntityReferenceSerializer.serialize(document.getDocumentReference()) + "]"); } else { content = new XDOM(headerBlock.getSection().getChildren(), content.getMetaData()); } } return content; }
Map<String, Object> metadataMap = new HashMap<String, Object>(xdom.getMetaData().getMetaData()); metadataMap.remove(MetaData.SYNTAX); xdom = new XDOM(xdom.getChildren(), new MetaData(metadataMap));