Annotation of zogiLib/zogiLib.py, revision 1.20

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.5       dwinter   430:     def __init__(self, id,title,digilibBaseUrl, localFileBase,version="book"):
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.18      casties   437:         self.layout=version
1.1       dwinter   438: 
                    439: 
1.18      casties   440:     def getDLInfo(self):
                    441:         """get DLInfo from digilib server"""
                    442:         paramH={}
                    443:         baseUrl=re.sub("servlet/Scaler","dlInfo-xml.jsp",self.digilibBaseUrl)
                    444:         try:
                    445:             url=urllib.urlopen(baseUrl+self.REQUEST['QUERY_STRING'])
                    446:             dom=xml.dom.minidom.parse(url)
                    447:             params=dom.getElementsByTagName('parameter')
                    448:             for param in params:
                    449:                 paramH[param.getAttribute('name')]=param.getAttribute('value')
                    450:             return paramH
                    451:         except:
                    452:             return null
                    453: 
1.1       dwinter   454: 
1.18      casties   455:     def createHeadJS(self):
1.19      casties   456:         """generate all javascript tags for head"""
1.18      casties   457:         pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/zogilib_head_js')).__of__(self)
                    458:         return pt()
1.19      casties   459: 
                    460:     def createParamJS(self):
                    461:         """generate javascript for parameters only"""
                    462:         pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/zogilib_param_js')).__of__(self)
                    463:         return pt()
                    464:         
1.3       dwinter   465:                         
1.18      casties   466:     def createScalerImg(self, requestString = None):
                    467:         """generate Scaler IMG Tag"""
1.20    ! casties   468:    self.checkQuery()
        !           469:    bt = self.REQUEST.SESSION['browserType']
1.18      casties   470:         if not requestString:
                    471:             requestString = self.REQUEST.QUERY_STRING
                    472:         url = self.digilibBaseUrl+requestString
                    473:         tag = ""
                    474:         if bt.isN4:
                    475:             tag += '<ilayer id="scaler">'
                    476:         else:
                    477:             tag += '<div id="scaler">'
                    478:         tag += '<script type="text/javascript">'
                    479:         tag += "var ps = bestPicSize(getElement('scaler'));"
                    480:         tag += 'document.write(\'<img id="pic" src="%s&dw=\'+ps.width+\'&dh=\'+ps.height+\'" />\')'%url
                    481:         tag += '</script>'
                    482:         if bt.isN4:
                    483:             tag += '</ilayer>'
                    484:         else:
                    485:             tag += '</div>'
                    486:         return tag
1.1       dwinter   487: 
1.18      casties   488:     def createAuxDiv(self):
                    489:         """generate other divs"""
1.20    ! casties   490:    self.checkQuery()
        !           491:    bt = self.REQUEST.SESSION['browserType']
1.18      casties   492:         if bt.isN4:
                    493:             f = 'zpt/zogilib_divsN4.zpt'
                    494:         else:
                    495:             f = 'zpt/zogilib_divs.zpt'
                    496:         pt=PageTemplateFile(os.path.join(package_home(globals()),f)).__of__(self)
                    497:         return pt()
1.3       dwinter   498: 
1.9       dwinter   499: 
1.18      casties   500:     def option_js(self):
                    501:         """option_js"""
                    502:         pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/option_js')).__of__(self)
                    503:         return pt()
1.1       dwinter   504: 
1.18      casties   505:     def dl_lib_js(self):
                    506:         """javascript"""
                    507:         return sendFile(self, 'js/dl_lib.js', 'text/plain')
                    508: 
                    509:     def js_lib_js(self):
                    510:         """javascript"""
                    511:         return sendFile(self, 'js/js_lib.js', 'text/plain')
1.1       dwinter   512: 
1.18      casties   513:     def optionwindow(self):
                    514:         """showoptions"""
                    515:         pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/optionwindow.zpt')).__of__(self)
                    516:         return pt()
1.13      casties   517: 
                    518:     def mark1(self):
                    519:         """mark image"""
