All Downloads are FREE. Search and download functionalities are using the official Maven repository.

fitnesse.wiki.refactoring.ContentReplacingSearchObserver Maven / Gradle / Ivy

There is a newer version: 20181217
Show newest version
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);
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy