1 53 54 106 107 package com.Yasna.forum.filter; 108 109 import com.Yasna.forum.*; 110 import com.Yasna.util.*; 111 import java.util.*; 112 import java.io.*; 113 114 119 public class FilterFontStyle extends ForumMessageFilter implements Serializable { 120 121 124 private Properties props; 125 126 129 private Properties propDescriptions; 130 131 136 public FilterFontStyle() { 137 super(); 138 this.props = new Properties(props); 139 this.propDescriptions = new Properties(propDescriptions); 140 initializeProperties(); 141 } 142 143 151 public FilterFontStyle(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 FilterFontStyle(message, props, propDescriptions); 167 } 168 169 172 public String getName() { 173 return "Font Stylizer"; 174 } 175 176 179 public String getDescription() { 180 return "Converts custom font tags into HTML equivalents. It " + 181 "currently supports [b][/b] and [i][/i] tags."; 182 } 183 184 187 public String getAuthor() { 188 return "CoolServlets.com"; 189 } 190 191 194 public int getMajorVersion() { 195 return 1; 196 } 197 198 201 public int getMinorVersion() { 202 return 0; 203 } 204 205 211 public String getFilterProperty(String name) { 212 return props.getProperty(name); 213 } 214 215 221 public String getFilterPropertyDescription(String name) { 222 return propDescriptions.getProperty(name); 223 } 224 225 228 public Enumeration filterPropertyNames() { 229 return props.propertyNames(); 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 return fontStyleToHTML(message.getBody()); 257 } 258 259 262 private void initializeProperties() { 263 props.put("Bold","on"); 264 props.put("Italics","on"); 265 266 propDescriptions.put( 267 "Bold", "Toggles translation of [b][/b] to HTML bold tags." 268 ); 269 propDescriptions.put( 270 "Italics", "Toggles translation of [i][/i] to HTML bold tags." 271 ); 272 } 273 274 284 private String fontStyleToHTML( String input ) { 285 if( input == null || input.length() == 0 ) { 287 return input; 288 } 289 else { 290 int [] boldStartCount = new int[1]; 293 int [] italicsStartCount = new int[1]; 294 int [] boldEndCount = new int[1]; 295 int [] italicsEndCount = new int[1]; 296 if (props.getProperty("Bold").equals("on")) { 297 input = StringUtils.replace( input, "[b]", "<b>", boldStartCount ); 298 input = StringUtils.replace( input, "[/b]", "</b>", boldEndCount ); 299 int bStartCount = boldStartCount[0]; 300 int bEndCount = boldEndCount[0]; 301 while (bStartCount > bEndCount) { 302 input = input.concat("</b>"); 303 bEndCount++; 304 } 305 } 306 if (props.getProperty("Italics").equals("on")) { 307 input = StringUtils.replace( input, "[i]", "<i>", italicsStartCount ); 308 input = StringUtils.replace( input, "[/i]", "</i>", italicsEndCount ); 309 int iStartCount = italicsStartCount[0]; 310 int iEndCount = italicsEndCount[0]; 311 while (iStartCount > iEndCount) { 312 input = input.concat("</i>"); 313 iEndCount++; 314 } 315 } 316 } 317 return input; 318 } 319 } 320 321 | Popular Tags |