Support for video and photo previews in chat window provided by Purvesh Sahoo as part of its GSoC project.

cusax-fix
Yana Stamcheva 15 years ago
parent 42fbfc3964
commit 7746c91783

@ -45,7 +45,7 @@
<property name="inst.resrc" value="${sc.basedir}/resources/install"/>
<property name='j2se_api' value='http://java.sun.com/j2se/1.5/docs/api' />
<property name='maxwarns' value='10000' />
<property name='java.net.preferIPv6Addresses' value='false' />
<property name='java.net.preferIPv6Addresses' value='true' />
<!-- set the build label property and make it take the cc bild into account -->
<condition property="build.label"
@ -746,8 +746,8 @@
<sysproperty key="java.net.preferIPv6Addresses"
value="${java.net.preferIPv6Addresses}"/>
<sysproperty key="net.java.sip.communicator.SC_HOME_DIR_LOCATION"
value="${user.home}/schome"/>
<!--sysproperty key="net.java.sip.communicator.SC_HOME_DIR_LOCATION"
value="${user.home}/schome"/-->
<!-- this is a temporary option that would need to disappear once
we finalize jingle -->
@ -926,10 +926,13 @@
bundle-filehistory,bundle-metahistory,bundle-metahistory-slick,
bundle-plugin-facebookaccregwizz,
bundle-bouncycastle,bundle-plugin-otr,bundle-plugin-iptelaccregwizz,
bundle-contactsource,bundle-plugin-reconnect,
bundle-plugin-securityconfig,bundle-plugin-advancedconfig,
bundle-plugin-sip2sipaccregwizz,
bundle-credentialsstorage,bundle-credentialsstorage-slick"/>
bundle-contactsource,bundle-plugin-reconnect,bundle-plugin-securityconfig,
bundle-plugin-advancedconfig,bundle-plugin-sip2sipaccregwizz,
bundle-credentialsstorage,bundle-credentialsstorage-slick,
bundle-youtube,bundle-dailymotion,bundle-smiley,bundle-vimeo,
bundle-vbox7,bundle-metacafe,bundle-flickr,bundle-hulu,
bundle-twitpic,bundle-directimage,bundle-bliptv,bundle-viddler,
bundle-plugin-chatconfig"/>
<!--BUNDLE-SC-LAUNCHER-->
<target name="bundle-sc-launcher">
@ -2375,4 +2378,154 @@ org.apache.http.util"/>
prefix="net/java/sip/communicator/plugin/advancedconfig"/>
</jar>
</target>
<!-- BUNDLE-YOUTUBE -->
<target name="bundle-youtube">
<jar compress="false" destfile="${bundles.dest}/replacement-youtube.jar"
manifest="${src}/net/java/sip/communicator/impl/replacement/youtube/youtube.source.manifest.mf">
<zipfileset dir="${dest}/net/java/sip/communicator/impl/replacement/youtube"
prefix="net/java/sip/communicator/impl/replacement/youtube"/>
<zipfileset dir="${dest}/net/java/sip/communicator/service/replacement"
prefix="net/java/sip/communicator/service/replacement"/>
<zipfileset src="${lib.noinst}/json-20090723.jar" prefix=""/>
</jar>
</target>
<!-- BUNDLE-DAILYMOTION -->
<target name="bundle-dailymotion">
<jar compress="false" destfile="${bundles.dest}/replacement-dailymotion.jar"
manifest="${src}/net/java/sip/communicator/impl/replacement/dailymotion/dailymotion.source.manifest.mf">
<zipfileset dir="${dest}/net/java/sip/communicator/impl/replacement/dailymotion"
prefix="net/java/sip/communicator/impl/replacement/dailymotion"/>
<zipfileset dir="${dest}/net/java/sip/communicator/service/replacement"
prefix="net/java/sip/communicator/service/replacement"/>
</jar>
</target>
<!-- BUNDLE-SMILEY -->
<target name="bundle-smiley">
<jar compress="false" destfile="${bundles.dest}/replacement-smiley.jar"
manifest="${src}/net/java/sip/communicator/impl/replacement/smiley/smiley.source.manifest.mf">
<zipfileset dir="${dest}/net/java/sip/communicator/impl/replacement/smiley"
prefix="net/java/sip/communicator/impl/replacement/smiley"/>
<zipfileset dir="${dest}/net/java/sip/communicator/service/replacement"
prefix="net/java/sip/communicator/service/replacement"/>
<zipfileset dir="${dest}/net/java/sip/communicator/impl/gui/utils"
prefix="net/java/sip/communicator/impl/gui/utils"/>
<zipfileset dir="${dest}/net/java/sip/communicator/impl/gui"
prefix="net/java/sip/communicator/impl/gui"/>
</jar>
</target>
<!-- BUNDLE-VIMEO -->
<target name="bundle-vimeo">
<jar compress="false" destfile="${bundles.dest}/replacement-vimeo.jar"
manifest="${src}/net/java/sip/communicator/impl/replacement/vimeo/vimeo.source.manifest.mf">
<zipfileset dir="${dest}/net/java/sip/communicator/impl/replacement/vimeo"
prefix="net/java/sip/communicator/impl/replacement/vimeo"/>
<zipfileset dir="${dest}/net/java/sip/communicator/service/replacement"
prefix="net/java/sip/communicator/service/replacement"/>
<zipfileset src="${lib.noinst}/json-20090723.jar" prefix=""/>
</jar>
</target>
<!-- BUNDLE-VBOX7 -->
<target name="bundle-vbox7">
<jar compress="false" destfile="${bundles.dest}/replacement-vbox7.jar"
manifest="${src}/net/java/sip/communicator/impl/replacement/vbox7/vbox7.source.manifest.mf">
<zipfileset dir="${dest}/net/java/sip/communicator/impl/replacement/vbox7"
prefix="net/java/sip/communicator/impl/replacement/vbox7"/>
<zipfileset dir="${dest}/net/java/sip/communicator/service/replacement"
prefix="net/java/sip/communicator/service/replacement"/>
</jar>
</target>
<!-- BUNDLE-METACAFE -->
<target name="bundle-metacafe">
<jar compress="false" destfile="${bundles.dest}/replacement-metacafe.jar"
manifest="${src}/net/java/sip/communicator/impl/replacement/metacafe/metacafe.source.manifest.mf">
<zipfileset dir="${dest}/net/java/sip/communicator/impl/replacement/metacafe"
prefix="net/java/sip/communicator/impl/replacement/metacafe"/>
<zipfileset dir="${dest}/net/java/sip/communicator/service/replacement"
prefix="net/java/sip/communicator/service/replacement"/>
</jar>
</target>
<!-- BUNDLE-FLICKR -->
<target name="bundle-flickr">
<jar compress="false" destfile="${bundles.dest}/replacement-flickr.jar"
manifest="${src}/net/java/sip/communicator/impl/replacement/flickr/flickr.source.manifest.mf">
<zipfileset dir="${dest}/net/java/sip/communicator/impl/replacement/flickr"
prefix="net/java/sip/communicator/impl/replacement/flickr"/>
<zipfileset dir="${dest}/net/java/sip/communicator/service/replacement"
prefix="net/java/sip/communicator/service/replacement"/>
<zipfileset src="${lib.noinst}/json-20090723.jar" prefix=""/>
</jar>
</target>
<!-- BUNDLE-HULU -->
<target name="bundle-hulu">
<jar compress="false" destfile="${bundles.dest}/replacement-hulu.jar"
manifest="${src}/net/java/sip/communicator/impl/replacement/hulu/hulu.source.manifest.mf">
<zipfileset dir="${dest}/net/java/sip/communicator/impl/replacement/hulu"
prefix="net/java/sip/communicator/impl/replacement/hulu"/>
<zipfileset dir="${dest}/net/java/sip/communicator/service/replacement"
prefix="net/java/sip/communicator/service/replacement"/>
<zipfileset src="${lib.noinst}/json-20090723.jar" prefix=""/>
</jar>
</target>
<!-- BUNDLE-TWITPIC -->
<target name="bundle-twitpic">
<jar compress="false" destfile="${bundles.dest}/replacement-twitpic.jar"
manifest="${src}/net/java/sip/communicator/impl/replacement/twitpic/twitpic.source.manifest.mf">
<zipfileset dir="${dest}/net/java/sip/communicator/impl/replacement/twitpic"
prefix="net/java/sip/communicator/impl/replacement/twitpic"/>
<zipfileset dir="${dest}/net/java/sip/communicator/service/replacement"
prefix="net/java/sip/communicator/service/replacement"/>
</jar>
</target>
<!-- BUNDLE-DIRECTIMAGE -->
<target name="bundle-directimage">
<jar compress="false" destfile="${bundles.dest}/replacement-directimage.jar"
manifest="${src}/net/java/sip/communicator/impl/replacement/directimage/directimage.source.manifest.mf">
<zipfileset dir="${dest}/net/java/sip/communicator/impl/replacement/directimage"
prefix="net/java/sip/communicator/impl/replacement/directimage"/>
<zipfileset dir="${dest}/net/java/sip/communicator/service/replacement"
prefix="net/java/sip/communicator/service/replacement"/>
</jar>
</target>
<!-- BUNDLE-BLIPTV -->
<target name="bundle-bliptv">
<jar compress="false" destfile="${bundles.dest}/replacement-bliptv.jar"
manifest="${src}/net/java/sip/communicator/impl/replacement/bliptv/bliptv.source.manifest.mf">
<zipfileset dir="${dest}/net/java/sip/communicator/impl/replacement/bliptv"
prefix="net/java/sip/communicator/impl/replacement/bliptv"/>
<zipfileset dir="${dest}/net/java/sip/communicator/service/replacement"
prefix="net/java/sip/communicator/service/replacement"/>
<zipfileset src="${lib.noinst}/json-20090723.jar" prefix=""/>
</jar>
</target>
<!-- BUNDLE-VIDDLER -->
<target name="bundle-viddler">
<jar compress="false" destfile="${bundles.dest}/replacement-viddler.jar"
manifest="${src}/net/java/sip/communicator/impl/replacement/viddler/viddler.source.manifest.mf">
<zipfileset dir="${dest}/net/java/sip/communicator/impl/replacement/viddler"
prefix="net/java/sip/communicator/impl/replacement/viddler"/>
<zipfileset dir="${dest}/net/java/sip/communicator/service/replacement"
prefix="net/java/sip/communicator/service/replacement"/>
</jar>
</target>
<!--BUNDLE-Chat Config-->
<target name="bundle-plugin-chatconfig">
<jar compress="false" destfile="${bundles.dest}/chatconfig.jar"
manifest="${src}/net/java/sip/communicator/plugin/chatconfig/chatconfig.manifest.mf">
<zipfileset dir="${dest}/net/java/sip/communicator/plugin/chatconfig"
prefix="net/java/sip/communicator/plugin/chatconfig" />
</jar>
</target>
</project>

@ -132,8 +132,22 @@ felix.auto.start.67= \
reference:file:sc-bundles/generalconfig.jar \
reference:file:sc-bundles/dictaccregwizz.jar \
reference:file:sc-bundles/otr.jar \
reference:file:sc-bundles/facebookaccregwizz.jar \
reference:file:sc-bundles/advancedconfig.jar \
reference:file:sc-bundles/facebookaccregwizz.jar
reference:file:sc-bundles/replacement-youtube.jar \
reference:file:sc-bundles/replacement-dailymotion.jar \
reference:file:sc-bundles/replacement-smiley.jar \
reference:file:sc-bundles/replacement-vimeo.jar \
reference:file:sc-bundles/replacement-vbox7.jar \
reference:file:sc-bundles/replacement-metacafe.jar \
reference:file:sc-bundles/replacement-flickr.jar \
reference:file:sc-bundles/replacement-hulu.jar \
reference:file:sc-bundles/replacement-twitpic.jar \
reference:file:sc-bundles/replacement-directimage.jar \
reference:file:sc-bundles/replacement-bliptv.jar \
reference:file:sc-bundles/replacement-viddler.jar \
reference:file:sc-bundles/chatconfig.jar
#level 68 is for profiler, don't use it or change the build.xml file accordingly

@ -481,4 +481,7 @@ impl.media.DESKTOP_STREAMING_ICON=resources/images/impl/media/desktopStreaming.p
plugin.globalproxy.PLUGIN_ICON=resources/images/plugin/globalproxyconfig/configureIcon.png
# Advanced config form icon
plugin.advancedconfig.PLUGIN_ICON=resources/images/plugin/advancedconfig/configIcon.png
plugin.advancedconfig.PLUGIN_ICON=resources/images/plugin/advancedconfig/configIcon.png
# Chat config form icon
plugin.chatconfig.PLUGIN_ICON=resources/images/plugin/chatconfig/chatIcon.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 977 B

