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