Attachment 'appletpad.py'
Download 1 # -*- coding: iso-8859-1 -*-
2 """
3 MoinMoin - embbed jgraphpad macro
4 more documentation available at: http://wiki.visualmodeller.org
5
6 @copyright: 2006 by Raphael Valyi
7 @license: GNU GPL, see COPYING for details.
8 """
9
10 from MoinMoin.Page import Page
11 import re, os
12
13
14 # README:
15 # make sure the following settings match with your own MoinMoin configuration
16 host = "http://wiki.visualmodeller.org" #the url before the page name
17 javascript_helper_path = "/applets/JGraphpadCE/lib/javascript/firepad.js" #relative path to the javascript helper
18 webstart_launchers_dir = "/home/rvalyi/public_html/wiki/applets/JGraphpadCE" #the place were you want the jnlp webstart launchers to be written out
19
20
21 javascript_helper_url = host + javascript_helper_path
22 codebase = host + "/applets/JGraphpadCE" #relative url to the jars (or to the the correct server redirectors)
23 host_without_protocol = host.replace('http://', '')
24
25
26 #generic parameters you might also want to change; see firepad.js javascript file for more details
27 archive = "jgraphpad.jar,jgraphpad_lazy.jar,library.jar,translations.jar,gpgraph.jar,layouts.jar,console.jar,codecs.jar" #you shoud also change the jnlp generation if you change it!
28 default_mainClass = "org.jgraph.pad.jgraphpad.JGraphpad.class"
29 default_plugins = "no" #add the plugins if you want
30 mode = "both" #you can also use 'applet' or 'webstart'
31 appletAutoPopup = "true"
32
33
34
35 def execute(macro, args):
36
37 #first we take some parameters from the wiki macro. May be a more generic system (like a map) could allow to pass more parameters
38 args = re.split (r'[;\s]+', args) #WARNING: we param separator is ";"
39
40 try:
41 basename = args[0] #diagram name param
42 except IndexError:
43 basename = "diagram1"
44
45 try:
46 plugins = args[1] #plugins if any, see JGraphpad examples; plugins should be separated by ","
47 except IndexError:
48 plugins = default_plugins
49
50 try:
51 appletMain = args[2] #the main class
52 except IndexError:
53 appletMain = default_mainClass
54
55
56 #common parameters for the applet code and the jnlp webstart code
57 pagename = macro.formatter.page.page_name
58 request = macro.request
59 savelink = Page(request, pagename).url(request) + "?action=AttachFile"
60 drawpath = savelink + """&do=get&target=%(basename)s.xml""" % {'basename' : basename}
61 pngpath = savelink + """&do=get&target=%(basename)s.png""" % {'basename' : basename}
62 fullpng = host + pngpath
63
64
65 #check if the user may upload the modified diagram or not
66 readOnly="false"
67 if not request.user.may.write(pagename):
68 readOnly="true"
69 elif not macro.formatter.page.isWritable():
70 readOnly="true"
71
72
73
74 #jnlp webstart launcher generation: this file should can't be generated by javascript, it should be available in a given URL of the server
75 #comment this section if you don't want webstart support
76 jnlpfile = webstart_launchers_dir + "/wspad_" + pagename + "_" + basename +".jnlp"
77 jnlpurl = codebase + "/wspad_" + pagename + "_" + basename + ".jnlp"
78 code = """<?xml version="1.0" encoding="utf-8"?>
79 <jnlp
80 spec="1.0+"
81 codebase="%(codebase)s" href="%(jnlpurl)s">
82 <information>
83 <title>JGraphpad Community Edition</title>
84 <vendor>the JGraph Team</vendor>
85 <description>JGraphpad Community Edition Diagram Editor</description>
86 <offline-allowed/>
87 </information>
88 <resources>
89 <j2se version="1.4+"/>
90 <jar href="jgraphpad.jar"/>
91 <jar href="jgraphpad_lazy.jar"/>
92 <jar href="library.jar"/>
93 <jar href="translations.jar"/>
94 <jar href="gpgraph.jar"/>
95 <jar href="library.jar"/>
96 <jar href="console.jar"/>
97 <jar href="codecs.jar"/>
98 </resources>
99 <application-desc>
100 <argument>-h</argument>
101 <argument>%(host_without_protocol)s</argument>
102 <argument>-p</argument>
103 <argument>80</argument>
104 <argument>-t</argument>
105 <argument>http</argument>
106 <argument>-d</argument>
107 <argument>%(drawpath)s</argument>
108 <argument>-v</argument>
109 <argument>%(pngpath)s</argument>
110 <argument>-f</argument>
111 <argument>%(basename)s</argument>
112 <argument>-u</argument>
113 <argument>%(savelink)s</argument>
114 <argument>-n</argument>
115 <argument>no</argument>
116 </application-desc>
117 </jnlp>""" % {
118 'pngpath': pngpath, 'drawpath': drawpath, 'jnlpurl': jnlpurl,
119 'savelink': savelink, 'basename': basename, 'codebase': codebase, 'host_without_protocol': host_without_protocol}
120 file = open(jnlpfile,'w')
121 file.write(code)
122 file.close()
123 os.chmod(jnlpfile, 0755) #todo: make sure this also work on windows based servers
124 #end of the webstart section
125
126
127
128 #firepad applet settings
129 code = """<script>id='%(basename)s'
130 archive = '%(archive)s'
131 basename='%(basename)s'
132 mode = '%(mode)s'
133 xmlDownloadPath='%(drawpath)s'
134 xmlUploadLPath='%(savelink)s'
135 imageDownloadPath='%(fullpng)s'
136 plugins='%(plugins)s'
137 appletMain='%(appletMain)s'
138 readOnly='%(readOnly)s'
139 webstartLink='%(jnlpurl)s'
140 </script><script type='text/javascript' src='%(javascript_helper_url)s'></script>""" % {
141 'pngpath': pngpath, 'drawpath': drawpath, 'fullpng' : fullpng,
142 'savelink': savelink, 'basename': basename, 'plugins': plugins, 'archive': archive, 'mode': mode, 'appletAutoPopup': appletAutoPopup,
143 'appletMain': appletMain, 'readOnly':readOnly, 'jnlpurl':jnlpurl, 'javascript_helper_url':javascript_helper_url}
144 return code
145
Attached Files
To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.You are not allowed to attach a file to this page.