⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 filer.java

📁 中应用程序的访问权限对Java Web Console 中应用程序的访问权限 成功登录 Web 控制台后,可能无法自动访问在该控制台中注册的所有应用程序。通常,必须安装应用程序,才能让所有的用户在控制
💻 JAVA
字号:
/**
 * 
 */
package edu.yinhe.mis.util;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 甘丽
 * 过滤字符串
 * <p><blockquote><pre>
 * String []b = new String[]{"<input @@*>","<p>","<br>"};
 *		Filer filter = new Filer(b);
 *		String s[][] = new String[1][];
 *		s[0]=new String[]{"*","&"};
 *		filter.setAttribute(s);
 *		String []a = (String[]) filter.execute();
 *		for(int i=0;i<a.length;i++){
 *			System.out.println(a[i]);
 *		}
 * </pre></blockquote><p>
 */
public class Filer {
	/**
	 * 过滤的String类型数组
	 */
	private String [] str=null;
	/**
	 * 存放所有的过滤介质
	 */
	private List list = new ArrayList();
	 

	/**
	 * 无参构造方法
	 */
	
	public Filer() {
		this.setMedium();
	}
	/**
	 * 带有一个参数的构造方法
	 * @param str 要过滤的字符串
	 */
	public Filer(String str) {
		this.str = new String[]{str};
		this.setMedium();
	}
	/**
	 * 带有一个参数的构造方法
	 * @param str 要过滤的字符串数组
	 */
	public Filer(String []str) {
		this.str = str;
		this.setMedium();
	}

	private void setMedium(){
		list.add(new String[]{"<", "&lt;"});
		list.add(new String[]{">", "&gt;"});
		list.add(new String[]{" ", "&nbsp;"});
		list.add(new String[]{"<br>","<br>"});
		list.add(new String[]{"<p>","<p>"});
	}
	/**
	 * 开始执行过滤
	 * @return 过滤后的对象
	 */
	public Object execute(){
		String []replace=new String[2];
		if(str!=null){
			for(int i = 0;i<str.length;i++){
				if(str[i]!=null&&!"".equals(str[i])){
					System.out.println(list.size());
					for(int j = 0;j<list.size();j++){
						replace=(String[]) list.get(j);
						System.out.println(replace[0]+"                 "+replace[1]);
						str[i]=str[i].replaceAll(replace[0], replace[1]);
					}
				}
			}
		}
		return str;

	}
	/**
	 * 开始执行过滤
	 * @param str 要过滤的字符串
	 * @return 过滤后的对象
	 */
	public Object execute(String str){
		String []replace=new String[2];
		if(str!=null&&!"".equals(str)){
			for(int j = 0;j<list.size();j++){
				replace=(String[]) list.get(j);
				str=str.replaceAll(replace[0], replace[1]);
			}
		}
		return str;

	}
	/**
	 * 开始执行过滤
	 * @param str 要过滤的字符串数组
	 * @return 过滤后的对象
	 */
	public Object execute(String []str){
		this.str=str;
		return this.execute();
	}
	/**
	 * 设置过滤介质
	 * @param formate 二维数组,二维数组中的一维数组的第一个字符串是要被过滤掉的,而第二个字符串过滤后的字符串(既替换)
	 */
	public void setAttribute(String [][]formate){
		if(formate!=null&&formate.length>0){
			for(int i = 0;i<formate.length;i++){
				if(formate[i][0].equals("*")){
					formate[i][0] = formate[i][0].replace("*", "\\*");
				}
				if(formate[i][1].equals("*")){
					formate[i][1] = formate[i][1].replace("*", "\\*");
				}
				System.out.println(formate[i][0]+"              "+formate[i][1]);
				list.add(new String[]{formate[i][0],formate[i][1]});
			}
		}
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -