Mercurial > lasercutter
diff src/clojure/contrib/javadoc/browse.clj @ 10:ef7dbbd6452c
added clojure source goodness
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sat, 21 Aug 2010 06:25:44 -0400 |
parents | |
children |
line wrap: on
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/clojure/contrib/javadoc/browse.clj Sat Aug 21 06:25:44 2010 -0400 1.3 @@ -0,0 +1,51 @@ 1.4 +;;; browse.clj -- start a web browser from Clojure 1.5 + 1.6 +; Copyright (c) Christophe Grand, December 2008. All rights reserved. 1.7 +; The use and distribution terms for this software are covered by the 1.8 +; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 1.9 +; which can be found in the file epl-v10.html at the root of this 1.10 +; distribution. 1.11 +; By using this software in any fashion, you are agreeing to be bound by 1.12 +; the terms of this license. 1.13 +; You must not remove this notice, or any other, from this software. 1.14 + 1.15 +(ns 1.16 + ^{:author "Christophe Grand", 1.17 + :deprecated "1.2" 1.18 + :doc "Start a web browser from Clojure"} 1.19 + clojure.contrib.javadoc.browse 1.20 + (:require [clojure.contrib.shell :as sh]) 1.21 + (:import (java.net URI))) 1.22 + 1.23 +(defn- macosx? [] 1.24 + (-> "os.name" System/getProperty .toLowerCase 1.25 + (.startsWith "mac os x"))) 1.26 + 1.27 +(def *open-url-script* (when (macosx?) "/usr/bin/open")) 1.28 + 1.29 +(defn open-url-in-browser 1.30 + "Opens url (a string) in the default system web browser. May not 1.31 + work on all platforms. Returns url on success, nil if not 1.32 + supported." 1.33 + [url] 1.34 + (try 1.35 + (when (clojure.lang.Reflector/invokeStaticMethod "java.awt.Desktop" 1.36 + "isDesktopSupported" (to-array nil)) 1.37 + (-> (clojure.lang.Reflector/invokeStaticMethod "java.awt.Desktop" 1.38 + "getDesktop" (to-array nil)) 1.39 + (.browse (URI. url))) 1.40 + url) 1.41 + (catch ClassNotFoundException e 1.42 + nil))) 1.43 + 1.44 +(defn open-url-in-swing 1.45 + "Opens url (a string) in a Swing window." 1.46 + [url] 1.47 + ; the implementation of this function resides in another namespace to be loaded "on demand" 1.48 + ; this fixes a bug on mac os x where requiring repl-utils turns the process into a GUI app 1.49 + ; see http://code.google.com/p/clojure-contrib/issues/detail?id=32 1.50 + (require 'clojure.contrib.javadoc.browse-ui) 1.51 + ((find-var 'clojure.contrib.javadoc.browse-ui/open-url-in-swing) url)) 1.52 + 1.53 +(defn browse-url [url] 1.54 + (or (open-url-in-browser url) (when *open-url-script* (sh/sh *open-url-script* (str url)) true) (open-url-in-swing url)))