Annotation of zogiLib/zogiLib.py, revision 1.21

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

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>