annotate documentViewer_old.py @ 467:8b75d55582e8 elementtree

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