Annotation of zogiLib/zogiLib.py, revision 1.44

1.1       dwinter     1: from Products.PageTemplates.PageTemplateFile import PageTemplateFile
                      2: from Products.PageTemplates.PageTemplate import PageTemplate
                      3: from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate
1.4       dwinter     4: from OFS.Image import Image
                      5: from webdav.common import rfc1123_date
1.1       dwinter     6: 
                      7: import xml.dom.minidom
                      8: from OFS.Folder import Folder
1.32      dwinter     9: from xml_helpers import getUniqueElementText,getText
1.1       dwinter    10: import os
                     11: import re
                     12: import string
                     13: import urllib
1.24      casties    14: import types
1.44    ! casties    15: import random
1.1       dwinter    16: from Globals import package_home
                     17: 
1.44    ! casties    18: ZOGIVERSION = "0.9.9 ROC:28.8.2004"
1.30      casties    19: 
                     20: def cropf(f):
                     21:     """returns a float with reduced precision"""
                     22:     return float(int(f * 10000)/10000.0)
                     23: 
1.28      casties    24: 
1.15      casties    25: def sendFile(self, filename, type):
1.44    ! casties    26:     """sends an object or a local file (from the product) as response"""
1.17      casties    27:     paths = filename.split('/')
                     28:     object = self
                     29:     # look for an object called filename
                     30:     for path in paths:
                     31:         if hasattr(object, path):
                     32:        object = getattr(object, path)
                     33:    else:
                     34:        object = None
                     35:        break
                     36:     if object:
1.18      casties    37:    # if the object exists then send it
                     38:    return object.index_html(self.REQUEST.REQUEST, self.REQUEST.RESPONSE)
1.17      casties    39:     else:
                     40:    # send a local file with the given content-type
                     41:    fn = os.path.join(package_home(globals()), filename)
                     42:    self.REQUEST.RESPONSE.setHeader("Content-Type", type)
                     43:    self.REQUEST.RESPONSE.write(file(fn).read())
1.15      casties    44:     return
                     45: 
1.26      casties    46: def browserCheck(self):
1.18      casties    47:     """check the browsers request to find out the browser type"""
1.26      casties    48:     bt = {}
                     49:     ua = self.REQUEST.get_header("HTTP_USER_AGENT")
                     50:     bt['ua'] = ua
                     51:     bt['isIE'] = string.find(ua, 'MSIE') > -1
                     52:     bt['isN4'] = (string.find(ua, 'Mozilla/4.') > -1) and not bt['isIE']
                     53:     nav = ua[string.find(ua, '('):]
                     54:     ie = string.split(nav, "; ")[1]
                     55:     if string.find(ie, "MSIE") > -1:
                     56:         bt['versIE'] = string.split(ie, " ")[1]
                     57:     bt['isMac'] = string.find(ua, 'Macintosh') > -1
                     58:     bt['isWin'] = string.find(ua, 'Windows') > -1
                     59:     bt['isIEWin'] = bt['isIE'] and bt['isWin']
                     60:     bt['isIEMac'] = bt['isIE'] and bt['isMac']
                     61:     bt['staticHTML'] = False
1.5       dwinter    62: 
1.26      casties    63:     return bt
1.5       dwinter    64: 
1.1       dwinter    65:     
1.4       dwinter    66: class zogiImage(Image):
                     67:     """einzelnes Image"""
                     68:     meta_type="zogiImage"
                     69: 
1.18      casties    70:     manage_options=ZopePageTemplate.manage_options+(
                     71:         {'label':'Main config','action':'changeZogiImageForm'},
                     72:        )
1.4       dwinter    73:     
                     74:     
                     75:     def __init__(self,id,title,baseUrl,queryString,content_type='',precondition=''):
                     76:         """init"""
                     77:         self.id=id
                     78:         self.title=title
                     79:         self.baseUrl=baseUrl
                     80:         self.queryString=queryString
                     81:         self.content_type=content_type
                     82:         self.precondition=precondition
                     83: 
                     84:     def getData(self):
                     85:         """getUrlData"""
                     86:         return urllib.urlopen(self.baseUrl+self.queryString)
                     87: 
                     88:     def changeZogiImageForm(self):
                     89:         """Main configuration"""
