TitleInsertPage with Search Replace
Date14-Nov-2005 14:36:33 EET
JSPWiki version2.2.28
SubmitterAndreasKohlbecker
Idea CategoryPluginIdea
Reference
Idea StatusNewIdea

In several situations we found it very useful 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;
do{
    r++;
    nextSearch = params.get( PARAM_SEARCH+r );
    if(nextSearch == null )
        nextSearch = "%"+r+"$";
    nextReplace = params.get( PARAM_REPLACE+r );
    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()).

Example:

[{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

Add new attachment

Only authorized users are allowed to upload new attachments.

List of attachments

Kind Attachment Name Size Version Date Modified Author Change note
java
InsertPage.java 7.6 kB 1 14-Nov-2005 14:55 AndreasKohlbecker
« This page (revision-4) was last changed on 14-Nov-2005 14:54 by AndreasKohlbecker