Attachment 'FreeMindBrowser_patched.py'
Download 1 # -*- coding: iso-8859-1 -*-
2 """
3 MoinMoin - FreeMind browser Macro
4
5 Inserts the FreeMindBrowser applet.
6 See http://freemind.sourceforge.net/wiki/index.php/Main_Page
7
8 [[FreeMindBrowser( urlOfMindmap )]]
9 displays the FreeMind mindmap specified by urlOfMindmap in the FreeMind browser applet
10 there is a default for the width and height of the applet
11
12 [[FreeMindBrowser( urlOfMindmap, width )]]
13 displays the FreeMind mindmap specified by urlOfMindmap in the FreeMind browser applet
14 the width is taken from the argument list
15 there is a default for the height of the applet
16
17 [[FreeMindBrowser( urlOfMindmap, width, height )]]
18 displays the FreeMind mindmap specified by urlOfMindmap in the FreeMind browser applet
19 the width and height are taken from the argument list
20
21
22 @copyright: 2005 by Jürgen Lind <xxx@xxx>
23 @license: GNU GPL, see COPYING for details.
24 """
25
26 from MoinMoin.action import AttachFile
27
28 Dependencies = []
29
30 debug = False
31
32 # # # # # # # # # # # # # # #
33 # FMBMacro class
34 # # # # # # # # # # # # # # #
35 """
36 Class FMBMacro implements the execution of a FreeMindBrowser macro call.
37 One instance must be used per execution.
38 """
39 class FMBMacro:
40
41 appletClass = 'freemind.main.FreeMindApplet.class'
42 widthDefault = '100%'
43 heightDefault= '500'
44
45
46 """
47 Construct the FMBMacro with the execution arguments.
48 """
49 def __init__(self, macro, args):
50 self.macro = macro
51 self.args = args
52
53 # Check and set, if we have an HTML formatter
54 self.isHTML = '<br />\n' == self.macro.formatter.linebreak(0)
55
56 appletArchive= "%s/applets/FreeMindBrowser/freemindbrowser.jar" % (self.macro.request.cfg.url_prefix)
57 self.appletArchive = self.macro.request.getQualifiedURL( appletArchive )
58
59 self.isFatal = False
60 self.applet = [] # this is for the applet code
61 self.messages = [] # this is for extra messages
62
63
64 def execute( self ):
65 self.info( "Yippieh - FMBMacro is executing!" )
66 self.checkArguments()
67 self.computeResult()
68 return self.result
69
70
71 """
72 Check the arguments given with the macro call.
73 """
74 def checkArguments(self):
75
76 if not self.args:
77 self.fatal( "At least one argument, i.e. the URL for the mindmap is expected!" )
78 self.usage()
79 else:
80 argsList = self.args.split(',')
81 argsLen = len(argsList)
82
83 self.width = FMBMacro.widthDefault
84 self.height = FMBMacro.heightDefault
85
86 mindmap = argsList[0].strip()
87
88 if 2 <= argsLen:
89 self.width = argsList[1].strip()
90
91 if 3 <= argsLen:
92 self.height = argsList[2].strip()
93
94 if 3 < argsLen:
95 self.warning( "Too many arguments!" )
96 self.usage()
97
98 self.mindmapUrl = self.getMindmapURL(mindmap)
99
100 # self.checkUrlAccess( self.mindmapUrl )
101
102 if True:
103 self.info( "isHTML= '%s'" %(self.isHTML) )
104 self.info( "mindmap= '%s'" %(mindmap) )
105 self.info( "width= '%s'" %(self.width) )
106 self.info( "height= '%s'" %(self.height) )
107 self.info( "mindmap-url= '%s'" %(self.mindmapUrl) )
108 self.info( "isFatal= '%s'" %(self.isFatal) )
109 self.usage()
110
111
112 """
113 Compute the result of the macro call.
114 """
115 def computeResult(self):
116 result = "".join( self.messages )
117 if not self.isFatal:
118 self.computeApplet()
119 result += "".join( self.applet )
120
121 if self.isHTML:
122 self.result = self.macro.formatter.rawHTML( result )
123 else:
124 self.result = result
125
126
127 """
128 Compute the applet link or applet tag (depending on formatter)
129 """
130 def computeApplet( self ):
131 if self.isHTML:
132 applet = """
133 <!--
134 - code generated by FreeMindBrowser macro -
135 - see http://freemind.sourceforge.net -
136 -->
137 <APPLET CODE="%s"
138 ARCHIVE="%s"
139 WIDTH="%s" HEIGHT="%s" >
140 <PARAM NAME="type" VALUE="application/x.java-applet;version=1.4">
141 <PARAM NAME="scriptable" VALUE="false">
142 <PARAM NAME="modes" VALUE="freemind.modes.browsemode.BrowseMode">
143 <PARAM NAME="browsemode_initial_map" VALUE="%s">
144 <PARAM NAME="initial_mode" VALUE="Browse">
145 <PARAM NAME="selection_method" VALUE="selection_method_direct">
146 <PARAM NAME="X" VALUE="XX">
147 </APPLET>
148
149 """ %( FMBMacro.appletClass, self.appletArchive, self.width, self.height, self.mindmapUrl )
150 self.applet.append( applet )
151
152 else:
153 self.applet.append( self.macro.formatter.url( 1, self.mindmapUrl ) )
154 self.applet.append( self.macro.formatter.url( 0 ) )
155
156
157 # # # # # # # # # # # #
158 # message methods
159 # # # # # # # # # # # #
160 def info( self, msg ):
161 if debug:
162 self.msg( 'Info: ' + msg )
163
164 def warning( self, msg ):
165 self.msg( 'Warning: ' + msg )
166
167 def error( self, msg ):
168 self.msg( 'Error: ' + msg )
169
170 def fatal( self, msg ):
171 self.msg( 'Fatal: ' + msg )
172 self.isFatal = True
173
174 def msg( self, msg ):
175 msg = "FreeMindBrowser-Macro:" + msg
176 print msg
177 if self.isHTML:
178 msg = '<h1 style="font-weight:bold;color:blue">' + msg.replace( '\n', '\n<br/>') + '</h1>'
179
180 self.messages.append(msg)
181
182
183 def usage( self ):
184 usage = """
185 Usage: [[FreeMindBrowser( urlOfMindmap [,width [,height]] )]]
186 urlOfMindmap: an URL reaching the mindmap - allowed schemes are 'http:' and 'attachment:'.
187 width: (optional) - width of the applet; default: %s
188 height: (optional) - height of the applet; default: %s
189 """ %(self.widthDefault, self.heightDefault)
190
191 self.info( usage )
192
193
194 """
195 Take the given URL of the mindmap, validate it and return an URL that can be linked to from the applet.
196 """
197 def getMindmapURL( self, url ):
198
199 if url.startswith( 'http:' ):
200 return url
201 elif url.startswith( 'attachment:'):
202 relativeUrl = AttachFile.getAttachUrl( self.macro.formatter.page.page_name, url[11:], self.macro.request )
203 qualifiedUrl = self.macro.request.getQualifiedURL( relativeUrl )
204 return qualifiedUrl
205 else:
206 self.warning( "Unrecognized scheme in mindmap URL! Url is '%s'!" %(url) )
207 self.usage()
208 return url
209
210
211
212 """
213 Desktop edition returns 200 on non existing resource :-(
214 is this correct behaviour?
215 """
216 def checkUrlAccess( self, url ):
217 import urllib
218
219 try:
220 obj = urllib.urlopen( url )
221 self.info( "urllib.urlopen( %s ) returns:" %(url) )
222 self.info( str(obj) )
223 self.info( "obj.info(): " )
224 self.info( obj.info() )
225 obj.close()
226 except IOError:
227 self.fatal( "Mindmap of specified url [%s] is not accessable." %(self.mindmapUrl) )
228
229
230 # # # # # # # # # # # # # # #
231 # Macro execution interface
232 # # # # # # # # # # # # # # #
233
234 def execute(macro, args):
235
236 fmb = FMBMacro( macro, args )
237 # fmb.execute()
238 return fmb.execute()
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.