1.18      casties    90:         pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/changeZogiImageForm.zpt')).__of__(self)
1.4       dwinter    91:         return pt()
                     92:     
                     93:     def changeZogiImage(self,title,baseUrl, queryString,RESPONSE=None):
                     94:         """change it"""
                     95:         self.title=title
                     96:         self.baseUrl=baseUrl
                     97:         self.queryString=queryString
                     98: 
                     99:         if RESPONSE is not None:
                    100:             RESPONSE.redirect('manage_main')
                    101: 
                    102:         
                    103:     def index_html(self, REQUEST, RESPONSE):
                    104:         """
                    105:         Modified version of OFS/Image.py
1.1       dwinter   106:         
1.4       dwinter   107:         The default view of the contents of a File or Image.
                    108: 
                    109:         Returns the contents of the file or image.  Also, sets the
                    110:         Content-Type HTTP header to the objects content type.
                    111:         """
                    112: 
                    113:         # HTTP If-Modified-Since header handling.
                    114:         header=REQUEST.get_header('If-Modified-Since', None)
                    115:         if header is not None:
                    116:             header=header.split( ';')[0]
                    117:             # Some proxies seem to send invalid date strings for this
                    118:             # header. If the date string is not valid, we ignore it
                    119:             # rather than raise an error to be generally consistent
                    120:             # with common servers such as Apache (which can usually
                    121:             # understand the screwy date string as a lucky side effect
                    122:             # of the way they parse it).
                    123:             # This happens to be what RFC2616 tells us to do in the face of an
                    124:             # invalid date.
                    125:             try:    mod_since=long(DateTime(header).timeTime())
                    126:             except: mod_since=None
                    127:             if mod_since is not None:
                    128:                 if self._p_mtime:
                    129:                     last_mod = long(self._p_mtime)
                    130:                 else:
                    131:                     last_mod = long(0)
                    132:                 if last_mod > 0 and last_mod <= mod_since:
                    133:                     # Set header values since apache caching will return Content-Length
                    134:                     # of 0 in response if size is not set here
                    135:                     RESPONSE.setHeader('Last-Modified', rfc1123_date(self._p_mtime))
                    136:                     RESPONSE.setHeader('Content-Type', self.content_type)
                    137:                     RESPONSE.setHeader('Content-Length', self.size)
                    138:                     RESPONSE.setHeader('Accept-Ranges', 'bytes')
                    139:                     self.ZCacheable_set(None)
                    140:                     RESPONSE.setStatus(304)
                    141:                     return ''
                    142: 
                    143:         if self.precondition and hasattr(self,self.precondition):
                    144:             # Grab whatever precondition was defined and then
                    145:             # execute it.  The precondition will raise an exception
                    146:             # if something violates its terms.
                    147:             c=getattr(self,self.precondition)
                    148:             if hasattr(c,'isDocTemp') and c.isDocTemp:
                    149:                 c(REQUEST['PARENTS'][1],REQUEST)
                    150:             else:
                    151:                 c()
                    152: 
                    153:         # HTTP Range header handling
                    154:         range = REQUEST.get_header('Range', None)
                    155:         request_range = REQUEST.get_header('Request-Range', None)
                    156:         if request_range is not None:
                    157:             # Netscape 2 through 4 and MSIE 3 implement a draft version
                    158:             # Later on, we need to serve a different mime-type as well.
                    159:             range = request_range
                    160:         if_range = REQUEST.get_header('If-Range', None)
                    161:         if range is not None:
                    162:             ranges = HTTPRangeSupport.parseRange(range)
                    163: 
                    164:             if if_range is not None:
                    165:                 # Only send ranges if the data isn't modified, otherwise send
                    166:                 # the whole object. Support both ETags and Last-Modified dates!
                    167:                 if len(if_range) > 1 and if_range[:2] == 'ts':
                    168:                     # ETag:
                    169:                     if if_range != self.http__etag():
                    170:                         # Modified, so send a normal response. We delete
                    171:                         # the ranges, which causes us to skip to the 200
                    172:                         # response.
                    173:                         ranges = None
                    174:                 else:
                    175:                     # Date
                    176:                     date = if_range.split( ';')[0]
                    177:                     try: mod_since=long(DateTime(date).timeTime())
                    178:                     except: mod_since=None
                    179:                     if mod_since is not None:
                    180:                         if self._p_mtime:
                    181:                             last_mod = long(self._p_mtime)
                    182:                         else:
                    183:                             last_mod = long(0)
                    184:                         if last_mod > mod_since:
                    185:                             # Modified, so send a normal response. We delete
                    186:                             # the ranges, which causes us to skip to the 200
                    187:                             # response.
                    188:                             ranges = None
                    189: 
                    190:             if ranges:
                    191:                 # Search for satisfiable ranges.
                    192:                 satisfiable = 0
                    193:                 for start, end in ranges:
                    194:                     if start < self.size:
                    195:                         satisfiable = 1
                    196:                         break
                    197: 
                    198:                 if not satisfiable:
                    199:                     RESPONSE.setHeader('Content-Range',
                    200:                         'bytes */%d' % self.size)
                    201:                     RESPONSE.setHeader('Accept-Ranges', 'bytes')
                    202:                     RESPONSE.setHeader('Last-Modified',
                    203:                         rfc1123_date(self._p_mtime))
                    204:                     RESPONSE.setHeader('Content-Type', self.content_type)
                    205:                     RESPONSE.setHeader('Content-Length', self.size)
                    206:                     RESPONSE.setStatus(416)
                    207:                     return ''
                    208: 
                    209:                 ranges = HTTPRangeSupport.expandRanges(ranges, self.size)
                    210:                                 
                    211:                 if len(ranges) == 1:
                    212:                     # Easy case, set extra header and return partial set.
                    213:                     start, end = ranges[0]
                    214:                     size = end - start
                    215: 
                    216:                     RESPONSE.setHeader('Last-Modified',
                    217:                         rfc1123_date(self._p_mtime))
                    218:                     RESPONSE.setHeader('Content-Type', self.content_type)
                    219:                     RESPONSE.setHeader('Content-Length', size)
                    220:                     RESPONSE.setHeader('Accept-Ranges', 'bytes')
                    221:                     RESPONSE.setHeader('Content-Range',
                    222:                         'bytes %d-%d/%d' % (start, end - 1, self.size))
                    223:                     RESPONSE.setStatus(206) # Partial content
                    224: 
                    225:                     data = urllib.urlopen(self.baseUrl+self.queryString).read()
                    226:                     if type(data) is StringType:
                    227:                         return data[start:end]
                    228: 
                    229:                     # Linked Pdata objects. Urgh.
                    230:                     pos = 0
                    231:                     while data is not None:
                    232:                         l = len(data.data)
                    233:                         pos = pos + l
                    234:                         if pos > start:
                    235:                             # We are within the range
                    236:                             lstart = l - (pos - start)
                    237: 
                    238:                             if lstart < 0: lstart = 0
                    239: 
                    240:                             # find the endpoint
                    241:                             if end <= pos:
                    242:                                 lend = l - (pos - end)
                    243: 
                    244:                                 # Send and end transmission
                    245:                                 RESPONSE.write(data[lstart:lend])
                    246:                                 break
                    247: 
                    248:                             # Not yet at the end, transmit what we have.
                    249:                             RESPONSE.write(data[lstart:])
                    250: 
                    251:                         data = data.next
                    252: 
                    253:                     return ''
                    254: 
                    255:                 else:
                    256:                     boundary = choose_boundary()
                    257: 
                    258:                     # Calculate the content length
                    259:                     size = (8 + len(boundary) + # End marker length
                    260:                         len(ranges) * (         # Constant lenght per set
                    261:                             49 + len(boundary) + len(self.content_type) +
                    262:                             len('%d' % self.size)))
                    263:                     for start, end in ranges:
                    264:                         # Variable length per set
                    265:                         size = (size + len('%d%d' % (start, end - 1)) +
                    266:                             end - start)
                    267: 
                    268: 
                    269:                     # Some clients implement an earlier draft of the spec, they
                    270:                     # will only accept x-byteranges.
                    271:                     draftprefix = (request_range is not None) and 'x-' or ''
                    272: 
                    273:                     RESPONSE.setHeader('Content-Length', size)
                    274:                     RESPONSE.setHeader('Accept-Ranges', 'bytes')
                    275:                     RESPONSE.setHeader('Last-Modified',
                    276:                         rfc1123_date(self._p_mtime))
                    277:                     RESPONSE.setHeader('Content-Type',
                    278:                         'multipart/%sbyteranges; boundary=%s' % (
                    279:                             draftprefix, boundary))
                    280:                     RESPONSE.setStatus(206) # Partial content
                    281: 
                    282:                     data = urllib.urlopen(self.baseUrl+self.queryString).read()
                    283:                     # The Pdata map allows us to jump into the Pdata chain
                    284:                     # arbitrarily during out-of-order range searching.
                    285:                     pdata_map = {}
                    286:                     pdata_map[0] = data
                    287: 
                    288:                     for start, end in ranges:
                    289:                         RESPONSE.write('\r\n--%s\r\n' % boundary)
                    290:                         RESPONSE.write('Content-Type: %s\r\n' %
                    291:                             self.content_type)
                    292:                         RESPONSE.write(
                    293:                             'Content-Range: bytes %d-%d/%d\r\n\r\n' % (
                    294:                                 start, end - 1, self.size))
                    295: 
                    296:                         if type(data) is StringType:
                    297:                             RESPONSE.write(data[start:end])
                    298: 
                    299:                         else:
                    300:                             # Yippee. Linked Pdata objects. The following
                    301:                             # calculations allow us to fast-forward through the
                    302:                             # Pdata chain without a lot of dereferencing if we
                    303:                             # did the work already.
                    304:                             first_size = len(pdata_map[0].data)
                    305:                             if start < first_size:
                    306:                                 closest_pos = 0
                    307:                             else:
                    308:                                 closest_pos = (
                    309:                                     ((start - first_size) >> 16 << 16) +
                    310:                                     first_size)
                    311:                             pos = min(closest_pos, max(pdata_map.keys()))
                    312:                             data = pdata_map[pos]
                    313: 
                    314:                             while data is not None:
                    315:                                 l = len(data.data)
                    316:                                 pos = pos + l
                    317:                                 if pos > start:
                    318:                                     # We are within the range
                    319:                                     lstart = l - (pos - start)
                    320: 
                    321:                                     if lstart < 0: lstart = 0
                    322: 
                    323:                                     # find the endpoint
                    324:                                     if end <= pos:
                    325:                                         lend = l - (pos - end)
                    326: 
                    327:                                         # Send and loop to next range
                    328:                                         RESPONSE.write(data[lstart:lend])
                    329:                                         break
                    330: 
                    331:                                     # Not yet at the end, transmit what we have.
                    332:                                     RESPONSE.write(data[lstart:])
                    333: 
                    334:                                 data = data.next
                    335:                                 # Store a reference to a Pdata chain link so we
                    336:                                 # don't have to deref during this request again.
                    337:                                 pdata_map[pos] = data
                    338: 
                    339:                     # Do not keep the link references around.
                    340:                     del pdata_map
                    341: 
                    342:                     RESPONSE.write('\r\n--%s--\r\n' % boundary)
                    343:                     return ''
                    344: 
                    345:         RESPONSE.setHeader('Last-Modified', rfc1123_date(self._p_mtime))
                    346:         RESPONSE.setHeader('Content-Type', self.content_type)
                    347:         RESPONSE.setHeader('Content-Length', self.size)
                    348:         RESPONSE.setHeader('Accept-Ranges', 'bytes')
                    349: 
                    350:         # Don't cache the data itself, but provide an opportunity
                    351:         # for a cache manager to set response headers.
                    352:         self.ZCacheable_set(None)
                    353: 
                    354:         data=urllib.urlopen(self.baseUrl+self.queryString).read()
                    355:         
                    356:         if type(data) is type(''): 
                    357:             RESPONSE.setBase(None)
                    358:             return data
                    359: 
                    360:         while data is not None:
                    361:             RESPONSE.write(data.data)
                    362:             data=data.next
                    363: 
                    364:         return ''
                    365: 
                    366: 
                    367: def manage_addZogiImageForm(self):
                    368:     """Form for adding"""
