Mercurial > lasercutter
view 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 source
1 ;;; browse.clj -- start a web browser from Clojure3 ; Copyright (c) Christophe Grand, December 2008. All rights reserved.4 ; The use and distribution terms for this software are covered by the5 ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)6 ; which can be found in the file epl-v10.html at the root of this7 ; distribution.8 ; By using this software in any fashion, you are agreeing to be bound by9 ; the terms of this license.10 ; You must not remove this notice, or any other, from this software.12 (ns13 ^{:author "Christophe Grand",14 :deprecated "1.2"15 :doc "Start a web browser from Clojure"}16 clojure.contrib.javadoc.browse17 (:require [clojure.contrib.shell :as sh])18 (:import (java.net URI)))20 (defn- macosx? []21 (-> "os.name" System/getProperty .toLowerCase22 (.startsWith "mac os x")))24 (def *open-url-script* (when (macosx?) "/usr/bin/open"))26 (defn open-url-in-browser27 "Opens url (a string) in the default system web browser. May not28 work on all platforms. Returns url on success, nil if not29 supported."30 [url]31 (try32 (when (clojure.lang.Reflector/invokeStaticMethod "java.awt.Desktop"33 "isDesktopSupported" (to-array nil))34 (-> (clojure.lang.Reflector/invokeStaticMethod "java.awt.Desktop"35 "getDesktop" (to-array nil))36 (.browse (URI. url)))37 url)38 (catch ClassNotFoundException e39 nil)))41 (defn open-url-in-swing42 "Opens url (a string) in a Swing window."43 [url]44 ; the implementation of this function resides in another namespace to be loaded "on demand"45 ; this fixes a bug on mac os x where requiring repl-utils turns the process into a GUI app46 ; see http://code.google.com/p/clojure-contrib/issues/detail?id=3247 (require 'clojure.contrib.javadoc.browse-ui)48 ((find-var 'clojure.contrib.javadoc.browse-ui/open-url-in-swing) url))50 (defn browse-url [url]51 (or (open-url-in-browser url) (when *open-url-script* (sh/sh *open-url-script* (str url)) true) (open-url-in-swing url)))