1 25 package org.nemesis.forum.filter; 26 27 import java.util.Enumeration ; 28 import java.util.Map ; 29 import java.util.Properties ; 30 31 import org.nemesis.forum.Message; 32 import org.nemesis.forum.MessageFilter; 33 34 37 public class FilterURLConverter extends MessageFilter { 38 39 42 private Properties props; 43 public Map getFilterProperties(){ 45 return props; 46 } 47 50 private Properties propDescriptions; 51 public Map getFilterPropertiesDescription(){ 53 return propDescriptions; 54 } 55 60 public FilterURLConverter() { 61 super(); 62 props = new Properties (); 63 propDescriptions = new Properties (); 64 initializeProperties(); 65 } 66 67 75 public FilterURLConverter(Message message, Properties properties, Properties propertyDescriptions) { 76 super(message); 77 this.props = new Properties (properties); 78 this.propDescriptions = new Properties (propertyDescriptions); 79 } 80 81 87 public MessageFilter clone(Message message) { 88 return new FilterURLConverter(message, props, propDescriptions); 89 } 90 91 94 public String getName() { 95 return "URL Converter"; 96 } 97 98 101 public String getDescription() { 102 return "Converts URL's to working web links."; 103 } 104 105 108 public String getAuthor() { 109 return "CoolServlets.com"; 110 } 111 112 115 public int getMajorVersion() { 116 return 1; 117 } 118 119 122 public int getMinorVersion() { 123 return 0; 124 } 125 126 132 public String getFilterProperty(String name) { 133 return props.getProperty(name); 134 } 135 136 142 public String getFilterPropertyDescription(String name) { 143 return propDescriptions.getProperty(name); 144 } 145 146 149 public Enumeration getFilterPropertyNames() { 150 return props.propertyNames(); 151 } 152 153 163 public void setFilterProperty(String name, String value) throws IllegalArgumentException { 164 if (props.getProperty(name) == null) { 165 throw new IllegalArgumentException (); 166 } 167 props.put(name, value); 168 } 169 170 174 public String getBody() { 175 return convertURL(message.getBody()); 176 } 177 178 181 private void initializeProperties() { 182 } 183 184 192 private String convertURL(String input) { 193 if (input == null || input.length() == 0) { 196 return input; 197 } else { 198 StringBuffer buf = new StringBuffer (); 199 200 int i = 0, j = 0, oldend = 0; 201 int len = input.length(); 202 char cur; 203 204 while ((i = input.indexOf("http://", oldend)) >= 0) { 205 j = i + 7; 206 cur = input.charAt(j); 207 while (j < len) { 208 if (cur == ' ') 210 break; 211 if (cur == '<') 213 break; 214 if (cur == '\n') 216 break; 217 if (cur == '\r' && j < len - 1 && input.charAt(j + 1) == '\n') 219 break; 220 221 j++; 222 if (j < len) { 223 cur = input.charAt(j); 224 } 225 } 226 buf.append(input.substring(oldend, i)); 227 buf.append("<a href =\""); 228 buf.append(input.substring(i, j)); 229 buf.append("\">"); 230 buf.append(input.substring(i, j)); 231 buf.append("</a>"); 232 oldend = j; 233 } 234 buf.append(input.substring(j, len)); 235 return buf.toString(); 236 } 237 } 238 } 239 | Popular Tags |