1 package org.columba.mail.gui.message.util; 17 18 import java.util.regex.Matcher ; 19 import java.util.regex.Pattern ; 20 21 22 30 public class DocumentParser { 31 private final static String [] smilyImage = { 32 "face1.png", "face4.png", "face8.png", "face3.png", "face11.png", 33 "face2.png", "face15.png" 34 }; 35 private final static Pattern [] smilyPattern = { 36 Pattern.compile("\\s:-\\)"), Pattern.compile("\\s:-\\("), 37 Pattern.compile("\\s:-\\|"), Pattern.compile("\\s;-\\)"), 38 Pattern.compile("\\s:cry:"), Pattern.compile("\\s:o"), 39 Pattern.compile("\\s8\\)"), 40 }; 41 private static final Pattern markQuotingsPattern = Pattern.compile("(^( )*>[^\\n]*)|\\n(( )*>[^\\n]*)", 42 Pattern.CASE_INSENSITIVE); 43 44 public DocumentParser() { 45 } 46 47 52 public static String markQuotings(String input) throws Exception { 53 Matcher matcher = markQuotingsPattern.matcher(input); 54 55 return matcher.replaceAll("\n<font class=\"quoting\">$1$3</font>"); 56 } 57 58 public static String addSmilies(String input) throws Exception { 59 Matcher matcher; 60 61 for (int i = 0; i < smilyPattern.length; i++) { 62 matcher = smilyPattern[i].matcher(input); 63 input = matcher.replaceAll(" <IMG SRC=\"" + smilyImage[i] + 64 "\">"); 65 } 66 67 return input; 68 } 69 } 70 | Popular Tags |