1.18      casties   369:     pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/addZogiImage.zpt')).__of__(self)
1.4       dwinter   370:     return pt()
                    371: 
                    372: 
                    373: def manage_addZogiImage(self,id,title,baseUrl, queryString,RESPONSE=None):
                    374:     """add dgilib"""
                    375:     newObj=zogiImage(id,title,baseUrl, queryString)
                    376:     self.Destination()._setObject(id,newObj)
                    377:     if RESPONSE is not None:
                    378:         RESPONSE.redirect('manage_main')
                    379: 
                    380: 
                    381: 
1.1       dwinter   382: class zogiLib(Folder):
                    383:     """StandardElement"""
                    384: 
                    385:     meta_type="zogiLib"
1.32      dwinter   386:     #xxxx
1.1       dwinter   387: 
1.18      casties   388:     manage_options = Folder.manage_options+(
                    389:             {'label':'Main Config','action':'changeZogiLibForm'},
                    390:             )
1.1       dwinter   391: 
1.37      casties   392:     def __init__(self, id, title, dlServerURL, layout="book", basePath="", dlTarget=None, dlToolbarBaseURL=None):
1.1       dwinter   393:         """init"""
                    394: 
                    395:         self.id=id
                    396:         self.title=title
1.34      casties   397:         self.dlServerURL = dlServerURL
1.21      casties   398:         self.basePath=basePath
1.37      casties   399:         self.layout=layout
1.44    ! casties   400:         self.dlTarget = dlTarget
1.1       dwinter   401: 
1.37      casties   402:         if dlToolbarBaseURL:
                    403:             self.dlToolbarBaseURL = dlToolbarBaseURL
                    404:         else:
                    405:             self.dlToolbarBaseURL = dlServerURL + "/digimage.jsp?"
                    406: 
                    407: 
1.28      casties   408:     def version(self):
                    409:         """version information"""
                    410:         return ZOGIVERSION
                    411: 
1.32      dwinter   412:     def getContextStatic(self):
                    413:         """get all the contexts which go to static pages"""
                    414:         
1.33      dwinter   415:         try:
                    416:             dom=xml.dom.minidom.parse(urllib.urlopen(self.getMetaFileName()))
                    417:             contexts=dom.getElementsByTagName("context")
                    418: 
                    419:             ret=[]
                    420:             for context in contexts:
                    421:                 name=getUniqueElementText(context.getElementsByTagName("name"))
                    422: 
                    423:                 link=getUniqueElementText(context.getElementsByTagName("link"))
                    424:                 if name or link:
                    425:                     ret.append((name,link))
                    426:             return ret
                    427:         except:
                    428:             return []
1.32      dwinter   429: 
                    430:     def getContextDatabases(self):
                    431:         """get all dynamic contexts"""
1.33      dwinter   432:         try:
                    433:             dom=xml.dom.minidom.parse(urllib.urlopen(self.getMetaFileName()))
                    434:             contexts=dom.getElementsByTagName("context")
                    435:             ret=[]
                    436:             for context in contexts:
                    437:                 metaDataLinks=context.getElementsByTagName("meta-datalink")
                    438:                 for metaDataLink in metaDataLinks:
                    439:                     db=metaDataLink.getAttribute("db")
                    440:                     link=self.REQUEST['URL1']+"/dl_db?db=%s"%db
                    441:                     if db:
                    442:                         ret.append((db,link))
                    443:                 metaDataLinks=context.getElementsByTagName("meta-baselink")
                    444: 
                    445:                 for metaDataLink in metaDataLinks:
                    446:                     db=metaDataLink.getAttribute("db")
                    447:                     link=self.REQUEST['URL1']+"/dl_db?db=%s"%db
                    448:                     if db:
                    449:                         ret.append((db,link))
                    450: 
                    451:             return ret
                    452:         except:
                    453:             return ret
1.32      dwinter   454: 
1.39      casties   455: 
1.32      dwinter   456:     def formatHTML(self,url,label=None,viewUrl=None):
                    457: 
                    458:         sets=xml.dom.minidom.parse(urllib.urlopen(url)).getElementsByTagName('dataset')
                    459:         ret=""
                    460:         print label
                    461:         if label:
                    462:             ret+="""<a href="%s">%s</a>"""%(viewUrl,label)
                    463:         for set in sets:
                    464:             ret+="<table>"
                    465:             for node in set.childNodes:
                    466:                 if hasattr(node,'tagName'):
                    467:                     tag=node.tagName
                    468:                     label=node.getAttribute("label")
                    469:                     if not label:
                    470:                         label=tag
                    471:                     text=getText(node.childNodes)
                    472:                     ret+="""<tr><td><b>%s:</b></td><td>%s</td></tr>"""%(label,text)
                    473:             ret+="</table>"
                    474:         return ret
