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