Change link text in XDOM with velocity or groovy


I have to update links in bulk on my wiki because the underlying URL changed. So I have a ton of links that display and point to After the update they should display and point to

I already have a script in velocity that loops over all links and updates the URL but I can’t find a way to update the display.

Is there a way to update displayed value also? It looks like it is composed of some Wordblocks and special character blocks that are children of the link. Is there an easy way to generate a new display value that is the URL?


So you used a regex to replace into what’s in your content was somehting like [[http~://>>]] ?

Yes in source mode my links look like this. I looped over all the Linkblocks in the XDOM and replaced the Reference of the ResourceReference, so the URL changed.

LinkBlock like many Blocks is more or less immutable so not so easy to manipulate with Velocity (since you don’t have any syntax to create new java objects). Would be much simpler using Groovy.

I can switch to groovy. Currently I’m cloning the Linkblocks, update the Reference and replace the old Linkblock with the new one (replaceChild). The only thing missing is to update the display text.

Edit: Updated the title, to show that velocity or groovy is possible.

OK so the question ist how ist this done in groovy?

What I would require is the following:
Loop over every link in page
Get full description text
Replace text if it matches my old address.
Set/Update new description

Currently if I work with LinkBlocks I don’t get the full description, only Text/SpecialCharacterBlocks.

Any suggestions?

This is the label. It’s just parsed as any plain text which mean separating special symbols from the rest, basically you should match something like:

  • WordBlock(“http”)
  • SpecialSymbolBlock(‘:’)
  • SpecialSymbolBlock(‘/’)
  • SpecialSymbolBlock(‘/’)
  • WordBlock(“foo”)
  • SpecialSymbolBlock(‘.’)
  • WordBlock(“com”)

That being said I really don’t think I would have used XDOM to do this search & replace. In this specific use case good old regexp based search&replace on the document String content field would be much simpler and there is no much risk to have false positive when you are searching for a URL (unless you actually want to keep the old domain in some cases in which case indeed regex is starting to be dangerous).

If you need info and some example on XDOM, please see