1 53 54 106 107 package com.Yasna.forum.filter; 108 109 import com.Yasna.forum.*; 110 import java.util.*; 111 112 115 public class FilterURLConverter extends ForumMessageFilter { 116 117 120 private Properties props; 121 122 125 private Properties propDescriptions; 126 127 132 public FilterURLConverter() { 133 super(); 134 props = new Properties(); 135 propDescriptions = new Properties(); 136 initializeProperties(); 137 } 138 139 147 public FilterURLConverter(ForumMessage message, Properties properties, 148 Properties propertyDescriptions) 149 { 150 super(message); 151 this.props = new Properties(properties); 152 this.propDescriptions = new Properties(propertyDescriptions); 153 } 154 155 161 public ForumMessageFilter clone(ForumMessage message){ 162 return new FilterURLConverter(message, props, propDescriptions); 163 } 164 165 168 public String getName() { 169 return "URL Converter"; 170 } 171 172 175 public String getDescription() { 176 return "Converts URL's to working web links."; 177 } 178 179 182 public String getAuthor() { 183 return "CoolServlets.com"; 184 } 185 186 189 public int getMajorVersion() { 190 return 1; 191 } 192 193 196 public int getMinorVersion() { 197 return 0; 198 } 199 200 206 public String getFilterProperty(String name) { 207 return props.getProperty(name); 208 } 209 210 216 public String getFilterPropertyDescription(String name) { 217 return propDescriptions.getProperty(name); 218 } 219 220 223 public Enumeration filterPropertyNames() { 224 return props.propertyNames(); 225 } 226 227 237 public void setFilterProperty(String name, String value) 238 throws IllegalArgumentException 239 { 240 if (props.getProperty(name) == null) { 241 throw new IllegalArgumentException (); 242 } 243 props.put(name, value); 244 } 245 246 250 public String getBody() { 251 return convertURL(message.getBody()); 252 } 253 254 257 private void initializeProperties() { 258 } 259 260 268 private String convertURL( String input ) { 269 if( input == null || input.length() == 0 ) { 272 return input; 273 } 274 else { 275 StringBuffer buf = new StringBuffer (); 276 277 int i = 0, j = 0, oldend = 0; 278 int len = input.length(); 279 char cur; 280 281 while ( ( i=input.indexOf( "http://", oldend) ) >= 0 ) { 282 j=i+7; 283 cur = input.charAt(j); 284 while (j < len) { 285 if (cur == ' ') break; 287 if (cur == '<') break; 289 if (cur == '\n') break; 291 if (cur == '\r' && j<len-1 && input.charAt(j+1) == '\n') 293 break; 294 295 j++; 296 if (j<len) { 297 cur = input.charAt(j); 298 } 299 } 300 buf.append(input.substring(oldend,i)); 301 buf.append("<a href =\""); 302 buf.append(input.substring(i,j)); 303 buf.append("\">"); 304 buf.append(input.substring(i,j)); 305 buf.append("</a>"); 306 oldend = j; 307 } 308 buf.append(input.substring(j,len)); 309 return buf.toString(); 310 } 311 } 312 } 313 | Popular Tags |