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