EasyJWeb是基于java技术

源代码在线查看: regfilterbuilder.java.svn-base

软件大小: 3476 K
上传用户: zhaoyanguangaaa
关键词: EasyJWeb java
下载地址: 免注册下载 普通下载 VIP

相关代码

				package com.easyjf.util.regx;
				
				import java.util.regex.Matcher;
				import java.util.regex.Pattern;
				/**
				 * 过滤实现
				 * @author stef_wu
				 *
				 */
				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;
							}
						});
					}
				
				}
							

相关资源