KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > mail > gui > message > util > DocumentParser


1 //The contents of this file are subject to the Mozilla Public License Version 1.1
2
//(the "License"); you may not use this file except in compliance with the
3
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
4
//
5
//Software distributed under the License is distributed on an "AS IS" basis,
6
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
7
//for the specific language governing rights and
8
//limitations under the License.
9
//
10
//The Original Code is "The Columba Project"
11
//
12
//The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
13
//Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
14
//
15
//All Rights Reserved.
16
package org.columba.mail.gui.message.util;
17
18 import java.util.regex.Matcher JavaDoc;
19 import java.util.regex.Pattern JavaDoc;
20
21
22 /**
23  * @author freddy
24  *
25  * To change this generated comment edit the template variable "typecomment":
26  * Window>Preferences>Java>Templates.
27  * To enable and disable the creation of type comments go to
28  * Window>Preferences>Java>Code Generation.
29  */

30 public class DocumentParser {
31     private final static String JavaDoc[] smilyImage = {
32         "face1.png", "face4.png", "face8.png", "face3.png", "face11.png",
33         "face2.png", "face15.png"
34     };
35     private final static Pattern JavaDoc[] 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 JavaDoc markQuotingsPattern = Pattern.compile("(^( )*>[^\\n]*)|\\n(( )*>[^\\n]*)",
42             Pattern.CASE_INSENSITIVE);
43
44     public DocumentParser() {
45     }
46
47     /*
48  *
49  * make quotes font-color darkgray
50  *
51  */

52     public static String JavaDoc markQuotings(String JavaDoc input) throws Exception JavaDoc {
53         Matcher JavaDoc matcher = markQuotingsPattern.matcher(input);
54
55         return matcher.replaceAll("\n<font class=\"quoting\">$1$3</font>");
56     }
57
58     public static String JavaDoc addSmilies(String JavaDoc input) throws Exception JavaDoc {
59         Matcher JavaDoc matcher;
60
61         for (int i = 0; i < smilyPattern.length; i++) {
62             matcher = smilyPattern[i].matcher(input);
63             input = matcher.replaceAll("&nbsp<IMG SRC=\"" + smilyImage[i] +
64                     "\">");
65         }
66
67         return input;
68     }
69 }
70
Popular Tags