001: /* CVS ID: $Id: Fancyfier.java,v 1.1.1.1 2002/10/02 18:42:54 wastl Exp $ */
002: package net.wastl.webmail.ui.html;
003:
004: import java.util.regex.*;
005:
006: /*
007: * Fancyfier.java
008: *
009: * Created: Mon Feb 22 14:55:36 1999
010: *
011: * Copyright (C) 1999-2000 Sebastian Schaffert
012: *
013: * This program is free software; you can redistribute it and/or
014: * modify it under the terms of the GNU General Public License
015: * as published by the Free Software Foundation; either version 2
016: * of the License, or (at your option) any later version.
017: *
018: * This program is distributed in the hope that it will be useful,
019: * but WITHOUT ANY WARRANTY; without even the implied warranty of
020: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
021: * GNU General Public License for more details.
022: *
023: * You should have received a copy of the GNU General Public License
024: * along with this program; if not, write to the Free Software
025: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
026: */
027:
028: /**
029: * Do some fancifying with the messages. Also filters JavaScript.
030: *
031: *
032: *
033: * Created: Mon Feb 22 14:55:36 1999
034: *
035: * @author Sebastian Schaffert
036: * @version $Revision: 1.1.1.1 $
037: */
038: public class Fancyfier {
039:
040: public Fancyfier() {
041:
042: }
043:
044: private static Pattern[] regs = null;
045: private static Pattern uri = null;
046:
047: private static String[] repls = {
048: "<IMG SRC=\"/images/emoticon11.gif\">",
049: "<IMG SRC=\"/images/emoticon12.gif\">",
050: "<IMG SRC=\"/images/emoticon13.gif\">",
051: "<IMG SRC=\"/images/emoticon14.gif\">",
052: "<IMG SRC=\"/images/emoticon11.gif\">",
053: "<IMG SRC=\"/images/emoticon12.gif\">",
054: "<IMG SRC=\"/images/emoticon13.gif\">",
055: "<IMG SRC=\"/images/emoticon14.gif\">",
056: "<IMG SRC=\"/images/emoticon21.gif\">",
057: "<IMG SRC=\"/images/emoticon22.gif\">",
058: "<IMG SRC=\"/images/emoticon23.gif\">",
059: "<IMG SRC=\"/images/emoticon24.gif\">",
060: "<IMG SRC=\"/images/emoticon31.gif\">",
061: "<IMG SRC=\"/images/emoticon32.gif\">",
062: "<IMG SRC=\"/images/emoticon33.gif\">",
063: "<IMG SRC=\"/images/emoticon34.gif\">",
064: "<IMG SRC=\"/images/emoticon41.gif\">",
065: "<IMG SRC=\"/images/emoticon42.gif\">",
066: "<IMG SRC=\"/images/emoticon43.gif\">",
067: "<IMG SRC=\"/images/emoticon44.gif\">",
068: "<IMG SRC=\"/images/emoticon51.gif\">",
069: "<IMG SRC=\"/images/emoticon52.gif\">", };
070:
071: public static void init() {
072: try {
073: // Smiley substitution
074: String[] temp = { ":-\\)", ":-\\(", ":-O", ":\\)", ":\\(",
075: ":O", ":\\|", ";-\\)", ";-\\(", ";-O", ";-\\|",
076: "B-\\)", "B-\\(", "B-O", "B-\\|", "%-\\)", "%-\\(",
077: "%-O", "%-\\|", ":-X", "\\}:->" };
078: regs = new Pattern[temp.length];
079: for (int i = 0; i < temp.length; i++) {
080: regs[i] = Pattern.compile(temp[i]);
081: }
082: // Link highlighting
083: //uri=new RE("http\\:\\/\\/(.+)(html|\\/)(\\S|\\-|\\+|\\.|\\\|\\:)");
084:
085: } catch (Exception e) {
086: e.printStackTrace();
087: }
088: }
089:
090: public static String apply(String s) {
091: if (regs == null) {
092: init();
093: }
094: String retval = s;
095: for (int i = 0; i < regs.length; i++) {
096: Matcher m = regs[i].matcher(retval);
097: retval = m.replaceAll(repls[i]);
098: //retval=regs[i].substituteAll(retval,repls[i]);
099: }
100: return retval;
101: }
102:
103: } // Fancyfier
|