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 40 public class SubstringTag extends StringTagSupport { 41 42 private String end; 43 private String start; 44 45 public SubstringTag() { 46 super(); 47 } 48 49 54 public String getStart() { 55 return this.start; 56 } 57 58 63 public void setStart(String start) { 64 this.start = start; 65 } 66 67 68 73 public String getEnd() { 74 return this.end; 75 } 76 77 82 public void setEnd(String end) { 83 this.end = end; 84 } 85 86 87 88 public String changeString(String text) throws JspException { 89 if(end == null) { 90 return StringUtils.substring(text, NumberUtils.stringToInt(start) ); 91 } else { 92 return StringUtils.substring(text, NumberUtils.stringToInt(start), NumberUtils.stringToInt(end) ); 93 } 94 } 95 96 public void initAttributes() { 97 98 this.start = "0"; 99 100 this.end = null; 101 102 } 103 104 105 } 106 | Popular Tags |