1 16 package dlog4j.util.tags; 17 18 import java.io.IOException ; 19 import java.io.Reader ; 20 import java.io.UnsupportedEncodingException ; 21 import java.net.URLEncoder ; 22 import java.security.AccessController ; 23 24 import javax.servlet.jsp.JspException ; 25 import javax.servlet.jsp.tagext.BodyTagSupport ; 26 27 import sun.security.action.GetPropertyAction; 28 29 33 public class URLEncoderTag extends BodyTagSupport { 34 35 38 public int doStartTag() throws JspException { 39 return EVAL_BODY_BUFFERED; 40 } 41 42 45 public int doEndTag() throws JspException { 46 Reader reader = getBodyContent().getReader(); 47 char[] buf = new char[32]; 48 try{ 49 StringBuffer content = new StringBuffer (32); 50 do{ 51 int rc = reader.read(buf); 52 if(rc>0) 53 content.append(buf,0,rc); 54 if(rc<32) 55 break; 56 }while(true); 57 pageContext.getOut().write(encodeURL(content.toString())); 58 }catch(IOException e0){ 59 } 60 return EVAL_PAGE; 61 } 62 68 public String encodeURL(String url) throws UnsupportedEncodingException { 69 String dfltEncName = (String )AccessController.doPrivileged(new GetPropertyAction("file.encoding")); 70 return URLEncoder.encode(url,dfltEncName); 71 } 72 } 73 | Popular Tags |