Tabnine Logo
XDOM
Code IndexAdd Tabnine to your IDE (free)

How to use
XDOM
in
org.xwiki.rendering.block

Best Java code snippets using org.xwiki.rendering.block.XDOM (Showing top 20 results out of 369)

origin: org.wikbook/wikbook.xwiki

Substitution(Block src, XDOM dst)
{
 this.src = src;
 this.dst = dst.getChildren();
}
origin: com.xpn.xwiki.platform/xwiki-core

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;
}
origin: org.xwiki.platform/xwiki-platform-display-api

  document.getXDOM().getBlocks(new ClassBlockMatcher(HeaderBlock.class), Block.Axes.DESCENDANT);
if (!blocks.isEmpty()) {
  HeaderBlock heading = blocks.get(0);
    XDOM headingXDOM = new XDOM(Collections.<Block> singletonList(heading));
    try {
      TransformationContext txContext =
      transformationManager.performTransformations(headingXDOM, txContext);
      Block headingBlock = headingXDOM.getChildren().size() > 0 ? headingXDOM.getChildren().get(0) : null;
      if (headingBlock instanceof HeaderBlock) {
        return new XDOM(headingBlock.getChildren());
origin: org.xwiki.rendering/xwiki-rendering-test

/**
 * @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();
}
origin: org.xwiki.platform/xwiki-platform-rendering-wikimacro-store

/**
 * 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;
}
origin: org.xwiki.rendering/xwiki-rendering-transformation-macro

/**
 * @param xdom the {@link XDOM} to convert
 * @return an inline version of the passed {@link XDOM}
 */
private XDOM convertToInline(XDOM xdom)
{
  List<Block> blocks = new ArrayList<Block>(xdom.getChildren());
  // TODO: use inline parser instead
  if (!blocks.isEmpty()) {
    this.parserUtils.removeTopLevelParagraph(blocks);
    // Make sure included macro is inline when script macro itself is inline
    Block block = blocks.get(0);
    if (block instanceof MacroBlock) {
      MacroBlock macro = (MacroBlock) block;
      if (!macro.isInline()) {
        blocks.set(0, new MacroBlock(macro.getId(), macro.getParameters(), macro.getContent(), true));
      }
    }
    xdom.setChildren(blocks);
  }
  return xdom;
}
origin: org.xwiki.rendering/xwiki-rendering-tests

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());
}
origin: org.xwiki.platform/xwiki-platform-display-macro

MetaDataBlock metadata = new MetaDataBlock(result.getChildren(), result.getMetaData());
String source = this.defaultEntityReferenceSerializer.serialize(includedReference);
metadata.getMetaData().addMetaData(MetaData.SOURCE, source);
origin: org.xwiki.platform/xwiki-platform-refactoring-api

if (newDoc.getChildren().size() > 0) {
  Block firstChild = newDoc.getChildren().get(0);
  if (firstChild instanceof HeaderBlock) {
    XDOM xdom = new XDOM(clonedHeaderBlock.getChildren());
origin: org.wikbook/wikbook.xwiki

if ("verbatim".equals(syntaxId))
 xdom = new XDOM(new ArrayList<Block>());
 xdom.addChild(new VerbatimBlock(s, false));
   for (HeaderBlock header : xdom.getChildrenByType(HeaderBlock.class, true))
return new IncludeBlock(syntaxId, xdom.getChildren());
origin: org.xwiki.platform/xwiki-core-rendering-parser-wikimodel

public XDOM getXDOM()
{
  return new XDOM(generateListFromStack(), this.idGenerator);
}
origin: org.xwiki.rendering/xwiki-rendering-macro-html

List<MacroBlock> macros = xdom.getBlocks(MACROBLOCKMATCHER, Axes.DESCENDANT);
for (MacroBlock macro : macros) {
  if ("html".equals(macro.getId())) {
    htmlMacroBlock.getContent(), xdom.getChildren(), htmlMacroBlock.isInline());
origin: org.xwiki.platform/xwiki-core-rendering-macro-html

List<MacroBlock> macros = xdom.getChildrenByType(MacroBlock.class, true);
for (MacroBlock macro : macros) {
  if (macro.getId().equals("html")) {
    .getContent(), xdom.getChildren(), htmlMacroBlock.isInline());
origin: org.xwiki.platform/xwiki-platform-display-api

/**
 * 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;
}
origin: com.xpn.xwiki.platform/xwiki-core

/**
 * Convert the passed content from the passed syntax to the passed new syntax.
 * 
 * @param content the content to convert
 * @param source the reference to where the content comes from (eg document reference)
 * @param targetSyntax the new syntax after the conversion
 * @param txContext the context when Transformation are executed or null if transformation shouldn't be executed
 * @return the converted content in the new syntax
 * @throws XWikiException if an exception occurred during the conversion process
 * @since 2.4M2
 */
private static String performSyntaxConversion(String content, String source, Syntax targetSyntax,
  TransformationContext txContext) throws XWikiException
{
  try {
    XDOM dom = parseContent(txContext.getSyntax().toIdString(), content);
    // Set the source metadata for the parsed XDOM so that Renderers can resolve relative links/images based
    // on it.
    dom.getMetaData().addMetaData(MetaData.SOURCE, source);
    return performSyntaxConversion(dom, targetSyntax, txContext);
  } catch (Exception e) {
    throw new XWikiException(XWikiException.MODULE_XWIKI_RENDERING, XWikiException.ERROR_XWIKI_UNKNOWN,
      "Failed to convert document to syntax [" + targetSyntax + "]", e);
  }
}
origin: org.xwiki.platform/xwiki-platform-chart-macro

@Override
protected TableBlock getTableBlock(String macroContent, MacroTransformationContext context)
  throws MacroExecutionException
{
  XDOM xdom = computeXDOM(context);
  // Find the correct table block.
  List<TableBlock> tableBlocks = xdom.getBlocks(new ClassBlockMatcher(TableBlock.class), Block.Axes.DESCENDANT);
  TableBlock result = null;
  this.logger.debug("Table id is [{}], there are [{}] tables in the document [{}]",
    new Object[]{this.tableId, tableBlocks.size(), this.documentReference});
  if (null != tableId) {
    for (TableBlock tableBlock : tableBlocks) {
      String id = tableBlock.getParameter("id");
      if (null != id && id.equals(this.tableId)) {
        result = tableBlock;
        break;
      }
    }
  } else {
    result = (tableBlocks.size() > 0) ? tableBlocks.get(0) : null;
  }
  if (null == result) {
    throw new MacroExecutionException("Unable to find a matching data table.");
  }
  return result;
}
origin: com.xpn.xwiki.platform/xwiki-core

/**
 * @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();
}
origin: org.xwiki.rendering/xwiki-rendering-test

if (xdom.getMetaData() != null) {
  Map<String, Object> metadataMap = new HashMap<String, Object>(xdom.getMetaData().getMetaData());
  metadataMap.remove(MetaData.SYNTAX);
  xdom = new XDOM(xdom.getChildren(), new MetaData(metadataMap));
origin: org.xwiki.platform/xwiki-platform-rendering-macro-include

MetaDataBlock metadata = new MetaDataBlock(result.getChildren(), result.getMetaData());
String source = this.defaultEntityReferenceSerializer.serialize(includedReference);
metadata.getMetaData().addMetaData(MetaData.SOURCE, source);
origin: org.xwiki.platform/xwiki-platform-refactoring-api

if (splittingCriterion.shouldSplit(block, depth)) {
  XDOM xdom = new XDOM(block.getChildren());
  String newDocumentName = namingCriterion.getDocumentName(xdom);
  WikiDocument newDoc = new WikiDocument(newDocumentName, xdom, parentDoc);
    split(newDoc, newDoc.getXdom().getChildren(), depth + 1, result, splittingCriterion,
      namingCriterion);
org.xwiki.rendering.blockXDOM

Javadoc

Contains the full tree of Block that represent a XWiki Document's content.

Most used methods

  • getChildren
  • <init>
  • getMetaData
  • getBlocks
  • clone
  • getChildrenByType
  • setIdGenerator
  • traverse
  • addChild
  • getFirstBlock
  • getParameters
  • indexOf
  • getParameters,
  • indexOf,
  • replaceChild,
  • setChildren

Popular in Java

  • Creating JSON documents from java classes using gson
  • setContentView (Activity)
  • getOriginalFilename (MultipartFile)
    Return the original filename in the client's filesystem.This may contain path information depending
  • getSystemService (Context)
  • FileOutputStream (java.io)
    An output stream that writes bytes to a file. If the output file exists, it can be replaced or appen
  • AtomicInteger (java.util.concurrent.atomic)
    An int value that may be updated atomically. See the java.util.concurrent.atomic package specificati
  • Stream (java.util.stream)
    A sequence of elements supporting sequential and parallel aggregate operations. The following exampl
  • Reference (javax.naming)
  • JOptionPane (javax.swing)
  • IsNull (org.hamcrest.core)
    Is the value null?
  • CodeWhisperer alternatives
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now