首页 / 更多教程 / Filter过滤链条
Filter过滤链条
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了Filter过滤链条,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2743字,纯文字阅读大概需要4分钟。
内容图文
<SPAN style=‘color: rgb(0, 0, 255); font-family: "times new roman", times;‘>Filter.java
<SPAN style=‘color: rgb(0, 0, 255); font-family: "times new roman", times; font-size: 16px;‘>SesitiveFilter.java
package com.bjsxt.dp.filter; public class SesitiveFilter implements Filter { @Override public String doFilter(String str) { // process the sensitive words String r = str.replace("被就业", "就业").replace("敏感", ""); return r; } }
<SPAN style=‘color: rgb(0, 0, 255); font-family: "times new roman", times;‘>FaceFilter.java
package com.bjsxt.dp.filter; public class FaceFilter implements Filter { @Override public String doFilter(String str) { return str.replace(":)", "^V^"); } }
<SPAN style=‘color: rgb(0, 0, 255); line-height: 1.5; font-family: "times new roman", times;‘>HTMLFilter.java
package com.bjsxt.dp.filter; public class HTMLFilter implements Filter { @Override public String doFilter(String str) { //process the html tag <> String r = str.replace(‘<‘, ‘[‘) .replace(‘>‘, ‘]‘); return r; } }
<SPAN style=‘color: rgb(0, 0, 255); font-family: "times new roman", times;‘>FilterChain.java
package com.bjsxt.dp.filter; import java.util.ArrayList; import java.util.List; public class FilterChain implements Filter { List<Filter> filters = new ArrayList<Filter>(); public FilterChain addFilter(Filter f) { this.filters.add(f); returnthis; } public String doFilter(String str) { String r = str; for(Filter f: filters) { r = f.doFilter(r); } return r; } }
<SPAN style=‘color: rgb(0, 0, 255); line-height: 1.5; font-family: "times new roman", times;‘>MsgProcessor.java
package com.bjsxt.dp.filter; public class MsgProcessor { private String msg; FilterChain fc; public FilterChain getFc() { return fc; } public void setFc(FilterChain fc) { this.fc = fc; } public String getMsg() { return msg; } publicvoid setMsg(String msg) { this.msg = msg; } public String process() { return fc.doFilter(msg); } }
<SPAN style=‘color: rgb(0, 0, 255); font-family: "times new roman", times; font-size: 16px;‘>Main.java
package com.bjsxt.dp.filter; public class Main { /** * @author admin */ public static void main(String[] args) { String msg = "大家好:),<script>,敏感,被就业,网络授课没感觉,因为看不见大家伙儿"; MsgProcessor mp = new MsgProcessor(); mp.setMsg(msg); FilterChain fc = new FilterChain(); fc.addFilter(new HTMLFilter()).addFilter(new SesitiveFilter()); FilterChain fc2 = new FilterChain(); fc2.addFilter(new FaceFilter()); fc.addFilter(fc2); mp.setFc(fc); String result = mp.process(); System.out.println(result); } }
各类之间的关系图:
原文:http://www.cnblogs.com/jianfengyun/p/3720334.html
内容总结
以上是互联网集市为您收集整理的Filter过滤链条全部内容,希望文章能够帮你解决Filter过滤链条所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。