1 16 package org.apache.taglibs.string; 17 18 import javax.servlet.jsp.JspException ; 19 import org.apache.commons.lang.StringUtils; 20 import org.apache.commons.lang.math.NumberUtils; 21 22 38 public class MidTag extends StringTagSupport { 39 40 private String count; 41 private String start; 42 43 public MidTag() { 44 super(); 45 } 46 47 52 public String getCount() { 53 return this.count; 54 } 55 56 61 public void setCount(String count) { 62 this.count = count; 63 } 64 65 70 public String getStart() { 71 return this.start; 72 } 73 74 79 public void setStart(String start) { 80 this.start = start; 81 } 82 83 84 public String changeString(String text) throws JspException { 85 int st = NumberUtils.stringToInt(start); 86 int ct = NumberUtils.stringToInt(count); 87 if(st == -1) { 88 st = (text.length() - ct)/2; 89 } 90 return StringUtils.mid(text, st, ct); 91 } 92 93 public void initAttributes() { 94 this.count = "0"; 95 this.start = "-1"; 96 } 97 98 99 } 100 | Popular Tags |