一、www.easyjf.com全站源码是EasyJF开源团队站务组及核心成员共同开发及维护的系统

源代码在线查看: regfilterbuilder.java

软件大小: 5862 K
上传用户: a1a1J0
关键词: easyjf EasyJF www com
下载地址: 免注册下载 普通下载 VIP

相关代码

				package com.easyjf.util.regx;
				
				import java.util.regex.Matcher;
				import java.util.regex.Pattern;
				
				public class RegFilterBuilder
				    implements FilterBuilder {
				
				  private String regex = null;
				  private String rpStr = null;
				  private String source = null;
				  private String result = null;
				
				  public RegFilterBuilder(String regex, String rpStr, String source) {
				    super();
				    this.regex = regex;
				    this.rpStr = rpStr;
				    this.source = source;
				  }
				
				  public void buildFilter() {
				    if (this.regex == null) {
				      return;
				    }
				    Pattern p = Pattern.compile(regex, 2);
				    Matcher matcher = p.matcher(this.source);
				    StringBuffer sb = new StringBuffer();
				    String tempString = rpStr;
				    int rpL = rpStr.split("\\$[0-9]+").length;
				    while (matcher.find()) {
				      for (int i = 0; (i < rpL) && (i < matcher.groupCount()); i++) {
				        tempString = tempString.replaceAll("\\$" + i, matcher.group(i));
				      }
				      matcher.appendReplacement(sb, tempString);
				    }
				    matcher.appendTail(sb);
				    this.result = sb.toString();
				  }
				
				  public Filter getFilter() {
				    return (new RegexFilter() {
				      public String getFilteredStr() {
				        return result;
				      }
				    });
				  }
				
				}
							

相关资源