Annotation of zogiLib/zogiLib.py, revision 1.51
1.1 dwinter 1: from Products.PageTemplates.PageTemplateFile import PageTemplateFile
2: from Products.PageTemplates.PageTemplate import PageTemplate
3: from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate
1.4 dwinter 4: from OFS.Image import Image
5: from webdav.common import rfc1123_date
1.1 dwinter 6:
7: import xml.dom.minidom
8: from OFS.Folder import Folder
1.32 dwinter 9: from xml_helpers import getUniqueElementText,getText
1.1 dwinter 10: import os
11: import re
12: import string
13: import urllib
1.24 casties 14: import types
1.44 casties 15: import random
1.1 dwinter 16: from Globals import package_home
17:
1.50 casties 18: ZOGIVERSION = "0.9.12b ROC:27.10.2004"
1.30 casties 19:
20: def cropf(f):
21: """returns a float with reduced precision"""
22: return float(int(f * 10000)/10000.0)
23:
1.28 casties 24:
1.15 casties 25: def sendFile(self, filename, type):
1.44 casties 26: """sends an object or a local file (from the product) as response"""
1.17 casties 27: paths = filename.split('/')
28: object = self
29: # look for an object called filename
30: for path in paths:
31: if hasattr(object, path):
32: object = getattr(object, path)
33: else:
34: object = None
35: break
36: if object:
1.18 casties 37: # if the object exists then send it
38: return object.index_html(self.REQUEST.REQUEST, self.REQUEST.RESPONSE)
1.17 casties 39: else:
40: # send a local file with the given content-type
41: fn = os.path.join(package_home(globals()), filename)
42: self.REQUEST.RESPONSE.setHeader("Content-Type", type)
43: self.REQUEST.RESPONSE.write(file(fn).read())
1.15 casties 44: return
45:
1.26 casties 46: def browserCheck(self):
1.18 casties 47: """check the browsers request to find out the browser type"""
1.26 casties 48: bt = {}
49: ua = self.REQUEST.get_header("HTTP_USER_AGENT")
50: bt['ua'] = ua
1.51 ! casties 51: bt['isIE'] = False
! 52: bt['isN4'] = False
1.50 casties 53: if string.find(ua, 'MSIE') > -1:
54: bt['isIE'] = True
55: else:
56: bt['isN4'] = (string.find(ua, 'Mozilla/4.') > -1)
57:
58: try:
59: nav = ua[string.find(ua, '('):]
60: ie = string.split(nav, "; ")[1]
61: if string.find(ie, "MSIE") > -1:
62: bt['versIE'] = string.split(ie, " ")[1]
63: except: pass
64:
1.26 casties 65: bt['isMac'] = string.find(ua, 'Macintosh') > -1
66: bt['isWin'] = string.find(ua, 'Windows') > -1
67: bt['isIEWin'] = bt['isIE'] and bt['isWin']
68: bt['isIEMac'] = bt['isIE'] and bt['isMac']
69: bt['staticHTML'] = False
1.5 dwinter 70:
1.26 casties 71: return bt
1.5 dwinter 72:
1.1 dwinter 73:
1.4 dwinter 74: class zogiImage(Image):
75: """einzelnes Image"""
76: meta_type="zogiImage"
77:
1.18 casties 78: manage_options=ZopePageTemplate.manage_options+(
79: {'label':'Main config','action':'changeZogiImageForm'},
80: )
1.4 dwinter 81:
82:
83: def __init__(self,id,title,baseUrl,queryString,content_type='',precondition=''):
84: """init"""
85: self.id=id
86: self.title=title
1.46 casties 87: if baseUrl:
88: self.baseUrl=baseUrl
89: else:
90: self.baseUrl="http://nausikaa.mpiwg-berlin.mpg.de/digitallibrary/servlet/Scaler?"
91:
1.4 dwinter 92: self.queryString=queryString
93: self.content_type=content_type
94: self.precondition=precondition
95:
96: def getData(self):
97: """getUrlData"""
98: return urllib.urlopen(self.baseUrl+self.queryString)
99:
100: def changeZogiImageForm(self):
101: """Main configuration"""
1.18 casties 102: pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/changeZogiImageForm.zpt')).__of__(self)
1.4 dwinter 103: return pt()
104:
105: def changeZogiImage(self,title,baseUrl, queryString,RESPONSE=None):
106: """change it"""
107: self.title=title
108: self.baseUrl=baseUrl
109: self.queryString=queryString
110:
111: if RESPONSE is not None:
112: RESPONSE.redirect('manage_main')
113:
1.46 casties 114: def index_html(self, REQUEST, RESPONSE):
115: """service the request by redirecting to digilib server"""
116: RESPONSE.redirect(self.baseUrl+self.queryString)
117: return ''
1.4 dwinter 118:
119:
120:
121: def manage_addZogiImageForm(self):
122: """Form for adding"""
1.18 casties 123: pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/addZogiImage.zpt')).__of__(self)
1.4 dwinter 124: return pt()
125:
126:
127: def manage_addZogiImage(self,id,title,baseUrl, queryString,RESPONSE=None):
1.46 casties 128: """add zogiimage"""
1.4 dwinter 129: newObj=zogiImage(id,title,baseUrl, queryString)
130: self.Destination()._setObject(id,newObj)
131: if RESPONSE is not None:
132: RESPONSE.redirect('manage_main')
133:
134:
135:
1.1 dwinter 136: class zogiLib(Folder):
1.50 casties 137: """digilib frontend with ZOPE"""
1.1 dwinter 138:
139: meta_type="zogiLib"
1.32 dwinter 140: #xxxx
1.1 dwinter 141:
1.18 casties 142: manage_options = Folder.manage_options+(
143: {'label':'Main Config','action':'changeZogiLibForm'},
144: )
1.1 dwinter 145:
1.37 casties 146: def __init__(self, id, title, dlServerURL, layout="book", basePath="", dlTarget=None, dlToolbarBaseURL=None):
1.1 dwinter 147: """init"""
148:
149: self.id=id
150: self.title=title
1.34 casties 151: self.dlServerURL = dlServerURL
1.21 casties 152: self.basePath=basePath
1.37 casties 153: self.layout=layout
1.44 casties 154: self.dlTarget = dlTarget
1.1 dwinter 155:
1.37 casties 156: if dlToolbarBaseURL:
157: self.dlToolbarBaseURL = dlToolbarBaseURL
158: else:
159: self.dlToolbarBaseURL = dlServerURL + "/digimage.jsp?"
160:
161:
1.28 casties 162: def version(self):
163: """version information"""
164: return ZOGIVERSION
165:
1.32 dwinter 166: def getContextStatic(self):
167: """get all the contexts which go to static pages"""
168:
1.33 dwinter 169: try:
170: dom=xml.dom.minidom.parse(urllib.urlopen(self.getMetaFileName()))
171: contexts=dom.getElementsByTagName("context")
172:
173: ret=[]
174: for context in contexts:
175: name=getUniqueElementText(context.getElementsByTagName("name"))
176:
177: link=getUniqueElementText(context.getElementsByTagName("link"))
178: if name or link:
179: ret.append((name,link))
180: return ret
181: except:
182: return []
1.32 dwinter 183:
184: def getContextDatabases(self):
185: """get all dynamic contexts"""
1.33 dwinter 186: try:
187: dom=xml.dom.minidom.parse(urllib.urlopen(self.getMetaFileName()))
188: contexts=dom.getElementsByTagName("context")
189: ret=[]
190: for context in contexts:
191: metaDataLinks=context.getElementsByTagName("meta-datalink")
192: for metaDataLink in metaDataLinks:
193: db=metaDataLink.getAttribute("db")
194: link=self.REQUEST['URL1']+"/dl_db?db=%s"%db
195: if db:
196: ret.append((db,link))
197: metaDataLinks=context.getElementsByTagName("meta-baselink")
198:
199: for metaDataLink in metaDataLinks:
200: db=metaDataLink.getAttribute("db")
201: link=self.REQUEST['URL1']+"/dl_db?db=%s"%db
202: if db:
203: ret.append((db,link))
204:
205: return ret
206: except:
1.45 casties 207:
208: return []
1.32 dwinter 209:
1.39 casties 210:
1.32 dwinter 211: def formatHTML(self,url,label=None,viewUrl=None):
212:
213: sets=xml.dom.minidom.parse(urllib.urlopen(url)).getElementsByTagName('dataset')
214: ret=""
215: print label
216: if label:
217: ret+="""<a href="%s">%s</a>"""%(viewUrl,label)
218: for set in sets:
219: ret+="<table>"
220: for node in set.childNodes:
221: if hasattr(node,'tagName'):
222: tag=node.tagName
223: label=node.getAttribute("label")
224: if not label:
225: label=tag
226: text=getText(node.childNodes)
227: ret+="""<tr><td><b>%s:</b></td><td>%s</td></tr>"""%(label,text)
228: ret+="</table>"
229: return ret
1.39 casties 230:
1.32 dwinter 231:
232: def getMetaData(self):
233: """getMetaData"""
1.33 dwinter 234: try:
235: dom=xml.dom.minidom.parse(urllib.urlopen(self.getMetaFileName()))
236: except:
237: return "error metadata"
238:
1.32 dwinter 239: contexts=dom.getElementsByTagName("context")
240: ret=[]
241: db=self.getDLParam("db")
242: ob=self.getDLParam("object")
243:
244: fn=self.getDLParam("fn")
245: pn=self.getDLParam("pn")
246: if not fn:
247: fn=""
248: if not pn:
249: pn=""
250: if not ob:
251: ob=""
252:
253: for context in contexts:
254: metaDataLinks=context.getElementsByTagName("meta-datalink")
255: for metaDataLink in metaDataLinks:
256:
257: if (db==metaDataLink.getAttribute("db")) or (len(metaDataLinks)==1):
258:
259: link=getUniqueElementText(metaDataLink.getElementsByTagName("metadata-url"))
260: label=getUniqueElementText(metaDataLink.getElementsByTagName("label"))
261: url=getUniqueElementText(metaDataLink.getElementsByTagName("url"))
262:
263: return self.formatHTML(link,label,url)
264:
265: metaDataLinks=context.getElementsByTagName("meta-baselink")
266:
267: for metaDataLink in metaDataLinks:
268:
269: if db==metaDataLink.getAttribute("db") or (len(metaDataLinks)==1):
270:
271: link=getUniqueElementText(metaDataLink.getElementsByTagName("metadata-url"))
272: label=getUniqueElementText(metaDataLink.getElementsByTagName("label"))
273: url=getUniqueElementText(metaDataLink.getElementsByTagName("url"))
274:
275: return self.formatHTML(link+'fn=%s&pn=%s&object=%s'%(fn,pn,ob),label,url)
276: return ret
277:
1.39 casties 278:
1.18 casties 279: def getDLInfo(self):
280: """get DLInfo from digilib server"""
281: paramH={}
1.34 casties 282: baseUrl=self.dlServerURL+"/dlInfo-xml.jsp"
1.18 casties 283: try:
1.39 casties 284: url=urllib.urlopen(baseUrl+'?'+self.REQUEST['QUERY_STRING'])
1.18 casties 285: dom=xml.dom.minidom.parse(url)
286: params=dom.getElementsByTagName('parameter')
287: for param in params:
288: paramH[param.getAttribute('name')]=param.getAttribute('value')
289: return paramH
290: except:
1.34 casties 291: return {}
1.18 casties 292:
1.1 dwinter 293:
1.18 casties 294: def createHeadJS(self):
1.19 casties 295: """generate all javascript tags for head"""
1.26 casties 296: self.checkQuery()
1.44 casties 297: bt = self.REQUEST.SESSION.get('browserType', {})
1.26 casties 298: if bt['staticHTML']:
299: return
300:
1.18 casties 301: pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/zogilib_head_js')).__of__(self)
302: return pt()
1.19 casties 303:
304: def createParamJS(self):
305: """generate javascript for parameters only"""
1.26 casties 306: self.checkQuery()
307: bt = self.REQUEST.SESSION['browserType']
308: if bt['staticHTML']:
309: return
310:
1.19 casties 311: pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/zogilib_param_js')).__of__(self)
312: return pt()
313:
1.3 dwinter 314:
1.26 casties 315: def createScalerImg(self, requestString=None, bottom=0, side=0, width=500, height=500):
1.18 casties 316: """generate Scaler IMG Tag"""
1.20 casties 317: self.checkQuery()
318: bt = self.REQUEST.SESSION['browserType']
1.24 casties 319: # override with parameters from session
320: if self.REQUEST.SESSION.has_key('scalerDiv'):
1.26 casties 321: (requestString, bottom, side, width, height) = self.REQUEST.SESSION['scalerDiv']
1.24 casties 322: # if not explicitly defined take normal request
1.18 casties 323: if not requestString:
1.21 casties 324: requestString = self.getAllDLParams()
1.35 casties 325: url = self.dlServerURL+'/servlet/Scaler?'+requestString
1.24 casties 326: # construct bottom and side insets
327: b_par = ""
328: s_par = ""
329: if (bottom != 0) or (side != 0):
330: b_par = "-" + str(int(bottom))
331: s_par = "-" + str(int(side))
1.18 casties 332: tag = ""
1.26 casties 333: if bt['staticHTML']:
334: tag += '<div id="scaler"><img id="pic" src="%s&dw=%i&dh=%i" /></div>'%(url, int(width-side), int(height-bottom))
1.18 casties 335: else:
1.26 casties 336: if bt['isN4']:
337: # N4 needs layers
338: tag += '<ilayer id="scaler">'
339: else:
340: tag += '<div id="scaler">'
341: tag += '<script type="text/javascript">'
342: tag += "var ps = bestPicSize(getElement('scaler'));"
343: # write img tag with javascript
344: tag += 'document.write(\'<img id="pic" src="%s&dw=\'+(ps.width%s)+\'&dh=\'+(ps.height%s)+\'" />\');'%(url, s_par, b_par)
345: tag += '</script>'
346: if bt['isN4']:
347: tag += '</ilayer>'
348: else:
349: tag += '</div>'
1.18 casties 350: return tag
1.1 dwinter 351:
1.26 casties 352: def createScalerDiv(self, requestString = None, bottom = 0, side = 0, width=500, height=500):
1.23 casties 353: """generate scaler img and table with navigation arrows"""
354: self.checkQuery()
1.24 casties 355: if requestString != None or bottom != 0 or side != 0:
1.26 casties 356: self.REQUEST.SESSION['scalerDiv'] = (requestString, bottom, side, width, height)
1.24 casties 357: else:
358: if self.REQUEST.SESSION.has_key('scalerDiv'):
1.26 casties 359: # make shure to remove unused parameter
1.24 casties 360: del self.REQUEST.SESSION['scalerDiv']
1.26 casties 361:
1.23 casties 362: pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt/zogilib_img_div')).__of__(self)
363: return pt()
364:
1.18 casties 365: def createAuxDiv(self):
366: """generate other divs"""
1.20 casties 367: self.checkQuery()
368: bt = self.REQUEST.SESSION['browserType']
1.26 casties 369: if bt['staticHTML']:
370: return
371: if bt['isN4']:
1.18 casties 372: f = 'zpt/zogilib_divsN4.zpt'
373: else:
374: f = 'zpt/zogilib_divs.zpt'
375: pt=PageTemplateFile(os.path.join(package_home(globals()),f)).__of__(self)
376: return pt()
1.3 dwinter 377:
1.9 dwinter 378:
1.18 casties 379: def option_js(self):
1.28 casties 380: """javascript"""
381: return sendFile(self, 'js/option.js', 'text/plain')
1.1 dwinter 382:
1.18 casties 383: def dl_lib_js(self):
384: """javascript"""
1.34 casties 385: return sendFile(self, 'js/dllib.js', 'text/plain')
1.18 casties 386:
387: def js_lib_js(self):
388: """javascript"""
1.34 casties 389: return sendFile(self, 'js/baselib.js', 'text/plain')
1.1 dwinter 390:
1.18 casties 391: def optionwindow(self):
392: """showoptions"""
1.26 casties 393: self.checkQuery()
394: bt = self.REQUEST.SESSION['browserType']
395: if bt['staticHTML']:
396: pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/optionwindow_static.zpt')).__of__(self)
397: else:
1.37 casties 398: tp = "viewingTools.zpt"
399: if hasattr(self, tp):
400: pt = getattr(self, tp)
1.31 dwinter 401: else:
402: pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/optionwindow.zpt')).__of__(self)
1.37 casties 403:
404: return pt()
1.13 casties 405:
406: def mark1(self):
407: """mark image"""
1.18 casties 408: return sendFile(self, 'images/mark1.gif', 'image/gif')
1.13 casties 409:
410: def mark2(self):
411: """mark image"""
1.18 casties 412: return sendFile(self, 'images/mark2.gif', 'image/gif')
1.13 casties 413:
414: def mark3(self):
415: """mark image"""
1.18 casties 416: return sendFile(self, 'images/mark3.gif', 'image/gif')
1.13 casties 417:
418: def mark4(self):
419: """mark image"""
1.18 casties 420: return sendFile(self, 'images/mark4.gif', 'image/gif')
1.13 casties 421:
422: def mark5(self):
423: """mark image"""
1.18 casties 424: return sendFile(self, 'images/mark5.gif', 'image/gif')
1.13 casties 425:
426: def mark6(self):
427: """mark image"""
1.18 casties 428: return sendFile(self, 'images/mark6.gif', 'image/gif')
1.13 casties 429:
430: def mark7(self):
431: """mark image"""
1.18 casties 432: return sendFile(self, 'images/mark7.gif', 'image/gif')
1.13 casties 433:
434: def mark8(self):
435: """mark image"""
1.18 casties 436: return sendFile(self, 'images/mark8.gif', 'image/gif')
1.13 casties 437:
438: def corner1(self):
439: """mark image"""
1.18 casties 440: return sendFile(self, 'images/olinks.gif', 'image/gif')
1.13 casties 441:
442: def corner2(self):
443: """mark image"""
1.18 casties 444: return sendFile(self, 'images/orechts.gif', 'image/gif')
1.13 casties 445:
446: def corner3(self):
447: """mark image"""
1.18 casties 448: return sendFile(self, 'images/ulinks.gif', 'image/gif')
1.13 casties 449:
450: def corner4(self):
451: """mark image"""
1.18 casties 452: return sendFile(self, 'images/urechts.gif', 'image/gif')
1.13 casties 453:
1.22 casties 454: def up_img(self):
455: """mark image"""
456: return sendFile(self, 'images/up.gif', 'image/gif')
457:
458: def down_img(self):
459: """mark image"""
460: return sendFile(self, 'images/down.gif', 'image/gif')
461:
462: def left_img(self):
463: """mark image"""
464: return sendFile(self, 'images/left.gif', 'image/gif')
465:
466: def right_img(self):
467: """mark image"""
468: return sendFile(self, 'images/right.gif', 'image/gif')
1.13 casties 469:
470:
1.1 dwinter 471:
472: def index_html(self):
473: """main action"""
1.26 casties 474: self.checkQuery()
475: bt = self.REQUEST.SESSION['browserType']
1.18 casties 476: tp = "zogiLibMainTemplate"
1.32 dwinter 477:
1.18 casties 478: if hasattr(self, tp):
479: pt = getattr(self, tp)
480: else:
1.26 casties 481: tpt = self.layout
1.32 dwinter 482:
1.26 casties 483: if bt['staticHTML']:
484: tpt = "static"
485:
486: pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/zogiLibMain_%s'%tpt)).__of__(self)
487:
1.18 casties 488: return pt()
489:
1.1 dwinter 490:
1.21 casties 491: def storeQuery(self, more = None):
1.1 dwinter 492: """storeQuery in session"""
1.18 casties 493: dlParams = {}
1.1 dwinter 494: for fm in self.REQUEST.form.keys():
1.18 casties 495: dlParams[fm] = self.REQUEST.form[fm]
1.21 casties 496: # look for more
497: if more:
498: for fm in more.split('&'):
499: try:
500: pv = fm.split('=')
501: dlParams[pv[0]] = pv[1]
502: except:
1.26 casties 503: pass
504:
1.21 casties 505: # parse digilib mode parameter
1.18 casties 506: if 'mo' in dlParams:
507: if len(dlParams['mo']) > 0:
508: modes=dlParams['mo'].split(',')
509: else:
510: modes=[]
1.44 casties 511:
512: wid = self.getWID()
513: self.REQUEST.set('wid', wid)
514: self.setSubSession('dlQuery', dlParams)
515: self.setSubSession('dlModes', modes)
516: self.setSubSession('dlInfo', self.getDLInfo())
1.26 casties 517: if not self.REQUEST.SESSION.has_key('browserType'):
518: self.REQUEST.SESSION['browserType'] = browserCheck(self)
519:
520: return
1.1 dwinter 521:
1.20 casties 522: def checkQuery(self):
523: """check if the query has been stored"""
1.44 casties 524: if not (self.REQUEST.SESSION and self.getSubSession('dlQuery')) :
1.20 casties 525: print "ZOGILIB: have to store query!!"
1.26 casties 526: self.storeQuery()
1.24 casties 527: return
1.23 casties 528:
1.24 casties 529: def zogilibPath(self, otherbase=None):
1.23 casties 530: """returns an URL to the zogiLib instance"""
531: url = self.REQUEST['URL1']
1.24 casties 532: # should end with "/"
533: if len(url) > 0 and url[-1] != '/':
534: url += '/'
535: if type(otherbase) is str:
536: url += otherbase
537: else:
538: url += self.basePath
1.23 casties 539: # should end with "/"
540: if len(url) > 0 and url[-1] != '/':
541: url += '/'
542: return url
1.44 casties 543:
544: def zogilibAction(self, action, otherbase=None, wid=None):
545: """returns a URL with zogilib path, action and wid"""
546: url = self.zogilibPath(otherbase)
547: url += action
548: if wid:
549: url += '?wid=' + wid
550: else:
551: url += '?wid=' + self.getWID()
552: return url
553:
554: def getSubSession(self, key, default=None):
555: """returns an element from a session with a wid"""
556: wid = self.getWID()
557: return self.REQUEST.SESSION.get(key+'_'+wid, default)
558:
559: def setSubSession(self, key, value):
560: """puts an element in a session with a wid"""
561: wid = self.getWID()
562: self.REQUEST.SESSION.set(key+'_'+wid, value)
563: return
564:
565: def getWID(self):
566: """returns a (new) window id"""
567: wid = self.REQUEST.get('wid')
568: if not wid:
569: wid = 'digi_'+str(int(random.random()*10000))
570: print "new WID:", wid
571: return wid
1.3 dwinter 572:
1.22 casties 573: def getDLParam(self, param):
1.18 casties 574: """returns parameter"""
1.3 dwinter 575: try:
1.44 casties 576: return self.getSubSession('dlQuery').get(param)
1.3 dwinter 577: except:
1.24 casties 578: return
1.3 dwinter 579:
1.18 casties 580: def setDLParam(self, param, value):
581: """sets parameter"""
1.44 casties 582: dlParams = self.getSubSession('dlQuery')
583: #try:
584: dlParams[param] = value
585: #except:
586: # self.setSubSession('dlQuery', {param: value})
1.18 casties 587: return
588:
589: def getAllDLParams(self):
590: """parameter string for digilib"""
1.44 casties 591: dlParams = self.getSubSession('dlQuery')
1.18 casties 592: # save modes
1.44 casties 593: modes = self.getSubSession('dlModes')
1.18 casties 594: dlParams['mo'] = string.join(modes, ',')
595: # assemble query string
596: ret = ""
597: for param in dlParams.keys():
1.29 casties 598: if dlParams[param] is None: continue
1.18 casties 599: val = str(dlParams[param])
600: if val != "":
601: ret += param + "=" + val + "&"
1.28 casties 602:
1.18 casties 603: # omit trailing "&"
604: return ret.rstrip('&')
605:
606:
607: def setDLParams(self,pn=None,ws=None,rot=None,brgt=None,cont=None):
608: """setze Parameter"""
609:
1.23 casties 610: self.setDLParam('brgt', brgt)
611: self.setDLParam('cont', cont)
612: self.setDLParam('ws', ws)
613: self.setDLParam('rot', rot)
1.18 casties 614:
615: if pn:
1.21 casties 616: # unmark
617: self.setDLParam('mk', None)
1.18 casties 618: self.setDLParam('pn', pn)
619:
620: return self.display()
621:
622:
623: def display(self):
624: """(re)display page"""
1.44 casties 625: if not self.getDLParam('wid'):
626: wid = self.getWID()
627: self.setDLParam('wid', wid)
628:
1.18 casties 629: params = self.getAllDLParams()
1.44 casties 630:
1.21 casties 631: if self.basePath:
632: self.REQUEST.RESPONSE.redirect(self.REQUEST['URL2']+'?'+params)
633: else:
634: self.REQUEST.RESPONSE.redirect(self.REQUEST['URL1']+'?'+params)
1.18 casties 635:
1.32 dwinter 636: def getMetaFileName(self):
1.34 casties 637: url=self.dlServerURL+'/dlContext-xml.jsp?'+self.getAllDLParams()
638: return urlbase
1.26 casties 639:
1.34 casties 640: def getToolbarPageURL(self):
641: """returns a toolbar-enabled page URL"""
1.37 casties 642: url=self.dlToolbarBaseURL+self.getAllDLParams()
1.34 casties 643: return url
1.32 dwinter 644:
1.30 casties 645: def getDLTarget(self):
646: """returns dlTarget"""
647: self.checkQuery()
648: s = self.dlTarget
1.44 casties 649: if s == None:
650: s = ""
1.30 casties 651: # s = 'dl'
652: # if self.getDLParam('fn'):
653: # s += "_" + self.getDLParam('fn')
654: # if self.getDLParam('pn'):
655: # s += "_" + self.getDLParam('pn')
656: return s
657:
1.26 casties 658: def setStaticHTML(self, static=True):
659: """sets the preference to static HTML"""
660: self.checkQuery()
661: self.REQUEST.SESSION['browserType']['staticHTML'] = static
662: return
663:
664: def isStaticHTML(self):
665: """returns if the page is using static HTML only"""
666: self.checkQuery()
667: return self.REQUEST.SESSION['browserType']['staticHTML']
668:
1.18 casties 669: def getPT(self):
670: """pagenums"""
1.47 casties 671: di = self.getSubSession('dlInfo')
1.18 casties 672: if di:
673: return int(di['pt'])
674: else:
675: return 1
676:
677: def getPN(self):
678: """Pagenum"""
679: pn = self.getDLParam('pn')
1.25 casties 680: try:
1.18 casties 681: return int(pn)
1.25 casties 682: except:
1.3 dwinter 683: return 1
684:
1.18 casties 685: def getBiggerWS(self):
1.3 dwinter 686: """ws+1"""
1.23 casties 687: ws = self.getDLParam('ws')
1.25 casties 688: try:
1.26 casties 689: return float(ws)+0.5
1.25 casties 690: except:
1.26 casties 691: return 1.5
1.3 dwinter 692:
1.18 casties 693: def getSmallerWS(self):
694: """ws-1"""
695: ws=self.getDLParam('ws')
1.25 casties 696: try:
1.26 casties 697: return max(float(ws)-0.5, 1)
1.25 casties 698: except:
1.3 dwinter 699: return 1
1.1 dwinter 700:
1.18 casties 701: def hasMode(self, mode):
702: """returns if mode is in the diglib mo parameter"""
1.44 casties 703: wid = self.getWID()
704: return (mode in self.REQUEST.SESSION['dlModes_'+wid])
1.18 casties 705:
706: def hasNextPage(self):
707: """returns if there is a next page"""
708: pn = self.getPN()
709: pt = self.getPT()
710: return (pn < pt)
711:
712: def hasPrevPage(self):
713: """returns if there is a previous page"""
714: pn = self.getPN()
715: return (pn > 1)
1.1 dwinter 716:
1.22 casties 717: def canMoveLeft(self):
718: """returns if its possible to move left"""
719: wx = float(self.getDLParam('wx') or 0)
720: return (wx > 0)
721:
722: def canMoveRight(self):
723: """returns if its possible to move right"""
724: wx = float(self.getDLParam('wx') or 0)
725: ww = float(self.getDLParam('ww') or 1)
726: return (wx + ww < 1)
727:
728: def canMoveUp(self):
729: """returns if its possible to move up"""
730: wy = float(self.getDLParam('wy') or 0)
731: return (wy > 0)
732:
733: def canMoveDown(self):
734: """returns if its possible to move down"""
735: wy = float(self.getDLParam('wy') or 0)
736: wh = float(self.getDLParam('wh') or 1)
737: return (wy + wh < 1)
738:
1.26 casties 739:
740: def dl_StaticHTML(self):
741: """set rendering to static HTML"""
742: self.checkQuery()
743: self.REQUEST.SESSION['browserType']['staticHTML'] = True
744: return self.display()
745:
746: def dl_DynamicHTML(self):
747: """set rendering to dynamic HTML"""
748: self.checkQuery()
749: self.REQUEST.SESSION['browserType']['staticHTML'] = False
750: return self.display()
1.1 dwinter 751:
1.18 casties 752: def dl_HMirror(self):
753: """mirror action"""
1.44 casties 754: modes = self.getSubSession('dlModes')
1.18 casties 755: if 'hmir' in modes:
756: modes.remove('hmir')
757: else:
758: modes.append('hmir')
1.1 dwinter 759:
1.18 casties 760: return self.display()
761:
762: def dl_VMirror(self):
763: """mirror action"""
1.44 casties 764: modes = self.getSubSession('dlModes')
1.18 casties 765: if 'vmir' in modes:
766: modes.remove('vmir')
767: else:
768: modes.append('vmir')
1.1 dwinter 769:
1.18 casties 770: return self.display()
1.1 dwinter 771:
1.22 casties 772: def dl_Zoom(self, z):
773: """general zoom action"""
774: ww1 = float(self.getDLParam('ww') or 1)
775: wh1 = float(self.getDLParam('wh') or 1)
776: wx = float(self.getDLParam('wx') or 0)
777: wy = float(self.getDLParam('wy') or 0)
778: ww2 = ww1 * z
779: wh2 = wh1 * z
780: wx += (ww1 - ww2) / 2
781: wy += (wh1 - wh2) / 2
782: ww2 = max(min(ww2, 1), 0)
783: wh2 = max(min(wh2, 1), 0)
784: wx = max(min(wx, 1), 0)
785: wy = max(min(wy, 1), 0)
1.30 casties 786: self.setDLParam('ww', cropf(ww2))
787: self.setDLParam('wh', cropf(wh2))
788: self.setDLParam('wx', cropf(wx))
789: self.setDLParam('wy', cropf(wy))
1.22 casties 790: return self.display()
791:
792: def dl_ZoomIn(self):
793: """zoom in action"""
794: z = 0.7071
795: return self.dl_Zoom(z)
796:
797: def dl_ZoomOut(self):
798: """zoom out action"""
799: z = 1.4142
800: return self.dl_Zoom(z)
801:
802: def dl_Move(self, dx, dy):
803: """general move action"""
804: ww = float(self.getDLParam('ww') or 1)
805: wh = float(self.getDLParam('wh') or 1)
806: wx = float(self.getDLParam('wx') or 0)
807: wy = float(self.getDLParam('wy') or 0)
808: wx += dx * 0.5 * ww
809: wy += dy * 0.5 * wh
810: wx = max(min(wx, 1), 0)
811: wy = max(min(wy, 1), 0)
1.30 casties 812: self.setDLParam('wx', cropf(wx))
813: self.setDLParam('wy', cropf(wy))
1.22 casties 814: return self.display()
815:
816: def dl_MoveLeft(self):
817: """move left action"""
818: return self.dl_Move(-1, 0)
819:
820: def dl_MoveRight(self):
821: """move left action"""
822: return self.dl_Move(1, 0)
823:
824: def dl_MoveUp(self):
825: """move left action"""
826: return self.dl_Move(0, -1)
827:
828: def dl_MoveDown(self):
829: """move left action"""
830: return self.dl_Move(0, 1)
831:
1.18 casties 832: def dl_WholePage(self):
833: """zoom out action"""
834: self.setDLParam('ww', 1)
835: self.setDLParam('wh', 1)
836: self.setDLParam('wx', 0)
837: self.setDLParam('wy', 0)
838: return self.display()
839:
840: def dl_PrevPage(self):
841: """next page action"""
842: pn = self.getPN() - 1
843: if pn < 1:
844: pn = 1
845: self.setDLParam('pn', pn)
846: # unmark
847: self.setDLParam('mk', None)
848: return self.display()
849:
850: def dl_NextPage(self):
851: """next page action"""
852: pn = self.getPN() + 1
853: pt = self.getPT()
854: if pn > pt:
855: pn = pt
856: self.setDLParam('pn', pn)
857: # unmark
858: self.setDLParam('mk', None)
859: return self.display()
860:
861: def dl_FirstPage(self):
862: """first page action"""
863: self.setDLParam('pn', 1)
864: # unmark
865: self.setDLParam('mk', None)
866: return self.display()
867:
868: def dl_LastPage(self):
869: """last page action"""
870: self.setDLParam('pn', self.getPT())
871: # unmark
872: self.setDLParam('mk', None)
873: return self.display()
874:
875: def dl_Unmark(self):
876: """action to remove last mark"""
877: mk = self.getDLParam('mk')
878: if mk:
879: marks = mk.split(',')
880: marks.pop()
881: mk = string.join(marks, ',')
882: self.setDLParam('mk', mk)
883: return self.display()
1.1 dwinter 884:
1.32 dwinter 885: def dl_db(self,db):
886: """set db"""
887: self.setDLParam('db',db)
888: self.display()
1.1 dwinter 889:
1.18 casties 890: def changeZogiLibForm(self):
891: """Main configuration"""
892: pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/changeZogiLibForm.zpt')).__of__(self)
893: return pt()
1.1 dwinter 894:
1.37 casties 895: def changeZogiLib(self,title,dlServerURL, version, basePath, dlTarget, dlToolbarBaseURL, RESPONSE=None):
1.18 casties 896: """change it"""
897: self.title=title
1.35 casties 898: self.dlServerURL=dlServerURL
1.21 casties 899: self.basePath = basePath
1.18 casties 900: self.layout=version
1.44 casties 901: self.dlTarget = dlTarget
1.3 dwinter 902:
1.37 casties 903: if dlToolbarBaseURL:
904: self.dlToolbarBaseURL = dlToolbarBaseURL
905: else:
906: self.dlToolbarBaseURL = dlServerURL + "/digimage.jsp?"
907:
1.18 casties 908: if RESPONSE is not None:
909: RESPONSE.redirect('manage_main')
1.8 dwinter 910:
1.35 casties 911:
912:
913: ##
1.44 casties 914: ## odds and ends
1.35 casties 915: ##
916:
917: def repairZogilib(self, obj=None):
918: """change stuff that broke on upgrading"""
919:
920: msg = ""
921:
922: if not obj:
923: obj = self.getPhysicalRoot()
924:
925: print "starting in ", obj
926:
927: entries=obj.ZopeFind(obj,obj_metatypes=['zogiLib'],search_sub=1)
928:
929: for entry in entries:
930: print " found ", entry
1.37 casties 931: #
932: # replace digilibBaseUrl by dlServerURL
1.35 casties 933: if hasattr(entry[1], 'digilibBaseUrl'):
1.37 casties 934: msg += " fixing digilibBaseUrl in "+entry[0]+"\n"
1.36 casties 935: entry[1].dlServerURL = re.sub('/servlet/Scaler\?','',entry[1].digilibBaseUrl)
1.35 casties 936: del entry[1].digilibBaseUrl
937:
1.37 casties 938: #
939: # add dlToolbarBaseURL
940: if not hasattr(entry[1], 'dlToolbarBaseURL'):
941: msg += " fixing dlToolbarBaseURL in "+entry[0]+"\n"
942: entry[1].dlToolbarBaseURL = entry[1].dlServerURL + "/digimage.jsp?"
943:
1.35 casties 944: return msg+"\n\nfixed all zogilib instances in: "+obj.title
945:
1.8 dwinter 946:
1.1 dwinter 947: def manage_addZogiLibForm(self):
948: """interface for adding zogilib"""
1.18 casties 949: pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/addZogiLibForm')).__of__(self)
1.1 dwinter 950: return pt()
951:
1.44 casties 952: def manage_addZogiLib(self,id,title,dlServerURL,version="book",basePath="",dlTarget=None,dlToolbarBaseURL=None,RESPONSE=None):
1.1 dwinter 953: """add dgilib"""
1.43 casties 954: newObj=zogiLib(id,title,dlServerURL, version, basePath, dlTarget, dlToolbarBaseURL)
1.1 dwinter 955: self.Destination()._setObject(id,newObj)
956: if RESPONSE is not None:
957: RESPONSE.redirect('manage_main')
1.29 casties 958:
959:
960: class zogiLibPageTemplate(ZopePageTemplate):
961: """pageTemplate Objekt"""
962: meta_type="zogiLib_pageTemplate"
963:
964:
965: ## def __init__(self, id, text=None, contentType=None):
966: ## self.id = str(id)
967: ## self.ZBindings_edit(self._default_bindings)
968: ## if text is None:
969: ## text = open(self._default_cont).read()
970: ## self.pt_edit(text, contentType)
971:
972: def manage_addZogiLibPageTemplateForm(self):
973: """Form for adding"""
974: pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/addZogiLibPageTemplateForm')).__of__(self)
975: return pt()
976:
977: def manage_addZogiLibPageTemplate(self, id='zogiLibMainTemplate', title=None, layout=None, text=None,
978: REQUEST=None, submit=None):
979: "Add a Page Template with optional file content."
980:
981: id = str(id)
982: self._setObject(id, zogiLibPageTemplate(id))
983: ob = getattr(self, id)
984: if not layout: layout = "book"
985: ob.pt_edit(open(os.path.join(package_home(globals()),'zpt/zogiLibMain_%s.zpt'%layout)).read(),None)
986: if title:
987: ob.pt_setTitle(title)
988: try:
989: u = self.DestinationURL()
990: except AttributeError:
991: u = REQUEST['URL1']
992:
993: u = "%s/%s" % (u, urllib.quote(id))
994: REQUEST.RESPONSE.redirect(u+'/manage_main')
995: return ''
1.35 casties 996:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>