aboutsummaryrefslogtreecommitdiffstats
path: root/src/net/java/sip/communicator/plugin/otr/OtrActivator.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/net/java/sip/communicator/plugin/otr/OtrActivator.java')
-rw-r--r--src/net/java/sip/communicator/plugin/otr/OtrActivator.java425
1 files changed, 214 insertions, 211 deletions
diff --git a/src/net/java/sip/communicator/plugin/otr/OtrActivator.java b/src/net/java/sip/communicator/plugin/otr/OtrActivator.java
index b5309ab..3b10939 100644
--- a/src/net/java/sip/communicator/plugin/otr/OtrActivator.java
+++ b/src/net/java/sip/communicator/plugin/otr/OtrActivator.java
@@ -28,10 +28,29 @@ public class OtrActivator
implements ServiceListener
{
/**
- * A property used in configuration to disable the OTR plugin.
+ * A property specifying whether private messaging should be automatically
+ * initiated.
*/
- public static final String OTR_DISABLED_PROP =
- "net.java.sip.communicator.plugin.otr.DISABLED";
+ public static final String AUTO_INIT_OTR_PROP =
+ "net.java.sip.communicator.plugin.otr.AUTO_INIT_PRIVATE_MESSAGING";
+
+ /**
+ * The {@link BundleContext} of the {@link OtrActivator}.
+ */
+ public static BundleContext bundleContext;
+
+ /**
+ * The {@link ConfigurationService} of the {@link OtrActivator}. Can also be
+ * obtained from the {@link OtrActivator#bundleContext} on demand, but we
+ * add it here for convenience.
+ */
+ public static ConfigurationService configService;
+
+ /**
+ * The <tt>Logger</tt> used by the <tt>OtrActivator</tt> class and its
+ * instances for logging output.
+ */
+ private static final Logger logger = Logger.getLogger(OtrActivator.class);
/**
* Indicates if the security/chat config form should be disabled, i.e.
@@ -41,24 +60,23 @@ public class OtrActivator
= "net.java.sip.communicator.plugin.otr.otrchatconfig.DISABLED";
/**
- * A property specifying whether private messaging should be made mandatory.
+ * A property used in configuration to disable the OTR plugin.
*/
- public static final String OTR_MANDATORY_PROP =
- "net.java.sip.communicator.plugin.otr.PRIVATE_MESSAGING_MANDATORY";
+ public static final String OTR_DISABLED_PROP =
+ "net.java.sip.communicator.plugin.otr.DISABLED";
/**
- * A property specifying whether private messaging should be automatically
- * initiated.
+ * A property specifying whether private messaging should be made mandatory.
*/
- public static final String AUTO_INIT_OTR_PROP =
- "net.java.sip.communicator.plugin.otr.AUTO_INIT_PRIVATE_MESSAGING";
+ public static final String OTR_MANDATORY_PROP =
+ "net.java.sip.communicator.plugin.otr.PRIVATE_MESSAGING_MANDATORY";
/**
- * The {@link BundleContext} of the {@link OtrActivator}.
+ * The {@link ResourceManagementService} of the {@link OtrActivator}. Can
+ * also be obtained from the {@link OtrActivator#bundleContext} on demand,
+ * but we add it here for convenience.
*/
- public static BundleContext bundleContext;
-
- private OtrTransformLayer otrTransformLayer;
+ public static ResourceManagementService resourceService;
/**
* The {@link ScOtrEngine} of the {@link OtrActivator}.
@@ -71,13 +89,6 @@ public class OtrActivator
public static ScOtrKeyManager scOtrKeyManager = new ScOtrKeyManagerImpl();
/**
- * The {@link ResourceManagementService} of the {@link OtrActivator}. Can
- * also be obtained from the {@link OtrActivator#bundleContext} on demand,
- * but we add it here for convenience.
- */
- public static ResourceManagementService resourceService;
-
- /**
* The {@link UIService} of the {@link OtrActivator}. Can also be obtained
* from the {@link OtrActivator#bundleContext} on demand, but we add it here
* for convenience.
@@ -85,17 +96,176 @@ public class OtrActivator
public static UIService uiService;
/**
- * The {@link ConfigurationService} of the {@link OtrActivator}. Can also be
- * obtained from the {@link OtrActivator#bundleContext} on demand, but we
- * add it here for convenience.
+ * Gets an {@link AccountID} by its UID.
+ *
+ * @param uid The {@link AccountID} UID.
+ * @return The {@link AccountID} with the requested UID or null.
*/
- public static ConfigurationService configService;
+ public static AccountID getAccountIDByUID(String uid)
+ {
+ if (uid == null || uid.length() < 1)
+ return null;
+
+ Map<Object, ProtocolProviderFactory> providerFactoriesMap =
+ OtrActivator.getProtocolProviderFactories();
+
+ if (providerFactoriesMap == null)
+ return null;
+
+ for (ProtocolProviderFactory providerFactory
+ : providerFactoriesMap.values())
+ {
+ for (AccountID accountID : providerFactory.getRegisteredAccounts())
+ {
+ if (accountID.getAccountUniqueID().equals(uid))
+ return accountID;
+ }
+ }
+
+ return null;
+ }
/**
- * The <tt>Logger</tt> used by the <tt>OtrActivator</tt> class and its
- * instances for logging output.
+ * Gets all the available accounts in SIP Communicator.
+ *
+ * @return a {@link List} of {@link AccountID}.
*/
- private static final Logger logger = Logger.getLogger(OtrActivator.class);
+ public static List<AccountID> getAllAccountIDs()
+ {
+ Map<Object, ProtocolProviderFactory> providerFactoriesMap =
+ OtrActivator.getProtocolProviderFactories();
+
+ if (providerFactoriesMap == null)
+ return null;
+
+ List<AccountID> accountIDs = new Vector<AccountID>();
+
+ for (ProtocolProviderFactory providerFactory
+ : providerFactoriesMap.values())
+ {
+ for (AccountID accountID : providerFactory.getRegisteredAccounts())
+ accountIDs.add(accountID);
+ }
+
+ return accountIDs;
+ }
+
+ private static Map<Object, ProtocolProviderFactory>
+ getProtocolProviderFactories()
+ {
+ ServiceReference[] serRefs = null;
+ try
+ {
+ // get all registered provider factories
+ serRefs =
+ bundleContext.getServiceReferences(
+ ProtocolProviderFactory.class.getName(), null);
+
+ }
+ catch (InvalidSyntaxException ex)
+ {
+ logger.error("Error while retrieving service refs", ex);
+ return null;
+ }
+
+ Map<Object, ProtocolProviderFactory> providerFactoriesMap =
+ new Hashtable<Object, ProtocolProviderFactory>();
+ if (serRefs != null)
+ {
+ for (ServiceReference serRef : serRefs)
+ {
+ ProtocolProviderFactory providerFactory =
+ (ProtocolProviderFactory) bundleContext.getService(serRef);
+
+ providerFactoriesMap.put(serRef
+ .getProperty(ProtocolProviderFactory.PROTOCOL),
+ providerFactory);
+ }
+ }
+ return providerFactoriesMap;
+ }
+
+ private OtrTransformLayer otrTransformLayer;
+
+ /**
+ * The dependent class. We are waiting for the ui service.
+ * @return the ui service class.
+ */
+ @Override
+ public Class<?> getDependentServiceClass()
+ {
+ return UIService.class;
+ }
+
+ private void handleProviderAdded(ProtocolProviderService provider)
+ {
+ OperationSetInstantMessageTransform opSetMessageTransform
+ = provider.getOperationSet(
+ OperationSetInstantMessageTransform.class);
+
+ if (opSetMessageTransform != null)
+ opSetMessageTransform.addTransformLayer(this.otrTransformLayer);
+ else if (logger.isTraceEnabled())
+ logger.trace("Service did not have a transform op. set.");
+ }
+
+ private void handleProviderRemoved(ProtocolProviderService provider)
+ {
+ // check whether the provider has a basic im operation set
+ OperationSetInstantMessageTransform opSetMessageTransform
+ = provider.getOperationSet(
+ OperationSetInstantMessageTransform.class);
+
+ if (opSetMessageTransform != null)
+ opSetMessageTransform.removeTransformLayer(this.otrTransformLayer);
+ }
+
+ /*
+ * Implements ServiceListener#serviceChanged(ServiceEvent).
+ */
+ public void serviceChanged(ServiceEvent serviceEvent)
+ {
+ Object sService =
+ bundleContext.getService(serviceEvent.getServiceReference());
+
+ if (logger.isTraceEnabled())
+ {
+ logger.trace(
+ "Received a service event for: "
+ + sService.getClass().getName());
+ }
+
+ // we don't care if the source service is not a protocol provider
+ if (!(sService instanceof ProtocolProviderService))
+ return;
+
+ if (logger.isDebugEnabled())
+ logger.debug("Service is a protocol provider.");
+ if (serviceEvent.getType() == ServiceEvent.REGISTERED)
+ {
+ if (logger.isDebugEnabled())
+ {
+ logger.debug(
+ "Handling registration of a new Protocol Provider.");
+ }
+ this.handleProviderAdded((ProtocolProviderService) sService);
+ }
+ else if (serviceEvent.getType() == ServiceEvent.UNREGISTERING)
+ {
+ this.handleProviderRemoved((ProtocolProviderService) sService);
+ }
+
+ }
+
+ /**
+ * The bundle context to use.
+ * @param context the context to set.
+ */
+ @Override
+ public void setBundleContext(BundleContext context)
+ {
+ bundleContext = context;
+ }
/*
* Implements AbstractServiceDependentActivator#start(UIService).
@@ -130,22 +300,26 @@ public class OtrActivator
// Register Transformation Layer
bundleContext.addServiceListener(this);
+ bundleContext.addServiceListener((ServiceListener) scOtrEngine);
- ServiceReference[] protocolProviderRefs = ServiceUtils
- .getServiceReferences(
- bundleContext,
- ProtocolProviderService.class);
+ ServiceReference[] protocolProviderRefs
+ = ServiceUtils.getServiceReferences(
+ bundleContext,
+ ProtocolProviderService.class);
if (protocolProviderRefs != null && protocolProviderRefs.length > 0)
{
if (logger.isDebugEnabled())
- logger.debug("Found " + protocolProviderRefs.length
- + " already installed providers.");
+ {
+ logger.debug(
+ "Found " + protocolProviderRefs.length
+ + " already installed providers.");
+ }
for (ServiceReference protocolProviderRef : protocolProviderRefs)
{
- ProtocolProviderService provider =
- (ProtocolProviderService) bundleContext
- .getService(protocolProviderRef);
+ ProtocolProviderService provider
+ = (ProtocolProviderService)
+ bundleContext.getService(protocolProviderRef);
this.handleProviderAdded(provider);
}
@@ -153,13 +327,13 @@ public class OtrActivator
if(!OSUtils.IS_ANDROID)
{
- Hashtable<String, String> containerFilter = new Hashtable<String, String>();
+ Hashtable<String, String> containerFilter
+ = new Hashtable<String, String>();
// Register the right-click menu item.
containerFilter.put(Container.CONTAINER_ID,
Container.CONTAINER_CONTACT_RIGHT_BUTTON_MENU.getID());
-
bundleContext
.registerService(PluginComponent.class.getName(),
new OtrMetaContactMenu(
@@ -197,6 +371,7 @@ public class OtrActivator
{
Dictionary<String, String> properties
= new Hashtable<String, String>();
+
properties.put( ConfigurationForm.FORM_TYPE,
ConfigurationForm.SECURITY_TYPE);
// Register the configuration form.
@@ -210,43 +385,6 @@ public class OtrActivator
}
}
- /**
- * The dependent class. We are waiting for the ui service.
- * @return the ui service class.
- */
- @Override
- public Class<?> getDependentServiceClass()
- {
- return UIService.class;
- }
-
- /**
- * The bundle context to use.
- * @param context the context to set.
- */
- @Override
- public void setBundleContext(BundleContext context)
- {
- bundleContext = context;
- }
-
- private void handleProviderAdded(ProtocolProviderService provider)
- {
- OperationSetInstantMessageTransform opSetMessageTransform
- = provider
- .getOperationSet(OperationSetInstantMessageTransform.class);
-
- if (opSetMessageTransform != null)
- {
- opSetMessageTransform.addTransformLayer(this.otrTransformLayer);
- }
- else
- {
- if (logger.isTraceEnabled())
- logger.trace("Service did not have a transform op. set.");
- }
- }
-
/*
* Implements BundleActivator#stop(BundleContext).
*/
@@ -284,139 +422,4 @@ public class OtrActivator
}
}
}
-
- private void handleProviderRemoved(ProtocolProviderService provider)
- {
- // check whether the provider has a basic im operation set
- OperationSetInstantMessageTransform opSetMessageTransform
- = provider
- .getOperationSet(OperationSetInstantMessageTransform.class);
-
- if (opSetMessageTransform != null)
- {
- opSetMessageTransform.removeTransformLayer(this.otrTransformLayer);
- }
- }
-
- /*
- * Implements ServiceListener#serviceChanged(ServiceEvent).
- */
- public void serviceChanged(ServiceEvent serviceEvent)
- {
- Object sService =
- bundleContext.getService(serviceEvent.getServiceReference());
-
- if (logger.isTraceEnabled())
- logger.trace("Received a service event for: "
- + sService.getClass().getName());
-
- // we don't care if the source service is not a protocol provider
- if (!(sService instanceof ProtocolProviderService))
- return;
-
- if (logger.isDebugEnabled())
- logger.debug("Service is a protocol provider.");
- if (serviceEvent.getType() == ServiceEvent.REGISTERED)
- {
- if (logger.isDebugEnabled())
- logger.debug("Handling registration of a new Protocol Provider.");
-
- this.handleProviderAdded((ProtocolProviderService) sService);
- }
- else if (serviceEvent.getType() == ServiceEvent.UNREGISTERING)
- {
- this.handleProviderRemoved((ProtocolProviderService) sService);
- }
-
- }
-
- /**
- * Gets all the available accounts in SIP Communicator.
- *
- * @return a {@link List} of {@link AccountID}.
- */
- public static List<AccountID> getAllAccountIDs()
- {
- Map<Object, ProtocolProviderFactory> providerFactoriesMap =
- OtrActivator.getProtocolProviderFactories();
-
- if (providerFactoriesMap == null)
- return null;
-
- List<AccountID> accountIDs = new Vector<AccountID>();
- for (ProtocolProviderFactory providerFactory : providerFactoriesMap
- .values())
- {
- for (AccountID accountID : providerFactory.getRegisteredAccounts())
- {
- accountIDs.add(accountID);
- }
- }
-
- return accountIDs;
- }
-
- /**
- * Gets an {@link AccountID} by its UID.
- *
- * @param uid The {@link AccountID} UID.
- * @return The {@link AccountID} with the requested UID or null.
- */
- public static AccountID getAccountIDByUID(String uid)
- {
- if (uid == null || uid.length() < 1)
- return null;
-
- Map<Object, ProtocolProviderFactory> providerFactoriesMap =
- OtrActivator.getProtocolProviderFactories();
-
- if (providerFactoriesMap == null)
- return null;
-
- for (ProtocolProviderFactory providerFactory : providerFactoriesMap
- .values())
- {
- for (AccountID accountID : providerFactory.getRegisteredAccounts())
- {
- if (accountID.getAccountUniqueID().equals(uid))
- return accountID;
- }
- }
-
- return null;
- }
-
- private static Map<Object, ProtocolProviderFactory> getProtocolProviderFactories()
- {
- ServiceReference[] serRefs = null;
- try
- {
- // get all registered provider factories
- serRefs =
- bundleContext.getServiceReferences(
- ProtocolProviderFactory.class.getName(), null);
-
- }
- catch (InvalidSyntaxException ex)
- {
- logger.error("Error while retrieving service refs", ex);
- return null;
- }
-
- Map<Object, ProtocolProviderFactory> providerFactoriesMap =
- new Hashtable<Object, ProtocolProviderFactory>();
- if (serRefs != null)
- {
- for (ServiceReference serRef : serRefs)
- {
- ProtocolProviderFactory providerFactory =
- (ProtocolProviderFactory) bundleContext.getService(serRef);
-
- providerFactoriesMap.put(serRef
- .getProperty(ProtocolProviderFactory.PROTOCOL),
- providerFactory);
- }
- }
- return providerFactoriesMap;
- }
}