1 16 package org.apache.taglibs.string; 17 18 import org.apache.commons.lang.StringUtils; 19 import org.apache.commons.lang.math.NumberUtils; 20 import javax.servlet.jsp.JspException ; 21 22 55 public class ReplaceTag extends StringTagSupport { 56 57 private String count; 58 private String replace; 59 private String with; 60 private String newlineToken; 61 private String carriageToken; 62 63 public ReplaceTag() { 64 super(); 65 } 66 67 72 public String getReplace() { 73 return this.replace; 74 } 75 76 81 public void setReplace(String replace) { 82 this.replace = replace; 83 } 84 85 90 public String getNewlineToken() { 91 return this.newlineToken; 92 } 93 94 99 public void setNewlineToken(String newlineToken) { 100 this.newlineToken = newlineToken; 101 } 102 103 108 public String getCarriageToken() { 109 return this.carriageToken; 110 } 111 112 117 public void setCarriageToken(String carriageToken) { 118 this.carriageToken = carriageToken; 119 } 120 121 122 127 public String getWith() { 128 return this.with; 129 } 130 131 136 public void setWith(String with) { 137 this.with = with; 138 } 139 140 141 146 public String getCount() { 147 return this.count; 148 } 149 150 155 public void setCount(String count) { 156 this.count = count; 157 } 158 159 160 161 public String changeString(String text) throws JspException { 162 String repl = replace; 163 String wit = with; 164 if(this.carriageToken != null) { 165 repl = StringUtils.replace(replace, this.carriageToken, "\r"); 166 wit = StringUtils.replace(with, this.carriageToken, "\r"); 167 } 168 if(this.newlineToken != null) { 169 repl = StringUtils.replace(replace, this.newlineToken, "\n"); 170 wit = StringUtils.replace(with, this.newlineToken, "\n"); 171 } 172 int ct = -1; 173 if(count != null) { 174 ct = NumberUtils.stringToInt(count); 175 } 176 return StringUtils.replace(text, repl, wit, ct); 177 } 178 179 public void initAttributes() { 180 181 this.replace = null; 182 183 this.with = null; 184 185 this.count = null; 186 187 this.newlineToken = null; 188 this.carriageToken = null; 189 190 } 191 192 } 193 | Popular Tags |