1.18      casties   520:         return sendFile(self, 'images/mark1.gif', 'image/gif')
1.13      casties   521: 
                    522:     def mark2(self):
                    523:         """mark image"""
1.18      casties   524:         return sendFile(self, 'images/mark2.gif', 'image/gif')
1.13      casties   525: 
                    526:     def mark3(self):
                    527:         """mark image"""
1.18      casties   528:         return sendFile(self, 'images/mark3.gif', 'image/gif')
1.13      casties   529: 
                    530:     def mark4(self):
                    531:         """mark image"""
1.18      casties   532:         return sendFile(self, 'images/mark4.gif', 'image/gif')
1.13      casties   533: 
                    534:     def mark5(self):
                    535:         """mark image"""
1.18      casties   536:         return sendFile(self, 'images/mark5.gif', 'image/gif')
1.13      casties   537: 
                    538:     def mark6(self):
                    539:         """mark image"""
1.18      casties   540:         return sendFile(self, 'images/mark6.gif', 'image/gif')
1.13      casties   541: 
                    542:     def mark7(self):
                    543:         """mark image"""
1.18      casties   544:         return sendFile(self, 'images/mark7.gif', 'image/gif')
1.13      casties   545: 
                    546:     def mark8(self):
                    547:         """mark image"""
1.18      casties   548:         return sendFile(self, 'images/mark8.gif', 'image/gif')
1.13      casties   549: 
                    550:     def corner1(self):
                    551:         """mark image"""
1.18      casties   552:         return sendFile(self, 'images/olinks.gif', 'image/gif')
1.13      casties   553: 
                    554:     def corner2(self):
                    555:         """mark image"""
1.18      casties   556:         return sendFile(self, 'images/orechts.gif', 'image/gif')
1.13      casties   557: 
                    558:     def corner3(self):
                    559:         """mark image"""
1.18      casties   560:         return sendFile(self, 'images/ulinks.gif', 'image/gif')
1.13      casties   561: 
                    562:     def corner4(self):
                    563:         """mark image"""
1.18      casties   564:         return sendFile(self, 'images/urechts.gif', 'image/gif')
1.13      casties   565: 
                    566: 
                    567: 
1.1       dwinter   568:             
                    569:     def index_html(self):
                    570:         """main action"""
1.18      casties   571:         tp = "zogiLibMainTemplate"
                    572:         if hasattr(self, tp):
                    573:        pt = getattr(self, tp)
                    574:         else:
                    575:             pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/zogiLibMain_%s'%self.layout)).__of__(self)
                    576:         return pt()
                    577: 
1.1       dwinter   578: 
                    579: 
                    580:     def storeQuery(self):
                    581:         """storeQuery in session"""
1.18      casties   582:         dlParams = {}
1.1       dwinter   583:         for fm in self.REQUEST.form.keys():
1.18      casties   584:             dlParams[fm] = self.REQUEST.form[fm]
                    585: 
                    586:         if 'mo' in dlParams:
                    587:             if len(dlParams['mo']) > 0:
                    588:                 modes=dlParams['mo'].split(',')
                    589:         else:
                    590:             modes=[]
                    591: 
                    592:         self.REQUEST.SESSION['query'] = dlParams
                    593:         self.REQUEST.SESSION['dlModes'] = modes
                    594:         self.REQUEST.SESSION['dlInfo'] = self.getDLInfo()
                    595:         self.REQUEST.SESSION['browserType'] = BrowserCheck(self)
1.1       dwinter   596: 
1.20    ! casties   597:     def checkQuery(self):
        !           598:    """check if the query has been stored"""
        !           599:    if not (self.REQUEST.SESSION and 'query' in self.REQUEST.SESSION):
        !           600:        print "ZOGILIB: have to store query!!"
        !           601:        storeQuery(self)
1.3       dwinter   602:         
1.18      casties   603:     def getDLParam(self,param):
                    604:         """returns parameter"""
1.3       dwinter   605:         try:
                    606:             return self.REQUEST.SESSION['query'][param]
                    607:         except:
                    608:             return None
                    609: 
