aboutsummaryrefslogtreecommitdiffstats
path: root/src/net/java/sip/communicator/impl/browserlauncher
diff options
context:
space:
mode:
authorYana Stamcheva <yana@jitsi.org>2007-01-25 13:07:34 +0000
committerYana Stamcheva <yana@jitsi.org>2007-01-25 13:07:34 +0000
commit05108fc89d0669b27919de720f6a5c553be519d1 (patch)
treef0da9becede0da4d990d992b5fb296b652c211f4 /src/net/java/sip/communicator/impl/browserlauncher
parent9e2445a9e9ff0b74ef7bd2ad6bfac3908f0d971e (diff)
downloadjitsi-05108fc89d0669b27919de720f6a5c553be519d1.zip
jitsi-05108fc89d0669b27919de720f6a5c553be519d1.tar.gz
jitsi-05108fc89d0669b27919de720f6a5c553be519d1.tar.bz2
Browser Launcher service and implementation - allows to open an URL in the default browser
Diffstat (limited to 'src/net/java/sip/communicator/impl/browserlauncher')
-rw-r--r--src/net/java/sip/communicator/impl/browserlauncher/BrowserLauncherActivator.java47
-rw-r--r--src/net/java/sip/communicator/impl/browserlauncher/BrowserLauncherImpl.java64
-rw-r--r--src/net/java/sip/communicator/impl/browserlauncher/browserlauncher.manifest.mf10
3 files changed, 121 insertions, 0 deletions
diff --git a/src/net/java/sip/communicator/impl/browserlauncher/BrowserLauncherActivator.java b/src/net/java/sip/communicator/impl/browserlauncher/BrowserLauncherActivator.java
new file mode 100644
index 0000000..7e1ddb4
--- /dev/null
+++ b/src/net/java/sip/communicator/impl/browserlauncher/BrowserLauncherActivator.java
@@ -0,0 +1,47 @@
+/*
+ * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package net.java.sip.communicator.impl.browserlauncher;
+
+import net.java.sip.communicator.service.browserlauncher.*;
+import net.java.sip.communicator.util.*;
+
+import org.osgi.framework.*;
+
+/**
+ * The activator for the browserlauncher bundle.
+ * @author Yana Stamcheva
+ */
+public class BrowserLauncherActivator
+ implements
+ BundleActivator
+{
+ private static Logger logger
+ = Logger.getLogger(BrowserLauncherActivator.class.getName());
+
+ private BundleContext bundleContext;
+
+ private BrowserLauncherImpl browserLauncher;
+
+ public void start(BundleContext bc)
+ throws Exception
+ {
+ bundleContext = bc;
+
+ //Create the browser launcher service
+ this.browserLauncher = new BrowserLauncherImpl();
+
+ logger.info("UI Service...[ STARTED ]");
+
+ bundleContext.registerService(BrowserLauncherService.class.getName(),
+ this.browserLauncher, null);
+
+ logger.info("UI Service ...[REGISTERED]");
+ }
+
+ public void stop(BundleContext arg0) throws Exception
+ {}
+}
diff --git a/src/net/java/sip/communicator/impl/browserlauncher/BrowserLauncherImpl.java b/src/net/java/sip/communicator/impl/browserlauncher/BrowserLauncherImpl.java
new file mode 100644
index 0000000..55f947b
--- /dev/null
+++ b/src/net/java/sip/communicator/impl/browserlauncher/BrowserLauncherImpl.java
@@ -0,0 +1,64 @@
+/*
+ * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package net.java.sip.communicator.impl.browserlauncher;
+
+import net.java.sip.communicator.service.browserlauncher.*;
+import net.java.sip.communicator.util.*;
+
+import com.apple.eio.*;
+
+/**
+ * A simple implementation of the BrowserLauncherService. Checks the operating
+ * system and launches the appropriate browser.
+ *
+ * @author Yana Stamcheva
+ */
+public class BrowserLauncherImpl
+ implements BrowserLauncherService
+{
+ private static Logger logger = Logger.getLogger(
+ BrowserLauncherImpl.class.getName());
+
+ public void openURL(String url)
+ {
+ String osName = System.getProperty("os.name");
+
+ try
+ {
+ if (osName.startsWith("Mac OS"))
+ {
+ FileManager.openURL(url);
+ }
+ else if (osName.startsWith("Windows"))
+ {
+ Runtime.getRuntime().exec(
+ "rundll32 url.dll,FileProtocolHandler " + url);
+ }
+ else
+ {
+ String[] browsers = {"firefox", "icedove", "opera", "konqueror",
+ "epiphany", "mozilla", "netscape" };
+
+ String browser = null;
+
+ for (int i = 0; i < browsers.length && browser == null; i ++)
+ {
+ if (Runtime.getRuntime().exec(
+ new String[] {"which", browsers[i]}).waitFor() == 0)
+ browser = browsers[i];
+ }
+ if (browser == null)
+ throw new Exception("Could not find web browser");
+ else
+ Runtime.getRuntime().exec(new String[] {browser, url});
+ }
+ }
+ catch (Exception e) {
+ logger.error("Failed to launch browser: " + e);
+ }
+ }
+}
diff --git a/src/net/java/sip/communicator/impl/browserlauncher/browserlauncher.manifest.mf b/src/net/java/sip/communicator/impl/browserlauncher/browserlauncher.manifest.mf
new file mode 100644
index 0000000..e061458
--- /dev/null
+++ b/src/net/java/sip/communicator/impl/browserlauncher/browserlauncher.manifest.mf
@@ -0,0 +1,10 @@
+Bundle-Activator: net.java.sip.communicator.impl.browserlauncher.BrowserLauncherActivator
+Bundle-Name: Browser Launcher Service
+Bundle-Description: An implementation of the BrowserLauncher service.
+Bundle-Vendor: sip-communicator.org
+Bundle-Version: 0.0.1
+Export-Package: net.java.sip.communicator.service.browserlauncher
+Import-Package: org.osgi.framework,
+ net.java.sip.communicator.util,
+ net.java.sip.communicator.service.browserlauncher,
+ com.apple.eio \ No newline at end of file