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