Mercurial > hg > documentViewer
annotate documentViewer.py @ 585:83eeed69793f
new annotator layer for images.
author | casties |
---|---|
date | Tue, 13 Nov 2012 17:33:34 +0100 |
parents | 011905457a5f |
children | 6000c7e24d8a |
rev | line source |
---|---|
0 | 1 from OFS.Folder import Folder |
2 from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate | |
486 | 3 from Products.PageTemplates.PageTemplateFile import PageTemplateFile |
487 | 4 from App.ImageFile import ImageFile |
0 | 5 from AccessControl import ClassSecurityInfo |
32 | 6 from AccessControl import getSecurityManager |
0 | 7 from Globals import package_home |
8 | |
453
beb7ccb92564
first version using elementtree instead of 4suite xml
casties
parents:
405
diff
changeset
|
9 import xml.etree.ElementTree as ET |
beb7ccb92564
first version using elementtree instead of 4suite xml
casties
parents:
405
diff
changeset
|
10 |
489
55e3398e395e
more new templates. monkey-patch for App.ImageFile.
casties
parents:
488
diff
changeset
|
11 import os |
31 | 12 import sys |
0 | 13 import urllib |
50
6c0f20cecc60
added evaluation of the presentation/info.xml in texttools
dwinter
parents:
49
diff
changeset
|
14 import logging |
61 | 15 import math |
46 | 16 import urlparse |
174 | 17 import re |
389 | 18 import string |
526 | 19 import json |
231 | 20 |
541 | 21 from Products.MetaDataProvider import MetaDataFolder |
22 | |
514 | 23 from SrvTxtUtils import getInt, utf8ify, getText, getHttpData, refreshingImageFileIndexHtml |
52 | 24 |
453
beb7ccb92564
first version using elementtree instead of 4suite xml
casties
parents:
405
diff
changeset
|
25 def serializeNode(node, encoding="utf-8"): |
84
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
26 """returns a string containing node as XML""" |
453
beb7ccb92564
first version using elementtree instead of 4suite xml
casties
parents:
405
diff
changeset
|
27 s = ET.tostring(node) |
beb7ccb92564
first version using elementtree instead of 4suite xml
casties
parents:
405
diff
changeset
|
28 |
beb7ccb92564
first version using elementtree instead of 4suite xml
casties
parents:
405
diff
changeset
|
29 # 4Suite: |
beb7ccb92564
first version using elementtree instead of 4suite xml
casties
parents:
405
diff
changeset
|
30 # stream = cStringIO.StringIO() |
beb7ccb92564
first version using elementtree instead of 4suite xml
casties
parents:
405
diff
changeset
|
31 # Ft.Xml.Domlette.Print(node, stream=stream, encoding=encoding) |
beb7ccb92564
first version using elementtree instead of 4suite xml
casties
parents:
405
diff
changeset
|
32 # s = stream.getvalue() |
beb7ccb92564
first version using elementtree instead of 4suite xml
casties
parents:
405
diff
changeset
|
33 # stream.close() |
84
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
34 return s |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
35 |
561
9255acc4518d
CLOSED - # 256: display texts from different backends (sandbox)
casties
parents:
560
diff
changeset
|
36 def getMDText(node): |
9255acc4518d
CLOSED - # 256: display texts from different backends (sandbox)
casties
parents:
560
diff
changeset
|
37 """returns the @text content from the MetaDataProvider metadata node""" |
9255acc4518d
CLOSED - # 256: display texts from different backends (sandbox)
casties
parents:
560
diff
changeset
|
38 if isinstance(node, dict): |
9255acc4518d
CLOSED - # 256: display texts from different backends (sandbox)
casties
parents:
560
diff
changeset
|
39 return node.get('@text', None) |
9255acc4518d
CLOSED - # 256: display texts from different backends (sandbox)
casties
parents:
560
diff
changeset
|
40 |
9255acc4518d
CLOSED - # 256: display texts from different backends (sandbox)
casties
parents:
560
diff
changeset
|
41 return node |
9255acc4518d
CLOSED - # 256: display texts from different backends (sandbox)
casties
parents:
560
diff
changeset
|
42 |
464 | 43 def getParentPath(path, cnt=1): |
44 """returns pathname shortened by cnt""" | |
45 # make sure path doesn't end with / | |
46 path = path.rstrip('/') | |
47 # split by /, shorten, and reassemble | |
48 return '/'.join(path.split('/')[0:-cnt]) | |
49 | |
585 | 50 |
22 | 51 ## |
52 ## documentViewer class | |
53 ## | |
54 class documentViewer(Folder): | |
0 | 55 """document viewer""" |
56 meta_type="Document viewer" | |
57 | |
58 security=ClassSecurityInfo() | |
22 | 59 manage_options=Folder.manage_options+( |
507 | 60 {'label':'Configuration','action':'changeDocumentViewerForm'}, |
0 | 61 ) |
463 | 62 |
63 metadataService = None | |
64 """MetaDataFolder instance""" | |
525 | 65 |
0 | 66 |
525 | 67 # |
22 | 68 # templates and forms |
525 | 69 # |
70 # viewMode templates | |
479 | 71 viewer_text = PageTemplateFile('zpt/viewer_text', globals()) |
503 | 72 viewer_xml = PageTemplateFile('zpt/viewer_xml', globals()) |
483 | 73 viewer_images = PageTemplateFile('zpt/viewer_images', globals()) |
499
3f9703746fef
more cleanup. new template for viewMode=index (not pretty so far).
casties
parents:
498
diff
changeset
|
74 viewer_index = PageTemplateFile('zpt/viewer_index', globals()) |
528 | 75 viewer_thumbs = PageTemplateFile('zpt/viewer_thumbs', globals()) |
584
011905457a5f
new viewmode=indexonly as coverpage for pdf-generation.
casties
parents:
581
diff
changeset
|
76 viewer_indexonly = PageTemplateFile('zpt/viewer_indexonly', globals()) |
546 | 77 # available layer types (annotator not default) |
78 builtinLayers = {'text': ['dict','search','gis'], | |
558 | 79 'xml': None, 'images': None, 'index': ['extended']} |
526 | 80 availableLayers = builtinLayers; |
525 | 81 # layer templates |
526 | 82 layer_text_dict = PageTemplateFile('zpt/layer_text_dict', globals()) |
83 layer_text_search = PageTemplateFile('zpt/layer_text_search', globals()) | |
525 | 84 layer_text_annotator = PageTemplateFile('zpt/layer_text_annotator', globals()) |
85 layer_text_gis = PageTemplateFile('zpt/layer_text_gis', globals()) | |
552 | 86 layer_text_pundit = PageTemplateFile('zpt/layer_text_pundit', globals()) |
585 | 87 layer_images_annotator = PageTemplateFile('zpt/layer_images_annotator', globals()) |
559 | 88 layer_index_extended = PageTemplateFile('zpt/layer_index_extended', globals()) |
525 | 89 # toc templates |
90
6a4a72033d58
new version with new full-text infrastructure and some more changed templates
casties
parents:
84
diff
changeset
|
90 toc_thumbs = PageTemplateFile('zpt/toc_thumbs', globals()) |
6a4a72033d58
new version with new full-text infrastructure and some more changed templates
casties
parents:
84
diff
changeset
|
91 toc_text = PageTemplateFile('zpt/toc_text', globals()) |
6a4a72033d58
new version with new full-text infrastructure and some more changed templates
casties
parents:
84
diff
changeset
|
92 toc_figures = PageTemplateFile('zpt/toc_figures', globals()) |
526 | 93 toc_concordance = PageTemplateFile('zpt/toc_concordance', globals()) |
577 | 94 toc_handwritten = PageTemplateFile('zpt/toc_handwritten', globals()) |
491 | 95 toc_none = PageTemplateFile('zpt/toc_none', globals()) |
525 | 96 # other templates |
501 | 97 common_template = PageTemplateFile('zpt/common_template', globals()) |
57 | 98 info_xml = PageTemplateFile('zpt/info_xml', globals()) |
487 | 99 docuviewer_css = ImageFile('css/docuviewer.css',globals()) |
532 | 100 # make docuviewer_css refreshable for development |
490
6f116b86a226
more new template stuff. moved ImageFile index method to SrvTxtUtils
casties
parents:
489
diff
changeset
|
101 docuviewer_css.index_html = refreshingImageFileIndexHtml |
535
510bae2b593b
more fixes, e.g. IE support. first version of index page.
casties
parents:
532
diff
changeset
|
102 docuviewer_ie_css = ImageFile('css/docuviewer_ie.css',globals()) |
510bae2b593b
more fixes, e.g. IE support. first version of index page.
casties
parents:
532
diff
changeset
|
103 # make docuviewer_ie_css refreshable for development |
585 | 104 #docuviewer_ie_css.index_html = refreshingImageFileIndexHtml |
501 | 105 jquery_js = ImageFile('js/jquery.js',globals()) |
130
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
106 |
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
107 |
95 | 108 def __init__(self,id,imageScalerUrl=None,textServerName=None,title="",digilibBaseUrl=None,thumbcols=2,thumbrows=5,authgroups="mpiwg"): |
0 | 109 """init document viewer""" |
110 self.id=id | |
111 self.title=title | |
25 | 112 self.thumbcols = thumbcols |
113 self.thumbrows = thumbrows | |
32 | 114 # authgroups is list of authorized groups (delimited by ,) |
115 self.authgroups = [s.strip().lower() for s in authgroups.split(',')] | |
84
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
116 # create template folder so we can always use template.something |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
117 |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
118 templateFolder = Folder('template') |
498 | 119 self['template'] = templateFolder # Zope-2.12 style |
120 #self._setObject('template',templateFolder) # old style | |
84
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
121 try: |
130
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
122 import MpdlXmlTextServer |
132 | 123 textServer = MpdlXmlTextServer.MpdlXmlTextServer(id='fulltextclient',serverName=textServerName) |
498 | 124 templateFolder['fulltextclient'] = textServer |
125 #templateFolder._setObject('fulltextclient',textServer) | |
84
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
126 except Exception, e: |
130
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
127 logging.error("Unable to create MpdlXmlTextServer for fulltextclient: "+str(e)) |
463 | 128 |
84
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
129 try: |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
130 from Products.zogiLib.zogiLib import zogiLib |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
131 zogilib = zogiLib(id="zogilib", title="zogilib for docuviewer", dlServerURL=imageScalerUrl, layout="book") |
498 | 132 templateFolder['zogilib'] = zogilib |
133 #templateFolder._setObject('zogilib',zogilib) | |
84
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
134 except Exception, e: |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
135 logging.error("Unable to create zogiLib for zogilib: "+str(e)) |
463 | 136 |
137 try: | |
138 # assume MetaDataFolder instance is called metadata | |
139 self.metadataService = getattr(self, 'metadata') | |
140 except Exception, e: | |
141 logging.error("Unable to find MetaDataFolder 'metadata': "+str(e)) | |
142 | |
477 | 143 if digilibBaseUrl is not None: |
144 self.digilibBaseUrl = digilibBaseUrl | |
566 | 145 self.digilibScalerUrl = digilibBaseUrl + '/servlet/Scaler' |
146 self.digilibViewerUrl = digilibBaseUrl + '/jquery/digilib.html' | |
477 | 147 |
130
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
148 |
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
149 # proxy text server methods to fulltextclient |
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
150 def getTextPage(self, **args): |
498 | 151 """returns full text content of page""" |
130
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
152 return self.template.fulltextclient.getTextPage(**args) |
22 | 153 |
508 | 154 def getSearchResults(self, **args): |
155 """loads list of search results and stores XML in docinfo""" | |
156 return self.template.fulltextclient.getSearchResults(**args) | |
157 | |
158 def getResultsPage(self, **args): | |
159 """returns one page of the search results""" | |
160 return self.template.fulltextclient.getResultsPage(**args) | |
161 | |
516 | 162 def getTextInfo(self, **args): |
163 """returns document info from the text server""" | |
164 return self.template.fulltextclient.getTextInfo(**args) | |
165 | |
499
3f9703746fef
more cleanup. new template for viewMode=index (not pretty so far).
casties
parents:
498
diff
changeset
|
166 def getToc(self, **args): |
508 | 167 """loads table of contents and stores XML in docinfo""" |
499
3f9703746fef
more cleanup. new template for viewMode=index (not pretty so far).
casties
parents:
498
diff
changeset
|
168 return self.template.fulltextclient.getToc(**args) |
3f9703746fef
more cleanup. new template for viewMode=index (not pretty so far).
casties
parents:
498
diff
changeset
|
169 |
3f9703746fef
more cleanup. new template for viewMode=index (not pretty so far).
casties
parents:
498
diff
changeset
|
170 def getTocPage(self, **args): |
3f9703746fef
more cleanup. new template for viewMode=index (not pretty so far).
casties
parents:
498
diff
changeset
|
171 """returns one page of the table of contents""" |
3f9703746fef
more cleanup. new template for viewMode=index (not pretty so far).
casties
parents:
498
diff
changeset
|
172 return self.template.fulltextclient.getTocPage(**args) |
3f9703746fef
more cleanup. new template for viewMode=index (not pretty so far).
casties
parents:
498
diff
changeset
|
173 |
561
9255acc4518d
CLOSED - # 256: display texts from different backends (sandbox)
casties
parents:
560
diff
changeset
|
174 def getRepositoryType(self, **args): |
9255acc4518d
CLOSED - # 256: display texts from different backends (sandbox)
casties
parents:
560
diff
changeset
|
175 """get repository type""" |
9255acc4518d
CLOSED - # 256: display texts from different backends (sandbox)
casties
parents:
560
diff
changeset
|
176 return self.template.fulltextclient.getRepositoryType(**args) |
9255acc4518d
CLOSED - # 256: display texts from different backends (sandbox)
casties
parents:
560
diff
changeset
|
177 |
559 | 178 def getTextDownloadUrl(self, **args): |
179 """get list of gis places on one page""" | |
180 return self.template.fulltextclient.getTextDownloadUrl(**args) | |
181 | |
506 | 182 def getPlacesOnPage(self, **args): |
183 """get list of gis places on one page""" | |
184 return self.template.fulltextclient.getPlacesOnPage(**args) | |
307 | 185 |
548 | 186 # Thumb list for CoolIris Plugin |
499
3f9703746fef
more cleanup. new template for viewMode=index (not pretty so far).
casties
parents:
498
diff
changeset
|
187 thumbs_main_rss = PageTemplateFile('zpt/thumbs_main_rss', globals()) |
68 | 188 security.declareProtected('View','thumbs_rss') |
189 def thumbs_rss(self,mode,url,viewMode="auto",start=None,pn=1): | |
190 ''' | |
191 view it | |
192 @param mode: defines how to access the document behind url | |
193 @param url: url which contains display information | |
194 @param viewMode: if images display images, if text display text, default is images (text,images or auto) | |
195 | |
196 ''' | |
197 | |
198 if not hasattr(self, 'template'): | |
199 # create template folder if it doesn't exist | |
200 self.manage_addFolder('template') | |
201 | |
202 if not self.digilibBaseUrl: | |
203 self.digilibBaseUrl = self.findDigilibUrl() or "http://nausikaa.mpiwg-berlin.mpg.de/digitallibrary" | |
204 | |
205 docinfo = self.getDocinfo(mode=mode,url=url) | |
338 | 206 #pageinfo = self.getPageinfo(start=start,current=pn,docinfo=docinfo) |
345 | 207 pageinfo = self.getPageinfo(start=start,current=pn, docinfo=docinfo) |
331 | 208 ''' ZDES ''' |
68 | 209 pt = getattr(self.template, 'thumbs_main_rss') |
210 | |
211 if viewMode=="auto": # automodus gewaehlt | |
453
beb7ccb92564
first version using elementtree instead of 4suite xml
casties
parents:
405
diff
changeset
|
212 if docinfo.has_key("textURL") or docinfo.get('textURLPath',None): #texturl gesetzt und textViewer konfiguriert |
68 | 213 viewMode="text" |
214 else: | |
215 viewMode="images" | |
216 | |
217 return pt(docinfo=docinfo,pageinfo=pageinfo,viewMode=viewMode) | |
465 | 218 |
68 | 219 |
22 | 220 security.declareProtected('View','index_html') |
548 | 221 def index_html(self,url,mode="texttool",viewMode="auto",viewLayer=None,tocMode=None,start=1,pn=1): |
464 | 222 """ |
543 | 223 show page |
471 | 224 @param url: url which contains display information |
57 | 225 @param mode: defines how to access the document behind url |
503 | 226 @param viewMode: 'images': display images, 'text': display text, 'xml': display xml, default is 'auto' |
543 | 227 @param viewLayer: sub-type of viewMode, e.g. layer 'dict' for viewMode='text' |
99 | 228 @param tocMode: type of 'table of contents' for navigation (thumbs, text, figures, none) |
464 | 229 """ |
0 | 230 |
503 | 231 logging.debug("documentViewer(index_html) mode=%s url=%s viewMode=%s viewLayer=%s start=%s pn=%s"%(mode,url,viewMode,viewLayer,start,pn)) |
22 | 232 |
233 if not hasattr(self, 'template'): | |
84
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
234 # this won't work |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
235 logging.error("template folder missing!") |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
236 return "ERROR: template folder missing!" |
22 | 237 |
84
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
238 if not getattr(self, 'digilibBaseUrl', None): |
132 | 239 self.digilibBaseUrl = self.findDigilibUrl() or "http://digilib.mpiwg-berlin.mpg.de/digitallibrary" |
22 | 240 |
548 | 241 # mode=filepath should not have toc-thumbs |
242 if tocMode is None: | |
243 if mode == "filepath": | |
244 tocMode = "none" | |
245 else: | |
246 tocMode = "thumbs" | |
247 | |
543 | 248 # docinfo: information about document (cached) |
518
91051b36b9cc
uses xml info from doc-info.xql for table of contents now.
casties
parents:
516
diff
changeset
|
249 docinfo = self.getDocinfo(mode=mode,url=url,tocMode=tocMode) |
97 | 250 |
543 | 251 # userinfo: user settings (cached) |
252 userinfo = self.getUserinfo() | |
253 | |
471 | 254 # auto viewMode: text if there is a text else images |
455 | 255 if viewMode=="auto": |
530 | 256 if docinfo.get('textURLPath', None): |
257 # docinfo.get('textURL', None) not implemented yet | |
471 | 258 viewMode = "text" |
543 | 259 if viewLayer is None and 'viewLayer' not in userinfo: |
260 # use layer dict as default | |
508 | 261 viewLayer = "dict" |
51
c5d3aabbf61b
textviewer now integrated, new modus auto introduced as standard for viewing
dwinter
parents:
50
diff
changeset
|
262 else: |
471 | 263 viewMode = "images" |
90
6a4a72033d58
new version with new full-text infrastructure and some more changed templates
casties
parents:
84
diff
changeset
|
264 |
474 | 265 elif viewMode == "text_dict": |
266 # legacy fix | |
267 viewMode = "text" | |
503 | 268 viewLayer = "dict" |
474 | 269 |
543 | 270 # safe viewLayer in userinfo |
271 userinfo['viewLayer'] = viewLayer | |
548 | 272 |
543 | 273 # pageinfo: information about page (not cached) |
274 pageinfo = self.getPageinfo(start=start, current=pn, docinfo=docinfo, userinfo=userinfo, viewMode=viewMode, viewLayer=viewLayer, tocMode=tocMode) | |
469 | 275 |
475 | 276 # get template /template/viewer_$viewMode |
277 pt = getattr(self.template, 'viewer_%s'%viewMode, None) | |
278 if pt is None: | |
279 logging.error("No template for viewMode=%s!"%viewMode) | |
280 # TODO: error page? | |
281 return "No template for viewMode=%s!"%viewMode | |
282 | |
455 | 283 # and execute with parameters |
471 | 284 return pt(docinfo=docinfo, pageinfo=pageinfo) |
0 | 285 |
525 | 286 def getAvailableLayers(self): |
287 """returns dict with list of available layers per viewMode""" | |
288 return self.availableLayers | |
289 | |
84
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
290 def findDigilibUrl(self): |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
291 """try to get the digilib URL from zogilib""" |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
292 url = self.template.zogilib.getDLBaseUrl() |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
293 return url |
480 | 294 |
295 def getScalerUrl(self, fn=None, pn=None, dw=100, dh=100, docinfo=None): | |
296 """returns URL to digilib Scaler with params""" | |
297 url = None | |
298 if docinfo is not None: | |
299 url = docinfo.get('imageURL', None) | |
300 | |
301 if url is None: | |
566 | 302 url = self.digilibScalerUrl |
480 | 303 if fn is None and docinfo is not None: |
304 fn = docinfo.get('imagePath','') | |
305 | |
306 url += "fn=%s"%fn | |
307 | |
308 if pn: | |
309 url += "&pn=%s"%pn | |
310 | |
311 url += "&dw=%s&dh=%s"%(dw,dh) | |
312 return url | |
126 | 313 |
314 def getDocumentViewerURL(self): | |
315 """returns the URL of this instance""" | |
316 return self.absolute_url() | |
84
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
317 |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
318 def getStyle(self, idx, selected, style=""): |
480 | 319 """returns a string with the given style and append 'sel' if idx == selected.""" |
84
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
320 #logger("documentViewer (getstyle)", logging.INFO, "idx: %s selected: %s style: %s"%(idx,selected,style)) |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
321 if idx == selected: |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
322 return style + 'sel' |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
323 else: |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
324 return style |
74 | 325 |
478 | 326 def getParams(self, param=None, val=None, params=None, duplicates=None): |
469 | 327 """returns dict with URL parameters. |
328 | |
329 Takes URL parameters and additionally param=val or dict params. | |
330 Deletes key if value is None.""" | |
453
beb7ccb92564
first version using elementtree instead of 4suite xml
casties
parents:
405
diff
changeset
|
331 # copy existing request params |
469 | 332 newParams=self.REQUEST.form.copy() |
453
beb7ccb92564
first version using elementtree instead of 4suite xml
casties
parents:
405
diff
changeset
|
333 # change single param |
25 | 334 if param is not None: |
31 | 335 if val is None: |
469 | 336 if newParams.has_key(param): |
337 del newParams[param] | |
25 | 338 else: |
469 | 339 newParams[param] = str(val) |
84
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
340 |
453
beb7ccb92564
first version using elementtree instead of 4suite xml
casties
parents:
405
diff
changeset
|
341 # change more params |
beb7ccb92564
first version using elementtree instead of 4suite xml
casties
parents:
405
diff
changeset
|
342 if params is not None: |
478 | 343 for (k, v) in params.items(): |
453
beb7ccb92564
first version using elementtree instead of 4suite xml
casties
parents:
405
diff
changeset
|
344 if v is None: |
beb7ccb92564
first version using elementtree instead of 4suite xml
casties
parents:
405
diff
changeset
|
345 # val=None removes param |
469 | 346 if newParams.has_key(k): |
347 del newParams[k] | |
453
beb7ccb92564
first version using elementtree instead of 4suite xml
casties
parents:
405
diff
changeset
|
348 |
beb7ccb92564
first version using elementtree instead of 4suite xml
casties
parents:
405
diff
changeset
|
349 else: |
469 | 350 newParams[k] = v |
478 | 351 |
352 if duplicates: | |
353 # eliminate lists (coming from duplicate keys) | |
354 for (k,v) in newParams.items(): | |
355 if isinstance(v, list): | |
356 if duplicates == 'comma': | |
357 # make comma-separated list of non-empty entries | |
358 newParams[k] = ','.join([t for t in v if t]) | |
359 elif duplicates == 'first': | |
360 # take first non-empty entry | |
361 newParams[k] = [t for t in v if t][0] | |
362 | |
469 | 363 return newParams |
364 | |
478 | 365 def getLink(self, param=None, val=None, params=None, baseUrl=None, paramSep='&', duplicates='comma'): |
469 | 366 """returns URL to documentviewer with parameter param set to val or from dict params""" |
478 | 367 urlParams = self.getParams(param=param, val=val, params=params, duplicates=duplicates) |
453
beb7ccb92564
first version using elementtree instead of 4suite xml
casties
parents:
405
diff
changeset
|
368 # quote values and assemble into query string (not escaping '/') |
514 | 369 ps = paramSep.join(["%s=%s"%(k, urllib.quote_plus(utf8ify(v), '/')) for (k, v) in urlParams.items()]) |
453
beb7ccb92564
first version using elementtree instead of 4suite xml
casties
parents:
405
diff
changeset
|
370 if baseUrl is None: |
469 | 371 baseUrl = self.getDocumentViewerURL() |
453
beb7ccb92564
first version using elementtree instead of 4suite xml
casties
parents:
405
diff
changeset
|
372 |
beb7ccb92564
first version using elementtree instead of 4suite xml
casties
parents:
405
diff
changeset
|
373 url = "%s?%s"%(baseUrl, ps) |
25 | 374 return url |
375 | |
478 | 376 def getLinkAmp(self, param=None, val=None, params=None, baseUrl=None, duplicates='comma'): |
68 | 377 """link to documentviewer with parameter param set to val""" |
478 | 378 return self.getLink(param=param, val=val, params=params, baseUrl=baseUrl, paramSep='&', duplicates=duplicates) |
81
fae97f071724
fixed problem with info.xml when url without index.meta
casties
parents:
79
diff
changeset
|
379 |
526 | 380 |
381 def setAvailableLayers(self, newLayerString=None): | |
382 """sets availableLayers to newLayerString or tries to autodetect available layers. | |
383 assumes layer templates have the form layer_{m}_{l} for layer l in mode m. | |
384 newLayerString is parsed as JSON.""" | |
385 if newLayerString is not None: | |
386 try: | |
387 layers = json.loads(newLayerString) | |
388 if 'text' in layers and 'images' in layers: | |
389 self.availableLayers = layers | |
390 return | |
391 except: | |
392 pass | |
393 | |
394 logging.error("invalid layers=%s! autodetecting..."%repr(newLayerString)) | |
395 | |
396 # start with builtin layers | |
397 self.availableLayers = self.builtinLayers.copy() | |
398 # add layers from templates | |
399 for t in self.template: | |
400 if t.startswith('layer_'): | |
401 try: | |
402 (x, m, l) = t.split('_', 3) | |
403 if m not in self.availableLayers: | |
404 # mode m doesn't exist -> new list | |
405 self.availableLayers[m] = [l] | |
406 | |
407 else: | |
408 # m exists -> append | |
409 if l not in self.availableLayers[m]: | |
410 self.availableLayers[m].append() | |
411 | |
412 except: | |
413 pass | |
414 | |
415 def getAvailableLayersJson(self): | |
416 """returns available layers as JSON string.""" | |
417 return json.dumps(self.availableLayers) | |
418 | |
469 | 419 |
57 | 420 def getInfo_xml(self,url,mode): |
421 """returns info about the document as XML""" | |
422 if not self.digilibBaseUrl: | |
514 | 423 self.digilibBaseUrl = self.findDigilibUrl() or "http://digilib.mpiwg-berlin.mpg.de/digitallibrary" |
57 | 424 |
425 docinfo = self.getDocinfo(mode=mode,url=url) | |
426 pt = getattr(self.template, 'info_xml') | |
427 return pt(docinfo=docinfo) | |
428 | |
528 | 429 def getAuthenticatedUser(self, anon=None): |
430 """returns the authenticated user object or None. (ignores Zopes anonymous user)""" | |
431 user = getSecurityManager().getUser() | |
432 if user is not None and user.getUserName() != "Anonymous User": | |
433 return user | |
434 else: | |
435 return anon | |
436 | |
35 | 437 def isAccessible(self, docinfo): |
32 | 438 """returns if access to the resource is granted""" |
439 access = docinfo.get('accessType', None) | |
167 | 440 logging.debug("documentViewer (accessOK) access type %s"%access) |
465 | 441 if access == 'free': |
167 | 442 logging.debug("documentViewer (accessOK) access is free") |
32 | 443 return True |
465 | 444 |
45 | 445 elif access is None or access in self.authgroups: |
35 | 446 # only local access -- only logged in users |
528 | 447 user = self.getAuthenticatedUser() |
167 | 448 logging.debug("documentViewer (accessOK) user=%s ip=%s"%(user,self.REQUEST.getClientAddr())) |
528 | 449 return (user is not None) |
32 | 450 |
167 | 451 logging.error("documentViewer (accessOK) unknown access type %s"%access) |
32 | 452 return False |
464 | 453 |
454 | |
543 | 455 def getUserinfo(self): |
456 """returns userinfo object""" | |
457 logging.debug("getUserinfo") | |
458 userinfo = {} | |
459 # look for cached userinfo in session | |
460 if self.REQUEST.SESSION.has_key('userinfo'): | |
461 userinfo = self.REQUEST.SESSION['userinfo'] | |
462 # check if its still current? | |
463 else: | |
464 # store in session | |
465 self.REQUEST.SESSION['userinfo'] = userinfo | |
466 | |
467 return userinfo | |
468 | |
518
91051b36b9cc
uses xml info from doc-info.xql for table of contents now.
casties
parents:
516
diff
changeset
|
469 def getDocinfo(self, mode, url, tocMode=None): |
464 | 470 """returns docinfo depending on mode""" |
471 logging.debug("getDocinfo: mode=%s, url=%s"%(mode,url)) | |
472 # look for cached docinfo in session | |
473 if self.REQUEST.SESSION.has_key('docinfo'): | |
474 docinfo = self.REQUEST.SESSION['docinfo'] | |
475 # check if its still current | |
476 if docinfo is not None and docinfo.get('mode', None) == mode and docinfo.get('url', None) == url: | |
477 logging.debug("getDocinfo: docinfo in session. keys=%s"%docinfo.keys()) | |
478 return docinfo | |
479 | |
480 # new docinfo | |
481 docinfo = {'mode': mode, 'url': url} | |
482 # add self url | |
483 docinfo['viewerUrl'] = self.getDocumentViewerURL() | |
477 | 484 docinfo['digilibBaseUrl'] = self.digilibBaseUrl |
566 | 485 docinfo['digilibScalerUrl'] = self.digilibScalerUrl |
486 docinfo['digilibViewerUrl'] = self.digilibViewerUrl | |
464 | 487 # get index.meta DOM |
488 docUrl = None | |
489 metaDom = None | |
490 if mode=="texttool": | |
491 # url points to document dir or index.meta | |
492 metaDom = self.metadataService.getDomFromPathOrUrl(url) | |
493 if metaDom is None: | |
494 raise IOError("Unable to find index.meta for mode=texttool!") | |
580
0806cb9061c1
fixed another bug when url starts with /mpiwg/online/
casties
parents:
578
diff
changeset
|
495 |
0806cb9061c1
fixed another bug when url starts with /mpiwg/online/
casties
parents:
578
diff
changeset
|
496 docUrl = url.replace('/index.meta', '') |
0806cb9061c1
fixed another bug when url starts with /mpiwg/online/
casties
parents:
578
diff
changeset
|
497 if url.startswith('/mpiwg/online/'): |
0806cb9061c1
fixed another bug when url starts with /mpiwg/online/
casties
parents:
578
diff
changeset
|
498 docUrl = url.replace('/mpiwg/online/', '', 1) |
464 | 499 |
500 elif mode=="imagepath": | |
501 # url points to folder with images, index.meta optional | |
502 # asssume index.meta in parent dir | |
503 docUrl = getParentPath(url) | |
504 metaDom = self.metadataService.getDomFromPathOrUrl(docUrl) | |
562 | 505 docinfo['imagePath'] = url.replace('/mpiwg/online/', '', 1) |
464 | 506 |
507 elif mode=="filepath": | |
508 # url points to image file, index.meta optional | |
566 | 509 docinfo['imageURL'] = "%s?fn=%s"%(self.digilibScalerUrl, url) |
548 | 510 docinfo['numPages'] = 1 |
464 | 511 # asssume index.meta is two path segments up |
512 docUrl = getParentPath(url, 2) | |
513 metaDom = self.metadataService.getDomFromPathOrUrl(docUrl) | |
514 | |
515 else: | |
516 logging.error("documentViewer (getdocinfo) unknown mode: %s!"%mode) | |
517 raise ValueError("Unknown mode %s! Has to be one of 'texttool','imagepath','filepath'."%(mode)) | |
518 | |
519 docinfo['documentUrl'] = docUrl | |
520 # process index.meta contents | |
473 | 521 if metaDom is not None and metaDom.tag == 'resource': |
464 | 522 # document directory name and path |
523 resource = self.metadataService.getResourceData(dom=metaDom) | |
524 if resource: | |
525 docinfo = self.getDocinfoFromResource(docinfo, resource) | |
526 | |
527 # texttool info | |
561
9255acc4518d
CLOSED - # 256: display texts from different backends (sandbox)
casties
parents:
560
diff
changeset
|
528 texttool = self.metadataService.getTexttoolData(dom=metaDom, recursive=1, all=True) |
464 | 529 if texttool: |
530 docinfo = self.getDocinfoFromTexttool(docinfo, texttool) | |
568 | 531 # document info from full text server |
516 | 532 if docinfo.get('textURLPath', None): |
565 | 533 docinfo = self.getTextInfo(mode=None, docinfo=docinfo) |
568 | 534 # include list of pages TODO: do we need this always? |
535 docinfo = self.getTextInfo(mode='pages', docinfo=docinfo) | |
464 | 536 |
537 # bib info | |
538 bib = self.metadataService.getBibData(dom=metaDom) | |
539 if bib: | |
548 | 540 # save extended version as 'bibx' TODO: ugly |
541 | 541 bibx = self.metadataService.getBibData(dom=metaDom, all=True, recursive=1) |
542 if len(bibx) == 1: | |
543 # unwrap list if possible | |
544 bibx = bibx[0] | |
545 | |
546 docinfo['bibx'] = bibx | |
547 docinfo = self.getDocinfoFromBib(docinfo, bib, bibx) | |
465 | 548 else: |
549 # no bib - try info.xml | |
550 docinfo = self.getDocinfoFromPresentationInfoXml(docinfo) | |
464 | 551 |
552 # auth info | |
553 access = self.metadataService.getAccessData(dom=metaDom) | |
554 if access: | |
555 docinfo = self.getDocinfoFromAccess(docinfo, access) | |
556 | |
466 | 557 # attribution info |
558 attribution = self.metadataService.getAttributionData(dom=metaDom) | |
559 if attribution: | |
560 logging.debug("getDocinfo: attribution=%s"%repr(attribution)) | |
561 docinfo['attribution'] = attribution | |
562 | |
563 # copyright info | |
564 copyright = self.metadataService.getCopyrightData(dom=metaDom) | |
565 if copyright: | |
566 logging.debug("getDocinfo: copyright=%s"%repr(copyright)) | |
567 docinfo['copyright'] = copyright | |
538 | 568 |
569 # DRI (permanent ID) | |
581 | 570 dri = self.metadataService.getDRI(dom=metaDom, type='mpiwg') |
538 | 571 if dri: |
572 docinfo['DRI'] = dri | |
466 | 573 |
578 | 574 # (presentation) context |
575 ctx = self.metadataService.getContextData(dom=metaDom, all=True) | |
576 if ctx: | |
577 logging.debug("getcontext: ctx=%s"%repr(ctx)) | |
578 docinfo['presentationContext'] = ctx | |
579 | |
464 | 580 # image path |
581 if mode != 'texttool': | |
532 | 582 # override image path from texttool with url parameter TODO: how about mode=auto? |
465 | 583 docinfo['imagePath'] = url.replace('/mpiwg/online/', '', 1) |
464 | 584 |
548 | 585 # check numPages |
586 if docinfo.get('numPages', 0) == 0: | |
587 # number of images from digilib | |
588 if docinfo.get('imagePath', None): | |
562 | 589 imgpath = docinfo['imagePath'].replace('/mpiwg/online/', '', 1) |
580
0806cb9061c1
fixed another bug when url starts with /mpiwg/online/
casties
parents:
578
diff
changeset
|
590 logging.debug("imgpath=%s"%imgpath) |
566 | 591 docinfo['imageURL'] = "%s?fn=%s"%(self.digilibScalerUrl, imgpath) |
562 | 592 docinfo = self.getDocinfoFromDigilib(docinfo, imgpath) |
548 | 593 else: |
594 # imagePath still missing? try "./pageimg" | |
595 imgPath = os.path.join(docUrl, 'pageimg') | |
596 docinfo = self.getDocinfoFromDigilib(docinfo, imgPath) | |
597 if docinfo.get('numPages', 0) > 0: | |
598 # there are pages | |
599 docinfo['imagePath'] = imgPath | |
566 | 600 docinfo['imageURL'] = "%s?fn=%s"%(self.digilibScalerUrl, docinfo['imagePath']) |
464 | 601 |
516 | 602 # check numPages |
603 if docinfo.get('numPages', 0) == 0: | |
604 if docinfo.get('numTextPages', 0) > 0: | |
605 # replace with numTextPages (text-only?) | |
606 docinfo['numPages'] = docinfo['numTextPages'] | |
607 | |
464 | 608 logging.debug("documentViewer (getdocinfo) docinfo: keys=%s"%docinfo.keys()) |
609 #logging.debug("documentViewer (getdocinfo) docinfo: %s"%docinfo) | |
610 # store in session | |
611 self.REQUEST.SESSION['docinfo'] = docinfo | |
612 return docinfo | |
613 | |
516 | 614 |
464 | 615 def getDocinfoFromResource(self, docinfo, resource): |
616 """reads contents of resource element into docinfo""" | |
617 docName = resource.get('name', None) | |
618 docinfo['documentName'] = docName | |
619 docPath = resource.get('archive-path', None) | |
620 if docPath: | |
621 # clean up document path | |
622 if docPath[0] != '/': | |
623 docPath = '/' + docPath | |
624 | |
625 if docName and (not docPath.endswith(docName)): | |
626 docPath += "/" + docName | |
627 | |
628 else: | |
629 # use docUrl as docPath | |
630 docUrl = docinfo['documentURL'] | |
631 if not docUrl.startswith('http:'): | |
632 docPath = docUrl | |
465 | 633 if docPath: |
634 # fix URLs starting with /mpiwg/online | |
635 docPath = docPath.replace('/mpiwg/online', '', 1) | |
636 | |
464 | 637 docinfo['documentPath'] = docPath |
638 return docinfo | |
639 | |
640 def getDocinfoFromTexttool(self, docinfo, texttool): | |
641 """reads contents of texttool element into docinfo""" | |
561
9255acc4518d
CLOSED - # 256: display texts from different backends (sandbox)
casties
parents:
560
diff
changeset
|
642 logging.debug("texttool=%s"%repr(texttool)) |
9255acc4518d
CLOSED - # 256: display texts from different backends (sandbox)
casties
parents:
560
diff
changeset
|
643 # unpack list if necessary |
9255acc4518d
CLOSED - # 256: display texts from different backends (sandbox)
casties
parents:
560
diff
changeset
|
644 if isinstance(texttool, list): |
9255acc4518d
CLOSED - # 256: display texts from different backends (sandbox)
casties
parents:
560
diff
changeset
|
645 texttool = texttool[0] |
9255acc4518d
CLOSED - # 256: display texts from different backends (sandbox)
casties
parents:
560
diff
changeset
|
646 |
464 | 647 # image dir |
561
9255acc4518d
CLOSED - # 256: display texts from different backends (sandbox)
casties
parents:
560
diff
changeset
|
648 imageDir = getMDText(texttool.get('image', None)) |
9255acc4518d
CLOSED - # 256: display texts from different backends (sandbox)
casties
parents:
560
diff
changeset
|
649 docPath = getMDText(docinfo.get('documentPath', None)) |
464 | 650 if imageDir and docPath: |
651 imageDir = os.path.join(docPath, imageDir) | |
652 imageDir = imageDir.replace('/mpiwg/online', '', 1) | |
653 docinfo['imagePath'] = imageDir | |
654 | |
655 # old style text URL | |
561
9255acc4518d
CLOSED - # 256: display texts from different backends (sandbox)
casties
parents:
560
diff
changeset
|
656 textUrl = getMDText(texttool.get('text', None)) |
464 | 657 if textUrl and docPath: |
658 if urlparse.urlparse(textUrl)[0] == "": #keine url | |
659 textUrl = os.path.join(docPath, textUrl) | |
660 | |
661 docinfo['textURL'] = textUrl | |
662 | |
561
9255acc4518d
CLOSED - # 256: display texts from different backends (sandbox)
casties
parents:
560
diff
changeset
|
663 # new style text-url-path (can be more than one with "repository" attribute) |
9255acc4518d
CLOSED - # 256: display texts from different backends (sandbox)
casties
parents:
560
diff
changeset
|
664 textUrlNode = texttool.get('text-url-path', None) |
9255acc4518d
CLOSED - # 256: display texts from different backends (sandbox)
casties
parents:
560
diff
changeset
|
665 if not isinstance(textUrlNode, list): |
9255acc4518d
CLOSED - # 256: display texts from different backends (sandbox)
casties
parents:
560
diff
changeset
|
666 textUrlNode = [textUrlNode] |
9255acc4518d
CLOSED - # 256: display texts from different backends (sandbox)
casties
parents:
560
diff
changeset
|
667 |
9255acc4518d
CLOSED - # 256: display texts from different backends (sandbox)
casties
parents:
560
diff
changeset
|
668 for tun in textUrlNode: |
9255acc4518d
CLOSED - # 256: display texts from different backends (sandbox)
casties
parents:
560
diff
changeset
|
669 textUrl = getMDText(tun) |
9255acc4518d
CLOSED - # 256: display texts from different backends (sandbox)
casties
parents:
560
diff
changeset
|
670 if textUrl: |
9255acc4518d
CLOSED - # 256: display texts from different backends (sandbox)
casties
parents:
560
diff
changeset
|
671 textUrlAtts = tun.get('@attr') |
9255acc4518d
CLOSED - # 256: display texts from different backends (sandbox)
casties
parents:
560
diff
changeset
|
672 if (textUrlAtts and 'repository' in textUrlAtts): |
9255acc4518d
CLOSED - # 256: display texts from different backends (sandbox)
casties
parents:
560
diff
changeset
|
673 textRepo = textUrlAtts['repository'] |
9255acc4518d
CLOSED - # 256: display texts from different backends (sandbox)
casties
parents:
560
diff
changeset
|
674 # use matching repository |
9255acc4518d
CLOSED - # 256: display texts from different backends (sandbox)
casties
parents:
560
diff
changeset
|
675 if self.getRepositoryType() == textRepo: |
9255acc4518d
CLOSED - # 256: display texts from different backends (sandbox)
casties
parents:
560
diff
changeset
|
676 docinfo['textURLPath'] = textUrl |
9255acc4518d
CLOSED - # 256: display texts from different backends (sandbox)
casties
parents:
560
diff
changeset
|
677 docinfo['textURLRepository'] = textRepo |
564 | 678 break |
561
9255acc4518d
CLOSED - # 256: display texts from different backends (sandbox)
casties
parents:
560
diff
changeset
|
679 |
9255acc4518d
CLOSED - # 256: display texts from different backends (sandbox)
casties
parents:
560
diff
changeset
|
680 else: |
9255acc4518d
CLOSED - # 256: display texts from different backends (sandbox)
casties
parents:
560
diff
changeset
|
681 # no repo attribute - use always |
9255acc4518d
CLOSED - # 256: display texts from different backends (sandbox)
casties
parents:
560
diff
changeset
|
682 docinfo['textURLPath'] = textUrl |
468 | 683 |
684 # page flow | |
561
9255acc4518d
CLOSED - # 256: display texts from different backends (sandbox)
casties
parents:
560
diff
changeset
|
685 docinfo['pageFlow'] = getMDText(texttool.get('page-flow', 'ltr')) |
468 | 686 |
687 # odd pages are left | |
561
9255acc4518d
CLOSED - # 256: display texts from different backends (sandbox)
casties
parents:
560
diff
changeset
|
688 docinfo['oddPage'] = getMDText(texttool.get('odd-scan-position', 'left')) |
468 | 689 |
541 | 690 # number of title page (default 1) |
561
9255acc4518d
CLOSED - # 256: display texts from different backends (sandbox)
casties
parents:
560
diff
changeset
|
691 docinfo['titlePage'] = getMDText(texttool.get('title-scan-no', 1)) |
464 | 692 |
693 # old presentation stuff | |
561
9255acc4518d
CLOSED - # 256: display texts from different backends (sandbox)
casties
parents:
560
diff
changeset
|
694 presentation = getMDText(texttool.get('presentation', None)) |
464 | 695 if presentation and docPath: |
465 | 696 if presentation.startswith('http:'): |
697 docinfo['presentationUrl'] = presentation | |
698 else: | |
699 docinfo['presentationUrl'] = os.path.join(docPath, presentation) | |
468 | 700 |
464 | 701 return docinfo |
702 | |
541 | 703 def getDocinfoFromBib(self, docinfo, bib, bibx=None): |
464 | 704 """reads contents of bib element into docinfo""" |
465 | 705 logging.debug("getDocinfoFromBib bib=%s"%repr(bib)) |
464 | 706 # put all raw bib fields in dict "bib" |
707 docinfo['bib'] = bib | |
708 bibtype = bib.get('@type', None) | |
709 docinfo['bibType'] = bibtype | |
710 # also store DC metadata for convenience | |
711 dc = self.metadataService.getDCMappedData(bib) | |
536
abd36d4d97b8
new version of index page. improvements for digilib page and thumbnail overview.
casties
parents:
535
diff
changeset
|
712 docinfo['creator'] = dc.get('creator','') |
abd36d4d97b8
new version of index page. improvements for digilib page and thumbnail overview.
casties
parents:
535
diff
changeset
|
713 docinfo['title'] = dc.get('title','') |
abd36d4d97b8
new version of index page. improvements for digilib page and thumbnail overview.
casties
parents:
535
diff
changeset
|
714 docinfo['date'] = dc.get('date','') |
464 | 715 return docinfo |
716 | |
717 def getDocinfoFromAccess(self, docinfo, acc): | |
718 """reads contents of access element into docinfo""" | |
719 #TODO: also read resource type | |
465 | 720 logging.debug("getDocinfoFromAccess acc=%s"%repr(acc)) |
464 | 721 try: |
465 | 722 acctype = acc['@attr']['type'] |
464 | 723 if acctype: |
724 access=acctype | |
725 if access in ['group', 'institution']: | |
726 access = acc['name'].lower() | |
727 | |
728 docinfo['accessType'] = access | |
729 | |
730 except: | |
731 pass | |
732 | |
733 return docinfo | |
734 | |
735 def getDocinfoFromDigilib(self, docinfo, path): | |
736 infoUrl=self.digilibBaseUrl+"/dirInfo-xml.jsp?mo=dir&fn="+path | |
737 # fetch data | |
738 txt = getHttpData(infoUrl) | |
739 if not txt: | |
740 logging.error("Unable to get dir-info from %s"%(infoUrl)) | |
741 return docinfo | |
742 | |
743 dom = ET.fromstring(txt) | |
744 size = getText(dom.find("size")) | |
745 logging.debug("getDocinfoFromDigilib: size=%s"%size) | |
746 if size: | |
747 docinfo['numPages'] = int(size) | |
748 else: | |
749 docinfo['numPages'] = 0 | |
750 | |
751 # TODO: produce and keep list of image names and numbers | |
752 return docinfo | |
753 | |
754 | |
465 | 755 def getDocinfoFromPresentationInfoXml(self,docinfo): |
756 """gets DC-like bibliographical information from the presentation entry in texttools""" | |
757 url = docinfo.get('presentationUrl', None) | |
758 if not url: | |
759 logging.error("getDocinfoFromPresentation: no URL!") | |
760 return docinfo | |
761 | |
762 dom = None | |
763 metaUrl = None | |
764 if url.startswith("http://"): | |
765 # real URL | |
766 metaUrl = url | |
767 else: | |
768 # online path | |
769 | |
770 server=self.digilibBaseUrl+"/servlet/Texter?fn=" | |
771 metaUrl=server+url | |
772 | |
773 txt=getHttpData(metaUrl) | |
774 if txt is None: | |
775 logging.error("Unable to read info.xml from %s"%(url)) | |
776 return docinfo | |
777 | |
778 dom = ET.fromstring(txt) | |
779 docinfo['creator']=getText(dom.find(".//author")) | |
780 docinfo['title']=getText(dom.find(".//title")) | |
781 docinfo['date']=getText(dom.find(".//date")) | |
782 return docinfo | |
783 | |
784 | |
543 | 785 def getPageinfo(self, current=None, start=None, rows=None, cols=None, docinfo=None, userinfo=None, viewMode=None, viewLayer=None, tocMode=None): |
22 | 786 """returns pageinfo with the given parameters""" |
503 | 787 logging.debug("getPageInfo(current=%s, start=%s, rows=%s, cols=%s, viewMode=%s, viewLayer=%s, tocMode=%s)"%(current,start,rows,cols,viewMode,viewLayer,tocMode)) |
22 | 788 pageinfo = {} |
471 | 789 pageinfo['viewMode'] = viewMode |
508 | 790 # split viewLayer if necessary |
791 if isinstance(viewLayer,basestring): | |
792 viewLayer = viewLayer.split(',') | |
793 | |
794 if isinstance(viewLayer, list): | |
795 logging.debug("getPageinfo: viewLayer is list:%s"%viewLayer) | |
796 # save (unique) list in viewLayers | |
797 seen = set() | |
798 viewLayers = [l for l in viewLayer if l and l not in seen and not seen.add(l)] | |
799 pageinfo['viewLayers'] = viewLayers | |
800 # stringify viewLayer | |
801 viewLayer = ','.join(viewLayers) | |
802 else: | |
803 #create list | |
804 pageinfo['viewLayers'] = [viewLayer] | |
805 | |
503 | 806 pageinfo['viewLayer'] = viewLayer |
471 | 807 pageinfo['tocMode'] = tocMode |
808 | |
516 | 809 # TODO: unify current and pn! |
25 | 810 current = getInt(current) |
811 pageinfo['current'] = current | |
480 | 812 pageinfo['pn'] = current |
25 | 813 rows = int(rows or self.thumbrows) |
814 pageinfo['rows'] = rows | |
815 cols = int(cols or self.thumbcols) | |
816 pageinfo['cols'] = cols | |
817 grpsize = cols * rows | |
818 pageinfo['groupsize'] = grpsize | |
476 | 819 # is start is empty use one around current |
61 | 820 start = getInt(start, default=(math.ceil(float(current)/float(grpsize))*grpsize-(grpsize-1))) |
821 # int(current / grpsize) * grpsize +1)) | |
22 | 822 pageinfo['start'] = start |
511 | 823 # get number of pages |
469 | 824 np = int(docinfo.get('numPages', 0)) |
825 if np == 0: | |
518
91051b36b9cc
uses xml info from doc-info.xql for table of contents now.
casties
parents:
516
diff
changeset
|
826 # try numTextPages |
91051b36b9cc
uses xml info from doc-info.xql for table of contents now.
casties
parents:
516
diff
changeset
|
827 np = docinfo.get('numTextPages', 0) |
91051b36b9cc
uses xml info from doc-info.xql for table of contents now.
casties
parents:
516
diff
changeset
|
828 if np != 0: |
91051b36b9cc
uses xml info from doc-info.xql for table of contents now.
casties
parents:
516
diff
changeset
|
829 docinfo['numPages'] = np |
91051b36b9cc
uses xml info from doc-info.xql for table of contents now.
casties
parents:
516
diff
changeset
|
830 |
511 | 831 # cache table of contents |
832 pageinfo['tocPageSize'] = getInt(self.REQUEST.get('tocPageSize', 30)) | |
469 | 833 pageinfo['numgroups'] = int(np / grpsize) |
834 if np % grpsize > 0: | |
835 pageinfo['numgroups'] += 1 | |
476 | 836 |
837 pageFlowLtr = docinfo.get('pageFlow', 'ltr') != 'rtl' | |
838 oddScanLeft = docinfo.get('oddPage', 'left') != 'right' | |
839 # add zeroth page for two columns | |
840 pageZero = (cols == 2 and (pageFlowLtr != oddScanLeft)) | |
841 pageinfo['pageZero'] = pageZero | |
480 | 842 pageinfo['pageBatch'] = self.getPageBatch(start=start, rows=rows, cols=cols, pageFlowLtr=pageFlowLtr, pageZero=pageZero, minIdx=1, maxIdx=np) |
516 | 843 # more page parameters |
453
beb7ccb92564
first version using elementtree instead of 4suite xml
casties
parents:
405
diff
changeset
|
844 pageinfo['characterNormalization'] = self.REQUEST.get('characterNormalization','reg') |
516 | 845 if docinfo.get('pageNumbers'): |
846 # get original page numbers | |
847 pageNumber = docinfo['pageNumbers'].get(current, None) | |
848 if pageNumber is not None: | |
849 pageinfo['pageNumberOrig'] = pageNumber['no'] | |
850 pageinfo['pageNumberOrigNorm'] = pageNumber['non'] | |
158 | 851 |
511 | 852 # cache search results |
853 pageinfo['resultPageSize'] = getInt(self.REQUEST.get('resultPageSize', 10)) | |
854 query = self.REQUEST.get('query',None) | |
855 pageinfo['query'] = query | |
856 if query: | |
857 queryType = self.REQUEST.get('queryType', 'fulltextMorph') | |
858 pageinfo['queryType'] = queryType | |
859 pageinfo['resultStart'] = getInt(self.REQUEST.get('resultStart', '1')) | |
860 self.getSearchResults(mode=queryType, query=query, pageinfo=pageinfo, docinfo=docinfo) | |
861 | |
862 # highlighting | |
863 highlightQuery = self.REQUEST.get('highlightQuery', None) | |
864 if highlightQuery: | |
865 pageinfo['highlightQuery'] = highlightQuery | |
866 pageinfo['highlightElement'] = self.REQUEST.get('highlightElement', '') | |
867 pageinfo['highlightElementPos'] = self.REQUEST.get('highlightElementPos', '') | |
460 | 868 |
22 | 869 return pageinfo |
460 | 870 |
463 | 871 |
482
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
872 def getPageBatch(self, start=1, rows=10, cols=2, pageFlowLtr=True, pageZero=False, minIdx=1, maxIdx=0): |
480 | 873 """returns dict with array of page informations for one screenfull of thumbnails""" |
482
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
874 batch = {} |
480 | 875 grpsize = rows * cols |
476 | 876 if maxIdx == 0: |
480 | 877 maxIdx = start + grpsize |
476 | 878 |
482
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
879 nb = int(math.ceil(maxIdx / float(grpsize))) |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
880 # list of all batch start and end points |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
881 batches = [] |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
882 if pageZero: |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
883 ofs = 0 |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
884 else: |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
885 ofs = 1 |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
886 |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
887 for i in range(nb): |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
888 s = i * grpsize + ofs |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
889 e = min((i + 1) * grpsize + ofs - 1, maxIdx) |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
890 batches.append({'start':s, 'end':e}) |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
891 |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
892 batch['batches'] = batches |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
893 |
476 | 894 pages = [] |
895 if pageZero and start == 1: | |
896 # correct beginning | |
897 idx = 0 | |
898 else: | |
899 idx = start | |
900 | |
901 for r in range(rows): | |
902 row = [] | |
903 for c in range(cols): | |
904 if idx < minIdx or idx > maxIdx: | |
905 page = {'idx':None} | |
906 else: | |
907 page = {'idx':idx} | |
908 | |
909 idx += 1 | |
910 if pageFlowLtr: | |
911 row.append(page) | |
912 else: | |
913 row.insert(0, page) | |
914 | |
915 pages.append(row) | |
916 | |
480 | 917 if start > 1: |
918 batch['prevStart'] = max(start - grpsize, 1) | |
919 else: | |
920 batch['prevStart'] = None | |
921 | |
526 | 922 if start + grpsize <= maxIdx: |
480 | 923 batch['nextStart'] = start + grpsize |
924 else: | |
925 batch['nextStart'] = None | |
926 | |
927 batch['pages'] = pages | |
571 | 928 batch['first'] = minIdx |
929 batch['last'] = maxIdx | |
482
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
930 return batch |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
931 |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
932 def getBatch(self, start=1, size=10, end=0, data=None, fullData=True): |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
933 """returns dict with information for one screenfull of data.""" |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
934 batch = {} |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
935 if end == 0: |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
936 end = start + size |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
937 |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
938 nb = int(math.ceil(end / float(size))) |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
939 # list of all batch start and end points |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
940 batches = [] |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
941 for i in range(nb): |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
942 s = i * size + 1 |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
943 e = min((i + 1) * size, end) |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
944 batches.append({'start':s, 'end':e}) |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
945 |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
946 batch['batches'] = batches |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
947 # list of elements in this batch |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
948 this = [] |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
949 j = 0 |
526 | 950 for i in range(start, min(start+size, end+1)): |
482
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
951 if data: |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
952 if fullData: |
526 | 953 d = data.get(i, None) |
482
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
954 else: |
526 | 955 d = data.get(j, None) |
482
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
956 j += 1 |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
957 |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
958 else: |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
959 d = i+1 |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
960 |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
961 this.append(d) |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
962 |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
963 batch['this'] = this |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
964 if start > 1: |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
965 batch['prevStart'] = max(start - size, 1) |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
966 else: |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
967 batch['prevStart'] = None |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
968 |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
969 if start + size < end: |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
970 batch['nextStart'] = start + size |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
971 else: |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
972 batch['nextStart'] = None |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
973 |
571 | 974 batch['first'] = start |
975 batch['last'] = end | |
480 | 976 return batch |
476 | 977 |
978 | |
546 | 979 def getAnnotatorGroupsForUser(self, user, annotationServerUrl="http://tuxserve03.mpiwg-berlin.mpg.de/AnnotationManager"): |
980 """returns list of groups {name:*, id:*} on the annotation server for the user""" | |
981 groups = [] | |
982 groupsUrl = "%s/annotator/groups?user=%s"%(annotationServerUrl,user) | |
983 data = getHttpData(url=groupsUrl, noExceptions=True) | |
984 if data: | |
985 res = json.loads(data) | |
986 rows = res.get('rows', None) | |
987 if rows is None: | |
988 return groups | |
989 for r in rows: | |
990 groups.append({'id': r.get('id', None), 'name': r.get('name', None), 'uri': r.get('uri', None)}) | |
991 | |
992 return groups | |
993 | |
994 | |
463 | 995 security.declareProtected('View management screens','changeDocumentViewerForm') |
996 changeDocumentViewerForm = PageTemplateFile('zpt/changeDocumentViewer', globals()) | |
22 | 997 |
526 | 998 def changeDocumentViewer(self,title="",digilibBaseUrl=None,thumbrows=2,thumbcols=5,authgroups='mpiwg',availableLayers=None,RESPONSE=None): |
22 | 999 """init document viewer""" |
1000 self.title=title | |
1001 self.digilibBaseUrl = digilibBaseUrl | |
566 | 1002 self.digilibScalerUrl = digilibBaseUrl + '/servlet/Scaler' |
1003 self.digilibViewerUrl = digilibBaseUrl + '/jquery/digilib.html' | |
25 | 1004 self.thumbrows = thumbrows |
1005 self.thumbcols = thumbcols | |
32 | 1006 self.authgroups = [s.strip().lower() for s in authgroups.split(',')] |
463 | 1007 try: |
1008 # assume MetaDataFolder instance is called metadata | |
1009 self.metadataService = getattr(self, 'metadata') | |
1010 except Exception, e: | |
1011 logging.error("Unable to find MetaDataFolder 'metadata': "+str(e)) | |
526 | 1012 |
1013 self.setAvailableLayers(availableLayers) | |
463 | 1014 |
22 | 1015 if RESPONSE is not None: |
1016 RESPONSE.redirect('manage_main') | |
0 | 1017 |
1018 def manage_AddDocumentViewerForm(self): | |
1019 """add the viewer form""" | |
22 | 1020 pt=PageTemplateFile('zpt/addDocumentViewer', globals()).__of__(self) |
0 | 1021 return pt() |
1022 | |
84
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
1023 def manage_AddDocumentViewer(self,id,imageScalerUrl="",textServerName="",title="",RESPONSE=None): |
0 | 1024 """add the viewer""" |
84
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
1025 newObj=documentViewer(id,imageScalerUrl=imageScalerUrl,title=title,textServerName=textServerName) |
0 | 1026 self._setObject(id,newObj) |
1027 | |
1028 if RESPONSE is not None: | |
1029 RESPONSE.redirect('manage_main') |