1.18      casties   610:     def setDLParam(self, param, value):
                    611:         """sets parameter"""
                    612:         self.REQUEST.SESSION['query'][param] = value
                    613:         return
                    614: 
                    615:     def getAllDLParams(self):
                    616:         """parameter string for digilib"""
                    617:         dlParams = self.REQUEST.SESSION['query']
                    618:         # save modes
                    619:         modes = self.REQUEST.SESSION['dlModes']
                    620:         dlParams['mo'] = string.join(modes, ',')
                    621:         # assemble query string
                    622:         ret = ""
                    623:         for param in dlParams.keys():
                    624:             val = str(dlParams[param])
                    625:             if val != "":
                    626:                 ret += param + "=" + val + "&"
                    627:         # omit trailing "&"
                    628:         return ret.rstrip('&')
                    629: 
                    630:         
                    631:     def setDLParams(self,pn=None,ws=None,rot=None,brgt=None,cont=None):
                    632:         """setze Parameter"""
                    633:         ret=""
                    634: 
                    635:         if brgt:
                    636:             self.setDLParam('brgt', brgt)
                    637: 
                    638:         if cont:
                    639:             self.setDLParam('cont', cont)
                    640: 
                    641:         if pn:
                    642:             self.setDLParam('pn', pn)
                    643: 
                    644:         if ws:
                    645:             self.setDLParam('ws', ws)
                    646: 
                    647:         if rot:
                    648:             self.setDLParam('rot', rot)
                    649:             
                    650:         return self.display()
                    651: 
                    652: 
                    653:     def display(self):
                    654:         """(re)display page"""
                    655:         params = self.getAllDLParams()
                    656:         self.REQUEST.RESPONSE.redirect(self.REQUEST['URL1']+'?'+params)
                    657: 
                    658:     def getPT(self):
                    659:         """pagenums"""
                    660:         di = self.REQUEST.SESSION['dlInfo']
                    661:         if di:
                    662:             return int(di['pt'])
                    663:         else:
                    664:             return 1
                    665:     
                    666:     def getPN(self):
                    667:         """Pagenum"""
                    668:         pn = self.getDLParam('pn')
1.3       dwinter   669:         if pn:
1.18      casties   670:             return int(pn)
1.3       dwinter   671:         else:
                    672:             return 1
                    673: 
1.18      casties   674:     def getBiggerWS(self):
1.3       dwinter   675:         """ws+1"""
1.18      casties   676:         ws=self.getDLParam('ws')
1.3       dwinter   677:         if ws:
                    678:             return int(ws)+1
                    679:         else:
                    680:             return 2
                    681: 
                    682:         
1.18      casties   683:     def getSmallerWS(self):
                    684:         """ws-1"""
                    685:         ws=self.getDLParam('ws')
1.3       dwinter   686:         if ws:
                    687:             if int(ws)==1:
1.12      casties   688:                 return 1
1.3       dwinter   689:             else:
                    690:                 return int(ws)-1
                    691:         else:
                    692:             return 1
1.1       dwinter   693: 
1.18      casties   694:     def hasMode(self, mode):
                    695:         """returns if mode is in the diglib mo parameter"""
                    696:         return (mode in self.REQUEST.SESSION['dlModes'])
                    697: 
                    698:     def hasNextPage(self):
                    699:         """returns if there is a next page"""
                    700:         pn = self.getPN()
                    701:         pt = self.getPT()
                    702:         return (pn < pt)
                    703:    
                    704:     def hasPrevPage(self):
                    705:         """returns if there is a previous page"""
                    706:         pn = self.getPN()
                    707:         return (pn > 1)
1.1       dwinter   708: 
1.3       dwinter   709:    
1.1       dwinter   710:         
1.18      casties   711:     def dl_HMirror(self):
                    712:         """mirror action"""
                    713:         modes = self.REQUEST.SESSION['dlModes']
                    714:         if 'hmir' in modes:
                    715:             modes.remove('hmir')
                    716:         else:
                    717:             modes.append('hmir')