1.39      casties   475: 
1.32      dwinter   476:     
                    477:     def getMetaData(self):
                    478:         """getMetaData"""
1.33      dwinter   479:         try:
                    480:             dom=xml.dom.minidom.parse(urllib.urlopen(self.getMetaFileName()))
                    481:         except:
                    482:             return "error metadata"
                    483:         
1.32      dwinter   484:         contexts=dom.getElementsByTagName("context")
                    485:         ret=[]
                    486:         db=self.getDLParam("db")
                    487:         ob=self.getDLParam("object")
                    488:         
                    489:         fn=self.getDLParam("fn")
                    490:         pn=self.getDLParam("pn")
                    491:         if not fn:
                    492:             fn=""
                    493:         if not pn:
                    494:             pn=""
                    495:         if not ob:
                    496:             ob=""
                    497:             
                    498:         for context in contexts:
                    499:             metaDataLinks=context.getElementsByTagName("meta-datalink")
                    500:             for metaDataLink in metaDataLinks:
                    501:                  
                    502:                 if (db==metaDataLink.getAttribute("db")) or (len(metaDataLinks)==1):
                    503:                     
                    504:                     link=getUniqueElementText(metaDataLink.getElementsByTagName("metadata-url"))
                    505:                     label=getUniqueElementText(metaDataLink.getElementsByTagName("label"))
                    506:                     url=getUniqueElementText(metaDataLink.getElementsByTagName("url"))
                    507: 
                    508:                     return self.formatHTML(link,label,url)
                    509: 
                    510:             metaDataLinks=context.getElementsByTagName("meta-baselink")
                    511:              
                    512:             for metaDataLink in metaDataLinks:
                    513:                 
                    514:                 if db==metaDataLink.getAttribute("db") or (len(metaDataLinks)==1):
                    515:                     
                    516:                     link=getUniqueElementText(metaDataLink.getElementsByTagName("metadata-url"))
                    517:                     label=getUniqueElementText(metaDataLink.getElementsByTagName("label"))
                    518:                     url=getUniqueElementText(metaDataLink.getElementsByTagName("url"))
                    519: 
                    520:                     return self.formatHTML(link+'fn=%s&pn=%s&object=%s'%(fn,pn,ob),label,url)
                    521:         return ret
                    522: 
1.39      casties   523: 
1.18      casties   524:     def getDLInfo(self):
                    525:         """get DLInfo from digilib server"""
                    526:         paramH={}
1.34      casties   527:         baseUrl=self.dlServerURL+"/dlInfo-xml.jsp"
1.18      casties   528:         try:
1.39      casties   529:             url=urllib.urlopen(baseUrl+'?'+self.REQUEST['QUERY_STRING'])
1.18      casties   530:             dom=xml.dom.minidom.parse(url)
                    531:             params=dom.getElementsByTagName('parameter')
                    532:             for param in params:
                    533:                 paramH[param.getAttribute('name')]=param.getAttribute('value')
                    534:             return paramH
                    535:         except:
1.34      casties   536:             return {}
1.18      casties   537: 
1.1       dwinter   538: 
1.18      casties   539:     def createHeadJS(self):
1.19      casties   540:         """generate all javascript tags for head"""
1.26      casties   541:    self.checkQuery()
1.44    ! casties   542:    bt = self.REQUEST.SESSION.get('browserType', {})
1.26      casties   543:         if bt['staticHTML']:
                    544:             return
                    545:         
1.18      casties   546:         pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/zogilib_head_js')).__of__(self)
                    547:         return pt()
1.19      casties   548: 
                    549:     def createParamJS(self):
                    550:         """generate javascript for parameters only"""
1.26      casties   551:    self.checkQuery()
                    552:    bt = self.REQUEST.SESSION['browserType']
                    553:         if bt['staticHTML']:
                    554:             return
                    555: 
1.19      casties   556:         pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/zogilib_param_js')).__of__(self)
                    557:         return pt()
                    558:         
1.3       dwinter   559:                         
1.26      casties   560:     def createScalerImg(self, requestString=None, bottom=0, side=0, width=500, height=500):
1.18      casties   561:         """generate Scaler IMG Tag"""
1.20      casties   562:    self.checkQuery()
                    563:    bt = self.REQUEST.SESSION['browserType']
1.24      casties   564:         # override with parameters from session
                    565:         if  self.REQUEST.SESSION.has_key('scalerDiv'):
1.26      casties   566:             (requestString, bottom, side, width, height) = self.REQUEST.SESSION['scalerDiv']
1.24      casties   567:         # if not explicitly defined take normal request
1.18      casties   568:         if not requestString:
1.21      casties   569:             requestString = self.getAllDLParams()
1.35      casties   570:         url = self.dlServerURL+'/servlet/Scaler?'+requestString
1.24      casties   571:         # construct bottom and side insets
                    572:         b_par = ""
                    573:         s_par = ""
                    574:         if (bottom != 0) or (side != 0):
                    575:             b_par = "-" + str(int(bottom))
                    576:             s_par = "-" + str(int(side))
1.18      casties   577:         tag = ""
1.26      casties   578:         if bt['staticHTML']:
                    579:             tag += '<div id="scaler"><img id="pic" src="%s&dw=%i&dh=%i" /></div>'%(url, int(width-side), int(height-bottom))
1.18      casties   580:         else:
1.26      casties   581:             if bt['isN4']:
                    582:                 # N4 needs layers
                    583:                 tag += '<ilayer id="scaler">'
                    584:             else:
                    585:                 tag += '<div id="scaler">'
                    586:             tag += '<script type="text/javascript">'
                    587:             tag += "var ps = bestPicSize(getElement('scaler'));"
                    588:             # write img tag with javascript
                    589:             tag += 'document.write(\'<img id="pic" src="%s&dw=\'+(ps.width%s)+\'&dh=\'+(ps.height%s)+\'" />\');'%(url, s_par, b_par)
                    590:             tag += '</script>'
                    591:             if bt['isN4']:
                    592:                 tag += '</ilayer>'
                    593:             else:
                    594:                 tag += '</div>'
1.18      casties   595:         return tag
1.1       dwinter   596: 
1.26      casties   597:     def createScalerDiv(self, requestString = None, bottom = 0, side = 0, width=500, height=500):
1.23      casties   598:         """generate scaler img and table with navigation arrows"""
                    599:    self.checkQuery()
1.24      casties   600:         if requestString != None or bottom != 0 or side != 0:
1.26      casties   601:             self.REQUEST.SESSION['scalerDiv'] = (requestString, bottom, side, width, height)
1.24      casties   602:         else:
                    603:             if self.REQUEST.SESSION.has_key('scalerDiv'):
1.26      casties   604:                 # make shure to remove unused parameter
1.24      casties   605:                 del self.REQUEST.SESSION['scalerDiv']
1.26      casties   606:                 
1.23      casties   607:         pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt/zogilib_img_div')).__of__(self)
                    608:         return pt()
                    609: 
1.18      casties   610:     def createAuxDiv(self):
                    611:         """generate other divs"""
1.20      casties   612:    self.checkQuery()
                    613:    bt = self.REQUEST.SESSION['browserType']
1.26      casties   614:         if bt['staticHTML']:
                    615:             return
                    616:         if bt['isN4']:
1.18      casties   617:             f = 'zpt/zogilib_divsN4.zpt'
                    618:         else:
                    619:             f = 'zpt/zogilib_divs.zpt'
                    620:         pt=PageTemplateFile(os.path.join(package_home(globals()),f)).__of__(self)
                    621:         return pt()
1.3       dwinter   622: 
1.9       dwinter   623: 
1.18      casties   624:     def option_js(self):
1.28      casties   625:         """javascript"""
                    626:         return sendFile(self, 'js/option.js', 'text/plain')
1.1       dwinter   627: 
1.18      casties   628:     def dl_lib_js(self):
                    629:         """javascript"""
1.34      casties   630:         return sendFile(self, 'js/dllib.js', 'text/plain')
1.18      casties   631: 
                    632:     def js_lib_js(self):
                    633:         """javascript"""
1.34      casties   634:         return sendFile(self, 'js/baselib.js', 'text/plain')
1.1       dwinter   635: 
1.18      casties   636:     def optionwindow(self):
                    637:         """showoptions"""
1.26      casties   638:    self.checkQuery()
                    639:    bt = self.REQUEST.SESSION['browserType']
                    640:         if bt['staticHTML']:
                    641:             pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/optionwindow_static.zpt')).__of__(self)
                    642:         else:
1.37      casties   643:             tp = "viewingTools.zpt"
                    644:             if hasattr(self, tp):
                    645:                 pt = getattr(self, tp)
1.31      dwinter   646:        else:
                    647:                 pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/optionwindow.zpt')).__of__(self)
1.37      casties   648:                 
                    649:         return pt()
1.13      casties   650: 
                    651:     def mark1(self):
                    652:         """mark image"""
1.18      casties   653:         return sendFile(self, 'images/mark1.gif', 'image/gif')
1.13      casties   654: 
                    655:     def mark2(self):
                    656:         """mark image"""
1.18      casties   657:         return sendFile(self, 'images/mark2.gif', 'image/gif')
1.13      casties   658: 
                    659:     def mark3(self):
                    660:         """mark image"""
1.18      casties   661:         return sendFile(self, 'images/mark3.gif', 'image/gif')
1.13      casties   662: 
                    663:     def mark4(self):
                    664:         """mark image"""
1.18      casties   665:         return sendFile(self, 'images/mark4.gif', 'image/gif')
1.13      casties   666: 
                    667:     def mark5(self):
                    668:         """mark image"""
1.18      casties   669:         return sendFile(self, 'images/mark5.gif', 'image/gif')
1.13      casties   670: 
                    671:     def mark6(self):
                    672:         """mark image"""
1.18      casties   673:         return sendFile(self, 'images/mark6.gif', 'image/gif')
1.13      casties   674: 
                    675:     def mark7(self):
                    676:         """mark image"""
1.18      casties   677:         return sendFile(self, 'images/mark7.gif', 'image/gif')
1.13      casties   678: 
                    679:     def mark8(self):
                    680:         """mark image"""
1.18      casties   681:         return sendFile(self, 'images/mark8.gif', 'image/gif')
1.13      casties   682: 
                    683:     def corner1(self):
                    684:         """mark image"""
1.18      casties   685:         return sendFile(self, 'images/olinks.gif', 'image/gif')
1.13      casties   686: 
                    687:     def corner2(self):
                    688:         """mark image"""
1.18      casties   689:         return sendFile(self, 'images/orechts.gif', 'image/gif')
1.13      casties   690: 
                    691:     def corner3(self):
                    692:         """mark image"""
1.18      casties   693:         return sendFile(self, 'images/ulinks.gif', 'image/gif')
1.13      casties   694: 
                    695:     def corner4(self):
                    696:         """mark image"""
1.18      casties   697:         return sendFile(self, 'images/urechts.gif', 'image/gif')
1.13      casties   698: 
1.22      casties   699:     def up_img(self):
                    700:         """mark image"""
                    701:         return sendFile(self, 'images/up.gif', 'image/gif')
                    702: 
                    703:     def down_img(self):
                    704:         """mark image"""
                    705:         return sendFile(self, 'images/down.gif', 'image/gif')
                    706: 
                    707:     def left_img(self):
                    708:         """mark image"""
                    709:         return sendFile(self, 'images/left.gif', 'image/gif')
                    710: 
                    711:     def right_img(self):
                    712:         """mark image"""
                    713:         return sendFile(self, 'images/right.gif', 'image/gif')
1.13      casties   714: 
                    715: 
1.1       dwinter   716:             
                    717:     def index_html(self):
                    718:         """main action"""
1.26      casties   719:    self.checkQuery()
                    720:    bt = self.REQUEST.SESSION['browserType']
1.18      casties   721:         tp = "zogiLibMainTemplate"
1.32      dwinter   722:         
1.18      casties   723:         if hasattr(self, tp):
                    724:        pt = getattr(self, tp)
                    725:         else:
1.26      casties   726:             tpt = self.layout
1.32      dwinter   727:             
1.26      casties   728:             if bt['staticHTML']:
                    729:                 tpt = "static"
                    730:                 
                    731:             pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/zogiLibMain_%s'%tpt)).__of__(self)
                    732:             
1.18      casties   733:         return pt()
                    734: 
1.1       dwinter   735: 
1.21      casties   736:     def storeQuery(self, more = None):
1.1       dwinter   737:         """storeQuery in session"""
1.18      casties   738:         dlParams = {}
1.1       dwinter   739:         for fm in self.REQUEST.form.keys():
1.18      casties   740:             dlParams[fm] = self.REQUEST.form[fm]
1.21      casties   741:         # look for more
                    742:         if more:
                    743:             for fm in more.split('&'):
                    744:                 try:
                    745:                     pv = fm.split('=')
                    746:                     dlParams[pv[0]] = pv[1]
                    747:                 except:
1.26      casties   748:                     pass
                    749:                 
1.21      casties   750:         # parse digilib mode parameter
1.18      casties   751:         if 'mo' in dlParams:
                    752:             if len(dlParams['mo']) > 0:
                    753:                 modes=dlParams['mo'].split(',')
                    754:         else:
                    755:             modes=[]
1.44    ! casties   756:             
        !           757:         wid = self.getWID()
        !           758:         self.REQUEST.set('wid', wid)
        !           759:         self.setSubSession('dlQuery', dlParams)
        !           760:         self.setSubSession('dlModes', modes)
        !           761:         self.setSubSession('dlInfo', self.getDLInfo())
1.26      casties   762:         if not self.REQUEST.SESSION.has_key('browserType'):
                    763:             self.REQUEST.SESSION['browserType'] = browserCheck(self)
                    764:             
                    765:         return
1.1       dwinter   766: 
1.20      casties   767:     def checkQuery(self):
                    768:    """check if the query has been stored"""
1.44    ! casties   769:    if not (self.REQUEST.SESSION and self.getSubSession('dlQuery')) :
1.20      casties   770:        print "ZOGILIB: have to store query!!"
1.26      casties   771:        self.storeQuery()
1.24      casties   772:         return
1.23      casties   773: 
1.24      casties   774:     def zogilibPath(self, otherbase=None):
1.23      casties   775:         """returns an URL to the zogiLib instance"""
                    776:         url = self.REQUEST['URL1']
