IMGFilter.java
上传用户:yuyunping
上传日期:2013-03-21
资源大小:1844k
文件大小:1k
源码类别:

Java书籍

开发平台:

Java

  1. package net.acai.filter;
  2. import java.util.regex.*;
  3. /**
  4.  * Title:        清清网络
  5.  * Description:
  6.  * Copyright:    Copyright (c) 2002
  7.  * Company:      www.SuperSpace.com
  8.  * @author:       SuperSpace
  9.  * @version 1.0
  10.  */
  11. public class IMGFilter extends filter  {
  12.   public IMGFilter(String s) {
  13.     super(s);
  14.   }
  15.   public IMGFilter(){}
  16.   public String  convertString(){
  17.     return this.IMGConverter();
  18.   }
  19.   public String IMGConverter(){
  20.         Pattern p = Pattern.compile(
  21.             "(\[IMG\])(.[^\[]*)(\[\/IMG\])",
  22.             Pattern.CASE_INSENSITIVE);
  23.         Matcher m = p.matcher(s);
  24.         StringBuffer sb = new StringBuffer();
  25.         //boolean result = m.find();
  26.         while((m.find())) {
  27.             m.appendReplacement(sb,"<IMG SRC=""+m.group(2)+"" border=0 alt=按此在新窗口浏览图片 onload="javascript:if(this.width>screen.width-333)this.width=screen.width-333;">");
  28.         }
  29.         m.appendTail(sb);
  30.         return sb.toString();
  31.     }
  32. }