Mercurial > hg > documentViewer
annotate documentViewer.py @ 397:5b078a6d8909
new toggle option method
author | casties |
---|---|
date | Mon, 08 Nov 2010 17:08:18 +0100 |
parents | 28a03e25a0e8 |
children | 55f9eeebc338 |
rev | line source |
---|---|
46 | 1 |
0 | 2 from OFS.Folder import Folder |
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 |
235 | 8 from Products.zogiLib.zogiLib import browserCheck |
0 | 9 |
130
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
10 from Ft.Xml import EMPTY_NAMESPACE, Parse |
134 | 11 import Ft.Xml.Domlette |
0 | 12 import os.path |
31 | 13 import sys |
0 | 14 import urllib |
130
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
15 import urllib2 |
50
6c0f20cecc60
added evaluation of the presentation/info.xml in texttools
dwinter
parents:
49
diff
changeset
|
16 import logging |
61 | 17 import math |
46 | 18 import urlparse |
130
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
19 import cStringIO |
174 | 20 import re |
389 | 21 import string |
231 | 22 |
52 | 23 def logger(txt,method,txt2): |
24 """logging""" | |
25 logging.info(txt+ txt2) | |
26 | |
27 | |
25 | 28 def getInt(number, default=0): |
29 """returns always an int (0 in case of problems)""" | |
30 try: | |
31 return int(number) | |
32 except: | |
62 | 33 return int(default) |
25 | 34 |
0 | 35 def getTextFromNode(nodename): |
46 | 36 """get the cdata content of a node""" |
32 | 37 if nodename is None: |
38 return "" | |
0 | 39 nodelist=nodename.childNodes |
40 rc = "" | |
41 for node in nodelist: | |
42 if node.nodeType == node.TEXT_NODE: | |
43 rc = rc + node.data | |
44 return rc | |
45 | |
84
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
46 def serializeNode(node, encoding='utf-8'): |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
47 """returns a string containing node as XML""" |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
48 buf = cStringIO.StringIO() |
136 | 49 Ft.Xml.Domlette.Print(node, stream=buf, encoding=encoding) |
84
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
50 s = buf.getvalue() |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
51 buf.close() |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
52 return s |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
53 |
387 | 54 def browserCheck(self): |
55 """check the browsers request to find out the browser type""" | |
56 bt = {} | |
57 ua = self.REQUEST.get_header("HTTP_USER_AGENT") | |
58 bt['ua'] = ua | |
59 bt['isIE'] = False | |
60 bt['isN4'] = False | |
61 if string.find(ua, 'MSIE') > -1: | |
62 bt['isIE'] = True | |
63 else: | |
64 bt['isN4'] = (string.find(ua, 'Mozilla/4.') > -1) | |
65 | |
66 try: | |
67 nav = ua[string.find(ua, '('):] | |
68 ie = string.split(nav, "; ")[1] | |
69 if string.find(ie, "MSIE") > -1: | |
70 bt['versIE'] = string.split(ie, " ")[1] | |
71 except: pass | |
72 | |
73 bt['isMac'] = string.find(ua, 'Macintosh') > -1 | |
74 bt['isWin'] = string.find(ua, 'Windows') > -1 | |
75 bt['isIEWin'] = bt['isIE'] and bt['isWin'] | |
76 bt['isIEMac'] = bt['isIE'] and bt['isMac'] | |
77 bt['staticHTML'] = False | |
78 | |
79 return bt | |
234 | 80 |
81 | |
35 | 82 def getParentDir(path): |
83 """returns pathname shortened by one""" | |
84 return '/'.join(path.split('/')[0:-1]) | |
85 | |
86 | |
130
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
87 def getHttpData(url, data=None, num_tries=3, timeout=10): |
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
88 """returns result from url+data HTTP request""" |
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
89 # we do GET (by appending data to url) |
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
90 if isinstance(data, str) or isinstance(data, unicode): |
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
91 # if data is string then append |
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
92 url = "%s?%s"%(url,data) |
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
93 elif isinstance(data, dict) or isinstance(data, list) or isinstance(data, tuple): |
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
94 # urlencode |
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
95 url = "%s?%s"%(url,urllib.urlencode(data)) |
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
96 |
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
97 response = None |
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
98 errmsg = None |
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
99 for cnt in range(num_tries): |
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
100 try: |
167 | 101 logging.debug("getHttpData(#%s %ss) url=%s"%(cnt+1,timeout,url)) |
130
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
102 if sys.version_info < (2, 6): |
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
103 # set timeout on socket -- ugly :-( |
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
104 import socket |
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
105 socket.setdefaulttimeout(float(timeout)) |
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
106 response = urllib2.urlopen(url) |
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
107 else: |
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
108 response = urllib2.urlopen(url,timeout=float(timeout)) |
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
109 # check result? |
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
110 break |
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
111 except urllib2.HTTPError, e: |
167 | 112 logging.error("getHttpData: HTTP error(%s): %s"%(e.code,e)) |
130
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
113 errmsg = str(e) |
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
114 # stop trying |
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
115 break |
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
116 except urllib2.URLError, e: |
167 | 117 logging.error("getHttpData: URLLIB error(%s): %s"%(e.reason,e)) |
130
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
118 errmsg = str(e) |
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
119 # stop trying |
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
120 #break |
0 | 121 |
130
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
122 if response is not None: |
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
123 data = response.read() |
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
124 response.close() |
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
125 return data |
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
126 |
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
127 raise IOError("ERROR fetching HTTP data from %s: %s"%(url,errmsg)) |
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
128 #return None |
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
129 |
0 | 130 |
131 | |
22 | 132 ## |
133 ## documentViewer class | |
134 ## | |
135 class documentViewer(Folder): | |
0 | 136 """document viewer""" |
137 meta_type="Document viewer" | |
138 | |
139 security=ClassSecurityInfo() | |
22 | 140 manage_options=Folder.manage_options+( |
0 | 141 {'label':'main config','action':'changeDocumentViewerForm'}, |
142 ) | |
143 | |
22 | 144 # templates and forms |
145 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
|
146 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
|
147 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
|
148 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
|
149 page_main_images = PageTemplateFile('zpt/page_main_images', globals()) |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
150 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
|
151 page_main_text_dict = PageTemplateFile('zpt/page_main_text_dict', globals()) |
140 | 152 page_main_gis =PageTemplateFile ('zpt/page_main_gis', globals()) |
99 | 153 page_main_xml = PageTemplateFile('zpt/page_main_xml', globals()) |
22 | 154 head_main = PageTemplateFile('zpt/head_main', globals()) |
155 docuviewer_css = PageTemplateFile('css/docuviewer.css', globals()) | |
57 | 156 info_xml = PageTemplateFile('zpt/info_xml', globals()) |
130
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
157 |
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
158 |
68 | 159 thumbs_main_rss = PageTemplateFile('zpt/thumbs_main_rss', globals()) |
22 | 160 security.declareProtected('View management screens','changeDocumentViewerForm') |
161 changeDocumentViewerForm = PageTemplateFile('zpt/changeDocumentViewer', globals()) | |
162 | |
0 | 163 |
95 | 164 def __init__(self,id,imageScalerUrl=None,textServerName=None,title="",digilibBaseUrl=None,thumbcols=2,thumbrows=5,authgroups="mpiwg"): |
0 | 165 """init document viewer""" |
166 self.id=id | |
167 self.title=title | |
25 | 168 self.thumbcols = thumbcols |
169 self.thumbrows = thumbrows | |
32 | 170 # authgroups is list of authorized groups (delimited by ,) |
171 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
|
172 # 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
|
173 |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
174 templateFolder = Folder('template') |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
175 #self['template'] = templateFolder # Zope-2.12 style |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
176 self._setObject('template',templateFolder) # old style |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
177 try: |
130
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
178 import MpdlXmlTextServer |
132 | 179 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
|
180 #templateFolder['fulltextclient'] = xmlRpcClient |
130
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
181 templateFolder._setObject('fulltextclient',textServer) |
84
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
182 except Exception, e: |
130
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
183 logging.error("Unable to create MpdlXmlTextServer for fulltextclient: "+str(e)) |
84
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
184 try: |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
185 from Products.zogiLib.zogiLib import zogiLib |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
186 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
|
187 #templateFolder['zogilib'] = zogilib |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
188 templateFolder._setObject('zogilib',zogilib) |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
189 except Exception, e: |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
190 logging.error("Unable to create zogiLib for zogilib: "+str(e)) |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
191 |
130
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
192 |
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
193 # proxy text server methods to fulltextclient |
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
194 def getTextPage(self, **args): |
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
195 """get page""" |
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
196 return self.template.fulltextclient.getTextPage(**args) |
22 | 197 |
130
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
198 def getQuery(self, **args): |
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
199 """get query""" |
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
200 return self.template.fulltextclient.getQuery(**args) |
386 | 201 |
396 | 202 def getQueryResultHits(self, **args): |
203 """get query""" | |
204 return self.template.fulltextclient.getQueryResultHits(**args) | |
205 | |
206 def getQueryResultHitsText(self, **args): | |
207 """get query""" | |
208 return self.template.fulltextclient.getQueryResultHitsText(**args) | |
209 | |
210 def getQueryResultHitsFigures(self, **args): | |
211 """get query""" | |
212 return self.template.fulltextclient.getQueryResultHitsFigures(**args) | |
213 | |
386 | 214 def getPDF(self, **args): |
215 """get query""" | |
216 return self.template.fulltextclient.getPDF(**args) | |
130
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
217 |
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
218 def getSearch(self, **args): |
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
219 """get search""" |
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
220 return self.template.fulltextclient.getSearch(**args) |
256 | 221 |
222 def getGisPlaces(self, **args): | |
307 | 223 """get gis places""" |
256 | 224 return self.template.fulltextclient.getGisPlaces(**args) |
307 | 225 |
226 def getAllGisPlaces(self, **args): | |
310 | 227 """get all gis places """ |
228 return self.template.fulltextclient.getAllGisPlaces(**args) | |
229 | |
230 def getOrigPages(self, **args): | |
231 """get original page number """ | |
232 return self.template.fulltextclient.getOrigPages(**args) | |
233 | |
133 | 234 def getNumPages(self, docinfo): |
130
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
235 """get numpages""" |
133 | 236 return self.template.fulltextclient.getNumPages(docinfo) |
191 | 237 |
238 def getNumTextPages(self, docinfo): | |
239 """get numpages text""" | |
240 return self.template.fulltextclient.getNumTextPages(docinfo) | |
241 | |
130
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
242 def getTranslate(self, **args): |
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
243 """get translate""" |
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
244 return self.template.fulltextclient.getTranslate(**args) |
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
245 |
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
246 def getLemma(self, **args): |
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
247 """get lemma""" |
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
248 return self.template.fulltextclient.getLemma(**args) |
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
249 |
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
250 def getToc(self, **args): |
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
251 """get toc""" |
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
252 return self.template.fulltextclient.getToc(**args) |
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
253 |
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
254 def getTocPage(self, **args): |
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
255 """get tocpage""" |
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
256 return self.template.fulltextclient.getTocPage(**args) |
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
257 |
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
258 |
68 | 259 security.declareProtected('View','thumbs_rss') |
260 def thumbs_rss(self,mode,url,viewMode="auto",start=None,pn=1): | |
261 ''' | |
262 view it | |
263 @param mode: defines how to access the document behind url | |
264 @param url: url which contains display information | |
265 @param viewMode: if images display images, if text display text, default is images (text,images or auto) | |
266 | |
267 ''' | |
167 | 268 logging.debug("HHHHHHHHHHHHHH:load the rss") |
269 logger("documentViewer (index)", logging.INFO, "mode: %s url:%s start:%s pn:%s"%(mode,url,start,pn)) | |
68 | 270 |
271 if not hasattr(self, 'template'): | |
272 # create template folder if it doesn't exist | |
273 self.manage_addFolder('template') | |
274 | |
275 if not self.digilibBaseUrl: | |
276 self.digilibBaseUrl = self.findDigilibUrl() or "http://nausikaa.mpiwg-berlin.mpg.de/digitallibrary" | |
277 | |
278 docinfo = self.getDocinfo(mode=mode,url=url) | |
338 | 279 #pageinfo = self.getPageinfo(start=start,current=pn,docinfo=docinfo) |
345 | 280 pageinfo = self.getPageinfo(start=start,current=pn, docinfo=docinfo) |
331 | 281 ''' ZDES ''' |
68 | 282 pt = getattr(self.template, 'thumbs_main_rss') |
283 | |
284 if viewMode=="auto": # automodus gewaehlt | |
130
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
285 if docinfo.has_key("textURL") or docinfo.has_key('textURLPath'): #texturl gesetzt und textViewer konfiguriert |
68 | 286 viewMode="text" |
287 else: | |
288 viewMode="images" | |
289 | |
290 return pt(docinfo=docinfo,pageinfo=pageinfo,viewMode=viewMode) | |
291 | |
22 | 292 security.declareProtected('View','index_html') |
392 | 293 def index_html(self,url,mode="texttool",viewMode="auto",tocMode="thumbs",start=None,pn=1,mk=None, query=None, querySearch=None, characterNormalization="", optionsClose=None): |
22 | 294 ''' |
295 view it | |
57 | 296 @param mode: defines how to access the document behind url |
22 | 297 @param url: url which contains display information |
90
6a4a72033d58
new version with new full-text infrastructure and some more changed templates
casties
parents:
84
diff
changeset
|
298 @param viewMode: if images display images, if text display text, default is auto (text,images or auto) |
99 | 299 @param tocMode: type of 'table of contents' for navigation (thumbs, text, figures, none) |
141 | 300 @param characterNormalization type of text display (reg, norm, none) |
100 | 301 @param querySearch: type of different search modes (fulltext, fulltextMorph, xpath, xquery, ftIndex, ftIndexMorph, fulltextMorphLemma) |
22 | 302 ''' |
0 | 303 |
345 | 304 logging.debug("documentViewer (index) mode: %s url:%s start:%s pn:%s"%(mode,url,start,pn)) |
22 | 305 |
306 if not hasattr(self, 'template'): | |
84
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
307 # this won't work |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
308 logging.error("template folder missing!") |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
309 return "ERROR: template folder missing!" |
22 | 310 |
84
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
311 if not getattr(self, 'digilibBaseUrl', None): |
132 | 312 self.digilibBaseUrl = self.findDigilibUrl() or "http://digilib.mpiwg-berlin.mpg.de/digitallibrary" |
22 | 313 |
25 | 314 docinfo = self.getDocinfo(mode=mode,url=url) |
97 | 315 |
90
6a4a72033d58
new version with new full-text infrastructure and some more changed templates
casties
parents:
84
diff
changeset
|
316 if tocMode != "thumbs": |
6a4a72033d58
new version with new full-text infrastructure and some more changed templates
casties
parents:
84
diff
changeset
|
317 # get table of contents |
6a4a72033d58
new version with new full-text infrastructure and some more changed templates
casties
parents:
84
diff
changeset
|
318 docinfo = self.getToc(mode=tocMode, docinfo=docinfo) |
97 | 319 |
51
c5d3aabbf61b
textviewer now integrated, new modus auto introduced as standard for viewing
dwinter
parents:
50
diff
changeset
|
320 if viewMode=="auto": # automodus gewaehlt |
132 | 321 if docinfo.has_key('textURL') or docinfo.has_key('textURLPath'): #texturl gesetzt und textViewer konfiguriert |
127 | 322 viewMode="text_dict" |
51
c5d3aabbf61b
textviewer now integrated, new modus auto introduced as standard for viewing
dwinter
parents:
50
diff
changeset
|
323 else: |
c5d3aabbf61b
textviewer now integrated, new modus auto introduced as standard for viewing
dwinter
parents:
50
diff
changeset
|
324 viewMode="images" |
90
6a4a72033d58
new version with new full-text infrastructure and some more changed templates
casties
parents:
84
diff
changeset
|
325 |
345 | 326 pageinfo = self.getPageinfo(start=start,current=pn, docinfo=docinfo,viewMode=viewMode,tocMode=tocMode) |
127 | 327 |
90
6a4a72033d58
new version with new full-text infrastructure and some more changed templates
casties
parents:
84
diff
changeset
|
328 pt = getattr(self.template, 'viewer_main') |
75
9673218e155b
minorCVS: ----------------------------------------------------------------------
dwinter
parents:
74
diff
changeset
|
329 return pt(docinfo=docinfo,pageinfo=pageinfo,viewMode=viewMode,mk=self.generateMarks(mk)) |
0 | 330 |
74 | 331 def generateMarks(self,mk): |
332 ret="" | |
90
6a4a72033d58
new version with new full-text infrastructure and some more changed templates
casties
parents:
84
diff
changeset
|
333 if mk is None: |
6a4a72033d58
new version with new full-text infrastructure and some more changed templates
casties
parents:
84
diff
changeset
|
334 return "" |
134 | 335 if not isinstance(mk, list): |
132 | 336 mk=[mk] |
74 | 337 for m in mk: |
75
9673218e155b
minorCVS: ----------------------------------------------------------------------
dwinter
parents:
74
diff
changeset
|
338 ret+="mk=%s"%m |
74 | 339 return ret |
389 | 340 |
341 | |
387 | 342 def getBrowser(self): |
343 """getBrowser the version of browser """ | |
389 | 344 names="" |
345 names = browserCheck(self) | |
346 #logging.debug("XXXXXXXXXXXXXXXX: %s"%names) | |
347 return names | |
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 |
126 | 353 |
354 def getDocumentViewerURL(self): | |
355 """returns the URL of this instance""" | |
356 return self.absolute_url() | |
84
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
357 |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
358 def getStyle(self, idx, selected, style=""): |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
359 """returns a string with the given style and append 'sel' if path == selected.""" |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
360 #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
|
361 if idx == selected: |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
362 return style + 'sel' |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
363 else: |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
364 return style |
74 | 365 |
25 | 366 def getLink(self,param=None,val=None): |
367 """link to documentviewer with parameter param set to val""" | |
35 | 368 params=self.REQUEST.form.copy() |
25 | 369 if param is not None: |
31 | 370 if val is None: |
371 if params.has_key(param): | |
372 del params[param] | |
25 | 373 else: |
35 | 374 params[param] = str(val) |
84
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
375 |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
376 if params.get("mode", None) == "filepath": #wenn beim erst Aufruf filepath gesetzt wurde aendere das nun zu imagepath |
78 | 377 params["mode"] = "imagepath" |
378 params["url"] = getParentDir(params["url"]) | |
31 | 379 |
35 | 380 # quote values and assemble into query string |
135 | 381 #ps = "&".join(["%s=%s"%(k,urllib.quote(v)) for (k, v) in params.items()]) |
382 ps = urllib.urlencode(params) | |
35 | 383 url=self.REQUEST['URL1']+"?"+ps |
25 | 384 return url |
385 | |
68 | 386 def getLinkAmp(self,param=None,val=None): |
387 """link to documentviewer with parameter param set to val""" | |
388 params=self.REQUEST.form.copy() | |
389 if param is not None: | |
390 if val is None: | |
391 if params.has_key(param): | |
392 del params[param] | |
393 else: | |
394 params[param] = str(val) | |
395 | |
396 # quote values and assemble into query string | |
167 | 397 logging.debug("XYXXXXX: %s"%repr(params.items())) |
68 | 398 ps = "&".join(["%s=%s"%(k,urllib.quote(v)) for (k, v) in params.items()]) |
399 url=self.REQUEST['URL1']+"?"+ps | |
400 return url | |
81
fae97f071724
fixed problem with info.xml when url without index.meta
casties
parents:
79
diff
changeset
|
401 |
57 | 402 def getInfo_xml(self,url,mode): |
403 """returns info about the document as XML""" | |
404 | |
405 if not self.digilibBaseUrl: | |
406 self.digilibBaseUrl = self.findDigilibUrl() or "http://nausikaa.mpiwg-berlin.mpg.de/digitallibrary" | |
407 | |
408 docinfo = self.getDocinfo(mode=mode,url=url) | |
409 pt = getattr(self.template, 'info_xml') | |
410 return pt(docinfo=docinfo) | |
411 | |
394 | 412 def getOptionToggle(self, newState=None, optionName='text_options_open', initialState=True): |
413 """returns new option state""" | |
397 | 414 if not self.REQUEST.SESSION.has_key(optionName): |
394 | 415 # not in session -- initial |
416 opt = {'lastState': newState, 'state': initialState} | |
417 else: | |
397 | 418 opt = self.REQUEST.SESSION.get(optionName) |
394 | 419 if opt['lastState'] != newState: |
420 # state in session has changed -- toggle | |
421 opt['state'] = not opt['state'] | |
422 opt['lastState'] = newState | |
423 | |
424 self.REQUEST.SESSION[optionName] = opt | |
425 return opt['state'] | |
0 | 426 |
35 | 427 def isAccessible(self, docinfo): |
32 | 428 """returns if access to the resource is granted""" |
429 access = docinfo.get('accessType', None) | |
167 | 430 logging.debug("documentViewer (accessOK) access type %s"%access) |
45 | 431 if access is not None and access == 'free': |
167 | 432 logging.debug("documentViewer (accessOK) access is free") |
32 | 433 return True |
45 | 434 elif access is None or access in self.authgroups: |
35 | 435 # only local access -- only logged in users |
436 user = getSecurityManager().getUser() | |
167 | 437 logging.debug("documentViewer (accessOK) user=%s ip=%s"%(user,self.REQUEST.getClientAddr())) |
35 | 438 if user is not None: |
439 #print "user: ", user | |
440 return (user.getUserName() != "Anonymous User") | |
441 else: | |
442 return False | |
32 | 443 |
167 | 444 logging.error("documentViewer (accessOK) unknown access type %s"%access) |
32 | 445 return False |
35 | 446 |
32 | 447 |
73 | 448 def getDirinfoFromDigilib(self,path,docinfo=None,cut=0): |
29 | 449 """gibt param von dlInfo aus""" |
31 | 450 if docinfo is None: |
451 docinfo = {} | |
73 | 452 |
453 for x in range(cut): | |
78 | 454 |
73 | 455 path=getParentDir(path) |
78 | 456 |
40 | 457 infoUrl=self.digilibBaseUrl+"/dirInfo-xml.jsp?mo=dir&fn="+path |
29 | 458 |
167 | 459 logging.debug("documentViewer (getparamfromdigilib) dirInfo from %s"%(infoUrl)) |
29 | 460 |
130
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
461 txt = getHttpData(infoUrl) |
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
462 if txt is None: |
40 | 463 raise IOError("Unable to get dir-info from %s"%(infoUrl)) |
130
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
464 |
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
465 dom = Parse(txt) |
37 | 466 sizes=dom.xpath("//dir/size") |
167 | 467 logging.debug("documentViewer (getparamfromdigilib) dirInfo:size"%sizes) |
29 | 468 |
37 | 469 if sizes: |
470 docinfo['numPages'] = int(getTextFromNode(sizes[0])) | |
31 | 471 else: |
472 docinfo['numPages'] = 0 | |
84
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
473 |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
474 # TODO: produce and keep list of image names and numbers |
31 | 475 |
476 return docinfo | |
32 | 477 |
174 | 478 def getIndexMetaPath(self,url): |
479 """gib nur den Pfad zurueck""" | |
480 regexp = re.compile(r".*(experimental|permanent)/(.*)") | |
481 regpath = regexp.match(url) | |
482 if (regpath==None): | |
483 return "" | |
224 | 484 logging.debug("(getDomFromIndexMeta): URLXAXA: %s"%regpath.group(2)) |
174 | 485 return ("/mpiwg/online/"+regpath.group(1)+"/"+regpath.group(2)) |
486 | |
225 | 487 |
488 | |
174 | 489 def getIndexMetaUrl(self,url): |
490 """returns utr of index.meta document at url""" | |
491 | |
39
1dd90aabd366
added retry when reading index meta from texter applet
casties
parents:
38
diff
changeset
|
492 metaUrl = None |
35 | 493 if url.startswith("http://"): |
494 # real URL | |
39
1dd90aabd366
added retry when reading index meta from texter applet
casties
parents:
38
diff
changeset
|
495 metaUrl = url |
35 | 496 else: |
497 # online path | |
498 server=self.digilibBaseUrl+"/servlet/Texter?fn=" | |
40 | 499 metaUrl=server+url.replace("/mpiwg/online","") |
35 | 500 if not metaUrl.endswith("index.meta"): |
501 metaUrl += "/index.meta" | |
174 | 502 |
503 return metaUrl | |
504 | |
505 def getDomFromIndexMeta(self, url): | |
506 """get dom from index meta""" | |
507 dom = None | |
508 metaUrl = self.getIndexMetaUrl(url) | |
39
1dd90aabd366
added retry when reading index meta from texter applet
casties
parents:
38
diff
changeset
|
509 |
174 | 510 logging.debug("(getDomFromIndexMeta): METAURL: %s"%metaUrl) |
130
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
511 txt=getHttpData(metaUrl) |
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
512 if txt is None: |
39
1dd90aabd366
added retry when reading index meta from texter applet
casties
parents:
38
diff
changeset
|
513 raise IOError("Unable to read index meta from %s"%(url)) |
130
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
514 |
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
515 dom = Parse(txt) |
35 | 516 return dom |
50
6c0f20cecc60
added evaluation of the presentation/info.xml in texttools
dwinter
parents:
49
diff
changeset
|
517 |
6c0f20cecc60
added evaluation of the presentation/info.xml in texttools
dwinter
parents:
49
diff
changeset
|
518 def getPresentationInfoXML(self, url): |
6c0f20cecc60
added evaluation of the presentation/info.xml in texttools
dwinter
parents:
49
diff
changeset
|
519 """returns dom of info.xml document at url""" |
6c0f20cecc60
added evaluation of the presentation/info.xml in texttools
dwinter
parents:
49
diff
changeset
|
520 dom = None |
6c0f20cecc60
added evaluation of the presentation/info.xml in texttools
dwinter
parents:
49
diff
changeset
|
521 metaUrl = None |
6c0f20cecc60
added evaluation of the presentation/info.xml in texttools
dwinter
parents:
49
diff
changeset
|
522 if url.startswith("http://"): |
6c0f20cecc60
added evaluation of the presentation/info.xml in texttools
dwinter
parents:
49
diff
changeset
|
523 # real URL |
6c0f20cecc60
added evaluation of the presentation/info.xml in texttools
dwinter
parents:
49
diff
changeset
|
524 metaUrl = url |
6c0f20cecc60
added evaluation of the presentation/info.xml in texttools
dwinter
parents:
49
diff
changeset
|
525 else: |
6c0f20cecc60
added evaluation of the presentation/info.xml in texttools
dwinter
parents:
49
diff
changeset
|
526 # online path |
6c0f20cecc60
added evaluation of the presentation/info.xml in texttools
dwinter
parents:
49
diff
changeset
|
527 server=self.digilibBaseUrl+"/servlet/Texter?fn=" |
6c0f20cecc60
added evaluation of the presentation/info.xml in texttools
dwinter
parents:
49
diff
changeset
|
528 metaUrl=server+url.replace("/mpiwg/online","") |
6c0f20cecc60
added evaluation of the presentation/info.xml in texttools
dwinter
parents:
49
diff
changeset
|
529 |
130
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
530 txt=getHttpData(metaUrl) |
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
531 if txt is None: |
50
6c0f20cecc60
added evaluation of the presentation/info.xml in texttools
dwinter
parents:
49
diff
changeset
|
532 raise IOError("Unable to read infoXMLfrom %s"%(url)) |
130
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
533 |
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
534 dom = Parse(txt) |
50
6c0f20cecc60
added evaluation of the presentation/info.xml in texttools
dwinter
parents:
49
diff
changeset
|
535 return dom |
35 | 536 |
537 | |
70 | 538 def getAuthinfoFromIndexMeta(self,path,docinfo=None,dom=None,cut=0): |
35 | 539 """gets authorization info from the index.meta file at path or given by dom""" |
167 | 540 logging.debug("documentViewer (getauthinfofromindexmeta) path: %s"%(path)) |
32 | 541 |
542 access = None | |
543 | |
544 if docinfo is None: | |
545 docinfo = {} | |
546 | |
547 if dom is None: | |
78 | 548 for x in range(cut): |
70 | 549 path=getParentDir(path) |
174 | 550 dom = self.getDomFromIndexMeta(path) |
46 | 551 |
32 | 552 acctype = dom.xpath("//access-conditions/access/@type") |
553 if acctype and (len(acctype)>0): | |
554 access=acctype[0].value | |
35 | 555 if access in ['group', 'institution']: |
32 | 556 access = getTextFromNode(dom.xpath("//access-conditions/access/name")[0]).lower() |
557 | |
558 docinfo['accessType'] = access | |
559 return docinfo | |
29 | 560 |
32 | 561 |
70 | 562 def getBibinfoFromIndexMeta(self,path,docinfo=None,dom=None,cut=0): |
35 | 563 """gets bibliographical info from the index.meta file at path or given by dom""" |
167 | 564 logging.debug("documentViewer (getbibinfofromindexmeta) path: %s"%(path)) |
20 | 565 |
22 | 566 if docinfo is None: |
567 docinfo = {} | |
78 | 568 |
22 | 569 if dom is None: |
78 | 570 for x in range(cut): |
70 | 571 path=getParentDir(path) |
174 | 572 dom = self.getDomFromIndexMeta(path) |
573 | |
574 docinfo['indexMetaPath']=self.getIndexMetaPath(path); | |
79
df6952ac93e9
bug in getDocInforFromImagePath, relative lage der index.meta zu path war falsch.
dwinter
parents:
78
diff
changeset
|
575 |
167 | 576 logging.debug("documentViewer (getbibinfofromindexmeta cutted) path: %s"%(path)) |
59 | 577 # put in all raw bib fields as dict "bib" |
578 bib = dom.xpath("//bib/*") | |
579 if bib and len(bib)>0: | |
580 bibinfo = {} | |
581 for e in bib: | |
582 bibinfo[e.localName] = getTextFromNode(e) | |
583 docinfo['bib'] = bibinfo | |
584 | |
585 # extract some fields (author, title, year) according to their mapping | |
25 | 586 metaData=self.metadata.main.meta.bib |
587 bibtype=dom.xpath("//bib/@type") | |
588 if bibtype and (len(bibtype)>0): | |
589 bibtype=bibtype[0].value | |
20 | 590 else: |
25 | 591 bibtype="generic" |
59 | 592 |
25 | 593 bibtype=bibtype.replace("-"," ") # wrong typesiin index meta "-" instead of " " (not wrong! ROC) |
59 | 594 docinfo['bib_type'] = bibtype |
25 | 595 bibmap=metaData.generateMappingForType(bibtype) |
174 | 596 logging.debug("documentViewer (getbibinfofromindexmeta) bibmap:"+repr(bibmap)) |
597 logging.debug("documentViewer (getbibinfofromindexmeta) bibtype:"+repr(bibtype)) | |
32 | 598 # if there is no mapping bibmap is empty (mapping sometimes has empty fields) |
31 | 599 if len(bibmap) > 0 and len(bibmap['author'][0]) > 0: |
63 | 600 try: |
601 docinfo['author']=getTextFromNode(dom.xpath("//bib/%s"%bibmap['author'][0])[0]) | |
602 except: pass | |
603 try: | |
604 docinfo['title']=getTextFromNode(dom.xpath("//bib/%s"%bibmap['title'][0])[0]) | |
605 except: pass | |
606 try: | |
607 docinfo['year']=getTextFromNode(dom.xpath("//bib/%s"%bibmap['year'][0])[0]) | |
608 except: pass | |
167 | 609 logging.debug("documentViewer (getbibinfofromindexmeta) using mapping for %s"%bibtype) |
52 | 610 try: |
611 docinfo['lang']=getTextFromNode(dom.xpath("//bib/lang")[0]) | |
612 except: | |
613 docinfo['lang']='' | |
227 | 614 |
22 | 615 return docinfo |
83 | 616 |
218 | 617 |
618 def getNameFromIndexMeta(self,path,docinfo=None,dom=None,cut=0): | |
619 """gets name info from the index.meta file at path or given by dom""" | |
620 if docinfo is None: | |
621 docinfo = {} | |
622 | |
623 if dom is None: | |
624 for x in range(cut): | |
625 path=getParentDir(path) | |
626 dom = self.getDomFromIndexMeta(path) | |
330 | 627 |
229 | 628 docinfo['name']=getTextFromNode(dom.xpath("/resource/name")[0]) |
230 | 629 logging.debug("documentViewer docinfo[name] %s"%docinfo['name']) |
218 | 630 return docinfo |
83 | 631 |
84
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
632 def getDocinfoFromTextTool(self, url, dom=None, docinfo=None): |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
633 """parse texttool tag in index meta""" |
167 | 634 logging.debug("documentViewer (getdocinfofromtexttool) url: %s" % (url)) |
84
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
635 if docinfo is None: |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
636 docinfo = {} |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
637 if docinfo.get('lang', None) is None: |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
638 docinfo['lang'] = '' # default keine Sprache gesetzt |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
639 if dom is None: |
174 | 640 dom = self.getDomFromIndexMeta(url) |
84
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
641 |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
642 archivePath = None |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
643 archiveName = None |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
644 |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
645 archiveNames = dom.xpath("//resource/name") |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
646 if archiveNames and (len(archiveNames) > 0): |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
647 archiveName = getTextFromNode(archiveNames[0]) |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
648 else: |
130
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
649 logging.warning("documentViewer (getdocinfofromtexttool) resource/name missing in: %s" % (url)) |
84
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
650 |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
651 archivePaths = dom.xpath("//resource/archive-path") |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
652 if archivePaths and (len(archivePaths) > 0): |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
653 archivePath = getTextFromNode(archivePaths[0]) |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
654 # clean up archive path |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
655 if archivePath[0] != '/': |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
656 archivePath = '/' + archivePath |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
657 if archiveName and (not archivePath.endswith(archiveName)): |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
658 archivePath += "/" + archiveName |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
659 else: |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
660 # try to get archive-path from url |
167 | 661 logging.warning("documentViewer (getdocinfofromtexttool) resource/archive-path missing in: %s" % (url)) |
84
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
662 if (not url.startswith('http')): |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
663 archivePath = url.replace('index.meta', '') |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
664 |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
665 if archivePath is None: |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
666 # we balk without archive-path |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
667 raise IOError("Missing archive-path (for text-tool) in %s" % (url)) |
22 | 668 |
84
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
669 imageDirs = dom.xpath("//texttool/image") |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
670 if imageDirs and (len(imageDirs) > 0): |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
671 imageDir = getTextFromNode(imageDirs[0]) |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
672 |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
673 else: |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
674 # we balk with no image tag / not necessary anymore because textmode is now standard |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
675 #raise IOError("No text-tool info in %s"%(url)) |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
676 imageDir = "" |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
677 #xquery="//pb" |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
678 docinfo['imagePath'] = "" # keine Bilder |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
679 docinfo['imageURL'] = "" |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
680 |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
681 if imageDir and archivePath: |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
682 #print "image: ", imageDir, " archivepath: ", archivePath |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
683 imageDir = os.path.join(archivePath, imageDir) |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
684 imageDir = imageDir.replace("/mpiwg/online", '') |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
685 docinfo = self.getDirinfoFromDigilib(imageDir, docinfo=docinfo) |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
686 docinfo['imagePath'] = imageDir |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
687 |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
688 docinfo['imageURL'] = self.digilibBaseUrl + "/servlet/Scaler?fn=" + imageDir |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
689 |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
690 viewerUrls = dom.xpath("//texttool/digiliburlprefix") |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
691 if viewerUrls and (len(viewerUrls) > 0): |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
692 viewerUrl = getTextFromNode(viewerUrls[0]) |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
693 docinfo['viewerURL'] = viewerUrl |
130
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
694 |
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
695 # old style text URL |
84
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
696 textUrls = dom.xpath("//texttool/text") |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
697 if textUrls and (len(textUrls) > 0): |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
698 textUrl = getTextFromNode(textUrls[0]) |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
699 if urlparse.urlparse(textUrl)[0] == "": #keine url |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
700 textUrl = os.path.join(archivePath, textUrl) |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
701 # fix URLs starting with /mpiwg/online |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
702 if textUrl.startswith("/mpiwg/online"): |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
703 textUrl = textUrl.replace("/mpiwg/online", '', 1) |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
704 |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
705 docinfo['textURL'] = textUrl |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
706 |
130
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
707 # new style text-url-path |
84
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
708 textUrls = dom.xpath("//texttool/text-url-path") |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
709 if textUrls and (len(textUrls) > 0): |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
710 textUrl = getTextFromNode(textUrls[0]) |
102 | 711 docinfo['textURLPath'] = textUrl |
712 if not docinfo['imagePath']: | |
713 # text-only, no page images | |
205 | 714 docinfo = self.getNumTextPages(docinfo) |
84
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
715 |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
716 presentationUrls = dom.xpath("//texttool/presentation") |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
717 docinfo = self.getBibinfoFromIndexMeta(url, docinfo=docinfo, dom=dom) # get info von bib tag |
228 | 718 docinfo = self.getNameFromIndexMeta(url, docinfo=docinfo, dom=dom) |
386 | 719 |
84
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
720 |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
721 if presentationUrls and (len(presentationUrls) > 0): # ueberschreibe diese durch presentation informationen |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
722 # presentation url ergiebt sich ersetzen von index.meta in der url der fuer die Metadaten |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
723 # durch den relativen Pfad auf die presentation infos |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
724 presentationPath = getTextFromNode(presentationUrls[0]) |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
725 if url.endswith("index.meta"): |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
726 presentationUrl = url.replace('index.meta', presentationPath) |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
727 else: |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
728 presentationUrl = url + "/" + presentationPath |
102 | 729 |
84
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
730 docinfo = self.getBibinfoFromTextToolPresentation(presentationUrl, docinfo=docinfo, dom=dom) |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
731 |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
732 docinfo = self.getAuthinfoFromIndexMeta(url, docinfo=docinfo, dom=dom) # get access info |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
733 |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
734 return docinfo |
22 | 735 |
50
6c0f20cecc60
added evaluation of the presentation/info.xml in texttools
dwinter
parents:
49
diff
changeset
|
736 |
6c0f20cecc60
added evaluation of the presentation/info.xml in texttools
dwinter
parents:
49
diff
changeset
|
737 def getBibinfoFromTextToolPresentation(self,url,docinfo=None,dom=None): |
6c0f20cecc60
added evaluation of the presentation/info.xml in texttools
dwinter
parents:
49
diff
changeset
|
738 """gets the bibliographical information from the preseantion entry in texttools |
6c0f20cecc60
added evaluation of the presentation/info.xml in texttools
dwinter
parents:
49
diff
changeset
|
739 """ |
6c0f20cecc60
added evaluation of the presentation/info.xml in texttools
dwinter
parents:
49
diff
changeset
|
740 dom=self.getPresentationInfoXML(url) |
62 | 741 try: |
742 docinfo['author']=getTextFromNode(dom.xpath("//author")[0]) | |
743 except: | |
744 pass | |
745 try: | |
746 docinfo['title']=getTextFromNode(dom.xpath("//title")[0]) | |
747 except: | |
748 pass | |
749 try: | |
750 docinfo['year']=getTextFromNode(dom.xpath("//date")[0]) | |
751 except: | |
752 pass | |
50
6c0f20cecc60
added evaluation of the presentation/info.xml in texttools
dwinter
parents:
49
diff
changeset
|
753 return docinfo |
6c0f20cecc60
added evaluation of the presentation/info.xml in texttools
dwinter
parents:
49
diff
changeset
|
754 |
70 | 755 def getDocinfoFromImagePath(self,path,docinfo=None,cut=0): |
22 | 756 """path ist the path to the images it assumes that the index.meta file is one level higher.""" |
167 | 757 logging.debug("documentViewer (getdocinfofromimagepath) path: %s"%(path)) |
22 | 758 if docinfo is None: |
759 docinfo = {} | |
29 | 760 path=path.replace("/mpiwg/online","") |
22 | 761 docinfo['imagePath'] = path |
73 | 762 docinfo=self.getDirinfoFromDigilib(path,docinfo=docinfo,cut=cut) |
78 | 763 |
79
df6952ac93e9
bug in getDocInforFromImagePath, relative lage der index.meta zu path war falsch.
dwinter
parents:
78
diff
changeset
|
764 pathorig=path |
78 | 765 for x in range(cut): |
766 path=getParentDir(path) | |
167 | 767 logging.debug("documentViewer (getdocinfofromimagepath) PATH:"+path) |
31 | 768 imageUrl=self.digilibBaseUrl+"/servlet/Scaler?fn="+path |
22 | 769 docinfo['imageURL'] = imageUrl |
770 | |
79
df6952ac93e9
bug in getDocInforFromImagePath, relative lage der index.meta zu path war falsch.
dwinter
parents:
78
diff
changeset
|
771 #path ist the path to the images it assumes that the index.meta file is one level higher. |
df6952ac93e9
bug in getDocInforFromImagePath, relative lage der index.meta zu path war falsch.
dwinter
parents:
78
diff
changeset
|
772 docinfo = self.getBibinfoFromIndexMeta(pathorig,docinfo=docinfo,cut=cut+1) |
df6952ac93e9
bug in getDocInforFromImagePath, relative lage der index.meta zu path war falsch.
dwinter
parents:
78
diff
changeset
|
773 docinfo = self.getAuthinfoFromIndexMeta(pathorig,docinfo=docinfo,cut=cut+1) |
22 | 774 return docinfo |
20 | 775 |
22 | 776 |
777 def getDocinfo(self, mode, url): | |
778 """returns docinfo depending on mode""" | |
167 | 779 logging.debug("documentViewer (getdocinfo) mode: %s, url: %s"%(mode,url)) |
22 | 780 # look for cached docinfo in session |
51
c5d3aabbf61b
textviewer now integrated, new modus auto introduced as standard for viewing
dwinter
parents:
50
diff
changeset
|
781 if self.REQUEST.SESSION.has_key('docinfo'): |
22 | 782 docinfo = self.REQUEST.SESSION['docinfo'] |
783 # check if its still current | |
784 if docinfo is not None and docinfo.get('mode') == mode and docinfo.get('url') == url: | |
167 | 785 logging.debug("documentViewer (getdocinfo) docinfo in session: %s"%docinfo) |
22 | 786 return docinfo |
787 # new docinfo | |
788 docinfo = {'mode': mode, 'url': url} | |
789 if mode=="texttool": #index.meta with texttool information | |
790 docinfo = self.getDocinfoFromTextTool(url, docinfo=docinfo) | |
791 elif mode=="imagepath": | |
792 docinfo = self.getDocinfoFromImagePath(url, docinfo=docinfo) | |
70 | 793 elif mode=="filepath": |
75
9673218e155b
minorCVS: ----------------------------------------------------------------------
dwinter
parents:
74
diff
changeset
|
794 docinfo = self.getDocinfoFromImagePath(url, docinfo=docinfo,cut=1) |
22 | 795 else: |
167 | 796 logging.error("documentViewer (getdocinfo) unknown mode: %s!"%mode) |
90
6a4a72033d58
new version with new full-text infrastructure and some more changed templates
casties
parents:
84
diff
changeset
|
797 raise ValueError("Unknown mode %s! Has to be one of 'texttool','imagepath','filepath'."%(mode)) |
37 | 798 |
167 | 799 logging.debug("documentViewer (getdocinfo) docinfo: %s"%docinfo) |
362 | 800 #logging.debug("documentViewer (getdocinfo) docinfo: %s"%) |
22 | 801 self.REQUEST.SESSION['docinfo'] = docinfo |
802 return docinfo | |
128 | 803 |
356 | 804 def getPageinfo(self, current, start=None, rows=None, cols=None, docinfo=None, viewMode=None, tocMode=None,characterNormalization=""): |
22 | 805 """returns pageinfo with the given parameters""" |
806 pageinfo = {} | |
25 | 807 current = getInt(current) |
338 | 808 |
25 | 809 pageinfo['current'] = current |
810 rows = int(rows or self.thumbrows) | |
811 pageinfo['rows'] = rows | |
812 cols = int(cols or self.thumbcols) | |
813 pageinfo['cols'] = cols | |
814 grpsize = cols * rows | |
815 pageinfo['groupsize'] = grpsize | |
61 | 816 start = getInt(start, default=(math.ceil(float(current)/float(grpsize))*grpsize-(grpsize-1))) |
817 # int(current / grpsize) * grpsize +1)) | |
22 | 818 pageinfo['start'] = start |
25 | 819 pageinfo['end'] = start + grpsize |
90
6a4a72033d58
new version with new full-text infrastructure and some more changed templates
casties
parents:
84
diff
changeset
|
820 if (docinfo is not None) and ('numPages' in docinfo): |
25 | 821 np = int(docinfo['numPages']) |
822 pageinfo['end'] = min(pageinfo['end'], np) | |
823 pageinfo['numgroups'] = int(np / grpsize) | |
824 if np % grpsize > 0: | |
128 | 825 pageinfo['numgroups'] += 1 |
90
6a4a72033d58
new version with new full-text infrastructure and some more changed templates
casties
parents:
84
diff
changeset
|
826 pageinfo['viewMode'] = viewMode |
6a4a72033d58
new version with new full-text infrastructure and some more changed templates
casties
parents:
84
diff
changeset
|
827 pageinfo['tocMode'] = tocMode |
384 | 828 pageinfo['characterNormalization'] = self.REQUEST.get('characterNormalization','') |
829 pageinfo['query'] = self.REQUEST.get('query','') | |
392 | 830 pageinfo['optionsClose']= self.REQUEST.get('optionsClose','') |
384 | 831 pageinfo['queryType'] = self.REQUEST.get('queryType','') |
95 | 832 pageinfo['querySearch'] =self.REQUEST.get('querySearch', 'fulltext') |
99 | 833 pageinfo['textPN'] = self.REQUEST.get('textPN','1') |
384 | 834 pageinfo['highlightQuery'] = self.REQUEST.get('highlightQuery','') |
95 | 835 pageinfo['tocPageSize'] = self.REQUEST.get('tocPageSize', '30') |
105 | 836 pageinfo['queryPageSize'] =self.REQUEST.get('queryPageSize', '10') |
90
6a4a72033d58
new version with new full-text infrastructure and some more changed templates
casties
parents:
84
diff
changeset
|
837 pageinfo['tocPN'] = self.REQUEST.get('tocPN', '1') |
99 | 838 toc = int (pageinfo['tocPN']) |
839 pageinfo['textPages'] =int (toc) | |
158 | 840 |
362 | 841 |
326 | 842 |
99 | 843 if 'tocSize_%s'%tocMode in docinfo: |
844 tocSize = int(docinfo['tocSize_%s'%tocMode]) | |
845 tocPageSize = int(pageinfo['tocPageSize']) | |
128 | 846 # cached toc |
99 | 847 if tocSize%tocPageSize>0: |
848 tocPages=tocSize/tocPageSize+1 | |
849 else: | |
850 tocPages=tocSize/tocPageSize | |
128 | 851 pageinfo['tocPN'] = min (tocPages,toc) |
95 | 852 pageinfo['searchPN'] =self.REQUEST.get('searchPN','1') |
112 | 853 pageinfo['sn'] =self.REQUEST.get('sn','') |
22 | 854 return pageinfo |
855 | |
128 | 856 def changeDocumentViewer(self,title="",digilibBaseUrl=None,thumbrows=2,thumbcols=5,authgroups='mpiwg',RESPONSE=None): |
22 | 857 """init document viewer""" |
858 self.title=title | |
859 self.digilibBaseUrl = digilibBaseUrl | |
25 | 860 self.thumbrows = thumbrows |
861 self.thumbcols = thumbcols | |
32 | 862 self.authgroups = [s.strip().lower() for s in authgroups.split(',')] |
22 | 863 if RESPONSE is not None: |
864 RESPONSE.redirect('manage_main') | |
0 | 865 |
866 def manage_AddDocumentViewerForm(self): | |
867 """add the viewer form""" | |
22 | 868 pt=PageTemplateFile('zpt/addDocumentViewer', globals()).__of__(self) |
0 | 869 return pt() |
870 | |
84
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
871 def manage_AddDocumentViewer(self,id,imageScalerUrl="",textServerName="",title="",RESPONSE=None): |
0 | 872 """add the viewer""" |
84
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
873 newObj=documentViewer(id,imageScalerUrl=imageScalerUrl,title=title,textServerName=textServerName) |
0 | 874 self._setObject(id,newObj) |
875 | |
876 if RESPONSE is not None: | |
877 RESPONSE.redirect('manage_main') | |
22 | 878 |
879 ## DocumentViewerTemplate class | |
880 class DocumentViewerTemplate(ZopePageTemplate): | |
881 """Template for document viewer""" | |
882 meta_type="DocumentViewer Template" | |
883 | |
884 | |
885 def manage_addDocumentViewerTemplateForm(self): | |
886 """Form for adding""" | |
887 pt=PageTemplateFile('zpt/addDocumentViewerTemplate', globals()).__of__(self) | |
888 return pt() | |
889 | |
890 def manage_addDocumentViewerTemplate(self, id='viewer_main', title=None, text=None, | |
891 REQUEST=None, submit=None): | |
892 "Add a Page Template with optional file content." | |
893 | |
894 self._setObject(id, DocumentViewerTemplate(id)) | |
895 ob = getattr(self, id) | |
53
f4e0af8c281d
NEW - # 44: ECHO - vollst?ndige bibliographische Angabe
dwinter
parents:
52
diff
changeset
|
896 txt=file(os.path.join(package_home(globals()),'zpt/viewer_main.zpt'),'r').read() |
167 | 897 logging.info("txt %s:"%txt) |
53
f4e0af8c281d
NEW - # 44: ECHO - vollst?ndige bibliographische Angabe
dwinter
parents:
52
diff
changeset
|
898 ob.pt_edit(txt,"text/html") |
22 | 899 if title: |
900 ob.pt_setTitle(title) | |
901 try: | |
902 u = self.DestinationURL() | |
903 except AttributeError: | |
904 u = REQUEST['URL1'] | |
905 | |
906 u = "%s/%s" % (u, urllib.quote(id)) | |
907 REQUEST.RESPONSE.redirect(u+'/manage_main') | |
908 return '' | |
909 | |
910 | |
41 | 911 |