1.24      casties   777:         # should end with "/"
                    778:         if len(url) > 0 and url[-1] != '/':
                    779:             url += '/'
                    780:         if type(otherbase) is str:
                    781:             url += otherbase
                    782:         else:
                    783:             url += self.basePath
1.23      casties   784:         # should end with "/"
                    785:         if len(url) > 0 and url[-1] != '/':
                    786:             url += '/'
                    787:         return url
1.44    ! casties   788: 
        !           789:     def zogilibAction(self, action, otherbase=None, wid=None):
        !           790:         """returns a URL with zogilib path, action and wid"""
        !           791:         url = self.zogilibPath(otherbase)
        !           792:         url += action
        !           793:         if wid:
        !           794:             url += '?wid=' + wid
        !           795:         else:
        !           796:             url += '?wid=' + self.getWID()
        !           797:         return url
        !           798: 
        !           799:     def getSubSession(self, key, default=None):
        !           800:         """returns an element from a session with a wid"""
        !           801:         wid = self.getWID()
        !           802:         return self.REQUEST.SESSION.get(key+'_'+wid, default)
        !           803: 
        !           804:     def setSubSession(self, key, value):
        !           805:         """puts an element in a session with a wid"""
        !           806:         wid = self.getWID()
        !           807:         self.REQUEST.SESSION.set(key+'_'+wid, value)
        !           808:         return
        !           809: 
        !           810:     def getWID(self):
        !           811:         """returns a (new) window id"""
        !           812:         wid = self.REQUEST.get('wid')
        !           813:         if not wid:
        !           814:             wid = 'digi_'+str(int(random.random()*10000))
        !           815:             print "new WID:", wid
        !           816:         return wid
1.3       dwinter   817:         
1.22      casties   818:     def getDLParam(self, param):
1.18      casties   819:         """returns parameter"""
1.3       dwinter   820:         try:
1.44    ! casties   821:             return self.getSubSession('dlQuery').get(param)
1.3       dwinter   822:         except:
1.24      casties   823:             return
1.3       dwinter   824: 
1.18      casties   825:     def setDLParam(self, param, value):
                    826:         """sets parameter"""
1.44    ! casties   827:         dlParams = self.getSubSession('dlQuery')
        !           828:         #try:
        !           829:         dlParams[param] = value
        !           830:         #except:
        !           831:         #    self.setSubSession('dlQuery', {param: value})
1.18      casties   832:         return
                    833: 
                    834:     def getAllDLParams(self):
                    835:         """parameter string for digilib"""
1.44    ! casties   836:         dlParams = self.getSubSession('dlQuery')
1.18      casties   837:         # save modes
1.44    ! casties   838:         modes = self.getSubSession('dlModes')
1.18      casties   839:         dlParams['mo'] = string.join(modes, ',')
                    840:         # assemble query string
                    841:         ret = ""
                    842:         for param in dlParams.keys():
1.29      casties   843:             if dlParams[param] is None: continue
1.18      casties   844:             val = str(dlParams[param])
                    845:             if val != "":
                    846:                 ret += param + "=" + val + "&"
1.28      casties   847: 
1.18      casties   848:         # omit trailing "&"
                    849:         return ret.rstrip('&')
                    850: 
                    851:         
                    852:     def setDLParams(self,pn=None,ws=None,rot=None,brgt=None,cont=None):
                    853:         """setze Parameter"""
                    854: 
1.23      casties   855:         self.setDLParam('brgt', brgt)
                    856:         self.setDLParam('cont', cont)
                    857:         self.setDLParam('ws', ws)
                    858:         self.setDLParam('rot', rot)
1.18      casties   859: 
                    860:         if pn:
1.21      casties   861:             # unmark
                    862:             self.setDLParam('mk', None)
1.18      casties   863:             self.setDLParam('pn', pn)
                    864:             
                    865:         return self.display()
                    866: 
                    867: 
                    868:     def display(self):
                    869:         """(re)display page"""
1.44    ! casties   870:         if not self.getDLParam('wid'):
        !           871:             wid = self.getWID()
        !           872:             self.setDLParam('wid', wid)
        !           873:             
1.18      casties   874:         params = self.getAllDLParams()
1.44    ! casties   875:             
1.21      casties   876:         if self.basePath:
                    877:             self.REQUEST.RESPONSE.redirect(self.REQUEST['URL2']+'?'+params)
                    878:         else:
                    879:             self.REQUEST.RESPONSE.redirect(self.REQUEST['URL1']+'?'+params)
1.18      casties   880: 
1.32      dwinter   881:     def getMetaFileName(self):
1.34      casties   882:         url=self.dlServerURL+'/dlContext-xml.jsp?'+self.getAllDLParams()
                    883:         return urlbase
1.26      casties   884: 
1.34      casties   885:     def getToolbarPageURL(self):
                    886:         """returns a toolbar-enabled page URL"""
1.37      casties   887:         url=self.dlToolbarBaseURL+self.getAllDLParams()
1.34      casties   888:         return url
1.32      dwinter   889:     
1.30      casties   890:     def getDLTarget(self):
                    891:         """returns dlTarget"""
                    892:         self.checkQuery()
                    893:         s = self.dlTarget
1.44    ! casties   894:         if s == None:
        !           895:             s = ""
1.30      casties   896: #         s = 'dl'
                    897: #         if self.getDLParam('fn'):
                    898: #             s += "_" + self.getDLParam('fn')
                    899: #         if self.getDLParam('pn'):
                    900: #             s += "_" + self.getDLParam('pn')
                    901:         return s
                    902: 
1.26      casties   903:     def setStaticHTML(self, static=True):
                    904:         """sets the preference to static HTML"""
                    905:         self.checkQuery()
                    906:    self.REQUEST.SESSION['browserType']['staticHTML'] = static
                    907:         return
                    908: 
                    909:     def isStaticHTML(self):
                    910:         """returns if the page is using static HTML only"""
                    911:         self.checkQuery()
                    912:    return self.REQUEST.SESSION['browserType']['staticHTML']
                    913: 
1.18      casties   914:     def getPT(self):
                    915:         """pagenums"""
1.44    ! casties   916:         di = self.getSubSession('dlInfo_')
1.18      casties   917:         if di:
                    918:             return int(di['pt'])
                    919:         else:
                    920:             return 1
                    921:     
                    922:     def getPN(self):
                    923:         """Pagenum"""
                    924:         pn = self.getDLParam('pn')
1.25      casties   925:         try:
1.18      casties   926:             return int(pn)
1.25      casties   927:         except:
1.3       dwinter   928:             return 1
                    929: 
1.18      casties   930:     def getBiggerWS(self):
1.3       dwinter   931:         """ws+1"""
1.23      casties   932:         ws = self.getDLParam('ws')
1.25      casties   933:         try:
1.26      casties   934:             return float(ws)+0.5
1.25      casties   935:         except:
1.26      casties   936:             return 1.5
1.3       dwinter   937:         
1.18      casties   938:     def getSmallerWS(self):
                    939:         """ws-1"""
                    940:         ws=self.getDLParam('ws')
1.25      casties   941:         try:
1.26      casties   942:             return max(float(ws)-0.5, 1)
1.25      casties   943:         except:
1.3       dwinter   944:             return 1
1.1       dwinter   945: 
1.18      casties   946:     def hasMode(self, mode):
                    947:         """returns if mode is in the diglib mo parameter"""
1.44    ! casties   948:         wid = self.getWID()
        !           949:         return (mode in self.REQUEST.SESSION['dlModes_'+wid])
1.18      casties   950: 
                    951:     def hasNextPage(self):
                    952:         """returns if there is a next page"""
                    953:         pn = self.getPN()
                    954:         pt = self.getPT()
                    955:         return (pn < pt)
                    956:    
                    957:     def hasPrevPage(self):
                    958:         """returns if there is a previous page"""
                    959:         pn = self.getPN()
                    960:         return (pn > 1)
1.1       dwinter   961: 
1.22      casties   962:     def canMoveLeft(self):
                    963:         """returns if its possible to move left"""
                    964:         wx = float(self.getDLParam('wx') or 0)
                    965:         return (wx > 0)
                    966: 
                    967:     def canMoveRight(self):
                    968:         """returns if its possible to move right"""
                    969:         wx = float(self.getDLParam('wx') or 0)
                    970:         ww = float(self.getDLParam('ww') or 1)
                    971:         return (wx + ww < 1)
                    972: 
                    973:     def canMoveUp(self):
                    974:         """returns if its possible to move up"""
                    975:         wy = float(self.getDLParam('wy') or 0)
                    976:         return (wy > 0)
                    977: 
                    978:     def canMoveDown(self):
                    979:         """returns if its possible to move down"""
                    980:         wy = float(self.getDLParam('wy') or 0)
                    981:         wh = float(self.getDLParam('wh') or 1)
                    982:         return (wy + wh < 1)
                    983: 
1.26      casties   984: 
                    985:     def dl_StaticHTML(self):
                    986:         """set rendering to static HTML"""
                    987:         self.checkQuery()
                    988:         self.REQUEST.SESSION['browserType']['staticHTML'] = True
                    989:         return self.display()
                    990: 
                    991:     def dl_DynamicHTML(self):
                    992:         """set rendering to dynamic HTML"""
                    993:         self.checkQuery()
                    994:         self.REQUEST.SESSION['browserType']['staticHTML'] = False
                    995:         return self.display()
1.1       dwinter   996:         
1.18      casties   997:     def dl_HMirror(self):
                    998:         """mirror action"""
1.44    ! casties   999:         modes = self.getSubSession('dlModes')
1.18      casties  1000:         if 'hmir' in modes:
                   1001:             modes.remove('hmir')
                   1002:         else:
                   1003:             modes.append('hmir')
1.1       dwinter  1004: 
1.18      casties  1005:         return self.display()
                   1006:        
                   1007:     def dl_VMirror(self):
                   1008:         """mirror action"""
1.44    ! casties  1009:         modes = self.getSubSession('dlModes')
1.18      casties  1010:         if 'vmir' in modes:
                   1011:             modes.remove('vmir')
                   1012:         else:
                   1013:             modes.append('vmir')
1.1       dwinter  1014: 
1.18      casties  1015:         return self.display()
1.1       dwinter  1016: 
1.22      casties  1017:     def dl_Zoom(self, z):
                   1018:         """general zoom action"""
                   1019:         ww1 = float(self.getDLParam('ww') or 1)
                   1020:         wh1 = float(self.getDLParam('wh') or 1)
                   1021:         wx = float(self.getDLParam('wx') or 0)
                   1022:         wy = float(self.getDLParam('wy') or 0)
                   1023:         ww2 = ww1 * z
                   1024:         wh2 = wh1 * z
                   1025:         wx += (ww1 - ww2) / 2
                   1026:         wy += (wh1 - wh2) / 2
                   1027:         ww2 = max(min(ww2, 1), 0)
                   1028:         wh2 = max(min(wh2, 1), 0)
                   1029:         wx = max(min(wx, 1), 0)
                   1030:         wy = max(min(wy, 1), 0)
1.30      casties  1031:         self.setDLParam('ww', cropf(ww2))
                   1032:         self.setDLParam('wh', cropf(wh2))
                   1033:         self.setDLParam('wx', cropf(wx))
                   1034:         self.setDLParam('wy', cropf(wy))
1.22      casties  1035:         return self.display()
                   1036:         
                   1037:     def dl_ZoomIn(self):
                   1038:         """zoom in action"""
                   1039:         z = 0.7071
                   1040:         return self.dl_Zoom(z)
                   1041: 
                   1042:     def dl_ZoomOut(self):
                   1043:         """zoom out action"""
                   1044:         z = 1.4142
                   1045:         return self.dl_Zoom(z)
                   1046: 
                   1047:     def dl_Move(self, dx, dy):
                   1048:         """general move action"""
                   1049:         ww = float(self.getDLParam('ww') or 1)
                   1050:         wh = float(self.getDLParam('wh') or 1)
                   1051:         wx = float(self.getDLParam('wx') or 0)
                   1052:         wy = float(self.getDLParam('wy') or 0)
                   1053:         wx += dx * 0.5 * ww
                   1054:         wy += dy * 0.5 * wh
                   1055:         wx = max(min(wx, 1), 0)
                   1056:         wy = max(min(wy, 1), 0)
1.30      casties  1057:         self.setDLParam('wx', cropf(wx))
                   1058:         self.setDLParam('wy', cropf(wy))
1.22      casties  1059:         return self.display()
                   1060:         
                   1061:     def dl_MoveLeft(self):
                   1062:         """move left action"""
                   1063:         return self.dl_Move(-1, 0)
                   1064:     
                   1065:     def dl_MoveRight(self):
                   1066:         """move left action"""
                   1067:         return self.dl_Move(1, 0)
                   1068:     
                   1069:     def dl_MoveUp(self):
                   1070:         """move left action"""
                   1071:         return self.dl_Move(0, -1)
                   1072:     
                   1073:     def dl_MoveDown(self):
                   1074:         """move left action"""
                   1075:         return self.dl_Move(0, 1)
                   1076:     
