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