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

fitnesse.wiki.search.SuiteSpecificationMatchFinder Maven / Gradle / Ivy

The newest version!
package fitnesse.wiki.search;

import fitnesse.components.TraversalListener;
import fitnesse.wiki.WikiPage;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class SuiteSpecificationMatchFinder extends WikiPageFinder {
  private String titleRegEx;
  private String contentRegEx;

  public SuiteSpecificationMatchFinder(String titleRegEx, String contentRegEx, TraversalListener observer) {
    super(observer);
    this.titleRegEx = titleRegEx;
    this.contentRegEx = contentRegEx;
  }

  @Override
  protected boolean pageMatches(WikiPage page) {
    if(!nullOrEmpty(titleRegEx) && !nullOrEmpty(contentRegEx))
       return patternMatches(titleRegEx, page.getName()) && patternMatches(contentRegEx,page.getData().getContent());
    else{
      return patternMatches(titleRegEx, page.getName()) || patternMatches(contentRegEx,page.getData().getContent());
    }
  }

  private boolean patternMatches(String regEx, String subject) {
    if (!nullOrEmpty(regEx)){
      Pattern pattern = Pattern.compile(regEx, Pattern.DOTALL);
      Matcher matcher = pattern.matcher(subject);
      if(matcher.find())
        return true;
    }
    return false;
  }

  private boolean nullOrEmpty(String regEx) {
    return regEx == null || regEx.equals("");
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy