annotate documentViewer_old.py @ 453:beb7ccb92564 elementtree

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