Mercurial > hg > documentViewer
annotate documentViewer.py @ 46:31059e3d9338
has now also a text mode viewMode=text
author | dwinter |
---|---|
date | Sat, 09 Sep 2006 12:52:59 +0200 |
parents | 0391fe75aef3 |
children | a10fff6199b0 |
rev | line source |
---|---|
46 | 1 |
2 | |
0 | 3 from OFS.Folder import Folder |
4 from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate | |
5 from Products.PageTemplates.PageTemplateFile import PageTemplateFile | |
6 from AccessControl import ClassSecurityInfo | |
32 | 7 from AccessControl import getSecurityManager |
0 | 8 from Globals import package_home |
9 | |
10 from Ft.Xml.Domlette import NonvalidatingReader | |
11 from Ft.Xml.Domlette import PrettyPrint, Print | |
38 | 12 from Ft.Xml import EMPTY_NAMESPACE, Parse |
0 | 13 |
14 import Ft.Xml.XPath | |
15 | |
16 import os.path | |
31 | 17 import sys |
0 | 18 import cgi |
19 import urllib | |
22 | 20 import zLOG |
46 | 21 import urlparse |
0 | 22 |
25 | 23 def getInt(number, default=0): |
24 """returns always an int (0 in case of problems)""" | |
25 try: | |
26 return int(number) | |
27 except: | |
28 return default | |
29 | |
0 | 30 def getTextFromNode(nodename): |
46 | 31 """get the cdata content of a node""" |
32 | 32 if nodename is None: |
33 return "" | |
0 | 34 nodelist=nodename.childNodes |
35 rc = "" | |
36 for node in nodelist: | |
37 if node.nodeType == node.TEXT_NODE: | |
38 rc = rc + node.data | |
39 return rc | |
40 | |
35 | 41 |
42 def getParentDir(path): | |
43 """returns pathname shortened by one""" | |
44 return '/'.join(path.split('/')[0:-1]) | |
45 | |
46 | |
0 | 47 import socket |
48 | |
32 | 49 def urlopen(url,timeout=2): |
0 | 50 """urlopen mit timeout""" |
32 | 51 socket.setdefaulttimeout(timeout) |
0 | 52 ret=urllib.urlopen(url) |
53 socket.setdefaulttimeout(5) | |
54 return ret | |
55 | |
56 | |
22 | 57 ## |
58 ## documentViewer class | |
59 ## | |
60 class documentViewer(Folder): | |
0 | 61 """document viewer""" |
46 | 62 textViewerUrl="http://127.0.0.1:8080/HFQP/testXSLT/getPage?" |
63 | |
0 | 64 meta_type="Document viewer" |
65 | |
66 security=ClassSecurityInfo() | |
22 | 67 manage_options=Folder.manage_options+( |
0 | 68 {'label':'main config','action':'changeDocumentViewerForm'}, |
69 ) | |
70 | |
22 | 71 # templates and forms |
72 viewer_main = PageTemplateFile('zpt/viewer_main', globals()) | |
73 thumbs_main = PageTemplateFile('zpt/thumbs_main', globals()) | |
74 image_main = PageTemplateFile('zpt/image_main', globals()) | |
75 head_main = PageTemplateFile('zpt/head_main', globals()) | |
76 docuviewer_css = PageTemplateFile('css/docuviewer.css', globals()) | |
77 | |
78 security.declareProtected('View management screens','changeDocumentViewerForm') | |
79 changeDocumentViewerForm = PageTemplateFile('zpt/changeDocumentViewer', globals()) | |
80 | |
0 | 81 |
46 | 82 def __init__(self,id,imageViewerUrl,textViewerUrl=None,title="",digilibBaseUrl=None,thumbcols=2,thumbrows=10,authgroups="mpiwg"): |
0 | 83 """init document viewer""" |
84 self.id=id | |
85 self.title=title | |
86 self.imageViewerUrl=imageViewerUrl | |
46 | 87 self.textViewerUrl=textViewerUrl |
88 | |
25 | 89 if not digilibBaseUrl: |
22 | 90 self.digilibBaseUrl = self.findDigilibUrl() |
25 | 91 else: |
92 self.digilibBaseUrl = digilibBaseUrl | |
93 self.thumbcols = thumbcols | |
94 self.thumbrows = thumbrows | |
32 | 95 # authgroups is list of authorized groups (delimited by ,) |
96 self.authgroups = [s.strip().lower() for s in authgroups.split(',')] | |
22 | 97 # add template folder so we can always use template.something |
98 self.manage_addFolder('template') | |
99 | |
100 | |
101 security.declareProtected('View','index_html') | |
46 | 102 def index_html(self,mode,url,viewMode="images",start=None,pn=1): |
22 | 103 ''' |
104 view it | |
105 @param mode: defines which type of document is behind url | |
106 @param url: url which contains display information | |
46 | 107 @param viewMode: if images display images, if text display text, default is images |
108 | |
22 | 109 ''' |
0 | 110 |
22 | 111 zLOG.LOG("documentViewer (index)", zLOG.INFO, "mode: %s url:%s start:%s pn:%s"%(mode,url,start,pn)) |
112 | |
113 if not hasattr(self, 'template'): | |
114 # create template folder if it doesn't exist | |
115 self.manage_addFolder('template') | |
116 | |
117 if not self.digilibBaseUrl: | |
118 self.digilibBaseUrl = self.findDigilibUrl() or "http://nausikaa.mpiwg-berlin.mpg.de/digitallibrary" | |
119 | |
25 | 120 docinfo = self.getDocinfo(mode=mode,url=url) |
121 pageinfo = self.getPageinfo(start=start,current=pn,docinfo=docinfo) | |
22 | 122 pt = getattr(self.template, 'viewer_main') |
46 | 123 return pt(docinfo=docinfo,pageinfo=pageinfo,viewMode=viewMode) |
0 | 124 |
125 | |
25 | 126 def getLink(self,param=None,val=None): |
127 """link to documentviewer with parameter param set to val""" | |
35 | 128 params=self.REQUEST.form.copy() |
25 | 129 if param is not None: |
31 | 130 if val is None: |
131 if params.has_key(param): | |
132 del params[param] | |
25 | 133 else: |
35 | 134 params[param] = str(val) |
31 | 135 |
35 | 136 # quote values and assemble into query string |
137 ps = "&".join(["%s=%s"%(k,urllib.quote(v)) for (k, v) in params.items()]) | |
138 url=self.REQUEST['URL1']+"?"+ps | |
25 | 139 return url |
140 | |
0 | 141 |
22 | 142 def getStyle(self, idx, selected, style=""): |
25 | 143 """returns a string with the given style and append 'sel' if path == selected.""" |
22 | 144 #zLOG.LOG("documentViewer (getstyle)", zLOG.INFO, "idx: %s selected: %s style: %s"%(idx,selected,style)) |
145 if idx == selected: | |
146 return style + 'sel' | |
147 else: | |
35 | 148 return style |
0 | 149 |
35 | 150 |
151 def isAccessible(self, docinfo): | |
32 | 152 """returns if access to the resource is granted""" |
153 access = docinfo.get('accessType', None) | |
41 | 154 zLOG.LOG("documentViewer (accessOK)", zLOG.INFO, "access type %s"%access) |
45 | 155 if access is not None and access == 'free': |
42
fbc7258e4b5c
changed default access to deny if no access information
casties
parents:
41
diff
changeset
|
156 zLOG.LOG("documentViewer (accessOK)", zLOG.INFO, "access is free") |
32 | 157 return True |
45 | 158 elif access is None or access in self.authgroups: |
35 | 159 # only local access -- only logged in users |
160 user = getSecurityManager().getUser() | |
161 if user is not None: | |
162 #print "user: ", user | |
163 return (user.getUserName() != "Anonymous User") | |
164 else: | |
165 return False | |
32 | 166 |
35 | 167 zLOG.LOG("documentViewer (accessOK)", zLOG.INFO, "unknown access type %s"%access) |
32 | 168 return False |
35 | 169 |
32 | 170 |
31 | 171 def getDirinfoFromDigilib(self,path,docinfo=None): |
29 | 172 """gibt param von dlInfo aus""" |
40 | 173 num_retries = 3 |
31 | 174 if docinfo is None: |
175 docinfo = {} | |
176 | |
40 | 177 infoUrl=self.digilibBaseUrl+"/dirInfo-xml.jsp?mo=dir&fn="+path |
29 | 178 |
40 | 179 zLOG.LOG("documentViewer (getparamfromdigilib)", zLOG.INFO, "dirInfo from %s"%(infoUrl)) |
29 | 180 |
40 | 181 for cnt in range(num_retries): |
35 | 182 try: |
40 | 183 # dom = NonvalidatingReader.parseUri(imageUrl) |
184 txt=urllib.urlopen(infoUrl).read() | |
185 dom = Parse(txt) | |
35 | 186 break |
187 except: | |
40 | 188 zLOG.LOG("documentViewer (getdirinfofromdigilib)", zLOG.ERROR, "error reading %s (try %d)"%(infoUrl,cnt)) |
35 | 189 else: |
40 | 190 raise IOError("Unable to get dir-info from %s"%(infoUrl)) |
29 | 191 |
37 | 192 sizes=dom.xpath("//dir/size") |
193 zLOG.LOG("documentViewer (getparamfromdigilib)", zLOG.INFO, "dirInfo:size"%sizes) | |
29 | 194 |
37 | 195 if sizes: |
196 docinfo['numPages'] = int(getTextFromNode(sizes[0])) | |
31 | 197 else: |
198 docinfo['numPages'] = 0 | |
199 | |
200 return docinfo | |
32 | 201 |
29 | 202 |
35 | 203 def getIndexMeta(self, url): |
204 """returns dom of index.meta document at url""" | |
39
1dd90aabd366
added retry when reading index meta from texter applet
casties
parents:
38
diff
changeset
|
205 num_retries = 3 |
35 | 206 dom = None |
39
1dd90aabd366
added retry when reading index meta from texter applet
casties
parents:
38
diff
changeset
|
207 metaUrl = None |
35 | 208 if url.startswith("http://"): |
209 # real URL | |
39
1dd90aabd366
added retry when reading index meta from texter applet
casties
parents:
38
diff
changeset
|
210 metaUrl = url |
35 | 211 else: |
212 # online path | |
213 server=self.digilibBaseUrl+"/servlet/Texter?fn=" | |
40 | 214 metaUrl=server+url.replace("/mpiwg/online","") |
35 | 215 if not metaUrl.endswith("index.meta"): |
216 metaUrl += "/index.meta" | |
46 | 217 print metaUrl |
40 | 218 for cnt in range(num_retries): |
35 | 219 try: |
39
1dd90aabd366
added retry when reading index meta from texter applet
casties
parents:
38
diff
changeset
|
220 # patch dirk encoding fehler treten dann nicht mehr auf |
38 | 221 # dom = NonvalidatingReader.parseUri(metaUrl) |
39
1dd90aabd366
added retry when reading index meta from texter applet
casties
parents:
38
diff
changeset
|
222 txt=urllib.urlopen(metaUrl).read() |
1dd90aabd366
added retry when reading index meta from texter applet
casties
parents:
38
diff
changeset
|
223 dom = Parse(txt) |
40 | 224 break |
35 | 225 except: |
39
1dd90aabd366
added retry when reading index meta from texter applet
casties
parents:
38
diff
changeset
|
226 zLOG.LOG("ERROR documentViewer (getIndexMata)", zLOG.INFO,"%s (%s)"%sys.exc_info()[0:2]) |
1dd90aabd366
added retry when reading index meta from texter applet
casties
parents:
38
diff
changeset
|
227 |
1dd90aabd366
added retry when reading index meta from texter applet
casties
parents:
38
diff
changeset
|
228 if dom is None: |
1dd90aabd366
added retry when reading index meta from texter applet
casties
parents:
38
diff
changeset
|
229 raise IOError("Unable to read index meta from %s"%(url)) |
35 | 230 |
231 return dom | |
232 | |
233 | |
32 | 234 def getAuthinfoFromIndexMeta(self,path,docinfo=None,dom=None): |
35 | 235 """gets authorization info from the index.meta file at path or given by dom""" |
37 | 236 zLOG.LOG("documentViewer (getauthinfofromindexmeta)", zLOG.INFO,"path: %s"%(path)) |
32 | 237 |
238 access = None | |
239 | |
240 if docinfo is None: | |
241 docinfo = {} | |
242 | |
243 if dom is None: | |
35 | 244 dom = self.getIndexMeta(getParentDir(path)) |
46 | 245 |
32 | 246 acctype = dom.xpath("//access-conditions/access/@type") |
247 if acctype and (len(acctype)>0): | |
248 access=acctype[0].value | |
35 | 249 if access in ['group', 'institution']: |
32 | 250 access = getTextFromNode(dom.xpath("//access-conditions/access/name")[0]).lower() |
251 | |
252 docinfo['accessType'] = access | |
253 return docinfo | |
29 | 254 |
32 | 255 |
22 | 256 def getBibinfoFromIndexMeta(self,path,docinfo=None,dom=None): |
35 | 257 """gets bibliographical info from the index.meta file at path or given by dom""" |
22 | 258 zLOG.LOG("documentViewer (getbibinfofromindexmeta)", zLOG.INFO,"path: %s"%(path)) |
20 | 259 |
22 | 260 if docinfo is None: |
261 docinfo = {} | |
262 | |
263 if dom is None: | |
35 | 264 dom = self.getIndexMeta(getParentDir(path)) |
265 | |
25 | 266 metaData=self.metadata.main.meta.bib |
267 bibtype=dom.xpath("//bib/@type") | |
268 if bibtype and (len(bibtype)>0): | |
269 bibtype=bibtype[0].value | |
20 | 270 else: |
25 | 271 bibtype="generic" |
272 bibtype=bibtype.replace("-"," ") # wrong typesiin index meta "-" instead of " " (not wrong! ROC) | |
273 bibmap=metaData.generateMappingForType(bibtype) | |
35 | 274 #print "bibmap: ", bibmap, " for: ", bibtype |
32 | 275 # if there is no mapping bibmap is empty (mapping sometimes has empty fields) |
31 | 276 if len(bibmap) > 0 and len(bibmap['author'][0]) > 0: |
25 | 277 docinfo['author']=getTextFromNode(dom.xpath("//bib/%s"%bibmap['author'][0])[0]) |
278 docinfo['title']=getTextFromNode(dom.xpath("//bib/%s"%bibmap['title'][0])[0]) | |
279 docinfo['year']=getTextFromNode(dom.xpath("//bib/%s"%bibmap['year'][0])[0]) | |
22 | 280 |
281 return docinfo | |
282 | |
283 | |
32 | 284 def getDocinfoFromTextTool(self,url,dom=None,docinfo=None): |
22 | 285 """parse texttool tag in index meta""" |
286 zLOG.LOG("documentViewer (getdocinfofromtexttool)", zLOG.INFO,"url: %s"%(url)) | |
287 if docinfo is None: | |
288 docinfo = {} | |
289 | |
32 | 290 if dom is None: |
35 | 291 dom = self.getIndexMeta(url) |
32 | 292 |
43
f3bc59cf64d9
fixed some problems with bad index.meta files (text-tools mode)
casties
parents:
42
diff
changeset
|
293 archivePath = None |
f3bc59cf64d9
fixed some problems with bad index.meta files (text-tools mode)
casties
parents:
42
diff
changeset
|
294 archiveName = None |
f3bc59cf64d9
fixed some problems with bad index.meta files (text-tools mode)
casties
parents:
42
diff
changeset
|
295 |
32 | 296 archiveNames=dom.xpath("//resource/name") |
297 if archiveNames and (len(archiveNames)>0): | |
298 archiveName=getTextFromNode(archiveNames[0]) | |
43
f3bc59cf64d9
fixed some problems with bad index.meta files (text-tools mode)
casties
parents:
42
diff
changeset
|
299 else: |
f3bc59cf64d9
fixed some problems with bad index.meta files (text-tools mode)
casties
parents:
42
diff
changeset
|
300 zLOG.LOG("documentViewer (getdocinfofromtexttool)", zLOG.WARNING,"resource/name missing in: %s"%(url)) |
22 | 301 |
302 archivePaths=dom.xpath("//resource/archive-path") | |
303 if archivePaths and (len(archivePaths)>0): | |
304 archivePath=getTextFromNode(archivePaths[0]) | |
32 | 305 # clean up archive path |
306 if archivePath[0] != '/': | |
307 archivePath = '/' + archivePath | |
43
f3bc59cf64d9
fixed some problems with bad index.meta files (text-tools mode)
casties
parents:
42
diff
changeset
|
308 if archiveName and (not archivePath.endswith(archiveName)): |
32 | 309 archivePath += "/" + archiveName |
22 | 310 else: |
43
f3bc59cf64d9
fixed some problems with bad index.meta files (text-tools mode)
casties
parents:
42
diff
changeset
|
311 # try to get archive-path from url |
f3bc59cf64d9
fixed some problems with bad index.meta files (text-tools mode)
casties
parents:
42
diff
changeset
|
312 zLOG.LOG("documentViewer (getdocinfofromtexttool)", zLOG.WARNING,"resource/archive-path missing in: %s"%(url)) |
f3bc59cf64d9
fixed some problems with bad index.meta files (text-tools mode)
casties
parents:
42
diff
changeset
|
313 if (not url.startswith('http')): |
f3bc59cf64d9
fixed some problems with bad index.meta files (text-tools mode)
casties
parents:
42
diff
changeset
|
314 archivePath = url.replace('index.meta', '') |
f3bc59cf64d9
fixed some problems with bad index.meta files (text-tools mode)
casties
parents:
42
diff
changeset
|
315 |
f3bc59cf64d9
fixed some problems with bad index.meta files (text-tools mode)
casties
parents:
42
diff
changeset
|
316 if archivePath is None: |
f3bc59cf64d9
fixed some problems with bad index.meta files (text-tools mode)
casties
parents:
42
diff
changeset
|
317 # we balk without archive-path |
f3bc59cf64d9
fixed some problems with bad index.meta files (text-tools mode)
casties
parents:
42
diff
changeset
|
318 raise IOError("Missing archive-path (for text-tool) in %s"%(url)) |
22 | 319 |
35 | 320 imageDirs=dom.xpath("//texttool/image") |
321 if imageDirs and (len(imageDirs)>0): | |
322 imageDir=getTextFromNode(imageDirs[0]) | |
22 | 323 else: |
37 | 324 # we balk with no image tag |
325 raise IOError("No text-tool info in %s"%(url)) | |
22 | 326 |
35 | 327 if imageDir and archivePath: |
328 #print "image: ", imageDir, " archivepath: ", archivePath | |
329 imageDir=os.path.join(archivePath,imageDir) | |
330 imageDir=imageDir.replace("/mpiwg/online",'') | |
331 docinfo=self.getDirinfoFromDigilib(imageDir,docinfo=docinfo) | |
332 docinfo['imagePath'] = imageDir | |
333 docinfo['imageURL'] = self.digilibBaseUrl+"/servlet/Scaler?fn="+imageDir | |
22 | 334 |
335 viewerUrls=dom.xpath("//texttool/digiliburlprefix") | |
336 if viewerUrls and (len(viewerUrls)>0): | |
337 viewerUrl=getTextFromNode(viewerUrls[0]) | |
31 | 338 docinfo['viewerURL'] = viewerUrl |
22 | 339 |
340 textUrls=dom.xpath("//texttool/text") | |
341 if textUrls and (len(textUrls)>0): | |
342 textUrl=getTextFromNode(textUrls[0]) | |
31 | 343 docinfo['textURL'] = textUrl |
22 | 344 |
345 docinfo = self.getBibinfoFromIndexMeta(url,docinfo=docinfo,dom=dom) | |
32 | 346 docinfo = self.getAuthinfoFromIndexMeta(url,docinfo=docinfo,dom=dom) |
22 | 347 return docinfo |
348 | |
349 | |
350 def getDocinfoFromImagePath(self,path,docinfo=None): | |
351 """path ist the path to the images it assumes that the index.meta file is one level higher.""" | |
352 zLOG.LOG("documentViewer (getdocinfofromimagepath)", zLOG.INFO,"path: %s"%(path)) | |
353 if docinfo is None: | |
354 docinfo = {} | |
29 | 355 path=path.replace("/mpiwg/online","") |
22 | 356 docinfo['imagePath'] = path |
31 | 357 docinfo=self.getDirinfoFromDigilib(path,docinfo=docinfo) |
358 imageUrl=self.digilibBaseUrl+"/servlet/Scaler?fn="+path | |
22 | 359 docinfo['imageURL'] = imageUrl |
360 | |
361 docinfo = self.getBibinfoFromIndexMeta(path,docinfo=docinfo) | |
32 | 362 docinfo = self.getAuthinfoFromIndexMeta(path,docinfo=docinfo) |
22 | 363 return docinfo |
20 | 364 |
22 | 365 |
366 def getDocinfo(self, mode, url): | |
367 """returns docinfo depending on mode""" | |
368 zLOG.LOG("documentViewer (getdocinfo)", zLOG.INFO,"mode: %s, url: %s"%(mode,url)) | |
369 # look for cached docinfo in session | |
370 if self.REQUEST.SESSION.has_key('docinfo'): | |
371 docinfo = self.REQUEST.SESSION['docinfo'] | |
372 # check if its still current | |
373 if docinfo is not None and docinfo.get('mode') == mode and docinfo.get('url') == url: | |
374 zLOG.LOG("documentViewer (getdocinfo)", zLOG.INFO,"docinfo in session: %s"%docinfo) | |
375 return docinfo | |
376 # new docinfo | |
377 docinfo = {'mode': mode, 'url': url} | |
378 if mode=="texttool": #index.meta with texttool information | |
379 docinfo = self.getDocinfoFromTextTool(url, docinfo=docinfo) | |
380 elif mode=="imagepath": | |
381 docinfo = self.getDocinfoFromImagePath(url, docinfo=docinfo) | |
382 else: | |
383 zLOG.LOG("documentViewer (getdocinfo)", zLOG.ERROR,"unknown mode!") | |
37 | 384 raise ValueError("Unknown mode %s"%(mode)) |
385 | |
22 | 386 zLOG.LOG("documentViewer (getdocinfo)", zLOG.INFO,"docinfo: %s"%docinfo) |
387 self.REQUEST.SESSION['docinfo'] = docinfo | |
388 return docinfo | |
20 | 389 |
390 | |
25 | 391 def getPageinfo(self, current, start=None, rows=None, cols=None, docinfo=None): |
22 | 392 """returns pageinfo with the given parameters""" |
393 pageinfo = {} | |
25 | 394 current = getInt(current) |
395 pageinfo['current'] = current | |
396 rows = int(rows or self.thumbrows) | |
397 pageinfo['rows'] = rows | |
398 cols = int(cols or self.thumbcols) | |
399 pageinfo['cols'] = cols | |
400 grpsize = cols * rows | |
401 pageinfo['groupsize'] = grpsize | |
402 start = getInt(start, default=(int(current / grpsize) * grpsize +1)) | |
22 | 403 pageinfo['start'] = start |
25 | 404 pageinfo['end'] = start + grpsize |
405 if docinfo is not None: | |
406 np = int(docinfo['numPages']) | |
407 pageinfo['end'] = min(pageinfo['end'], np) | |
408 pageinfo['numgroups'] = int(np / grpsize) | |
409 if np % grpsize > 0: | |
410 pageinfo['numgroups'] += 1 | |
411 | |
22 | 412 return pageinfo |
413 | |
0 | 414 def text(self,mode,url,pn): |
415 """give text""" | |
416 if mode=="texttool": #index.meta with texttool information | |
417 (viewerUrl,imagepath,textpath)=parseUrlTextTool(url) | |
418 | |
35 | 419 #print textpath |
0 | 420 try: |
421 dom = NonvalidatingReader.parseUri(textpath) | |
422 except: | |
423 return None | |
424 | |
425 list=[] | |
426 nodes=dom.xpath("//pb") | |
427 | |
428 node=nodes[int(pn)-1] | |
429 | |
430 p=node | |
431 | |
432 while p.tagName!="p": | |
433 p=p.parentNode | |
434 | |
435 | |
436 endNode=nodes[int(pn)] | |
437 | |
438 | |
439 e=endNode | |
440 | |
441 while e.tagName!="p": | |
442 e=e.parentNode | |
443 | |
444 | |
445 next=node.parentNode | |
446 | |
447 #sammle s | |
448 while next and (next!=endNode.parentNode): | |
449 list.append(next) | |
450 next=next.nextSibling | |
451 list.append(endNode.parentNode) | |
452 | |
453 if p==e:# beide im selben paragraphen | |
20 | 454 pass |
455 # else: | |
456 # next=p | |
457 # while next!=e: | |
458 # print next,e | |
459 # list.append(next) | |
460 # next=next.nextSibling | |
461 # | |
462 # for x in list: | |
463 # PrettyPrint(x) | |
464 # | |
465 # return list | |
22 | 466 # |
467 | |
468 def findDigilibUrl(self): | |
469 """try to get the digilib URL from zogilib""" | |
470 url = self.imageViewerUrl[:-1] + "/getScalerUrl" | |
46 | 471 print urlparse.urlparse(url)[0] |
472 print urlparse.urljoin(self.absolute_url(),url) | |
22 | 473 try: |
46 | 474 if urlparse.urlparse(url)[0]=='': #relative path |
475 url=urlparse.urljoin(self.absolute_url()+"/",url) | |
476 | |
22 | 477 scaler = urlopen(url).read() |
478 return scaler.replace("/servlet/Scaler?", "") | |
479 except: | |
480 return None | |
481 | |
46 | 482 def changeDocumentViewer(self,imageViewerUrl,textViewerUrl,title="",digilibBaseUrl=None,thumbrows=2,thumbcols=10,authgroups='mpiwg',RESPONSE=None): |
22 | 483 """init document viewer""" |
484 self.title=title | |
485 self.imageViewerUrl=imageViewerUrl | |
46 | 486 self.textViewerUrl=textViewerUrl |
22 | 487 self.digilibBaseUrl = digilibBaseUrl |
25 | 488 self.thumbrows = thumbrows |
489 self.thumbcols = thumbcols | |
32 | 490 self.authgroups = [s.strip().lower() for s in authgroups.split(',')] |
22 | 491 if RESPONSE is not None: |
492 RESPONSE.redirect('manage_main') | |
0 | 493 |
494 | |
495 | |
496 | |
497 # security.declareProtected('View management screens','renameImageForm') | |
498 | |
499 def manage_AddDocumentViewerForm(self): | |
500 """add the viewer form""" | |
22 | 501 pt=PageTemplateFile('zpt/addDocumentViewer', globals()).__of__(self) |
0 | 502 return pt() |
503 | |
46 | 504 def manage_AddDocumentViewer(self,id,imageViewerUrl="",textViewerUrl="",title="",RESPONSE=None): |
0 | 505 """add the viewer""" |
46 | 506 newObj=documentViewer(id,imageViewerUrl,title=title,textViewerUrl=textViewerUrl) |
0 | 507 self._setObject(id,newObj) |
508 | |
509 if RESPONSE is not None: | |
510 RESPONSE.redirect('manage_main') | |
22 | 511 |
512 | |
513 ## | |
514 ## DocumentViewerTemplate class | |
515 ## | |
516 class DocumentViewerTemplate(ZopePageTemplate): | |
517 """Template for document viewer""" | |
518 meta_type="DocumentViewer Template" | |
519 | |
520 | |
521 def manage_addDocumentViewerTemplateForm(self): | |
522 """Form for adding""" | |
523 pt=PageTemplateFile('zpt/addDocumentViewerTemplate', globals()).__of__(self) | |
524 return pt() | |
525 | |
526 def manage_addDocumentViewerTemplate(self, id='viewer_main', title=None, text=None, | |
527 REQUEST=None, submit=None): | |
528 "Add a Page Template with optional file content." | |
529 | |
530 self._setObject(id, DocumentViewerTemplate(id)) | |
531 ob = getattr(self, id) | |
532 ob.pt_edit(open(os.path.join(package_home(globals()),'zpt/viewer_main.zpt')).read(),None) | |
533 if title: | |
534 ob.pt_setTitle(title) | |
535 try: | |
536 u = self.DestinationURL() | |
537 except AttributeError: | |
538 u = REQUEST['URL1'] | |
539 | |
540 u = "%s/%s" % (u, urllib.quote(id)) | |
541 REQUEST.RESPONSE.redirect(u+'/manage_main') | |
542 return '' | |
543 | |
544 | |
41 | 545 |