diff options
Diffstat (limited to 'src/net')
15 files changed, 406 insertions, 225 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 2280ca9..7166164 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 @@ -37,7 +37,9 @@ import net.java.sip.communicator.service.replacement.*; import net.java.sip.communicator.service.replacement.directimage.*; import net.java.sip.communicator.service.replacement.smilies.*; import net.java.sip.communicator.util.*; +import net.java.sip.communicator.util.Logger; import net.java.sip.communicator.util.skin.*; +import org.jitsi.util.*; /** * The <tt>ChatConversationPanel</tt> is the panel, where all sent and received @@ -87,6 +89,18 @@ public class ChatConversationPanel Pattern.compile("(<div[^>]*>)(.*)(</div>)", Pattern.DOTALL); /** + * Extracting text from plaintext tags or content of anchors, + * text to be replaced. + */ + private static final Pattern TEXT_TO_REPLACE_PATTERN = + Pattern.compile( + ChatHtmlUtils.START_PLAINTEXT_TAG + + "(.*?)" + + ChatHtmlUtils.END_PLAINTEXT_TAG + + "|<a[^>]+>(.+?)</a>", + Pattern.CASE_INSENSITIVE | Pattern.DOTALL); + + /** * List for observing text messages. */ private Set<ChatLinkClickedListener> chatLinkClickedListeners = @@ -854,205 +868,11 @@ public class ChatConversationPanel * @param chatString the message. * @param contentType */ - void processReplacement(final String messageID, - final String chatString, - final String contentType) + void processReplacement(String messageID, + String chatString, + String contentType) { - SwingWorker worker = new SwingWorker() - { - /** - * Called on the event dispatching thread (not on the worker thread) - * after the <code>construct</code> method has returned. - */ - @Override - public void finished() - { - String newMessage = (String) get(); - - if (newMessage != null && !newMessage.equals(chatString)) - { - showPreview.getMsgIDToChatString().put( - messageID, newMessage); - synchronized (scrollToBottomRunnable) - { - scrollToBottomIsPending = true; - - try - { - Element elem = document.getElement(messageID); - document.setOuterHTML(elem, newMessage); - } - catch (BadLocationException ex) - { - logger.error("Could not replace chat message", ex); - } - catch (IOException ex) - { - logger.error("Could not replace chat message", ex); - } - } - } - } - - @Override - public Object construct() throws Exception - { - ConfigurationService cfg - = GuiActivator.getConfigurationService(); - boolean isEnabled - = cfg.getBoolean( - ReplacementProperty.REPLACEMENT_ENABLE, - true); - boolean isProposalEnabled - = cfg.getBoolean( - ReplacementProperty.REPLACEMENT_PROPOSAL, - true); - Matcher divMatcher = DIV_PATTERN.matcher(chatString); - String openingTag = ""; - String msgStore = chatString; - String closingTag = ""; - if (divMatcher.find()) - { - openingTag = divMatcher.group(1); - msgStore = divMatcher.group(2); - closingTag = divMatcher.group(3); - } - - int linkCounter = 0; - for (Map.Entry<String, ReplacementService> entry - : GuiActivator.getReplacementSources().entrySet()) - { - ReplacementService source = entry.getValue(); - - boolean isSmiley - = source instanceof SmiliesReplacementService; - boolean isDirectImage - = source instanceof DirectImageReplacementService; - boolean isEnabledForSource - = cfg.getBoolean( - ReplacementProperty.getPropertyName( - source.getSourceName()), true); - - String sourcePattern = source.getPattern(); - Pattern p - = Pattern.compile( - sourcePattern, - Pattern.CASE_INSENSITIVE | Pattern.DOTALL); - Matcher m = p.matcher(msgStore); - StringBuilder msgBuff = new StringBuilder(); - int startPos = 0; - - while (m.find()) - { - msgBuff.append(msgStore.substring(startPos, m.start())); - startPos = m.end(); - - String group = m.group(); - String temp = source.getReplacement(group); - String group0 = m.group(0); - - if(!temp.equals(group0) || isDirectImage) - { - if (isSmiley) - { - if (cfg.getBoolean(ReplacementProperty. - getPropertyName("SMILEY"), - true)) - { - msgBuff.append( - ChatHtmlUtils.createEndPlainTextTag( - contentType)); - msgBuff.append("<IMG SRC=\""); - msgBuff.append(temp); - msgBuff.append("\" BORDER=\"0\" ALT=\""); - msgBuff.append(group0); - msgBuff.append("\"></IMG>"); - msgBuff.append( - ChatHtmlUtils.createStartPlainTextTag( - contentType)); - } - else - { - msgBuff.append(group); - } - } - else if (isEnabled && isEnabledForSource) - { - if (isDirectImage) - { - DirectImageReplacementService service - = (DirectImageReplacementService)source; - if (service.isDirectImage(group) - && service.getImageSize(group) != -1) - { - msgBuff.append( - "<IMG HEIGHT=\"90\" " - + "WIDTH=\"120\" SRC=\""); - msgBuff.append(temp); - msgBuff.append("\" BORDER=\"0\" ALT=\""); - msgBuff.append(group0); - msgBuff.append("\"></IMG>"); - } - else - { - msgBuff.append(group); - } - } - else - { - msgBuff.append( - "<IMG HEIGHT=\"90\" " - + "WIDTH=\"120\" SRC=\""); - msgBuff.append(temp); - msgBuff.append("\" BORDER=\"0\" ALT=\""); - msgBuff.append(group0); - msgBuff.append("\"></IMG>"); - } - } - else if (isProposalEnabled) - { - msgBuff.append(group); - msgBuff.append( - "</A> <A href=\"jitsi://" - + showPreview.getClass().getName() - + "/SHOWPREVIEW?" + messageID + "#" - + linkCounter + "\">" - + GuiActivator.getResources(). - getI18NString("service.gui.SHOW_PREVIEW")); - - showPreview.getMsgIDandPositionToLink() - .put( - messageID + "#" + linkCounter++, group); - showPreview.getLinkToReplacement() - .put( - group, temp); - } - else - { - msgBuff.append(group); - } - } - else - { - msgBuff.append(group); - } - } - - msgBuff.append(msgStore.substring(startPos)); - - /* - * replace the msgStore variable with the current replaced - * message before next iteration - */ - String msgBuffString = msgBuff.toString(); - - if (!msgBuffString.equals(msgStore)) - msgStore = msgBuffString; - } - return openingTag + msgStore + closingTag; - } - }; - worker.start(); + new ReplacementWorker(messageID, chatString, contentType).start(); } /** @@ -2255,4 +2075,316 @@ public class ChatConversationPanel } catch(Throwable t){} } } + + /** + * Swing worker used by processReplacement. + */ + private class ReplacementWorker + extends SwingWorker + { + /** + * The messageID element. + */ + private final String messageID; + + /** + * The message. + */ + private final String chatString; + + /** + * The content type of the message. + */ + private final String contentType; + + /** + * Counts links while processing. Used to generate unique href. + */ + private int linkCounter = 0; + + /** + * Is image replacement enabled. + */ + private final boolean isEnabled; + + /** + * Is replacement proposal enabled. + */ + private final boolean isProposalEnabled; + + /** + * Constructs worker. + * @param messageID the messageID element. + * @param chatString the messages. + * @param contentType the message content type. + */ + private ReplacementWorker( + String messageID, String chatString, String contentType) + { + this.messageID = messageID; + this.chatString = chatString; + this.contentType = contentType; + + ConfigurationService cfg = GuiActivator.getConfigurationService(); + isEnabled = cfg.getBoolean( + ReplacementProperty.REPLACEMENT_ENABLE, + true); + isProposalEnabled + = cfg.getBoolean( + ReplacementProperty.REPLACEMENT_PROPOSAL, + true); + } + + /** + * Called on the event dispatching thread (not on the worker thread) + * after the <code>construct</code> method has returned. + */ + @Override + public void finished() + { + String newMessage = (String) get(); + + if (newMessage != null && !newMessage.equals(chatString)) + { + showPreview.getMsgIDToChatString().put( + messageID, newMessage); + synchronized (scrollToBottomRunnable) + { + scrollToBottomIsPending = true; + + try + { + Element elem = document.getElement(messageID); + document.setOuterHTML(elem, newMessage); + } + catch (BadLocationException ex) + { + logger.error("Could not replace chat message", ex); + } + catch (IOException ex) + { + logger.error("Could not replace chat message", ex); + } + } + } + } + + @Override + public Object construct() throws Exception + { + Matcher divMatcher = DIV_PATTERN.matcher(chatString); + String openingTag = ""; + String msgStore = chatString; + String closingTag = ""; + if (divMatcher.find()) + { + openingTag = divMatcher.group(1); + msgStore = divMatcher.group(2); + closingTag = divMatcher.group(3); + } + + StringBuilder msgBuff; + for (Map.Entry<String, ReplacementService> entry + : GuiActivator.getReplacementSources().entrySet()) + { + msgBuff = new StringBuilder(); + processReplacementService(entry.getValue(), msgStore, msgBuff); + msgStore = msgBuff.toString(); + } + + return openingTag + msgStore + closingTag; + } + + /** + * Process message for a ReplacementService. + * @param service the service. + * @param msg the message. + * @param buff current accumulated buffer. + */ + private void processReplacementService(ReplacementService service, + String msg, + StringBuilder buff) + { + String sourcePattern = service.getPattern(); + Pattern pattern + = Pattern.compile( + sourcePattern, Pattern.CASE_INSENSITIVE | Pattern.DOTALL); + + int startPos = 0; + + Matcher plainTextMatcher = TEXT_TO_REPLACE_PATTERN.matcher(msg); + while(plainTextMatcher.find()) + { + // our match pattern detects plaintexts or links + // the first group is when it detects a plaintext nodes + // second one is the text inside anchor + + String text = plainTextMatcher.group(1); + int startMatchPosition = plainTextMatcher.start(1); + int endMatchPosition = plainTextMatcher.end(1); + // when processing links content we skip processing smileys + // or we will replace stuff like :p in the links + boolean skipSmileys = false; + + if(text == null) + { + text = plainTextMatcher.group(2); + startMatchPosition = plainTextMatcher.start(2); + endMatchPosition = plainTextMatcher.end(2); + skipSmileys = true; + } + + // don't process nothing + // or don't process already processed links content + if(!StringUtils.isNullOrEmpty(text) + && !(skipSmileys && text.startsWith("<I"))) + { + // always add from the end of previous match, to current one + // or from the start to the first match + buff.append( + msg.substring(startPos, startMatchPosition)); + + processText( + text, + buff, + pattern, + service, + skipSmileys); + + startPos = endMatchPosition; + } + } + + // add end from startPos to end + buff.append(msg.substring(startPos)); + } + + /** + * Process content between plaintext nodes. + * @param plainText the nodes text. + * @param msgBuff the currently accumulated buffer. + * @param pattern the pattern for current replacement service, + * created earlier so we don't create it for every text we check. + * @param rService the replacement service. + * @param skipSmileys whether to skip processing smileys + */ + private void processText(String plainText, + StringBuilder msgBuff, + Pattern pattern, + ReplacementService rService, + boolean skipSmileys) + { + Matcher m = pattern.matcher(plainText); + + ConfigurationService cfg = GuiActivator.getConfigurationService(); + boolean isSmiley + = rService instanceof SmiliesReplacementService; + boolean isDirectImage + = rService instanceof DirectImageReplacementService; + boolean isEnabledForSource + = cfg.getBoolean( + ReplacementProperty.getPropertyName( + rService.getSourceName()), true); + + int startPos = 0; + while (m.find()) + { + msgBuff.append(plainText.substring(startPos, m.start())); + startPos = m.end(); + + String group = m.group(); + String temp = rService.getReplacement(group); + String group0 = m.group(0); + + if(!temp.equals(group0) || isDirectImage) + { + if (isSmiley) + { + if (cfg.getBoolean(ReplacementProperty. + getPropertyName("SMILEY"), + true) + && !skipSmileys) + { + msgBuff.append( + ChatHtmlUtils.createEndPlainTextTag( + contentType)); + msgBuff.append("<IMG SRC=\""); + msgBuff.append(temp); + msgBuff.append("\" BORDER=\"0\" ALT=\""); + msgBuff.append(group0); + msgBuff.append("\"></IMG>"); + msgBuff.append( + ChatHtmlUtils.createStartPlainTextTag( + contentType)); + } + else + { + msgBuff.append(group); + } + } + else if (isEnabled && isEnabledForSource) + { + if (isDirectImage) + { + DirectImageReplacementService service + = (DirectImageReplacementService)rService; + if (service.isDirectImage(group) + && service.getImageSize(group) != -1) + { + msgBuff.append( + "<IMG HEIGHT=\"90\" " + + "WIDTH=\"120\" SRC=\""); + msgBuff.append(temp); + msgBuff.append("\" BORDER=\"0\" ALT=\""); + msgBuff.append(group0); + msgBuff.append("\"></IMG>"); + } + else + { + msgBuff.append(group); + } + } + else + { + msgBuff.append( + "<IMG HEIGHT=\"90\" " + + "WIDTH=\"120\" SRC=\""); + msgBuff.append(temp); + msgBuff.append("\" BORDER=\"0\" ALT=\""); + msgBuff.append(group0); + msgBuff.append("\"></IMG>"); + } + } + else if (isProposalEnabled) + { + msgBuff.append(group); + msgBuff.append( + "</A> <A href=\"jitsi://" + + showPreview.getClass().getName() + + "/SHOWPREVIEW?" + messageID + "#" + + linkCounter + "\">" + + GuiActivator.getResources(). + getI18NString("service.gui.SHOW_PREVIEW")); + + showPreview.getMsgIDandPositionToLink() + .put( + messageID + "#" + linkCounter++, group); + showPreview.getLinkToReplacement() + .put( + group, temp); + } + else + { + msgBuff.append(group); + } + } + else + { + msgBuff.append(group); + } + } + + msgBuff.append(plainText.substring(startPos)); + } + } } 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 cf57149..8a2971d 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 @@ -49,12 +49,12 @@ public class ChatHtmlUtils /** * The closing tag of the <code>PLAINTEXT</code> HTML element. */ - private static final String END_PLAINTEXT_TAG = "</PLAINTEXT>"; + public static final String END_PLAINTEXT_TAG = "</PLAINTEXT>"; /** * The opening tag of the <code>PLAINTEXT</code> HTML element. */ - private static final String START_PLAINTEXT_TAG = "<PLAINTEXT>"; + public static final String START_PLAINTEXT_TAG = "<PLAINTEXT>"; /** * The html text content type. diff --git a/src/net/java/sip/communicator/impl/gui/main/chat/ChatPanel.java b/src/net/java/sip/communicator/impl/gui/main/chat/ChatPanel.java index 02e588d..a4f50c5 100644 --- a/src/net/java/sip/communicator/impl/gui/main/chat/ChatPanel.java +++ b/src/net/java/sip/communicator/impl/gui/main/chat/ChatPanel.java @@ -1095,7 +1095,8 @@ public class ChatPanel { String keyword = null; - if (chatSession instanceof ConferenceChatSession && Chat.INCOMING_MESSAGE.equals(chatMessage.getMessageType())) + if (chatSession instanceof ConferenceChatSession + && Chat.INCOMING_MESSAGE.equals(chatMessage.getMessageType())) { keyword = ((ChatRoomWrapper) chatSession.getDescriptor()).getChatRoom() 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 40658ce..43ffdd7 100644 --- a/src/net/java/sip/communicator/impl/replacement/bliptv/ReplacementServiceBliptvImpl.java +++ b/src/net/java/sip/communicator/impl/replacement/bliptv/ReplacementServiceBliptvImpl.java @@ -32,8 +32,7 @@ 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+)([?&\\?]\\w+=[\\w-]+)*)(?=</A>)"; + "(http:\\/\\/(?:www\\.)?blip\\.tv\\/.*)"; /** * Configuration label shown in the config form. @@ -64,7 +63,8 @@ public class ReplacementServiceBliptvImpl { try { - String url = "http://oohembed.com/oohembed/?url=" + sourceString; + String url = "http://api.embed.ly/1/oembed?url=" + sourceString + + "&key=cff57b37766440a6a8aa45df88097efe"; URL sourceURL = new URL(url); URLConnection conn = sourceURL.openConnection(); diff --git a/src/net/java/sip/communicator/impl/replacement/dailymotion/ReplacementServiceDailymotionImpl.java b/src/net/java/sip/communicator/impl/replacement/dailymotion/ReplacementServiceDailymotionImpl.java index 56f9cbb..235adf2 100644 --- a/src/net/java/sip/communicator/impl/replacement/dailymotion/ReplacementServiceDailymotionImpl.java +++ b/src/net/java/sip/communicator/impl/replacement/dailymotion/ReplacementServiceDailymotionImpl.java @@ -29,8 +29,8 @@ public class ReplacementServiceDailymotionImpl * The regex used to match the link in the message. */ public static final String DAILYMOTION_PATTERN = - "(?<=>)(https?\\:\\/\\/(www\\.)*?dailymotion\\.com" - + "\\/video\\/([a-zA-Z0-9_\\-]+))([?#]([a-zA-Z0-9_\\-]+))*(?=</A>)"; + "(https?\\:\\/\\/(www\\.)*?dailymotion\\.com" + + "\\/video\\/([a-zA-Z0-9_\\-]+))([?#]([a-zA-Z0-9_\\-]+))*"; /** * Configuration label shown in the config form. diff --git a/src/net/java/sip/communicator/impl/replacement/directimage/ReplacementServiceDirectImageImpl.java b/src/net/java/sip/communicator/impl/replacement/directimage/ReplacementServiceDirectImageImpl.java index 5139d8c..bdaa415 100644 --- a/src/net/java/sip/communicator/impl/replacement/directimage/ReplacementServiceDirectImageImpl.java +++ b/src/net/java/sip/communicator/impl/replacement/directimage/ReplacementServiceDirectImageImpl.java @@ -33,7 +33,7 @@ public class ReplacementServiceDirectImageImpl * The regex used to match the link in the message. */ public static final String URL_PATTERN = - "[^<>]+\\.(?:jpg|png|gif)[^<>]*(?=</a>)"; + "https?\\:\\/\\/(www\\.)*.*\\.(?:jpg|png|gif)"; /** * Configuration label shown in the config form. diff --git a/src/net/java/sip/communicator/impl/replacement/flickr/ReplacementServiceFlickrImpl.java b/src/net/java/sip/communicator/impl/replacement/flickr/ReplacementServiceFlickrImpl.java index 100b301..a9a142e 100644 --- a/src/net/java/sip/communicator/impl/replacement/flickr/ReplacementServiceFlickrImpl.java +++ b/src/net/java/sip/communicator/impl/replacement/flickr/ReplacementServiceFlickrImpl.java @@ -33,8 +33,8 @@ public class ReplacementServiceFlickrImpl * The regex used to match the link in the message. */ public static final String FLICKR_PATTERN = - "(?<=>)(https?\\:\\/\\/(www\\.)*?flickr\\.com" - + "\\/photos\\/[0-9a-zA-Z_\\-\\@]+\\/([0-9]+)(\\/[^\"\\<]*)*)(?=</A>)"; + "(https?\\:\\/\\/(www\\.)*?flickr\\.com" + + "\\/photos\\/[0-9a-zA-Z_\\-\\@]+\\/([0-9]+)(\\/[^\"\\<]*)*)"; /** * API Key required to access the Flickr api. @@ -107,7 +107,7 @@ public class ReplacementServiceFlickrImpl JSONObject result = (JSONObject)wrapper.get("photo"); if (!(result.isEmpty())) { - String farmID = (String)result.get("farm"); + String farmID = String.valueOf(result.get("farm")); String serverID = (String)result.get("server"); String secret = (String)result.get("secret"); diff --git a/src/net/java/sip/communicator/impl/replacement/hulu/ReplacementServiceHuluImpl.java b/src/net/java/sip/communicator/impl/replacement/hulu/ReplacementServiceHuluImpl.java index 95c73cd..0eb312f 100644 --- a/src/net/java/sip/communicator/impl/replacement/hulu/ReplacementServiceHuluImpl.java +++ b/src/net/java/sip/communicator/impl/replacement/hulu/ReplacementServiceHuluImpl.java @@ -31,8 +31,8 @@ public class ReplacementServiceHuluImpl * The regex used to match the link in the message. */ public static final String HULU_PATTERN = - "(?<=>)(https?\\:\\/\\/(www\\.)*?hulu\\.com" - + "\\/watch\\/([a-zA-Z0-9_\\-]+))(\\/([^\\\"\\<]*)*)(?=<\\/A>)"; + "(https?\\:\\/\\/(www\\.)*?hulu\\.com" + + "\\/watch\\/([a-zA-Z0-9_\\-]+))(\\/([^\\\"\\<]*)*)"; /** * Configuration label shown in the config form. @@ -63,7 +63,8 @@ public class ReplacementServiceHuluImpl { try { - String url = "http://oohembed.com/oohembed/?url=" + sourceString; + String url = "http://api.embed.ly/1/oembed?url=" + sourceString + + "&key=cff57b37766440a6a8aa45df88097efe"; URL sourceURL = new URL(url); URLConnection conn = sourceURL.openConnection(); diff --git a/src/net/java/sip/communicator/impl/replacement/metacafe/ReplacementServiceMetacafeImpl.java b/src/net/java/sip/communicator/impl/replacement/metacafe/ReplacementServiceMetacafeImpl.java index 96f1664..f0525ec 100644 --- a/src/net/java/sip/communicator/impl/replacement/metacafe/ReplacementServiceMetacafeImpl.java +++ b/src/net/java/sip/communicator/impl/replacement/metacafe/ReplacementServiceMetacafeImpl.java @@ -29,8 +29,8 @@ public class ReplacementServiceMetacafeImpl * The regex used to match the link in the message. */ public static final String METACAFE_PATTERN = - "(?<=>)(https?\\:\\/\\/(www\\.)*?metacafe\\.com" - + "\\/watch\\/([a-zA-Z0-9_\\-]+))(\\/[a-zA-Z0-9_\\-\\/]+)*(?=</A>)"; + "(https?\\:\\/\\/(www\\.)*?metacafe\\.com" + + "\\/watch\\/([a-zA-Z0-9_\\-]+))(\\/[a-zA-Z0-9_\\-\\/]+)*"; /** * Configuration label shown in the config form. 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; } diff --git a/src/net/java/sip/communicator/impl/replacement/vbox7/ReplacementServiceVbox7Impl.java b/src/net/java/sip/communicator/impl/replacement/vbox7/ReplacementServiceVbox7Impl.java index 2d4b272..4c708ad 100644 --- a/src/net/java/sip/communicator/impl/replacement/vbox7/ReplacementServiceVbox7Impl.java +++ b/src/net/java/sip/communicator/impl/replacement/vbox7/ReplacementServiceVbox7Impl.java @@ -5,8 +5,10 @@ */ package net.java.sip.communicator.impl.replacement.vbox7; +import java.util.*; import java.util.regex.*; +import net.java.sip.communicator.service.httputil.*; import net.java.sip.communicator.service.replacement.*; import net.java.sip.communicator.util.*; @@ -29,8 +31,8 @@ public class ReplacementServiceVbox7Impl * The regex used to match the link in the message. */ public static final String VBOX7_PATTERN = - "(?<=>)(https?\\:\\/\\/(www\\.)*?vbox7\\.com" - + "\\/play\\:([a-zA-Z0-9_\\-]+))([?&]\\w+=[\\w-]*)*(?=</A>)"; + "(https?\\:\\/\\/(www\\.)*?vbox7\\.com" + + "\\/play\\:([a-zA-Z0-9_\\-]+))([?&]\\w+=[\\w-]*)*"; /** * Configuration label shown in the config form. @@ -63,10 +65,36 @@ public class ReplacementServiceVbox7Impl Pattern.CASE_INSENSITIVE | Pattern.DOTALL); Matcher m = p.matcher(sourceString); String thumbUrl = sourceString; + String id = null; while (m.find()) { - thumbUrl = "https://i.vbox7.com/p/" + m.group(1) + "3.jpg"; + id = m.group(1); + thumbUrl = "https://i.vbox7.com/p/" + id + "3.jpg"; + } + + if(id != null) + { + try + { + HttpUtils.HTTPResponseResult res = HttpUtils.openURLConnection( + "http://vbox7.com/etc/ext.do?key=" + id); + + StringTokenizer toks = new StringTokenizer( + res.getContentString(), "&"); + while(toks.hasMoreTokens()) + { + String value = toks.nextToken(); + String[] entries = value.split("="); + if(entries.length > 1 + && entries[0].equals("jpg_addr")) + { + return "http://" + entries[1]; + } + } + } + catch(Throwable t) + {} } return thumbUrl; diff --git a/src/net/java/sip/communicator/impl/replacement/vbox7/vbox7.source.manifest.mf b/src/net/java/sip/communicator/impl/replacement/vbox7/vbox7.source.manifest.mf index d7da965..1ebe3e6 100644 --- a/src/net/java/sip/communicator/impl/replacement/vbox7/vbox7.source.manifest.mf +++ b/src/net/java/sip/communicator/impl/replacement/vbox7/vbox7.source.manifest.mf @@ -5,6 +5,7 @@ Bundle-Vendor: jitsi.org Bundle-Version: 1.0.0 Bundle-SymbolicName: net.java.sip.communicator.replacement.vbox7 Import-Package: org.osgi.framework, + net.java.sip.communicator.service.httputil, net.java.sip.communicator.service.replacement, org.jitsi.service.configuration, org.jitsi.service.resources, net.java.sip.communicator.service.resources, diff --git a/src/net/java/sip/communicator/impl/replacement/viddler/ReplacementServiceViddlerImpl.java b/src/net/java/sip/communicator/impl/replacement/viddler/ReplacementServiceViddlerImpl.java index 8bda865..4ddff36 100644 --- a/src/net/java/sip/communicator/impl/replacement/viddler/ReplacementServiceViddlerImpl.java +++ b/src/net/java/sip/communicator/impl/replacement/viddler/ReplacementServiceViddlerImpl.java @@ -30,8 +30,8 @@ public class ReplacementServiceViddlerImpl * The regex used to match the link in the message. */ public static final String VIDDLER_PATTERN = - "(?<=>)(http:\\/\\/(?:www\\.)?viddler\\.com" - + "\\/explore\\/(\\w+)\\/videos\\/\\d+.*(?=<\\/A>))"; + "(http:\\/\\/(?:www\\.)?viddler\\.com" + + "\\/explore\\/(\\w+)\\/videos\\/\\d+.*)"; /** * API Key required to access the viddler api. diff --git a/src/net/java/sip/communicator/impl/replacement/vimeo/ReplacementServiceVimeoImpl.java b/src/net/java/sip/communicator/impl/replacement/vimeo/ReplacementServiceVimeoImpl.java index 95fd9a2..a6e5473 100644 --- a/src/net/java/sip/communicator/impl/replacement/vimeo/ReplacementServiceVimeoImpl.java +++ b/src/net/java/sip/communicator/impl/replacement/vimeo/ReplacementServiceVimeoImpl.java @@ -33,8 +33,8 @@ public class ReplacementServiceVimeoImpl * The regex used to match the link in the message. */ public static final String VIMEO_PATTERN = - "(?<=>)(https?\\:\\/\\/(www\\.)*?vimeo\\.com" - + "\\/([a-zA-Z0-9_\\-]+))(?=</A>)"; + "(https?\\:\\/\\/(www\\.)*?vimeo\\.com" + + "\\/([a-zA-Z0-9_\\-]+))"; /** * Configuration label shown in the config form. diff --git a/src/net/java/sip/communicator/impl/replacement/youtube/ReplacementServiceYoutubeImpl.java b/src/net/java/sip/communicator/impl/replacement/youtube/ReplacementServiceYoutubeImpl.java index 2fdf8ef..1e45a9e 100644 --- a/src/net/java/sip/communicator/impl/replacement/youtube/ReplacementServiceYoutubeImpl.java +++ b/src/net/java/sip/communicator/impl/replacement/youtube/ReplacementServiceYoutubeImpl.java @@ -29,8 +29,8 @@ public class ReplacementServiceYoutubeImpl * The regex used to match the link in the message. */ public static final String YOUTUBE_PATTERN = - "(?<=>)(https?\\:\\/\\/(www\\.)*?youtube\\.com" - + "\\/watch\\?v=([a-zA-Z0-9_\\-]+))([?&]\\w+=[\\w-]+)*(?=</A>)"; + "(https?\\:\\/\\/(www\\.)*?youtube\\.com" + + "\\/watch\\?v=([a-zA-Z0-9_\\-]+))([?&]\\w+=[\\w-]+)*"; /** * Configuration label shown in the config form. |