Annotation of zogiLib/zogiLib.py, revision 1.59
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.59 ! casties 21: ZOGIVERSION = "0.10.1a ROC 3.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.59 ! casties 469: if hasattr(self, 'template'):
! 470: pt = getattr(self.template, 'main_'+tpt)
1.18 casties 471: else:
1.59 ! casties 472: pt = getattr(self, 'main_'+tpt)
1.26 casties 473:
1.18 casties 474: return pt()
475:
1.59 ! casties 476: def checkQuery(self):
! 477: """make shure that the query has been saved"""
! 478: if not self.REQUEST.has_key('dlParams'):
! 479: self.storeQuery()
! 480: if not self.REQUEST.SESSION.has_key('browserType'):
! 481: bt = browserCheck(self)
! 482: self.REQUEST.SESSION.set('browserType', bt)
1.1 dwinter 483:
1.59 ! casties 484: def storeQuery(self, more=None, withpt=False):
! 485: """parse query parameters into a hash in REQUEST"""
! 486: params = {}
1.1 dwinter 487: for fm in self.REQUEST.form.keys():
1.59 ! casties 488: params[fm] = self.REQUEST.form[fm]
1.21 casties 489: # look for more
490: if more:
491: for fm in more.split('&'):
492: try:
493: pv = fm.split('=')
1.59 ! casties 494: params[pv[0]] = pv[1]
1.21 casties 495: except:
1.26 casties 496: pass
497:
1.21 casties 498: # parse digilib mode parameter
1.59 ! casties 499: if 'mo' in params:
! 500: if len(params['mo']) > 0:
! 501: modes=params['mo'].split(',')
1.18 casties 502: else:
1.59 ! casties 503: modes = [];
! 504:
! 505: self.REQUEST.set('dlParams', params)
! 506: self.REQUEST.set('dlModes', modes)
! 507:
! 508: # trigger get pt (from dlInfo) if requested
! 509: if withpt:
! 510: pt = self.getPT()
1.44 casties 511:
1.59 ! casties 512: return params
! 513:
1.44 casties 514:
1.53 casties 515: def getDLParam(self, param, default=None):
516: """returns parameter or default"""
1.59 ! casties 517: self.checkQuery()
! 518: dlParams = self.REQUEST.get('dlParams')
1.3 dwinter 519: try:
1.59 ! casties 520: return dlParams[param]
1.3 dwinter 521: except:
1.53 casties 522: return default
1.3 dwinter 523:
1.18 casties 524: def setDLParam(self, param, value):
525: """sets parameter"""
1.59 ! casties 526: self.checkQuery()
! 527: dlParams = self.REQUEST.get('dlParams')
1.44 casties 528: dlParams[param] = value
1.18 casties 529: return
530:
531: def getAllDLParams(self):
532: """parameter string for digilib"""
1.59 ! casties 533: self.checkQuery()
! 534: dlParams = self.REQUEST.get('dlParams')
1.18 casties 535: # save modes
1.59 ! casties 536: modes = self.REQUEST.get('dlModes')
! 537: if modes:
! 538: dlParams['mo'] = string.join(modes, ',')
1.18 casties 539: # assemble query string
540: ret = ""
541: for param in dlParams.keys():
1.29 casties 542: if dlParams[param] is None: continue
1.18 casties 543: val = str(dlParams[param])
544: if val != "":
545: ret += param + "=" + val + "&"
1.28 casties 546:
1.18 casties 547: # omit trailing "&"
548: return ret.rstrip('&')
549:
550: def setDLParams(self,pn=None,ws=None,rot=None,brgt=None,cont=None):
551: """setze Parameter"""
552:
1.23 casties 553: self.setDLParam('brgt', brgt)
554: self.setDLParam('cont', cont)
555: self.setDLParam('ws', ws)
556: self.setDLParam('rot', rot)
1.18 casties 557:
558: if pn:
1.21 casties 559: # unmark
560: self.setDLParam('mk', None)
1.18 casties 561: self.setDLParam('pn', pn)
562:
563: return self.display()
564:
565:
566: def display(self):
567: """(re)display page"""
568: params = self.getAllDLParams()
1.44 casties 569:
1.21 casties 570: if self.basePath:
571: self.REQUEST.RESPONSE.redirect(self.REQUEST['URL2']+'?'+params)
572: else:
573: self.REQUEST.RESPONSE.redirect(self.REQUEST['URL1']+'?'+params)
1.18 casties 574:
1.32 dwinter 575: def getMetaFileName(self):
1.34 casties 576: url=self.dlServerURL+'/dlContext-xml.jsp?'+self.getAllDLParams()
577: return urlbase
1.26 casties 578:
1.34 casties 579: def getToolbarPageURL(self):
580: """returns a toolbar-enabled page URL"""
1.37 casties 581: url=self.dlToolbarBaseURL+self.getAllDLParams()
1.34 casties 582: return url
1.32 dwinter 583:
1.30 casties 584: def getDLTarget(self):
585: """returns dlTarget"""
586: self.checkQuery()
587: s = self.dlTarget
1.44 casties 588: if s == None:
589: s = ""
1.30 casties 590: # s = 'dl'
591: # if self.getDLParam('fn'):
592: # s += "_" + self.getDLParam('fn')
593: # if self.getDLParam('pn'):
594: # s += "_" + self.getDLParam('pn')
595: return s
596:
1.59 ! casties 597: def getPN(self):
! 598: """pagenums"""
! 599: pn = int(self.getDLParam('pn', 1))
! 600: return pn
! 601:
1.18 casties 602: def getPT(self):
603: """pagenums"""
1.59 ! casties 604: pt = self.getDLParam('pt', None)
! 605: if pt is None:
! 606: # get pt from dlInfo
! 607: if self.REQUEST.has_key('dlInfo'):
! 608: info = self.REQUEST.get('dlInfo')
! 609: else:
! 610: info = self.getDLInfo()
! 611: self.REQUEST.set('dlInfo', info)
! 612: pt = int(info.get('pt', 1))
! 613: self.setDLParam('pt', pt)
! 614: return int(pt)
1.18 casties 615:
616: def hasMode(self, mode):
617: """returns if mode is in the diglib mo parameter"""
1.59 ! casties 618: return (mode in self.REQUEST.get('dlModes'))
1.18 casties 619:
620: def hasNextPage(self):
621: """returns if there is a next page"""
622: pn = self.getPN()
623: pt = self.getPT()
624: return (pn < pt)
625:
626: def hasPrevPage(self):
627: """returns if there is a previous page"""
628: pn = self.getPN()
629: return (pn > 1)
1.1 dwinter 630:
1.22 casties 631: def canMoveLeft(self):
632: """returns if its possible to move left"""
633: wx = float(self.getDLParam('wx') or 0)
634: return (wx > 0)
635:
636: def canMoveRight(self):
637: """returns if its possible to move right"""
638: wx = float(self.getDLParam('wx') or 0)
639: ww = float(self.getDLParam('ww') or 1)
640: return (wx + ww < 1)
641:
642: def canMoveUp(self):
643: """returns if its possible to move up"""
644: wy = float(self.getDLParam('wy') or 0)
645: return (wy > 0)
646:
647: def canMoveDown(self):
648: """returns if its possible to move down"""
649: wy = float(self.getDLParam('wy') or 0)
650: wh = float(self.getDLParam('wh') or 1)
651: return (wy + wh < 1)
652:
1.26 casties 653:
654: def dl_StaticHTML(self):
655: """set rendering to static HTML"""
656: self.checkQuery()
657: self.REQUEST.SESSION['browserType']['staticHTML'] = True
658: return self.display()
659:
660: def dl_DynamicHTML(self):
661: """set rendering to dynamic HTML"""
662: self.checkQuery()
663: self.REQUEST.SESSION['browserType']['staticHTML'] = False
664: return self.display()
1.1 dwinter 665:
1.18 casties 666: def dl_HMirror(self):
667: """mirror action"""
1.44 casties 668: modes = self.getSubSession('dlModes')
1.18 casties 669: if 'hmir' in modes:
670: modes.remove('hmir')
671: else:
672: modes.append('hmir')
1.1 dwinter 673:
1.18 casties 674: return self.display()
675:
676: def dl_VMirror(self):
677: """mirror action"""
1.44 casties 678: modes = self.getSubSession('dlModes')
1.18 casties 679: if 'vmir' in modes:
680: modes.remove('vmir')
681: else:
682: modes.append('vmir')
1.1 dwinter 683:
1.18 casties 684: return self.display()
1.1 dwinter 685:
1.22 casties 686: def dl_Zoom(self, z):
687: """general zoom action"""
688: ww1 = float(self.getDLParam('ww') or 1)
689: wh1 = float(self.getDLParam('wh') or 1)
690: wx = float(self.getDLParam('wx') or 0)
691: wy = float(self.getDLParam('wy') or 0)
692: ww2 = ww1 * z
693: wh2 = wh1 * z
694: wx += (ww1 - ww2) / 2
695: wy += (wh1 - wh2) / 2
696: ww2 = max(min(ww2, 1), 0)
697: wh2 = max(min(wh2, 1), 0)
698: wx = max(min(wx, 1), 0)
699: wy = max(min(wy, 1), 0)
1.30 casties 700: self.setDLParam('ww', cropf(ww2))
701: self.setDLParam('wh', cropf(wh2))
702: self.setDLParam('wx', cropf(wx))
703: self.setDLParam('wy', cropf(wy))
1.22 casties 704: return self.display()
705:
706: def dl_ZoomIn(self):
707: """zoom in action"""
708: z = 0.7071
709: return self.dl_Zoom(z)
710:
711: def dl_ZoomOut(self):
712: """zoom out action"""
713: z = 1.4142
714: return self.dl_Zoom(z)
715:
716: def dl_Move(self, dx, dy):
717: """general move action"""
718: ww = float(self.getDLParam('ww') or 1)
719: wh = float(self.getDLParam('wh') or 1)
720: wx = float(self.getDLParam('wx') or 0)
721: wy = float(self.getDLParam('wy') or 0)
722: wx += dx * 0.5 * ww
723: wy += dy * 0.5 * wh
724: wx = max(min(wx, 1), 0)
725: wy = max(min(wy, 1), 0)
1.30 casties 726: self.setDLParam('wx', cropf(wx))
727: self.setDLParam('wy', cropf(wy))
1.22 casties 728: return self.display()
729:
730: def dl_MoveLeft(self):
731: """move left action"""
732: return self.dl_Move(-1, 0)
733:
734: def dl_MoveRight(self):
735: """move left action"""
736: return self.dl_Move(1, 0)
737:
738: def dl_MoveUp(self):
739: """move left action"""
740: return self.dl_Move(0, -1)
741:
742: def dl_MoveDown(self):
743: """move left action"""
744: return self.dl_Move(0, 1)
745:
1.18 casties 746: def dl_WholePage(self):
747: """zoom out action"""
748: self.setDLParam('ww', 1)
749: self.setDLParam('wh', 1)
750: self.setDLParam('wx', 0)
751: self.setDLParam('wy', 0)
752: return self.display()
753:
754: def dl_PrevPage(self):
755: """next page action"""
756: pn = self.getPN() - 1
757: if pn < 1:
758: pn = 1
759: self.setDLParam('pn', pn)
760: # unmark
761: self.setDLParam('mk', None)
762: return self.display()
763:
764: def dl_NextPage(self):
765: """next page action"""
766: pn = self.getPN() + 1
767: pt = self.getPT()
768: if pn > pt:
769: pn = pt
770: self.setDLParam('pn', pn)
771: # unmark
772: self.setDLParam('mk', None)
773: return self.display()
774:
775: def dl_FirstPage(self):
776: """first page action"""
777: self.setDLParam('pn', 1)
778: # unmark
779: self.setDLParam('mk', None)
780: return self.display()
781:
782: def dl_LastPage(self):
783: """last page action"""
784: self.setDLParam('pn', self.getPT())
785: # unmark
786: self.setDLParam('mk', None)
787: return self.display()
788:
789: def dl_Unmark(self):
790: """action to remove last mark"""
791: mk = self.getDLParam('mk')
792: if mk:
793: marks = mk.split(',')
794: marks.pop()
795: mk = string.join(marks, ',')
796: self.setDLParam('mk', mk)
797: return self.display()
1.1 dwinter 798:
1.32 dwinter 799: def dl_db(self,db):
800: """set db"""
801: self.setDLParam('db',db)
802: self.display()
1.1 dwinter 803:
1.18 casties 804: def changeZogiLibForm(self):
805: """Main configuration"""
806: pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/changeZogiLibForm.zpt')).__of__(self)
807: return pt()
1.1 dwinter 808:
1.37 casties 809: def changeZogiLib(self,title,dlServerURL, version, basePath, dlTarget, dlToolbarBaseURL, RESPONSE=None):
1.18 casties 810: """change it"""
811: self.title=title
1.35 casties 812: self.dlServerURL=dlServerURL
1.21 casties 813: self.basePath = basePath
1.18 casties 814: self.layout=version
1.44 casties 815: self.dlTarget = dlTarget
1.3 dwinter 816:
1.37 casties 817: if dlToolbarBaseURL:
818: self.dlToolbarBaseURL = dlToolbarBaseURL
819: else:
820: self.dlToolbarBaseURL = dlServerURL + "/digimage.jsp?"
821:
1.18 casties 822: if RESPONSE is not None:
823: RESPONSE.redirect('manage_main')
1.8 dwinter 824:
1.35 casties 825:
826:
827: ##
1.44 casties 828: ## odds and ends
1.35 casties 829: ##
830:
831: def repairZogilib(self, obj=None):
832: """change stuff that broke on upgrading"""
833:
834: msg = ""
835:
836: if not obj:
837: obj = self.getPhysicalRoot()
838:
839: print "starting in ", obj
840:
841: entries=obj.ZopeFind(obj,obj_metatypes=['zogiLib'],search_sub=1)
842:
843: for entry in entries:
844: print " found ", entry
1.37 casties 845: #
846: # replace digilibBaseUrl by dlServerURL
1.35 casties 847: if hasattr(entry[1], 'digilibBaseUrl'):
1.37 casties 848: msg += " fixing digilibBaseUrl in "+entry[0]+"\n"
1.36 casties 849: entry[1].dlServerURL = re.sub('/servlet/Scaler\?','',entry[1].digilibBaseUrl)
1.35 casties 850: del entry[1].digilibBaseUrl
851:
1.37 casties 852: #
853: # add dlToolbarBaseURL
854: if not hasattr(entry[1], 'dlToolbarBaseURL'):
855: msg += " fixing dlToolbarBaseURL in "+entry[0]+"\n"
856: entry[1].dlToolbarBaseURL = entry[1].dlServerURL + "/digimage.jsp?"
857:
1.35 casties 858: return msg+"\n\nfixed all zogilib instances in: "+obj.title
859:
1.8 dwinter 860:
1.1 dwinter 861: def manage_addZogiLibForm(self):
862: """interface for adding zogilib"""
1.18 casties 863: pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/addZogiLibForm')).__of__(self)
1.1 dwinter 864: return pt()
865:
1.44 casties 866: def manage_addZogiLib(self,id,title,dlServerURL,version="book",basePath="",dlTarget=None,dlToolbarBaseURL=None,RESPONSE=None):
1.1 dwinter 867: """add dgilib"""
1.43 casties 868: newObj=zogiLib(id,title,dlServerURL, version, basePath, dlTarget, dlToolbarBaseURL)
1.1 dwinter 869: self.Destination()._setObject(id,newObj)
870: if RESPONSE is not None:
871: RESPONSE.redirect('manage_main')
1.29 casties 872:
873:
874: class zogiLibPageTemplate(ZopePageTemplate):
875: """pageTemplate Objekt"""
876: meta_type="zogiLib_pageTemplate"
877:
878:
879: ## def __init__(self, id, text=None, contentType=None):
880: ## self.id = str(id)
881: ## self.ZBindings_edit(self._default_bindings)
882: ## if text is None:
883: ## text = open(self._default_cont).read()
884: ## self.pt_edit(text, contentType)
885:
886: def manage_addZogiLibPageTemplateForm(self):
887: """Form for adding"""
888: pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/addZogiLibPageTemplateForm')).__of__(self)
889: return pt()
890:
891: def manage_addZogiLibPageTemplate(self, id='zogiLibMainTemplate', title=None, layout=None, text=None,
892: REQUEST=None, submit=None):
893: "Add a Page Template with optional file content."
894:
895: id = str(id)
896: self._setObject(id, zogiLibPageTemplate(id))
897: ob = getattr(self, id)
898: if not layout: layout = "book"
899: ob.pt_edit(open(os.path.join(package_home(globals()),'zpt/zogiLibMain_%s.zpt'%layout)).read(),None)
900: if title:
901: ob.pt_setTitle(title)
902: try:
903: u = self.DestinationURL()
904: except AttributeError:
905: u = REQUEST['URL1']
906:
907: u = "%s/%s" % (u, urllib.quote(id))
908: REQUEST.RESPONSE.redirect(u+'/manage_main')
909: return ''
1.35 casties 910:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>