[sip-comm-dev] Re: svn commit: r7237 - branches/gsoc10/previews: . lib lib/installer-exclude src/net/java/sip/communicator/impl/gui src/net/java/sip/communicator/impl...


#1

Hi Purvesh,

I've checked out your branch. I'm quite impressed by the amount of work you have done in the last few weeks. Bravo!

However when I tried to send a youtube link, nothing happened, it wasn't replaced. Is this supposed to work already? If yes, do you have in mind what the reason could be that it's not working for me?

Cheers,
Yana

···

On Jun 12, 2010, at 4:14 PM, jimpu2@dev.java.net wrote:

Author: jimpu2
Date: 2010-06-12 14:14:41+0000
New Revision: 7237

Added:
  branches/gsoc10/previews/.project_old
  branches/gsoc10/previews/lib/installer-exclude/gdata-base-1.0.jar (contents, props changed)
  branches/gsoc10/previews/lib/installer-exclude/gdata-client-1.0.jar (contents, props changed)
  branches/gsoc10/previews/lib/installer-exclude/gdata-client-meta-1.0.jar (contents, props changed)
  branches/gsoc10/previews/lib/installer-exclude/gdata-core-1.0.jar (contents, props changed)
  branches/gsoc10/previews/lib/installer-exclude/gdata-media-1.0.jar (contents, props changed)
  branches/gsoc10/previews/lib/installer-exclude/gdata-youtube-2.0.jar (contents, props changed)
  branches/gsoc10/previews/lib/installer-exclude/gdata-youtube-meta-2.0.jar (contents, props changed)
  branches/gsoc10/previews/lib/installer-exclude/mail.jar (contents, props changed)
  branches/gsoc10/previews/src/net/java/sip/communicator/impl/replacement/
  branches/gsoc10/previews/src/net/java/sip/communicator/impl/replacement/dailymotion/
  branches/gsoc10/previews/src/net/java/sip/communicator/impl/replacement/dailymotion/DailymotionActivator.java
  branches/gsoc10/previews/src/net/java/sip/communicator/impl/replacement/dailymotion/ReplacementServiceDailymotionImpl.java
  branches/gsoc10/previews/src/net/java/sip/communicator/impl/replacement/dailymotion/dailymotion.source.manifest.mf
  branches/gsoc10/previews/src/net/java/sip/communicator/impl/replacement/smiley/
  branches/gsoc10/previews/src/net/java/sip/communicator/impl/replacement/smiley/ReplacementServiceSmileyImpl.java
  branches/gsoc10/previews/src/net/java/sip/communicator/impl/replacement/smiley/SmileyActivator.java
  branches/gsoc10/previews/src/net/java/sip/communicator/impl/replacement/smiley/smiley.source.manifest.mf
  branches/gsoc10/previews/src/net/java/sip/communicator/impl/replacement/vimeo/
  branches/gsoc10/previews/src/net/java/sip/communicator/impl/replacement/vimeo/ReplacementServiceVimeoImpl.java
  branches/gsoc10/previews/src/net/java/sip/communicator/impl/replacement/vimeo/VimeoActivator.java
  branches/gsoc10/previews/src/net/java/sip/communicator/impl/replacement/vimeo/vimeo.source.manifest.mf
  branches/gsoc10/previews/src/net/java/sip/communicator/impl/replacement/youtube/
  branches/gsoc10/previews/src/net/java/sip/communicator/impl/replacement/youtube/ReplacementServiceYoutubeImpl.java
  branches/gsoc10/previews/src/net/java/sip/communicator/impl/replacement/youtube/YoutubeActivator.java
  branches/gsoc10/previews/src/net/java/sip/communicator/impl/replacement/youtube/youtube.source.manifest.mf
  branches/gsoc10/previews/src/net/java/sip/communicator/service/replacement/
  branches/gsoc10/previews/src/net/java/sip/communicator/service/replacement/ReplacementService.java
Modified:
  branches/gsoc10/previews/build.xml
  branches/gsoc10/previews/lib/felix.client.run.properties
  branches/gsoc10/previews/src/net/java/sip/communicator/impl/gui/GuiActivator.java
  branches/gsoc10/previews/src/net/java/sip/communicator/impl/gui/main/chat/ChatConversationPanel.java
  branches/gsoc10/previews/src/net/java/sip/communicator/impl/gui/swing.ui.manifest.mf
  branches/gsoc10/previews/src/net/java/sip/communicator/impl/gui/utils/Smiley.java

Log:
Replacement Service

Added: branches/gsoc10/previews/.project_old
Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/branches/gsoc10/previews/.project_old?view=auto&rev=7237

--- (empty file)
+++ branches/gsoc10/previews/.project_old 2010-06-12 14:14:41+0000
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>sip-comm-new</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ </buildSpec>
+ <natures>
+ </natures>
+</projectDescription>

Modified: branches/gsoc10/previews/build.xml
Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/branches/gsoc10/previews/build.xml?view=diff&rev=7237&p1=branches/gsoc10/previews/build.xml&p2=branches/gsoc10/previews/build.xml&r1=7236&r2=7237

--- branches/gsoc10/previews/build.xml (original)
+++ branches/gsoc10/previews/build.xml 2010-06-12 14:14:41+0000
@@ -911,7 +911,8 @@
        bundle-filehistory,bundle-metahistory,bundle-metahistory-slick,
        bundle-plugin-facebookaccregwizz,
        bundle-bouncycastle,bundle-plugin-otr,bundle-plugin-iptelaccregwizz,
- bundle-contactsource,bundle-plugin-reconnect"/>
+ bundle-contactsource,bundle-plugin-reconnect,bundle-youtube,
+ bundle-dailymotion,bundle-smiley,bundle-vimeo"/>

    <!--BUNDLE-SC-LAUNCHER-->
    <target name="bundle-sc-launcher">
@@ -1522,7 +1523,7 @@
                prefix="net/java/sip/communicator/impl/gui"/>
            <zipfileset src="lib/installer-exclude/jna.jar" prefix=""/>
            <zipfileset src="lib/installer-exclude/transparency.jar" prefix=""/>
- <zipfileset src="lib/installer-exclude/swing-worker-1.2.jar" prefix=""/>
+ <zipfileset src="lib/installer-exclude/swing-worker-1.2.jar" prefix=""/>
        </jar>
    </target>

@@ -2325,4 +2326,61 @@
                prefix="net/java/sip/communicator/plugin/reconnectplugin"/>
        </jar>
    </target>
+
+ <!-- BUNDLE-YOUTUBE -->
+ <target name="bundle-youtube">
+ <jar compress="false" destfile="\{bundles\.dest\}/replacement\-youtube\.jar&quot; \+ manifest=&quot;{src}/net/java/sip/communicator/impl/replacement/youtube/youtube.source.manifest.mf">
+ <zipfileset dir="\{dest\}/net/java/sip/communicator/impl/replacement/youtube&quot; \+ prefix=&quot;net/java/sip/communicator/impl/replacement/youtube&quot;/&gt; \+ &lt;zipfileset dir=&quot;{dest}/net/java/sip/communicator/service/replacement"
+ prefix="net/java/sip/communicator/service/replacement"/>
+ <zipfileset src="\{lib\.noinst\}/gdata\-base\-1\.0\.jar&quot; prefix=&quot;&quot;/&gt; \+ &lt;zipfileset src=&quot;{lib.noinst}/gdata-client-1.0.jar" prefix=""/>
+ <zipfileset src="\{lib\.noinst\}/gdata\-client\-meta\-1\.0\.jar&quot; prefix=&quot;&quot;/&gt; \+ &lt;zipfileset src=&quot;{lib.noinst}/gdata-core-1.0.jar" prefix=""/>
+ <zipfileset src="\{lib\.noinst\}/gdata\-media\-1\.0\.jar&quot; prefix=&quot;&quot;/&gt; \+ &lt;zipfileset src=&quot;{lib.noinst}/gdata-youtube-2.0.jar" prefix=""/>
+ <zipfileset src="\{lib\.noinst\}/gdata\-youtube\-meta\-2\.0\.jar&quot; prefix=&quot;&quot;/&gt; \+ &lt;zipfileset src=&quot;{lib.noinst}/mail.jar" prefix=""/>
+ </jar>
+ </target>
+
+ <!-- BUNDLE-DAILYMOTION -->
+ <target name="bundle-dailymotion">
+ <jar compress="false" destfile="\{bundles\.dest\}/replacement\-dailymotion\.jar&quot; \+ manifest=&quot;{src}/net/java/sip/communicator/impl/replacement/dailymotion/dailymotion.source.manifest.mf">
+ <zipfileset dir="\{dest\}/net/java/sip/communicator/impl/replacement/dailymotion&quot; \+ prefix=&quot;net/java/sip/communicator/impl/replacement/dailymotion&quot;/&gt; \+ &lt;zipfileset dir=&quot;{dest}/net/java/sip/communicator/service/replacement"
+ prefix="net/java/sip/communicator/service/replacement"/>
+ </jar>
+ </target>
+
+ <!-- BUNDLE-SMILEY -->
+ <target name="bundle-smiley">
+ <jar compress="false" destfile="\{bundles\.dest\}/replacement\-smiley\.jar&quot; \+ manifest=&quot;{src}/net/java/sip/communicator/impl/replacement/smiley/smiley.source.manifest.mf">
+ <zipfileset dir="\{dest\}/net/java/sip/communicator/impl/replacement/smiley&quot; \+ prefix=&quot;net/java/sip/communicator/impl/replacement/smiley&quot;/&gt; \+ &lt;zipfileset dir=&quot;{dest}/net/java/sip/communicator/service/replacement"
+ prefix="net/java/sip/communicator/service/replacement"/>
+ <zipfileset dir="\{dest\}/net/java/sip/communicator/impl/gui/utils&quot; \+ prefix=&quot;net/java/sip/communicator/impl/gui/utils&quot;/&gt; \+ &lt;zipfileset dir=&quot;{dest}/net/java/sip/communicator/impl/gui"
+ prefix="net/java/sip/communicator/impl/gui"/>
+ </jar>
+ </target>
+
+ <!-- BUNDLE-VIMEO -->
+ <target name="bundle-vimeo">
+ <jar compress="false" destfile="\{bundles\.dest\}/replacement\-vimeo\.jar&quot; \+ manifest=&quot;{src}/net/java/sip/communicator/impl/replacement/vimeo/vimeo.source.manifest.mf">
+ <zipfileset dir="\{dest\}/net/java/sip/communicator/impl/replacement/vimeo&quot; \+ prefix=&quot;net/java/sip/communicator/impl/replacement/vimeo&quot;/&gt; \+ &lt;zipfileset dir=&quot;{dest}/net/java/sip/communicator/service/replacement"
+ prefix="net/java/sip/communicator/service/replacement"/>
+ <zipfileset src="${lib.noinst}/json-20090723.jar" prefix=""/>
+ </jar>
+ </target>
</project>

Modified: branches/gsoc10/previews/lib/felix.client.run.properties
Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/branches/gsoc10/previews/lib/felix.client.run.properties?view=diff&rev=7237&p1=branches/gsoc10/previews/lib/felix.client.run.properties&p2=branches/gsoc10/previews/lib/felix.client.run.properties&r1=7236&r2=7237

--- branches/gsoc10/previews/lib/felix.client.run.properties (original)
+++ branches/gsoc10/previews/lib/felix.client.run.properties 2010-06-12 14:14:41+0000
@@ -130,7 +130,11 @@
reference:file:sc-bundles/generalconfig.jar \
reference:file:sc-bundles/dictaccregwizz.jar \
reference:file:sc-bundles/otr.jar \
- reference:file:sc-bundles/facebookaccregwizz.jar
+ reference:file:sc-bundles/facebookaccregwizz.jar \
+ reference:file:sc-bundles/replacement-youtube.jar \
+ reference:file:sc-bundles/replacement-dailymotion.jar \
+ reference:file:sc-bundles/replacement-smiley.jar \
+ reference:file:sc-bundles/replacement-vimeo.jar

#level 68 is for profiler, don't use it or change the build.xml file accordingly

Added: branches/gsoc10/previews/lib/installer-exclude/gdata-base-1.0.jar
Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/branches/gsoc10/previews/lib/installer-exclude/gdata-base-1.0.jar?view=auto&rev=7237

Binary file. No diff available.

Added: branches/gsoc10/previews/lib/installer-exclude/gdata-client-1.0.jar
Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/branches/gsoc10/previews/lib/installer-exclude/gdata-client-1.0.jar?view=auto&rev=7237

Binary file. No diff available.

Added: branches/gsoc10/previews/lib/installer-exclude/gdata-client-meta-1.0.jar
Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/branches/gsoc10/previews/lib/installer-exclude/gdata-client-meta-1.0.jar?view=auto&rev=7237

Binary file. No diff available.

Added: branches/gsoc10/previews/lib/installer-exclude/gdata-core-1.0.jar
Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/branches/gsoc10/previews/lib/installer-exclude/gdata-core-1.0.jar?view=auto&rev=7237

Binary file. No diff available.

Added: branches/gsoc10/previews/lib/installer-exclude/gdata-media-1.0.jar
Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/branches/gsoc10/previews/lib/installer-exclude/gdata-media-1.0.jar?view=auto&rev=7237

Binary file. No diff available.

Added: branches/gsoc10/previews/lib/installer-exclude/gdata-youtube-2.0.jar
Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/branches/gsoc10/previews/lib/installer-exclude/gdata-youtube-2.0.jar?view=auto&rev=7237

Binary file. No diff available.

Added: branches/gsoc10/previews/lib/installer-exclude/gdata-youtube-meta-2.0.jar
Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/branches/gsoc10/previews/lib/installer-exclude/gdata-youtube-meta-2.0.jar?view=auto&rev=7237

Binary file. No diff available.

Added: branches/gsoc10/previews/lib/installer-exclude/mail.jar
Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/branches/gsoc10/previews/lib/installer-exclude/mail.jar?view=auto&rev=7237

Binary file. No diff available.

Modified: branches/gsoc10/previews/src/net/java/sip/communicator/impl/gui/GuiActivator.java
Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/branches/gsoc10/previews/src/net/java/sip/communicator/impl/gui/GuiActivator.java?view=diff&rev=7237&p1=branches/gsoc10/previews/src/net/java/sip/communicator/impl/gui/GuiActivator.java&p2=branches/gsoc10/previews/src/net/java/sip/communicator/impl/gui/GuiActivator.java&r1=7236&r2=7237

--- branches/gsoc10/previews/src/net/java/sip/communicator/impl/gui/GuiActivator.java (original)
+++ branches/gsoc10/previews/src/net/java/sip/communicator/impl/gui/GuiActivator.java 2010-06-12 14:14:41+0000
@@ -1,8 +1,7 @@
/*
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
- *
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
+ *
+ * Distributable under LGPL license. See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.gui;

@@ -25,6 +24,7 @@
import net.java.sip.communicator.service.neomedia.*;
import net.java.sip.communicator.service.notification.*;
import net.java.sip.communicator.service.protocol.*;
+import net.java.sip.communicator.service.replacement.ReplacementService;
import net.java.sip.communicator.service.resources.*;
import net.java.sip.communicator.service.shutdown.*;
import net.java.sip.communicator.service.systray.*;
@@ -34,10 +34,11 @@

/**
* The GUI Activator class.
- *
+ *
* @author Yana Stamcheva
*/
-public class GuiActivator implements BundleActivator
+public class GuiActivator
+ implements BundleActivator
{
    private static final Logger logger = Logger.getLogger(GuiActivator.class);

@@ -58,7 +59,8 @@
    private static BrowserLauncherService browserLauncherService;

    private static NotificationService notificationService;
- private NotificationServiceListener notificationServiceListener;
+
+ private NotificationServiceListener notificationServiceListener;

    private static SystrayService systrayService;

@@ -74,13 +76,16 @@

    private static List<ContactSourceService> contactSources;

- private static final Map<Object, ProtocolProviderFactory>
- providerFactoriesMap = new Hashtable<Object, ProtocolProviderFactory>();
+ private static final Map<Object, ProtocolProviderFactory> providerFactoriesMap =
+ new Hashtable<Object, ProtocolProviderFactory>();
+
+ private static final Map<Object, ReplacementService> replacementSourcesMap =
+ new Hashtable<Object, ReplacementService>();

    /**
     * Indicates if this bundle has been started.
     */
- public static boolean isStarted = false;
+ public static boolean isStarted = false;

    /**
     * The contact list object.
@@ -89,12 +94,11 @@

    /**
     * Called when this bundle is started.
- *
+ *
     * @param bContext The execution context of the bundle being started.
     * @throws Exception if the bundle is not correctly started
     */
- public void start(BundleContext bContext)
- throws Exception
+ public void start(BundleContext bContext) throws Exception
    {
        isStarted = true;
        GuiActivator.bundleContext = bContext;
@@ -113,21 +117,17 @@
            if (logger.isInfoEnabled())
                logger.info("UI Service...[ STARTED ]");

- bundleContext.registerService(UIService.class.getName(),
- uiService,
- null);
+ bundleContext.registerService(UIService.class.getName(), uiService,
+ null);
            if (logger.isInfoEnabled())
                logger.info("UI Service ...[REGISTERED]");

            // UIServiceImpl also implements ShutdownService.
            bundleContext.registerService(ShutdownService.class.getName(),
- (ShutdownService) uiService,
- null);
+ (ShutdownService) uiService, null);

- bundleContext.registerService(
- CertificateVerificationService.class.getName(),
- new CertificateVerificationServiceImpl(),
- null);
+ bundleContext.registerService(CertificateVerificationService.class
+ .getName(), new CertificateVerificationServiceImpl(), null);

            uiService.loadApplicationGui();

@@ -138,8 +138,8 @@
            logger.logExit();
        }

- GuiActivator.getConfigurationService()
- .addPropertyChangeListener(uiService);
+ GuiActivator.getConfigurationService().addPropertyChangeListener(
+ uiService);

        bundleContext.addServiceListener(uiService);
    }
