1 34 package net.myvietnam.mvncore.filter; 35 36 public final class EnableEmotionFilter { 37 38 private EnableEmotionFilter() { } 40 41 static String [][] emotion = { 43 { "[:))]", "laughing.gif", "laughing"}, 45 { "[:)]", "smile.gif", "smile"}, 46 { "[:-)]", "smile.gif", "smile"}, 47 { "[:((]", "crying.gif", "crying"}, 48 { "[:(]", "sad.gif", "sad"}, 49 { "[:-(]", "sad.gif", "sad"}, 50 { "[;)]", "wink.gif", "wink"}, 51 { "[:D]", "biggrin.gif", "biggrin"}, 52 { "[;;)]", "batting_eyelashes.gif","batting eyelashes"}, 53 { "[:-/]", "confused.gif", "confused"}, 54 { "[:x]", "love.gif", "love struck"}, 55 56 { "[:\">]", "blushing.gif", "blushing"}, 57 { "[:">]", "blushing.gif", "blushing"}, 58 59 { "[:p]", "tongue.gif", "tongue"}, 60 { "[:*]", "kiss.gif", "kiss"}, 61 { "[:O]", "shock.gif", "shock"}, 62 { "[X-(]", "angry.gif", "angry"}, 63 64 { "[:>]", "smug.gif", "smug"}, 65 { "[:>]", "smug.gif", "smug"}, 66 67 { "[B-)]", "cool.gif", "cool"}, 68 { "[:-s]", "worried.gif", "worried"}, 69 70 { "[>:)]", "devilish.gif", "devilish"}, 71 { "[>:)]", "devilish.gif", "devilish"}, 72 73 { "[:|]", "straight_face.gif", "straight face"}, 74 { "[/:)]", "raised_eyebrow.gif", "raised eyebrow"}, 75 { "[O:)]", "angel.gif", "angel"}, 76 { "[:-B]", "nerd.gif", "nerd"}, 77 { "[=;]", "talk_to_the_hand.gif", "talk to the hand"}, 78 { "[I-)]", "sleep.gif", "sleep"}, 79 { "[8-|]", "rolling_eyes.gif", "rolling eyes"}, 80 81 { "[:-&]", "sick.gif", "sick"}, 82 { "[:-&]", "sick.gif", "sick"}, 83 84 { "[:-$]", "shhh.gif", "shhh"}, 85 { "[[-(]", "not_talking.gif", "not talking"}, 86 { "[:o)]", "clown.gif", "clown"}, 87 { "[8-}]", "silly.gif", "silly"}, 88 { "[(:|]", "tired.gif", "tired"}, 89 { "[=P~]", "drooling.gif", "drooling"}, 90 { "[:-?]", "thinking.gif", "thinking"}, 91 { "[#-o]", "d_oh.gif", "d oh"}, 92 93 { "[=D>]", "applause.gif", "applause"}, 94 { "[=D>]", "applause.gif", "applause"}, 95 { "[:@)]", "pig.gif", "pig"}, 97 { "[3:-O]", "cow.gif", "cow"}, 98 { "[:(|)]", "monkey.gif", "monkey"}, 99 100 { "[~:>]", "chicken.gif", "chicken"}, 101 { "[~:>]", "chicken.gif", "chicken"}, 102 103 { "[@};-]", "rose.gif", "rose"}, 104 { "[%%-]", "good_luck.gif", "good luck"}, 105 { "[**==]", "flag.gif", "flag"}, 106 { "[(~~)]", "pumpkin.gif", "pumpkin"}, 107 { "[~o)]", "coffee.gif", "coffee"}, 108 { "[*-:)]", "idea.gif", "idea"}, 109 { "[8-X]", "skull.gif", "skull"}, 110 { "[=:)]", "alien_1.gif", "alien 1"}, 111 112 { "[>-)]", "alien_2.gif", "alien 2"}, 113 { "[>-)]", "alien_2.gif", "alien 2"}, 114 115 { "[:-L]", "frustrated.gif", "frustrated"}, 116 117 { "[<):)]", "cowboy.gif", "cowboy"}, 118 { "[<):)]", "cowboy.gif", "cowboy"}, 119 120 { "[[-o<]", "praying.gif", "praying"}, 121 { "[[-o<]", "praying.gif", "praying"}, 122 123 { "[@-)]", "hypnotized.gif", "hypnotized"}, 124 { "[$-)]", "money_eyes.gif", "money eyes"}, 125 126 { "[:-\"]", "whistling.gif", "whistling"}, 127 { "[:-"]", "whistling.gif", "whistling"}, 128 129 { "[:^o]", "liar.gif", "liar"}, 130 { "[b-(]", "beat_up.gif", "beat up"}, 131 132 { "[:)>-]", "peace.gif", "peace"}, 133 { "[:)>-]", "peace.gif", "peace"}, 134 135 { "[[-X]", "shame_on_you.gif", "shame on you"}, 136 { "[\\:D/]", "dancing.gif", "dancing"}, 137 138 { "[>:D<]", "hugs.gif", "hugs"}, 139 { "[>:D<]", "hugs.gif", "hugs"}, 140 }; 141 142 public static String filter(String input, String emotionFolder) { 143 if (input == null) return null; 144 145 int beginIndex = 0; 146 int currentBracketIndex = 0; 147 int inputLength = input.length(); 148 int emotionLength = emotion.length; 149 StringBuffer output = new StringBuffer (inputLength * 2); 150 151 if (emotionFolder.endsWith("/") == false) { 152 emotionFolder = emotionFolder + "/"; 153 } 154 155 while(beginIndex < inputLength) { 156 currentBracketIndex = input.indexOf('[', beginIndex); 157 if (currentBracketIndex == -1) { String remain = input.substring(beginIndex, inputLength); 159 output.append(remain); 160 break; 161 } 162 163 String remain = input.substring(beginIndex, currentBracketIndex); output.append(remain); 166 boolean matchFound = false; 167 168 for (int i = 0; i < emotionLength; i++) { 170 String currentEmotion = emotion[i][0]; 171 int endIndex = currentBracketIndex + currentEmotion.length(); 172 if (endIndex > inputLength) continue; 173 String match = input.substring(currentBracketIndex, endIndex); 174 if (currentEmotion.equals(match)) { 175 String imgTag = "<img SRC='" + emotionFolder + emotion[i][1] + "' border='0' alt='" + emotion[i][2] + "' title='" + emotion[i][2] + "'>"; 176 output.append(imgTag); 177 beginIndex = currentBracketIndex + currentEmotion.length(); 178 matchFound = true; 179 break; 180 } 181 } 183 if (matchFound == false) { 184 beginIndex = currentBracketIndex + 1; 185 output.append('['); 186 } 187 } 189 return output.toString(); 190 } 191 208 } 209 | Popular Tags |