diff options
author | Damian Minkov <damencho@jitsi.org> | 2014-05-09 12:40:16 +0300 |
---|---|---|
committer | Damian Minkov <damencho@jitsi.org> | 2014-05-09 12:44:05 +0300 |
commit | f14f2e248a73011901d7fb439975f80b1f826cdf (patch) | |
tree | 7c0ab8b50584f5df9796aec675d49a33ef13302d /src/net/java/sip/communicator/impl/replacement/twitpic/ReplacementServiceTwitpicImpl.java | |
parent | b2d44ec255747e377283e97188aa102539d2b3d6 (diff) | |
download | jitsi-f14f2e248a73011901d7fb439975f80b1f826cdf.zip jitsi-f14f2e248a73011901d7fb439975f80b1f826cdf.tar.gz jitsi-f14f2e248a73011901d7fb439975f80b1f826cdf.tar.bz2 |
Do replacements only inside plaintext nodes or on link content, avoid replacing text in already replaced one. Fixes some replacement services.
Diffstat (limited to 'src/net/java/sip/communicator/impl/replacement/twitpic/ReplacementServiceTwitpicImpl.java')
-rw-r--r-- | src/net/java/sip/communicator/impl/replacement/twitpic/ReplacementServiceTwitpicImpl.java | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/src/net/java/sip/communicator/impl/replacement/twitpic/ReplacementServiceTwitpicImpl.java b/src/net/java/sip/communicator/impl/replacement/twitpic/ReplacementServiceTwitpicImpl.java index 1f87d49..23f7d98 100644 --- a/src/net/java/sip/communicator/impl/replacement/twitpic/ReplacementServiceTwitpicImpl.java +++ b/src/net/java/sip/communicator/impl/replacement/twitpic/ReplacementServiceTwitpicImpl.java @@ -5,6 +5,7 @@ */ package net.java.sip.communicator.impl.replacement.twitpic; +import java.net.*; import java.util.regex.*; import net.java.sip.communicator.service.replacement.*; @@ -29,7 +30,7 @@ public class ReplacementServiceTwitpicImpl * The regex used to match the link in the message. */ public static final String TWITPIC_PATTERN = - "(?<=>)http:\\/\\/(?:www\\.)?twitpic\\.com\\/([^\\/<]*)(?=</A>)"; + "http:\\/\\/(?:www\\.)?twitpic\\.com\\/([^\\/<]*)"; /** * Configuration label shown in the config form. @@ -70,6 +71,23 @@ public class ReplacementServiceTwitpicImpl thumbUrl = "http://twitpic.com/show/thumb/" + m.group(1); } + // check for redirect headers + try + { + HttpURLConnection con = (HttpURLConnection) + (new URL(thumbUrl).openConnection()); + con.setInstanceFollowRedirects(false); + con.connect(); + int responseCode = con.getResponseCode(); + if(responseCode == HttpURLConnection.HTTP_MOVED_TEMP + || responseCode == HttpURLConnection.HTTP_MOVED_PERM) + { + return con.getHeaderField("Location"); + } + } + catch(Throwable t) + {} + return thumbUrl; } |