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