aboutsummaryrefslogtreecommitdiffstats
path: root/src/net/java/sip/communicator/impl/replacement/smiley
diff options
context:
space:
mode:
authorYana Stamcheva <yana@jitsi.org>2010-09-15 15:57:40 +0000
committerYana Stamcheva <yana@jitsi.org>2010-09-15 15:57:40 +0000
commite36f654bb3ed43fdad82905a1cd30f0fa09293e1 (patch)
tree688d69decd4ad160fb8d7e00582b3af1d1e8dee9 /src/net/java/sip/communicator/impl/replacement/smiley
parent8f01ecde7408b0d13d5e6f7eee2e8632354a9353 (diff)
downloadjitsi-e36f654bb3ed43fdad82905a1cd30f0fa09293e1.zip
jitsi-e36f654bb3ed43fdad82905a1cd30f0fa09293e1.tar.gz
jitsi-e36f654bb3ed43fdad82905a1cd30f0fa09293e1.tar.bz2
Patch provided by Purvesh Sahoo, fixing redundant code in replacement implementations + removed replacement blue borders
Diffstat (limited to 'src/net/java/sip/communicator/impl/replacement/smiley')
-rw-r--r--src/net/java/sip/communicator/impl/replacement/smiley/ReplacementServiceSmileyImpl.java104
1 files changed, 39 insertions, 65 deletions
diff --git a/src/net/java/sip/communicator/impl/replacement/smiley/ReplacementServiceSmileyImpl.java b/src/net/java/sip/communicator/impl/replacement/smiley/ReplacementServiceSmileyImpl.java
index 6863954..d954f2c 100644
--- a/src/net/java/sip/communicator/impl/replacement/smiley/ReplacementServiceSmileyImpl.java
+++ b/src/net/java/sip/communicator/impl/replacement/smiley/ReplacementServiceSmileyImpl.java
@@ -6,7 +6,6 @@
package net.java.sip.communicator.impl.replacement.smiley;
import java.util.*;
-import java.util.regex.*;
import net.java.sip.communicator.service.replacement.*;
import net.java.sip.communicator.service.replacement.smilies.*;
@@ -23,97 +22,60 @@ public class ReplacementServiceSmileyImpl
implements SmiliesReplacementService
{
/**
- * The compiled <tt>Pattern</tt> which matches {@link #smileyStrings}.
- */
- private static Pattern smileyPattern;
-
- /**
* The <tt>List</tt> of smiley strings which are matched by
- * {@link #smileyPattern}.
+ * {@link #smileyRegex}.
*/
private static final java.util.List<String> smileyStrings =
new ArrayList<String>();
/**
- * The closing tag of the <code>PLAINTEXT</code> HTML element.
- */
- private static final String END_PLAINTEXT_TAG = "</PLAINTEXT>";
-
- /**
- * The opening tag of the <code>PLAINTEXT</code> HTML element.
+ * Configuration label shown in the config form.
*/
- private static final String START_PLAINTEXT_TAG = "<PLAINTEXT>";
+ public static final String SMILEY_SOURCE = "SMILEY";
/**
- * Configuration label shown in the config form.
+ * The regex used to match the smileys in the message.
*/
- public static final String SMILEY_SOURCE = "SMILEY";
+ public static String smileyRegex;
/**
- * Replaces the smiley strings in the chat message with their
- * corresponding smiley image.
- *
- * @param chatString the original chat message.
- * @return replaced chat message with the smiley images; the original
- * message in case of no match.
+ * Replaces the smiley strings with their corresponding smiley image.
+ *
+ * @param sourceString the original smiley string.
+ * @return the smiley image replaced for the smiley string; the original
+ * smiley string in case of no match.
*/
- public String getReplacedMessage(final String chatString)
+ public String getReplacement(final String sourceString)
{
- String startPlainTextTag = START_PLAINTEXT_TAG;
- String endPlainTextTag = END_PLAINTEXT_TAG;
- Collection<Smiley> smilies = Resources.getDefaultSmileyPack();
-
- Matcher m = getSmileyPattern(smilies).matcher(chatString);
- StringBuffer msgBuffer = new StringBuffer();
-
- int prevEnd = 0;
-
- while (m.find())
+ try
{
- msgBuffer.append(chatString.substring(prevEnd, m.start()));
- prevEnd = m.end();
-
- String smileyString = m.group().trim();
-
- msgBuffer.append(endPlainTextTag);
- msgBuffer.append("<IMG SRC=\"");
- try
- {
- msgBuffer.append(
- Resources.getSmiley(smileyString).getImagePath());
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- msgBuffer.append("\" ALT=\"");
- msgBuffer.append(smileyString);
- msgBuffer.append("\"></IMG>");
- msgBuffer.append(startPlainTextTag);
-
+ return Resources.getSmiley(sourceString.trim()).getImagePath();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
}
- msgBuffer.append(chatString.substring(prevEnd));
- return msgBuffer.toString();
+ return sourceString;
}
/**
- * Gets a compiled <tt>Pattern</tt> which matches the smiley strings of the
- * specified <tt>Collection</tt> of <tt>Smiley</tt>s.
+ * Gets a regex string which matches the smiley strings of the specified
+ * <tt>Collection</tt> of <tt>Smiley</tt>s.
*
* @param smileys the <tt>Collection</tt> of <tt>Smiley</tt>s for which to
* get a compiled <tt>Pattern</tt> which matches its smiley
* strings
- * @return a compiled <tt>Pattern</tt> which matches the smiley strings of
- * the specified <tt>Collection</tt> of <tt>Smiley</tt>s
+ * @return a regex string which matches the smiley strings of the specified
+ * <tt>Collection</tt> of <tt>Smiley</tt>s
*/
- private static Pattern getSmileyPattern(Collection<Smiley> smileys)
+ private static String getSmileyPattern(Collection<Smiley> smileys)
{
synchronized (smileyStrings)
{
boolean smileyStringsIsEqual;
- if (smileyPattern == null)
+ if (smileyRegex == null)
smileyStringsIsEqual = false;
else
{
@@ -157,15 +119,15 @@ public class ReplacementServiceSmileyImpl
regex = regex.deleteCharAt(regex.length() - 1);
regex.append(')');
- smileyPattern = Pattern.compile(regex.toString());
+ smileyRegex = regex.toString();
}
- return smileyPattern;
+ return smileyRegex;
}
}
/**
* Returns the source name
- *
+ *
* @return the source name
*/
public String getSourceName()
@@ -174,7 +136,19 @@ public class ReplacementServiceSmileyImpl
}
/**
+ * Returns the pattern of the source
+ *
+ * @return the source pattern
+ */
+ public String getPattern()
+ {
+ Collection<Smiley> smileys = Resources.getDefaultSmileyPack();
+ return getSmileyPattern(smileys);
+ }
+
+ /**
* Returns the smileys pack to use in the user interface.
+ *
* @return a collection of all smileys available
*/
public Collection<Smiley> getSmiliesPack()