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 import org.nemesis.forum.util.StringUtils; 34 35 39 public class FilterNewline extends MessageFilter { 40 41 private static final String BR_TAG = "<BR>"; 42 43 46 private Properties props; 47 public Map getFilterProperties(){ 49 return props; 50 } 51 54 private Properties propDescriptions; 55 public Map getFilterPropertiesDescription(){ 57 return propDescriptions; 58 } 59 64 public FilterNewline() { 65 super(); 66 this.props = new Properties (); 67 this.propDescriptions = new Properties (); 68 } 69 70 78 public FilterNewline(Message message, Properties props, Properties propDescriptions) { 79 super(message); 80 this.props = new Properties (props); 81 this.propDescriptions = new Properties (propDescriptions); 82 } 83 84 90 public MessageFilter clone(Message message) { 91 return new FilterNewline(message, props, propDescriptions); 92 } 93 94 97 public String getName() { 98 return "Newline Converter"; 99 } 100 101 104 public String getDescription() { 105 return "Replaces newline characters with the <br> HTML tag."; 106 } 107 108 111 public String getAuthor() { 112 return "CoolServlets.com"; 113 } 114 115 118 public int getMajorVersion() { 119 return 1; 120 } 121 122 125 public int getMinorVersion() { 126 return 0; 127 } 128 129 135 public String getFilterProperty(String name) { 136 return props.getProperty(name); 137 } 138 139 145 public String getFilterPropertyDescription(String name) { 146 return propDescriptions.getProperty(name); 147 } 148 149 152 public Enumeration getFilterPropertyNames() { 153 return null; 155 } 156 157 167 public void setFilterProperty(String name, String value) throws IllegalArgumentException { 168 if (props.getProperty(name) == null) { 169 throw new IllegalArgumentException (); 170 } 171 props.put(name, value); 172 } 173 174 178 public String getBody() { 179 if (message.getBody() == null) { 180 return null; 181 } 182 return convertNewlines(message.getBody()); 183 } 184 185 193 private String convertNewlines(String input) { 194 String result = StringUtils.replace(input, "\r\n", BR_TAG); 195 return StringUtils.replace(result, "\n", BR_TAG); 196 } 197 } 198 | Popular Tags |