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