@ -1048,3 +1048,23 @@ plugin.globalproxy.PROTOCOL_SUPPORT=<html><table> \
# plugin reconnect
plugin.reconnectplugin.CONNECTION_FAILED_MSG=Connection failed for the following account:\nUser name: {0}, Server name: {1}.\nPlease check your settings or contact your network administrator for more information.
plugin.reconnectplugin.NETWORK_DOWN=Network connectivity lost!
#plugin chat config
plugin.chatconfig.TITLE=Chat
plugin.chatconfig.replacement.TITLE=Image/Video:
plugin.chatconfig.replacement.ENABLE_SMILEY_STATUS=Enable smiley replacement
plugin.chatconfig.replacement.ENABLE_REPLACEMENT_STATUS=Enable Image/Video replacement
plugin.chatconfig.replacement.REPLACEMENT_SOURCES=Sources:
plugin.chatconfig.replacement.sources.METACAFE=Metacafe
plugin.chatconfig.replacement.sources.HULU=Hulu
plugin.chatconfig.replacement.sources.DAILYMOTION=DailyMotion
plugin.chatconfig.replacement.sources.DIRECTIMAGE=Direct Image Link
plugin.chatconfig.replacement.sources.FLICKR=Flickr Images
plugin.chatconfig.replacement.sources.TWITPIC=Twitpic
plugin.chatconfig.replacement.sources.VBOX7=Vbox7
plugin.chatconfig.replacement.sources.VIMEO=Vimeo
plugin.chatconfig.replacement.sources.YOUTUBE=Youtube
plugin.chatconfig.replacement.sources.BLIPTV=Blip.tv
plugin.chatconfig.replacement.sources.VIDDLER=Viddler

@ -25,6 +25,7 @@
import net.java.sip.communicator.service.neomedia.*;
import net.java.sip.communicator.service.notification.*;
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.service.replacement.*;
import net.java.sip.communicator.service.resources.*;
import net.java.sip.communicator.service.shutdown.*;
import net.java.sip.communicator.service.systray.*;
@ -83,10 +84,13 @@ public class GuiActivator implements BundleActivator
private static final Map<Object, ProtocolProviderFactory>
providerFactoriesMap = new Hashtable<Object, ProtocolProviderFactory>();
private static final Map<Object, ReplacementService>
replacementSourcesMap = new Hashtable<Object, ReplacementService>();
/**
* Indicates if this bundle has been started.
*/
public static boolean isStarted = false;
public static boolean isStarted = false;
/**
* The contact list object.
@ -613,6 +617,44 @@ public static List<ContactSourceService> getContactSources()
return contactSources;
}
/**
* Returns all <tt>ReplacementService</tt>s obtained from the bundle
* context.
*
* @return all <tt>ReplacementService</tt> implementation obtained from the
* bundle context
*/
public static Map<Object, ReplacementService> getReplacementSources()
{
ServiceReference[] serRefs = null;
try
{
// get all registered sources
serRefs
= bundleContext.getServiceReferences(ReplacementService.class
.getName(), null);
}
catch (InvalidSyntaxException e)
{
logger.error("Error : " + e);
}
if (serRefs != null)
{
for (int i = 0; i < serRefs.length; i++)
{
ReplacementService replacementSources =
(ReplacementService) bundleContext.getService(serRefs[i]);
replacementSourcesMap.put(serRefs[i]
.getProperty(ReplacementService.SOURCE_NAME),
replacementSources);
}
}
return replacementSourcesMap;
}
/**
* Sets the <tt>contactList</tt> component currently used to show the
* contact list.

@ -11,6 +11,7 @@
import java.awt.event.*;
import java.io.*;
import java.util.*;
import java.util.Map.*;
import java.util.regex.*;
import javax.swing.*;
@ -24,8 +25,10 @@
import net.java.sip.communicator.impl.gui.main.chat.menus.*;
import net.java.sip.communicator.impl.gui.utils.*;
import net.java.sip.communicator.service.gui.*;
import net.java.sip.communicator.service.replacement.*;
import net.java.sip.communicator.util.*;
import net.java.sip.communicator.util.swing.*;
import net.java.sip.communicator.util.swing.SwingWorker;
/**
* The <tt>ChatConversationPanel</tt> is the panel, where all sent and received
@ -69,41 +72,68 @@ public class ChatConversationPanel
+ ")");
/**
* The compiled <tt>Pattern</tt> which matches {@link #smileyStrings}.
* The component rendering chat conversation panel text.
*/
private static Pattern smileyPattern;
private final JTextPane chatTextPane = new MyTextPane();
/**
* The <tt>List</tt> of smiley strings which are matched by
* {@link #smileyPattern}.
* The editor kit used by the text component.
*/
private static final java.util.List<String> smileyStrings
= new ArrayList<String>();
private final JTextPane chatTextPane = new MyTextPane();
private final HTMLEditorKit editorKit;
/**
* The document used by the text component.
*/
private HTMLDocument document;
/**
* The parent container.
*/
private final ChatConversationContainer chatContainer;
/**
* The menu shown on right button mouse click.
*/
private final ChatRightButtonMenu rightButtonMenu;
/**
* The currently shown href.
*/
private String currentHref;
/**
* The copy link item, contained in the right mouse click menu.
*/
private final JMenuItem copyLinkItem;
/**
* The open link item, contained in the right mouse click menu.
*/
private final JMenuItem openLinkItem;
/**
* The right mouse click menu separator.
*/
private final JSeparator copyLinkSeparator = new JSeparator();
/**
* The timestamp of the last incoming message.
*/
private long lastIncomingMsgTimestamp;
/**
* Indicates if this component is rendering a history conversation.
*/
private final boolean isHistory;
/**
* The html text content type.
*/
public static final String HTML_CONTENT_TYPE = "text/html";
/**
* The plain text content type.
*/
public static final String TEXT_CONTENT_TYPE = "text/plain";
/**
@ -245,7 +275,7 @@ public void componentResized(ComponentEvent e)
getViewport().addComponentListener(componentListener);
}
/*
/**
* Overrides Component#setBounds(int, int, int, int) in order to determine
* whether an automatic scroll of #chatTextPane to its bottom will be
* necessary at a later time in order to keep its vertical scroll bar to its
@ -519,9 +549,103 @@ public void appendMessageToEnd(String chatString)
}
if (!isHistory)
ensureDocumentSize();
// Process replacements.
final Element elem;
/*
* Check to make sure element isn't the first element in the HTML
* document.
*/
if (!(root.getElementCount() < 2))
{
elem = root.getElement(root.getElementCount() - 2);
}
else
elem = root.getElement(1);
/*
* Replacements will be processed only if it is enabled in the
* property
*/
if (GuiActivator.getConfigurationService().getBoolean(
ReplacementProperty.REPLACEMENT_ENABLE, true)
|| GuiActivator.getConfigurationService().getBoolean(
ReplacementProperty.getPropertyName("SMILEY"), true))
{
processReplacement(elem, chatString);
}
}
}
/**
* Formats the given message. Processes the messages and replaces links to
* video/image sources with their previews or any other substitution. Spawns
* a separate thread for replacement.
*
* @param elem the element in the HTML Document.
* @param chatString the message.
*/
private void processReplacement(final Element elem, final String chatString)
{
final String chatFinal = chatString;
SwingWorker worker = new SwingWorker()
{
public Object construct() throws Exception
{
String temp = "", msgStore = chatFinal;
boolean isEnabled
= GuiActivator.getConfigurationService().getBoolean(
ReplacementProperty.REPLACEMENT_ENABLE, true);
Map<Object, ReplacementService> listSources
= GuiActivator.getReplacementSources();
Iterator<Entry<Object, ReplacementService>> entrySetIter
= listSources.entrySet().iterator();
for (int i = 0; i < listSources.size(); i++)
{
Map.Entry<Object, ReplacementService> entry
= entrySetIter.next();
ReplacementService source = entry.getValue();
if (!(GuiActivator.getConfigurationService().getBoolean(
ReplacementProperty.getPropertyName((String) entry
.getKey()), true) && (isEnabled || entry.getKey()
.equals("SMILEY"))))
continue;
temp = source.getReplacedMessage(msgStore);
/*
* replace the msgStore variable with the current replaced
* message before next iteration
*/
if (!temp.equals(msgStore))
{
msgStore = temp;
}
}
if (!temp.equals(chatFinal))
{
synchronized (scrollToBottomRunnable)
{
scrollToBottomIsPending = true;
document.setOuterHTML(elem, temp.toString().substring(
temp.indexOf("<DIV")));
}
}
return "";
}
};
worker.start();
}
/**
* Ensures that the document won't become too big. When the document reaches
* a certain size the first message in the page is removed.
@ -703,9 +827,6 @@ private String formatMessage(String message,
message = processImgTags(processBrTags(message));
}
if (ConfigurationManager.isShowSmileys())
message = processSmileys(message, contentType);
return message;
}
@ -805,123 +926,6 @@ private String processNewLines(String message)
END_PLAINTEXT_TAG + "<BR>&#10;" + START_PLAINTEXT_TAG);
}
/**
* Formats message smileys.
*
* @param message the source message string
* @param contentType the content type
* @return the message string with properly formated smileys
*/
private String processSmileys(String message, String contentType)
{
String startPlainTextTag;
String endPlainTextTag;
if (!HTML_CONTENT_TYPE.equals(contentType))
{
startPlainTextTag = START_PLAINTEXT_TAG;
endPlainTextTag = END_PLAINTEXT_TAG;
}
else
{
startPlainTextTag = "";
endPlainTextTag = "";
}
Collection<Smiley> smileys = ImageLoader.getDefaultSmileyPack();
Matcher m = getSmileyPattern(smileys).matcher(message);
StringBuffer msgBuffer = new StringBuffer();
int prevEnd = 0;
while (m.find())
{
msgBuffer.append(message.substring(prevEnd, m.start()));
prevEnd = m.end();
String smileyString = m.group().trim();
msgBuffer.append(endPlainTextTag);
msgBuffer.append("<IMG SRC=\"");
msgBuffer
.append(ImageLoader.getSmiley(smileyString).getImagePath());
msgBuffer.append("\" ALT=\"");
msgBuffer.append(smileyString);
msgBuffer.append("\"></IMG>");
msgBuffer.append(startPlainTextTag);
}
msgBuffer.append(message.substring(prevEnd));
return msgBuffer.toString();
}
/**
* Gets a compiled <tt>Pattern</tt> 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
*/
private static Pattern getSmileyPattern(Collection<Smiley> smileys)
{
synchronized (smileyStrings)
{
boolean smileyStringsIsEqual;
if (smileyPattern == null)
smileyStringsIsEqual = false;
else
{
smileyStringsIsEqual = true;
int smileyStringIndex = 0;
int smileyStringCount = smileyStrings.size();
smileyLoop: for (Smiley smiley : smileys)
for (String smileyString : smiley.getSmileyStrings())
if ((smileyStringIndex < smileyStringCount)
&& smileyString
.equals(
smileyStrings.get(smileyStringIndex)))
smileyStringIndex++;
else
{
smileyStringsIsEqual = false;
break smileyLoop;
}
if (smileyStringsIsEqual
&& (smileyStringIndex != smileyStringCount))
smileyStringsIsEqual = false;
}
if (!smileyStringsIsEqual)
{
smileyStrings.clear();
StringBuffer regex = new StringBuffer();
regex.append("(?<!(alt='|alt=\"))(");
for (Smiley smiley : smileys)
for (String smileyString : smiley.getSmileyStrings())
{
smileyStrings.add(smileyString);
regex
.append(
GuiUtils
.replaceSpecialRegExpChars(
smileyString))
.append("|");
}
regex = regex.deleteCharAt(regex.length() - 1);
regex.append(')');
smileyPattern = Pattern.compile(regex.toString());
}
return smileyPattern;
}
}
/**
* Opens a link in the default browser when clicked and shows link url in a
* popup on mouseover.

@ -33,6 +33,7 @@ Import-Package: org.osgi.framework,
net.java.sip.communicator.service.neomedia,
net.java.sip.communicator.service.neomedia.device,
net.java.sip.communicator.service.contactsource,
net.java.sip.communicator.service.replacement,
net.java.sip.communicator.util,
net.java.sip.communicator.util.swing,
net.java.sip.communicator.util.swing.border,

@ -32,6 +32,7 @@ public class Smiley
* @param imageID The image identifier of the smiley icon.
* @param smileyStrings A set of strings corresponding to the smiley
* icon.
* @param description the description of the smiley
*/
public Smiley(ImageID imageID, String[] smileyStrings, String description)
{
@ -95,4 +96,22 @@ public String getImagePath()
return url.toString();
}
/**
* Returns the path of the image corresponding to this smiley.
* @param resourcesService The ResourceManagementService required to get the
* image URL.
* @return the path of the image corresponding to this smiley.
*/
public String getImagePath(ResourceManagementService resourcesService)
{
URL url
= resourcesService
.getImageURL(this.getImageID().getId());
if(url == null)
return null;
return url.toString();
}
}

@ -0,0 +1,70 @@
/*
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license. See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.replacement.bliptv;
import java.util.*;
import net.java.sip.communicator.service.replacement.*;
import net.java.sip.communicator.util.*;
import org.osgi.framework.*;
/**
* Activator for the Blip.tv source bundle.
*
* @author Purvesh Sahoo
*/
public class BliptvActivator
implements BundleActivator
{
/**
* The <tt>Logger</tt> used by the <tt>BliptvActivator</tt> class.
*/
private static final Logger logger =
Logger.getLogger(BliptvActivator.class);
/**
* The blip tv service registration.
*/
private ServiceRegistration bliptvServReg = null;
/**
* The source implementation reference.
*/
private static ReplacementService bliptvSource = null;
/**
* Starts the Blip.tv replacement source bundle
*
* @param context the <tt>BundleContext</tt> as provided from the OSGi
* framework
* @throws Exception if anything goes wrong
*/
public void start(BundleContext context) throws Exception
{
Hashtable<String, String> hashtable = new Hashtable<String, String>();
hashtable.put(ReplacementService.SOURCE_NAME, "BLIPTV");
bliptvSource = new ReplacementServiceBliptvImpl();
bliptvServReg =
context.registerService(ReplacementService.class.getName(),
bliptvSource, hashtable);
logger.info("Blip.TV source implementation [STARTED].");
}
/**
* Unregisters the Blip.tv replacement service.
*
* @param context BundleContext
* @throws Exception if anything goes wrong
*/
public void stop(BundleContext context) throws Exception
{
bliptvServReg.unregister();
logger.info("Blip.TV source implementation [STOPPED].");
}
}

@ -0,0 +1,130 @@
/*
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license. See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.replacement.bliptv;
import java.io.*;
import java.net.*;
import java.util.regex.*;
import org.json.*;
import net.java.sip.communicator.service.replacement.*;
import net.java.sip.communicator.util.*;
/**
* Implements the {@link ReplacementService} to provide previews for Blip.tv
* links.
*
* @author Purvesh Sahoo
*/
public class ReplacementServiceBliptvImpl
implements ReplacementService
{
/**
* The logger for this class.
*/
private static final Logger logger =
Logger.getLogger(ReplacementServiceBliptvImpl.class);
/**
* The regex used to match the link in the message.
*/
public static final String BLIPTV_PATTERN =
"(?:[\\>])(http:\\/\\/(?:www\\.)?blip\\.tv\\/file\\/(\\d+).*(?=<))";
/**
* Configuration label property name. The label is saved in the languages
* file under this property.
*/
public static final String BLIPTV_CONFIG_LABEL = "BLIPTV";
/**
* Constructor for <tt>ReplacementServiceBliptvImpl</tt>. The source needs
* to add itself to {@link ReplacementService} sourceList to be displayed in
* the configuration panel.
*/
public ReplacementServiceBliptvImpl()
{
sourceList.add(BLIPTV_CONFIG_LABEL);
logger.trace("Creating a Blip.TV Source.");
}
/**
* 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.
*/
public String getReplacedMessage(String chatString)
{
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())
{
count++;
msgBuff.append(chatString.substring(startPos, m.start()));
startPos = m.end();
try
{
String url = "http://oohembed.com/oohembed/?url=" + m.group(1);
URL sourceURL = new URL(url);
URLConnection conn = sourceURL.openConnection();
BufferedReader in =
new BufferedReader(new InputStreamReader(conn
.getInputStream()));
String inputLine, holder = "";
while ((inputLine = in.readLine()) != null)
holder += inputLine;
in.close();
JSONObject wrapper = new JSONObject(holder);
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)
{
startPos = 0;
msgBuff = new StringBuffer();
e.printStackTrace();
}
}
msgBuff.append(chatString.substring(startPos));
if (!msgBuff.toString().equals(chatString))
return msgBuff.toString();
return chatString;
}
}

@ -0,0 +1,13 @@
Bundle-Activator: net.java.sip.communicator.impl.replacement.bliptv.BliptvActivator
Bundle-Name: Blip.tv Preview Replacement Source
Bundle-Description: A bundle providing processing for Blip.tv previews.
Bundle-Vendor: sip-communicator.org
Bundle-Version: 1.0.0
System-Bundle: yes
Export-Package: net.java.sip.communicator.service.replacement
Import-Package: org.osgi.framework,
net.java.sip.communicator.service.configuration,
net.java.sip.communicator.service.resources,
net.java.sip.communicator.util,
net.java.sip.communicator.service.replacement,
org.apache.http

@ -0,0 +1,70 @@
/*
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.replacement.dailymotion;
import java.util.*;
import net.java.sip.communicator.service.replacement.*;
import net.java.sip.communicator.service.resources.*;
import net.java.sip.communicator.util.*;
import org.osgi.framework.*;
/**
* Activator for the Dailymotion source bundle.
* @author Purvesh Sahoo
*/
public class DailymotionActivator
implements BundleActivator
{
/**
* The currently valid bundle context.
*/
private static final Logger logger =
Logger.getLogger(DailymotionActivator.class);
/**
* The daily motion source service registration.
*/
private ServiceRegistration dailymotionSourceServReg = null;
/**
* The source implementation reference.
*/
private static ReplacementService dailymotionSource = null;
/**
* Starts the Dailymotion replacement source bundle
*
* @param context the <tt>BundleContext</tt> as provided from the OSGi
* framework
* @throws Exception if anything goes wrong
*/
public void start(BundleContext context) throws Exception
{
Hashtable<String, String> hashtable = new Hashtable<String, String>();
hashtable.put(ReplacementService.SOURCE_NAME, "DAILYMOTION");
dailymotionSource = new ReplacementServiceDailymotionImpl();
dailymotionSourceServReg =
context.registerService(ReplacementService.class.getName(),
dailymotionSource, hashtable);
logger.info("Dailymotion source implementation [STARTED].");
}
/**
* Unregisters the Dailymotion replacement service.
*
* @param context BundleContext
* @throws Exception if anything goes wrong
*/
public void stop(BundleContext context) throws Exception
{
dailymotionSourceServReg.unregister();
logger.info("Dailymotion source implementation [STOPPED].");
}
}

@ -0,0 +1,98 @@
/*
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license. See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.replacement.dailymotion;
import java.util.regex.*;
import net.java.sip.communicator.service.replacement.*;
import net.java.sip.communicator.util.*;
/**
* Implements the {@link ReplacementService} to provide previews for Dailymotion
* links.
*
* @author Purvesh Sahoo
*/
public class ReplacementServiceDailymotionImpl
implements ReplacementService
{
/**
* The logger for this class.
*/
private static final Logger logger =
Logger.getLogger(ReplacementServiceDailymotionImpl.class);
/**
* The regex used to match the link in the message.
*/
public static final String DAILYMOTION_PATTERN =
"(http.*?(www\\.)*?dailymotion\\.com\\/video\\/([a-zA-Z0-9_\\-]+))([?#]([a-zA-Z0-9_\\-]+))*";
/**
* Configuration label property name. The label is saved in the languages
* file under this property.
*/
public static final String DAILYMOTION_CONFIG_LABEL = "DAILYMOTION";
/**
* Constructor for <tt>ReplacementServiceDailymotionImpl</tt>. The source
* needs to add itself to {@link ReplacementService} sourceList to be
* displayed in the configuration panel.
*/
public ReplacementServiceDailymotionImpl()
{
sourceList.add(DAILYMOTION_CONFIG_LABEL);
logger.trace("Creating a DailyMotion Source.");
}
/**
* Replaces the dailymotion 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.
*/
public String getReplacedMessage(final String chatString)
{
final Pattern p =
Pattern.compile(DAILYMOTION_PATTERN, Pattern.CASE_INSENSITIVE
| Pattern.DOTALL);
Matcher m = p.matcher(chatString);
int count = 0, startPos = 0;
StringBuffer msgBuff = new StringBuffer();
while (m.find())
{
count++;
msgBuff.append(chatString.substring(startPos, m.start()));
startPos = m.end();
if (count % 2 == 0)
{
msgBuff.append("<IMG HEIGHT=\"120\" WIDTH=\"160\" SRC=\"");
msgBuff
.append("http://www.dailymotion.com/thumbnail/160x120/video/");
msgBuff.append(m.group(3));
msgBuff.append("\"></IMG>");
}
else
{
msgBuff.append(chatString.substring(m.start(), m.end()));
}
}
msgBuff.append(chatString.substring(startPos));
if (!msgBuff.toString().equals(chatString))
return msgBuff.toString();
return chatString;
}
}

@ -0,0 +1,14 @@
Bundle-Activator: net.java.sip.communicator.impl.replacement.dailymotion.DailymotionActivator
Bundle-Name: Dailymotion Replacement Source
Bundle-Description: A bundle providing replacement for dailymotion links.
Bundle-Vendor: sip-communicator.org
Bundle-Version: 1.0.0
System-Bundle: yes
Export-Package: net.java.sip.communicator.service.replacement
Import-Package: org.osgi.framework,
net.java.sip.communicator.service.configuration,
net.java.sip.communicator.service.resources,
net.java.sip.communicator.service.configuration.event,
net.java.sip.communicator.util,
net.java.sip.communicator.service.version,
net.java.sip.communicator.service.replacement

@ -0,0 +1,70 @@
/*
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.replacement.directimage;
import java.util.*;
import net.java.sip.communicator.service.replacement.*;
import net.java.sip.communicator.util.*;
import org.osgi.framework.*;
/**
* Activator for the direct image links source bundle.
* @author Purvesh Sahoo
*/
public class DirectImageActivator
implements BundleActivator
{
/**
* The <tt>Logger</tt> used by the <tt>DirectImageActivator</tt>
* class.
*/
private static final Logger logger =
Logger.getLogger(DirectImageActivator.class);
/**
* The direct image source service registration.
*/
private ServiceRegistration directImageSourceServReg = null;
/**
* The source implementation reference.
*/
private static ReplacementService directImageSource = null;
/**
* Starts the Direct image links replacement source bundle
*
* @param context the <tt>BundleContext</tt> as provided from the OSGi
* framework
* @throws Exception if anything goes wrong
*/
public void start(BundleContext context) throws Exception
{
Hashtable<String, String> hashtable = new Hashtable<String, String>();
hashtable.put(ReplacementService.SOURCE_NAME, "DIRECTIMAGE");
directImageSource = new ReplacementServiceDirectImageImpl();
directImageSourceServReg =
context.registerService(ReplacementService.class.getName(),
directImageSource, hashtable);
logger.info("Direct Image Link source implementation [STARTED].");
}
/**
* Unregisters the Direct image links replacement service.
*
* @param context BundleContext
* @throws Exception if anything goes wrong
*/
public void stop(BundleContext context) throws Exception
{
directImageSourceServReg.unregister();
logger.info("Direct Image Link source implementation [STOPPED].");
}
}

@ -0,0 +1,90 @@
/*
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license. See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.replacement.directimage;
import java.util.regex.*;
import net.java.sip.communicator.service.replacement.*;
import net.java.sip.communicator.util.*;
/**
* Implements the {@link ReplacementService} to provide previews for direct
* image links.
*
* @author Purvesh Sahoo
*/
public class ReplacementServiceDirectImageImpl
implements ReplacementService
{
/**
* The logger for this class.
*/
private static final Logger logger =
Logger.getLogger(ReplacementServiceDirectImageImpl.class);
/**
* The regex used to match the link in the message.
*/
public static final String URL_PATTERN =
"[^<>]+\\.(?:jpg|png|gif)[^<>]*(?=</a>)";
/**
* Configuration label property name. The label is saved in the languages
* file under this property.
*/
public static final String DIRECT_IMAGE_CONFIG_LABEL = "DIRECTIMAGE";
/**
* Constructor for <tt>ReplacementServiceDirectImageImpl</tt>. The source
* needs to add itself to {@link ReplacementService} sourceList to be
* displayed in the configuration panel.
*/
public ReplacementServiceDirectImageImpl()
{
sourceList.add(DIRECT_IMAGE_CONFIG_LABEL);
logger.trace("Creating a Direct Image Link Source.");
}
/**
* Replaces the direct image 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 exception.
*/
public String getReplacedMessage(String chatString)
{
final Pattern p =
Pattern.compile(URL_PATTERN, Pattern.CASE_INSENSITIVE
| Pattern.DOTALL);
Matcher m = p.matcher(chatString);
int count = 0, startPos = 0;
StringBuffer msgBuff = new StringBuffer();
while (m.find())
{
count++;
msgBuff.append(chatString.substring(startPos, m.start()));
startPos = m.end();
String url =
"<IMG HEIGHT=\"90\" WIDTH=\"120\" SRC=\"" + m.group(0)
+ "\"></IMG>";
msgBuff.append(url);
}
msgBuff.append(chatString.substring(startPos));
if (!msgBuff.toString().equals(chatString))
return msgBuff.toString();
return chatString;
}
}

@ -0,0 +1,14 @@
Bundle-Activator: net.java.sip.communicator.impl.replacement.directimage.DirectImageActivator
Bundle-Name: Direct Image Link Replacement Source
Bundle-Description: A bundle providing replacement for direct image links.
Bundle-Vendor: sip-communicator.org
Bundle-Version: 1.0.0
System-Bundle: yes
Export-Package: net.java.sip.communicator.service.replacement
Import-Package: org.osgi.framework,
net.java.sip.communicator.service.configuration,
net.java.sip.communicator.service.resources,
net.java.sip.communicator.service.configuration.event,
net.java.sip.communicator.util,
net.java.sip.communicator.service.version,
net.java.sip.communicator.service.replacement

@ -0,0 +1,70 @@
/*
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license. See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.replacement.flickr;
import java.util.*;
import net.java.sip.communicator.service.replacement.*;
import net.java.sip.communicator.util.*;
import org.osgi.framework.*;
/**
* Activator for the Flickr source bundle.
*
* @author Purvesh Sahoo
*/
public class FlickrActivator
implements BundleActivator
{
/**
* The <tt>Logger</tt> used by the <tt>FlickrActivator</tt> class.
*/
private static final Logger logger =
Logger.getLogger(FlickrActivator.class);
/**
* Flickr service registration.
*/
private ServiceRegistration flickrServReg = null;
/**
* The source implementation reference.
*/
private static ReplacementService flickrSource = null;
/**
* Starts the Flickr replacement source bundle
*
* @param context the <tt>BundleContext</tt> as provided from the OSGi
* framework
* @throws Exception if anything goes wrong
*/
public void start(BundleContext context) throws Exception
{
Hashtable<String, String> hashtable = new Hashtable<String, String>();
hashtable.put(ReplacementService.SOURCE_NAME, "FLICKR");
flickrSource = new ReplacementServiceFlickrImpl();
flickrServReg =
context.registerService(ReplacementService.class.getName(),
flickrSource, hashtable);
logger.info("Flickr source implementation [STARTED].");
}
/**
* Unregisters the Flickr replacement service.
*
* @param context BundleContext
* @throws Exception if anything goes wrong
*/
public void stop(BundleContext context) throws Exception
{
flickrServReg.unregister();
logger.info("Flickr source implementation [STOPPED].");
}
}

@ -0,0 +1,158 @@
/*
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license. See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.replacement.flickr;
import java.io.*;
import java.net.*;
import java.util.regex.*;
import org.json.*;
import net.java.sip.communicator.service.replacement.*;
import net.java.sip.communicator.util.*;
/**
* Implements the {@link ReplacementService} to provide previews for Flickr
* links.
*
* @author Purvesh Sahoo
*/
public class ReplacementServiceFlickrImpl
implements ReplacementService
{
/**
* The logger for this class.
*/
private static final Logger logger =
Logger.getLogger(ReplacementServiceFlickrImpl.class);
/**
* The regex used to match the link in the message.
*/
public static final String FLICKR_PATTERN =
"(http.*?(www\\.)*?flickr\\.com\\/photos\\/[0-9a-zA-Z_\\-\\@]+\\/([0-9]+)(\\/[^\"\\<]*)*)";
/**
* API Key required to access the Flickr api.
*/
public static final String API_KEY = "8b5d9cee22f0f5154bf4e9846c025484";
/**
* Configuration label property name. The label is saved in the languages
* file under this property.
*/
public static final String FLICKR_CONFIG_LABEL = "FLICKR";
/**
* Constructor for <tt>ReplacementServiceFlickrImpl</tt>. The source needs
* to add itself to {@link ReplacementService} sourceList to be displayed in
* the configuration panel.
*/
public ReplacementServiceFlickrImpl()
{
sourceList.add(FLICKR_CONFIG_LABEL);
logger.trace("Creating a Flickr Source.");
}
/**
* Replaces the Flickr image 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.
*/
public String getReplacedMessage(String chatString)
{
final Pattern p =
Pattern.compile(FLICKR_PATTERN, Pattern.CASE_INSENSITIVE
| Pattern.DOTALL);
Matcher m = p.matcher(chatString);
int count = 0, startPos = 0;
StringBuffer msgBuff = new StringBuffer();
while (m.find())
{
count++;
msgBuff.append(chatString.substring(startPos, m.start()));
startPos = m.end();
if (count % 2 == 0)
{
try
{
// API URL
String url =
"http://api.flickr.com/services/rest/?method=flickr.photos.getInfo&api_key="
+ API_KEY + "&photo_id=" + m.group(3)
+ "&format=json&nojsoncallback=1";
URL flickrURL = new URL(url);
URLConnection conn = flickrURL.openConnection();
BufferedReader in =
new BufferedReader(new InputStreamReader(conn
.getInputStream()));
String inputLine, holder = "";
while ((inputLine = in.readLine()) != null)
holder = inputLine;
in.close();
JSONObject wrapper = new JSONObject(holder);
if (wrapper.getString("stat").equals("ok"))
{
JSONObject result = wrapper.getJSONObject("photo");
String farmID = result.getString("farm");
String serverID = result.getString("server");
String secret = result.getString("secret");
String thumbURL =
"http://farm" + farmID + ".static.flickr.com/"
+ serverID + "/" + m.group(3) + "_" + secret
+ "_t.jpg";
if (!(result.length() == 0))
{
msgBuff
.append("<IMG HEIGHT=\"90\" WIDTH=\"120\" SRC=\"");
msgBuff.append(thumbURL);
msgBuff.append("\"></IMG>");
}
}
else
{
startPos = 0;
msgBuff = new StringBuffer();
}
}
catch (Exception e)
{
startPos = 0;
msgBuff = new StringBuffer();
e.printStackTrace();
}
}
else
{
msgBuff.append(chatString.substring(m.start(), m.end()));
}
}
msgBuff.append(chatString.substring(startPos));
if (!msgBuff.toString().equals(chatString))
return msgBuff.toString();
return chatString;
}
}

@ -0,0 +1,13 @@
Bundle-Activator: net.java.sip.communicator.impl.replacement.flickr.FlickrActivator
Bundle-Name: Flickr Preview Replacement Source
Bundle-Description: A bundle providing processing for flickr previews.
Bundle-Vendor: sip-communicator.org
Bundle-Version: 1.0.0
System-Bundle: yes
Export-Package: net.java.sip.communicator.service.replacement
Import-Package: org.osgi.framework,
net.java.sip.communicator.service.configuration,
net.java.sip.communicator.service.resources,
net.java.sip.communicator.util,
net.java.sip.communicator.service.replacement,
org.apache.http

@ -0,0 +1,69 @@
/*
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license. See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.replacement.hulu;
import java.util.*;
import net.java.sip.communicator.service.replacement.*;
import net.java.sip.communicator.util.*;
import org.osgi.framework.*;
/**
* Activator for the Hulu source bundle.
*
* @author Purvesh Sahoo
*/
public class HuluActivator
implements BundleActivator
{
/**
* The <tt>Logger</tt> used by the <tt>HuluActivator</tt> class.
*/
private static final Logger logger = Logger.getLogger(HuluActivator.class);
/**
* The hulu service registration.
*/
private ServiceRegistration huluServReg = null;
/**
* The source implementation reference.
*/
private static ReplacementService huluSource = null;
/**
* Starts the Hulu replacement source bundle
*
* @param context the <tt>BundleContext</tt> as provided from the OSGi
* framework
* @throws Exception if anything goes wrong
*/
public void start(BundleContext context) throws Exception
{
Hashtable<String, String> hashtable = new Hashtable<String, String>();
hashtable.put(ReplacementService.SOURCE_NAME, "HULU");
huluSource = new ReplacementServiceHuluImpl();
huluServReg =
context.registerService(ReplacementService.class.getName(),
huluSource, hashtable);
logger.info("HULU source implementation [STARTED].");
}
/**
* Unregisters the Hulu replacement service.
*
* @param context BundleContext
* @throws Exception if anything goes wrong
*/
public void stop(BundleContext context) throws Exception
{
huluServReg.unregister();
logger.info("Hulu source implementation [STOPPED].");
}
}

@ -0,0 +1,138 @@
/*
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license. See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.replacement.hulu;
import java.io.*;
import java.net.*;
import java.util.regex.*;
import org.json.*;
import net.java.sip.communicator.service.replacement.*;
import net.java.sip.communicator.util.*;
/**
* Implements the {@link ReplacementService} to provide previews for Hulu links.
*
* @author Purvesh Sahoo
*/
public class ReplacementServiceHuluImpl
implements ReplacementService
{
/**
* The logger for this class.
*/
private static final Logger logger =
Logger.getLogger(ReplacementServiceHuluImpl.class);
/**
* The regex used to match the link in the message.
*/
public static final String HULU_PATTERN =
"(http.*?(www\\.)*?hulu\\.com\\/watch\\/([a-zA-Z0-9_\\-]+))(\\/([^\\\"\\<]*)*)";
/**
* Configuration label property name. The label is saved in the languages
* file under this property.
*/
public static final String HULU_CONFIG_LABEL = "HULU";
/**
* Constructor for <tt>ReplacementServiceHuluImpl</tt>. The source needs to
* register itself with {@link ReplacementService} sourceList to be
* displayed in the configuration panel.
*/
public ReplacementServiceHuluImpl()
{
sourceList.add(HULU_CONFIG_LABEL);
logger.trace("Creating a Hulu Source.");
}
/**
* Replaces the Hulu 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.
*/
public String getReplacedMessage(String chatString)
{
final Pattern p =
Pattern.compile(HULU_PATTERN, Pattern.CASE_INSENSITIVE
| Pattern.DOTALL);
Matcher m = p.matcher(chatString);
int count = 0, startPos = 0;
StringBuffer msgBuff = new StringBuffer();
while (m.find())
{
count++;
msgBuff.append(chatString.substring(startPos, m.start()));
startPos = m.end();
if (count % 2 == 0)
{
try
{
String url =
"http://oohembed.com/oohembed/?url=" + m.group(0);
URL sourceURL = new URL(url);
URLConnection conn = sourceURL.openConnection();
BufferedReader in =
new BufferedReader(new InputStreamReader(conn
.getInputStream()));
String inputLine, holder = "";
while ((inputLine = in.readLine()) != null)
holder = inputLine;
in.close();
JSONObject wrapper = new JSONObject(holder);
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)
{
startPos = 0;
msgBuff = new StringBuffer();
e.printStackTrace();
}
}
else
{
msgBuff.append(chatString.substring(m.start(), m.end()));
}
}
msgBuff.append(chatString.substring(startPos));
if (!msgBuff.toString().equals(chatString))
return msgBuff.toString();
return chatString;
}
}

@ -0,0 +1,13 @@
Bundle-Activator: net.java.sip.communicator.impl.replacement.hulu.HuluActivator
Bundle-Name: Hulu Preview Replacement Source
Bundle-Description: A bundle providing processing for Hulu previews.
Bundle-Vendor: sip-communicator.org
Bundle-Version: 1.0.0
System-Bundle: yes
Export-Package: net.java.sip.communicator.service.replacement
Import-Package: org.osgi.framework,
net.java.sip.communicator.service.configuration,
net.java.sip.communicator.service.resources,
net.java.sip.communicator.util,
net.java.sip.communicator.service.replacement,
org.apache.http

@ -0,0 +1,70 @@
/*
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license. See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.replacement.metacafe;
import java.util.*;
import net.java.sip.communicator.service.replacement.*;
import net.java.sip.communicator.util.*;
import org.osgi.framework.*;
/**
* Activator for the Metacafe source bundle.
*
* @author Purvesh Sahoo
*/
public class MetacafeActivator
implements BundleActivator
{
/**
* The <tt>Logger</tt> used by the <tt>MetacafeActivator</tt> class.
*/
private static final Logger logger =
Logger.getLogger(MetacafeActivator.class);
/**
* The metacafe service registration.
*/
private ServiceRegistration metacafeServReg = null;
/**
* The source implementation reference.
*/
private static ReplacementService metacafeSource = null;
/**
* Starts the Metacafe replacement source bundle
*
* @param context the <tt>BundleContext</tt> as provided from the OSGi
* framework
* @throws Exception if anything goes wrong
*/
public void start(BundleContext context) throws Exception
{
Hashtable<String, String> hashtable = new Hashtable<String, String>();
hashtable.put(ReplacementService.SOURCE_NAME, "METACAFE");
metacafeSource = new ReplacementServiceMetacafeImpl();
metacafeServReg =
context.registerService(ReplacementService.class.getName(),
metacafeSource, hashtable);
logger.info("Metacafe source implementation [STARTED].");
}
/**
* Unregisters the Metacafe replacement service.
*
* @param context BundleContext
* @throws Exception if anything goes wrong
*/
public void stop(BundleContext context) throws Exception
{
metacafeServReg.unregister();
logger.info("Metacafe source implementation [STOPPED].");
}
}

@ -0,0 +1,95 @@
/*
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license. See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.replacement.metacafe;
import java.util.regex.*;
import net.java.sip.communicator.service.replacement.*;
import net.java.sip.communicator.util.*;
/**
* Implements the {@link ReplacementService} to provide previews for Metacafe
* links.
*
* @author Purvesh Sahoo
*/
public class ReplacementServiceMetacafeImpl
implements ReplacementService
{
/**
* The logger for this class.
*/
private static final Logger logger =
Logger.getLogger(ReplacementServiceMetacafeImpl.class);
/**
* The regex used to match the link in the message.
*/
public static final String METACAFE_PATTERN =
"(http.*?(www\\.)*?metacafe\\.com\\/watch\\/([a-zA-Z0-9_\\-]+))(\\/[a-zA-Z0-9_\\-\\/]+)*";
/**
* Configuration label property name. The label is saved in the languages
* file under this property.
*/
public static final String METACAFE_CONFIG_LABEL = "METACAFE";
/**
* Constructor for <tt>ReplacementServiceMetacafeImpl</tt>. The source needs
* to register itself with {@link ReplacementService} sourceList to be
* displayed in the configuration panel.
*/
public ReplacementServiceMetacafeImpl()
{
logger.trace("Creating a Metacafe Source.");
sourceList.add(METACAFE_CONFIG_LABEL);
}
/**
* Replaces the metacafe 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.
*/
public String getReplacedMessage(String chatString)
{
final Pattern p =
Pattern.compile(METACAFE_PATTERN, Pattern.CASE_INSENSITIVE
| Pattern.DOTALL);
Matcher m = p.matcher(chatString);
int count = 0, startPos = 0;
StringBuffer msgBuff = new StringBuffer();
while (m.find())
{
count++;
msgBuff.append(chatString.substring(startPos, m.start()));
startPos = m.end();
if (count % 2 == 0)
{
msgBuff.append("<IMG HEIGHT=\"81\" WIDTH=\"136\" SRC=\"");
msgBuff.append("http://www.metacafe.com/thumb/");
msgBuff.append(m.group(3));
msgBuff.append(".jpg\"></IMG>");
}
else
{
msgBuff.append(chatString.substring(m.start(), m.end()));
}
}
msgBuff.append(chatString.substring(startPos));
if (!msgBuff.toString().equals(chatString))
return msgBuff.toString();
return chatString;
}
}

@ -0,0 +1,12 @@
Bundle-Activator: net.java.sip.communicator.impl.replacement.metacafe.MetacafeActivator
Bundle-Name: Metacafe Preview Replacement Source
Bundle-Description: A bundle providing processing for metacafe previews.
Bundle-Vendor: sip-communicator.org
Bundle-Version: 1.0.0
System-Bundle: yes
Export-Package: net.java.sip.communicator.service.replacement
Import-Package: org.osgi.framework,
net.java.sip.communicator.service.configuration,
net.java.sip.communicator.service.resources,
net.java.sip.communicator.util,
net.java.sip.communicator.service.replacement

@ -0,0 +1,166 @@
/*
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license. See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.replacement.smiley;
import java.util.*;
import java.util.regex.*;
import net.java.sip.communicator.impl.gui.utils.*;
import net.java.sip.communicator.service.replacement.*;
import net.java.sip.communicator.util.*;
/**
* Implements the {@link ReplacementService} to provide smiley as replacement
* source.
*
* @author Yana Stamcheva
* @author Purvesh Sahoo
*/
public class ReplacementServiceSmileyImpl
implements ReplacementService
{
/**
* 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}.
*/
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.
*/
private static final String START_PLAINTEXT_TAG = "<PLAINTEXT>";
/**
* Configuration label property name. The label is saved in the languages
* file under this property.
*/
public static final String SMILEY_SOURCE = "SMILEY";
/**
* 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.
*/
public String getReplacedMessage(final String chatString)
{
String startPlainTextTag = START_PLAINTEXT_TAG;
String endPlainTextTag = END_PLAINTEXT_TAG;
Collection<Smiley> smileys = ImageLoader.getDefaultSmileyPack();
Matcher m = getSmileyPattern(smileys).matcher(chatString);
StringBuffer msgBuffer = new StringBuffer();
int prevEnd = 0;
while (m.find())
{
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(ImageLoader.getSmiley(smileyString)
.getImagePath(SmileyActivator.getResources()));
}
catch (Exception e)
{
e.printStackTrace();
}
msgBuffer.append("\" ALT=\"");
msgBuffer.append(smileyString);
msgBuffer.append("\"></IMG>");
msgBuffer.append(startPlainTextTag);
}
msgBuffer.append(chatString.substring(prevEnd));
return msgBuffer.toString();
}
/**
* Gets a compiled <tt>Pattern</tt> 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
*/
private static Pattern getSmileyPattern(Collection<Smiley> smileys)
{
synchronized (smileyStrings)
{
boolean smileyStringsIsEqual;
if (smileyPattern == null)
smileyStringsIsEqual = false;
else
{
smileyStringsIsEqual = true;
int smileyStringIndex = 0;
int smileyStringCount = smileyStrings.size();
smileyLoop: for (Smiley smiley : smileys)
for (String smileyString : smiley.getSmileyStrings())
if ((smileyStringIndex < smileyStringCount)
&& smileyString.equals(smileyStrings
.get(smileyStringIndex)))
smileyStringIndex++;
else
{
smileyStringsIsEqual = false;
break smileyLoop;
}
if (smileyStringsIsEqual
&& (smileyStringIndex != smileyStringCount))
smileyStringsIsEqual = false;
}
if (!smileyStringsIsEqual)
{
smileyStrings.clear();
StringBuffer regex = new StringBuffer();
regex.append("(?<!(alt='|alt=\"))(");
for (Smiley smiley : smileys)
for (String smileyString : smiley.getSmileyStrings())
{
smileyStrings.add(smileyString);
regex.append(
GuiUtils.replaceSpecialRegExpChars(smileyString))
.append("|");
}
regex = regex.deleteCharAt(regex.length() - 1);
regex.append(')');
smileyPattern = Pattern.compile(regex.toString());
}
return smileyPattern;
}
}
}

@ -0,0 +1,110 @@
/*
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.replacement.smiley;
import java.util.*;
import net.java.sip.communicator.service.replacement.*;
import net.java.sip.communicator.service.resources.*;
import net.java.sip.communicator.util.*;
import org.osgi.framework.*;
/**
* Activator for the Smiley source bundle.
* @author Purvesh Sahoo
*/
public class SmileyActivator
implements BundleActivator
{
/**
* The <tt>Logger</tt> used by the <tt>SmileyActivator</tt>
* class.
*/
private static final Logger logger =
Logger.getLogger(SmileyActivator.class);
/**
* The currently valid bundle context.
*/
private static BundleContext bundleContext = null;
/**
* The resources service
*/
private static ResourceManagementService resourcesService;
/**
* The smileyy service registration.
*/
private ServiceRegistration smileyServReg = null;
/**
* The source implementation reference.
*/
private static ReplacementService smileySource = null;
/**
* Starts the Smiley replacement source bundle
*
* @param context the <tt>BundleContext</tt> as provided from the OSGi
* framework
* @throws Exception if anything goes wrong
*/
public void start(BundleContext context) throws Exception
{
bundleContext = context;
Hashtable<String, String> hashtable = new Hashtable<String, String>();
hashtable.put(ReplacementService.SOURCE_NAME, "SMILEY");
smileySource = new ReplacementServiceSmileyImpl();
smileyServReg =
context.registerService(ReplacementService.class.getName(),
smileySource, hashtable);
logger.info("Smiley source implementation [STARTED].");
}
/**
* Unregisters the Smiley replacement service.
*
* @param context BundleContext
* @throws Exception if anything goes wrong
*/
public void stop(BundleContext context) throws Exception
{
smileyServReg.unregister();
logger.info("Smiley source implementation [STOPPED].");
}
/**
* Returns the <tt>ResourceManagementService</tt>, through which we will
* access all resources.
*
* @return the <tt>ResourceManagementService</tt>, through which we will
* access all resources.
*/
public static ResourceManagementService getResources()
{
if (resourcesService == null)
{
ServiceReference serviceReference =
bundleContext
.getServiceReference(ResourceManagementService.class
.getName());
if (serviceReference == null)
return null;
resourcesService =
(ResourceManagementService) bundleContext
.getService(serviceReference);
}
return resourcesService;
}
}

@ -0,0 +1,15 @@
Bundle-Activator: net.java.sip.communicator.impl.replacement.smiley.SmileyActivator
Bundle-Name: Smiley Replacement Source
Bundle-Description: A bundle providing processing for smileys.
Bundle-Vendor: sip-communicator.org
Bundle-Version: 1.0.0
System-Bundle: yes
Export-Package: net.java.sip.communicator.service.replacement
Import-Package: org.osgi.framework,
net.java.sip.communicator.service.configuration,
net.java.sip.communicator.service.resources,
net.java.sip.communicator.service.neomedia,
net.java.sip.communicator.service.configuration.event,
net.java.sip.communicator.util,
net.java.sip.communicator.service.replacement,
net.java.sip.communicator.service.gui

@ -0,0 +1,89 @@
/*
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license. See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.replacement.twitpic;
import java.util.regex.*;
import net.java.sip.communicator.service.replacement.*;
import net.java.sip.communicator.util.*;
/**
* Implements the {@link ReplacementService} to provide previews for Twitpic
* links.
*
* @author Purvesh Sahoo
*/
public class ReplacementServiceTwitpicImpl
implements ReplacementService
{
/**
* The logger for this class.
*/
private static final Logger logger
= Logger.getLogger(ReplacementServiceTwitpicImpl.class);
/**
* The regex used to match the link in the message.
*/
public static final String TWITPIC_PATTERN =
"http:\\/\\/(?:www\\.)?twitpic\\.com\\/([^\\/<]*)(?=<)";
/**
* Configuration label property name. The label is saved in the languages
* file under this property.
*/
public static final String TWITPIC_CONFIG_LABEL = "TWITPIC";
/**
* Constructor for <tt>ReplacementServiceTwitpicImpl</tt>. The source needs
* to register itself with {@link ReplacementService} sourceList to be
* displayed in the configuration panel.
*/
public ReplacementServiceTwitpicImpl()
{
sourceList.add(TWITPIC_CONFIG_LABEL);
logger.trace("Creating a Twitpic Source.");
}
/**
* Replaces the twitpic image 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.
*/
public String getReplacedMessage(String chatString)
{
final Pattern p =
Pattern.compile(TWITPIC_PATTERN, Pattern.CASE_INSENSITIVE
| Pattern.DOTALL);
Matcher m = p.matcher(chatString);
int count = 0, startPos = 0;
StringBuffer msgBuff = new StringBuffer();
while (m.find())
{
count++;
msgBuff.append(chatString.substring(startPos, m.start()));
startPos = m.end();
msgBuff.append("<IMG HEIGHT=\"90\" WIDTH=\"120\" SRC=\"");
msgBuff.append("http://twitpic.com/show/thumb/");
msgBuff.append(m.group(1));
msgBuff.append("\"></IMG>");
}
msgBuff.append(chatString.substring(startPos));
if (!msgBuff.toString().equals(chatString))
return msgBuff.toString();
return chatString;
}
}

