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