Annotation of zogiLib/zogiLib.py, revision 1.24
1.13 casties 1:
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
6: from webdav.common import rfc1123_date
1.1 dwinter 7:
8: import xml.dom.minidom
9: from OFS.Folder import Folder
10: from xml_helpers import getText
11: import os
12: import re
13: import string
14: import urllib
1.24 ! casties 15: import types
1.1 dwinter 16: from Globals import package_home
17:
18: def getString(self,key,default=''):
19: try:
20: return self.REQUEST[key]
21: except:
22: return default
23:
1.15 casties 24: def sendFile(self, filename, type):
1.17 casties 25: """sends an object or a local file (in the product) as response"""
26: paths = filename.split('/')
27: object = self
28: # look for an object called filename
29: for path in paths:
30: if hasattr(object, path):
31: object = getattr(object, path)
32: else:
33: object = None
34: break
35: if object:
1.18 casties 36: # if the object exists then send it
37: return object.index_html(self.REQUEST.REQUEST, self.REQUEST.RESPONSE)
1.17 casties 38: else:
39: # send a local file with the given content-type
40: fn = os.path.join(package_home(globals()), filename)
41: self.REQUEST.RESPONSE.setHeader("Content-Type", type)
42: self.REQUEST.RESPONSE.write(file(fn).read())
1.15 casties 43: return
44:
1.18 casties 45: class BrowserCheck:
46: """check the browsers request to find out the browser type"""
1.5 dwinter 47:
1.18 casties 48: def __init__(self, zope):
49: self.ua = zope.REQUEST.get_header("HTTP_USER_AGENT")
50: self.isIE = string.find(self.ua, 'MSIE') > -1
51: self.isN4 = (string.find(self.ua, 'Mozilla/4.') > -1) and not self.isIE
52: self.nav = self.ua[string.find(self.ua, '('):]
53: ie = string.split(self.nav, "; ")[1]
54: if string.find(ie, "MSIE") > -1:
55: self.versIE = string.split(ie, " ")[1]
56: self.isMac = string.find(self.ua, 'Macintosh') > -1
57: self.isWin = string.find(self.ua, 'Windows') > -1
58: self.isIEWin = self.isIE and self.isWin
59: self.isIEMac = self.isIE and self.isMac
1.5 dwinter 60:
61:
62: def manage_addZogiLibMainTemplateForm(self):
63: """Form for adding"""
1.18 casties 64: #FIXME:???
65: pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/AddOSAS_thumbTemplate.zpt')).__of__(self)
1.5 dwinter 66: return pt()
67:
68:
69:
70:
71: def manage_addZogiLibMainTemplate(self, id,title=None, text=None,
72: REQUEST=None, submit=None):
73: "Add a Page Template with optional file content."
1.18 casties 74: #FIXME:???
1.5 dwinter 75: id = str(id)
76: if REQUEST is None:
77: self._setObject(id, zogiLib_mainTemplate(id, text))
78: ob = getattr(self, id)
79:
80: if title:
81: ob.pt_setTitle(title)
82: return ob
83: else:
84: file = REQUEST.form.get('file')
85: headers = getattr(file, 'headers', None)
86: if headers is None or not file.filename:
87: zpt = zogiLib_mainTemplate(id)
88: else:
89: zpt = zogiLib_mainTemplate(id, file, headers.get('content_type'))
90:
91: self._setObject(id, zpt)
92: ob = getattr(self, id)
93:
94:
95: try:
96: u = self.DestinationURL()
97: except AttributeError:
98: u = REQUEST['URL1']
99:
100: if submit == " Add and Edit ":
101: u = "%s/%s" % (u, quote(id))
102: REQUEST.RESPONSE.redirect(u+'/manage_main')
103: return ''
104:
1.1 dwinter 105:
1.4 dwinter 106: class zogiImage(Image):
107: """einzelnes Image"""
108: meta_type="zogiImage"
109:
1.18 casties 110: manage_options=ZopePageTemplate.manage_options+(
111: {'label':'Main config','action':'changeZogiImageForm'},
112: )
1.4 dwinter 113:
114:
115: def __init__(self,id,title,baseUrl,queryString,content_type='',precondition=''):
116: """init"""
117: self.id=id
118: self.title=title
119: self.baseUrl=baseUrl
120: self.queryString=queryString
121: self.content_type=content_type
122: self.precondition=precondition
123:
124: def getData(self):
125: """getUrlData"""
126: return urllib.urlopen(self.baseUrl+self.queryString)
127:
128: def changeZogiImageForm(self):
129: """Main configuration"""
1.18 casties 130: pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/changeZogiImageForm.zpt')).__of__(self)
1.4 dwinter 131: return pt()
132:
133: def changeZogiImage(self,title,baseUrl, queryString,RESPONSE=None):
134: """change it"""
135: self.title=title
136: self.baseUrl=baseUrl
137: self.queryString=queryString
138:
139: if RESPONSE is not None:
140: RESPONSE.redirect('manage_main')
141:
142:
143: def index_html(self, REQUEST, RESPONSE):
144: """
145: Modified version of OFS/Image.py
1.1 dwinter 146:
1.4 dwinter 147: The default view of the contents of a File or Image.
148:
149: Returns the contents of the file or image. Also, sets the
150: Content-Type HTTP header to the objects content type.
151: """
152:
153: # HTTP If-Modified-Since header handling.
154: header=REQUEST.get_header('If-Modified-Since', None)
155: if header is not None:
156: header=header.split( ';')[0]
157: # Some proxies seem to send invalid date strings for this
158: # header. If the date string is not valid, we ignore it
159: # rather than raise an error to be generally consistent
160: # with common servers such as Apache (which can usually
161: # understand the screwy date string as a lucky side effect
162: # of the way they parse it).
163: # This happens to be what RFC2616 tells us to do in the face of an
164: # invalid date.
165: try: mod_since=long(DateTime(header).timeTime())
166: except: mod_since=None
167: if mod_since is not None:
168: if self._p_mtime:
169: last_mod = long(self._p_mtime)
170: else:
171: last_mod = long(0)
172: if last_mod > 0 and last_mod <= mod_since:
173: # Set header values since apache caching will return Content-Length
174: # of 0 in response if size is not set here
175: RESPONSE.setHeader('Last-Modified', rfc1123_date(self._p_mtime))
176: RESPONSE.setHeader('Content-Type', self.content_type)
177: RESPONSE.setHeader('Content-Length', self.size)
178: RESPONSE.setHeader('Accept-Ranges', 'bytes')
179: self.ZCacheable_set(None)
180: RESPONSE.setStatus(304)
181: return ''
182:
183: if self.precondition and hasattr(self,self.precondition):
184: # Grab whatever precondition was defined and then
185: # execute it. The precondition will raise an exception
186: # if something violates its terms.
187: c=getattr(self,self.precondition)
188: if hasattr(c,'isDocTemp') and c.isDocTemp:
189: c(REQUEST['PARENTS'][1],REQUEST)
190: else:
191: c()
192:
193: # HTTP Range header handling
194: range = REQUEST.get_header('Range', None)
195: request_range = REQUEST.get_header('Request-Range', None)
196: if request_range is not None:
197: # Netscape 2 through 4 and MSIE 3 implement a draft version
198: # Later on, we need to serve a different mime-type as well.
199: range = request_range
200: if_range = REQUEST.get_header('If-Range', None)
201: if range is not None:
202: ranges = HTTPRangeSupport.parseRange(range)
203:
204: if if_range is not None:
205: # Only send ranges if the data isn't modified, otherwise send
206: # the whole object. Support both ETags and Last-Modified dates!
207: if len(if_range) > 1 and if_range[:2] == 'ts':
208: # ETag:
209: if if_range != self.http__etag():
210: # Modified, so send a normal response. We delete
211: # the ranges, which causes us to skip to the 200
212: # response.
213: ranges = None
214: else:
215: # Date
216: date = if_range.split( ';')[0]
217: try: mod_since=long(DateTime(date).timeTime())
218: except: mod_since=None
219: if mod_since is not None:
220: if self._p_mtime:
221: last_mod = long(self._p_mtime)
222: else:
223: last_mod = long(0)
224: if last_mod > mod_since:
225: # Modified, so send a normal response. We delete
226: # the ranges, which causes us to skip to the 200
227: # response.
228: ranges = None
229:
230: if ranges:
231: # Search for satisfiable ranges.
232: satisfiable = 0
233: for start, end in ranges:
234: if start < self.size:
235: satisfiable = 1
236: break
237:
238: if not satisfiable:
239: RESPONSE.setHeader('Content-Range',
240: 'bytes */%d' % self.size)
241: RESPONSE.setHeader('Accept-Ranges', 'bytes')
242: RESPONSE.setHeader('Last-Modified',
243: rfc1123_date(self._p_mtime))
244: RESPONSE.setHeader('Content-Type', self.content_type)
245: RESPONSE.setHeader('Content-Length', self.size)
246: RESPONSE.setStatus(416)
247: return ''
248:
249: ranges = HTTPRangeSupport.expandRanges(ranges, self.size)
250:
251: if len(ranges) == 1:
252: # Easy case, set extra header and return partial set.
253: start, end = ranges[0]
254: size = end - start
255:
256: RESPONSE.setHeader('Last-Modified',
257: rfc1123_date(self._p_mtime))
258: RESPONSE.setHeader('Content-Type', self.content_type)
259: RESPONSE.setHeader('Content-Length', size)
260: RESPONSE.setHeader('Accept-Ranges', 'bytes')
261: RESPONSE.setHeader('Content-Range',
262: 'bytes %d-%d/%d' % (start, end - 1, self.size))
263: RESPONSE.setStatus(206) # Partial content
264:
265: data = urllib.urlopen(self.baseUrl+self.queryString).read()
266: if type(data) is StringType:
267: return data[start:end]
268:
269: # Linked Pdata objects. Urgh.
270: pos = 0
271: while data is not None:
272: l = len(data.data)
273: pos = pos + l
274: if pos > start:
275: # We are within the range
276: lstart = l - (pos - start)
277:
278: if lstart < 0: lstart = 0
279:
280: # find the endpoint
281: if end <= pos:
282: lend = l - (pos - end)
283:
284: # Send and end transmission
285: RESPONSE.write(data[lstart:lend])
286: break
287:
288: # Not yet at the end, transmit what we have.
289: RESPONSE.write(data[lstart:])
290:
291: data = data.next
292:
293: return ''
294:
295: else:
296: boundary = choose_boundary()
297:
298: # Calculate the content length
299: size = (8 + len(boundary) + # End marker length
300: len(ranges) * ( # Constant lenght per set
301: 49 + len(boundary) + len(self.content_type) +
302: len('%d' % self.size)))
303: for start, end in ranges:
304: # Variable length per set
305: size = (size + len('%d%d' % (start, end - 1)) +
306: end - start)
307:
308:
309: # Some clients implement an earlier draft of the spec, they
310: # will only accept x-byteranges.
311: draftprefix = (request_range is not None) and 'x-' or ''
312:
313: RESPONSE.setHeader('Content-Length', size)
314: RESPONSE.setHeader('Accept-Ranges', 'bytes')
315: RESPONSE.setHeader('Last-Modified',
316: rfc1123_date(self._p_mtime))
317: RESPONSE.setHeader('Content-Type',
318: 'multipart/%sbyteranges; boundary=%s' % (
319: draftprefix, boundary))
320: RESPONSE.setStatus(206) # Partial content
321:
322: data = urllib.urlopen(self.baseUrl+self.queryString).read()
323: # The Pdata map allows us to jump into the Pdata chain
324: # arbitrarily during out-of-order range searching.
325: pdata_map = {}
326: pdata_map[0] = data
327:
328: for start, end in ranges:
329: RESPONSE.write('\r\n--%s\r\n' % boundary)
330: RESPONSE.write('Content-Type: %s\r\n' %
331: self.content_type)
332: RESPONSE.write(
333: 'Content-Range: bytes %d-%d/%d\r\n\r\n' % (
334: start, end - 1, self.size))
335:
336: if type(data) is StringType:
337: RESPONSE.write(data[start:end])
338:
339: else:
340: # Yippee. Linked Pdata objects. The following
341: # calculations allow us to fast-forward through the
342: # Pdata chain without a lot of dereferencing if we
343: # did the work already.
344: first_size = len(pdata_map[0].data)
345: if start < first_size:
346: closest_pos = 0
347: else:
348: closest_pos = (
349: ((start - first_size) >> 16 << 16) +
350: first_size)
351: pos = min(closest_pos, max(pdata_map.keys()))
352: data = pdata_map[pos]
353:
354: while data is not None:
355: l = len(data.data)
356: pos = pos + l
357: if pos > start:
358: # We are within the range
359: lstart = l - (pos - start)
360:
361: if lstart < 0: lstart = 0
362:
363: # find the endpoint
364: if end <= pos:
365: lend = l - (pos - end)
366:
367: # Send and loop to next range
368: RESPONSE.write(data[lstart:lend])
369: break
370:
371: # Not yet at the end, transmit what we have.
372: RESPONSE.write(data[lstart:])
373:
374: data = data.next
375: # Store a reference to a Pdata chain link so we
376: # don't have to deref during this request again.
377: pdata_map[pos] = data
378:
379: # Do not keep the link references around.
380: del pdata_map
381:
382: RESPONSE.write('\r\n--%s--\r\n' % boundary)
383: return ''
384:
385: RESPONSE.setHeader('Last-Modified', rfc1123_date(self._p_mtime))
386: RESPONSE.setHeader('Content-Type', self.content_type)
387: RESPONSE.setHeader('Content-Length', self.size)
388: RESPONSE.setHeader('Accept-Ranges', 'bytes')
389:
390: # Don't cache the data itself, but provide an opportunity
391: # for a cache manager to set response headers.
392: self.ZCacheable_set(None)
393:
394: data=urllib.urlopen(self.baseUrl+self.queryString).read()
395:
396: if type(data) is type(''):
397: RESPONSE.setBase(None)
398: return data
399:
400: while data is not None:
401: RESPONSE.write(data.data)
402: data=data.next
403:
404: return ''
405:
406:
407: def manage_addZogiImageForm(self):
408: """Form for adding"""
1.18 casties 409: pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/addZogiImage.zpt')).__of__(self)
1.4 dwinter 410: return pt()
411:
412:
413: def manage_addZogiImage(self,id,title,baseUrl, queryString,RESPONSE=None):
414: """add dgilib"""
415: newObj=zogiImage(id,title,baseUrl, queryString)
416: self.Destination()._setObject(id,newObj)
417: if RESPONSE is not None:
418: RESPONSE.redirect('manage_main')
419:
420:
421:
1.1 dwinter 422: class zogiLib(Folder):
423: """StandardElement"""
424:
425: meta_type="zogiLib"
426:
1.18 casties 427: manage_options = Folder.manage_options+(
428: {'label':'Main Config','action':'changeZogiLibForm'},
429: )
1.1 dwinter 430:
1.21 casties 431: def __init__(self, id, title, digilibBaseUrl, localFileBase, version="book", basePath=""):
1.1 dwinter 432: """init"""
433:
434: self.id=id
435: self.title=title
1.2 dwinter 436: self.digilibBaseUrl=digilibBaseUrl
1.1 dwinter 437: self.localFileBase=localFileBase
1.21 casties 438: self.basePath=basePath
1.18 casties 439: self.layout=version
1.1 dwinter 440:
441:
1.18 casties 442: def getDLInfo(self):
443: """get DLInfo from digilib server"""
444: paramH={}
445: baseUrl=re.sub("servlet/Scaler","dlInfo-xml.jsp",self.digilibBaseUrl)
446: try:
447: url=urllib.urlopen(baseUrl+self.REQUEST['QUERY_STRING'])
448: dom=xml.dom.minidom.parse(url)
449: params=dom.getElementsByTagName('parameter')
450: for param in params:
451: paramH[param.getAttribute('name')]=param.getAttribute('value')
452: return paramH
453: except:
454: return null
455:
1.1 dwinter 456:
1.18 casties 457: def createHeadJS(self):
1.19 casties 458: """generate all javascript tags for head"""
1.18 casties 459: pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/zogilib_head_js')).__of__(self)
460: return pt()
1.19 casties 461:
462: def createParamJS(self):
463: """generate javascript for parameters only"""
464: pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/zogilib_param_js')).__of__(self)
465: return pt()
466:
1.3 dwinter 467:
1.21 casties 468: def createScalerImg(self, requestString = None, bottom = 0, side = 0):
1.18 casties 469: """generate Scaler IMG Tag"""
1.20 casties 470: self.checkQuery()
471: bt = self.REQUEST.SESSION['browserType']
1.24 ! casties 472: # override with parameters from session
! 473: if self.REQUEST.SESSION.has_key('scalerDiv'):
! 474: (requestString, bottom, side) = self.REQUEST.SESSION['scalerDiv']
! 475: # if not explicitly defined take normal request
1.18 casties 476: if not requestString:
1.21 casties 477: requestString = self.getAllDLParams()
1.18 casties 478: url = self.digilibBaseUrl+requestString
1.24 ! casties 479: # construct bottom and side insets
! 480: b_par = ""
! 481: s_par = ""
! 482: if (bottom != 0) or (side != 0):
! 483: b_par = "-" + str(int(bottom))
! 484: s_par = "-" + str(int(side))
1.18 casties 485: tag = ""
486: if bt.isN4:
1.24 ! casties 487: # N4 needs layers
1.18 casties 488: tag += '<ilayer id="scaler">'
489: else:
490: tag += '<div id="scaler">'
491: tag += '<script type="text/javascript">'
492: tag += "var ps = bestPicSize(getElement('scaler'));"
1.24 ! casties 493: # write img tag with javascript
1.21 casties 494: tag += 'document.write(\'<img id="pic" src="%s&dw=\'+(ps.width%s)+\'&dh=\'+(ps.height%s)+\'" />\')'%(url, s_par, b_par)
1.18 casties 495: tag += '</script>'
496: if bt.isN4:
497: tag += '</ilayer>'
498: else:
499: tag += '</div>'
500: return tag
1.1 dwinter 501:
1.24 ! casties 502: def createScalerDiv(self, requestString = None, bottom = 0, side = 0):
1.23 casties 503: """generate scaler img and table with navigation arrows"""
504: self.checkQuery()
1.24 ! casties 505: if requestString != None or bottom != 0 or side != 0:
! 506: self.REQUEST.SESSION['scalerDiv'] = (requestString, bottom, side)
! 507: else:
! 508: if self.REQUEST.SESSION.has_key('scalerDiv'):
! 509: del self.REQUEST.SESSION['scalerDiv']
1.23 casties 510: pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt/zogilib_img_div')).__of__(self)
511: return pt()
512:
1.18 casties 513: def createAuxDiv(self):
514: """generate other divs"""
1.20 casties 515: self.checkQuery()
516: bt = self.REQUEST.SESSION['browserType']
1.18 casties 517: if bt.isN4:
518: f = 'zpt/zogilib_divsN4.zpt'
519: else:
520: f = 'zpt/zogilib_divs.zpt'
521: pt=PageTemplateFile(os.path.join(package_home(globals()),f)).__of__(self)
522: return pt()
1.3 dwinter 523:
1.9 dwinter 524:
1.18 casties 525: def option_js(self):
526: """option_js"""
527: pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/option_js')).__of__(self)
528: return pt()
1.1 dwinter 529:
1.18 casties 530: def dl_lib_js(self):
531: """javascript"""
532: return sendFile(self, 'js/dl_lib.js', 'text/plain')
533:
534: def js_lib_js(self):
535: """javascript"""
536: return sendFile(self, 'js/js_lib.js', 'text/plain')
1.1 dwinter 537:
1.18 casties 538: def optionwindow(self):
539: """showoptions"""
540: pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/optionwindow.zpt')).__of__(self)
541: return pt()
1.13 casties 542:
543: def mark1(self):
544: """mark image"""
1.18 casties 545: return sendFile(self, 'images/mark1.gif', 'image/gif')
1.13 casties 546:
547: def mark2(self):
548: """mark image"""
1.18 casties 549: return sendFile(self, 'images/mark2.gif', 'image/gif')
1.13 casties 550:
551: def mark3(self):
552: """mark image"""
1.18 casties 553: return sendFile(self, 'images/mark3.gif', 'image/gif')
1.13 casties 554:
555: def mark4(self):
556: """mark image"""
1.18 casties 557: return sendFile(self, 'images/mark4.gif', 'image/gif')
1.13 casties 558:
559: def mark5(self):
560: """mark image"""
1.18 casties 561: return sendFile(self, 'images/mark5.gif', 'image/gif')
1.13 casties 562:
563: def mark6(self):
564: """mark image"""
1.18 casties 565: return sendFile(self, 'images/mark6.gif', 'image/gif')
1.13 casties 566:
567: def mark7(self):
568: """mark image"""
1.18 casties 569: return sendFile(self, 'images/mark7.gif', 'image/gif')
1.13 casties 570:
571: def mark8(self):
572: """mark image"""
1.18 casties 573: return sendFile(self, 'images/mark8.gif', 'image/gif')
1.13 casties 574:
575: def corner1(self):
576: """mark image"""
1.18 casties 577: return sendFile(self, 'images/olinks.gif', 'image/gif')
1.13 casties 578:
579: def corner2(self):
580: """mark image"""
1.18 casties 581: return sendFile(self, 'images/orechts.gif', 'image/gif')
1.13 casties 582:
583: def corner3(self):
584: """mark image"""
1.18 casties 585: return sendFile(self, 'images/ulinks.gif', 'image/gif')
1.13 casties 586:
587: def corner4(self):
588: """mark image"""
1.18 casties 589: return sendFile(self, 'images/urechts.gif', 'image/gif')
1.13 casties 590:
1.22 casties 591: def up_img(self):
592: """mark image"""
593: return sendFile(self, 'images/up.gif', 'image/gif')
594:
595: def down_img(self):
596: """mark image"""
597: return sendFile(self, 'images/down.gif', 'image/gif')
598:
599: def left_img(self):
600: """mark image"""
601: return sendFile(self, 'images/left.gif', 'image/gif')
602:
603: def right_img(self):
604: """mark image"""
605: return sendFile(self, 'images/right.gif', 'image/gif')
1.13 casties 606:
607:
1.1 dwinter 608:
609: def index_html(self):
610: """main action"""
1.18 casties 611: tp = "zogiLibMainTemplate"
612: if hasattr(self, tp):
613: pt = getattr(self, tp)
614: else:
615: pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/zogiLibMain_%s'%self.layout)).__of__(self)
616: return pt()
617:
1.1 dwinter 618:
619:
1.21 casties 620: def storeQuery(self, more = None):
1.1 dwinter 621: """storeQuery in session"""
1.18 casties 622: dlParams = {}
1.1 dwinter 623: for fm in self.REQUEST.form.keys():
1.18 casties 624: dlParams[fm] = self.REQUEST.form[fm]
1.21 casties 625: # look for more
626: if more:
627: for fm in more.split('&'):
628: try:
629: pv = fm.split('=')
630: dlParams[pv[0]] = pv[1]
631: except:
632: print "ouch!"
633: # parse digilib mode parameter
1.18 casties 634: if 'mo' in dlParams:
635: if len(dlParams['mo']) > 0:
636: modes=dlParams['mo'].split(',')
637: else:
638: modes=[]
639:
640: self.REQUEST.SESSION['query'] = dlParams
641: self.REQUEST.SESSION['dlModes'] = modes
642: self.REQUEST.SESSION['dlInfo'] = self.getDLInfo()
643: self.REQUEST.SESSION['browserType'] = BrowserCheck(self)
1.1 dwinter 644:
1.20 casties 645: def checkQuery(self):
646: """check if the query has been stored"""
1.21 casties 647: if not (self.REQUEST.SESSION):
1.20 casties 648: print "ZOGILIB: have to store query!!"
1.24 ! casties 649: self.storeQuery
! 650: return
1.23 casties 651:
1.24 ! casties 652: def zogilibPath(self, otherbase=None):
1.23 casties 653: """returns an URL to the zogiLib instance"""
654: url = self.REQUEST['URL1']
1.24 ! casties 655: # should end with "/"
! 656: if len(url) > 0 and url[-1] != '/':
! 657: url += '/'
! 658: if type(otherbase) is str:
! 659: url += otherbase
! 660: else:
! 661: url += self.basePath
1.23 casties 662: # should end with "/"
663: if len(url) > 0 and url[-1] != '/':
664: url += '/'
665: return url
1.3 dwinter 666:
1.22 casties 667: def getDLParam(self, param):
1.18 casties 668: """returns parameter"""
1.3 dwinter 669: try:
670: return self.REQUEST.SESSION['query'][param]
671: except:
1.24 ! casties 672: return
1.3 dwinter 673:
1.18 casties 674: def setDLParam(self, param, value):
675: """sets parameter"""
676: self.REQUEST.SESSION['query'][param] = value
677: return
678:
679: def getAllDLParams(self):
680: """parameter string for digilib"""
681: dlParams = self.REQUEST.SESSION['query']
682: # save modes
683: modes = self.REQUEST.SESSION['dlModes']
684: dlParams['mo'] = string.join(modes, ',')
685: # assemble query string
686: ret = ""
687: for param in dlParams.keys():
688: val = str(dlParams[param])
689: if val != "":
690: ret += param + "=" + val + "&"
691: # omit trailing "&"
692: return ret.rstrip('&')
693:
694:
695: def setDLParams(self,pn=None,ws=None,rot=None,brgt=None,cont=None):
696: """setze Parameter"""
697:
1.23 casties 698: self.setDLParam('brgt', brgt)
699: self.setDLParam('cont', cont)
700: self.setDLParam('ws', ws)
701: self.setDLParam('rot', rot)
1.18 casties 702:
703: if pn:
1.21 casties 704: # unmark
705: self.setDLParam('mk', None)
1.18 casties 706: self.setDLParam('pn', pn)
707:
708: return self.display()
709:
710:
711: def display(self):
712: """(re)display page"""
713: params = self.getAllDLParams()
1.21 casties 714: if self.basePath:
715: self.REQUEST.RESPONSE.redirect(self.REQUEST['URL2']+'?'+params)
716: else:
717: self.REQUEST.RESPONSE.redirect(self.REQUEST['URL1']+'?'+params)
1.18 casties 718:
719: def getPT(self):
720: """pagenums"""
721: di = self.REQUEST.SESSION['dlInfo']
722: if di:
723: return int(di['pt'])
724: else:
725: return 1
726:
727: def getPN(self):
728: """Pagenum"""
729: pn = self.getDLParam('pn')
1.3 dwinter 730: if pn:
1.18 casties 731: return int(pn)
1.3 dwinter 732: else:
733: return 1
734:
1.18 casties 735: def getBiggerWS(self):
1.3 dwinter 736: """ws+1"""
1.23 casties 737: ws = self.getDLParam('ws')
1.3 dwinter 738: if ws:
739: return int(ws)+1
740: else:
741: return 2
742:
1.18 casties 743: def getSmallerWS(self):
744: """ws-1"""
745: ws=self.getDLParam('ws')
1.3 dwinter 746: if ws:
1.23 casties 747: return max(int(ws)-1, 1)
1.3 dwinter 748: else:
749: return 1
1.1 dwinter 750:
1.18 casties 751: def hasMode(self, mode):
752: """returns if mode is in the diglib mo parameter"""
753: return (mode in self.REQUEST.SESSION['dlModes'])
754:
755: def hasNextPage(self):
756: """returns if there is a next page"""
757: pn = self.getPN()
758: pt = self.getPT()
759: return (pn < pt)
760:
761: def hasPrevPage(self):
762: """returns if there is a previous page"""
763: pn = self.getPN()
764: return (pn > 1)
1.1 dwinter 765:
1.22 casties 766: def canMoveLeft(self):
767: """returns if its possible to move left"""
768: wx = float(self.getDLParam('wx') or 0)
769: return (wx > 0)
770:
771: def canMoveRight(self):
772: """returns if its possible to move right"""
773: wx = float(self.getDLParam('wx') or 0)
774: ww = float(self.getDLParam('ww') or 1)
775: return (wx + ww < 1)
776:
777: def canMoveUp(self):
778: """returns if its possible to move up"""
779: wy = float(self.getDLParam('wy') or 0)
780: return (wy > 0)
781:
782: def canMoveDown(self):
783: """returns if its possible to move down"""
784: wy = float(self.getDLParam('wy') or 0)
785: wh = float(self.getDLParam('wh') or 1)
786: return (wy + wh < 1)
787:
1.1 dwinter 788:
1.18 casties 789: def dl_HMirror(self):
790: """mirror action"""
791: modes = self.REQUEST.SESSION['dlModes']
792: if 'hmir' in modes:
793: modes.remove('hmir')
794: else:
795: modes.append('hmir')
1.1 dwinter 796:
1.18 casties 797: return self.display()
798:
799: def dl_VMirror(self):
800: """mirror action"""
801: modes = self.REQUEST.SESSION['dlModes']
802: if 'vmir' in modes:
803: modes.remove('vmir')
804: else:
805: modes.append('vmir')
1.1 dwinter 806:
1.18 casties 807: return self.display()
1.1 dwinter 808:
1.22 casties 809: def dl_Zoom(self, z):
810: """general zoom action"""
811: ww1 = float(self.getDLParam('ww') or 1)
812: wh1 = float(self.getDLParam('wh') or 1)
813: wx = float(self.getDLParam('wx') or 0)
814: wy = float(self.getDLParam('wy') or 0)
815: ww2 = ww1 * z
816: wh2 = wh1 * z
817: wx += (ww1 - ww2) / 2
818: wy += (wh1 - wh2) / 2
819: ww2 = max(min(ww2, 1), 0)
820: wh2 = max(min(wh2, 1), 0)
821: wx = max(min(wx, 1), 0)
822: wy = max(min(wy, 1), 0)
823: self.setDLParam('ww', ww2)
824: self.setDLParam('wh', wh2)
825: self.setDLParam('wx', wx)
826: self.setDLParam('wy', wy)
827: return self.display()
828:
829: def dl_ZoomIn(self):
830: """zoom in action"""
831: z = 0.7071
832: return self.dl_Zoom(z)
833:
834: def dl_ZoomOut(self):
835: """zoom out action"""
836: z = 1.4142
837: return self.dl_Zoom(z)
838:
839: def dl_Move(self, dx, dy):
840: """general move action"""
841: ww = float(self.getDLParam('ww') or 1)
842: wh = float(self.getDLParam('wh') or 1)
843: wx = float(self.getDLParam('wx') or 0)
844: wy = float(self.getDLParam('wy') or 0)
845: wx += dx * 0.5 * ww
846: wy += dy * 0.5 * wh
847: wx = max(min(wx, 1), 0)
848: wy = max(min(wy, 1), 0)
849: self.setDLParam('wx', wx)
850: self.setDLParam('wy', wy)
851: return self.display()
852:
853: def dl_MoveLeft(self):
854: """move left action"""
855: return self.dl_Move(-1, 0)
856:
857: def dl_MoveRight(self):
858: """move left action"""
859: return self.dl_Move(1, 0)
860:
861: def dl_MoveUp(self):
862: """move left action"""
863: return self.dl_Move(0, -1)
864:
865: def dl_MoveDown(self):
866: """move left action"""
867: return self.dl_Move(0, 1)
868:
1.18 casties 869: def dl_WholePage(self):
870: """zoom out action"""
871: self.setDLParam('ww', 1)
872: self.setDLParam('wh', 1)
873: self.setDLParam('wx', 0)
874: self.setDLParam('wy', 0)
875: return self.display()
876:
877: def dl_PrevPage(self):
878: """next page action"""
879: pn = self.getPN() - 1
880: if pn < 1:
881: pn = 1
882: self.setDLParam('pn', pn)
883: # unmark
884: self.setDLParam('mk', None)
885: return self.display()
886:
887: def dl_NextPage(self):
888: """next page action"""
889: pn = self.getPN() + 1
890: pt = self.getPT()
891: if pn > pt:
892: pn = pt
893: self.setDLParam('pn', pn)
894: # unmark
895: self.setDLParam('mk', None)
896: return self.display()
897:
898: def dl_FirstPage(self):
899: """first page action"""
900: self.setDLParam('pn', 1)
901: # unmark
902: self.setDLParam('mk', None)
903: return self.display()
904:
905: def dl_LastPage(self):
906: """last page action"""
907: self.setDLParam('pn', self.getPT())
908: # unmark
909: self.setDLParam('mk', None)
910: return self.display()
911:
912: def dl_Unmark(self):
913: """action to remove last mark"""
914: mk = self.getDLParam('mk')
915: if mk:
916: marks = mk.split(',')
917: marks.pop()
918: mk = string.join(marks, ',')
919: self.setDLParam('mk', mk)
920: return self.display()
1.1 dwinter 921:
922:
923:
1.18 casties 924: def changeZogiLibForm(self):
925: """Main configuration"""
926: pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/changeZogiLibForm.zpt')).__of__(self)
927: return pt()
1.1 dwinter 928:
1.21 casties 929: def changeZogiLib(self,title,digilibBaseUrl, localFileBase, version, basePath, RESPONSE=None):
1.18 casties 930: """change it"""
931: self.title=title
932: self.digilibBaseUrl=digilibBaseUrl
933: self.localFileBase=localFileBase
1.21 casties 934: self.basePath = basePath
1.18 casties 935: self.layout=version
1.3 dwinter 936:
1.18 casties 937: if RESPONSE is not None:
938: RESPONSE.redirect('manage_main')
1.8 dwinter 939:
940:
1.1 dwinter 941: def manage_addZogiLibForm(self):
942: """interface for adding zogilib"""
1.18 casties 943: pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/addZogiLibForm')).__of__(self)
1.1 dwinter 944: return pt()
945:
1.21 casties 946: def manage_addZogiLib(self,id,title,digilibBaseUrl, localFileBase,version="book",basePath="",RESPONSE=None):
1.1 dwinter 947: """add dgilib"""
1.21 casties 948: newObj=zogiLib(id,title,digilibBaseUrl, localFileBase, version, basePath)
1.1 dwinter 949: self.Destination()._setObject(id,newObj)
950: if RESPONSE is not None:
951: RESPONSE.redirect('manage_main')
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>