aboutsummaryrefslogtreecommitdiffstats
path: root/src/net/java/sip/communicator/impl/replacement/twitpic/ReplacementServiceTwitpicImpl.java
diff options
context:
space:
mode:
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.java20
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;
}