1 package com.sslexplorer.input.tags; 2 3 import javax.servlet.jsp.JspException ; 4 5 import org.apache.commons.logging.Log; 6 import org.apache.commons.logging.LogFactory; 7 import org.apache.struts.taglib.TagUtils; 8 import org.apache.struts.taglib.html.BaseFieldTag; 9 10 import com.sslexplorer.boot.Util; 11 12 13 19 public class RestrictTag extends BaseFieldTag { 20 21 final static Log log = LogFactory.getLog(FrameTag.class); 22 23 25 protected int width; 26 27 28 33 public void setWidth(int width) { 34 this.width = width; 35 } 36 37 42 public int doEndTag() throws JspException { 43 TagUtils.getInstance().write(pageContext, generateFragment()); 44 return (EVAL_PAGE); 45 } 46 47 52 public void release() { 53 super.release(); 54 width = 40; 55 } 56 57 62 public int doStartTag() throws JspException { 63 return EVAL_BODY_BUFFERED; 64 } 65 66 String generateFragment() throws JspException { 67 StringBuffer buf = new StringBuffer (); 68 String content = Util.trimBoth(bodyContent.getString()); 69 while(true) { 70 if(content.length() <= width) { 72 buf.append(content); 73 break; 74 } 75 else { 76 78 char[] chars = { '\n', ' ', '-', '.', ',' }; 79 int sidx = -1; 80 for(int i = 0 ; i < chars.length ; i++) { 81 sidx = Math.max(content.lastIndexOf(chars[i], width - 1), sidx); 82 } 83 84 if(sidx == -1) { 86 buf.append(content.substring(0, width)); 87 buf.append("<br/>"); 88 content = content.substring(width); 89 } 90 else { 91 buf.append(content.substring(0, sidx)); 93 buf.append("<br/>"); 94 content = Util.trimBoth(content.substring(sidx)); 95 } 96 } 97 } 98 return buf.toString(); 99 } 100 } 101 | Popular Tags |