@ -0,0 +1,70 @@
/*
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license. See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.replacement.twitpic;
import java.util.*;
import net.java.sip.communicator.service.replacement.*;
import net.java.sip.communicator.util.*;
import org.osgi.framework.*;
/**
* Activator for the Twitpic source bundle.
*
* @author Purvesh Sahoo
*/
public class TwitpicActivator
implements BundleActivator
{
/**
* The <tt>Logger</tt> used by the <tt>TwitpicActivator</tt> class.
*/
private static final Logger logger =
Logger.getLogger(TwitpicActivator.class);
/**
* The twitpic service registration.
*/
private ServiceRegistration twitpicServReg = null;
/**
* The source implementation reference.
*/
private static ReplacementService twitpicSource = null;
/**
* Starts the Twitpic replacement source bundle
*
* @param context the <tt>BundleContext</tt> as provided from the OSGi
* framework
* @throws Exception if anything goes wrong
*/
public void start(BundleContext context) throws Exception
{
Hashtable<String, String> hashtable = new Hashtable<String, String>();
hashtable.put(ReplacementService.SOURCE_NAME, "TWITPIC");
twitpicSource = new ReplacementServiceTwitpicImpl();
twitpicServReg =
context.registerService(ReplacementService.class.getName(),
twitpicSource, hashtable);
logger.info("Twitpic source implementation [STARTED].");
}
/**
* Unregisters the Twitpic replacement service.
*
* @param context BundleContext
* @throws Exception if anything goes wrong
*/
public void stop(BundleContext context) throws Exception
{
twitpicServReg.unregister();
logger.info("Twitpic source implementation [STOPPED].");
}
}

@ -0,0 +1,12 @@
Bundle-Activator: net.java.sip.communicator.impl.replacement.twitpic.TwitpicActivator
Bundle-Name: Twitpic Preview Replacement Source
Bundle-Description: A bundle providing processing for Twitpic previews.
Bundle-Vendor: sip-communicator.org
Bundle-Version: 1.0.0
System-Bundle: yes
Export-Package: net.java.sip.communicator.service.replacement
Import-Package: org.osgi.framework,
net.java.sip.communicator.service.configuration,
net.java.sip.communicator.service.resources,
net.java.sip.communicator.util,
net.java.sip.communicator.service.replacement

@ -0,0 +1,96 @@
/*
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license. See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.replacement.vbox7;
import java.util.regex.*;
import net.java.sip.communicator.service.replacement.*;
import net.java.sip.communicator.util.*;
/**
* Implements the {@link ReplacementService} to provide previews for Vbox7
* links.
*
* @author Purvesh Sahoo
*/
public class ReplacementServiceVbox7Impl
implements ReplacementService
{
/**
* The logger for this class.
*/
private static final Logger logger =
Logger.getLogger(ReplacementServiceVbox7Impl.class);
/**
* The regex used to match the link in the message.
*/
public static final String VBOX7_PATTERN =
"(http.*?(www\\.)*?vbox7\\.com\\/play\\:([a-zA-Z0-9_\\-]+))([?&]\\w+=[\\w-]*)*";
/**
* Configuration label property name. The label is saved in the languages
* file under this property.
*/
public static final String VBOX7_CONFIG_LABEL = "VBOX7";
/**
* Constructor for <tt>ReplacementServiceVbox7Impl</tt>. The source needs
* to register itself with {@link ReplacementService} sourceList to be
* displayed in the configuration panel.
*/
public ReplacementServiceVbox7Impl()
{
sourceList.add(VBOX7_CONFIG_LABEL);
logger.trace("Creating a Vbox7 Source.");
}
/**
* Replaces the vbox7 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.
*/
public String getReplacedMessage(String chatString)
{
final Pattern p =
Pattern.compile(VBOX7_PATTERN, Pattern.CASE_INSENSITIVE
| Pattern.DOTALL);
Matcher m = p.matcher(chatString);
int count = 0, startPos = 0;
StringBuffer msgBuff = new StringBuffer();
while (m.find())
{
count++;
msgBuff.append(chatString.substring(startPos, m.start()));
startPos = m.end();
if (count % 2 == 0)
{
msgBuff.append("<IMG HEIGHT=\"90\" WIDTH=\"120\" SRC=\"");
msgBuff
.append("http://i.vbox7.com/p/");
msgBuff.append(m.group(3));
msgBuff.append("3.jpg\"></IMG>");
}
else
{
msgBuff.append(chatString.substring(m.start(), m.end()));
}
}
msgBuff.append(chatString.substring(startPos));
if (!msgBuff.toString().equals(chatString))
return msgBuff.toString();
return chatString;
}
}

@ -0,0 +1,70 @@
/*
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.replacement.vbox7;
import java.util.*;
import net.java.sip.communicator.service.replacement.*;
import net.java.sip.communicator.util.*;
import org.osgi.framework.*;
/**
* Activator for the VBOX7 source bundle.
* @author Purvesh Sahoo
*/
public class Vbox7Activator
implements BundleActivator
{
/**
* The <tt>Logger</tt> used by the <tt>Vbox7Activator</tt>
* class.
*/
private static final Logger logger = Logger.getLogger(Vbox7Activator.class);
/**
* The vbox7 service registration.
*/
private ServiceRegistration vbox7ServReg = null;
/**
* The source implementation reference.
*/
private static ReplacementService vbox7Source = null;
/**
* Starts the Vbox7 replacement source bundle
*
* @param context the <tt>BundleContext</tt> as provided from the OSGi
* framework
* @throws Exception if anything goes wrong
*/
public void start(BundleContext context) throws Exception
{
Hashtable<String, String> hashtable = new Hashtable<String, String>();
hashtable.put(ReplacementService.SOURCE_NAME, "VBOX7");
vbox7Source = new ReplacementServiceVbox7Impl();
vbox7ServReg =
context.registerService(ReplacementService.class.getName(),
vbox7Source, hashtable);
logger.info("Vbox7 source implementation [STARTED].");
}
/**
* Unregisters the Vbox7 replacement service.
*
* @param context BundleContext
* @throws Exception if anything goes wrong
*/
public void stop(BundleContext context) throws Exception
{
vbox7ServReg.unregister();
logger.info("Vbox7 source implementation [STOPPED].");
}
}

@ -0,0 +1,12 @@
Bundle-Activator: net.java.sip.communicator.impl.replacement.vbox7.Vbox7Activator
Bundle-Name: Vbox7 Preview Replacement Source
Bundle-Description: A bundle providing processing for vbox7 previews.
Bundle-Vendor: sip-communicator.org
Bundle-Version: 1.0.0
System-Bundle: yes
Export-Package: net.java.sip.communicator.service.replacement
Import-Package: org.osgi.framework,
net.java.sip.communicator.service.configuration,
net.java.sip.communicator.service.resources,
net.java.sip.communicator.util,
net.java.sip.communicator.service.replacement

@ -0,0 +1,145 @@
/*
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license. See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.replacement.viddler;
import java.io.*;
import java.net.*;
import java.util.regex.*;
import net.java.sip.communicator.service.replacement.*;
import net.java.sip.communicator.util.*;
/**
* Implements the {@link ReplacementService} to provide previews for Viddler
* links.
*
* @author Purvesh Sahoo
*/
public class ReplacementServiceViddlerImpl
implements ReplacementService
{
/**
* The logger for this class.
*/
private static final Logger logger =
Logger.getLogger(ReplacementServiceViddlerImpl.class);
/**
* 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>))";
/**
* API Key required to access the viddler api.
*/
private static final String API_KEY = "1bi6ckuzmklyaqseiqtl";
/**
* Viddler API url.
*/
private static final String sourceURL =
"http://api.viddler.com/rest/v1/?method=viddler.videos.getDetailsByUrl&api_key="
+ API_KEY;
/**
* Configuration label property name. The label is saved in the languages
* file under this property.
*/
public static final String VIDDLER_CONFIG_LABEL = "VIDDLER";
/**
* Constructor for <tt>ReplacementServiceViddlerImpl</tt>. The source needs
* to add itself to {@link ReplacementService} sourceList to be
* displayed in the configuration panel.
*/
public ReplacementServiceViddlerImpl()
{
sourceList.add(VIDDLER_CONFIG_LABEL);
logger.trace("Creating a Viddler Source.");
}
/**
* Replaces the viddler 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.
*/
public String getReplacedMessage(String chatString)
{
final Pattern p =
Pattern.compile(VIDDLER_PATTERN, Pattern.CASE_INSENSITIVE
| Pattern.DOTALL);
Matcher m = p.matcher(chatString);
int count = 0, startPos = 0;
StringBuffer msgBuff = new StringBuffer();
while (m.find())
{
count++;
msgBuff.append(chatString.substring(startPos, m.start()));
startPos = m.end();
try
{
String url = sourceURL + "&url=" + m.group(1) + "/";
URL sourceURL = new URL(url);
URLConnection conn = sourceURL.openConnection();
BufferedReader in =
new BufferedReader(new InputStreamReader(conn
.getInputStream()));
String inputLine;
StringBuffer holder = new StringBuffer();
while ((inputLine = in.readLine()) != null)
holder.append(inputLine);
in.close();
String startTag = "<thumbnail_url>";
String endTag = "</thumbnail_url>";
String response = holder.toString();
int start = response.indexOf(startTag) + startTag.length();
int end = response.toString().indexOf(endTag);
String thumbUrl = response.substring(start, end);
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)
{
startPos = 0;
msgBuff = new StringBuffer();
e.printStackTrace();
}
}
msgBuff.append(chatString.substring(startPos));
if (!msgBuff.toString().equals(chatString))
return msgBuff.toString();
return chatString;
}
}

@ -0,0 +1,71 @@
/*
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.replacement.viddler;
import java.util.*;
import net.java.sip.communicator.service.replacement.*;
import net.java.sip.communicator.util.*;
import org.osgi.framework.*;
/**
* Activator for the Viddler source bundle.
* @author Purvesh Sahoo
*/
public class ViddlerActivator
implements BundleActivator
{
/**
* The <tt>Logger</tt> used by the <tt>ViddlerActivator</tt>
* class.
*/
private static final Logger logger =
Logger.getLogger(ViddlerActivator.class);
/**
* The Viddler source service registration.
*/
private ServiceRegistration viddlerServReg = null;
/**
* The source implementation reference.
*/
private static ReplacementService viddlerSource = null;
/**
* Starts this bundle.
*
* @param context bundle context.
* @throws Exception
*/
public void start(BundleContext context) throws Exception
{
Hashtable<String, String> hashtable = new Hashtable<String, String>();
hashtable.put(ReplacementService.SOURCE_NAME, "VIDDLER");
viddlerSource = new ReplacementServiceViddlerImpl();
viddlerServReg =
context.registerService(ReplacementService.class.getName(),
viddlerSource, hashtable);
logger.info("Viddler source implementation [STARTED].");
}
/**
* Stops bundle.
*
* @param bc context.
* @throws Exception
*/
public void stop(BundleContext bc) throws Exception
{
viddlerServReg.unregister();
logger.info("Viddler source implementation [STOPPED].");
}
}

@ -0,0 +1,13 @@
Bundle-Activator: net.java.sip.communicator.impl.replacement.viddler.ViddlerActivator
Bundle-Name: Viddler Preview Replacement Source
Bundle-Description: A bundle providing processing for Viddler previews.
Bundle-Vendor: sip-communicator.org
Bundle-Version: 1.0.0
System-Bundle: yes
Export-Package: net.java.sip.communicator.service.replacement
Import-Package: org.osgi.framework,
net.java.sip.communicator.service.configuration,
net.java.sip.communicator.service.resources,
net.java.sip.communicator.util,
net.java.sip.communicator.service.replacement,
org.apache.http

