|Title|InsertPage with Search Replace  
|Date|14-Nov-2005 14:36:33 EET
|JSPWiki version|2.2.28
|[Idea Category]|PluginIdea
|[Idea Status]|NewIdea

%%small __[Previous Page| %1$] | [Next Page| xyz] | [Page Scan| %3$]__\\
This page version is under ongoing correction and all [markup rules|AboutWikiMarkupRules] should be observed. Revision 4 contains only global corrections
but has not been proofread on a page-by-page basis. Please verify the information by comparing it with scanned page image in revision 1!%%

We found it very useful in several situations to be able to search and replace the text of pages inserted by the {{InsertPage}} plugin.

Therefore i implemented this functionality into the existing {{InsertPage}} plugin. Here are the additional code snippets (The complete source code is attached to this page):

Starting at line 45:
public static final String PARAM_SEARCH    = "search";
public static final String PARAM_REPLACE    = "replace";

Staring at line 142 after insertion of the snipped above:
// Perform search replace according to the parameters 
// search1 to searchN and replace1 to replaceN
int r = 0;
Object nextReplace = null;
Object nextSearch;
    nextSearch = params.get( PARAM_SEARCH+r );
    if(nextSearch == null )
        nextSearch = "%"+r+"$";
    nextReplace = params.get( PARAM_REPLACE+r );
    log.fatal("Replace"+r+" = "+nextReplace);
    if(nextReplace != null){
        pageData = pageData.replace((String)nextSearch, (String)nextReplace);
}while( nextReplace != null );

The {{InsertPage}} plugin now understands the parameters {{search1}} to {{searchN}} and {{replace1}} to {{replaceN}} whereas N is a positive integer.
If {{replaceN}} is defined and {{searchN}} is not defined {{searchN}} defaults to the string {{%N$}} (syntax adapted from String.format()).

[{InsertPage page='ContentToReplace' replace1='BoringPage'  replace2='Someone' search='xyz' replace3='http://www.foo.bar/~Someone/index.html' }]

content of ContentToReplace:
This is a very interesting page written by [xyz|%3$]. 

If you like boring pages click [here|%1$]

It would be nice to have it already implemented in further releases of the JSPWiki.

Andreas Kohlbecker, Berlin