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