@ -0,0 +1,137 @@
/*
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license. See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.replacement.vimeo;
import java.net.*;
import java.util.regex.*;
import org.json.*;
import net.java.sip.communicator.service.replacement.*;
import net.java.sip.communicator.util.*;
import java.io.*;
/**
* Implements the {@link ReplacementService} to provide previews for Vimeo
* links.
*
* @author Purvesh Sahoo
*/
public class ReplacementServiceVimeoImpl
implements ReplacementService
{
/**
* The logger for this class.
*/
private static final Logger logger =
Logger.getLogger(ReplacementServiceVimeoImpl.class);
/**
* The regex used to match the link in the message.
*/
public static final String VIMEO_PATTERN =
"(http.*?(www\\.)*?vimeo\\.com\\/([a-zA-Z0-9_\\-]+))";
/**
* Configuration label property name. The label is saved in the languages
* file under this property.
*/
public static final String VIMEO_CONFIG_LABEL = "VIMEO";
/**
* Constructor for <tt>ReplacementServiceVimeoImpl</tt>. The source needs
* to register itself with {@link ReplacementService} sourceList to be
* displayed in the configuration panel.
*/
public ReplacementServiceVimeoImpl()
{
sourceList.add(VIMEO_CONFIG_LABEL);
logger.trace("Creating a Vimeo Source.");
}
/**
* Replaces the vimeo 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.
*/
public String getReplacedMessage(String chatString)
{
final Pattern p =
Pattern.compile(VIMEO_PATTERN, Pattern.CASE_INSENSITIVE
| Pattern.DOTALL);
Matcher m = p.matcher(chatString);
int count = 0, startPos = 0;
StringBuffer msgBuff = new StringBuffer();
while (m.find())
{
count++;
msgBuff.append(chatString.substring(startPos, m.start()));
startPos = m.end();
if (count % 2 == 0)
{
try
{
String url =
"http://vimeo.com/api/v2/video/" + m.group(3) + ".json";
URL vimeoURL = new URL(url);
URLConnection conn = vimeoURL.openConnection();
BufferedReader in =
new BufferedReader(new InputStreamReader(conn
.getInputStream()));
String inputLine, holder = "";
while ((inputLine = in.readLine()) != null)
holder = inputLine;
in.close();
JSONArray result = new JSONArray(holder);
if (!(result.length() == 0))
{
msgBuff
.append("<IMG HEIGHT=\"150\" WIDTH=\"200\" SRC=\"");
msgBuff.append(result.getJSONObject(0).getString(
"thumbnail_medium"));
msgBuff.append("\"></IMG>");
}
else
{
startPos = 0;
msgBuff = new StringBuffer();
}
}
catch (Exception e)
{
startPos = 0;
msgBuff = new StringBuffer();
e.printStackTrace();
}
}
else
{
msgBuff.append(chatString.substring(m.start(), m.end()));
}
}
msgBuff.append(chatString.substring(startPos));
if (!msgBuff.toString().equals(chatString))
return msgBuff.toString();
return chatString;
}
}

@ -0,0 +1,69 @@
/*
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license. See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.replacement.vimeo;
import java.util.*;
import net.java.sip.communicator.service.replacement.*;
import net.java.sip.communicator.util.*;
import org.osgi.framework.*;
/**
* Activator for the Vimeo source bundle.
*
* @author Purvesh Sahoo
*/
public class VimeoActivator
implements BundleActivator
{
/**
* The logger for this class.
*/
private static final Logger logger = Logger.getLogger(VimeoActivator.class);
/**
* The vimeo service registration.
*/
private ServiceRegistration vimeoServReg = null;
/**
* The source implementation reference.
*/
private static ReplacementService vimeoSource = null;
/**
* Starts the Vimeo replacement source bundle
*
* @param context the <tt>BundleContext</tt> as provided from the OSGi
* framework
* @throws Exception if anything goes wrong
*/
public void start(BundleContext context) throws Exception
{
Hashtable<String, String> hashtable = new Hashtable<String, String>();
hashtable.put(ReplacementService.SOURCE_NAME, "VIMEO");
vimeoSource = new ReplacementServiceVimeoImpl();
vimeoServReg =
context.registerService(ReplacementService.class.getName(),
vimeoSource, hashtable);
logger.info("Vimeo source implementation [STARTED].");
}
/**
* Unregisters the Vimeo replacement service.
*
* @param context BundleContext
* @throws Exception if anything goes wrong
*/
public void stop(BundleContext context) throws Exception
{
vimeoServReg.unregister();
logger.info("Vimeo source implementation [STOPPED].");
}
}

@ -0,0 +1,13 @@
Bundle-Activator: net.java.sip.communicator.impl.replacement.vimeo.VimeoActivator
Bundle-Name: Vimeo Preview Replacement Source
Bundle-Description: A bundle providing processing for vimeo previews.
Bundle-Vendor: sip-communicator.org
Bundle-Version: 1.0.0
System-Bundle: yes
Export-Package: net.java.sip.communicator.service.replacement
Import-Package: org.osgi.framework,
net.java.sip.communicator.service.configuration,
net.java.sip.communicator.service.resources,
net.java.sip.communicator.util,
net.java.sip.communicator.service.replacement,
org.apache.http

