mirror of https://github.com/sipwise/jitsi.git
Support for video and photo previews in chat window provided by Purvesh Sahoo as part of its GSoC project.
parent
42fbfc3964
commit
7746c91783
|
After Width: | Height: | Size: 977 B |
@ -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…
Reference in new issue