aboutsummaryrefslogtreecommitdiffstats
path: root/src/net/java/sip/communicator/impl/replacement/bliptv
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/bliptv
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/bliptv')
-rw-r--r--src/net/java/sip/communicator/impl/replacement/bliptv/ReplacementServiceBliptvImpl.java101
1 files changed, 39 insertions, 62 deletions
diff --git a/src/net/java/sip/communicator/impl/replacement/bliptv/ReplacementServiceBliptvImpl.java b/src/net/java/sip/communicator/impl/replacement/bliptv/ReplacementServiceBliptvImpl.java
index d51bd36..fcd885b 100644
--- a/src/net/java/sip/communicator/impl/replacement/bliptv/ReplacementServiceBliptvImpl.java
+++ b/src/net/java/sip/communicator/impl/replacement/bliptv/ReplacementServiceBliptvImpl.java
@@ -33,7 +33,8 @@ public class ReplacementServiceBliptvImpl
* The regex used to match the link in the message.
*/
public static final String BLIPTV_PATTERN =
- "(?:[\\>])(http:\\/\\/(?:www\\.)?blip\\.tv\\/file\\/(\\d+).*(?=<))";
+ "(?<=>)(http:\\/\\/(?:www\\.)?blip\\.tv"
+ + "\\/file\\/(\\d+)([?&\\?]\\w+=[\\w-]+)*)(?=</A>)";
/**
* Configuration label shown in the config form.
@@ -44,7 +45,7 @@ public class ReplacementServiceBliptvImpl
* Source name; also used as property label.
*/
public static final String SOURCE_NAME = "BLIPTV";
-
+
/**
* Constructor for <tt>ReplacementServiceBliptvImpl</tt>.
*/
@@ -54,81 +55,47 @@ public class ReplacementServiceBliptvImpl
}
/**
- * Replaces the Blip.tv video links in the chat message with their
- * corresponding thumbnails.
- *
- * @param chatString the original chat message.
- * @return replaced chat message with the thumbnail image; the original
- * message in case of no match.
+ * Replaces the Blip.tv video links with their corresponding thumbnails.
+ *
+ * @param sourceString the original chat message.
+ * @return replaced thumbnail image link; the original video link in case of
+ * no match.
*/
- public String getReplacedMessage(String chatString)
+ public String getReplacement(String sourceString)
{
- final Pattern p =
- Pattern.compile(BLIPTV_PATTERN, Pattern.CASE_INSENSITIVE
- | Pattern.DOTALL);
- Matcher m = p.matcher(chatString);
-
- int count = 0, startPos = 0;
- StringBuffer msgBuff = new StringBuffer();
-
- while (m.find())
+ try
{
- count++;
- msgBuff.append(chatString.substring(startPos, m.start()));
- startPos = m.end();
-
- try
- {
- String url = "http://oohembed.com/oohembed/?url=" + m.group(1);
+ String url = "http://oohembed.com/oohembed/?url=" + sourceString;
- URL sourceURL = new URL(url);
- URLConnection conn = sourceURL.openConnection();
+ URL sourceURL = new URL(url);
+ URLConnection conn = sourceURL.openConnection();
- BufferedReader in =
- new BufferedReader(new InputStreamReader(conn
- .getInputStream()));
+ BufferedReader in =
+ new BufferedReader(new InputStreamReader(conn.getInputStream()));
- String inputLine, holder = "";
+ String inputLine, holder = "";
- while ((inputLine = in.readLine()) != null)
- holder += inputLine;
- in.close();
+ while ((inputLine = in.readLine()) != null)
+ holder += inputLine;
+ in.close();
- JSONObject wrapper = new JSONObject(holder);
+ JSONObject wrapper = new JSONObject(holder);
- String thumbUrl = wrapper.getString("thumbnail_url");
+ String thumbUrl = wrapper.getString("thumbnail_url");
- if (thumbUrl != null)
- {
- msgBuff.append("<IMG HEIGHT=\"90\" WIDTH=\"120\" SRC=\"");
- msgBuff.append(thumbUrl);
- msgBuff.append("\"></IMG>");
-
- }
- else
- {
- startPos = 0;
- msgBuff = new StringBuffer();
- }
-
- }
- catch (Exception e)
+ if (thumbUrl != null)
{
- startPos = 0;
- msgBuff = new StringBuffer();
- e.printStackTrace();
+ return thumbUrl;
}
-
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
}
- msgBuff.append(chatString.substring(startPos));
-
- if (!msgBuff.toString().equals(chatString))
- return msgBuff.toString();
-
- return chatString;
+ return sourceString;
}
-
+
/**
* Returns the source name
*
@@ -138,4 +105,14 @@ public class ReplacementServiceBliptvImpl
{
return SOURCE_NAME;
}
+
+ /**
+ * Returns the pattern of the source
+ *
+ * @return the source pattern
+ */
+ public String getPattern()
+ {
+ return BLIPTV_PATTERN;
+ }
} \ No newline at end of file