Initial Commit
[packages] / xemacs-packages / w3 / lisp / w3-java.el
1 ;;; w3-java.el --- Rudimentary java support
2 ;; Author: $Author: fx $
3 ;; Created: $Date: 2002/01/22 18:31:50 $
4 ;; Version: $Revision: 1.3 $
5 ;; Keywords: hypermedia, scripting
6
7 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8 ;;; Copyright (c) 1999, 2008 Free Software Foundation, Inc.
9 ;;;
10 ;;; This file is part of GNU Emacs.
11 ;;;
12 ;;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;;; it under the terms of the GNU General Public License as published by
14 ;;; the Free Software Foundation; either version 2, or (at your option)
15 ;;; any later version.
16 ;;;
17 ;;; GNU Emacs is distributed in the hope that it will be useful,
18 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 ;;; GNU General Public License for more details.
21 ;;;
22 ;;; You should have received a copy of the GNU General Public License
23 ;;; along with GNU Emacs; see the file COPYING.  If not, write to the
24 ;;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 ;;; Boston, MA 02111-1307, USA.
26 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
27 (require 'mailcap)
28 ; (require 'url-util)                   ; for `url-generate-unique-filename'
29
30 (defgroup w3-java nil
31   "Emacs/W3 Java Runtime support"
32   :prefix "w3-java"
33   :group 'w3)
34
35 (defcustom w3-java-vm-program "hotjava"
36   "*The program name of the Java virtual machine."
37   :type '(choice (string :tag "External program")
38                  (function :tag "Lisp function"))
39   :group 'w3-java)
40
41 (defcustom w3-java-vm-arguments '(file)
42   "*Arguments that should be passed to the program `w3-java-vm-program'.
43 The special symbol 'file may be used in the list of arguments and will
44 be replaced with the name of a file containing the commands to run a
45 Java applet."
46   :type 'list
47   :group 'w3-java)
48
49 (defun w3-java-run-applet (options params)
50   (let ((file (url-generate-unique-filename "%s-runjava.html")))
51     (save-excursion
52       (set-buffer (get-buffer-create " *java*"))
53       (erase-buffer)
54       (insert "<html>\n"
55               " <head>\n"
56               "  <title>Emacs/W3 Java Application</title>\n"
57               " </head>\n"
58               " <body>\n"
59               "  <p>\n"
60               "   This page was automatically generated by Emacs/W3 to\n"
61               "   run this Java applet.  Any problems with the HTML should\n"
62               "   be referred to <a href='mailto:w3-bugs@xemacs.org'>\n"
63               "   the Emacs/W3 bug list</a>.\n"
64               "  </p>\n"
65               "  <hr>\n"
66               "  <applet "
67               (mapconcat (lambda (x) (format "%s=\"%s\"" (car x) (cdr x))) options " ")
68               ">\n"
69               (mapconcat (lambda (x) (format "   <param name=\"%s\" value=\"%s\">" (car x) (cdr x))) params "\n")
70               "  </applet>\n"
71               " </body>\n"
72               "</html>\n")
73       (write-region (point-min) (point-max) file)
74
75       (if (stringp w3-java-vm-program)
76           (let ((process-connection-type nil)
77                 (proc nil))
78             (setq proc (eval
79                         `(start-process name buffer w3-java-vm-program
80                                         ,@w3-java-vm-arguments)))
81             (process-kill-without-query proc)
82             proc)
83         (eval `(funcall w3-java-vm-program
84                           ,@w3-java-vm-arguments))))))
85
86 (provide 'w3-java)