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