1.18      casties  1077:     def dl_WholePage(self):
                   1078:         """zoom out action"""
                   1079:         self.setDLParam('ww', 1)
                   1080:         self.setDLParam('wh', 1)
                   1081:         self.setDLParam('wx', 0)
                   1082:         self.setDLParam('wy', 0)
                   1083:         return self.display()
                   1084:         
                   1085:     def dl_PrevPage(self):
                   1086:         """next page action"""
                   1087:         pn = self.getPN() - 1
                   1088:         if pn < 1:
                   1089:             pn = 1
                   1090:         self.setDLParam('pn', pn)
                   1091:         # unmark
                   1092:         self.setDLParam('mk', None)
                   1093:         return self.display()
                   1094:         
                   1095:     def dl_NextPage(self):
                   1096:         """next page action"""
                   1097:         pn = self.getPN() + 1
                   1098:         pt = self.getPT()
                   1099:         if pn > pt:
                   1100:             pn = pt
                   1101:         self.setDLParam('pn', pn)
                   1102:         # unmark
                   1103:         self.setDLParam('mk', None)
                   1104:         return self.display()
                   1105: 
                   1106:     def dl_FirstPage(self):
                   1107:         """first page action"""
                   1108:         self.setDLParam('pn', 1)
                   1109:         # unmark
                   1110:         self.setDLParam('mk', None)
                   1111:         return self.display()
                   1112:     
                   1113:     def dl_LastPage(self):
                   1114:         """last page action"""
                   1115:         self.setDLParam('pn', self.getPT())
                   1116:         # unmark
                   1117:         self.setDLParam('mk', None)
                   1118:         return self.display()
                   1119: 
                   1120:     def dl_Unmark(self):
                   1121:         """action to remove last mark"""
                   1122:         mk = self.getDLParam('mk')
                   1123:         if mk:
                   1124:             marks = mk.split(',')
                   1125:             marks.pop()
                   1126:             mk = string.join(marks, ',')
                   1127:             self.setDLParam('mk', mk)
                   1128:         return self.display()
1.1       dwinter  1129: 
1.32      dwinter  1130:     def dl_db(self,db):
                   1131:         """set db"""
                   1132:         self.setDLParam('db',db)
                   1133:         self.display()
1.1       dwinter  1134: 
1.18      casties  1135:     def changeZogiLibForm(self):
                   1136:         """Main configuration"""
                   1137:         pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/changeZogiLibForm.zpt')).__of__(self)
                   1138:         return pt()
1.1       dwinter  1139:     
1.37      casties  1140:     def changeZogiLib(self,title,dlServerURL, version, basePath, dlTarget, dlToolbarBaseURL, RESPONSE=None):
1.18      casties  1141:         """change it"""
                   1142:         self.title=title
1.35      casties  1143:         self.dlServerURL=dlServerURL
1.21      casties  1144:         self.basePath = basePath
1.18      casties  1145:         self.layout=version
1.44    ! casties  1146:         self.dlTarget = dlTarget
1.3       dwinter  1147: 
1.37      casties  1148:         if dlToolbarBaseURL:
                   1149:             self.dlToolbarBaseURL = dlToolbarBaseURL
                   1150:         else:
                   1151:             self.dlToolbarBaseURL = dlServerURL + "/digimage.jsp?"
                   1152: 
1.18      casties  1153:         if RESPONSE is not None:
                   1154:             RESPONSE.redirect('manage_main')
1.8       dwinter  1155: 
1.35      casties  1156: 
                   1157: 
                   1158:     ##
1.44    ! casties  1159:     ## odds and ends
1.35      casties  1160:     ##
                   1161: 
                   1162:     def repairZogilib(self, obj=None):
                   1163:         """change stuff that broke on upgrading"""
                   1164: 
                   1165:         msg = ""
                   1166: 
                   1167:         if not obj:
                   1168:             obj = self.getPhysicalRoot()
                   1169: 
                   1170:         print "starting in ", obj
                   1171:         
                   1172:         entries=obj.ZopeFind(obj,obj_metatypes=['zogiLib'],search_sub=1)
                   1173: 
                   1174:         for entry in entries:
                   1175:             print "  found ", entry
1.37      casties  1176:             #
                   1177:             # replace digilibBaseUrl by dlServerURL
1.35      casties  1178:             if hasattr(entry[1], 'digilibBaseUrl'):
1.37      casties  1179:                 msg += "  fixing digilibBaseUrl in "+entry[0]+"\n"
1.36      casties  1180:                 entry[1].dlServerURL = re.sub('/servlet/Scaler\?','',entry[1].digilibBaseUrl)
1.35      casties  1181:                 del entry[1].digilibBaseUrl
                   1182:                 
1.37      casties  1183:             #
                   1184:             # add dlToolbarBaseURL
                   1185:             if not hasattr(entry[1], 'dlToolbarBaseURL'):
                   1186:                 msg += "  fixing dlToolbarBaseURL in "+entry[0]+"\n"
                   1187:                 entry[1].dlToolbarBaseURL = entry[1].dlServerURL + "/digimage.jsp?"
                   1188:                 
1.35      casties  1189:         return msg+"\n\nfixed all zogilib instances in: "+obj.title
                   1190: 
1.8       dwinter  1191:           
1.1       dwinter  1192: def manage_addZogiLibForm(self):
                   1193:     """interface for adding zogilib"""
1.18      casties  1194:     pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/addZogiLibForm')).__of__(self)
1.1       dwinter  1195:     return pt()
                   1196: 
1.44    ! casties  1197: def manage_addZogiLib(self,id,title,dlServerURL,version="book",basePath="",dlTarget=None,dlToolbarBaseURL=None,RESPONSE=None):
1.1       dwinter  1198:     """add dgilib"""
1.43      casties  1199:     newObj=zogiLib(id,title,dlServerURL, version, basePath, dlTarget, dlToolbarBaseURL)
1.1       dwinter  1200:     self.Destination()._setObject(id,newObj)
                   1201:     if RESPONSE is not None:
                   1202:         RESPONSE.redirect('manage_main')
1.29      casties  1203: 
                   1204: 
                   1205: class zogiLibPageTemplate(ZopePageTemplate):
                   1206:     """pageTemplate Objekt"""
                   1207:     meta_type="zogiLib_pageTemplate"
                   1208: 
                   1209: 
                   1210: ## def __init__(self, id, text=None, contentType=None):
                   1211: ##         self.id = str(id)
                   1212: ##         self.ZBindings_edit(self._default_bindings)
                   1213: ##         if text is None:
                   1214: ##             text = open(self._default_cont).read()
                   1215: ##         self.pt_edit(text, contentType)
                   1216: 
                   1217: def manage_addZogiLibPageTemplateForm(self):
                   1218:     """Form for adding"""
                   1219:     pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/addZogiLibPageTemplateForm')).__of__(self)
                   1220:     return pt()
                   1221: 
                   1222: def manage_addZogiLibPageTemplate(self, id='zogiLibMainTemplate', title=None, layout=None, text=None,
                   1223:                            REQUEST=None, submit=None):
                   1224:     "Add a Page Template with optional file content."
                   1225: 
                   1226:     id = str(id)
                   1227:     self._setObject(id, zogiLibPageTemplate(id))
                   1228:     ob = getattr(self, id)
                   1229:     if not layout: layout = "book"
                   1230:     ob.pt_edit(open(os.path.join(package_home(globals()),'zpt/zogiLibMain_%s.zpt'%layout)).read(),None)
                   1231:     if title:
                   1232:         ob.pt_setTitle(title)
                   1233:     try:
                   1234:         u = self.DestinationURL()
                   1235:     except AttributeError:
                   1236:         u = REQUEST['URL1']
                   1237:         
                   1238:     u = "%s/%s" % (u, urllib.quote(id))
                   1239:     REQUEST.RESPONSE.redirect(u+'/manage_main')
                   1240:     return ''
1.35      casties  1241: 

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