fitnesse.wiki.refactoring.ContentReplacingSearchObserver Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of fitnesse Show documentation
Show all versions of fitnesse Show documentation
The fully integrated standalone wiki, and acceptance testing framework.
package fitnesse.wiki.refactoring;
import java.util.regex.Pattern;
import fitnesse.components.TraversalListener;
import fitnesse.wiki.PageData;
import fitnesse.wiki.WikiPage;
public class ContentReplacingSearchObserver implements TraversalListener {
private Pattern searchPattern;
private String replacement;
public ContentReplacingSearchObserver(String searchPattern, String replacement) {
this.searchPattern = Pattern.compile(searchPattern);
this.replacement = replacement;
}
@Override
public void process(WikiPage page) {
PageData pageData = page.getData();
String replacedContent = searchPattern.matcher(pageData.getContent()).replaceAll(replacement);
pageData.setContent(replacedContent);
page.commit(pageData);
}
}