Rewrite link urls

Hi,

I have created xPages for an ‘old’ Domino solution. The documents have a rich text field which contains (among other things) links to other documents. These links are on an old format (…/frmWeb?ReadForm&unid=123). I want to rewrite these linke to the new format (…/page.xsp?unid=123). Any ideas on how to do this?

I thought of reading the querystring in the xpage, parse it and redirect to the new format, but (ofcourse) I never reach the xpage when entering the old link format - I just reach the form. It is desirable for the two formats to exist simultanously, so I cannot edit the document content directly.

Regards Anja

Subject: Hack idea…

  • In WebQueryOpen on your original form, have it check the Domino server version it’s running on. If it’s R8.5 or higher, load the URL of the .xsp, otherwise do nothing and let it load normally.

  • Don’t know if this will work. It’s just a random idea I had. There should be tons of posts on this or the R-prior forum to tell you how to detect the server version.

Hope this helps…

Subject: Use dojo on the xPage (re: Rewrite link urls)

Since you’ve got dojo available with xPages, you should be able to put it to use for this sort of thing. On the xPage you use to display the doc with the links embedded in RTF, you could use dojo functions in your onLoad code to find and rewrite the bad URLs. You’d want to do something like this:

dojo.require(“dojo._base.query”);

var links = dojo.query( “a[href*=‘frmWeb?ReadForm’]”);

links.forEach(function(node, index, nodeList){

<... parse and rewrite node.href here... >

});

This uses dojo.query to find all the A nodes on the page that have an HREF containing the old form and URL command string. Then you just iterate over the nodelist array, parse out the UNID from the old HREF and set node.href to your new xPage url built from the UNID.