From e813127908039b09db8dd5acc2e8c59725996602 Mon Sep 17 00:00:00 2001 From: Yana Stamcheva Date: Tue, 25 Sep 2007 11:56:41 +0000 Subject: [PATCH] Fixed problem with smilies for Yahoo protocol. Details: removeAltFromHTMLSmilies method was matching a wrong regular expression. This method was removed and we are now using a "negative look-behind" to exclude smilies inside alt tags. --- .../gui/main/chat/ChatConversationPanel.java | 69 ++----------------- 1 file changed, 5 insertions(+), 64 deletions(-) diff --git a/src/net/java/sip/communicator/impl/gui/main/chat/ChatConversationPanel.java b/src/net/java/sip/communicator/impl/gui/main/chat/ChatConversationPanel.java index b66ae4d97..dab4d7033 100755 --- a/src/net/java/sip/communicator/impl/gui/main/chat/ChatConversationPanel.java +++ b/src/net/java/sip/communicator/impl/gui/main/chat/ChatConversationPanel.java @@ -588,7 +588,7 @@ else if(contentType.equals(HTML_CONTENT_TYPE)) processedString = processImgTags(processedString, contentType); } - + return processSmilies(processedString, contentType); } @@ -686,11 +686,6 @@ private String processSmilies(String message, String contentType) } else { - if (HTML_CONTENT_TYPE.equals(contentType)) - { - message = removeAltFromHTMLSmilies(message); - } - startPlainTextTag = ""; endPlainTextTag = ""; } @@ -699,6 +694,8 @@ private String processSmilies(String message, String contentType) StringBuffer regexp = new StringBuffer(); + regexp.append("(? tag in the - * processSmilies method and this will cause having an tag within - * another tag and a malformatted html. - * - * @param content the message content - * @return formatted messages content - */ - private String removeAltFromHTMLSmilies(String content) - { - StringBuffer result = new StringBuffer(); - StringBuffer smileyRegexp = new StringBuffer(); - - //building supported smilies list - ArrayList smiliesList = ImageLoader.getDefaultSmiliesPack(); - for (int i = 0; i < smiliesList.size(); i++) - { - Smiley smiley = (Smiley) smiliesList.get(i); - String[] smileyStrings = smiley.getSmileyStrings(); - - for(int j = 0; j < smileyStrings.length; j++) - { - smileyRegexp.append(GuiUtils.replaceSpecialRegExpChars( - smileyStrings[j])).append("|"); - } - } - smileyRegexp.deleteCharAt(smileyRegexp.length() - 1); - - //creating pattern string. we want to remove all smilies that appear - //in the 'alt' attribute of an '' tag, like :) - String imgPattern = ""; - - Pattern p = Pattern.compile(imgPattern, Pattern.CASE_INSENSITIVE); - Matcher imgFinder = p.matcher(content); - - boolean foundMatch = false; - - //creating escaped message - while (imgFinder.find()) - { - if (!foundMatch) - foundMatch = true; - - String matchGroup = imgFinder.group(); - String replacement = - matchGroup.replaceAll(smileyRegexp.toString(), ""); - imgFinder.appendReplacement(result, - GuiUtils.replaceSpecialRegExpChars(replacement)); - } - imgFinder.appendTail(result); - - return result.toString(); - } - /** * Opens a link in the default browser when clicked and shows link url in a * popup on mouseover.