1 53 54 106 107 package com.Yasna.forum.filter; 108 109 import java.util.*; 110 111 import com.Yasna.forum.*; 112 import com.Yasna.util.*; 113 114 118 public class FilterNewline extends ForumMessageFilter { 119 120 private static final String BR_TAG = "<BR>"; 121 122 125 private Properties props; 126 127 130 private Properties propDescriptions; 131 132 137 public FilterNewline() { 138 super(); 139 this.props = new Properties(); 140 this.propDescriptions = new Properties(); 141 } 142 143 151 public FilterNewline(ForumMessage message, Properties props, 152 Properties propDescriptions) 153 { 154 super(message); 155 this.props = new Properties(props); 156 this.propDescriptions = new Properties(propDescriptions); 157 } 158 159 165 public ForumMessageFilter clone(ForumMessage message){ 166 return new FilterNewline(message, props, propDescriptions); 167 } 168 169 172 public String getName() { 173 return "Newline Converter"; 174 } 175 176 179 public String getDescription() { 180 return "Replaces newline characters with the <br> HTML tag."; 181 } 182 183 186 public String getAuthor() { 187 return "CoolServlets.com"; 188 } 189 190 193 public int getMajorVersion() { 194 return 1; 195 } 196 197 200 public int getMinorVersion() { 201 return 0; 202 } 203 204 210 public String getFilterProperty(String name) { 211 return props.getProperty(name); 212 } 213 214 220 public String getFilterPropertyDescription(String name) { 221 return propDescriptions.getProperty(name); 222 } 223 224 227 public Enumeration filterPropertyNames() { 228 return null; 230 } 231 232 242 public void setFilterProperty(String name, String value) 243 throws IllegalArgumentException 244 { 245 if (props.getProperty(name) == null) { 246 throw new IllegalArgumentException (); 247 } 248 props.put(name, value); 249 } 250 251 255 public String getBody() { 256 if (message.getBody() == null) { 257 return null; 258 } 259 return convertNewlines(message.getBody()); 260 } 261 262 270 private String convertNewlines( String input ) { 271 String result = StringUtils.replace(input, "\r\n", BR_TAG); 272 return StringUtils.replace(result, "\n", BR_TAG); 273 } 274 } 275 | Popular Tags |