This method should be called whenever a wiki document is stored, we want to store the permanent identifiers of a target node. That way, the target node can be renamed and the document that links to that target node still contains the valid link.
Either parse the wikiText by hand to find and replace links, or use the REGEX_WIKILINK_FORWARD pattern which matches [GROUP1=>GROUP2]. Convert the target name (GROUP2) to a unique wiki name, and then to some primary identifier which you can lookup again in the future in a reliable fashion. GROUP1 is the optional link description entered by the user, you need to keep this string and only replace GROUP2 with a permanent identifier (prefixed with the wiki:// protocol).
Note that cross-namespace linking should be supported, so in addition to [=>Target Name], links can be entered by the user as [=>Target Area|Target Name]. To resolve these link texts, use REGEX_WIKILINK_CROSSAREA on the original GROUP2, which produces two groups. Ignore the given currentAreaNumber parameter and resolve in the target namespace entered by the user on the link tag.
Example pseudo code:
if (targetName = wikiText.match(REGEX_WIKI_LINK_FORWARD)) { if (targetNamespace, newTargetName = targetName.match(REGEX_WIKILINK_CROSSAREA) { wikiText.replace( resolveNodeId(targetNamespace, newTargetName) ); } else { wikiText.replace( resolveNodeId(givenNamespace, targetName) ); } }@param linkTargets This collection will be filled with WikiFile instances which are the link targets in the wiki text @param currentAreaNumber The currennt area useable as the namespace for scoped resolving @param wikiText Text with wiki markup containing [=>Target Name] links @return The wikiText with all [=>Target Name] links replaced with [=>wiki://id]
|
|