@@ -147,12 +147,12 @@
    /**
     * Called when this bundle is stopped so the Framework can perform the
     * bundle-specific activities necessary to stop the bundle.
- *
+ *
     * @param bContext The execution context of the bundle being stopped.
- * @throws Exception If this method throws an exception, the bundle is
- * still marked as stopped, and the Framework will remove the bundle's
- * listeners, unregister all services registered by the bundle, and
- * release all services used by the bundle.
+ * @throws Exception If this method throws an exception, the bundle is still
+ * marked as stopped, and the Framework will remove the bundle's
+ * listeners, unregister all services registered by the bundle,
+ * and release all services used by the bundle.
     */
    public void stop(BundleContext bContext) throws Exception
    {
@@ -160,8 +160,8 @@
            logger.info("UI Service ...[STOPPED]");
        isStarted = false;

- GuiActivator.getConfigurationService()
- .removePropertyChangeListener(uiService);
+ GuiActivator.getConfigurationService().removePropertyChangeListener(
+ uiService);

        bContext.removeServiceListener(uiService);
        bContext.removeServiceListener(notificationServiceListener);
@@ -174,8 +174,7 @@
     * @return all <tt>ProtocolProviderFactory</tt>s obtained from the bundle
     * context
     */
- public static Map<Object, ProtocolProviderFactory>
- getProtocolProviderFactories()
+ public static Map<Object, ProtocolProviderFactory> getProtocolProviderFactories()
    {

        ServiceReference[] serRefs = null;
@@ -192,45 +191,46 @@
            logger.error("LoginManager : " + e);
        }

- if (serRefs != null)
+ if (serRefs != null)
        {
- for (int i = 0; i < serRefs.length; i++)
+ for (int i = 0; i < serRefs.length; i++)
            {

- ProtocolProviderFactory providerFactory
- = (ProtocolProviderFactory) bundleContext
+ ProtocolProviderFactory providerFactory =
+ (ProtocolProviderFactory) bundleContext
                        .getService(serRefs[i]);

                providerFactoriesMap.put(serRefs[i]
- .getProperty(ProtocolProviderFactory.PROTOCOL),
- providerFactory);
+ .getProperty(ProtocolProviderFactory.PROTOCOL),
+ providerFactory);
            }
        }
        return providerFactoriesMap;
    }

    /**
- * Returns a <tt>ProtocolProviderFactory</tt> for a given protocol
- * provider.
+ * Returns a <tt>ProtocolProviderFactory</tt> for a given protocol provider.
+ *
     * @param protocolProvider the <tt>ProtocolProviderService</tt>, which
- * factory we're looking for
- * @return a <tt>ProtocolProviderFactory</tt> for a given protocol
- * provider
+ * factory we're looking for
+ * @return a <tt>ProtocolProviderFactory</tt> for a given protocol provider
     */
    public static ProtocolProviderFactory getProtocolProviderFactory(
- ProtocolProviderService protocolProvider)
+ ProtocolProviderService protocolProvider)
    {
- String osgiFilter = "("
- + ProtocolProviderFactory.PROTOCOL
- + "="+protocolProvider.getProtocolName()+")";
+ String osgiFilter =
+ "(" + ProtocolProviderFactory.PROTOCOL + "="
+ + protocolProvider.getProtocolName() + ")";

        ProtocolProviderFactory protocolProviderFactory = null;
        try
        {
- ServiceReference[] serRefs = GuiActivator.bundleContext.getServiceReferences(
- ProtocolProviderFactory.class.getName(), osgiFilter);
- protocolProviderFactory = (ProtocolProviderFactory) GuiActivator
- .bundleContext.getService(serRefs[0]);
+ ServiceReference[] serRefs =
+ GuiActivator.bundleContext.getServiceReferences(
+ ProtocolProviderFactory.class.getName(), osgiFilter);
+ protocolProviderFactory =
+ (ProtocolProviderFactory) GuiActivator.bundleContext
+ .getService(serRefs[0]);
        }
        catch (InvalidSyntaxException ex)
        {
@@ -241,41 +241,88 @@
    }

    /**
+ * Returns all <tt>ReplacementService</tt>s obtained from the bundle
+ * context.
+ *
+ * @return all <tt>ReplacementService</tt> implementation obtained from the
+ * bundle context
+ */
+ public static Map<Object, ReplacementService> getReplacementSources()
+ {
+
+ ServiceReference[] serRefs = null;
+ try
+ {
+ // get all registered sources
+ serRefs =
+ bundleContext.getServiceReferences(ReplacementService.class
+ .getName(), null);
+
+ }
+ catch (InvalidSyntaxException e)
+ {
+ logger.error("Error : " + e);
+ }
+
+ if (serRefs != null)
+ {
+
+ for (int i = 0; i < serRefs.length; i++)
+ {
+
+ ReplacementService replacementSources =
+ (ReplacementService) bundleContext.getService(serRefs[i]);
+
+ replacementSourcesMap.put(serRefs[i]
+ .getProperty(ReplacementService.SOURCE_NAME),
+ replacementSources);
+
+ // replacementSourcesMap.put("YOUTUBE",replacementSources);
+ }
+ }
+ return replacementSourcesMap;
+ }
+
+ /**
     * Returns the <tt>ConfigurationService</tt> obtained from the bundle
     * context.
+ *
     * @return the <tt>ConfigurationService</tt> obtained from the bundle
- * context
+ * context
     */
    public static ConfigurationService getConfigurationService()
    {
- if(configService == null)
+ if (configService == null)
        {
- ServiceReference configReference = bundleContext
- .getServiceReference(ConfigurationService.class.getName());
-
- configService = (ConfigurationService) bundleContext
- .getService(configReference);
+ ServiceReference configReference =
+ bundleContext.getServiceReference(ConfigurationService.class
+ .getName());
+
+ configService =
+ (ConfigurationService) bundleContext
+ .getService(configReference);
        }

        return configService;
    }

    /**
- * Returns the <tt>MetaHistoryService</tt> obtained from the bundle
- * context.
- * @return the <tt>MetaHistoryService</tt> obtained from the bundle
- * context
+ * Returns the <tt>MetaHistoryService</tt> obtained from the bundle context.
+ *
+ * @return the <tt>MetaHistoryService</tt> obtained from the bundle context
     */
    public static MetaHistoryService getMetaHistoryService()
    {
        if (metaHistoryService == null)
        {
- ServiceReference serviceReference = bundleContext
- .getServiceReference(MetaHistoryService.class.getName());
+ ServiceReference serviceReference =
+ bundleContext.getServiceReference(MetaHistoryService.class
+ .getName());

            if (serviceReference != null)
- metaHistoryService = (MetaHistoryService) bundleContext
- .getService(serviceReference);
+ metaHistoryService =
+ (MetaHistoryService) bundleContext
+ .getService(serviceReference);
        }

        return metaHistoryService;
@@ -284,17 +331,20 @@
    /**
     * Returns the <tt>MetaContactListService</tt> obtained from the bundle
     * context.
+ *
     * @return the <tt>MetaContactListService</tt> obtained from the bundle
- * context
+ * context
     */
    public static MetaContactListService getContactListService()
    {
        if (metaCListService == null)
        {
- ServiceReference clistReference = bundleContext
- .getServiceReference(MetaContactListService.class.getName());
+ ServiceReference clistReference =
+ bundleContext.getServiceReference(MetaContactListService.class
+ .getName());

- metaCListService = (MetaContactListService) bundleContext
+ metaCListService =
+ (MetaContactListService) bundleContext
                    .getService(clistReference);
        }

@@ -302,20 +352,20 @@
    }

    /**
- * Returns the <tt>CallHistoryService</tt> obtained from the bundle
- * context.
- * @return the <tt>CallHistoryService</tt> obtained from the bundle
- * context
+ * Returns the <tt>CallHistoryService</tt> obtained from the bundle context.
+ *
+ * @return the <tt>CallHistoryService</tt> obtained from the bundle context
     */
    public static CallHistoryService getCallHistoryService()
    {
        if (callHistoryService == null)
        {
- ServiceReference serviceReference = bundleContext
- .getServiceReference(CallHistoryService.class.getName());
+ ServiceReference serviceReference =
+ bundleContext.getServiceReference(CallHistoryService.class
+ .getName());

- callHistoryService = (CallHistoryService) bundleContext
- .getService(serviceReference);
+ callHistoryService =
+ (CallHistoryService) bundleContext.getService(serviceReference);
        }

        return callHistoryService;
@@ -324,21 +374,22 @@
    /**
     * Returns the <tt>AudioNotifierService</tt> obtained from the bundle
     * context.
+ *
     * @return the <tt>AudioNotifierService</tt> obtained from the bundle
- * context
+ * context
     */
    public static AudioNotifierService getAudioNotifier()
    {
        if (audioNotifierService == null)
        {
- ServiceReference serviceReference
- = bundleContext
- .getServiceReference(AudioNotifierService.class.getName());
+ ServiceReference serviceReference =
+ bundleContext.getServiceReference(AudioNotifierService.class
+ .getName());

            if (serviceReference != null)
- audioNotifierService
- = (AudioNotifierService)
- bundleContext.getService(serviceReference);
+ audioNotifierService =
+ (AudioNotifierService) bundleContext
+ .getService(serviceReference);
        }
        return audioNotifierService;
    }
@@ -346,18 +397,21 @@
    /**
     * Returns the <tt>BrowserLauncherService</tt> obtained from the bundle
     * context.
+ *
     * @return the <tt>BrowserLauncherService</tt> obtained from the bundle
- * context
+ * context
     */
    public static BrowserLauncherService getBrowserLauncher()
    {
        if (browserLauncherService == null)
        {
- ServiceReference serviceReference = bundleContext
- .getServiceReference(BrowserLauncherService.class.getName());
+ ServiceReference serviceReference =
+ bundleContext.getServiceReference(BrowserLauncherService.class
+ .getName());

- browserLauncherService = (BrowserLauncherService) bundleContext
- .getService(serviceReference);
+ browserLauncherService =
+ (BrowserLauncherService) bundleContext
+ .getService(serviceReference);
        }

        return browserLauncherService;
@@ -365,6 +419,7 @@

    /**
     * Returns the current implementation of the <tt>UIService</tt>.
+ *
     * @return the current implementation of the <tt>UIService</tt>
     */
    public static UIServiceImpl getUIService()
@@ -374,21 +429,22 @@

    /**
     * Returns the <tt>SystrayService</tt> obtained from the bundle context.
- *
+ *
     * @return the <tt>SystrayService</tt> obtained from the bundle context
     */
    public static SystrayService getSystrayService()
    {
        if (systrayService == null)
        {
- ServiceReference serviceReference = bundleContext
- .getServiceReference(SystrayService.class.getName());
+ ServiceReference serviceReference =
+ bundleContext.getServiceReference(SystrayService.class
+ .getName());

- if(serviceReference == null)
+ if (serviceReference == null)
                return null;

- systrayService = (SystrayService) bundleContext
- .getService(serviceReference);
+ systrayService =
+ (SystrayService) bundleContext.getService(serviceReference);
        }

        return systrayService;
@@ -396,18 +452,19 @@

    /**
     * Returns the <tt>KeybindingsService</tt> obtained from the bundle context.
- *
+ *
     * @return the <tt>KeybindingsService</tt> obtained from the bundle context
     */
    public static KeybindingsService getKeybindingsService()
    {
        if (keybindingsService == null)
        {
- ServiceReference serviceReference = bundleContext
- .getServiceReference(KeybindingsService.class.getName());
+ ServiceReference serviceReference =
+ bundleContext.getServiceReference(KeybindingsService.class
+ .getName());

- keybindingsService = (KeybindingsService) bundleContext
- .getService(serviceReference);
+ keybindingsService =
+ (KeybindingsService) bundleContext.getService(serviceReference);
        }

        return keybindingsService;
@@ -416,41 +473,47 @@
    /**
     * Returns the <tt>ResourceManagementService</tt>, through which we will
     * access all resources.
- *
+ *
     * @return the <tt>ResourceManagementService</tt>, through which we will
- * access all resources.
+ * access all resources.
     */
    public static ResourceManagementService getResources()
    {
        if (resourcesService == null)
        {
- ServiceReference serviceReference = bundleContext
- .getServiceReference(ResourceManagementService.class.getName());
+ ServiceReference serviceReference =
+ bundleContext
+ .getServiceReference(ResourceManagementService.class
+ .getName());

- if(serviceReference == null)
+ if (serviceReference == null)
                return null;

- resourcesService = (ResourceManagementService) bundleContext
- .getService(serviceReference);
+ resourcesService =
+ (ResourceManagementService) bundleContext
+ .getService(serviceReference);
        }

        return resourcesService;
    }

    /**
- * Returns the <tt>NotificationService</tt> obtained from the bundle context.
- *
+ * Returns the <tt>NotificationService</tt> obtained from the bundle
+ * context.
+ *
     * @return the <tt>NotificationService</tt> obtained from the bundle context
     */
    public static NotificationService getNotificationService()
    {
        if (notificationService == null)
        {
- ServiceReference serviceReference = bundleContext
- .getServiceReference(NotificationService.class.getName());
+ ServiceReference serviceReference =
+ bundleContext.getServiceReference(NotificationService.class
+ .getName());

- notificationService = (NotificationService) bundleContext
- .getService(serviceReference);
+ notificationService =
+ (NotificationService) bundleContext
+ .getService(serviceReference);
        }

        return notificationService;
@@ -458,18 +521,19 @@

    /**
     * Returns the <tt>FileAccessService</tt> obtained from the bundle context.
- *
+ *
     * @return the <tt>FileAccessService</tt> obtained from the bundle context
     */
    public static FileAccessService getFileAccessService()
    {
        if (fileAccessService == null)
        {
- ServiceReference serviceReference = bundleContext
- .getServiceReference(FileAccessService.class.getName());
+ ServiceReference serviceReference =
+ bundleContext.getServiceReference(FileAccessService.class
+ .getName());

- fileAccessService = (FileAccessService) bundleContext
- .getService(serviceReference);
+ fileAccessService =
+ (FileAccessService) bundleContext.getService(serviceReference);
        }

        return fileAccessService;
@@ -477,69 +541,72 @@

    /**
     * Returns the <tt>DesktopService</tt> obtained from the bundle context.
- *
+ *
     * @return the <tt>DesktopService</tt> obtained from the bundle context
     */
    public static DesktopService getDesktopService()
    {
        if (desktopService == null)
        {
- ServiceReference serviceReference = bundleContext
- .getServiceReference(DesktopService.class.getName());
+ ServiceReference serviceReference =
+ bundleContext.getServiceReference(DesktopService.class
+ .getName());

- desktopService = (DesktopService) bundleContext
- .getService(serviceReference);
+ desktopService =
+ (DesktopService) bundleContext.getService(serviceReference);
        }

        return desktopService;
    }

    /**
- * Returns an instance of the <tt>MediaService</tt> obtained from the
- * bundle context.
- * @return an instance of the <tt>MediaService</tt> obtained from the
- * bundle context
+ * Returns an instance of the <tt>MediaService</tt> obtained from the bundle
+ * context.
+ *
+ * @return an instance of the <tt>MediaService</tt> obtained from the bundle
+ * context
     */
    public static MediaService getMediaService()
    {
        if (mediaService == null)
        {
- ServiceReference serviceReference = bundleContext
- .getServiceReference(MediaService.class.getName());
+ ServiceReference serviceReference =
+ bundleContext.getServiceReference(MediaService.class.getName());

- mediaService = (MediaService) bundleContext
- .getService(serviceReference);
+ mediaService =
+ (MediaService) bundleContext.getService(serviceReference);
        }

        return mediaService;
    }

    /**
- * Implements the <tt>ServiceListener</tt>. Verifies whether the
- * passed event concerns a <tt>NotificationService</tt> and if so
- * initiates the user interface NotificationManager.
+ * Implements the <tt>ServiceListener</tt>. Verifies whether the passed
+ * event concerns a <tt>NotificationService</tt> and if so initiates the
+ * user interface NotificationManager.
     */
- private static class NotificationServiceListener implements ServiceListener
+ private static class NotificationServiceListener
+ implements ServiceListener
    {
        /**
         * Implements the <tt>ServiceListener</tt> method. Verifies whether the
         * passed event concerns a <tt>NotificationService</tt> and if so
         * initiates the NotificationManager.
- *
+ *
         * @param event The <tt>ServiceEvent</tt> object.
         */
        public void serviceChanged(ServiceEvent event)
        {
            // if the event is caused by a bundle being stopped, we don't want
            // to know
- if (event.getServiceReference().getBundle().getState()
- == Bundle.STOPPING)
+ if (event.getServiceReference().getBundle().getState() == Bundle.STOPPING)
            {
                return;
            }

- Object service = GuiActivator.bundleContext.getService(event
- .getServiceReference());
+ Object service =
+ GuiActivator.bundleContext.getService(event
+ .getServiceReference());

            // we don't care if the source service is not a notification service
            if (!(service instanceof NotificationService))
@@ -556,6 +623,7 @@

    /**
     * Returns a list of all registered contact sources.
+ *
     * @return a list of all registered contact sources
     */
    public static List<ContactSourceService> getContactSources()
@@ -570,21 +638,20 @@
        {
            // get all registered provider factories
            serRefs =
- bundleContext.getServiceReferences(
- ContactSourceService.class.getName(), null);
+ bundleContext.getServiceReferences(ContactSourceService.class
+ .getName(), null);
        }
        catch (InvalidSyntaxException e)
        {
            logger.error("GuiActivator : " + e);
        }

- if (serRefs != null)
+ if (serRefs != null)
        {
            for (int i = 0; i < serRefs.length; i++)
            {
- ContactSourceService contactSource
- = (ContactSourceService) bundleContext
- .getService(serRefs[i]);
+ ContactSourceService contactSource =
+ (ContactSourceService) bundleContext.getService(serRefs[i]);

                contactSources.add(contactSource);
            }
@@ -595,6 +662,7 @@
    /**
     * Sets the <tt>contactList</tt> component currently used to show the
     * contact list.
+ *
     * @param list the contact list object to set
     */
    public static void setContactList(TreeContactList list)
@@ -604,6 +672,7 @@

    /**
     * Returns the component used to show the contact list.
+ *
     * @return the component used to show the contact list
     */
    public static TreeContactList getContactList()

Modified: branches/gsoc10/previews/src/net/java/sip/communicator/impl/gui/main/chat/ChatConversationPanel.java
Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/branches/gsoc10/previews/src/net/java/sip/communicator/impl/gui/main/chat/ChatConversationPanel.java?view=diff&rev=7237&p1=branches/gsoc10/previews/src/net/java/sip/communicator/impl/gui/main/chat/ChatConversationPanel.java&p2=branches/gsoc10/previews/src/net/java/sip/communicator/impl/gui/main/chat/ChatConversationPanel.java&r1=7236&r2=7237

--- branches/gsoc10/previews/src/net/java/sip/communicator/impl/gui/main/chat/ChatConversationPanel.java (original)
+++ branches/gsoc10/previews/src/net/java/sip/communicator/impl/gui/main/chat/ChatConversationPanel.java 2010-06-12 14:14:41+0000
@@ -1,8 +1,7 @@
/*
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
- *
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
+ *
+ * Distributable under LGPL license. See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.gui.main.chat;

@@ -26,6 +25,9 @@
import net.java.sip.communicator.service.gui.*;
import net.java.sip.communicator.util.*;
import net.java.sip.communicator.util.swing.*;
+import net.java.sip.communicator.util.swing.SwingWorker;
+
+import net.java.sip.communicator.service.replacement.*;

/**
* The <tt>ChatConversationPanel</tt> is the panel, where all sent and received
@@ -33,18 +35,16 @@
* is applied to the document to provide the look&feel. All smileys and link
* strings are processed and finally replaced by corresponding images and HTML
* links.
- *
+ *
* @author Yana Stamcheva
* @author Lubomir Marinov
*/
public class ChatConversationPanel
    extends SCScrollPane
- implements HyperlinkListener,
- MouseListener,
- ClipboardOwner
+ implements HyperlinkListener, MouseListener, ClipboardOwner
{
- private static final Logger logger
- = Logger.getLogger(ChatConversationPanel.class);
+ private static final Logger logger =
+ Logger.getLogger(ChatConversationPanel.class);

    /**
     * The closing tag of the <code>PLAINTEXT</code> HTML element.
@@ -60,16 +60,14 @@
     * The regular expression (in the form of compiled <tt>Pattern</tt>) which
     * matches URLs for the purposed of turning them into links.
     */
- private static final Pattern URL_PATTERN
- = Pattern.compile(
- "("
+ private static final Pattern URL_PATTERN =
+ Pattern.compile("("
            + "(\\bwww\\.[^\\s<>\"]+\\.[^\\s<>\"]+/*[?#]*(\\w+[&=;?]\\w+)*\\b)" // wwwURL
- + "|"
- + "(\\b\\w+://[^\\s<>\"]+/*[?#]*(\\w+[&=;?]\\w+)*\\b)" // protocolURL
+ + "|" + "(\\b\\w+://[^\\s<>\"]+/*[?#]*(\\w+[&=;?]\\w+)*\\b)" // protocolURL
            + ")");

    /**
- * The compiled <tt>Pattern</tt> which matches {@link #smileyStrings}.
+ * The compiled <tt>Pattern</tt> which matches {@link #smileyStrings}.
     */
    private static Pattern smileyPattern;

@@ -77,8 +75,8 @@
     * The <tt>List</tt> of smiley strings which are matched by
     * {@link #smileyPattern}.
     */
- private static final java.util.List<String> smileyStrings
- = new ArrayList<String>();
+ private static final java.util.List<String> smileyStrings =
+ new ArrayList<String>();

    private final JTextPane chatTextPane = new MyTextPane();

@@ -106,6 +104,9 @@

    public static final String TEXT_CONTENT_TYPE = "text/plain";

+ private Map<Object, ReplacementService> listsources =
+ new HashMap<Object, ReplacementService>();
+
    /**
     * The indicator which determines whether an automatic scroll to the bottom
     * of {@link #chatTextPane} is to be performed.
@@ -113,8 +114,8 @@
    private boolean scrollToBottomIsPending = false;

    /**
- * The implementation of the routine which scrolls {@link #chatTextPane} to its
- * bottom.
+ * The implementation of the routine which scrolls {@link #chatTextPane} to
+ * its bottom.
     */
    private final Runnable scrollToBottomRunnable = new Runnable()
    {
@@ -132,7 +133,7 @@

    /**
     * Creates an instance of <tt>ChatConversationPanel</tt>.
- *
+ *
     * @param chatContainer The parent <tt>ChatConversationContainer</tt>.
     */
    public ChatConversationPanel(ChatConversationContainer chatContainer)
@@ -153,53 +154,52 @@
        this.chatTextPane.setDocument(document);
        this.chatTextPane.setDragEnabled(true);

- chatTextPane.putClientProperty(
- JEditorPane.HONOR_DISPLAY_PROPERTIES, Boolean.TRUE);
- Constants.loadSimpleStyle(
- document.getStyleSheet(), chatTextPane.getFont());
+ chatTextPane.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES,
+ Boolean.TRUE);
+ Constants.loadSimpleStyle(document.getStyleSheet(), chatTextPane
+ .getFont());

        this.chatTextPane.addHyperlinkListener(this);
        this.chatTextPane.addMouseListener(this);
- this.chatTextPane.setCursor(
- Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR));
+ this.chatTextPane.setCursor(Cursor
+ .getPredefinedCursor(Cursor.TEXT_CURSOR));

        this.setWheelScrollingEnabled(true);

        this.setViewportView(chatTextPane);

- this.setHorizontalScrollBarPolicy(
- JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
+ this
+ .setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);

        ToolTipManager.sharedInstance().registerComponent(chatTextPane);

- String copyLinkString
- = GuiActivator.getResources().getI18NString("service.gui.COPY_LINK");
+ String copyLinkString =
+ GuiActivator.getResources().getI18NString("service.gui.COPY_LINK");

        copyLinkItem =
- new JMenuItem(copyLinkString,
- new ImageIcon(ImageLoader.getImage(ImageLoader.COPY_ICON)));
+ new JMenuItem(copyLinkString, new ImageIcon(ImageLoader
+ .getImage(ImageLoader.COPY_ICON)));

        copyLinkItem.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {
- StringSelection stringSelection = new StringSelection(
- currentHref);
- Clipboard clipboard = Toolkit.getDefaultToolkit()
- .getSystemClipboard();
+ StringSelection stringSelection =
+ new StringSelection(currentHref);
+ Clipboard clipboard =
+ Toolkit.getDefaultToolkit().getSystemClipboard();
                clipboard.setContents(stringSelection,
                    ChatConversationPanel.this);
            }
        });

- String openLinkString
- = GuiActivator.getResources().getI18NString(
+ String openLinkString =
+ GuiActivator.getResources().getI18NString(
                "service.gui.OPEN_IN_BROWSER");

        openLinkItem =
- new JMenuItem(
- openLinkString,
- new ImageIcon(ImageLoader.getImage(ImageLoader.BROWSER_ICON)));
+ new JMenuItem(openLinkString, new ImageIcon(ImageLoader
+ .getImage(ImageLoader.BROWSER_ICON)));

        openLinkItem.addActionListener(new ActionListener()
        {
@@ -209,13 +209,11 @@
            }
        });

- openLinkItem.setMnemonic(
- GuiActivator.getResources().getI18nMnemonic(
- "service.gui.OPEN_IN_BROWSER"));
-
- copyLinkItem.setMnemonic(
- GuiActivator.getResources().getI18nMnemonic(
- "service.gui.COPY_LINK"));
+ openLinkItem.setMnemonic(GuiActivator.getResources().getI18nMnemonic(
+ "service.gui.OPEN_IN_BROWSER"));
+
+ copyLinkItem.setMnemonic(GuiActivator.getResources().getI18nMnemonic(
+ "service.gui.COPY_LINK"));

        /*
         * When we append a new message (regardless of whether it is a string or
@@ -243,6 +241,8 @@
        };
        chatTextPane.addComponentListener(componentListener);
        getViewport().addComponentListener(componentListener);
+
+ listsources = GuiActivator.getReplacementSources();
    }

    /*
@@ -261,13 +261,13 @@

            if (verticalScrollBar != null)
            {
- BoundedRangeModel verticalScrollBarModel
- = verticalScrollBar.getModel();
+ BoundedRangeModel verticalScrollBarModel =
+ verticalScrollBar.getModel();

                if ((verticalScrollBarModel.getValue()
- + verticalScrollBarModel.getExtent()
- >= verticalScrollBarModel.getMaximum())
- || !verticalScrollBar.isVisible())
+ + verticalScrollBarModel.getExtent() >= verticalScrollBarModel
+ .getMaximum())
+ || !verticalScrollBar.isVisible())
                    scrollToBottomIsPending = true;
            }
        }
@@ -276,34 +276,34 @@
    }

    /**
- * Initializes the editor by adding a header containing the date.
- * TODO: remove if not used anymore
+ * Initializes the editor by adding a header containing the date. TODO:
+ * remove if not used anymore
     */
-// private void initEditor()
-// {
-// Element root = this.document.getDefaultRootElement();
-//
-// Date date = new Date(System.currentTimeMillis());
-//
-// String chatHeader = "<h1>" + GuiUtils.formatDate(date) + " " + "</h1>";
-//
-// try
-// {
-// this.document.insertAfterStart(root, chatHeader);
-// }
-// catch (BadLocationException e)
-// {
-// logger.error("Insert in the HTMLDocument failed.", e);
-// }
-// catch (IOException e)
-// {
-// logger.error("Insert in the HTMLDocument failed.", e);
-// }
-// }
+ // private void initEditor()
+ // {
+ // Element root = this.document.getDefaultRootElement();
+ //
+ // Date date = new Date(System.currentTimeMillis());
+ //
+ // String chatHeader = "<h1>" + GuiUtils.formatDate(date) + " " + "</h1>";
+ //
+ // try
+ // {
+ // this.document.insertAfterStart(root, chatHeader);
+ // }
+ // catch (BadLocationException e)
+ // {
+ // logger.error("Insert in the HTMLDocument failed.", e);
+ // }
+ // catch (IOException e)
+ // {
+ // logger.error("Insert in the HTMLDocument failed.", e);
+ // }
+ // }

    /**
     * Processes the message given by the parameters.
- *
+ *
     * @param chatMessage the message
     * @param keyword
     * @return the processed message
@@ -324,10 +324,10 @@
        String dateString = getDateString(date);

        String startDivTag = "<DIV identifier=\"" + msgID + "\">";
- String startHistoryDivTag
- = "<DIV identifier=\"" + msgID + "\" style=\"color:#707070;\">";
- String startSystemDivTag
- = "<DIV identifier=\"systemMessage\" style=\"color:#627EB7;\">";
+ String startHistoryDivTag =
+ "<DIV identifier=\"" + msgID + "\" style=\"color:#707070;\">";
+ String startSystemDivTag =
+ "<DIV identifier=\"systemMessage\" style=\"color:#627EB7;\">";
        String endDivTag = "</DIV>";

        String startPlainTextTag;
@@ -348,30 +348,26 @@
        {
            this.lastIncomingMsgTimestamp = System.currentTimeMillis();

- chatString = "<h2 identifier=\""
- + msgHeaderID
- + "\" date=\""
- + date + "\">";
+ chatString =
+ "<h2 identifier=\"" + msgHeaderID + "\" date=\"" + date + "\">";

            endHeaderTag = "</h2>";

- chatString
- += dateString + contactName + " at " + GuiUtils.formatTime(date)
+ chatString +=
+ dateString + contactName + " at " + GuiUtils.formatTime(date)
                    + endHeaderTag + startDivTag + startPlainTextTag
                    + formatMessage(message, contentType, keyword)
                    + endPlainTextTag + endDivTag;
        }
        else if (messageType.equals(Chat.SMS_MESSAGE))
        {
- chatString = "<h2 identifier=\""
- + msgHeaderID
- + "\" date=\""
- + date + "\">";
+ chatString =
+ "<h2 identifier=\"" + msgHeaderID + "\" date=\"" + date + "\">";

            endHeaderTag = "</h2>";

- chatString
- += "SMS: " + dateString + contactName + " at "
+ chatString +=
+ "SMS: " + dateString + contactName + " at "
                    + GuiUtils.formatTime(date) + endHeaderTag + startDivTag
                    + startPlainTextTag
                    + formatMessage(message, contentType, keyword)
@@ -379,97 +375,87 @@
        }
        else if (messageType.equals(Chat.OUTGOING_MESSAGE))
        {
- chatString = "<h3 identifier=\""
- + msgHeaderID
- + "\" date=\""
- + date + "\">";
+ chatString =
+ "<h3 identifier=\"" + msgHeaderID + "\" date=\"" + date + "\">";

            endHeaderTag = "</h3>";

- chatString
- += dateString
- + GuiActivator
- .getResources().getI18NString("service.gui.ME")
- + " at " + GuiUtils.formatTime(date) + endHeaderTag
- + startDivTag + startPlainTextTag
+ chatString +=
+ dateString
+ + GuiActivator.getResources().getI18NString(
+ "service.gui.ME") + " at " + GuiUtils.formatTime(date)
+ + endHeaderTag + startDivTag + startPlainTextTag
                    + formatMessage(message, contentType, keyword)
                    + endPlainTextTag + endDivTag;
        }
        else if (messageType.equals(Chat.STATUS_MESSAGE))
        {
- chatString = "<h4 identifier=\"statusMessage\" date=\""
- + date + "\">";
+ chatString =
+ "<h4 identifier=\"statusMessage\" date=\"" + date + "\">";
            endHeaderTag = "</h4>";

- chatString
- += GuiUtils.formatTime(date) + " " + contactName + " " + message
+ chatString +=
+ GuiUtils.formatTime(date) + " " + contactName + " " + message
                    + endHeaderTag;
        }
        else if (messageType.equals(Chat.ACTION_MESSAGE))
        {
- chatString = "<p identifier=\"actionMessage\" date=\""
- + date + "\">";
+ chatString =
+ "<p identifier=\"actionMessage\" date=\"" + date + "\">";
            endHeaderTag = "</p>";

- chatString += "* " + GuiUtils.formatTime(date)
- + " " + contactName + " "
- + message
- + endHeaderTag;
+ chatString +=
+ "* " + GuiUtils.formatTime(date) + " " + contactName + " "
+ + message + endHeaderTag;
        }
        else if (messageType.equals(Chat.SYSTEM_MESSAGE))
        {
- chatString
- += startSystemDivTag + startPlainTextTag
+ chatString +=
+ startSystemDivTag + startPlainTextTag
                    + formatMessage(message, contentType, keyword)
                    + endPlainTextTag + endDivTag;
        }
        else if (messageType.equals(Chat.ERROR_MESSAGE))
        {
- chatString = "<h6 identifier=\""
- + msgHeaderID
- + "\" date=\""
- + date + "\">";
+ chatString =
+ "<h6 identifier=\"" + msgHeaderID + "\" date=\"" + date + "\">";

            endHeaderTag = "</h6>";

- String errorIcon = "<IMG SRC='"
- + ImageLoader.getImageUri(ImageLoader.EXCLAMATION_MARK)
- + "' </IMG>";
-
- chatString += errorIcon
- + messageTitle
- + endHeaderTag + "<h5>" + message + "</h5>";
+ String errorIcon =
+ "<IMG SRC='"
+ + ImageLoader.getImageUri(ImageLoader.EXCLAMATION_MARK)
+ + "' </IMG>";
+
+ chatString +=
+ errorIcon + messageTitle + endHeaderTag + "<h5>" + message
+ + "</h5>";
        }
        else if (messageType.equals(Chat.HISTORY_INCOMING_MESSAGE))
        {
- chatString = "<h2 identifier='"
- + msgHeaderID
- + "' date=\""
- + date + "\">";
+ chatString =
+ "<h2 identifier='" + msgHeaderID + "' date=\"" + date + "\">";

            endHeaderTag = "</h2>";

- chatString
- += dateString + contactName + " at " + GuiUtils.formatTime(date)
+ chatString +=
+ dateString + contactName + " at " + GuiUtils.formatTime(date)
                    + endHeaderTag + startHistoryDivTag + startPlainTextTag
                    + formatMessage(message, contentType, keyword)
                    + endPlainTextTag + endDivTag;
        }
        else if (messageType.equals(Chat.HISTORY_OUTGOING_MESSAGE))
        {
- chatString = "<h3 identifier=\""
- + msgHeaderID
- + "\" date=\""
- + date + "\">";
+ chatString =
+ "<h3 identifier=\"" + msgHeaderID + "\" date=\"" + date + "\">";

            endHeaderTag = "</h3>";

- chatString
- += dateString
- + GuiActivator
- .getResources().getI18NString("service.gui.ME")
- + " at " + GuiUtils.formatTime(date) + endHeaderTag
- + startHistoryDivTag + startPlainTextTag
+ chatString +=
+ dateString
+ + GuiActivator.getResources().getI18NString(
+ "service.gui.ME") + " at " + GuiUtils.formatTime(date)
+ + endHeaderTag + startHistoryDivTag + startPlainTextTag
                    + formatMessage(message, contentType, keyword)
                    + endPlainTextTag + endDivTag;
        }
@@ -479,7 +465,7 @@

    /**
     * Processes the message given by the parameters.
- *
+ *
     * @param chatMessage the message.
     * @return the formatted message
     */
@@ -491,7 +477,7 @@
    /**
     * Appends the given string at the end of the contained in this panel
     * document.
- *
+ *
     * @param chatString the string to append
     */
    public void appendMessageToEnd(String chatString)
@@ -504,10 +490,8 @@

            try
            {
- document
- .insertAfterEnd(
- root.getElement(root.getElementCount() - 1),
- chatString);
+ document.insertAfterEnd(root
+ .getElement(root.getElementCount() - 1), chatString);
            }
            catch (BadLocationException e)
            {
@@ -519,10 +503,96 @@
            }
            if (!isHistory)
                ensureDocumentSize();
+
+ final Element elem;
+
+ /*
+ * Check to make sure element isn't the first element in the HTML
+ * document.
+ */
+ if (!(root.getElementCount() < 2))
+ {
+ elem = root.getElement(root.getElementCount() - 2);
+ }
+ else
+ elem = root.getElement(1);
+
+ String prefix =
+ "net.java.sip.communicator.impl.gui.replacement.isEnabled";
+ String obj =
+ (String) GuiActivator.getConfigurationService().getProperty(
+ prefix);
+ /*
+ * Replacements will be processed only if it is enabled in the
+ * property
+ */
+ if (obj != null && Boolean.parseBoolean(obj))
+ {
+ processReplacement(elem, chatString);
+ }
        }
    }

    /**
+ * Formats the given message. Processes the messages and replaces links to
+ * video/image sources with their previews or any other substitution. Spawns
+ * a separate thread for replacement.
+ *
+ * @param elem the element in the HTML Document.
+ * @param chatString the message.
+ */
+ private void processReplacement(final Element elem, final String chatString)
+ {
+
+ final String chatFinal = chatString;
+
+ SwingWorker worker = new SwingWorker()
+ {
+
+ @Override
+ public Object construct() throws Exception
+ {
+ String temp = "", msgStore = chatFinal;
+
+ Iterator entrySetIter = listsources.entrySet().iterator();
+
+ for (int i = 0; i < listsources.size(); i++)
+ {
+
+ Map.Entry entry = (Map.Entry) entrySetIter.next();
+ ReplacementService source =
+ (ReplacementService) entry.getValue();
+
+ temp = source.getReplacedMessage(msgStore);
+
+ /*
+ * replace the msgStore variable with the current replaced
+ * message before next iteration
+ */
+
+ if (!temp.equals(msgStore))
+ {
+ msgStore = temp;
+ }
+ }
+
+ if (!temp.equals(chatFinal))
+ {
+ synchronized (scrollToBottomRunnable)
+ {
+ scrollToBottomIsPending = true;
+ document.setOuterHTML(elem, temp.toString().substring(
+ temp.indexOf("<DIV")));
+ }
+ }
+
+ return "";
+ }
+ };
+ worker.start();
+ }
+
+ /**
     * Ensures that the document won't become too big. When the document reaches
     * a certain size the first message in the page is removed.
     */
@@ -540,15 +610,16 @@
            // Count how many messages we have in the document.
            for (int i = 0; i < rootElement.getElementCount(); i++)
            {
- String idAttr = (String) rootElement.getElement(i)
- .getAttributes().getAttribute("identifier");
+ String idAttr =
+ (String) rootElement.getElement(i).getAttributes()
+ .getAttribute("identifier");

- if(idAttr != null
+ if (idAttr != null
                    && (idAttr.equals("message")
- || idAttr.equals("statusMessage")
- || idAttr.equals("systemMessage")))
+ || idAttr.equals("statusMessage") || idAttr
+ .equals("systemMessage")))
                {
- if(firstMsgElement == null)
+ if (firstMsgElement == null)
                    {
                        firstMsgElement = rootElement.getElement(i);
                        firstMsgIndex = i;
@@ -560,20 +631,22 @@

            // If we doesn't have any known elements in the document or if we
            // have only one long message we don't want to remove it.
- if(firstMsgElement == null || msgElementCount < 2)
+ if (firstMsgElement == null || msgElementCount < 2)
                return;

            try
            {
                // Remove the header of the message if such exists.
- if(firstMsgIndex > 0)
+ if (firstMsgIndex > 0)
                {
- Element headerElement = rootElement.getElement(firstMsgIndex - 1);
+ Element headerElement =
+ rootElement.getElement(firstMsgIndex - 1);

- String idAttr = (String) headerElement
- .getAttributes().getAttribute("identifier");
+ String idAttr =
+ (String) headerElement.getAttributes().getAttribute(
+ "identifier");

- if(idAttr != null && idAttr.equals("messageHeader"))
+ if (idAttr != null && idAttr.equals("messageHeader"))
                    {
                        this.document.remove(headerElement.getStartOffset(),
                            headerElement.getEndOffset()
@@ -583,8 +656,8 @@

                // Remove the message itself.
                this.document.remove(firstMsgElement.getStartOffset(),
- firstMsgElement.getEndOffset()
- - firstMsgElement.getStartOffset());
+ firstMsgElement.getEndOffset()
+ - firstMsgElement.getStartOffset());
            }
            catch (BadLocationException e)
            {
@@ -595,15 +668,14 @@

    /**
     * Highlights keywords searched in the history.
- *
+ *
     * @param message the source message
     * @param contentType the content type
     * @param keyword the searched keyword
     * @return the formatted message
     */
- private String processKeyword( String message,
- String contentType,
- String keyword)
+ private String processKeyword(String message, String contentType,
+ String keyword)
    {
        String startPlainTextTag;
        String endPlainTextTag;
@@ -619,9 +691,8 @@
            endPlainTextTag = END_PLAINTEXT_TAG;
        }

- Matcher m
- = Pattern
- .compile(keyword, Pattern.CASE_INSENSITIVE).matcher(message);
+ Matcher m =
+ Pattern.compile(keyword, Pattern.CASE_INSENSITIVE).matcher(message);
        StringBuffer msgBuffer = new StringBuffer();
        int prevEnd = 0;

@@ -653,15 +724,14 @@
    /**
     * Formats the given message. Processes all smiley chars, new lines and
     * links.
- *
+ *
     * @param message the message to be formatted
     * @param contentType the content type of the message to be formatted
     * @param keyword the word to be highlighted
     * @return the formatted message
     */
- private String formatMessage(String message,
- String contentType,
- String keyword)
+ private String formatMessage(String message, String contentType,
+ String keyword)
    {
        // If the message content type is HTML we won't process links and
        // new lines, but only the smileys.
@@ -677,8 +747,8 @@

            if ((keyword != null) && (keyword.length() != 0))
            {
- String messageWithProcessedKeyword
- = processKeyword(message, contentType, keyword);
+ String messageWithProcessedKeyword =
+ processKeyword(message, contentType, keyword);

                /*
                 * The same String instance will be returned if there was no
@@ -691,9 +761,9 @@
            else
                processHTMLChars = true;

- message
- = processNewLines(
- processLinksAndHTMLChars(message, processHTMLChars));
+ message =
+ processNewLines(processLinksAndHTMLChars(message,
+ processHTMLChars));
        }
        // If the message content is HTML, we process br and img tags.
        else
@@ -703,9 +773,7 @@
            message = processImgTags(processBrTags(message));
        }

- if (ConfigurationManager.isShowSmileys())
- message = processSmileys(message, contentType);
-
+ // return processSmileys(message, contentType);
        return message;
    }

@@ -719,12 +787,12 @@
     * characters such as &amp;.
     *
     * @param message The source message string.
- * @param processHTMLChars <tt>true</tt> to escape the special HTML chars;
- * otherwise, <tt>false</tt>
+ * @param processHTMLChars <tt>true</tt> to escape the special HTML chars;
+ * otherwise, <tt>false</tt>
     * @return The message string with properly formatted links.
     */
    private String processLinksAndHTMLChars(String message,
- boolean processHTMLChars)
+ boolean processHTMLChars)
    {
        Matcher m = URL_PATTERN.matcher(message);
        StringBuffer msgBuffer = new StringBuffer();
@@ -764,23 +832,19 @@
    /**
     * Escapes special HTML characters such as &lt;, &gt;, &amp; and &quot; in
     * the specified message.
- *
+ *
     * @param message the message to be processed
     * @return the processed message with escaped special HTML characters
     */
    private String processHTMLChars(String message)
    {
- return
- message
- .replace("&", "&amp;")
- .replace("<", "&lt;")
- .replace(">", "&gt;")
- .replace("\"", "&quot;");
+ return message.replace("&", "&amp;").replace("<", "&lt;").replace(">",
+ "&gt;").replace("\"", "&quot;");
    }

    /**
     * Formats message new lines.
- *
+ *
     * @param message The source message string.
     * @return The message string with properly formatted new lines.
     */
@@ -791,23 +855,20 @@
         * <br> tags are needed to visualize a new line in the html format, but
         * when copied to the clipboard they are exported to the plain text
         * format as ' ' and not as '\n'.
- *
+ *
         * See bug N4988885:
         * http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4988885
- *
+ *
         * To fix this we need "&#10;" - the HTML-Code for ASCII-Character No.10
         * (Line feed).
         */
- return
- message
- .replaceAll(
- "\n",
- END_PLAINTEXT_TAG + "<BR>&#10;" + START_PLAINTEXT_TAG);
+ return message.replaceAll("\n", END_PLAINTEXT_TAG + "<BR>&#10;"
+ + START_PLAINTEXT_TAG);
    }

    /**
     * Formats message smileys.
- *
+ *
     * @param message the source message string
     * @param contentType the content type
     * @return the message string with properly formated smileys
@@ -856,11 +917,12 @@
    /**
     * 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
+ * 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
+ * the specified <tt>Collection</tt> of <tt>Smiley</tt>s
     */
    private static Pattern getSmileyPattern(Collection<Smiley> smileys)
    {
@@ -880,9 +942,8 @@
                smileyLoop: for (Smiley smiley : smileys)
                    for (String smileyString : smiley.getSmileyStrings())
                        if ((smileyStringIndex < smileyStringCount)
- && smileyString
- .equals(
- smileyStrings.get(smileyStringIndex)))
+ && smileyString.equals(smileyStrings
+ .get(smileyStringIndex)))
                            smileyStringIndex++;
                        else
                        {
@@ -890,7 +951,7 @@
                            break smileyLoop;
                        }
                if (smileyStringsIsEqual
- && (smileyStringIndex != smileyStringCount))
+ && (smileyStringIndex != smileyStringCount))
                    smileyStringsIsEqual = false;
            }

@@ -906,12 +967,9 @@
                    {
                        smileyStrings.add(smileyString);

- regex
- .append(
- GuiUtils
- .replaceSpecialRegExpChars(
- smileyString))
- .append("|");
+ regex.append(
+ GuiUtils.replaceSpecialRegExpChars(smileyString))
+ .append("|");
                    }
                regex = regex.deleteCharAt(regex.length() - 1);
                regex.append(')');
@@ -925,7 +983,7 @@
    /**
     * Opens a link in the default browser when clicked and shows link url in a
     * popup on mouseover.
- *
+ *
     * @param e The HyperlinkEvent.
     */
    public void hyperlinkUpdate(HyperlinkEvent e)
@@ -944,7 +1002,7 @@

    /**
     * Returns the text pane of this conversation panel.
- *
+ *
     * @return The text pane of this conversation panel.
     */
    public JTextPane getChatTextPane()
@@ -954,7 +1012,7 @@

    /**
     * Returns the time of the last received message.
- *
+ *
     * @return The time of the last received message.
     */
    public long getLastIncomingMsgTimestamp()
@@ -965,7 +1023,7 @@
    /**
     * When a right button click is performed in the editor pane, a popup menu
     * is opened.
- *
+ *
     * @param e The MouseEvent.
     */
    public void mouseClicked(MouseEvent e)
@@ -987,7 +1045,7 @@

    /**
     * Opens this panel context menu at the given point.
- *
+ *
     * @param p the point where to position the left-top cornet of the context
     * menu
     */
@@ -1019,19 +1077,29 @@
        rightButtonMenu.setVisible(true);
    }

- public void mousePressed(MouseEvent e) {}
+ public void mousePressed(MouseEvent e)
+ {
+ }

- public void mouseReleased(MouseEvent e) {}
+ public void mouseReleased(MouseEvent e)
+ {
+ }

- public void mouseEntered(MouseEvent e) {}
+ public void mouseEntered(MouseEvent e)
+ {
+ }

- public void mouseExited(MouseEvent e) {}
+ public void mouseExited(MouseEvent e)
+ {
+ }

- public void lostOwnership(Clipboard clipboard, Transferable contents) {}
+ public void lostOwnership(Clipboard clipboard, Transferable contents)
+ {
+ }

    /**
     * Returns the chat container.
- *
+ *
     * @return the chat container
     */
    public ChatConversationContainer getChatContainer()
@@ -1054,13 +1122,13 @@
    public void clear()
    {
        this.document = (HTMLDocument) editorKit.createDefaultDocument();
- Constants.loadSimpleStyle(
- document.getStyleSheet(), chatTextPane.getFont());
+ Constants.loadSimpleStyle(document.getStyleSheet(), chatTextPane
+ .getFont());
    }

    /**
     * Sets the given document to the editor pane in this panel.
- *
+ *
     * @param document the document to set
     */
    public void setContent(HTMLDocument document)
@@ -1085,7 +1153,7 @@

    /**
     * Returns the document contained in this panel.
- *
+ *
     * @return the document contained in this panel
     */
    public HTMLDocument getContent()
@@ -1095,7 +1163,7 @@

    /**
     * Returns the right button popup menu.
- *
+ *
     * @return the right button popup menu
     */
    public ChatRightButtonMenu getRightButtonMenu()
@@ -1105,7 +1173,7 @@

    /**
     * Returns the date of the first message in the current page.
- *
+ *
     * @return the date of the first message in the current page
     */
    public Date getPageFirstMsgTimestamp()
@@ -1114,10 +1182,11 @@

        Element firstMessageElement = null;

- for(int i = 0; i < rootElement.getElementCount(); i ++)
+ for (int i = 0; i < rootElement.getElementCount(); i++)
        {
- String idAttr = (String) rootElement.getElement(i)
- .getAttributes().getAttribute("identifier");
+ String idAttr =
+ (String) rootElement.getElement(i).getAttributes()
+ .getAttribute("identifier");

            if (idAttr != null && idAttr.equals("messageHeader"))
            {
@@ -1126,18 +1195,18 @@
            }
        }

- if(firstMessageElement == null)
+ if (firstMessageElement == null)
            return new Date(Long.MAX_VALUE);

- String dateObject = firstMessageElement
- .getAttributes().getAttribute("date").toString();
+ String dateObject =
+ firstMessageElement.getAttributes().getAttribute("date").toString();

        return new Date(Long.parseLong(dateObject));
    }

    /**
     * Returns the date of the last message in the current page.
- *
+ *
     * @return the date of the last message in the current page
     */
    public Date getPageLastMsgTimestamp()
@@ -1146,10 +1215,11 @@

        Element lastMessageElement = null;

- for(int i = rootElement.getElementCount() - 1; i >= 0; i --)
+ for (int i = rootElement.getElementCount() - 1; i >= 0; i--)
        {
- String idAttr = (String) rootElement.getElement(i)
- .getAttributes().getAttribute("identifier");
+ String idAttr =
+ (String) rootElement.getElement(i).getAttributes()
+ .getAttribute("identifier");

            if (idAttr != null && idAttr.equals("messageHeader"))
            {
@@ -1158,20 +1228,21 @@
            }
        }

- if(lastMessageElement == null)
+ if (lastMessageElement == null)
            return new Date(0);

- String dateObject = lastMessageElement
- .getAttributes().getAttribute("date").toString();
+ String dateObject =
+ lastMessageElement.getAttributes().getAttribute("date").toString();

        return new Date(Long.parseLong(dateObject));
    }

    /**
     * Formats HTML tags &lt;br/&gt; to &lt;br&gt; or &lt;BR/&gt; to &lt;BR&gt;.
- * The reason of this function is that the ChatPanel does not support
- * &lt;br /&gt; closing tags (XHTML syntax), thus we have to remove every
- * slash from each &lt;br /&gt; tags.
+ * The reason of this function is that the ChatPanel does not support &lt;br
+ * /&gt; closing tags (XHTML syntax), thus we have to remove every slash
+ * from each &lt;br /&gt; tags.
+ *
     * @param message The source message string.
     * @return The message string with properly formatted &lt;br&gt; tags.
     */
@@ -1183,12 +1254,12 @@
        // Compile the regex to match something like <br .. /> or <BR .. />.
        // This regex is case sensitive and keeps the style or other
        // attributes of the <br> tag.
- Matcher m
- = Pattern.compile("<\\s*[bB][rR](.*?)(/\\s*>)").matcher(message);
+ Matcher m =
+ Pattern.compile("<\\s*[bB][rR](.*?)(/\\s*>)").matcher(message);
        int start = 0;

        // while we find some <br /> closing tags with a slash inside.
- while(m.find())
+ while (m.find())
        {
            // First, we have to copy all the message preceding the <br> tag.
            processedMessage.append(message.substring(start, m.start()));
@@ -1197,7 +1268,7 @@
            // We copy the <br> tag till the slash exclude.
            processedMessage.append(m.group().substring(0, slash_index));
            // We copy all the end of the tag following the slash exclude.
- processedMessage.append(m.group().substring(slash_index+1));
+ processedMessage.append(m.group().substring(slash_index + 1));
            start = m.end();
        }
        // Finally, we have to add the end of the message following the last
@@ -1209,11 +1280,11 @@

    /**
     * Formats HTML tags &lt;img ... /&gt; to &lt; img ... &gt;&lt;/img&gt; or
- * &lt;IMG ... /&gt; to &lt;IMG&gt;&lt;/IMG&gt;.
- * The reason of this function is that the ChatPanel does not support
- * &lt;img /&gt; tags (XHTML syntax).
+ * &lt;IMG ... /&gt; to &lt;IMG&gt;&lt;/IMG&gt;. The reason of this function
+ * is that the ChatPanel does not support &lt;img /&gt; tags (XHTML syntax).
     * Thus, we remove every slash from each &lt;img /&gt; and close it with a
     * separate closing tag.
+ *
     * @param message The source message string.
     * @return The message string with properly formatted &lt;img&gt; tags.
     */
@@ -1231,7 +1302,8 @@
        int start = 0;

        // while we find some <img /> self-closing tags with a slash inside.
- while(m.find()){
+ while (m.find())
+ {
            // First, we have to copy all the message preceding the <img> tag.
            processedMessage.append(message.substring(start, m.start()));
            // Then, we find the position of the slash inside the tag.
@@ -1239,7 +1311,7 @@
            // We copy the <img> tag till the slash exclude.
            processedMessage.append(m.group().substring(0, slash_index));
            // We copy all the end of the tag following the slash exclude.
- processedMessage.append(m.group().substring(slash_index+1));
+ processedMessage.append(m.group().substring(slash_index + 1));
            // We close the tag with a separate closing tag.
            processedMessage.append("</img>");
            start = m.end();
@@ -1258,14 +1330,14 @@
        extends JTextPane
    {
        /**
- * Returns the string to be used as the tooltip for <i>event</i>.
- *
- * @param event the <tt>MouseEvent</tt>
+ * Returns the string to be used as the tooltip for <i>event</i>.
+ *
+ * @param event the <tt>MouseEvent</tt>
         * @return the string to be used as the tooltip for <i>event</i>.
         */
        public String getToolTipText(MouseEvent event)
        {
- if(currentHref != null && currentHref.length() != 0)
+ if (currentHref != null && currentHref.length() != 0)
                return currentHref;
            else
                return null;
@@ -1282,25 +1354,20 @@
        synchronized (scrollToBottomRunnable)
        {
            StyleSheet styleSheet = document.getStyleSheet();
- Style style
- = styleSheet
- .addStyle(
- StyleConstants.ComponentElementName,
- styleSheet.getStyle("body"));
+ Style style =
+ styleSheet.addStyle(StyleConstants.ComponentElementName,
+ styleSheet.getStyle("body"));

            // The image must first be wrapped in a style
- style
- .addAttribute(
- AbstractDocument.ElementNameAttribute,
- StyleConstants.ComponentElementName);
+ style.addAttribute(AbstractDocument.ElementNameAttribute,
+ StyleConstants.ComponentElementName);

- TransparentPanel wrapPanel
- = new TransparentPanel(new BorderLayout());
+ TransparentPanel wrapPanel =
+ new TransparentPanel(new BorderLayout());

            wrapPanel.add(component, BorderLayout.NORTH);

- style
- .addAttribute(StyleConstants.ComponentAttribute, wrapPanel);
+ style.addAttribute(StyleConstants.ComponentAttribute, wrapPanel);
            style.addAttribute("identifier", "messageHeader");
            style.addAttribute("date", component.getDate().getTime());

@@ -1309,8 +1376,8 @@
            // Insert the component style at the end of the text
            try
            {
- document
- .insertString(document.getLength(), "ignored text", style);
+ document.insertString(document.getLength(), "ignored text",
+ style);
            }
            catch (BadLocationException e)
            {

Modified: branches/gsoc10/previews/src/net/java/sip/communicator/impl/gui/swing.ui.manifest.mf
Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/branches/gsoc10/previews/src/net/java/sip/communicator/impl/gui/swing.ui.manifest.mf?view=diff&rev=7237&p1=branches/gsoc10/previews/src/net/java/sip/communicator/impl/gui/swing.ui.manifest.mf&p2=branches/gsoc10/previews/src/net/java/sip/communicator/impl/gui/swing.ui.manifest.mf&r1=7236&r2=7237

--- branches/gsoc10/previews/src/net/java/sip/communicator/impl/gui/swing.ui.manifest.mf (original)
+++ branches/gsoc10/previews/src/net/java/sip/communicator/impl/gui/swing.ui.manifest.mf 2010-06-12 14:14:41+0000
@@ -58,4 +58,5 @@
javax.swing.undo,
org.jdesktop.jdic.desktop,
say.swing,
- com.apple.eawt
+ com.apple.eawt,
+ net.java.sip.communicator.service.replacement

Modified: branches/gsoc10/previews/src/net/java/sip/communicator/impl/gui/utils/Smiley.java
Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/branches/gsoc10/previews/src/net/java/sip/communicator/impl/gui/utils/Smiley.java?view=diff&rev=7237&p1=branches/gsoc10/previews/src/net/java/sip/communicator/impl/gui/utils/Smiley.java&p2=branches/gsoc10/previews/src/net/java/sip/communicator/impl/gui/utils/Smiley.java&r1=7236&r2=7237

--- branches/gsoc10/previews/src/net/java/sip/communicator/impl/gui/utils/Smiley.java (original)
+++ branches/gsoc10/previews/src/net/java/sip/communicator/impl/gui/utils/Smiley.java 2010-06-12 14:14:41+0000
@@ -1,5 +1,5 @@
/*
- * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
+F * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
@@ -95,4 +95,22 @@

        return url.toString();
    }
+
+ /**
+ * Returns the path of the image corresponding to this smiley.
+ * @param resourcesService The ResourceManagementService required to get the
+ * image URL.
+ * @return the path of the image corresponding to this smiley.
+ */
+ public String getImagePath(ResourceManagementService resourcesService)
+ {
+ URL url
+ = resourcesService
+ .getImageURL(this.getImageID().getId());
+
+ if(url == null)
+ return null;
+
+ return url.toString();
+ }
}

Added: branches/gsoc10/previews/src/net/java/sip/communicator/impl/replacement/dailymotion/DailymotionActivator.java
Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/branches/gsoc10/previews/src/net/java/sip/communicator/impl/replacement/dailymotion/DailymotionActivator.java?view=auto&rev=7237

--- (empty file)
+++ branches/gsoc10/previews/src/net/java/sip/communicator/impl/replacement/dailymotion/DailymotionActivator.java 2010-06-12 14:14:41+0000
@@ -0,0 +1,76 @@
+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.*;
+
+public class DailymotionActivator
+ implements BundleActivator
+{
+
+ private static final Logger logger =
+ Logger.getLogger(DailymotionActivator.class);
+
+ /**
+ * The currently valid bundle context.
+ */
+ private static BundleContext bundleContext = null;
+
+ private ServiceRegistration dailymotionSourceServReg = null;
+
+ private static ReplacementService dailymotionSource = null;
+
+ private static ResourceManagementService resourceService;
+
+ public void start(BundleContext context) throws Exception
+ {
+
+ bundleContext = context;
+
+ 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].");
+
+ }
+
+ public static BundleContext getBundleContext()
+ {
+ return bundleContext;
+ }
+
+ public void stop(BundleContext arg0) throws Exception
+ {
+
+ dailymotionSourceServReg.unregister();
+ logger.info("Dailymotion source implementation [STOPPED].");
+ }
+
+ public static ResourceManagementService getResources()
+ {
+ if (resourceService == null)
+ {
+ ServiceReference serviceReference =
+ bundleContext
+ .getServiceReference(ResourceManagementService.class
+ .getName());
+
+ if (serviceReference == null)
+ return null;
+
+ resourceService =
+ (ResourceManagementService) bundleContext
+ .getService(serviceReference);
+ }
+
+ return resourceService;
+ }
+}

Added: branches/gsoc10/previews/src/net/java/sip/communicator/impl/replacement/dailymotion/ReplacementServiceDailymotionImpl.java
Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/branches/gsoc10/previews/src/net/java/sip/communicator/impl/replacement/dailymotion/ReplacementServiceDailymotionImpl.java?view=auto&rev=7237

--- (empty file)
+++ branches/gsoc10/previews/src/net/java/sip/communicator/impl/replacement/dailymotion/ReplacementServiceDailymotionImpl.java 2010-06-12 14:14:41+0000
@@ -0,0 +1,64 @@
+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.*;
+
+public class ReplacementServiceDailymotionImpl
+ implements ReplacementService
+{
+
+ private static final Logger logger =
+ Logger.getLogger(ReplacementServiceDailymotionImpl.class);
+
+ public static final String DAILYMOTION_PATTERN =
+ "(http.*?(www\\.)*?dailymotion\\.com\\/video\\/([a-zA-Z0-9_\\-]+))([?#]([a-zA-Z0-9_\\-]+))*";
+
+ public ReplacementServiceDailymotionImpl()
+ {
+
+ logger.trace("Creating a DailyMotion Source.");
+ }
+
+ 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;
+ }
+
+}

Added: branches/gsoc10/previews/src/net/java/sip/communicator/impl/replacement/dailymotion/dailymotion.source.manifest.mf
Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/branches/gsoc10/previews/src/net/java/sip/communicator/impl/replacement/dailymotion/dailymotion.source.manifest.mf?view=auto&rev=7237

--- (empty file)
+++ branches/gsoc10/previews/src/net/java/sip/communicator/impl/replacement/dailymotion/dailymotion.source.manifest.mf 2010-06-12 14:14:41+0000
@@ -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,

Added: branches/gsoc10/previews/src/net/java/sip/communicator/impl/replacement/smiley/ReplacementServiceSmileyImpl.java
Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/branches/gsoc10/previews/src/net/java/sip/communicator/impl/replacement/smiley/ReplacementServiceSmileyImpl.java?view=auto&rev=7237

--- (empty file)
+++ branches/gsoc10/previews/src/net/java/sip/communicator/impl/replacement/smiley/ReplacementServiceSmileyImpl.java 2010-06-12 14:14:41+0000
@@ -0,0 +1,148 @@
+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.*;
+
+public class ReplacementServiceSmileyImpl
+ implements ReplacementService
+{
+
+ private static final Logger logger =
+ Logger.getLogger(ReplacementServiceSmileyImpl.class);
+
+ /**
+ * 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>";
+
+ @Override
+ 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;
+ }
+ }
+
+}

Added: branches/gsoc10/previews/src/net/java/sip/communicator/impl/replacement/smiley/SmileyActivator.java
Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/branches/gsoc10/previews/src/net/java/sip/communicator/impl/replacement/smiley/SmileyActivator.java?view=auto&rev=7237

--- (empty file)
+++ branches/gsoc10/previews/src/net/java/sip/communicator/impl/replacement/smiley/SmileyActivator.java 2010-06-12 14:14:41+0000
@@ -0,0 +1,80 @@
+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.*;
+
+public class SmileyActivator
+ implements BundleActivator
+{
+
+ private static final Logger logger =
+ Logger.getLogger(SmileyActivator.class);
+
+ /**
+ * The currently valid bundle context.
+ */
+ private static BundleContext bundleContext = null;
+
+ private static ResourceManagementService resourcesService;
+
+ private ServiceRegistration smileyServReg = null;
+
+ private static ReplacementService smileySource = null;
+
+ 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].");
+
+ }
+
+ public void stop(BundleContext arg0) 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;
+ }
+
+}

Added: branches/gsoc10/previews/src/net/java/sip/communicator/impl/replacement/smiley/smiley.source.manifest.mf
Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/branches/gsoc10/previews/src/net/java/sip/communicator/impl/replacement/smiley/smiley.source.manifest.mf?view=auto&rev=7237

--- (empty file)
+++ branches/gsoc10/previews/src/net/java/sip/communicator/impl/replacement/smiley/smiley.source.manifest.mf 2010-06-12 14:14:41+0000
@@ -0,0 +1,17 @@
+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,
+
+
\ No newline at end of file

Added: branches/gsoc10/previews/src/net/java/sip/communicator/impl/replacement/vimeo/ReplacementServiceVimeoImpl.java
Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/branches/gsoc10/previews/src/net/java/sip/communicator/impl/replacement/vimeo/ReplacementServiceVimeoImpl.java?view=auto&rev=7237

--- (empty file)
+++ branches/gsoc10/previews/src/net/java/sip/communicator/impl/replacement/vimeo/ReplacementServiceVimeoImpl.java 2010-06-12 14:14:41+0000
@@ -0,0 +1,107 @@
+package net.java.sip.communicator.impl.replacement.vimeo;
+
+import java.net.*;
+import java.util.regex.*;
+
+import org.apache.http.*;
+import org.json.*;
+
+import net.java.sip.communicator.service.replacement.*;
+import net.java.sip.communicator.util.*;
+
+import java.io.*;
+
+public class ReplacementServiceVimeoImpl
+ implements ReplacementService
+{
+
+ private static final Logger logger =
+ Logger.getLogger(ReplacementServiceVimeoImpl.class);
+
+ public static final String VIMEO_PATTERN =
+ "(http.*?(www\\.)*?vimeo\\.com\\/([a-zA-Z0-9_\\-]+))";
+
+ public ReplacementServiceVimeoImpl()
+ {
+
+ logger.trace("Creating a Vimeo Source.");
+ }
+
+ @Override
+ 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;
+ }
+
+}

Added: branches/gsoc10/previews/src/net/java/sip/communicator/impl/replacement/vimeo/VimeoActivator.java
Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/branches/gsoc10/previews/src/net/java/sip/communicator/impl/replacement/vimeo/VimeoActivator.java?view=auto&rev=7237

--- (empty file)
+++ branches/gsoc10/previews/src/net/java/sip/communicator/impl/replacement/vimeo/VimeoActivator.java 2010-06-12 14:14:41+0000
@@ -0,0 +1,52 @@
+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.*;
+
+public class VimeoActivator
+ implements BundleActivator
+{
+
+ private static final Logger logger = Logger.getLogger(VimeoActivator.class);
+
+ /**
+ * The currently valid bundle context.
+ */
+ private static BundleContext bundleContext = null;
+
+ private ServiceRegistration vimeoServReg = null;
+
+ private static ReplacementService vimeoSource = null;
+
+ @Override
+ public void start(BundleContext context) throws Exception
+ {
+
+ bundleContext = context;
+
+ 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].");
+
+ }
+
+ @Override
+ public void stop(BundleContext arg0) throws Exception
+ {
+
+ vimeoServReg.unregister();
+ logger.info("Vimeo source implementation [STOPPED].");
+
+ }
+
+}

Added: branches/gsoc10/previews/src/net/java/sip/communicator/impl/replacement/vimeo/vimeo.source.manifest.mf
Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/branches/gsoc10/previews/src/net/java/sip/communicator/impl/replacement/vimeo/vimeo.source.manifest.mf?view=auto&rev=7237

--- (empty file)
+++ branches/gsoc10/previews/src/net/java/sip/communicator/impl/replacement/vimeo/vimeo.source.manifest.mf 2010-06-12 14:14:41+0000
@@ -0,0 +1,14 @@
+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,
+
\ No newline at end of file

Added: branches/gsoc10/previews/src/net/java/sip/communicator/impl/replacement/youtube/ReplacementServiceYoutubeImpl.java
Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/branches/gsoc10/previews/src/net/java/sip/communicator/impl/replacement/youtube/ReplacementServiceYoutubeImpl.java?view=auto&rev=7237

--- (empty file)
+++ branches/gsoc10/previews/src/net/java/sip/communicator/impl/replacement/youtube/ReplacementServiceYoutubeImpl.java 2010-06-12 14:14:41+0000
@@ -0,0 +1,126 @@
+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 com.google.gdata.client.youtube.*;
+import com.google.gdata.data.media.mediarss.*;
+import com.google.gdata.data.youtube.*;
+import com.google.gdata.util.*;
+
+public class ReplacementServiceYoutubeImpl
+ implements ReplacementService
+{
+
+ private static final Logger logger =
+ Logger.getLogger(ReplacementServiceYoutubeImpl.class);
+
+ public static String re1 =
+ "(http.*?(www\\.)*?youtube\\.com\\/watch\\?v=([a-zA-Z0-9_\\-]+))([?&]\\w+=[\\w-]+)*";
+
+ public final static String API_URL =
+ "http://gdata.youtube.com/feeds/api/videos/";
+
+ /**
+ * The name of this source.
+ */
+ public static final String YOUTUBE_SOURCE_NAME = "Youtube";
+
+ public ReplacementServiceYoutubeImpl()
+ {
+ logger.trace("Creating a Youtube Source.");
+ }
+
+ public String getReplacedMessage(final String chatString)
+ {
+
+ YouTubeService service =
+ new YouTubeService(
+ "sip-communicator",
+ "AI39si6BTBWcTyQWItjdm40FVeIvFa9RS9xT5i3-RB8cYpnr4GQkdQk38HBpwgYzAqWV5afHIJ_M3F5qQpPM9ULUU0yiMx6joQ");
+ 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();
+
+ if (count % 2 == 0)
+ {
+
+ String videoEntryUrl = API_URL + m.group(3);
+ VideoEntry videoEntry = null;
+
+ try
+ {
+ try
+ {
+ videoEntry =
+ service.getEntry(new URL(videoEntryUrl),
+ VideoEntry.class);
+ }
+ catch (MalformedURLException e)
+ {
+ e.printStackTrace();
+ }
+ catch (IOException e)
+ {
+ e.printStackTrace();
+ }
+ }
+ catch (ServiceException e)
+ {
+ e.printStackTrace();
+ }
+
+ YouTubeMediaGroup mediaGroup = videoEntry.getMediaGroup();
+
+ for (MediaThumbnail mediaThumbnail : mediaGroup.getThumbnails())
+ {
+
+ if (mediaThumbnail.getUrl().matches(".*1\\.jpg"))
+ {
+ msgBuff.append("<IMG HEIGHT=\""
+ + mediaThumbnail.getHeight() + "\" WIDTH=\""
+ + mediaThumbnail.getWidth() + "\" SRC=\"");
+ msgBuff.append(mediaThumbnail.getUrl());
+ msgBuff.append("\"></IMG>");
+ }
+ }
+ }
+ else
+ {
+ msgBuff.append(chatString.substring(m.start(), m.end()));
+ }
+
+ }
+
+ msgBuff.append(chatString.substring(startPos));
+
+ /*
+ * synchronized(document){
+ *
+ * document.setOuterHTML(elem,
+ * msgBuff.toString().substring(chatBuff.indexOf("<DIV")));
+ * System.out.println(chatString.substring(chatString.indexOf("<DIV")));
+ *
+ * }
+ */
+
+ if (!msgBuff.toString().equals(chatString))
+ return msgBuff.toString();
+
+ return chatString;
+ }
+}

Added: branches/gsoc10/previews/src/net/java/sip/communicator/impl/replacement/youtube/YoutubeActivator.java
Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/branches/gsoc10/previews/src/net/java/sip/communicator/impl/replacement/youtube/YoutubeActivator.java?view=auto&rev=7237

--- (empty file)
+++ branches/gsoc10/previews/src/net/java/sip/communicator/impl/replacement/youtube/YoutubeActivator.java 2010-06-12 14:14:41+0000
@@ -0,0 +1,78 @@
+package net.java.sip.communicator.impl.replacement.youtube;
+
+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.*;
+
+public class YoutubeActivator
+ implements BundleActivator
+{
+
+ private static final Logger logger =
+ Logger.getLogger(YoutubeActivator.class);
+
+ /**
+ * The currently valid bundle context.
+ */
+ private static BundleContext bundleContext = null;
+
+ private ServiceRegistration youtubeSourceServReg = null;
+
+ private static ReplacementService youtubeSource = null;
+
+ private static ResourceManagementService resourceService;
+
+ public void start(BundleContext context) throws Exception
+ {
+
+ bundleContext = context;
+
+ 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].");
+
+ }
+
+ public static BundleContext getBundleContext()
+ {
+ return bundleContext;
+ }
+
+ public void stop(BundleContext context) throws Exception
+ {
+
+ youtubeSourceServReg.unregister();
+ logger.info("Youtube source implementation [STOPPED].");
+
+ }
+
+ public static ResourceManagementService getResources()
+ {
+ if (resourceService == null)
+ {
+ ServiceReference serviceReference =
+ bundleContext
+ .getServiceReference(ResourceManagementService.class
+ .getName());
+
+ if (serviceReference == null)
+ return null;
+
+ resourceService =
+ (ResourceManagementService) bundleContext
+ .getService(serviceReference);
+ }
+
+ return resourceService;
+ }
+
+}

Added: branches/gsoc10/previews/src/net/java/sip/communicator/impl/replacement/youtube/youtube.source.manifest.mf
Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/branches/gsoc10/previews/src/net/java/sip/communicator/impl/replacement/youtube/youtube.source.manifest.mf?view=auto&rev=7237

--- (empty file)
+++ branches/gsoc10/previews/src/net/java/sip/communicator/impl/replacement/youtube/youtube.source.manifest.mf 2010-06-12 14:14:41+0000
@@ -0,0 +1,18 @@
+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.version,
+ org.xml.sax.helpers,
+ org.xml.sax,
+ javax.xml.parsers,
+ javax.activation,
+ net.java.sip.communicator.service.replacement,

Added: branches/gsoc10/previews/src/net/java/sip/communicator/service/replacement/ReplacementService.java
Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/branches/gsoc10/previews/src/net/java/sip/communicator/service/replacement/ReplacementService.java?view=auto&rev=7237

--- (empty file)
+++ branches/gsoc10/previews/src/net/java/sip/communicator/service/replacement/ReplacementService.java 2010-06-12 14:14:41+0000
@@ -0,0 +1,24 @@
+package net.java.sip.communicator.service.replacement;
+
+/**
+ * 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
+{
+ public final String SOURCE_NAME = "SOURCE";
+
+ /**
+ * 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);
+
+}

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@sip-communicator.dev.java.net
For additional commands, e-mail: commits-help@sip-communicator.dev.java.net

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@sip-communicator.dev.java.net
For additional commands, e-mail: dev-help@sip-communicator.dev.java.net


#2

Hi Yana,

You have to set the "net.java.sip.communicator.impl.gui.replacement.isEnabled"
to true manually in the sip-communicator.properties file for the
replacements to be processed. This was in accordance to what Emil had
suggested earlier.

In the current version, I've also included the smiley replacements to use
this service. So even the smilies would require this property set. I plan to
make it more flexible in the future.

Thanks,
Purvesh

···

On Mon, Jun 14, 2010 at 4:59 PM, Yana Stamcheva <yana@sip-communicator.org>wrote:

Hi Purvesh,

I've checked out your branch. I'm quite impressed by the amount of work you
have done in the last few weeks. Bravo!

However when I tried to send a youtube link, nothing happened, it wasn't
replaced. Is this supposed to work already? If yes, do you have in mind what
the reason could be that it's not working for me?

Cheers,
Yana

On Jun 12, 2010, at 4:14 PM, jimpu2@dev.java.net wrote:

> Author: jimpu2
> Date: 2010-06-12 14:14:41+0000
> New Revision: 7237
>
> Added:
> branches/gsoc10/previews/.project_old
> branches/gsoc10/previews/lib/installer-exclude/gdata-base-1.0.jar
(contents, props changed)
> branches/gsoc10/previews/lib/installer-exclude/gdata-client-1.0.jar
(contents, props changed)
>
branches/gsoc10/previews/lib/installer-exclude/gdata-client-meta-1.0.jar
(contents, props changed)
> branches/gsoc10/previews/lib/installer-exclude/gdata-core-1.0.jar
(contents, props changed)
> branches/gsoc10/previews/lib/installer-exclude/gdata-media-1.0.jar
(contents, props changed)
> branches/gsoc10/previews/lib/installer-exclude/gdata-youtube-2.0.jar
(contents, props changed)
>
branches/gsoc10/previews/lib/installer-exclude/gdata-youtube-meta-2.0.jar
(contents, props changed)
> branches/gsoc10/previews/lib/installer-exclude/mail.jar (contents,
props changed)
>
branches/gsoc10/previews/src/net/java/sip/communicator/impl/replacement/
>
branches/gsoc10/previews/src/net/java/sip/communicator/impl/replacement/dailymotion/
>
branches/gsoc10/previews/src/net/java/sip/communicator/impl/replacement/dailymotion/DailymotionActivator.java
>
branches/gsoc10/previews/src/net/java/sip/communicator/impl/replacement/dailymotion/ReplacementServiceDailymotionImpl.java
>
branches/gsoc10/previews/src/net/java/sip/communicator/impl/replacement/dailymotion/dailymotion.source.manifest.mf
>
branches/gsoc10/previews/src/net/java/sip/communicator/impl/replacement/smiley/
>
branches/gsoc10/previews/src/net/java/sip/communicator/impl/replacement/smiley/ReplacementServiceSmileyImpl.java
>
branches/gsoc10/previews/src/net/java/sip/communicator/impl/replacement/smiley/SmileyActivator.java
>
branches/gsoc10/previews/src/net/java/sip/communicator/impl/replacement/smiley/smiley.source.manifest.mf
>
branches/gsoc10/previews/src/net/java/sip/communicator/impl/replacement/vimeo/
>
branches/gsoc10/previews/src/net/java/sip/communicator/impl/replacement/vimeo/ReplacementServiceVimeoImpl.java
>
branches/gsoc10/previews/src/net/java/sip/communicator/impl/replacement/vimeo/VimeoActivator.java
>
branches/gsoc10/previews/src/net/java/sip/communicator/impl/replacement/vimeo/vimeo.source.manifest.mf
>
branches/gsoc10/previews/src/net/java/sip/communicator/impl/replacement/youtube/
>
branches/gsoc10/previews/src/net/java/sip/communicator/impl/replacement/youtube/ReplacementServiceYoutubeImpl.java
>
branches/gsoc10/previews/src/net/java/sip/communicator/impl/replacement/youtube/YoutubeActivator.java
>
branches/gsoc10/previews/src/net/java/sip/communicator/impl/replacement/youtube/youtube.source.manifest.mf
>
branches/gsoc10/previews/src/net/java/sip/communicator/service/replacement/
>
branches/gsoc10/previews/src/net/java/sip/communicator/service/replacement/ReplacementService.java
> Modified:
> branches/gsoc10/previews/build.xml
> branches/gsoc10/previews/lib/felix.client.run.properties
>
branches/gsoc10/previews/src/net/java/sip/communicator/impl/gui/GuiActivator.java
>
branches/gsoc10/previews/src/net/java/sip/communicator/impl/gui/main/chat/ChatConversationPanel.java
>
branches/gsoc10/previews/src/net/java/sip/communicator/impl/gui/swing.ui.manifest.mf
>
branches/gsoc10/previews/src/net/java/sip/communicator/impl/gui/utils/Smiley.java
>
> Log:
> Replacement Service
>
> Added: branches/gsoc10/previews/.project_old
> Url:
https://sip-communicator.dev.java.net/source/browse/sip-communicator/branches/gsoc10/previews/.project_old?view=auto&rev=7237
>

> --- (empty file)
> +++ branches/gsoc10/previews/.project_old 2010-06-12 14:14:41+0000
> @@ -0,0 +1,11 @@
> +<?xml version="1.0" encoding="UTF-8"?>
> +<projectDescription>
> + <name>sip-comm-new</name>
> + <comment></comment>
> + <projects>
> + </projects>
> + <buildSpec>
> + </buildSpec>
> + <natures>
> + </natures>
> +</projectDescription>
>
> Modified: branches/gsoc10/previews/build.xml
> Url:
https://sip-communicator.dev.java.net/source/browse/sip-communicator/branches/gsoc10/previews/build.xml?view=diff&rev=7237&p1=branches/gsoc10/previews/build.xml&p2=branches/gsoc10/previews/build.xml&r1=7236&r2=7237
>

> --- branches/gsoc10/previews/build.xml (original)
> +++ branches/gsoc10/previews/build.xml 2010-06-12 14:14:41+0000
> @@ -911,7 +911,8 @@
> bundle-filehistory,bundle-metahistory,bundle-metahistory-slick,
> bundle-plugin-facebookaccregwizz,
>
bundle-bouncycastle,bundle-plugin-otr,bundle-plugin-iptelaccregwizz,
> - bundle-contactsource,bundle-plugin-reconnect"/>
> + bundle-contactsource,bundle-plugin-reconnect,bundle-youtube,
> + bundle-dailymotion,bundle-smiley,bundle-vimeo"/>
>
> <!--BUNDLE-SC-LAUNCHER-->
> <target name="bundle-sc-launcher">
> @@ -1522,7 +1523,7 @@
> prefix="net/java/sip/communicator/impl/gui"/>
> <zipfileset src="lib/installer-exclude/jna.jar" prefix=""/>
> <zipfileset src="lib/installer-exclude/transparency.jar"
prefix=""/>
> - <zipfileset src="lib/installer-exclude/swing-worker-1.2.jar"
prefix=""/>
> + <zipfileset src="lib/installer-exclude/swing-worker-1.2.jar"
prefix=""/>
> </jar>
> </target>
>
> @@ -2325,4 +2326,61 @@
>
prefix="net/java/sip/communicator/plugin/reconnectplugin"/>
> </jar>
> </target>
> +
> + <!-- BUNDLE-YOUTUBE -->
> + <target name="bundle-youtube">
> + <jar compress="false"
destfile="${bundles.dest}/replacement-youtube.jar"
> +
manifest="${src}/net/java/sip/communicator/impl/replacement/youtube/youtube.source.manifest.mf">
> + <zipfileset
dir="${dest}/net/java/sip/communicator/impl/replacement/youtube"
> +
prefix="net/java/sip/communicator/impl/replacement/youtube"/>
> + <zipfileset
dir="${dest}/net/java/sip/communicator/service/replacement"
> + prefix="net/java/sip/communicator/service/replacement"/>
> + <zipfileset src="${lib.noinst}/gdata-base-1.0.jar"
prefix=""/>
> + <zipfileset
src="${lib.noinst}/gdata-client-1.0.jar" prefix=""/>
> + <zipfileset
src="${lib.noinst}/gdata-client-meta-1.0.jar" prefix=""/>
> + <zipfileset src="${lib.noinst}/gdata-core-1.0.jar"
prefix=""/>
> + <zipfileset src="${lib.noinst}/gdata-media-1.0.jar"
prefix=""/>
> + <zipfileset
src="${lib.noinst}/gdata-youtube-2.0.jar" prefix=""/>
> + <zipfileset
src="${lib.noinst}/gdata-youtube-meta-2.0.jar" prefix=""/>
> + <zipfileset src="${lib.noinst}/mail.jar"
prefix=""/>
> + </jar>
> + </target>
> +
> + <!-- BUNDLE-DAILYMOTION -->
> + <target name="bundle-dailymotion">
> + <jar compress="false"
destfile="${bundles.dest}/replacement-dailymotion.jar"
> +
manifest="${src}/net/java/sip/communicator/impl/replacement/dailymotion/dailymotion.source.manifest.mf">
> + <zipfileset
dir="${dest}/net/java/sip/communicator/impl/replacement/dailymotion"
> +
prefix="net/java/sip/communicator/impl/replacement/dailymotion"/>
> + <zipfileset
dir="${dest}/net/java/sip/communicator/service/replacement"
> +
prefix="net/java/sip/communicator/service/replacement"/>
> + </jar>
> + </target>
> +
> + <!-- BUNDLE-SMILEY -->
> + <target name="bundle-smiley">
> + <jar compress="false"
destfile="${bundles.dest}/replacement-smiley.jar"
> +
manifest="${src}/net/java/sip/communicator/impl/replacement/smiley/smiley.source.manifest.mf">
> + <zipfileset
dir="${dest}/net/java/sip/communicator/impl/replacement/smiley"
> +
prefix="net/java/sip/communicator/impl/replacement/smiley"/>
> + <zipfileset
dir="${dest}/net/java/sip/communicator/service/replacement"
> +
prefix="net/java/sip/communicator/service/replacement"/>
> + <zipfileset
dir="${dest}/net/java/sip/communicator/impl/gui/utils"
> +
prefix="net/java/sip/communicator/impl/gui/utils"/>
> + <zipfileset
dir="${dest}/net/java/sip/communicator/impl/gui"
> +
prefix="net/java/sip/communicator/impl/gui"/>
> + </jar>
> + </target>
> +
> + <!-- BUNDLE-VIMEO -->
> + <target name="bundle-vimeo">
> + <jar compress="false"
destfile="${bundles.dest}/replacement-vimeo.jar"
> +
manifest="${src}/net/java/sip/communicator/impl/replacement/vimeo/vimeo.source.manifest.mf">
> + <zipfileset
dir="${dest}/net/java/sip/communicator/impl/replacement/vimeo"
> +
prefix="net/java/sip/communicator/impl/replacement/vimeo"/>
> + <zipfileset
dir="${dest}/net/java/sip/communicator/service/replacement"
> +
prefix="net/java/sip/communicator/service/replacement"/>
> + <zipfileset src="${lib.noinst}/json-20090723.jar"
prefix=""/>
> + </jar>
> + </target>
> </project>
>
> Modified: branches/gsoc10/previews/lib/felix.client.run.properties
> Url:
https://sip-communicator.dev.java.net/source/browse/sip-communicator/branches/gsoc10/previews/lib/felix.client.run.properties?view=diff&rev=7237&p1=branches/gsoc10/previews/lib/felix.client.run.properties&p2=branches/gsoc10/previews/lib/felix.client.run.properties&r1=7236&r2=7237
>

> --- branches/gsoc10/previews/lib/felix.client.run.properties (original)
> +++ branches/gsoc10/previews/lib/felix.client.run.properties 2010-06-12
14:14:41+0000
> @@ -130,7 +130,11 @@
> reference:file:sc-bundles/generalconfig.jar \
> reference:file:sc-bundles/dictaccregwizz.jar \
> reference:file:sc-bundles/otr.jar \
> - reference:file:sc-bundles/facebookaccregwizz.jar
> + reference:file:sc-bundles/facebookaccregwizz.jar \
> + reference:file:sc-bundles/replacement-youtube.jar \
> + reference:file:sc-bundles/replacement-dailymotion.jar \
> + reference:file:sc-bundles/replacement-smiley.jar \
> + reference:file:sc-bundles/replacement-vimeo.jar
>
> #level 68 is for profiler, don't use it or change the build.xml file
accordingly
>
>
> Added: branches/gsoc10/previews/lib/installer-exclude/gdata-base-1.0.jar
> Url:
https://sip-communicator.dev.java.net/source/browse/sip-communicator/branches/gsoc10/previews/lib/installer-exclude/gdata-base-1.0.jar?view=auto&rev=7237
>

> Binary file. No diff available.
>
> Added:
branches/gsoc10/previews/lib/installer-exclude/gdata-client-1.0.jar
> Url:
https://sip-communicator.dev.java.net/source/browse/sip-communicator/branches/gsoc10/previews/lib/installer-exclude/gdata-client-1.0.jar?view=auto&rev=7237
>

> Binary file. No diff available.
>
> Added:
branches/gsoc10/previews/lib/installer-exclude/gdata-client-meta-1.0.jar
> Url:
https://sip-communicator.dev.java.net/source/browse/sip-communicator/branches/gsoc10/previews/lib/installer-exclude/gdata-client-meta-1.0.jar?view=auto&rev=7237
>

> Binary file. No diff available.
>
> Added: branches/gsoc10/previews/lib/installer-exclude/gdata-core-1.0.jar
> Url:
https://sip-communicator.dev.java.net/source/browse/sip-communicator/branches/gsoc10/previews/lib/installer-exclude/gdata-core-1.0.jar?view=auto&rev=7237
>

> Binary file. No diff available.
>
> Added: branches/gsoc10/previews/lib/installer-exclude/gdata-media-1.0.jar
> Url:
https://sip-communicator.dev.java.net/source/browse/sip-communicator/branches/gsoc10/previews/lib/installer-exclude/gdata-media-1.0.jar?view=auto&rev=7237
>

> Binary file. No diff available.
>
> Added:
branches/gsoc10/previews/lib/installer-exclude/gdata-youtube-2.0.jar
> Url:
https://sip-communicator.dev.java.net/source/browse/sip-communicator/branches/gsoc10/previews/lib/installer-exclude/gdata-youtube-2.0.jar?view=auto&rev=7237
>

> Binary file. No diff available.
>
> Added:
branches/gsoc10/previews/lib/installer-exclude/gdata-youtube-meta-2.0.jar
> Url:
https://sip-communicator.dev.java.net/source/browse/sip-communicator/branches/gsoc10/previews/lib/installer-exclude/gdata-youtube-meta-2.0.jar?view=auto&rev=7237
>

> Binary file. No diff available.
>
> Added: branches/gsoc10/previews/lib/installer-exclude/mail.jar
> Url:
https://sip-communicator.dev.java.net/source/browse/sip-communicator/branches/gsoc10/previews/lib/installer-exclude/mail.jar?view=auto&rev=7237
>

> Binary file. No diff available.
>
> Modified:
branches/gsoc10/previews/src/net/java/sip/communicator/impl/gui/GuiActivator.java
> Url:
https://sip-communicator.dev.java.net/source/browse/sip-communicator/branches/gsoc10/previews/src/net/java/sip/communicator/impl/gui/GuiActivator.java?view=diff&rev=7237&p1=branches/gsoc10/previews/src/net/java/sip/communicator/impl/gui/GuiActivator.java&p2=branches/gsoc10/previews/src/net/java/sip/communicator/impl/gui/GuiActivator.java&r1=7236&r2=7237
>

> ---
branches/gsoc10/previews/src/net/java/sip/communicator/impl/gui/GuiActivator.java
(original)
> +++
branches/gsoc10/previews/src/net/java/sip/communicator/impl/gui/GuiActivator.java
2010-06-12 14:14:41+0000
> @@ -1,8 +1,7 @@
> /*
> * SIP Communicator, the OpenSource Java VoIP and Instant Messaging
client.
> - *
> - * Distributable under LGPL license.
> - * See terms of license at gnu.org.
> + *
> + * Distributable under LGPL license. See terms of license at gnu.org.
> */
> package net.java.sip.communicator.impl.gui;
>
> @@ -25,6 +24,7 @@
> import net.java.sip.communicator.service.neomedia.*;
> import net.java.sip.communicator.service.notification.*;
> import net.java.sip.communicator.service.protocol.*;
> +import net.java.sip.communicator.service.replacement.ReplacementService;
> import net.java.sip.communicator.service.resources.*;
> import net.java.sip.communicator.service.shutdown.*;
> import net.java.sip.communicator.service.systray.*;
> @@ -34,10 +34,11 @@
>
> /**
> * The GUI Activator class.
> - *
> + *
> * @author Yana Stamcheva
> */
> -public class GuiActivator implements BundleActivator
> +public class GuiActivator
> + implements BundleActivator
> {
> private static final Logger logger =
Logger.getLogger(GuiActivator.class);
>
> @@ -58,7 +59,8 @@
> private static BrowserLauncherService browserLauncherService;
>
> private static NotificationService notificationService;
> - private NotificationServiceListener
notificationServiceListener;
> +
> + private NotificationServiceListener notificationServiceListener;
>
> private static SystrayService systrayService;
>
> @@ -74,13 +76,16 @@
>
> private static List<ContactSourceService> contactSources;
>
> - private static final Map<Object, ProtocolProviderFactory>
> - providerFactoriesMap = new Hashtable<Object,
>();
> + private static final Map<Object, ProtocolProviderFactory>
providerFactoriesMap =
> + new Hashtable<Object, ProtocolProviderFactory>();
> +
> + private static final Map<Object, ReplacementService>
replacementSourcesMap =
> + new Hashtable<Object, ReplacementService>();
>
> /**
> * Indicates if this bundle has been started.
> */
> - public static boolean isStarted = false;
> + public static boolean isStarted = false;
>
> /**
> * The contact list object.
> @@ -89,12 +94,11 @@
>
> /**
> * Called when this bundle is started.
> - *
> + *
> * @param bContext The execution context of the bundle being started.
> * @throws Exception if the bundle is not correctly started
> */
> - public void start(BundleContext bContext)
> - throws Exception
> + public void start(BundleContext bContext) throws Exception
> {
> isStarted = true;
> GuiActivator.bundleContext = bContext;
> @@ -113,21 +117,17 @@
> if (logger.isInfoEnabled())
> logger.info("UI Service...[ STARTED ]");
>
> - bundleContext.registerService(UIService.class.getName(),
> - uiService,
> - null);
> + bundleContext.registerService(UIService.class.getName(),
uiService,
> + null);
> if (logger.isInfoEnabled())
> logger.info("UI Service ...[REGISTERED]");
>
> // UIServiceImpl also implements ShutdownService.
>
bundleContext.registerService(ShutdownService.class.getName(),
> - (ShutdownService) uiService,
> - null);
> + (ShutdownService) uiService, null);
>
> - bundleContext.registerService(
> - CertificateVerificationService.class.getName(),
> - new CertificateVerificationServiceImpl(),
> - null);
> +
bundleContext.registerService(CertificateVerificationService.class
> + .getName(), new CertificateVerificationServiceImpl(),
null);
>
> uiService.loadApplicationGui();
>
> @@ -138,8 +138,8 @@
> logger.logExit();
> }
>
> - GuiActivator.getConfigurationService()
> - .addPropertyChangeListener(uiService);
> +
GuiActivator.getConfigurationService().addPropertyChangeListener(
> + uiService);
>
> bundleContext.addServiceListener(uiService);
> }
> @@ -147,12 +147,12 @@
> /**
> * Called when this bundle is stopped so the Framework can perform
the
> * bundle-specific activities necessary to stop the bundle.
> - *
> + *
> * @param bContext The execution context of the bundle being stopped.
> - * @throws Exception If this method throws an exception, the bundle
is
> - * still marked as stopped, and the Framework will remove the
bundle's
> - * listeners, unregister all services registered by the bundle,
and
> - * release all services used by the bundle.
> + * @throws Exception If this method throws an exception, the bundle
is still
> + * marked as stopped, and the Framework will remove the
bundle's
> + * listeners, unregister all services registered by the
bundle,
> + * and release all services used by the bundle.
> */
> public void stop(BundleContext bContext) throws Exception
> {
> @@ -160,8 +160,8 @@
> logger.info("UI Service ...[STOPPED]");
> isStarted = false;
>
> - GuiActivator.getConfigurationService()
> - .removePropertyChangeListener(uiService);
> +
GuiActivator.getConfigurationService().removePropertyChangeListener(
> + uiService);
>
> bContext.removeServiceListener(uiService);
> bContext.removeServiceListener(notificationServiceListener);
> @@ -174,8 +174,7 @@
> * @return all <tt>ProtocolProviderFactory</tt>s obtained from the
bundle
> * context
> */
> - public static Map<Object, ProtocolProviderFactory>
> - getProtocolProviderFactories()
> + public static Map<Object, ProtocolProviderFactory>
getProtocolProviderFactories()
> {
>
> ServiceReference[] serRefs = null;
> @@ -192,45 +191,46 @@
> logger.error("LoginManager : " + e);
> }
>
> - if (serRefs != null)
> + if (serRefs != null)
> {
> - for (int i = 0; i < serRefs.length; i++)
> + for (int i = 0; i < serRefs.length; i++)
> {
>
> - ProtocolProviderFactory providerFactory
> - = (ProtocolProviderFactory) bundleContext
> + ProtocolProviderFactory providerFactory =
> + (ProtocolProviderFactory) bundleContext
> .getService(serRefs[i]);
>
> providerFactoriesMap.put(serRefs[i]
> - .getProperty(ProtocolProviderFactory.PROTOCOL),
> - providerFactory);
> + .getProperty(ProtocolProviderFactory.PROTOCOL),
> + providerFactory);
> }
> }
> return providerFactoriesMap;
> }
>
> /**
> - * Returns a <tt>ProtocolProviderFactory</tt> for a given protocol
> - * provider.
> + * Returns a <tt>ProtocolProviderFactory</tt> for a given protocol
provider.
> + *
> * @param protocolProvider the <tt>ProtocolProviderService</tt>,
which
> - * factory we're looking for
> - * @return a <tt>ProtocolProviderFactory</tt> for a given protocol
> - * provider
> + * factory we're looking for
> + * @return a <tt>ProtocolProviderFactory</tt> for a given protocol
provider
> */
> public static ProtocolProviderFactory getProtocolProviderFactory(
> - ProtocolProviderService protocolProvider)
> + ProtocolProviderService protocolProvider)
> {
> - String osgiFilter = "("
> - + ProtocolProviderFactory.PROTOCOL
> - + "="+protocolProvider.getProtocolName()+")";
> + String osgiFilter =
> + "(" + ProtocolProviderFactory.PROTOCOL + "="
> + + protocolProvider.getProtocolName() + ")";
>
> ProtocolProviderFactory protocolProviderFactory = null;
> try
> {
> - ServiceReference[] serRefs =
GuiActivator.bundleContext.getServiceReferences(
> - ProtocolProviderFactory.class.getName(), osgiFilter);
> - protocolProviderFactory = (ProtocolProviderFactory)
GuiActivator
> - .bundleContext.getService(serRefs[0]);
> + ServiceReference[] serRefs =
> + GuiActivator.bundleContext.getServiceReferences(
> + ProtocolProviderFactory.class.getName(),
osgiFilter);
> + protocolProviderFactory =
> + (ProtocolProviderFactory) GuiActivator.bundleContext
> + .getService(serRefs[0]);
> }
> catch (InvalidSyntaxException ex)
> {
> @@ -241,41 +241,88 @@
> }
>
> /**
> + * Returns all <tt>ReplacementService</tt>s obtained from the bundle
> + * context.
> + *
> + * @return all <tt>ReplacementService</tt> implementation obtained
from the
> + * bundle context
> + */
> + public static Map<Object, ReplacementService>
getReplacementSources()
> + {
> +
> + ServiceReference[] serRefs = null;
> + try
> + {
> + // get all registered sources
> + serRefs =
> +
bundleContext.getServiceReferences(ReplacementService.class
> + .getName(), null);
> +
> + }
> + catch (InvalidSyntaxException e)
> + {
> + logger.error("Error : " + e);
> + }
> +
> + if (serRefs != null)
> + {
> +
> + for (int i = 0; i < serRefs.length; i++)
> + {
> +
> + ReplacementService replacementSources =
> + (ReplacementService)
bundleContext.getService(serRefs[i]);
> +
> + replacementSourcesMap.put(serRefs[i]
> + .getProperty(ReplacementService.SOURCE_NAME),
> + replacementSources);
> +
> + //
replacementSourcesMap.put("YOUTUBE",replacementSources);
> + }
> + }
> + return replacementSourcesMap;
> + }
> +
> + /**
> * Returns the <tt>ConfigurationService</tt> obtained from the bundle
> * context.
> + *
> * @return the <tt>ConfigurationService</tt> obtained from the bundle
> - * context
> + * context
> */
> public static ConfigurationService getConfigurationService()
> {
> - if(configService == null)
> + if (configService == null)
> {
> - ServiceReference configReference = bundleContext
> -
.getServiceReference(ConfigurationService.class.getName());
> -
> - configService = (ConfigurationService) bundleContext
> - .getService(configReference);
> + ServiceReference configReference =
> +
bundleContext.getServiceReference(ConfigurationService.class
> + .getName());
> +
> + configService =
> + (ConfigurationService) bundleContext
> + .getService(configReference);
> }
>
> return configService;
> }
>
> /**
> - * Returns the <tt>MetaHistoryService</tt> obtained from the bundle
> - * context.
> - * @return the <tt>MetaHistoryService</tt> obtained from the bundle
> - * context
> + * Returns the <tt>MetaHistoryService</tt> obtained from the bundle
context.
> + *
> + * @return the <tt>MetaHistoryService</tt> obtained from the bundle
context
> */
> public static MetaHistoryService getMetaHistoryService()
> {
> if (metaHistoryService == null)
> {
> - ServiceReference serviceReference = bundleContext
> -
.getServiceReference(MetaHistoryService.class.getName());
> + ServiceReference serviceReference =
> +
bundleContext.getServiceReference(MetaHistoryService.class
> + .getName());
>
> if (serviceReference != null)
> - metaHistoryService = (MetaHistoryService) bundleContext
> - .getService(serviceReference);
> + metaHistoryService =
> + (MetaHistoryService) bundleContext
> + .getService(serviceReference);
> }
>
> return metaHistoryService;
> @@ -284,17 +331,20 @@
> /**
> * Returns the <tt>MetaContactListService</tt> obtained from the
bundle
> * context.
> + *
> * @return the <tt>MetaContactListService</tt> obtained from the
bundle
> - * context
> + * context
> */
> public static MetaContactListService getContactListService()
> {
> if (metaCListService == null)
> {
> - ServiceReference clistReference = bundleContext
> -
.getServiceReference(MetaContactListService.class.getName());
> + ServiceReference clistReference =
> +
bundleContext.getServiceReference(MetaContactListService.class
> + .getName());
>
> - metaCListService = (MetaContactListService) bundleContext
> + metaCListService =
> + (MetaContactListService) bundleContext
> .getService(clistReference);
> }
>
> @@ -302,20 +352,20 @@
> }
>
> /**
> - * Returns the <tt>CallHistoryService</tt> obtained from the bundle
> - * context.
> - * @return the <tt>CallHistoryService</tt> obtained from the bundle
> - * context
> + * Returns the <tt>CallHistoryService</tt> obtained from the bundle
context.
> + *
> + * @return the <tt>CallHistoryService</tt> obtained from the bundle
context
> */
> public static CallHistoryService getCallHistoryService()
> {
> if (callHistoryService == null)
> {
> - ServiceReference serviceReference = bundleContext
> -
.getServiceReference(CallHistoryService.class.getName());
> + ServiceReference serviceReference =
> +
bundleContext.getServiceReference(CallHistoryService.class
> + .getName());
>
> - callHistoryService = (CallHistoryService) bundleContext
> - .getService(serviceReference);
> + callHistoryService =
> + (CallHistoryService)
bundleContext.getService(serviceReference);
> }
>
> return callHistoryService;
> @@ -324,21 +374,22 @@
> /**
> * Returns the <tt>AudioNotifierService</tt> obtained from the bundle
> * context.
> + *
> * @return the <tt>AudioNotifierService</tt> obtained from the bundle
> - * context
> + * context
> */
> public static AudioNotifierService getAudioNotifier()
> {
> if (audioNotifierService == null)
> {
> - ServiceReference serviceReference
> - = bundleContext
> -
.getServiceReference(AudioNotifierService.class.getName());
> + ServiceReference serviceReference =
> +
bundleContext.getServiceReference(AudioNotifierService.class
> + .getName());
>
> if (serviceReference != null)
> - audioNotifierService
> - = (AudioNotifierService)
> - bundleContext.getService(serviceReference);
> + audioNotifierService =
> + (AudioNotifierService) bundleContext
> + .getService(serviceReference);
> }
> return audioNotifierService;
> }
> @@ -346,18 +397,21 @@
> /**
> * Returns the <tt>BrowserLauncherService</tt> obtained from the
bundle
> * context.
> + *
> * @return the <tt>BrowserLauncherService</tt> obtained from the
bundle
> - * context
> + * context
> */
> public static BrowserLauncherService getBrowserLauncher()
> {
> if (browserLauncherService == null)
> {
> - ServiceReference serviceReference = bundleContext
> -
.getServiceReference(BrowserLauncherService.class.getName());
> + ServiceReference serviceReference =
> +
bundleContext.getServiceReference(BrowserLauncherService.class
> + .getName());
>
> - browserLauncherService = (BrowserLauncherService)
bundleContext
> - .getService(serviceReference);
> + browserLauncherService =
> + (BrowserLauncherService) bundleContext
> + .getService(serviceReference);
> }
>
> return browserLauncherService;
> @@ -365,6 +419,7 @@
>
> /**
> * Returns the current implementation of the <tt>UIService</tt>.
> + *
> * @return the current implementation of the <tt>UIService</tt>
> */
> public static UIServiceImpl getUIService()
> @@ -374,21 +429,22 @@
>
> /**
> * Returns the <tt>SystrayService</tt> obtained from the bundle
context.
> - *
> + *
> * @return the <tt>SystrayService</tt> obtained from the bundle
context
> */
> public static SystrayService getSystrayService()
> {
> if (systrayService == null)
> {
> - ServiceReference serviceReference = bundleContext
> - .getServiceReference(SystrayService.class.getName());
> + ServiceReference serviceReference =
> + bundleContext.getServiceReference(SystrayService.class
> + .getName());
>
> - if(serviceReference == null)
> + if (serviceReference == null)
> return null;
>
> - systrayService = (SystrayService) bundleContext
> - .getService(serviceReference);
> + systrayService =
> + (SystrayService)
bundleContext.getService(serviceReference);
> }
>
> return systrayService;
> @@ -396,18 +452,19 @@
>
> /**
> * Returns the <tt>KeybindingsService</tt> obtained from the bundle
context.
> - *
> + *
> * @return the <tt>KeybindingsService</tt> obtained from the bundle
context
> */
> public static KeybindingsService getKeybindingsService()
> {
> if (keybindingsService == null)
> {
> - ServiceReference serviceReference = bundleContext
> -
.getServiceReference(KeybindingsService.class.getName());
> + ServiceReference serviceReference =
> +
bundleContext.getServiceReference(KeybindingsService.class
> + .getName());
>
> - keybindingsService = (KeybindingsService) bundleContext
> - .getService(serviceReference);
> + keybindingsService =
> + (KeybindingsService)
bundleContext.getService(serviceReference);
> }
>
> return keybindingsService;
> @@ -416,41 +473,47 @@
> /**
> * Returns the <tt>ResourceManagementService</tt>, through which we
will
> * access all resources.
> - *
> + *
> * @return the <tt>ResourceManagementService</tt>, through which we
will
> - * access all resources.
> + * access all resources.
> */
> public static ResourceManagementService getResources()
> {
> if (resourcesService == null)
> {
> - ServiceReference serviceReference = bundleContext
> -
.getServiceReference(ResourceManagementService.class.getName());
> + ServiceReference serviceReference =
> + bundleContext
> + .getServiceReference(ResourceManagementService.class
> + .getName());
>
> - if(serviceReference == null)
> + if (serviceReference == null)
> return null;
>
> - resourcesService = (ResourceManagementService) bundleContext
> - .getService(serviceReference);
> + resourcesService =
> + (ResourceManagementService) bundleContext
> + .getService(serviceReference);
> }
>
> return resourcesService;
> }
>
> /**
> - * Returns the <tt>NotificationService</tt> obtained from the bundle
context.
> - *
> + * Returns the <tt>NotificationService</tt> obtained from the bundle
> + * context.
> + *
> * @return the <tt>NotificationService</tt> obtained from the bundle
context
> */
> public static NotificationService getNotificationService()
> {
> if (notificationService == null)
> {
> - ServiceReference serviceReference = bundleContext
> -
.getServiceReference(NotificationService.class.getName());
> + ServiceReference serviceReference =
> +
bundleContext.getServiceReference(NotificationService.class
> + .getName());
>
> - notificationService = (NotificationService) bundleContext
> - .getService(serviceReference);
> + notificationService =
> + (NotificationService) bundleContext
> + .getService(serviceReference);
> }
>
> return notificationService;
> @@ -458,18 +521,19 @@
>
> /**
> * Returns the <tt>FileAccessService</tt> obtained from the bundle
context.
> - *
> + *
> * @return the <tt>FileAccessService</tt> obtained from the bundle
context
> */
> public static FileAccessService getFileAccessService()
> {
> if (fileAccessService == null)
> {
> - ServiceReference serviceReference = bundleContext
> - .getServiceReference(FileAccessService.class.getName());
> + ServiceReference serviceReference =
> +
bundleContext.getServiceReference(FileAccessService.class
> + .getName());
>
> - fileAccessService = (FileAccessService) bundleContext
> - .getService(serviceReference);
> + fileAccessService =
> + (FileAccessService)
bundleContext.getService(serviceReference);
> }
>
> return fileAccessService;
> @@ -477,69 +541,72 @@
>
> /**
> * Returns the <tt>DesktopService</tt> obtained from the bundle
context.
> - *
> + *
> * @return the <tt>DesktopService</tt> obtained from the bundle
context
> */
> public static DesktopService getDesktopService()
> {
> if (desktopService == null)
> {
> - ServiceReference serviceReference = bundleContext
> - .getServiceReference(DesktopService.class.getName());
> + ServiceReference serviceReference =
> + bundleContext.getServiceReference(DesktopService.class
> + .getName());
>
> - desktopService = (DesktopService) bundleContext
> - .getService(serviceReference);
> + desktopService =
> + (DesktopService)
bundleContext.getService(serviceReference);
> }
>
> return desktopService;
> }
>
> /**
> - * Returns an instance of the <tt>MediaService</tt> obtained from
the
> - * bundle context.
> - * @return an instance of the <tt>MediaService</tt> obtained from
the
> - * bundle context
> + * Returns an instance of the <tt>MediaService</tt> obtained from
the bundle
> + * context.
> + *
> + * @return an instance of the <tt>MediaService</tt> obtained from
the bundle
> + * context
> */
> public static MediaService getMediaService()
> {
> if (mediaService == null)
> {
> - ServiceReference serviceReference = bundleContext
> - .getServiceReference(MediaService.class.getName());
> + ServiceReference serviceReference =
> +
bundleContext.getServiceReference(MediaService.class.getName());
>
> - mediaService = (MediaService) bundleContext
> - .getService(serviceReference);
> + mediaService =
> + (MediaService)
bundleContext.getService(serviceReference);
> }
>
> return mediaService;
> }
>
> /**
> - * Implements the <tt>ServiceListener</tt>. Verifies whether the
> - * passed event concerns a <tt>NotificationService</tt> and if so
> - * initiates the user interface NotificationManager.
> + * Implements the <tt>ServiceListener</tt>. Verifies whether the
passed
> + * event concerns a <tt>NotificationService</tt> and if so initiates
the
> + * user interface NotificationManager.
> */
> - private static class NotificationServiceListener implements
ServiceListener
> + private static class NotificationServiceListener
> + implements ServiceListener
> {
> /**
> * Implements the <tt>ServiceListener</tt> method. Verifies
whether the
> * passed event concerns a <tt>NotificationService</tt> and if so
> * initiates the NotificationManager.
> - *
> + *
> * @param event The <tt>ServiceEvent</tt> object.
> */
> public void serviceChanged(ServiceEvent event)
> {
> // if the event is caused by a bundle being stopped, we don't
want
> // to know
> - if (event.getServiceReference().getBundle().getState()
> - == Bundle.STOPPING)
> + if (event.getServiceReference().getBundle().getState() ==
Bundle.STOPPING)
> {
> return;
> }
>
> - Object service = GuiActivator.bundleContext.getService(event
> - .getServiceReference());
> + Object service =
> + GuiActivator.bundleContext.getService(event
> + .getServiceReference());
>
> // we don't care if the source service is not a notification
service
> if (!(service instanceof NotificationService))
> @@ -556,6 +623,7 @@
>
> /**
> * Returns a list of all registered contact sources.
> + *
> * @return a list of all registered contact sources
> */
> public static List<ContactSourceService> getContactSources()
> @@ -570,21 +638,20 @@
> {
> // get all registered provider factories
> serRefs =
> - bundleContext.getServiceReferences(
> - ContactSourceService.class.getName(), null);
> +
bundleContext.getServiceReferences(ContactSourceService.class
> + .getName(), null);
> }
> catch (InvalidSyntaxException e)
> {
> logger.error("GuiActivator : " + e);
> }
>
> - if (serRefs != null)
> + if (serRefs != null)
> {
> for (int i = 0; i < serRefs.length; i++)
> {
> - ContactSourceService contactSource
> - = (ContactSourceService) bundleContext
> - .getService(serRefs[i]);
> + ContactSourceService contactSource =
> + (ContactSourceService)
bundleContext.getService(serRefs[i]);
>
> contactSources.add(contactSource);
> }
> @@ -595,6 +662,7 @@
> /**
> * Sets the <tt>contactList</tt> component currently used to show the
> * contact list.
> + *
> * @param list the contact list object to set
> */
> public static void setContactList(TreeContactList list)
> @@ -604,6 +672,7 @@
>
> /**
> * Returns the component used to show the contact list.
> + *
> * @return the component used to show the contact list
> */
> public static TreeContactList getContactList()
>
> Modified:
branches/gsoc10/previews/src/net/java/sip/communicator/impl/gui/main/chat/ChatConversationPanel.java
> Url:
https://sip-communicator.dev.java.net/source/browse/sip-communicator/branches/gsoc10/previews/src/net/java/sip/communicator/impl/gui/main/chat/ChatConversationPanel.java?view=diff&rev=7237&p1=branches/gsoc10/previews/src/net/java/sip/communicator/impl/gui/main/chat/ChatConversationPanel.java&p2=branches/gsoc10/previews/src/net/java/sip/communicator/impl/gui/main/chat/ChatConversationPanel.java&r1=7236&r2=7237
>

> ---
branches/gsoc10/previews/src/net/java/sip/communicator/impl/gui/main/chat/ChatConversationPanel.java
     (original)
> +++
branches/gsoc10/previews/src/net/java/sip/communicator/impl/gui/main/chat/ChatConversationPanel.java
     2010-06-12 14:14:41+0000
> @@ -1,8 +1,7 @@
> /*
> * SIP Communicator, the OpenSource Java VoIP and Instant Messaging
client.
> - *
> - * Distributable under LGPL license.
> - * See terms of license at gnu.org.
> + *
> + * Distributable under LGPL license. See terms of license at gnu.org.
> */
> package net.java.sip.communicator.impl.gui.main.chat;
>
> @@ -26,6 +25,9 @@
> import net.java.sip.communicator.service.gui.*;
> import net.java.sip.communicator.util.*;
> import net.java.sip.communicator.util.swing.*;
> +import net.java.sip.communicator.util.swing.SwingWorker;
> +
> +import net.java.sip.communicator.service.replacement.*;
>
> /**
> * The <tt>ChatConversationPanel</tt> is the panel, where all sent and
received
> @@ -33,18 +35,16 @@
> * is applied to the document to provide the look&feel. All smileys and
link
> * strings are processed and finally replaced by corresponding images and
HTML
> * links.
> - *
> + *
> * @author Yana Stamcheva
> * @author Lubomir Marinov
> */
> public class ChatConversationPanel
> extends SCScrollPane
> - implements HyperlinkListener,
> - MouseListener,
> - ClipboardOwner
> + implements HyperlinkListener, MouseListener, ClipboardOwner
> {
> - private static final Logger logger
> - = Logger.getLogger(ChatConversationPanel.class);
> + private static final Logger logger =
> + Logger.getLogger(ChatConversationPanel.class);
>
> /**
> * The closing tag of the <code>PLAINTEXT</code> HTML element.
> @@ -60,16 +60,14 @@
> * The regular expression (in the form of compiled <tt>Pattern</tt>)
which
> * matches URLs for the purposed of turning them into links.
> */
> - private static final Pattern URL_PATTERN
> - = Pattern.compile(
> - "("
> + private static final Pattern URL_PATTERN =
> + Pattern.compile("("
> +
"(\\bwww\\.[^\\s<>\"]+\\.[^\\s<>\"]+/*[?#]*(\\w+[&=;?]\\w+)*\\b)" // wwwURL
> - + "|"
> - + "(\\b\\w+://[^\\s<>\"]+/*[?#]*(\\w+[&=;?]\\w+)*\\b)" //
protocolURL
> + + "|" + "(\\b\\w+://[^\\s<>\"]+/*[?#]*(\\w+[&=;?]\\w+)*\\b)"
// protocolURL
> + ")");
>
> /**
> - * The compiled <tt>Pattern</tt> which matches {@link
#smileyStrings}.
> + * The compiled <tt>Pattern</tt> which matches {@link
#smileyStrings}.
> */
> private static Pattern smileyPattern;
>
> @@ -77,8 +75,8 @@
> * The <tt>List</tt> of smiley strings which are matched by
> * {@link #smileyPattern}.
> */
> - private static final java.util.List<String> smileyStrings
> - = new ArrayList<String>();
> + private static final java.util.List<String> smileyStrings =
> + new ArrayList<String>();
>
> private final JTextPane chatTextPane = new MyTextPane();
>
> @@ -106,6 +104,9 @@
>
> public static final String TEXT_CONTENT_TYPE = "text/plain";
>
> + private Map<Object, ReplacementService> listsources =
> + new HashMap<Object, ReplacementService>();
> +
> /**
> * The indicator which determines whether an automatic scroll to the
bottom
> * of {@link #chatTextPane} is to be performed.
> @@ -113,8 +114,8 @@
> private boolean scrollToBottomIsPending = false;
>
> /**
> - * The implementation of the routine which scrolls {@link
#chatTextPane} to its
> - * bottom.
> + * The implementation of the routine which scrolls {@link
#chatTextPane} to
> + * its bottom.
> */
> private final Runnable scrollToBottomRunnable = new Runnable()
> {
> @@ -132,7 +133,7 @@
>
> /**
> * Creates an instance of <tt>ChatConversationPanel</tt>.
> - *
> + *
> * @param chatContainer The parent
<tt>ChatConversationContainer</tt>.
> */
> public ChatConversationPanel(ChatConversationContainer chatContainer)
> @@ -153,53 +154,52 @@
> this.chatTextPane.setDocument(document);
> this.chatTextPane.setDragEnabled(true);
>
> - chatTextPane.putClientProperty(
> - JEditorPane.HONOR_DISPLAY_PROPERTIES, Boolean.TRUE);
> - Constants.loadSimpleStyle(
> - document.getStyleSheet(), chatTextPane.getFont());
> +
chatTextPane.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES,
> + Boolean.TRUE);
> + Constants.loadSimpleStyle(document.getStyleSheet(), chatTextPane
> + .getFont());
>
> this.chatTextPane.addHyperlinkListener(this);
> this.chatTextPane.addMouseListener(this);
> - this.chatTextPane.setCursor(
> - Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR));
> + this.chatTextPane.setCursor(Cursor
> + .getPredefinedCursor(Cursor.TEXT_CURSOR));
>
> this.setWheelScrollingEnabled(true);
>
> this.setViewportView(chatTextPane);
>
> - this.setHorizontalScrollBarPolicy(
> - JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
> + this
> +
.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
>
> ToolTipManager.sharedInstance().registerComponent(chatTextPane);
>
> - String copyLinkString
> - =
GuiActivator.getResources().getI18NString("service.gui.COPY_LINK");
> + String copyLinkString =
> +
GuiActivator.getResources().getI18NString("service.gui.COPY_LINK");
>
> copyLinkItem =
> - new JMenuItem(copyLinkString,
> - new
ImageIcon(ImageLoader.getImage(ImageLoader.COPY_ICON)));
> + new JMenuItem(copyLinkString, new ImageIcon(ImageLoader
> + .getImage(ImageLoader.COPY_ICON)));
>
> copyLinkItem.addActionListener(new ActionListener()
> {
> public void actionPerformed(ActionEvent e)
> {
> - StringSelection stringSelection = new StringSelection(
> - currentHref);
> - Clipboard clipboard = Toolkit.getDefaultToolkit()
> - .getSystemClipboard();
> + StringSelection stringSelection =
> + new StringSelection(currentHref);
> + Clipboard clipboard =
> + Toolkit.getDefaultToolkit().getSystemClipboard();
> clipboard.setContents(stringSelection,
> ChatConversationPanel.this);
> }
> });
>
> - String openLinkString
> - = GuiActivator.getResources().getI18NString(
> + String openLinkString =
> + GuiActivator.getResources().getI18NString(
> "service.gui.OPEN_IN_BROWSER");
>
> openLinkItem =
> - new JMenuItem(
> - openLinkString,
> - new
ImageIcon(ImageLoader.getImage(ImageLoader.BROWSER_ICON)));
> + new JMenuItem(openLinkString, new ImageIcon(ImageLoader
> + .getImage(ImageLoader.BROWSER_ICON)));
>
> openLinkItem.addActionListener(new ActionListener()
> {
> @@ -209,13 +209,11 @@
> }
> });
>
> - openLinkItem.setMnemonic(
> - GuiActivator.getResources().getI18nMnemonic(
> - "service.gui.OPEN_IN_BROWSER"));
> -
> - copyLinkItem.setMnemonic(
> - GuiActivator.getResources().getI18nMnemonic(
> - "service.gui.COPY_LINK"));
> +
openLinkItem.setMnemonic(GuiActivator.getResources().getI18nMnemonic(
> + "service.gui.OPEN_IN_BROWSER"));
> +
> +
copyLinkItem.setMnemonic(GuiActivator.getResources().getI18nMnemonic(
> + "service.gui.COPY_LINK"));
>
> /*
> * When we append a new message (regardless of whether it is a
string or
> @@ -243,6 +241,8 @@
> };
> chatTextPane.addComponentListener(componentListener);
> getViewport().addComponentListener(componentListener);
> +
> + listsources = GuiActivator.getReplacementSources();
> }
>
> /*
> @@ -261,13 +261,13 @@
>
> if (verticalScrollBar != null)
> {
> - BoundedRangeModel verticalScrollBarModel
> - = verticalScrollBar.getModel();
> + BoundedRangeModel verticalScrollBarModel =
> + verticalScrollBar.getModel();
>
> if ((verticalScrollBarModel.getValue()
> - + verticalScrollBarModel.getExtent()
> - >= verticalScrollBarModel.getMaximum())
> - || !verticalScrollBar.isVisible())
> + + verticalScrollBarModel.getExtent() >=
verticalScrollBarModel
> + .getMaximum())
> + || !verticalScrollBar.isVisible())
> scrollToBottomIsPending = true;
> }
> }
> @@ -276,34 +276,34 @@
> }
>
> /**
> - * Initializes the editor by adding a header containing the date.
> - * TODO: remove if not used anymore
> + * Initializes the editor by adding a header containing the date.
TODO:
> + * remove if not used anymore
> */
> -// private void initEditor()
> -// {
> -// Element root = this.document.getDefaultRootElement();
> -//
> -// Date date = new Date(System.currentTimeMillis());
> -//
> -// String chatHeader = "<h1>" + GuiUtils.formatDate(date) + " " +
"</h1>";
> -//
> -// try
> -// {
> -// this.document.insertAfterStart(root, chatHeader);
> -// }
> -// catch (BadLocationException e)
> -// {
> -// logger.error("Insert in the HTMLDocument failed.", e);
> -// }
> -// catch (IOException e)
> -// {
> -// logger.error("Insert in the HTMLDocument failed.", e);
> -// }
> -// }
> + // private void initEditor()
> + // {
> + // Element root = this.document.getDefaultRootElement();
> + //
> + // Date date = new Date(System.currentTimeMillis());
> + //
> + // String chatHeader = "<h1>" + GuiUtils.formatDate(date) + " " +
"</h1>";
> + //
> + // try
> + // {
> + // this.document.insertAfterStart(root, chatHeader);
> + // }
> + // catch (BadLocationException e)
> + // {
> + // logger.error("Insert in the HTMLDocument failed.", e);
> + // }
> + // catch (IOException e)
> + // {
> + // logger.error("Insert in the HTMLDocument failed.", e);
> + // }
> + // }
>
> /**
> * Processes the message given by the parameters.
> - *
> + *
> * @param chatMessage the message
> * @param keyword
> * @return the processed message
> @@ -324,10 +324,10 @@
> String dateString = getDateString(date);
>
> String startDivTag = "<DIV identifier=\"" + msgID + "\">";
> - String startHistoryDivTag
> - = "<DIV identifier=\"" + msgID + "\"
style=\"color:#707070;\">";
> - String startSystemDivTag
> - = "<DIV identifier=\"systemMessage\"
style=\"color:#627EB7;\">";
> + String startHistoryDivTag =
> + "<DIV identifier=\"" + msgID + "\"
style=\"color:#707070;\">";
> + String startSystemDivTag =
> + "<DIV identifier=\"systemMessage\"
style=\"color:#627EB7;\">";
> String endDivTag = "</DIV>";
>
> String startPlainTextTag;
> @@ -348,30 +348,26 @@
> {
> this.lastIncomingMsgTimestamp = System.currentTimeMillis();
>
> - chatString = "<h2 identifier=\""
> - + msgHeaderID
> - + "\" date=\""
> - + date + "\">";
> + chatString =
> + "<h2 identifier=\"" + msgHeaderID + "\" date=\"" + date
+ "\">";
>
> endHeaderTag = "</h2>";
>
> - chatString
> - += dateString + contactName + " at " +
GuiUtils.formatTime(date)
> + chatString +=
> + dateString + contactName + " at " +
GuiUtils.formatTime(date)
> + endHeaderTag + startDivTag + startPlainTextTag
> + formatMessage(message, contentType, keyword)
> + endPlainTextTag + endDivTag;
> }
> else if (messageType.equals(Chat.SMS_MESSAGE))
> {
> - chatString = "<h2 identifier=\""
> - + msgHeaderID
> - + "\" date=\""
> - + date + "\">";
> + chatString =
> + "<h2 identifier=\"" + msgHeaderID + "\" date=\"" + date
+ "\">";
>
> endHeaderTag = "</h2>";
>
> - chatString
> - += "SMS: " + dateString + contactName + " at "
> + chatString +=
> + "SMS: " + dateString + contactName + " at "
> + GuiUtils.formatTime(date) + endHeaderTag +
startDivTag
> + startPlainTextTag
> + formatMessage(message, contentType, keyword)
> @@ -379,97 +375,87 @@
> }
> else if (messageType.equals(Chat.OUTGOING_MESSAGE))
> {
> - chatString = "<h3 identifier=\""
> - + msgHeaderID
> - + "\" date=\""
> - + date + "\">";
> + chatString =
> + "<h3 identifier=\"" + msgHeaderID + "\" date=\"" + date
+ "\">";
>
> endHeaderTag = "</h3>";
>
> - chatString
> - += dateString
> - + GuiActivator
> - .getResources().getI18NString("service.gui.ME")
> - + " at " + GuiUtils.formatTime(date) + endHeaderTag
> - + startDivTag + startPlainTextTag
> + chatString +=
> + dateString
> + + GuiActivator.getResources().getI18NString(
> + "service.gui.ME") + " at " +
GuiUtils.formatTime(date)
> + + endHeaderTag + startDivTag + startPlainTextTag
> + formatMessage(message, contentType, keyword)
> + endPlainTextTag + endDivTag;
> }
> else if (messageType.equals(Chat.STATUS_MESSAGE))
> {
> - chatString = "<h4 identifier=\"statusMessage\" date=\""
> - + date + "\">";
> + chatString =
> + "<h4 identifier=\"statusMessage\" date=\"" + date +
"\">";
> endHeaderTag = "</h4>";
>
> - chatString
> - += GuiUtils.formatTime(date) + " " + contactName + " " +
message
> + chatString +=
> + GuiUtils.formatTime(date) + " " + contactName + " " +
message
> + endHeaderTag;
> }
> else if (messageType.equals(Chat.ACTION_MESSAGE))
> {
> - chatString = "<p identifier=\"actionMessage\" date=\""
> - + date + "\">";
> + chatString =
> + "<p identifier=\"actionMessage\" date=\"" + date +
"\">";
> endHeaderTag = "</p>";
>
> - chatString += "* " + GuiUtils.formatTime(date)
> - + " " + contactName + " "
> - + message
> - + endHeaderTag;
> + chatString +=
> + "* " + GuiUtils.formatTime(date) + " " + contactName + "
"
> + + message + endHeaderTag;
> }
> else if (messageType.equals(Chat.SYSTEM_MESSAGE))
> {
> - chatString
> - += startSystemDivTag + startPlainTextTag
> + chatString +=
> + startSystemDivTag + startPlainTextTag
> + formatMessage(message, contentType, keyword)
> + endPlainTextTag + endDivTag;
> }
> else if (messageType.equals(Chat.ERROR_MESSAGE))
> {
> - chatString = "<h6 identifier=\""
> - + msgHeaderID
> - + "\" date=\""
> - + date + "\">";
> + chatString =
> + "<h6 identifier=\"" + msgHeaderID + "\" date=\"" + date
+ "\">";
>
> endHeaderTag = "</h6>";
>
> - String errorIcon = "<IMG SRC='"
> - + ImageLoader.getImageUri(ImageLoader.EXCLAMATION_MARK)
> - + "' </IMG>";
> -
> - chatString += errorIcon
> - + messageTitle
> - + endHeaderTag + "<h5>" + message + "</h5>";
> + String errorIcon =
> + "<IMG SRC='"
> + +
ImageLoader.getImageUri(ImageLoader.EXCLAMATION_MARK)
> + + "' </IMG>";
> +
> + chatString +=
> + errorIcon + messageTitle + endHeaderTag + "<h5>" +
message
> + + "</h5>";
> }
> else if (messageType.equals(Chat.HISTORY_INCOMING_MESSAGE))
> {
> - chatString = "<h2 identifier='"
> - + msgHeaderID
> - + "' date=\""
> - + date + "\">";
> + chatString =
> + "<h2 identifier='" + msgHeaderID + "' date=\"" + date +
"\">";
>
> endHeaderTag = "</h2>";
>
> - chatString
> - += dateString + contactName + " at " +
GuiUtils.formatTime(date)
> + chatString +=
> + dateString + contactName + " at " +
GuiUtils.formatTime(date)
> + endHeaderTag + startHistoryDivTag +
startPlainTextTag
> + formatMessage(message, contentType, keyword)
> + endPlainTextTag + endDivTag;
> }
> else if (messageType.equals(Chat.HISTORY_OUTGOING_MESSAGE))
> {
> - chatString = "<h3 identifier=\""
> - + msgHeaderID
> - + "\" date=\""
> - + date + "\">";
> + chatString =
> + "<h3 identifier=\"" + msgHeaderID + "\" date=\"" + date
+ "\">";
>
> endHeaderTag = "</h3>";
>
> - chatString
> - += dateString
> - + GuiActivator
> - .getResources().getI18NString("service.gui.ME")
> - + " at " + GuiUtils.formatTime(date) + endHeaderTag
> - + startHistoryDivTag + startPlainTextTag
> + chatString +=
> + dateString
> + + GuiActivator.getResources().getI18NString(
> + "service.gui.ME") + " at " +
GuiUtils.formatTime(date)
> + + endHeaderTag + startHistoryDivTag +
startPlainTextTag
> + formatMessage(message, contentType, keyword)
> + endPlainTextTag + endDivTag;
> }
> @@ -479,7 +465,7 @@
>
> /**
> * Processes the message given by the parameters.
> - *
> + *
> * @param chatMessage the message.
> * @return the formatted message
> */
> @@ -491,7 +477,7 @@
> /**
> * Appends the given string at the end of the contained in this panel
> * document.
> - *
> + *
> * @param chatString the string to append
> */
> public void appendMessageToEnd(String chatString)
> @@ -504,10 +490,8 @@
>
> try
> {
> - document
> - .insertAfterEnd(
> - root.getElement(root.getElementCount() - 1),
> - chatString);
> + document.insertAfterEnd(root
> + .getElement(root.getElementCount() - 1),
chatString);
> }
> catch (BadLocationException e)
> {
> @@ -519,10 +503,96 @@
> }
> if (!isHistory)
> ensureDocumentSize();
> +
> + final Element elem;
> +
> + /*
> + * Check to make sure element isn't the first element in the
HTML
> + * document.
> + */
> + if (!(root.getElementCount() < 2))
> + {
> + elem = root.getElement(root.getElementCount() - 2);
> + }
> + else
> + elem = root.getElement(1);
> +
> + String prefix =
> +
"net.java.sip.communicator.impl.gui.replacement.isEnabled";
> + String obj =
> + (String)
GuiActivator.getConfigurationService().getProperty(
> + prefix);
> + /*
> + * Replacements will be processed only if it is enabled in
the
> + * property
> + */
> + if (obj != null && Boolean.parseBoolean(obj))
> + {
> + processReplacement(elem, chatString);
> + }
> }
> }
>
> /**
> + * Formats the given message. Processes the messages and replaces
links to
> + * video/image sources with their previews or any other
substitution. Spawns
> + * a separate thread for replacement.
> + *
> + * @param elem the element in the HTML Document.
> + * @param chatString the message.
> + */
> + private void processReplacement(final Element elem, final String
chatString)
> + {
> +
> + final String chatFinal = chatString;
> +
> + SwingWorker worker = new SwingWorker()
> + {
> +
> + @Override
> + public Object construct() throws Exception
> + {
> + String temp = "", msgStore = chatFinal;
> +
> + Iterator entrySetIter =
listsources.entrySet().iterator();
> +
> + for (int i = 0; i < listsources.size(); i++)
> + {
> +
> + Map.Entry entry = (Map.Entry) entrySetIter.next();
> + ReplacementService source =
> + (ReplacementService) entry.getValue();
> +
> + temp = source.getReplacedMessage(msgStore);
> +
> + /*
> + * replace the msgStore variable with the current
replaced
> + * message before next iteration
> + */
> +
> + if (!temp.equals(msgStore))
> + {
> + msgStore = temp;
> + }
> + }
> +
> + if (!temp.equals(chatFinal))
> + {
> + synchronized (scrollToBottomRunnable)
> + {
> + scrollToBottomIsPending = true;
> + document.setOuterHTML(elem,
temp.toString().substring(
> + temp.indexOf("<DIV")));
> + }
> + }
> +
> + return "";
> + }
> + };
> + worker.start();
> + }
> +
> + /**
> * Ensures that the document won't become too big. When the document
reaches
> * a certain size the first message in the page is removed.
> */
> @@ -540,15 +610,16 @@
> // Count how many messages we have in the document.
> for (int i = 0; i < rootElement.getElementCount(); i++)
> {
> - String idAttr = (String) rootElement.getElement(i)
> - .getAttributes().getAttribute("identifier");
> + String idAttr =
> + (String) rootElement.getElement(i).getAttributes()
> + .getAttribute("identifier");
>
> - if(idAttr != null
> + if (idAttr != null
> && (idAttr.equals("message")
> - || idAttr.equals("statusMessage")
> - || idAttr.equals("systemMessage")))
> + || idAttr.equals("statusMessage") || idAttr
> + .equals("systemMessage")))
> {
> - if(firstMsgElement == null)
> + if (firstMsgElement == null)
> {
> firstMsgElement = rootElement.getElement(i);
> firstMsgIndex = i;
> @@ -560,20 +631,22 @@
>
> // If we doesn't have any known elements in the document or
if we
> // have only one long message we don't want to remove it.
> - if(firstMsgElement == null || msgElementCount < 2)
> + if (firstMsgElement == null || msgElementCount < 2)
> return;
>
> try
> {
> // Remove the header of the message if such exists.
> - if(firstMsgIndex > 0)
> + if (firstMsgIndex > 0)
> {
> - Element headerElement =
rootElement.getElement(firstMsgIndex - 1);
> + Element headerElement =
> + rootElement.getElement(firstMsgIndex - 1);
>
> - String idAttr = (String) headerElement
> - .getAttributes().getAttribute("identifier");
> + String idAttr =
> + (String)
headerElement.getAttributes().getAttribute(
> + "identifier");
>
> - if(idAttr != null && idAttr.equals("messageHeader"))
> + if (idAttr != null &&
idAttr.equals("messageHeader"))
> {
>
this.document.remove(headerElement.getStartOffset(),
> headerElement.getEndOffset()
> @@ -583,8 +656,8 @@
>
> // Remove the message itself.
> this.document.remove(firstMsgElement.getStartOffset(),
> - firstMsgElement.getEndOffset()
> - - firstMsgElement.getStartOffset());
> + firstMsgElement.getEndOffset()
> + - firstMsgElement.getStartOffset());
> }
> catch (BadLocationException e)
> {
> @@ -595,15 +668,14 @@
>
> /**
> * Highlights keywords searched in the history.
> - *
> + *
> * @param message the source message
> * @param contentType the content type
> * @param keyword the searched keyword
> * @return the formatted message
> */
> - private String processKeyword( String message,
> - String contentType,
> - String keyword)
> + private String processKeyword(String message, String contentType,
> + String keyword)
> {
> String startPlainTextTag;
> String endPlainTextTag;
> @@ -619,9 +691,8 @@
> endPlainTextTag = END_PLAINTEXT_TAG;
> }
>
> - Matcher m
> - = Pattern
> - .compile(keyword,
Pattern.CASE_INSENSITIVE).matcher(message);
> + Matcher m =
> + Pattern.compile(keyword,
Pattern.CASE_INSENSITIVE).matcher(message);
> StringBuffer msgBuffer = new StringBuffer();
> int prevEnd = 0;
>
> @@ -653,15 +724,14 @@
> /**
> * Formats the given message. Processes all smiley chars, new lines
and
> * links.
> - *
> + *
> * @param message the message to be formatted
> * @param contentType the content type of the message to be formatted
> * @param keyword the word to be highlighted
> * @return the formatted message
> */
> - private String formatMessage(String message,
> - String contentType,
> - String keyword)
> + private String formatMessage(String message, String contentType,
> + String keyword)
> {
> // If the message content type is HTML we won't process links and
> // new lines, but only the smileys.
> @@ -677,8 +747,8 @@
>
> if ((keyword != null) && (keyword.length() != 0))
> {
> - String messageWithProcessedKeyword
> - = processKeyword(message, contentType, keyword);
> + String messageWithProcessedKeyword =
> + processKeyword(message, contentType, keyword);
>
> /*
> * The same String instance will be returned if there was
no
> @@ -691,9 +761,9 @@
> else
> processHTMLChars = true;
>
> - message
> - = processNewLines(
> - processLinksAndHTMLChars(message,
processHTMLChars));
> + message =
> + processNewLines(processLinksAndHTMLChars(message,
> + processHTMLChars));
> }
> // If the message content is HTML, we process br and img tags.
> else
> @@ -703,9 +773,7 @@
> message = processImgTags(processBrTags(message));
> }
>
> - if (ConfigurationManager.isShowSmileys())
> - message = processSmileys(message, contentType);
> -
> + // return processSmileys(message, contentType);
> return message;
> }
>
> @@ -719,12 +787,12 @@
> * characters such as &amp;.
> *
> * @param message The source message string.
> - * @param processHTMLChars <tt>true</tt> to escape the special HTML
chars;
> - * otherwise, <tt>false</tt>
> + * @param processHTMLChars <tt>true</tt> to escape the special HTML
chars;
> + * otherwise, <tt>false</tt>
> * @return The message string with properly formatted links.
> */
> private String processLinksAndHTMLChars(String message,
> - boolean processHTMLChars)
> + boolean processHTMLChars)
> {
> Matcher m = URL_PATTERN.matcher(message);
> StringBuffer msgBuffer = new StringBuffer();
> @@ -764,23 +832,19 @@
> /**
> * Escapes special HTML characters such as &lt;, &gt;, &amp; and
&quot; in
> * the specified message.
> - *
> + *
> * @param message the message to be processed
> * @return the processed message with escaped special HTML characters
> */
> private String processHTMLChars(String message)
> {
> - return
> - message
> - .replace("&", "&amp;")
> - .replace("<", "&lt;")
> - .replace(">", "&gt;")
> - .replace("\"", "&quot;");
> + return message.replace("&", "&amp;").replace("<",
"&lt;").replace(">",
> + "&gt;").replace("\"", "&quot;");
> }
>
> /**
> * Formats message new lines.
> - *
> + *
> * @param message The source message string.
> * @return The message string with properly formatted new lines.
> */
> @@ -791,23 +855,20 @@
> * <br> tags are needed to visualize a new line in the html
format, but


#3

Hi Yana,

You have to set the "net.java.sip.communicator.impl.gui.replacement.isEnabled" to true manually in the sip-communicator.properties file for the replacements to be processed. This was in accordance to what Emil had suggested earlier.

Thanks!:slight_smile: It works great now!

In the current version, I've also included the smiley replacements to use this service. So even the smilies would require this property set. I plan to make it more flexible in the future.

Yep, agree.

Cheers,
Yana

···

On Jun 14, 2010, at 2:16 PM, Purvesh Sahoo wrote:

Thanks,
Purvesh

On Mon, Jun 14, 2010 at 4:59 PM, Yana Stamcheva <yana@sip-communicator.org> wrote:
Hi Purvesh,

I've checked out your branch. I'm quite impressed by the amount of work you have done in the last few weeks. Bravo!

However when I tried to send a youtube link, nothing happened, it wasn't replaced. Is this supposed to work already? If yes, do you have in mind what the reason could be that it's not working for me?

Cheers,
Yana

On Jun 12, 2010, at 4:14 PM, jimpu2@dev.java.net wrote:

> Author: jimpu2
> Date: 2010-06-12 14:14:41+0000
> New Revision: 7237
>
> Added:
> branches/gsoc10/previews/.project_old
> branches/gsoc10/previews/lib/installer-exclude/gdata-base-1.0.jar (contents, props changed)
> branches/gsoc10/previews/lib/installer-exclude/gdata-client-1.0.jar (contents, props changed)
> branches/gsoc10/previews/lib/installer-exclude/gdata-client-meta-1.0.jar (contents, props changed)
> branches/gsoc10/previews/lib/installer-exclude/gdata-core-1.0.jar (contents, props changed)
> branches/gsoc10/previews/lib/installer-exclude/gdata-media-1.0.jar (contents, props changed)
> branches/gsoc10/previews/lib/installer-exclude/gdata-youtube-2.0.jar (contents, props changed)
> branches/gsoc10/previews/lib/installer-exclude/gdata-youtube-meta-2.0.jar (contents, props changed)
> branches/gsoc10/previews/lib/installer-exclude/mail.jar (contents, props changed)
> branches/gsoc10/previews/src/net/java/sip/communicator/impl/replacement/
> branches/gsoc10/previews/src/net/java/sip/communicator/impl/replacement/dailymotion/
> branches/gsoc10/previews/src/net/java/sip/communicator/impl/replacement/dailymotion/DailymotionActivator.java
> branches/gsoc10/previews/src/net/java/sip/communicator/impl/replacement/dailymotion/ReplacementServiceDailymotionImpl.java
> branches/gsoc10/previews/src/net/java/sip/communicator/impl/replacement/dailymotion/dailymotion.source.manifest.mf
> branches/gsoc10/previews/src/net/java/sip/communicator/impl/replacement/smiley/
> branches/gsoc10/previews/src/net/java/sip/communicator/impl/replacement/smiley/ReplacementServiceSmileyImpl.java
> branches/gsoc10/previews/src/net/java/sip/communicator/impl/replacement/smiley/SmileyActivator.java
> branches/gsoc10/previews/src/net/java/sip/communicator/impl/replacement/smiley/smiley.source.manifest.mf
> branches/gsoc10/previews/src/net/java/sip/communicator/impl/replacement/vimeo/
> branches/gsoc10/previews/src/net/java/sip/communicator/impl/replacement/vimeo/ReplacementServiceVimeoImpl.java
> branches/gsoc10/previews/src/net/java/sip/communicator/impl/replacement/vimeo/VimeoActivator.java
> branches/gsoc10/previews/src/net/java/sip/communicator/impl/replacement/vimeo/vimeo.source.manifest.mf
> branches/gsoc10/previews/src/net/java/sip/communicator/impl/replacement/youtube/
> branches/gsoc10/previews/src/net/java/sip/communicator/impl/replacement/youtube/ReplacementServiceYoutubeImpl.java
> branches/gsoc10/previews/src/net/java/sip/communicator/impl/replacement/youtube/YoutubeActivator.java
> branches/gsoc10/previews/src/net/java/sip/communicator/impl/replacement/youtube/youtube.source.manifest.mf
> branches/gsoc10/previews/src/net/java/sip/communicator/service/replacement/
> branches/gsoc10/previews/src/net/java/sip/communicator/service/replacement/ReplacementService.java
> Modified:
> branches/gsoc10/previews/build.xml
> branches/gsoc10/previews/lib/felix.client.run.properties
> branches/gsoc10/previews/src/net/java/sip/communicator/impl/gui/GuiActivator.java
> branches/gsoc10/previews/src/net/java/sip/communicator/impl/gui/main/chat/ChatConversationPanel.java
> branches/gsoc10/previews/src/net/java/sip/communicator/impl/gui/swing.ui.manifest.mf
> branches/gsoc10/previews/src/net/java/sip/communicator/impl/gui/utils/Smiley.java
>
> Log:
> Replacement Service
>
> Added: branches/gsoc10/previews/.project_old
> Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/branches/gsoc10/previews/.project_old?view=auto&rev=7237
> ==============================================================================
> --- (empty file)
> +++ branches/gsoc10/previews/.project_old 2010-06-12 14:14:41+0000
> @@ -0,0 +1,11 @@
> +<?xml version="1.0" encoding="UTF-8"?>
> +<projectDescription>
> + <name>sip-comm-new</name>
> + <comment></comment>
> + <projects>
> + </projects>
> + <buildSpec>
> + </buildSpec>
> + <natures>
> + </natures>
> +</projectDescription>
>
> Modified: branches/gsoc10/previews/build.xml
> Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/branches/gsoc10/previews/build.xml?view=diff&rev=7237&p1=branches/gsoc10/previews/build.xml&p2=branches/gsoc10/previews/build.xml&r1=7236&r2=7237
> ==============================================================================
> --- branches/gsoc10/previews/build.xml (original)
> +++ branches/gsoc10/previews/build.xml 2010-06-12 14:14:41+0000
> @@ -911,7 +911,8 @@
> bundle-filehistory,bundle-metahistory,bundle-metahistory-slick,
> bundle-plugin-facebookaccregwizz,
> bundle-bouncycastle,bundle-plugin-otr,bundle-plugin-iptelaccregwizz,
> - bundle-contactsource,bundle-plugin-reconnect"/>
> + bundle-contactsource,bundle-plugin-reconnect,bundle-youtube,
> + bundle-dailymotion,bundle-smiley,bundle-vimeo"/>
>
> <!--BUNDLE-SC-LAUNCHER-->
> <target name="bundle-sc-launcher">
> @@ -1522,7 +1523,7 @@
> prefix="net/java/sip/communicator/impl/gui"/>
> <zipfileset src="lib/installer-exclude/jna.jar" prefix=""/>
> <zipfileset src="lib/installer-exclude/transparency.jar" prefix=""/>
> - <zipfileset src="lib/installer-exclude/swing-worker-1.2.jar" prefix=""/>
> + <zipfileset src="lib/installer-exclude/swing-worker-1.2.jar" prefix=""/>
> </jar>
> </target>
>
> @@ -2325,4 +2326,61 @@
> prefix="net/java/sip/communicator/plugin/reconnectplugin"/>
> </jar>
> </target>
> +
> + <!-- BUNDLE-YOUTUBE -->
> + <target name="bundle-youtube">
> + <jar compress="false" destfile="\{bundles\.dest\}/replacement\-youtube\.jar&quot; &gt; \+ manifest=&quot;{src}/net/java/sip/communicator/impl/replacement/youtube/youtube.source.manifest.mf">
> + <zipfileset dir="\{dest\}/net/java/sip/communicator/impl/replacement/youtube&quot; &gt; \+ prefix=&quot;net/java/sip/communicator/impl/replacement/youtube&quot;/&gt; &gt; \+ &lt;zipfileset dir=&quot;{dest}/net/java/sip/communicator/service/replacement"
> + prefix="net/java/sip/communicator/service/replacement"/>
> + <zipfileset src="\{lib\.noinst\}/gdata\-base\-1\.0\.jar&quot; prefix=&quot;&quot;/&gt; &gt; \+ &lt;zipfileset src=&quot;{lib.noinst}/gdata-client-1.0.jar" prefix=""/>
> + <zipfileset src="\{lib\.noinst\}/gdata\-client\-meta\-1\.0\.jar&quot; prefix=&quot;&quot;/&gt; &gt; \+ &lt;zipfileset src=&quot;{lib.noinst}/gdata-core-1.0.jar" prefix=""/>
> + <zipfileset src="\{lib\.noinst\}/gdata\-media\-1\.0\.jar&quot; prefix=&quot;&quot;/&gt; &gt; \+ &lt;zipfileset src=&quot;{lib.noinst}/gdata-youtube-2.0.jar" prefix=""/>
> + <zipfileset src="\{lib\.noinst\}/gdata\-youtube\-meta\-2\.0\.jar&quot; prefix=&quot;&quot;/&gt; &gt; \+ &lt;zipfileset src=&quot;{lib.noinst}/mail.jar" prefix=""/>
> + </jar>
> + </target>
> +
> + <!-- BUNDLE-DAILYMOTION -->
> + <target name="bundle-dailymotion">
> + <jar compress="false" destfile="\{bundles\.dest\}/replacement\-dailymotion\.jar&quot; &gt; \+ manifest=&quot;{src}/net/java/sip/communicator/impl/replacement/dailymotion/dailymotion.source.manifest.mf">
> + <zipfileset dir="\{dest\}/net/java/sip/communicator/impl/replacement/dailymotion&quot; &gt; \+ prefix=&quot;net/java/sip/communicator/impl/replacement/dailymotion&quot;/&gt; &gt; \+ &lt;zipfileset dir=&quot;{dest}/net/java/sip/communicator/service/replacement"
> + prefix="net/java/sip/communicator/service/replacement"/>
> + </jar>
> + </target>
> +
> + <!-- BUNDLE-SMILEY -->
> + <target name="bundle-smiley">
> + <jar compress="false" destfile="\{bundles\.dest\}/replacement\-smiley\.jar&quot; &gt; \+ manifest=&quot;{src}/net/java/sip/communicator/impl/replacement/smiley/smiley.source.manifest.mf">
> + <zipfileset dir="\{dest\}/net/java/sip/communicator/impl/replacement/smiley&quot; &gt; \+ prefix=&quot;net/java/sip/communicator/impl/replacement/smiley&quot;/&gt; &gt; \+ &lt;zipfileset dir=&quot;{dest}/net/java/sip/communicator/service/replacement"
> + prefix="net/java/sip/communicator/service/replacement"/>
> + <zipfileset dir="\{dest\}/net/java/sip/communicator/impl/gui/utils&quot; &gt; \+ prefix=&quot;net/java/sip/communicator/impl/gui/utils&quot;/&gt; &gt; \+ &lt;zipfileset dir=&quot;{dest}/net/java/sip/communicator/impl/gui"
> + prefix="net/java/sip/communicator/impl/gui"/>
> + </jar>
> + </target>
> +
> + <!-- BUNDLE-VIMEO -->
> + <target name="bundle-vimeo">
> + <jar compress="false" destfile="\{bundles\.dest\}/replacement\-vimeo\.jar&quot; &gt; \+ manifest=&quot;{src}/net/java/sip/communicator/impl/replacement/vimeo/vimeo.source.manifest.mf">
> + <zipfileset dir="\{dest\}/net/java/sip/communicator/impl/replacement/vimeo&quot; &gt; \+ prefix=&quot;net/java/sip/communicator/impl/replacement/vimeo&quot;/&gt; &gt; \+ &lt;zipfileset dir=&quot;{dest}/net/java/sip/communicator/service/replacement"
> + prefix="net/java/sip/communicator/service/replacement"/>
> + <zipfileset src="${lib.noinst}/json-20090723.jar" prefix=""/>
> + </jar>
> + </target>
> </project>
>
> Modified: branches/gsoc10/previews/lib/felix.client.run.properties
> Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/branches/gsoc10/previews/lib/felix.client.run.properties?view=diff&rev=7237&p1=branches/gsoc10/previews/lib/felix.client.run.properties&p2=branches/gsoc10/previews/lib/felix.client.run.properties&r1=7236&r2=7237
> ==============================================================================
> --- branches/gsoc10/previews/lib/felix.client.run.properties (original)
> +++ branches/gsoc10/previews/lib/felix.client.run.properties 2010-06-12 14:14:41+0000
> @@ -130,7 +130,11 @@
> reference:file:sc-bundles/generalconfig.jar \
> reference:file:sc-bundles/dictaccregwizz.jar \
> reference:file:sc-bundles/otr.jar \
> - reference:file:sc-bundles/facebookaccregwizz.jar
> + reference:file:sc-bundles/facebookaccregwizz.jar \
> + reference:file:sc-bundles/replacement-youtube.jar \
> + reference:file:sc-bundles/replacement-dailymotion.jar \
> + reference:file:sc-bundles/replacement-smiley.jar \
> + reference:file:sc-bundles/replacement-vimeo.jar
>
> #level 68 is for profiler, don't use it or change the build.xml file accordingly
>
>
> Added: branches/gsoc10/previews/lib/installer-exclude/gdata-base-1.0.jar
> Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/branches/gsoc10/previews/lib/installer-exclude/gdata-base-1.0.jar?view=auto&rev=7237
> ==============================================================================
> Binary file. No diff available.
>
> Added: branches/gsoc10/previews/lib/installer-exclude/gdata-client-1.0.jar
> Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/branches/gsoc10/previews/lib/installer-exclude/gdata-client-1.0.jar?view=auto&rev=7237
> ==============================================================================
> Binary file. No diff available.
>
> Added: branches/gsoc10/previews/lib/installer-exclude/gdata-client-meta-1.0.jar
> Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/branches/gsoc10/previews/lib/installer-exclude/gdata-client-meta-1.0.jar?view=auto&rev=7237
> ==============================================================================
> Binary file. No diff available.
>
> Added: branches/gsoc10/previews/lib/installer-exclude/gdata-core-1.0.jar
> Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/branches/gsoc10/previews/lib/installer-exclude/gdata-core-1.0.jar?view=auto&rev=7237
> ==============================================================================
> Binary file. No diff available.
>
> Added: branches/gsoc10/previews/lib/installer-exclude/gdata-media-1.0.jar
> Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/branches/gsoc10/previews/lib/installer-exclude/gdata-media-1.0.jar?view=auto&rev=7237
> ==============================================================================
> Binary file. No diff available.
>
> Added: branches/gsoc10/previews/lib/installer-exclude/gdata-youtube-2.0.jar
> Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/branches/gsoc10/previews/lib/installer-exclude/gdata-youtube-2.0.jar?view=auto&rev=7237
> ==============================================================================
> Binary file. No diff available.
>
> Added: branches/gsoc10/previews/lib/installer-exclude/gdata-youtube-meta-2.0.jar
> Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/branches/gsoc10/previews/lib/installer-exclude/gdata-youtube-meta-2.0.jar?view=auto&rev=7237
> ==============================================================================
> Binary file. No diff available.
>
> Added: branches/gsoc10/previews/lib/installer-exclude/mail.jar
> Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/branches/gsoc10/previews/lib/installer-exclude/mail.jar?view=auto&rev=7237
> ==============================================================================
> Binary file. No diff available.
>
> Modified: branches/gsoc10/previews/src/net/java/sip/communicator/impl/gui/GuiActivator.java
> Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/branches/gsoc10/previews/src/net/java/sip/communicator/impl/gui/GuiActivator.java?view=diff&rev=7237&p1=branches/gsoc10/previews/src/net/java/sip/communicator/impl/gui/GuiActivator.java&p2=branches/gsoc10/previews/src/net/java/sip/communicator/impl/gui/GuiActivator.java&r1=7236&r2=7237
> ==============================================================================
> --- branches/gsoc10/previews/src/net/java/sip/communicator/impl/gui/GuiActivator.java (original)
> +++ branches/gsoc10/previews/src/net/java/sip/communicator/impl/gui/GuiActivator.java 2010-06-12 14:14:41+0000
> @@ -1,8 +1,7 @@
> /*
> * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
> - *
> - * Distributable under LGPL license.
> - * See terms of license at gnu.org.
> + *
> + * Distributable under LGPL license. See terms of license at gnu.org.
> */
> package net.java.sip.communicator.impl.gui;
>
> @@ -25,6 +24,7 @@
> import net.java.sip.communicator.service.neomedia.*;
> import net.java.sip.communicator.service.notification.*;
> import net.java.sip.communicator.service.protocol.*;
> +import net.java.sip.communicator.service.replacement.ReplacementService;
> import net.java.sip.communicator.service.resources.*;
> import net.java.sip.communicator.service.shutdown.*;
> import net.java.sip.communicator.service.systray.*;
> @@ -34,10 +34,11 @@
>
> /**
> * The GUI Activator class.
> - *
> + *
> * @author Yana Stamcheva
> */
> -public class GuiActivator implements BundleActivator
> +public class GuiActivator
> + implements BundleActivator
> {
> private static final Logger logger = Logger.getLogger(GuiActivator.class);
>
> @@ -58,7 +59,8 @@
> private static BrowserLauncherService browserLauncherService;
>
> private static NotificationService notificationService;
> - private NotificationServiceListener notificationServiceListener;
> +
> + private NotificationServiceListener notificationServiceListener;
>
> private static SystrayService systrayService;
>
> @@ -74,13 +76,16 @@
>
> private static List<ContactSourceService> contactSources;
>
> - private static final Map<Object, ProtocolProviderFactory>
> - providerFactoriesMap = new Hashtable<Object, ProtocolProviderFactory>();
> + private static final Map<Object, ProtocolProviderFactory> providerFactoriesMap =
> + new Hashtable<Object, ProtocolProviderFactory>();
> +
> + private static final Map<Object, ReplacementService> replacementSourcesMap =
> + new Hashtable<Object, ReplacementService>();
>
> /**
> * Indicates if this bundle has been started.
> */
> - public static boolean isStarted = false;
> + public static boolean isStarted = false;
>
> /**
> * The contact list object.
> @@ -89,12 +94,11 @@
>
> /**
> * Called when this bundle is started.
> - *
> + *
> * @param bContext The execution context of the bundle being started.
> * @throws Exception if the bundle is not correctly started
> */
> - public void start(BundleContext bContext)
> - throws Exception
> + public void start(BundleContext bContext) throws Exception
> {
> isStarted = true;
> GuiActivator.bundleContext = bContext;
> @@ -113,21 +117,17 @@
> if (logger.isInfoEnabled())
> logger.info("UI Service...[ STARTED ]");
>
> - bundleContext.registerService(UIService.class.getName(),
> - uiService,
> - null);
> + bundleContext.registerService(UIService.class.getName(), uiService,
> + null);
> if (logger.isInfoEnabled())
> logger.info("UI Service ...[REGISTERED]");
>
> // UIServiceImpl also implements ShutdownService.
> bundleContext.registerService(ShutdownService.class.getName(),
> - (ShutdownService) uiService,
> - null);
> + (ShutdownService) uiService, null);
>
> - bundleContext.registerService(
> - CertificateVerificationService.class.getName(),
> - new CertificateVerificationServiceImpl(),
> - null);
> + bundleContext.registerService(CertificateVerificationService.class
> + .getName(), new CertificateVerificationServiceImpl(), null);
>
> uiService.loadApplicationGui();
>
> @@ -138,8 +138,8 @@
> logger.logExit();
> }
>
> - GuiActivator.getConfigurationService()
> - .addPropertyChangeListener(uiService);
> + GuiActivator.getConfigurationService().addPropertyChangeListener(
> + uiService);
>
> bundleContext.addServiceListener(uiService);
> }
> @@ -147,12 +147,12 @@
> /**
> * Called when this bundle is stopped so the Framework can perform the
> * bundle-specific activities necessary to stop the bundle.
> - *
> + *
> * @param bContext The execution context of the bundle being stopped.
> - * @throws Exception If this method throws an exception, the bundle is
> - * still marked as stopped, and the Framework will remove the bundle's
> - * listeners, unregister all services registered by the bundle, and
> - * release all services used by the bundle.
> + * @throws Exception If this method throws an exception, the bundle is still
> + * marked as stopped, and the Framework will remove the bundle's
> + * listeners, unregister all services registered by the bundle,
> + * and release all services used by the bundle.
> */
> public void stop(BundleContext bContext) throws Exception
> {
> @@ -160,8 +160,8 @@
> logger.info("UI Service ...[STOPPED]");
> isStarted = false;
>
> - GuiActivator.getConfigurationService()
> - .removePropertyChangeListener(uiService);
> + GuiActivator.getConfigurationService().removePropertyChangeListener(
> + uiService);
>
> bContext.removeServiceListener(uiService);
> bContext.removeServiceListener(notificationServiceListener);
> @@ -174,8 +174,7 @@
> * @return all <tt>ProtocolProviderFactory</tt>s obtained from the bundle
> * context
> */
> - public static Map<Object, ProtocolProviderFactory>
> - getProtocolProviderFactories()
> + public static Map<Object, ProtocolProviderFactory> getProtocolProviderFactories()
> {
>
> ServiceReference[] serRefs = null;
> @@ -192,45 +191,46 @@
> logger.error("LoginManager : " + e);
> }
>
> - if (serRefs != null)
> + if (serRefs != null)
> {
> - for (int i = 0; i < serRefs.length; i++)
> + for (int i = 0; i < serRefs.length; i++)
> {
>
> - ProtocolProviderFactory providerFactory
> - = (ProtocolProviderFactory) bundleContext
> + ProtocolProviderFactory providerFactory =
> + (ProtocolProviderFactory) bundleContext
> .getService(serRefs[i]);
>
> providerFactoriesMap.put(serRefs[i]
> - .getProperty(ProtocolProviderFactory.PROTOCOL),
> - providerFactory);
> + .getProperty(ProtocolProviderFactory.PROTOCOL),
> + providerFactory);
> }
> }
> return providerFactoriesMap;
> }
>
> /**
> - * Returns a <tt>ProtocolProviderFactory</tt> for a given protocol
> - * provider.
> + * Returns a <tt>ProtocolProviderFactory</tt> for a given protocol provider.
> + *
> * @param protocolProvider the <tt>ProtocolProviderService</tt>, which
> - * factory we're looking for
> - * @return a <tt>ProtocolProviderFactory</tt> for a given protocol
> - * provider
> + * factory we're looking for
> + * @return a <tt>ProtocolProviderFactory</tt> for a given protocol provider
> */
> public static ProtocolProviderFactory getProtocolProviderFactory(
> - ProtocolProviderService protocolProvider)
> + ProtocolProviderService protocolProvider)
> {
> - String osgiFilter = "("
> - + ProtocolProviderFactory.PROTOCOL
> - + "="+protocolProvider.getProtocolName()+")";
> + String osgiFilter =
> + "(" + ProtocolProviderFactory.PROTOCOL + "="
> + + protocolProvider.getProtocolName() + ")";
>
> ProtocolProviderFactory protocolProviderFactory = null;
> try
> {
> - ServiceReference[] serRefs = GuiActivator.bundleContext.getServiceReferences(
> - ProtocolProviderFactory.class.getName(), osgiFilter);
> - protocolProviderFactory = (ProtocolProviderFactory) GuiActivator
> - .bundleContext.getService(serRefs[0]);
> + ServiceReference[] serRefs =
> + GuiActivator.bundleContext.getServiceReferences(
> + ProtocolProviderFactory.class.getName(), osgiFilter);
> + protocolProviderFactory =
> + (ProtocolProviderFactory) GuiActivator.bundleContext
> + .getService(serRefs[0]);
> }
> catch (InvalidSyntaxException ex)
> {
> @@ -241,41 +241,88 @@
> }
>
> /**
> + * Returns all <tt>ReplacementService</tt>s obtained from the bundle
> + * context.
> + *
> + * @return all <tt>ReplacementService</tt> implementation obtained from the
> + * bundle context
> + */
> + public static Map<Object, ReplacementService> getReplacementSources()
> + {
> +
> + ServiceReference[] serRefs = null;
> + try
> + {
> + // get all registered sources
> + serRefs =
> + bundleContext.getServiceReferences(ReplacementService.class
> + .getName(), null);
> +
> + }
> + catch (InvalidSyntaxException e)
> + {
> + logger.error("Error : " + e);
> + }
> +
> + if (serRefs != null)
> + {
> +
> + for (int i = 0; i < serRefs.length; i++)
> + {
> +
> + ReplacementService replacementSources =
> + (ReplacementService) bundleContext.getService(serRefs[i]);
> +
> + replacementSourcesMap.put(serRefs[i]
> + .getProperty(ReplacementService.SOURCE_NAME),
> + replacementSources);
> +
> + // replacementSourcesMap.put("YOUTUBE",replacementSources);
> + }
> + }
> + return replacementSourcesMap;
> + }
> +
> + /**
> * Returns the <tt>ConfigurationService</tt> obtained from the bundle
> * context.
> + *
> * @return the <tt>ConfigurationService</tt> obtained from the bundle
> - * context
> + * context
> */
> public static ConfigurationService getConfigurationService()
> {
> - if(configService == null)
> + if (configService == null)
> {
> - ServiceReference configReference = bundleContext
> - .getServiceReference(ConfigurationService.class.getName());
> -
> - configService = (ConfigurationService) bundleContext
> - .getService(configReference);
> + ServiceReference configReference =
> + bundleContext.getServiceReference(ConfigurationService.class
> + .getName());
> +
> + configService =
> + (ConfigurationService) bundleContext
> + .getService(configReference);
> }
>
> return configService;
> }
>
> /**
> - * Returns the <tt>MetaHistoryService</tt> obtained from the bundle
> - * context.
> - * @return the <tt>MetaHistoryService</tt> obtained from the bundle
> - * context
> + * Returns the <tt>MetaHistoryService</tt> obtained from the bundle context.
> + *
> + * @return the <tt>MetaHistoryService</tt> obtained from the bundle context
> */
> public static MetaHistoryService getMetaHistoryService()
> {
> if (metaHistoryService == null)
> {
> - ServiceReference serviceReference = bundleContext
> - .getServiceReference(MetaHistoryService.class.getName());
> + ServiceReference serviceReference =
> + bundleContext.getServiceReference(MetaHistoryService.class
> + .getName());
>
> if (serviceReference != null)
> - metaHistoryService = (MetaHistoryService) bundleContext
> - .getService(serviceReference);
> + metaHistoryService =
> + (MetaHistoryService) bundleContext
> + .getService(serviceReference);
> }
>
> return metaHistoryService;
> @@ -284,17 +331,20 @@
> /**
> * Returns the <tt>MetaContactListService</tt> obtained from the bundle
> * context.
> + *
> * @return the <tt>MetaContactListService</tt> obtained from the bundle
> - * context
> + * context
> */
> public static MetaContactListService getContactListService()
> {
> if (metaCListService == null)
> {
> - ServiceReference clistReference = bundleContext
> - .getServiceReference(MetaContactListService.class.getName());
> + ServiceReference clistReference =
> + bundleContext.getServiceReference(MetaContactListService.class
> + .getName());
>
> - metaCListService = (MetaContactListService) bundleContext
> + metaCListService =
> + (MetaContactListService) bundleContext
> .getService(clistReference);
> }
>
> @@ -302,20 +352,20 @@
> }
>
> /**
> - * Returns the <tt>CallHistoryService</tt> obtained from the bundle
> - * context.
> - * @return the <tt>CallHistoryService</tt> obtained from the bundle
> - * context
> + * Returns the <tt>CallHistoryService</tt> obtained from the bundle context.
> + *
> + * @return the <tt>CallHistoryService</tt> obtained from the bundle context
> */
> public static CallHistoryService getCallHistoryService()
> {
> if (callHistoryService == null)
> {
> - ServiceReference serviceReference = bundleContext
> - .getServiceReference(CallHistoryService.class.getName());
> + ServiceReference serviceReference =
> + bundleContext.getServiceReference(CallHistoryService.class
> + .getName());
>
> - callHistoryService = (CallHistoryService) bundleContext
> - .getService(serviceReference);
> + callHistoryService =
> + (CallHistoryService) bundleContext.getService(serviceReference);
> }
>
> return callHistoryService;
> @@ -324,21 +374,22 @@
> /**
> * Returns the <tt>AudioNotifierService</tt> obtained from the bundle
> * context.
> + *
> * @return the <tt>AudioNotifierService</tt> obtained from the bundle
> - * context
> + * context
> */
> public static AudioNotifierService getAudioNotifier()
> {
> if (audioNotifierService == null)
> {
> - ServiceReference serviceReference
> - = bundleContext
> - .getServiceReference(AudioNotifierService.class.getName());
> + ServiceReference serviceReference =
> + bundleContext.getServiceReference(AudioNotifierService.class
> + .getName());
>
> if (serviceReference != null)
> - audioNotifierService
> - = (AudioNotifierService)
> - bundleContext.getService(serviceReference);
> + audioNotifierService =
> + (AudioNotifierService) bundleContext
> + .getService(serviceReference);
> }
> return audioNotifierService;
> }
> @@ -346,18 +397,21 @@
> /**
> * Returns the <tt>BrowserLauncherService</tt> obtained from the bundle
> * context.
> + *
> * @return the <tt>BrowserLauncherService</tt> obtained from the bundle
> - * context
> + * context
> */
> public static BrowserLauncherService getBrowserLauncher()
> {
> if (browserLauncherService == null)
> {
> - ServiceReference serviceReference = bundleContext
> - .getServiceReference(BrowserLauncherService.class.getName());
> + ServiceReference serviceReference =
> + bundleContext.getServiceReference(BrowserLauncherService.class
> + .getName());
>
> - browserLauncherService = (BrowserLauncherService) bundleContext
> - .getService(serviceReference);
> + browserLauncherService =
> + (BrowserLauncherService) bundleContext
> + .getService(serviceReference);
> }
>
> return browserLauncherService;
> @@ -365,6 +419,7 @@
>
> /**
> * Returns the current implementation of the <tt>UIService</tt>.
> + *
> * @return the current implementation of the <tt>UIService</tt>
> */
> public static UIServiceImpl getUIService()
> @@ -374,21 +429,22 @@
>
> /**
> * Returns the <tt>SystrayService</tt> obtained from the bundle context.
> - *
> + *
> * @return the <tt>SystrayService</tt> obtained from the bundle context
> */
> public static SystrayService getSystrayService()
> {
> if (systrayService == null)
> {
> - ServiceReference serviceReference = bundleContext
> - .getServiceReference(SystrayService.class.getName());
> + ServiceReference serviceReference =
> + bundleContext.getServiceReference(SystrayService.class
> + .getName());
>
> - if(serviceReference == null)
> + if (serviceReference == null)
> return null;
>
> - systrayService = (SystrayService) bundleContext
> - .getService(serviceReference);
> + systrayService =
> + (SystrayService) bundleContext.getService(serviceReference);
> }
>
> return systrayService;
> @@ -396,18 +452,19 @@
>
> /**
> * Returns the <tt>KeybindingsService</tt> obtained from the bundle context.
> - *
> + *
> * @return the <tt>KeybindingsService</tt> obtained from the bundle context
> */
> public static KeybindingsService getKeybindingsService()
> {
> if (keybindingsService == null)
> {
> - ServiceReference serviceReference = bundleContext
> - .getServiceReference(KeybindingsService.class.getName());
> + ServiceReference serviceReference =
> + bundleContext.getServiceReference(KeybindingsService.class
> + .getName());
>
> - keybindingsService = (KeybindingsService) bundleContext
> - .getService(serviceReference);
> + keybindingsService =
> + (KeybindingsService) bundleContext.getService(serviceReference);
> }
>
> return keybindingsService;
> @@ -416,41 +473,47 @@
> /**
> * Returns the <tt>ResourceManagementService</tt>, through which we will
> * access all resources.
> - *
> + *
> * @return the <tt>ResourceManagementService</tt>, through which we will
> - * access all resources.
> + * access all resources.
> */
> public static ResourceManagementService getResources()
> {
> if (resourcesService == null)
> {
> - ServiceReference serviceReference = bundleContext
> - .getServiceReference(ResourceManagementService.class.getName());
> + ServiceReference serviceReference =
> + bundleContext
> + .getServiceReference(ResourceManagementService.class
> + .getName());
>
> - if(serviceReference == null)
> + if (serviceReference == null)
> return null;
>
> - resourcesService = (ResourceManagementService) bundleContext
> - .getService(serviceReference);
> + resourcesService =
> + (ResourceManagementService) bundleContext
> + .getService(serviceReference);
> }
>
> return resourcesService;
> }
>
> /**
> - * Returns the <tt>NotificationService</tt> obtained from the bundle context.
> - *
> + * Returns the <tt>NotificationService</tt> obtained from the bundle
> + * context.
> + *
> * @return the <tt>NotificationService</tt> obtained from the bundle context
> */
> public static NotificationService getNotificationService()
> {
> if (notificationService == null)
> {
> - ServiceReference serviceReference = bundleContext
> - .getServiceReference(NotificationService.class.getName());
> + ServiceReference serviceReference =
> + bundleContext.getServiceReference(NotificationService.class
> + .getName());
>
> - notificationService = (NotificationService) bundleContext
> - .getService(serviceReference);
> + notificationService =
> + (NotificationService) bundleContext
> + .getService(serviceReference);
> }
>
> return notificationService;
> @@ -458,18 +521,19 @@
>
> /**
> * Returns the <tt>FileAccessService</tt> obtained from the bundle context.
> - *
> + *
> * @return the <tt>FileAccessService</tt> obtained from the bundle context
> */
> public static FileAccessService getFileAccessService()
> {
> if (fileAccessService == null)
> {
> - ServiceReference serviceReference = bundleContext
> - .getServiceReference(FileAccessService.class.getName());
> + ServiceReference serviceReference =
> + bundleContext.getServiceReference(FileAccessService.class
> + .getName());
>
> - fileAccessService = (FileAccessService) bundleContext
> - .getService(serviceReference);
> + fileAccessService =
> + (FileAccessService) bundleContext.getService(serviceReference);
> }
>
> return fileAccessService;
> @@ -477,69 +541,72 @@
>
> /**
> * Returns the <tt>DesktopService</tt> obtained from the bundle context.
> - *
> + *
> * @return the <tt>DesktopService</tt> obtained from the bundle context
> */
> public static DesktopService getDesktopService()
> {
> if (desktopService == null)
> {
> - ServiceReference serviceReference = bundleContext
> - .getServiceReference(DesktopService.class.getName());
> + ServiceReference serviceReference =
> + bundleContext.getServiceReference(DesktopService.class
> + .getName());
>
> - desktopService = (DesktopService) bundleContext
> - .getService(serviceReference);
> + desktopService =
> + (DesktopService) bundleContext.getService(serviceReference);
> }
>
> return desktopService;
> }
>
> /**
> - * Returns an instance of the <tt>MediaService</tt> obtained from the
> - * bundle context.
> - * @return an instance of the <tt>MediaService</tt> obtained from the
> - * bundle context
> + * Returns an instance of the <tt>MediaService</tt> obtained from the bundle
> + * context.
> + *
> + * @return an instance of the <tt>MediaService</tt> obtained from the bundle
> + * context
> */
> public static MediaService getMediaService()
> {
> if (mediaService == null)
> {
> - ServiceReference serviceReference = bundleContext
> - .getServiceReference(MediaService.class.getName());
> + ServiceReference serviceReference =
> + bundleContext.getServiceReference(MediaService.class.getName());
>
> - mediaService = (MediaService) bundleContext
> - .getService(serviceReference);
> + mediaService =
> + (MediaService) bundleContext.getService(serviceReference);
> }
>
> return mediaService;
> }
>
> /**
> - * Implements the <tt>ServiceListener</tt>. Verifies whether the
> - * passed event concerns a <tt>NotificationService</tt> and if so
> - * initiates the user interface NotificationManager.
> + * Implements the <tt>ServiceListener</tt>. Verifies whether the passed
> + * event concerns a <tt>NotificationService</tt> and if so initiates the
> + * user interface NotificationManager.
> */
> - private static class NotificationServiceListener implements ServiceListener
> + private static class NotificationServiceListener
> + implements ServiceListener
> {
> /**
> * Implements the <tt>ServiceListener</tt> method. Verifies whether the
> * passed event concerns a <tt>NotificationService</tt> and if so
> * initiates the NotificationManager.
> - *
> + *
> * @param event The <tt>ServiceEvent</tt> object.
> */
> public void serviceChanged(ServiceEvent event)
> {
> // if the event is caused by a bundle being stopped, we don't want
> // to know
> - if (event.getServiceReference().getBundle().getState()
> - == Bundle.STOPPING)
> + if (event.getServiceReference().getBundle().getState() == Bundle.STOPPING)
> {
> return;
> }
>
> - Object service = GuiActivator.bundleContext.getService(event
> - .getServiceReference());
> + Object service =
> + GuiActivator.bundleContext.getService(event
> + .getServiceReference());
>
> // we don't care if the source service is not a notification service
> if (!(service instanceof NotificationService))
> @@ -556,6 +623,7 @@
>
> /**
> * Returns a list of all registered contact sources.
> + *
> * @return a list of all registered contact sources
> */
> public static List<ContactSourceService> getContactSources()
> @@ -570,21 +638,20 @@
> {
> // get all registered provider factories
> serRefs =
> - bundleContext.getServiceReferences(
> - ContactSourceService.class.getName(), null);
> + bundleContext.getServiceReferences(ContactSourceService.class
> + .getName(), null);
> }
> catch (InvalidSyntaxException e)
> {
> logger.error("GuiActivator : " + e);
> }
>
> - if (serRefs != null)
> + if (serRefs != null)
> {
> for (int i = 0; i < serRefs.length; i++)
> {
> - ContactSourceService contactSource
> - = (ContactSourceService) bundleContext
> - .getService(serRefs[i]);
> + ContactSourceService contactSource =
> + (ContactSourceService) bundleContext.getService(serRefs[i]);
>
> contactSources.add(contactSource);
> }
> @@ -595,6 +662,7 @@
> /**
> * Sets the <tt>contactList</tt> component currently used to show the
> * contact list.
> + *
> * @param list the contact list object to set
> */
> public static void setContactList(TreeContactList list)
> @@ -604,6 +672,7 @@
>
> /**
> * Returns the component used to show the contact list.
> + *
> * @return the component used to show the contact list
> */
> public static TreeContactList getContactList()
>
> Modified: branches/gsoc10/previews/src/net/java/sip/communicator/impl/gui/main/chat/ChatConversationPanel.java
> Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/branches/gsoc10/previews/src/net/java/sip/communicator/impl/gui/main/chat/ChatConversationPanel.java?view=diff&rev=7237&p1=branches/gsoc10/previews/src/net/java/sip/communicator/impl/gui/main/chat/ChatConversationPanel.java&p2=branches/gsoc10/previews/src/net/java/sip/communicator/impl/gui/main/chat/ChatConversationPanel.java&r1=7236&r2=7237
> ==============================================================================
> --- branches/gsoc10/previews/src/net/java/sip/communicator/impl/gui/main/chat/ChatConversationPanel.java (original)
> +++ branches/gsoc10/previews/src/net/java/sip/communicator/impl/gui/main/chat/ChatConversationPanel.java 2010-06-12 14:14:41+0000
> @@ -1,8 +1,7 @@
> /*
> * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
> - *
> - * Distributable under LGPL license.
> - * See terms of license at gnu.org.
> + *
> + * Distributable under LGPL license. See terms of license at gnu.org.
> */
> package net.java.sip.communicator.impl.gui.main.chat;
>
> @@ -26,6 +25,9 @@
> import net.java.sip.communicator.service.gui.*;
> import net.java.sip.communicator.util.*;
> import net.java.sip.communicator.util.swing.*;
> +import net.java.sip.communicator.util.swing.SwingWorker;
> +
> +import net.java.sip.communicator.service.replacement.*;
>
> /**
> * The <tt>ChatConversationPanel</tt> is the panel, where all sent and received
> @@ -33,18 +35,16 @@
> * is applied to the document to provide the look&feel. All smileys and link
> * strings are processed and finally replaced by corresponding images and HTML
> * links.
> - *
> + *
> * @author Yana Stamcheva
> * @author Lubomir Marinov
> */
> public class ChatConversationPanel
> extends SCScrollPane
> - implements HyperlinkListener,
> - MouseListener,
> - ClipboardOwner
> + implements HyperlinkListener, MouseListener, ClipboardOwner
> {
> - private static final Logger logger
> - = Logger.getLogger(ChatConversationPanel.class);
> + private static final Logger logger =
> + Logger.getLogger(ChatConversationPanel.class);
>
> /**
> * The closing tag of the <code>PLAINTEXT</code> HTML element.
> @@ -60,16 +60,14 @@
> * The regular expression (in the form of compiled <tt>Pattern</tt>) which
> * matches URLs for the purposed of turning them into links.
> */
> - private static final Pattern URL_PATTERN
> - = Pattern.compile(
> - "("
> + private static final Pattern URL_PATTERN =
> + Pattern.compile("("
> + "(\\bwww\\.[^\\s<>\"]+\\.[^\\s<>\"]+/*[?#]*(\\w+[&=;?]\\w+)*\\b)" // wwwURL
> - + "|"
> - + "(\\b\\w+://[^\\s<>\"]+/*[?#]*(\\w+[&=;?]\\w+)*\\b)" // protocolURL
> + + "|" + "(\\b\\w+://[^\\s<>\"]+/*[?#]*(\\w+[&=;?]\\w+)*\\b)" // protocolURL
> + ")");
>
> /**
> - * The compiled <tt>Pattern</tt> which matches {@link #smileyStrings}.
> + * The compiled <tt>Pattern</tt> which matches {@link #smileyStrings}.
> */
> private static Pattern smileyPattern;
>
> @@ -77,8 +75,8 @@
> * The <tt>List</tt> of smiley strings which are matched by
> * {@link #smileyPattern}.
> */
> - private static final java.util.List<String> smileyStrings
> - = new ArrayList<String>();
> + private static final java.util.List<String> smileyStrings =
> + new ArrayList<String>();
>
> private final JTextPane chatTextPane = new MyTextPane();
>
> @@ -106,6 +104,9 @@
>
> public static final String TEXT_CONTENT_TYPE = "text/plain";
>
> + private Map<Object, ReplacementService> listsources =
> + new HashMap<Object, ReplacementService>();
> +
> /**
> * The indicator which determines whether an automatic scroll to the bottom
> * of {@link #chatTextPane} is to be performed.
> @@ -113,8 +114,8 @@
> private boolean scrollToBottomIsPending = false;
>
> /**
> - * The implementation of the routine which scrolls {@link #chatTextPane} to its
> - * bottom.
> + * The implementation of the routine which scrolls {@link #chatTextPane} to
> + * its bottom.
> */
> private final Runnable scrollToBottomRunnable = new Runnable()
> {
> @@ -132,7 +133,7 @@
>
> /**
> * Creates an instance of <tt>ChatConversationPanel</tt>.
> - *
> + *
> * @param chatContainer The parent <tt>ChatConversationContainer</tt>.
> */
> public ChatConversationPanel(ChatConversationContainer chatContainer)
> @@ -153,53 +154,52 @@
> this.chatTextPane.setDocument(document);
> this.chatTextPane.setDragEnabled(true);
>
> - chatTextPane.putClientProperty(
> - JEditorPane.HONOR_DISPLAY_PROPERTIES, Boolean.TRUE);
> - Constants.loadSimpleStyle(
> - document.getStyleSheet(), chatTextPane.getFont());
> + chatTextPane.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES,
> + Boolean.TRUE);
> + Constants.loadSimpleStyle(document.getStyleSheet(), chatTextPane
> + .getFont());
>
> this.chatTextPane.addHyperlinkListener(this);
> this.chatTextPane.addMouseListener(this);
> - this.chatTextPane.setCursor(
> - Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR));
> + this.chatTextPane.setCursor(Cursor
> + .getPredefinedCursor(Cursor.TEXT_CURSOR));
>
> this.setWheelScrollingEnabled(true);
>
> this.setViewportView(chatTextPane);
>
> - this.setHorizontalScrollBarPolicy(
> - JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
> + this
> + .setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
>
> ToolTipManager.sharedInstance().registerComponent(chatTextPane);
>
> - String copyLinkString
> - = GuiActivator.getResources().getI18NString("service.gui.COPY_LINK");
> + String copyLinkString =
> + GuiActivator.getResources().getI18NString("service.gui.COPY_LINK");
>
> copyLinkItem =
> - new JMenuItem(copyLinkString,
> - new ImageIcon(ImageLoader.getImage(ImageLoader.COPY_ICON)));
> + new JMenuItem(copyLinkString, new ImageIcon(ImageLoader
> + .getImage(ImageLoader.COPY_ICON)));
>
> copyLinkItem.addActionListener(new ActionListener()
> {
> public void actionPerformed(ActionEvent e)
> {
> - StringSelection stringSelection = new StringSelection(
> - currentHref);
> - Clipboard clipboard = Toolkit.getDefaultToolkit()
> - .getSystemClipboard();
> + StringSelection stringSelection =
> + new StringSelection(currentHref);
> + Clipboard clipboard =
> + Toolkit.getDefaultToolkit().getSystemClipboard();
> clipboard.setContents(stringSelection,
> ChatConversationPanel.this);
> }
> });
>
> - String openLinkString
> - = GuiActivator.getResources().getI18NString(
> + String openLinkString =
> + GuiActivator.getResources().getI18NString(
> "service.gui.OPEN_IN_BROWSER");
>
> openLinkItem =
> - new JMenuItem(
> - openLinkString,
> - new ImageIcon(ImageLoader.getImage(ImageLoader.BROWSER_ICON)));
> + new JMenuItem(openLinkString, new ImageIcon(ImageLoader
> + .getImage(ImageLoader.BROWSER_ICON)));
>
> openLinkItem.addActionListener(new ActionListener()
> {
> @@ -209,13 +209,11 @@
> }
> });
>
> - openLinkItem.setMnemonic(
> - GuiActivator.getResources().getI18nMnemonic(
> - "service.gui.OPEN_IN_BROWSER"));
> -
> - copyLinkItem.setMnemonic(
> - GuiActivator.getResources().getI18nMnemonic(
> - "service.gui.COPY_LINK"));
> + openLinkItem.setMnemonic(GuiActivator.getResources().getI18nMnemonic(
> + "service.gui.OPEN_IN_BROWSER"));
> +
> + copyLinkItem.setMnemonic(GuiActivator.getResources().getI18nMnemonic(
> + "service.gui.COPY_LINK"));
>
> /*
> * When we append a new message (regardless of whether it is a string or
> @@ -243,6 +241,8 @@
> };
> chatTextPane.addComponentListener(componentListener);
> getViewport().addComponentListener(componentListener);
> +
> + listsources = GuiActivator.getReplacementSources();
> }
>
> /*
> @@ -261,13 +261,13 @@
>
> if (verticalScrollBar != null)
> {
> - BoundedRangeModel verticalScrollBarModel
> - = verticalScrollBar.getModel();
> + BoundedRangeModel verticalScrollBarModel =
> + verticalScrollBar.getModel();
>
> if ((verticalScrollBarModel.getValue()
> - + verticalScrollBarModel.getExtent()
> - >= verticalScrollBarModel.getMaximum())
> - || !verticalScrollBar.isVisible())
> + + verticalScrollBarModel.getExtent() >= verticalScrollBarModel
> + .getMaximum())
> + || !verticalScrollBar.isVisible())
> scrollToBottomIsPending = true;
> }
> }
> @@ -276,34 +276,34 @@
> }
>
> /**
> - * Initializes the editor by adding a header containing the date.
> - * TODO: remove if not used anymore
> + * Initializes the editor by adding a header containing the date. TODO:
> + * remove if not used anymore
> */
> -// private void initEditor()
> -// {
> -// Element root = this.document.getDefaultRootElement();
> -//
> -// Date date = new Date(System.currentTimeMillis());
> -//
> -// String chatHeader = "<h1>" + GuiUtils.formatDate(date) + " " + "</h1>";
> -//
> -// try
> -// {
> -// this.document.insertAfterStart(root, chatHeader);
> -// }
> -// catch (BadLocationException e)
> -// {
> -// logger.error("Insert in the HTMLDocument failed.", e);
> -// }
> -// catch (IOException e)
> -// {
> -// logger.error("Insert in the HTMLDocument failed.", e);
> -// }
> -// }
> + // private void initEditor()
> + // {
> + // Element root = this.document.getDefaultRootElement();
> + //
> + // Date date = new Date(System.currentTimeMillis());
> + //
> + // String chatHeader = "<h1>" + GuiUtils.formatDate(date) + " " + "</h1>";
> + //
> + // try
> + // {
> + // this.document.insertAfterStart(root, chatHeader);
> + // }
> + // catch (BadLocationException e)
> + // {
> + // logger.error("Insert in the HTMLDocument failed.", e);
> + // }
> + // catch (IOException e)
> + // {
> + // logger.error("Insert in the HTMLDocument failed.", e);
> + // }
> + // }
>
> /**
> * Processes the message given by the parameters.
> - *
> + *
> * @param chatMessage the message
> * @param keyword
> * @return the processed message
> @@ -324,10 +324,10 @@
> String dateString = getDateString(date);
>
> String startDivTag = "<DIV identifier=\"" + msgID + "\">";
> - String startHistoryDivTag
> - = "<DIV identifier=\"" + msgID + "\" style=\"color:#707070;\">";
> - String startSystemDivTag
> - = "<DIV identifier=\"systemMessage\" style=\"color:#627EB7;\">";
> + String startHistoryDivTag =
> + "<DIV identifier=\"" + msgID + "\" style=\"color:#707070;\">";
> + String startSystemDivTag =
> + "<DIV identifier=\"systemMessage\" style=\"color:#627EB7;\">";
> String endDivTag = "</DIV>";
>
> String startPlainTextTag;
> @@ -348,30 +348,26 @@
> {
> this.lastIncomingMsgTimestamp = System.currentTimeMillis();
>
> - chatString = "<h2 identifier=\""
> - + msgHeaderID
> - + "\" date=\""
> - + date + "\">";
> + chatString =
> + "<h2 identifier=\"" + msgHeaderID + "\" date=\"" + date + "\">";
>
> endHeaderTag = "</h2>";
>
> - chatString
> - += dateString + contactName + " at " + GuiUtils.formatTime(date)
> + chatString +=
> + dateString + contactName + " at " + GuiUtils.formatTime(date)
> + endHeaderTag + startDivTag + startPlainTextTag
> + formatMessage(message, contentType, keyword)
> + endPlainTextTag + endDivTag;
> }
> else if (messageType.equals(Chat.SMS_MESSAGE))
> {
> - chatString = "<h2 identifier=\""
> - + msgHeaderID
> - + "\" date=\""
> - + date + "\">";
> + chatString =
> + "<h2 identifier=\"" + msgHeaderID + "\" date=\"" + date + "\">";
>
> endHeaderTag = "</h2>";
>
> - chatString
> - += "SMS: " + dateString + contactName + " at "
> + chatString +=
> + "SMS: " + dateString + contactName + " at "
> + GuiUtils.formatTime(date) + endHeaderTag + startDivTag
> + startPlainTextTag
> + formatMessage(message, contentType, keyword)
> @@ -379,97 +375,87 @@
> }
> else if (messageType.equals(Chat.OUTGOING_MESSAGE))
> {
> - chatString = "<h3 identifier=\""
> - + msgHeaderID
> - + "\" date=\""
> - + date + "\">";
> + chatString =
> + "<h3 identifier=\"" + msgHeaderID + "\" date=\"" + date + "\">";
>
> endHeaderTag = "</h3>";
>
> - chatString
> - += dateString
> - + GuiActivator
> - .getResources().getI18NString("service.gui.ME")
> - + " at " + GuiUtils.formatTime(date) + endHeaderTag
> - + startDivTag + startPlainTextTag
> + chatString +=
> + dateString
> + + GuiActivator.getResources().getI18NString(
> + "service.gui.ME") + " at " + GuiUtils.formatTime(date)
> + + endHeaderTag + startDivTag + startPlainTextTag
> + formatMessage(message, contentType, keyword)
> + endPlainTextTag + endDivTag;
> }
> else if (messageType.equals(Chat.STATUS_MESSAGE))
> {
> - chatString = "<h4 identifier=\"statusMessage\" date=\""
> - + date + "\">";
> + chatString =
> + "<h4 identifier=\"statusMessage\" date=\"" + date + "\">";
> endHeaderTag = "</h4>";
>
> - chatString
> - += GuiUtils.formatTime(date) + " " + contactName + " " + message
> + chatString +=
> + GuiUtils.formatTime(date) + " " + contactName + " " + message
> + endHeaderTag;
> }
> else if (messageType.equals(Chat.ACTION_MESSAGE))
> {
> - chatString = "<p identifier=\"actionMessage\" date=\""
> - + date + "\">";
> + chatString =
> + "<p identifier=\"actionMessage\" date=\"" + date + "\">";
> endHeaderTag = "</p>";
>
> - chatString += "* " + GuiUtils.formatTime(date)
> - + " " + contactName + " "
> - + message
> - + endHeaderTag;
> + chatString +=
> + "* " + GuiUtils.formatTime(date) + " " + contactName + " "
> + + message + endHeaderTag;
> }
> else if (messageType.equals(Chat.SYSTEM_MESSAGE))
> {
> - chatString
> - += startSystemDivTag + startPlainTextTag
> + chatString +=
> + startSystemDivTag + startPlainTextTag
> + formatMessage(message, contentType, keyword)
> + endPlainTextTag + endDivTag;
> }
> else if (messageType.equals(Chat.ERROR_MESSAGE))
> {
> - chatString = "<h6 identifier=\""
> - + msgHeaderID
> - + "\" date=\""
> - + date + "\">";
> + chatString =
> + "<h6 identifier=\"" + msgHeaderID + "\" date=\"" + date + "\">";
>
> endHeaderTag = "</h6>";
>
> - String errorIcon = "<IMG SRC='"
> - + ImageLoader.getImageUri(ImageLoader.EXCLAMATION_MARK)
> - + "' </IMG>";
> -
> - chatString += errorIcon
> - + messageTitle
> - + endHeaderTag + "<h5>" + message + "</h5>";
> + String errorIcon =
> + "<IMG SRC='"
> + + ImageLoader.getImageUri(ImageLoader.EXCLAMATION_MARK)
> + + "' </IMG>";
> +
> + chatString +=
> + errorIcon + messageTitle + endHeaderTag + "<h5>" + message
> + + "</h5>";
> }
> else if (messageType.equals(Chat.HISTORY_INCOMING_MESSAGE))
> {
> - chatString = "<h2 identifier='"
> - + msgHeaderID
> - + "' date=\""
> - + date + "\">";
> + chatString =
> + "<h2 identifier='" + msgHeaderID + "' date=\"" + date + "\">";
>
> endHeaderTag = "</h2>";
>
> - chatString
> - += dateString + contactName + " at " + GuiUtils.formatTime(date)
> + chatString +=
> + dateString + contactName + " at " + GuiUtils.formatTime(date)
> + endHeaderTag + startHistoryDivTag + startPlainTextTag
> + formatMessage(message, contentType, keyword)
> + endPlainTextTag + endDivTag;
> }
> else if (messageType.equals(Chat.HISTORY_OUTGOING_MESSAGE))
> {
> - chatString = "<h3 identifier=\""
> - + msgHeaderID
> - + "\" date=\""
> - + date + "\">";
> + chatString =
> + "<h3 identifier=\"" + msgHeaderID + "\" date=\"" + date + "\">";
>
> endHeaderTag = "</h3>";
>
> - chatString
> - += dateString
> - + GuiActivator
> - .getResources().getI18NString("service.gui.ME")
> - + " at " + GuiUtils.formatTime(date) + endHeaderTag
> - + startHistoryDivTag + startPlainTextTag
> + chatString +=
> + dateString
> + + GuiActivator.getResources().getI18NString(
> + "service.gui.ME") + " at " + GuiUtils.formatTime(date)
> + + endHeaderTag + startHistoryDivTag + startPlainTextTag
> + formatMessage(message, contentType, keyword)
> + endPlainTextTag + endDivTag;
> }
> @@ -479,7 +465,7 @@
>
> /**
> * Processes the message given by the parameters.
> - *
> + *
> * @param chatMessage the message.
> * @return the formatted message
> */
> @@ -491,7 +477,7 @@
> /**
> * Appends the given string at the end of the contained in this panel
> * document.
> - *
> + *
> * @param chatString the string to append
> */
> public void appendMessageToEnd(String chatString)
> @@ -504,10 +490,8 @@
>
> try
> {
> - document
> - .insertAfterEnd(
> - root.getElement(root.getElementCount() - 1),
> - chatString);
> + document.insertAfterEnd(root
> + .getElement(root.getElementCount() - 1), chatString);
> }
> catch (BadLocationException e)
> {
> @@ -519,10 +503,96 @@
> }
> if (!isHistory)
> ensureDocumentSize();
> +
> + final Element elem;
> +
> + /*
> + * Check to make sure element isn't the first element in the HTML
> + * document.
> + */
> + if (!(root.getElementCount() < 2))
> + {
> + elem = root.getElement(root.getElementCount() - 2);
> + }
> + else
> + elem = root.getElement(1);
> +
> + String prefix =
> + "net.java.sip.communicator.impl.gui.replacement.isEnabled";
> + String obj =
> + (String) GuiActivator.getConfigurationService().getProperty(
> + prefix);
> + /*
> + * Replacements will be processed only if it is enabled in the
> + * property
> + */
> + if (obj != null && Boolean.parseBoolean(obj))
> + {
> + processReplacement(elem, chatString);
> + }
> }
> }
>
> /**
> + * Formats the given message. Processes the messages and replaces links to
> + * video/image sources with their previews or any other substitution. Spawns
> + * a separate thread for replacement.
> + *
> + * @param elem the element in the HTML Document.
> + * @param chatString the message.
> + */
> + private void processReplacement(final Element elem, final String chatString)
> + {
> +
> + final String chatFinal = chatString;
> +
> + SwingWorker worker = new SwingWorker()
> + {
> +
> + @Override
> + public Object construct() throws Exception
> + {
> + String temp = "", msgStore = chatFinal;
> +
> + Iterator entrySetIter = listsources.entrySet().iterator();
> +
> + for (int i = 0; i < listsources.size(); i++)
> + {
> +
> + Map.Entry entry = (Map.Entry) entrySetIter.next();
> + ReplacementService source =
> + (ReplacementService) entry.getValue();
> +
> + temp = source.getReplacedMessage(msgStore);
> +
> + /*
> + * replace the msgStore variable with the current replaced
> + * message before next iteration
> + */
> +
> + if (!temp.equals(msgStore))
> + {
> + msgStore = temp;
> + }
> + }
> +
> + if (!temp.equals(chatFinal))
> + {
> + synchronized (scrollToBottomRunnable)
> + {
> + scrollToBottomIsPending = true;
> + document.setOuterHTML(elem, temp.toString().substring(
> + temp.indexOf("<DIV")));
> + }
> + }
> +
> + return "";
> + }
> + };
> + worker.start();
> + }
> +
> + /**
> * Ensures that the document won't become too big. When the document reaches
> * a certain size the first message in the page is removed.
> */
> @@ -540,15 +610,16 @@
> // Count how many messages we have in the document.
> for (int i = 0; i < rootElement.getElementCount(); i++)
> {
> - String idAttr = (String) rootElement.getElement(i)
> - .getAttributes().getAttribute("identifier");
> + String idAttr =
> + (String) rootElement.getElement(i).getAttributes()
> + .getAttribute("identifier");
>
> - if(idAttr != null
> + if (idAttr != null
> && (idAttr.equals("message")
> - || idAttr.equals("statusMessage")
> - || idAttr.equals("systemMessage")))
> + || idAttr.equals("statusMessage") || idAttr
> + .equals("systemMessage")))
> {
> - if(firstMsgElement == null)
> + if (firstMsgElement == null)
> {
> firstMsgElement = rootElement.getElement(i);
> firstMsgIndex = i;
> @@ -560,20 +631,22 @@
>
> // If we doesn't have any known elements in the document or if we
> // have only one long message we don't want to remove it.
> - if(firstMsgElement == null || msgElementCount < 2)
> + if (firstMsgElement == null || msgElementCount < 2)
> return;
>
> try
> {
> // Remove the header of the message if such exists.
> - if(firstMsgIndex > 0)
> + if (firstMsgIndex > 0)
> {
> - Element headerElement = rootElement.getElement(firstMsgIndex - 1);
> + Element headerElement =
> + rootElement.getElement(firstMsgIndex - 1);
>
> - String idAttr = (String) headerElement
> - .getAttributes().getAttribute("identifier");
> + String idAttr =
> + (String) headerElement.getAttributes().getAttribute(
> + "identifier");
>
> - if(idAttr != null && idAttr.equals("messageHeader"))
> + if (idAttr != null && idAttr.equals("messageHeader"))
> {
> this.document.remove(headerElement.getStartOffset(),
> headerElement.getEndOffset()
> @@ -583,8 +656,8 @@
>
> // Remove the message itself.
> this.document.remove(firstMsgElement.getStartOffset(),
> - firstMsgElement.getEndOffset()
> - - firstMsgElement.getStartOffset());
> + firstMsgElement.getEndOffset()
> + - firstMsgElement.getStartOffset());
> }
> catch (BadLocationException e)
> {
> @@ -595,15 +668,14 @@
>
> /**
> * Highlights keywords searched in the history.
> - *
> + *
> * @param message the source message
> * @param contentType the content type
> * @param keyword the searched keyword
> * @return the formatted message
> */
> - private String processKeyword( String message,
> - String contentType,
> - String keyword)
> + private String processKeyword(String message, String contentType,
> + String keyword)
> {
> String startPlainTextTag;
> String endPlainTextTag;
> @@ -619,9 +691,8 @@
> endPlainTextTag = END_PLAINTEXT_TAG;
> }
>
> - Matcher m
> - = Pattern
> - .compile(keyword, Pattern.CASE_INSENSITIVE).matcher(message);
> + Matcher m =
> + Pattern.compile(keyword, Pattern.CASE_INSENSITIVE).matcher(message);
> StringBuffer msgBuffer = new StringBuffer();
> int prevEnd = 0;
>
> @@ -653,15 +724,14 @@
> /**
> * Formats the given message. Processes all smiley chars, new lines and
> * links.
> - *
> + *
> * @param message the message to be formatted
> * @param contentType the content type of the message to be formatted
> * @param keyword the word to be highlighted
> * @return the formatted message
> */
> - private String formatMessage(String message,
> - String contentType,
> - String keyword)
> + private String formatMessage(String message, String contentType,
> + String keyword)
> {
> // If the message content type is HTML we won't process links and
> // new lines, but only the smileys.
> @@ -677,8 +747,8 @@
>
> if ((keyword != null) && (keyword.length() != 0))
> {
> - String messageWithProcessedKeyword
> - = processKeyword(message, contentType, keyword);
> + String messageWithProcessedKeyword =
> + processKeyword(message, contentType, keyword);
>
> /*
> * The same String instance will be returned if there was no
> @@ -691,9 +761,9 @@
> else
> processHTMLChars = true;
>
> - message
> - = processNewLines(
> - processLinksAndHTMLChars(message, processHTMLChars));
> + message =
> + processNewLines(processLinksAndHTMLChars(message,
> + processHTMLChars));
> }
> // If the message content is HTML, we process br and img tags.
> else
> @@ -703,9 +773,7 @@
> message = processImgTags(processBrTags(message));
> }
>
> - if (ConfigurationManager.isShowSmileys())
> - message = processSmileys(message, contentType);
> -
> + // return processSmileys(message, contentType);
> return message;
> }
>
> @@ -719,12 +787,12 @@
> * characters such as &amp;.
> *
> * @param message The source message string.
> - * @param processHTMLChars <tt>true</tt> to escape the special HTML chars;
> - * otherwise, <tt>false</tt>
> + * @param processHTMLChars <tt>true</tt> to escape the special HTML chars;
> + * otherwise, <tt>false</tt>
> * @return The message string with properly formatted links.
> */
> private String processLinksAndHTMLChars(String message,
> - boolean processHTMLChars)
> + boolean processHTMLChars)
> {
> Matcher m = URL_PATTERN.matcher(message);
> StringBuffer msgBuffer = new StringBuffer();
> @@ -764,23 +832,19 @@
> /**
> * Escapes special HTML characters such as &lt;, &gt;, &amp; and &quot; in
> * the specified message.
> - *
> + *
> * @param message the message to be processed
> * @return the processed message with escaped special HTML characters
> */
> private String processHTMLChars(String message)
> {
> - return
> - message
> - .replace("&", "&amp;")
> - .replace("<", "&lt;")
> - .replace(">", "&gt;")
> - .replace("\"", "&quot;");
> + return message.replace("&", "&amp;").replace("<", "&lt;").replace(">",
> + "&gt;").replace("\"", "&quot;");
> }
>
> /**
> * Formats message new lines.
> - *
> + *
> * @param message The source message string.
> * @return The message string with properly formatted new lines.
> */
> @@ -791,23 +855,20 @@
> * <br> tags are needed to visualize a new line in the html format, but

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@sip-communicator.dev.java.net
For additional commands, e-mail: dev-help@sip-communicator.dev.java.net