diff options
author | Yana Stamcheva <yana@jitsi.org> | 2013-02-22 10:26:23 +0000 |
---|---|---|
committer | Yana Stamcheva <yana@jitsi.org> | 2013-02-22 10:26:23 +0000 |
commit | 399d5ee1c672f2d610bc408d1511bb1ec3e02d23 (patch) | |
tree | b243cfd3443c606d0a4de5b5ad5f3f16926f1f43 /src/net | |
parent | 66584bbd44a85fe555e3083ff9140d2a161fa63a (diff) | |
download | jitsi-399d5ee1c672f2d610bc408d1511bb1ec3e02d23.zip jitsi-399d5ee1c672f2d610bc408d1511bb1ec3e02d23.tar.gz jitsi-399d5ee1c672f2d610bc408d1511bb1ec3e02d23.tar.bz2 |
Fixes <3 copying in the chat window. Patch provided by Hristo Terezov on dev (21/02/2013 subject: "[PATCH] Fix for copying text from the chat window that contains images").
Diffstat (limited to 'src/net')
4 files changed, 48 insertions, 28 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 f5c5d91..8c5f6b9 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 @@ -1126,7 +1126,7 @@ public class ChatConversationPanel if (processHTMLChars) { fromPrevEndToStart = - ChatHtmlUtils.escapeHTMLChars(fromPrevEndToStart); + GuiUtils.escapeHTMLChars(fromPrevEndToStart); } msgBuffer.append(fromPrevEndToStart); prevEnd = m.end(); @@ -1147,7 +1147,7 @@ public class ChatConversationPanel String fromPrevEndToEnd = message.substring(prevEnd); if (processHTMLChars) - fromPrevEndToEnd = ChatHtmlUtils.escapeHTMLChars(fromPrevEndToEnd); + fromPrevEndToEnd = GuiUtils.escapeHTMLChars(fromPrevEndToEnd); msgBuffer.append(fromPrevEndToEnd); return msgBuffer.toString(); @@ -1690,7 +1690,7 @@ public class ChatConversationPanel String endHeaderTag = "</I></B></DIV>"; chatString += - ChatHtmlUtils.escapeHTMLChars("*** " + chatMessage.getContactName() + GuiUtils.escapeHTMLChars("*** " + chatMessage.getContactName() + " " + message.substring(4)) + endHeaderTag; diff --git a/src/net/java/sip/communicator/impl/gui/main/chat/ChatHtmlUtils.java b/src/net/java/sip/communicator/impl/gui/main/chat/ChatHtmlUtils.java index 2fe344f..27d67f8 100644 --- a/src/net/java/sip/communicator/impl/gui/main/chat/ChatHtmlUtils.java +++ b/src/net/java/sip/communicator/impl/gui/main/chat/ChatHtmlUtils.java @@ -653,7 +653,7 @@ public class ChatHtmlUtils contactName)); messageTag.append(DATE_ATTRIBUTE + "=\"" + date + "\" "); messageTag.append(String.format("%s = '%s' ", - ORIGINAL_MESSAGE_ATTRIBUTE, escapeHTMLChars(message))); + ORIGINAL_MESSAGE_ATTRIBUTE, GuiUtils.escapeHTMLChars(message))); messageTag.append(IncomingMessageStyle .createSingleMessageStyle(isHistory, isEdited, true)); messageTag.append(">"); @@ -696,7 +696,7 @@ public class ChatHtmlUtils contactName)); messageTag.append(DATE_ATTRIBUTE + "=\"" + date + "\" "); messageTag.append(String.format("%s = '%s' ", - ORIGINAL_MESSAGE_ATTRIBUTE, escapeHTMLChars(message))); + ORIGINAL_MESSAGE_ATTRIBUTE, GuiUtils.escapeHTMLChars(message))); messageTag.append(IncomingMessageStyle .createSingleMessageStyle(isHistory, isEdited, false)); messageTag.append(">"); @@ -745,22 +745,4 @@ public class ChatHtmlUtils new String[]{GuiUtils.formatTime(date)}) + ")</font>"; } - - /** - * Escapes special HTML characters such as <, >, & and " in - * the specified message. - * - * @param message the message to be processed - * @return the processed message with escaped special HTML characters - */ - public static String escapeHTMLChars(String message) - { - return message - .replace("&", "&") - .replace("<", "<") - .replace(">", ">") - .replace("\"", """) - .replace("'", "'") - .replace("/", "/"); - } } diff --git a/src/net/java/sip/communicator/plugin/desktoputil/ExtendedTransferHandler.java b/src/net/java/sip/communicator/plugin/desktoputil/ExtendedTransferHandler.java index a65789d..50fc9f7 100644 --- a/src/net/java/sip/communicator/plugin/desktoputil/ExtendedTransferHandler.java +++ b/src/net/java/sip/communicator/plugin/desktoputil/ExtendedTransferHandler.java @@ -19,6 +19,8 @@ import javax.swing.text.*; import javax.swing.text.html.*; import java.util.regex.*; +import net.java.sip.communicator.util.*; + /** * A TransferHandler that we use to handle copying, pasting and DnD operations. @@ -212,26 +214,44 @@ public class ExtendedTransferHandler "[\\\"'](.*?)>"; Pattern p - = Pattern.compile(smileyHtmlPattern,Pattern.DOTALL); + = Pattern.compile(smileyHtmlPattern, Pattern.DOTALL); Matcher m = p.matcher(data); if(m.find()) { /* + * This loop replaces the IMG tags with the value of + * the ALT attribute. The value of the ALT attribute + * is escaped to prevent illegal parsing of special + * HTML chars (like "<", ">", "&") later. If the chars + * aren't escaped the parser will skip them. + */ + int start = 0; + String tempData = ""; + do + { + tempData += data.substring(start, m.start()) + + GuiUtils.escapeHTMLChars(m.group(2)); + start = m.end(); + } + while(m.find()); + tempData += data.substring(start); + + /* * Remove the PLAINTEXT tags because they brake the * HTML */ - data = data.replaceAll( + tempData = tempData.replaceAll( "<[/]*PLAINTEXT>.*<[/]*PLAINTEXT>", ""); /* * The getText method ignores the BR tag, * empty A tag is replaced with \n */ - data = data.replaceAll( + tempData = tempData.replaceAll( "<\\s*[bB][rR][^>]*>", "<a></a>"); - data = data.replaceAll(smileyHtmlPattern, "$2"); + htmlDoc.remove(0, htmlDoc.getLength()); - htmlKit.read(new StringReader(data), htmlDoc, 0); + htmlKit.read(new StringReader(tempData), htmlDoc, 0); srcData = htmlDoc.getText(0, htmlDoc.getLength()); } diff --git a/src/net/java/sip/communicator/util/GuiUtils.java b/src/net/java/sip/communicator/util/GuiUtils.java index 0cc288e..196dc8c 100644 --- a/src/net/java/sip/communicator/util/GuiUtils.java +++ b/src/net/java/sip/communicator/util/GuiUtils.java @@ -430,4 +430,22 @@ public class GuiUtils } return resultId; } + + /** + * Escapes special HTML characters such as <, >, & and " in + * the specified message. + * + * @param message the message to be processed + * @return the processed message with escaped special HTML characters + */ + public static String escapeHTMLChars(String message) + { + return message + .replace("&", "&") + .replace("<", "<") + .replace(">", ">") + .replace("\"", """) + .replace("'", "'") + .replace("/", "/"); + } } |