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