1.1       dwinter   718: 
1.18      casties   719:         return self.display()
                    720:        
                    721:     def dl_VMirror(self):
                    722:         """mirror action"""
                    723:         modes = self.REQUEST.SESSION['dlModes']
                    724:         if 'vmir' in modes:
                    725:             modes.remove('vmir')
                    726:         else:
                    727:             modes.append('vmir')
1.1       dwinter   728: 
1.18      casties   729:         return self.display()
1.1       dwinter   730: 
1.18      casties   731:     def dl_WholePage(self):
                    732:         """zoom out action"""
                    733:         self.setDLParam('ww', 1)
                    734:         self.setDLParam('wh', 1)
                    735:         self.setDLParam('wx', 0)
                    736:         self.setDLParam('wy', 0)
                    737:         return self.display()
                    738:         
                    739:     def dl_PrevPage(self):
                    740:         """next page action"""
                    741:         pn = self.getPN() - 1
                    742:         if pn < 1:
                    743:             pn = 1
                    744:         self.setDLParam('pn', pn)
                    745:         # unmark
                    746:         self.setDLParam('mk', None)
                    747:         return self.display()
                    748:         
                    749:     def dl_NextPage(self):
                    750:         """next page action"""
                    751:         pn = self.getPN() + 1
                    752:         pt = self.getPT()
                    753:         if pn > pt:
                    754:             pn = pt
                    755:         self.setDLParam('pn', pn)
                    756:         # unmark
                    757:         self.setDLParam('mk', None)
                    758:         return self.display()
                    759: 
                    760:     def dl_FirstPage(self):
                    761:         """first page action"""
                    762:         self.setDLParam('pn', 1)
                    763:         # unmark
                    764:         self.setDLParam('mk', None)
                    765:         return self.display()
                    766:     
                    767:     def dl_LastPage(self):
                    768:         """last page action"""
                    769:         self.setDLParam('pn', self.getPT())
                    770:         # unmark
                    771:         self.setDLParam('mk', None)
                    772:         return self.display()
                    773: 
                    774:     def dl_Unmark(self):
                    775:         """action to remove last mark"""
                    776:         mk = self.getDLParam('mk')
                    777:         if mk:
                    778:             marks = mk.split(',')
                    779:             marks.pop()
                    780:             mk = string.join(marks, ',')
                    781:             self.setDLParam('mk', mk)
                    782:         return self.display()
1.1       dwinter   783: 
                    784: 
                    785: 
1.18      casties   786:     def changeZogiLibForm(self):
                    787:         """Main configuration"""
                    788:         pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/changeZogiLibForm.zpt')).__of__(self)
                    789:         return pt()
1.1       dwinter   790:     
1.18      casties   791:     def changeZogiLib(self,title,digilibBaseUrl, localFileBase, version, RESPONSE=None):
                    792:         """change it"""
                    793:         self.title=title
                    794:         self.digilibBaseUrl=digilibBaseUrl
                    795:         self.localFileBase=localFileBase
                    796:         self.layout=version
1.3       dwinter   797: 
1.18      casties   798:         if RESPONSE is not None:
                    799:             RESPONSE.redirect('manage_main')
1.8       dwinter   800: 
                    801:           
1.1       dwinter   802: def manage_addZogiLibForm(self):
                    803:     """interface for adding zogilib"""
1.18      casties   804:     pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/addZogiLibForm')).__of__(self)
1.1       dwinter   805:     return pt()
                    806: 
1.5       dwinter   807: def manage_addZogiLib(self,id,title,digilibBaseUrl, localFileBase,version="book",RESPONSE=None):
1.1       dwinter   808:     """add dgilib"""
1.5       dwinter   809:     newObj=zogiLib(id,title,digilibBaseUrl, localFileBase, version)
1.1       dwinter   810:     self.Destination()._setObject(id,newObj)
                    811:     if RESPONSE is not None:
                    812:         RESPONSE.redirect('manage_main')

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