@ -0,0 +1,139 @@
/*
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license. See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.replacement.youtube;
import java.io.*;
import java.net.*;
import java.util.regex.*;
import net.java.sip.communicator.service.replacement.*;
import net.java.sip.communicator.util.*;
import org.json.*;
/**
* Implements the {@link ReplacementService} to provide previews for Youtube
* links.
*
* @author Purvesh Sahoo
*/
public class ReplacementServiceYoutubeImpl
implements ReplacementService
{
/**
* The logger for this class.
*/
private static final Logger logger =
Logger.getLogger(ReplacementServiceYoutubeImpl.class);
/**
* The regex used to match the link in the message.
*/
public static String re1 =
"(http.*?(www\\.)*?youtube\\.com\\/watch\\?v=([a-zA-Z0-9_\\-]+))([?&]\\w+=[\\w-]+)*";
/**
* Configuration label property name. The label is saved in the languages
* file under this property.
*/
public static final String YOUTUBE_CONFIG_LABEL = "YOUTUBE";
/**
* Constructor for <tt>ReplacementServiceYoutubeImpl</tt>. The source needs
* to register itself with {@link ReplacementService} sourceList to be
* displayed in the configuration panel.
*/
public ReplacementServiceYoutubeImpl()
{
sourceList.add(YOUTUBE_CONFIG_LABEL);
logger.trace("Creating a Youtube Source.");
}
/**
* Replaces the youtube 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.
*/
public String getReplacedMessage(final String chatString)
{
final Pattern p =
Pattern.compile(re1, Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
Matcher m = p.matcher(chatString);
int count = 0, startPos = 0;
StringBuffer msgBuff = new StringBuffer();
while (m.find())
{
count++;
msgBuff.append(chatString.substring(startPos, m.start()));
startPos = m.end();
// We only want to replace the inner link text and not the link src.
// All even matches are the text we want to replace.
if (count % 2 == 0)
{
try
{
String url =
"http://youtube.com/oembed/?url=" + m.group(0);
URL sourceURL = new URL(url);
URLConnection conn = sourceURL.openConnection();
BufferedReader in =
new BufferedReader(new InputStreamReader(conn
.getInputStream()));
String inputLine, holder = "";
while ((inputLine = in.readLine()) != null)
holder = inputLine;
in.close();
JSONObject wrapper = new JSONObject(holder);
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)
{
startPos = 0;
msgBuff = new StringBuffer();
e.printStackTrace();
}
}
else
{
msgBuff.append(chatString.substring(m.start(), m.end()));
}
}
msgBuff.append(chatString.substring(startPos));
if (!msgBuff.toString().equals(chatString))
return msgBuff.toString();
return chatString;
}
}

@ -0,0 +1,69 @@
/*
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license. See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.replacement.youtube;
import java.util.*;
import net.java.sip.communicator.service.replacement.*;
import net.java.sip.communicator.util.*;
import org.osgi.framework.*;
/**
* Activator for the Youtube source bundle.
*
* @author Purvesh Sahoo
*/
public class YoutubeActivator
implements BundleActivator
{
/**
* The <tt>Logger</tt> used by the <tt>YoutubeActivator</tt> class.
*/
private static final Logger logger =
Logger.getLogger(YoutubeActivator.class);
/**
* The youtube source service registration.
*/
private ServiceRegistration youtubeSourceServReg = null;
/**
* The source implementation reference.
*/
private static ReplacementService youtubeSource = null;
/**
* Starts the Youtube replacement source bundle
*
* @param context the <tt>BundleContext</tt> as provided from the OSGi
* framework
* @throws Exception if anything goes wrong
*/
public void start(BundleContext context) throws Exception
{
Hashtable<String, String> hashtable = new Hashtable<String, String>();
hashtable.put(ReplacementService.SOURCE_NAME, "YOUTUBE");
youtubeSource = new ReplacementServiceYoutubeImpl();
youtubeSourceServReg =
context.registerService(ReplacementService.class.getName(),
youtubeSource, hashtable);
logger.info("Youtube source implementation [STARTED].");
}
/**
* Unregisters the Youtube replacement service.
*
* @param context BundleContext
* @throws Exception if anything goes wrong
*/
public void stop(BundleContext context) throws Exception
{
youtubeSourceServReg.unregister();
logger.info("Youtube source implementation [STOPPED].");
}
}

@ -0,0 +1,14 @@
Bundle-Activator: net.java.sip.communicator.impl.replacement.youtube.YoutubeActivator
Bundle-Name: Youtube Replacement Source
Bundle-Description: A bundle providing replacement for youtube links.
Bundle-Vendor: sip-communicator.org
Bundle-Version: 1.0.0
System-Bundle: yes
Export-Package: net.java.sip.communicator.service.replacement
Import-Package: org.osgi.framework,
net.java.sip.communicator.service.configuration,
net.java.sip.communicator.service.resources,
net.java.sip.communicator.service.configuration.event,
net.java.sip.communicator.util,
net.java.sip.communicator.service.replacement,
org.apache.http

@ -0,0 +1,137 @@
/*
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license. See terms of license at gnu.org.
*/
package net.java.sip.communicator.plugin.chatconfig;
import java.awt.*;
import java.util.*;
import javax.swing.*;
import net.java.sip.communicator.service.configuration.*;
import net.java.sip.communicator.service.gui.*;
import net.java.sip.communicator.service.resources.*;
import net.java.sip.communicator.util.*;
import net.java.sip.communicator.util.swing.*;
import org.osgi.framework.*;
/**
* The chat configuration form activator.
*
* @author Purvesh Sahoo
*/
public class ChatConfigActivator
implements BundleActivator
{
/**
* The <tt>Logger</tt> used by the <tt>ChatConfigActivator</tt> class.
*/
private final static Logger logger =
Logger.getLogger(ChatConfigActivator.class);
/**
* The currently valid bundle context.
*/
public static BundleContext bundleContext;
/**
* The configuration service.
*/
private static ConfigurationService configService;
/**
* The resource management service.
*/
private static ResourceManagementService resourceService;
/**
* Starts this bundle.
*
* @param bc the BundleContext
* @throws Exception if some of the operations executed in the start method
* fails
*/
public void start(BundleContext bc) throws Exception
{
bundleContext = bc;
Dictionary<String, String> properties = new Hashtable<String, String>();
properties.put(ConfigurationForm.FORM_TYPE,
ConfigurationForm.GENERAL_TYPE);
bundleContext.registerService(ConfigurationForm.class.getName(),
new LazyConfigurationForm(
"net.java.sip.communicator.plugin.chatconfig.ChatConfigPanel",
getClass().getClassLoader(), "plugin.chatconfig.PLUGIN_ICON",
"plugin.chatconfig.TITLE", 40), properties);
if (logger.isTraceEnabled())
logger.trace("Chat Configuration: [ STARTED ]");
}
/**
* Stops this bundle.
*
* @param bc the bundle context
* @throws Exception if something goes wrong
*/
public void stop(BundleContext bc) throws Exception {}
/**
* Gets the service giving access to all application resources.
*
* @return the service giving access to all application resources.
*/
public static ResourceManagementService getResources()
{
if (resourceService == null)
resourceService =
ResourceManagementServiceUtils.getService(bundleContext);
return resourceService;
}
/**
* Creates a config section label from the given text.
*
* @param labelText the text of the label.
* @return the created label
*/
public static Component createConfigSectionComponent(String labelText)
{
JLabel label = new JLabel(labelText);
label.setFont(label.getFont().deriveFont(Font.BOLD));
label.setAlignmentX(Component.RIGHT_ALIGNMENT);
JPanel parentPanel = new TransparentPanel(new BorderLayout());
parentPanel.add(label, BorderLayout.NORTH);
parentPanel.setPreferredSize(new Dimension(180, 25));
return parentPanel;
}
/**
* Returns the <tt>ConfigurationService</tt> obtained from the bundle
* context.
*
* @return the <tt>ConfigurationService</tt> obtained from the bundle
* context
*/
public static ConfigurationService getConfigurationService()
{
if (configService == null)
{
ServiceReference configReference =
bundleContext.getServiceReference(ConfigurationService.class
.getName());
configService =
(ConfigurationService) bundleContext
.getService(configReference);
}
return configService;
}
}

@ -0,0 +1,38 @@
/*
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license. See terms of license at gnu.org.
*/
package net.java.sip.communicator.plugin.chatconfig;
import java.awt.*;
import javax.swing.*;
import net.java.sip.communicator.plugin.chatconfig.replacement.*;
import net.java.sip.communicator.util.swing.*;
/**
* The chat configuration panel.
*
* @author Purvesh Sahoo
*/
public class ChatConfigPanel
extends TransparentPanel
{
/**
* Creates the <tt>ChatConfigPanel</tt>.
*/
public ChatConfigPanel()
{
super(new BorderLayout());
TransparentPanel mainPanel = new TransparentPanel();
BoxLayout boxLayout = new BoxLayout(mainPanel, BoxLayout.Y_AXIS);
mainPanel.setLayout(boxLayout);
this.add(mainPanel, BorderLayout.NORTH);
mainPanel.add(new ReplacementConfigPanel());
mainPanel.add(Box.createVerticalStrut(10));
}
}

@ -0,0 +1,28 @@
Bundle-Activator: net.java.sip.communicator.plugin.chatconfig.ChatConfigActivator
Bundle-Name: Plugin Manager Chat
Bundle-Description: Manage all chat options.
Bundle-Vendor: sip-communicator.org
Bundle-Version: 0.0.1
System-Bundle: yes
Import-Package: org.osgi.framework,
net.java.sip.communicator.service.configuration,
net.java.sip.communicator.service.gui,
net.java.sip.communicator.service.gui.event,
net.java.sip.communicator.service.resources,
net.java.sip.communicator.util,
net.java.sip.communicator.util.swing,
net.java.sip.communicator.service.replacement,
javax.swing,
javax.swing.event,
javax.swing.table,
javax.swing.text,
javax.swing.text.html,
javax.accessibility,
javax.swing.plaf,
javax.swing.plaf.metal,
javax.swing.plaf.basic,
javax.imageio,
javax.swing.filechooser,
javax.swing.tree,
javax.swing.undo,
javax.swing.border

@ -0,0 +1,232 @@
/*
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license. See terms of license at gnu.org.
*/
package net.java.sip.communicator.plugin.chatconfig.replacement;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.table.*;
import net.java.sip.communicator.impl.replacement.smiley.*;
import net.java.sip.communicator.plugin.chatconfig.*;
import net.java.sip.communicator.service.configuration.*;
import net.java.sip.communicator.service.replacement.*;
import net.java.sip.communicator.util.swing.*;
/**
* The <tt>ConfigurationForm</tt> that would be added in the chat configuration
* window.
*
* @author Purvesh Sahoo
*/
public class ReplacementConfigPanel
extends TransparentPanel
{
/**
* Checkbox to enable/disable smiley replacement.
*/
private JCheckBox enableSmiley;
/**
* Checkbox to enable/disable replacements other than smileys.
*/
private JCheckBox enableReplacement;
/**
* Jtable to list all the available replacement sources.
*/
private JTable table;
/**
* Create an instance of Replacement Config
*/
public ReplacementConfigPanel()
{
super(new BorderLayout());
add(ChatConfigActivator
.createConfigSectionComponent(ChatConfigActivator.getResources()
.getI18NString("plugin.chatconfig.replacement.TITLE")),
BorderLayout.WEST);
add(createMainPanel());
initValues();
}
/**
* Init the main panel.
*
* @return the created component
*/
private Component createMainPanel()
{
JPanel mainPanel = new TransparentPanel(new BorderLayout());
mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS));
enableSmiley =
new SIPCommCheckBox(ChatConfigActivator.getResources()
.getI18NString(
"plugin.chatconfig.replacement.ENABLE_SMILEY_STATUS"));
mainPanel.add(enableSmiley, BorderLayout.WEST);
enableSmiley.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
saveData();
}
});
mainPanel.add(Box.createVerticalStrut(10));
enableReplacement =
new SIPCommCheckBox(ChatConfigActivator.getResources()
.getI18NString(
"plugin.chatconfig.replacement.ENABLE_REPLACEMENT_STATUS"));
mainPanel.add(enableReplacement, BorderLayout.WEST);
enableReplacement.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
saveData();
table.revalidate();
table.repaint();
}
});
// the Jtable to list all the available sources
table = new JTable();
table.setShowGrid(false);
table.setTableHeader(null);
table.setOpaque(true);
table.setBackground(Color.white);
JScrollPane tablePane = new JScrollPane(table);
tablePane.setOpaque(false);
tablePane.setPreferredSize(new Dimension(mainPanel.getWidth(), 150));
tablePane.setAlignmentX(LEFT_ALIGNMENT);
JPanel container = new TransparentPanel(new BorderLayout());
container.setPreferredSize(new Dimension(mainPanel.getWidth(), 200));
container.setLayout(new BoxLayout(container, BoxLayout.Y_AXIS));
JLabel label =
new JLabel(ChatConfigActivator.getResources().getI18NString(
"plugin.chatconfig.replacement.REPLACEMENT_SOURCES"));
label.setDisplayedMnemonic(ChatConfigActivator.getResources()
.getI18nMnemonic(
"plugin.chatconfig.replacement.REPLACEMENT_SOURCES"));
label.setLabelFor(table);
container.add(label);
container.add(Box.createRigidArea(new Dimension(0, 5)));
container.add(tablePane, BorderLayout.EAST);
table.setModel(new ReplacementConfigurationTableModel(
ReplacementService.sourceList));
table.getSelectionModel().addListSelectionListener(
new ListSelectionListener()
{
public void valueChanged(ListSelectionEvent e)
{
if (e.getValueIsAdjusting())
return;
if (table.getSelectedRow() != -1)
{
boolean isEnabled =
(Boolean) table.getValueAt(table.getSelectedRow(),
0);
if (isEnabled)
{
enableReplacement.setSelected(true);
}
}
}
});
TableColumnModel tableColumnModel = table.getColumnModel();
TableColumn tableColumn = tableColumnModel.getColumn(0);
tableColumn.setMaxWidth(tableColumn.getMinWidth());
table.setDefaultRenderer(table.getColumnClass(1),
new FixedTableCellRenderer());
mainPanel.add(Box.createVerticalStrut(10));
mainPanel.add(container, BorderLayout.WEST);
return mainPanel;
}
/**
* Init the values of the widgets
*/
private void initValues()
{
ConfigurationService configService =
ChatConfigActivator.getConfigurationService();
boolean e =
configService.getBoolean(ReplacementProperty
.getPropertyName(ReplacementServiceSmileyImpl.SMILEY_SOURCE),
true);
this.enableSmiley.setSelected(e);
e =
configService.getBoolean(ReplacementProperty.REPLACEMENT_ENABLE,
true);
this.enableReplacement.setSelected(e);
this.table.setEnabled(e);
}
/**
* Save data in the configuration file
*/
private void saveData()
{
ConfigurationService configService =
ChatConfigActivator.getConfigurationService();
configService.setProperty(ReplacementProperty
.getPropertyName(ReplacementServiceSmileyImpl.SMILEY_SOURCE),
Boolean.toString(enableSmiley.isSelected()));
configService.setProperty(ReplacementProperty.REPLACEMENT_ENABLE,
Boolean.toString(enableReplacement.isSelected()));
boolean e = enableReplacement.isSelected();
table.getSelectionModel().clearSelection();
table.setEnabled(e);
}
/**
* Renderer for text column in the table.
*/
private static class FixedTableCellRenderer
extends DefaultTableCellRenderer
{
public Component getTableCellRendererComponent(JTable table, Object value,
boolean selected, boolean focused, int row, int column)
{
setEnabled(table == null || table.isEnabled());
super.getTableCellRendererComponent(table, value, selected, focused,
row, column);
return this;
}
}
}

@ -0,0 +1,135 @@
/*
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license. See terms of license at gnu.org.
*/
package net.java.sip.communicator.plugin.chatconfig.replacement;
import java.util.*;
import javax.swing.table.*;
import net.java.sip.communicator.plugin.chatconfig.*;
import net.java.sip.communicator.service.configuration.*;
import net.java.sip.communicator.service.replacement.*;
/**
* Table model for the table in <tt>ReplacementConfigPanel</tt> listing all
* available replacement sources
*
* @author Purvesh Sahoo
*/
public class ReplacementConfigurationTableModel
extends AbstractTableModel
{
/**
* The source list of all the available replacement sources
*/
private ArrayList<String> sourceList;
/**
* The configuration service
*/
private static ConfigurationService configService =
ChatConfigActivator.getConfigurationService();
/**
* Creates an instance of <tt>ReplacementConfigurationTableModel</tt> by
* specifying the source list.
*
* @param source the source list to initialize the table model with
*/
public ReplacementConfigurationTableModel(ArrayList<String> source)
{
this.sourceList = source;
}
/**
* @param columnIndex
* @return the Class of the column. <tt>Boolean</tt> for the first column.
*/
public Class<?> getColumnClass(int columnIndex)
{
return (columnIndex == 0) ? Boolean.class : super
.getColumnClass(columnIndex);
}
/**
* {@inheritDoc }
*/
public int getColumnCount()
{
return 2;
}
/**
* {@inheritDoc }
*/
public int getRowCount()
{
return sourceList.size();
}
/**
* @param rowIndex the row index.
* @param columnIndex the column index
*
* @return the value specified rowIndex and columnIndex. boolean in case of
* the first column, String replacement source label in case of the
* second column; null otherwise
*/
public Object getValueAt(int rowIndex, int columnIndex)
{
String source = sourceList.get(rowIndex);
switch (columnIndex)
{
case 0:
boolean e =
configService.getBoolean(ReplacementProperty
.getPropertyName(source), true);
return e;
case 1:
return ChatConfigActivator.getResources().getI18NString(
"plugin.chatconfig.replacement.sources." + source);
default:
return null;
}
}
/**
* @param rowIndex the row index
* @param columnIndex the column index
*
* @return boolean; true for first column false otherwise
*/
public boolean isCellEditable(int rowIndex, int columnIndex)
{
return (columnIndex == 0);
}
/**
* Set the value at rowIndex and columnIndex. Sets the replacement source
* property enabled/disabled based on whether the first column is true or
* false.
*
* @param value The object to set at rowIndex and columnIndex
* @param rowIndex
* @param columnIndex
*/
public void setValueAt(Object value, int rowIndex, int columnIndex)
{
if ((columnIndex == 0) && (value instanceof Boolean))
{
String source = sourceList.get(rowIndex);
boolean e = (Boolean) value;
configService.setProperty(ReplacementProperty
.getPropertyName(source), e);
configService.setProperty(ReplacementProperty.REPLACEMENT_ENABLE,
Boolean.toString(e));
fireTableCellUpdated(rowIndex, columnIndex);
}
}
}

@ -0,0 +1,34 @@
/*
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license. See terms of license at gnu.org.
*/
package net.java.sip.communicator.service.replacement;
/**
* Property for Replacement Service
*
* @author Purvesh Sahoo
*/
public final class ReplacementProperty
{
/**
* The replacement property.
*/
public static final String REPLACEMENT_ENABLE =
"net.java.sip.communicator.service.replacement.enable";
/**
* Returns the property name of individual replacement sources
*
* @param source the replacement source name.
* @return the property name of the specified source as will be stored in
* the properties file.
*/
public static String getPropertyName(String source)
{
return "net.java.sip.communicator.service.replacement."
+ source
+ ".enable";
}
}

@ -0,0 +1,38 @@
/*
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license. See terms of license at gnu.org.
*/
package net.java.sip.communicator.service.replacement;
import java.util.*;
/**
* A service used to provide substitution for any text in chat messages, like
* smileys, video and image previews, etc.
*
* @author Purvesh Sahoo
*/
public interface ReplacementService
{
/**
* The source name property name.
*/
public final String SOURCE_NAME = "SOURCE";
/**
* List of all the available replacement sources. All sources need to
* register itself.
*/
public static ArrayList<String> sourceList = new ArrayList<String>();
/**
* Returns the chat message with the text replacements if any or returns the
* original chat message.
*
* @param chatString the original chat message.
* @return the replaced chat message in case of match; the original message
* in case of no match.
*/
public String getReplacedMessage(String chatString);
}
Loading…
Cancel
Save