Uploaded image for project: 'XWiki Platform'
  1. XWiki Platform
  2. XWIKI-3938

Improve Rendering Block's API for replacing a Block

    XMLWordPrintable

Details

    • Improvement
    • Resolution: Fixed
    • Minor
    • 2.0 M1
    • 1.9 RC1
    • {Unused} Rendering 2.0
    • None
    • Unit
    • Unknown

    Description

      The problem with the current implementation is that you cannot write:

      for (LinkBlock block : xdom.getChildrenByType(LinkBlock.class, true))

      Unknown macro: { Block newBlock = new FormatBlock(Collections.<Block>singletonList(block), Format.ITALIC); block.replace(newBlock); }

      This fails because when the "block" is added in FormatBlock, its parent is set to be the FormatBlock and thus when block.replace() executes the parent of the new block is set to be the format block instead of its parent.

      I thus propose an API that is inline with the w3c DOM API:

      /**

      • Replaces an existing children block with the passed new block.
      • Also sets the new block's parent to be the current block.
        *
      • @param newBlock the new block to replace the old block with
        */
        void replaceChild(Block newBlock, Block oldBlock);

      /**

      • Replaces an existing children block with the passed new blocks.
      • Also sets the new block's parents to be the current block.
        *
      • @param newBlocks the new blocks to replace the old block with
        */
        void replaceChild(List<Block> newBlocks, Block oldBlock);

      Attachments

        Activity

          People

            vmassol Vincent Massol
            vmassol Vincent Massol
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: