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