Annotation of zogiLib/zogiLib.py, revision 1.45

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: 
1.45    ! casties   354:    #return "zogiimage: "+self.baseUrl+self.queryString
1.4       dwinter   355:         data=urllib.urlopen(self.baseUrl+self.queryString).read()
                    356:         
                    357:         if type(data) is type(''): 
                    358:             RESPONSE.setBase(None)
                    359:             return data
                    360: 
                    361:         while data is not None:
                    362:             RESPONSE.write(data.data)
                    363:             data=data.next
                    364: 
                    365:         return ''
                    366: 
                    367: 
                    368: def manage_addZogiImageForm(self):
                    369:     """Form for adding"""
1.18      casties   370:     pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/addZogiImage.zpt')).__of__(self)
1.4       dwinter   371:     return pt()
                    372: 
                    373: 
                    374: def manage_addZogiImage(self,id,title,baseUrl, queryString,RESPONSE=None):
                    375:     """add dgilib"""
                    376:     newObj=zogiImage(id,title,baseUrl, queryString)
                    377:     self.Destination()._setObject(id,newObj)
                    378:     if RESPONSE is not None:
                    379:         RESPONSE.redirect('manage_main')
                    380: 
                    381: 
                    382: 
1.1       dwinter   383: class zogiLib(Folder):
                    384:     """StandardElement"""
                    385: 
                    386:     meta_type="zogiLib"
1.32      dwinter   387:     #xxxx
1.1       dwinter   388: 
1.18      casties   389:     manage_options = Folder.manage_options+(
                    390:             {'label':'Main Config','action':'changeZogiLibForm'},
                    391:             )
1.1       dwinter   392: 
1.37      casties   393:     def __init__(self, id, title, dlServerURL, layout="book", basePath="", dlTarget=None, dlToolbarBaseURL=None):
1.1       dwinter   394:         """init"""
                    395: 
                    396:         self.id=id
                    397:         self.title=title
1.34      casties   398:         self.dlServerURL = dlServerURL
1.21      casties   399:         self.basePath=basePath
1.37      casties   400:         self.layout=layout
1.44      casties   401:         self.dlTarget = dlTarget
1.1       dwinter   402: 
1.37      casties   403:         if dlToolbarBaseURL:
                    404:             self.dlToolbarBaseURL = dlToolbarBaseURL
                    405:         else:
                    406:             self.dlToolbarBaseURL = dlServerURL + "/digimage.jsp?"
                    407: 
                    408: 
1.28      casties   409:     def version(self):
                    410:         """version information"""
                    411:         return ZOGIVERSION
                    412: 
1.32      dwinter   413:     def getContextStatic(self):
                    414:         """get all the contexts which go to static pages"""
                    415:         
1.33      dwinter   416:         try:
                    417:             dom=xml.dom.minidom.parse(urllib.urlopen(self.getMetaFileName()))
                    418:             contexts=dom.getElementsByTagName("context")
                    419: 
                    420:             ret=[]
                    421:             for context in contexts:
                    422:                 name=getUniqueElementText(context.getElementsByTagName("name"))
                    423: 
                    424:                 link=getUniqueElementText(context.getElementsByTagName("link"))
                    425:                 if name or link:
                    426:                     ret.append((name,link))
                    427:             return ret
                    428:         except:
                    429:             return []
1.32      dwinter   430: 
                    431:     def getContextDatabases(self):
                    432:         """get all dynamic contexts"""
1.33      dwinter   433:         try:
                    434:             dom=xml.dom.minidom.parse(urllib.urlopen(self.getMetaFileName()))
                    435:             contexts=dom.getElementsByTagName("context")
                    436:             ret=[]
                    437:             for context in contexts:
                    438:                 metaDataLinks=context.getElementsByTagName("meta-datalink")
                    439:                 for metaDataLink in metaDataLinks:
                    440:                     db=metaDataLink.getAttribute("db")
                    441:                     link=self.REQUEST['URL1']+"/dl_db?db=%s"%db
                    442:                     if db:
                    443:                         ret.append((db,link))
                    444:                 metaDataLinks=context.getElementsByTagName("meta-baselink")
                    445: 
                    446:                 for metaDataLink in metaDataLinks:
                    447:                     db=metaDataLink.getAttribute("db")
                    448:                     link=self.REQUEST['URL1']+"/dl_db?db=%s"%db
                    449:                     if db:
                    450:                         ret.append((db,link))
                    451: 
                    452:             return ret
                    453:         except:
1.45    ! casties   454: 
        !           455:             return []
1.32      dwinter   456: 
1.39      casties   457: 
1.32      dwinter   458:     def formatHTML(self,url,label=None,viewUrl=None):
                    459: 
                    460:         sets=xml.dom.minidom.parse(urllib.urlopen(url)).getElementsByTagName('dataset')
                    461:         ret=""
                    462:         print label
                    463:         if label:
                    464:             ret+="""<a href="%s">%s</a>"""%(viewUrl,label)
                    465:         for set in sets:
                    466:             ret+="<table>"
                    467:             for node in set.childNodes:
                    468:                 if hasattr(node,'tagName'):
                    469:                     tag=node.tagName
                    470:                     label=node.getAttribute("label")
                    471:                     if not label:
                    472:                         label=tag
                    473:                     text=getText(node.childNodes)
                    474:                     ret+="""<tr><td><b>%s:</b></td><td>%s</td></tr>"""%(label,text)
                    475:             ret+="</table>"
                    476:         return ret
1.39      casties   477: 
1.32      dwinter   478:     
                    479:     def getMetaData(self):
                    480:         """getMetaData"""
1.33      dwinter   481:         try:
                    482:             dom=xml.dom.minidom.parse(urllib.urlopen(self.getMetaFileName()))
                    483:         except:
                    484:             return "error metadata"
                    485:         
1.32      dwinter   486:         contexts=dom.getElementsByTagName("context")
                    487:         ret=[]
                    488:         db=self.getDLParam("db")
                    489:         ob=self.getDLParam("object")
                    490:         
                    491:         fn=self.getDLParam("fn")
                    492:         pn=self.getDLParam("pn")
                    493:         if not fn:
                    494:             fn=""
                    495:         if not pn:
                    496:             pn=""
                    497:         if not ob:
                    498:             ob=""
                    499:             
                    500:         for context in contexts:
                    501:             metaDataLinks=context.getElementsByTagName("meta-datalink")
                    502:             for metaDataLink in metaDataLinks:
                    503:                  
                    504:                 if (db==metaDataLink.getAttribute("db")) or (len(metaDataLinks)==1):
                    505:                     
                    506:                     link=getUniqueElementText(metaDataLink.getElementsByTagName("metadata-url"))
                    507:                     label=getUniqueElementText(metaDataLink.getElementsByTagName("label"))
                    508:                     url=getUniqueElementText(metaDataLink.getElementsByTagName("url"))
                    509: 
                    510:                     return self.formatHTML(link,label,url)
                    511: 
                    512:             metaDataLinks=context.getElementsByTagName("meta-baselink")
                    513:              
                    514:             for metaDataLink in metaDataLinks:
                    515:                 
                    516:                 if db==metaDataLink.getAttribute("db") or (len(metaDataLinks)==1):
                    517:                     
                    518:                     link=getUniqueElementText(metaDataLink.getElementsByTagName("metadata-url"))
                    519:                     label=getUniqueElementText(metaDataLink.getElementsByTagName("label"))
                    520:                     url=getUniqueElementText(metaDataLink.getElementsByTagName("url"))
                    521: 
                    522:                     return self.formatHTML(link+'fn=%s&pn=%s&object=%s'%(fn,pn,ob),label,url)
                    523:         return ret
                    524: 
1.39      casties   525: 
1.18      casties   526:     def getDLInfo(self):
                    527:         """get DLInfo from digilib server"""
                    528:         paramH={}
1.34      casties   529:         baseUrl=self.dlServerURL+"/dlInfo-xml.jsp"
1.18      casties   530:         try:
1.39      casties   531:             url=urllib.urlopen(baseUrl+'?'+self.REQUEST['QUERY_STRING'])
1.18      casties   532:             dom=xml.dom.minidom.parse(url)
                    533:             params=dom.getElementsByTagName('parameter')
                    534:             for param in params:
                    535:                 paramH[param.getAttribute('name')]=param.getAttribute('value')
                    536:             return paramH
                    537:         except:
1.34      casties   538:             return {}
1.18      casties   539: 
1.1       dwinter   540: 
1.18      casties   541:     def createHeadJS(self):
1.19      casties   542:         """generate all javascript tags for head"""
1.26      casties   543:    self.checkQuery()
1.44      casties   544:    bt = self.REQUEST.SESSION.get('browserType', {})
1.26      casties   545:         if bt['staticHTML']:
                    546:             return
                    547:         
1.18      casties   548:         pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/zogilib_head_js')).__of__(self)
                    549:         return pt()
1.19      casties   550: 
                    551:     def createParamJS(self):
                    552:         """generate javascript for parameters only"""
1.26      casties   553:    self.checkQuery()
                    554:    bt = self.REQUEST.SESSION['browserType']
                    555:         if bt['staticHTML']:
                    556:             return
                    557: 
1.19      casties   558:         pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/zogilib_param_js')).__of__(self)
                    559:         return pt()
                    560:         
1.3       dwinter   561:                         
1.26      casties   562:     def createScalerImg(self, requestString=None, bottom=0, side=0, width=500, height=500):
1.18      casties   563:         """generate Scaler IMG Tag"""
1.20      casties   564:    self.checkQuery()
                    565:    bt = self.REQUEST.SESSION['browserType']
1.24      casties   566:         # override with parameters from session
                    567:         if  self.REQUEST.SESSION.has_key('scalerDiv'):
1.26      casties   568:             (requestString, bottom, side, width, height) = self.REQUEST.SESSION['scalerDiv']
1.24      casties   569:         # if not explicitly defined take normal request
1.18      casties   570:         if not requestString:
1.21      casties   571:             requestString = self.getAllDLParams()
1.35      casties   572:         url = self.dlServerURL+'/servlet/Scaler?'+requestString
1.24      casties   573:         # construct bottom and side insets
                    574:         b_par = ""
                    575:         s_par = ""
                    576:         if (bottom != 0) or (side != 0):
                    577:             b_par = "-" + str(int(bottom))
                    578:             s_par = "-" + str(int(side))
1.18      casties   579:         tag = ""
1.26      casties   580:         if bt['staticHTML']:
                    581:             tag += '<div id="scaler"><img id="pic" src="%s&dw=%i&dh=%i" /></div>'%(url, int(width-side), int(height-bottom))
1.18      casties   582:         else:
1.26      casties   583:             if bt['isN4']:
                    584:                 # N4 needs layers
                    585:                 tag += '<ilayer id="scaler">'
                    586:             else:
                    587:                 tag += '<div id="scaler">'
                    588:             tag += '<script type="text/javascript">'
                    589:             tag += "var ps = bestPicSize(getElement('scaler'));"
                    590:             # write img tag with javascript
                    591:             tag += 'document.write(\'<img id="pic" src="%s&dw=\'+(ps.width%s)+\'&dh=\'+(ps.height%s)+\'" />\');'%(url, s_par, b_par)
                    592:             tag += '</script>'
                    593:             if bt['isN4']:
                    594:                 tag += '</ilayer>'
                    595:             else:
                    596:                 tag += '</div>'
1.18      casties   597:         return tag
1.1       dwinter   598: 
1.26      casties   599:     def createScalerDiv(self, requestString = None, bottom = 0, side = 0, width=500, height=500):
1.23      casties   600:         """generate scaler img and table with navigation arrows"""
                    601:    self.checkQuery()
1.24      casties   602:         if requestString != None or bottom != 0 or side != 0:
1.26      casties   603:             self.REQUEST.SESSION['scalerDiv'] = (requestString, bottom, side, width, height)
1.24      casties   604:         else:
                    605:             if self.REQUEST.SESSION.has_key('scalerDiv'):
1.26      casties   606:                 # make shure to remove unused parameter
1.24      casties   607:                 del self.REQUEST.SESSION['scalerDiv']
1.26      casties   608:                 
1.23      casties   609:         pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt/zogilib_img_div')).__of__(self)
                    610:         return pt()
                    611: 
1.18      casties   612:     def createAuxDiv(self):
                    613:         """generate other divs"""
1.20      casties   614:    self.checkQuery()
                    615:    bt = self.REQUEST.SESSION['browserType']
1.26      casties   616:         if bt['staticHTML']:
                    617:             return
                    618:         if bt['isN4']:
1.18      casties   619:             f = 'zpt/zogilib_divsN4.zpt'
                    620:         else:
                    621:             f = 'zpt/zogilib_divs.zpt'
                    622:         pt=PageTemplateFile(os.path.join(package_home(globals()),f)).__of__(self)
                    623:         return pt()
1.3       dwinter   624: 
1.9       dwinter   625: 
1.18      casties   626:     def option_js(self):
1.28      casties   627:         """javascript"""
                    628:         return sendFile(self, 'js/option.js', 'text/plain')
1.1       dwinter   629: 
1.18      casties   630:     def dl_lib_js(self):
                    631:         """javascript"""
1.34      casties   632:         return sendFile(self, 'js/dllib.js', 'text/plain')
1.18      casties   633: 
                    634:     def js_lib_js(self):
                    635:         """javascript"""
1.34      casties   636:         return sendFile(self, 'js/baselib.js', 'text/plain')
1.1       dwinter   637: 
1.18      casties   638:     def optionwindow(self):
                    639:         """showoptions"""
1.26      casties   640:    self.checkQuery()
                    641:    bt = self.REQUEST.SESSION['browserType']
                    642:         if bt['staticHTML']:
                    643:             pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/optionwindow_static.zpt')).__of__(self)
                    644:         else:
1.37      casties   645:             tp = "viewingTools.zpt"
                    646:             if hasattr(self, tp):
                    647:                 pt = getattr(self, tp)
1.31      dwinter   648:        else:
                    649:                 pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/optionwindow.zpt')).__of__(self)
1.37      casties   650:                 
                    651:         return pt()
1.13      casties   652: 
                    653:     def mark1(self):
                    654:         """mark image"""
1.18      casties   655:         return sendFile(self, 'images/mark1.gif', 'image/gif')
1.13      casties   656: 
                    657:     def mark2(self):
                    658:         """mark image"""
1.18      casties   659:         return sendFile(self, 'images/mark2.gif', 'image/gif')
1.13      casties   660: 
                    661:     def mark3(self):
                    662:         """mark image"""
1.18      casties   663:         return sendFile(self, 'images/mark3.gif', 'image/gif')
1.13      casties   664: 
                    665:     def mark4(self):
                    666:         """mark image"""
1.18      casties   667:         return sendFile(self, 'images/mark4.gif', 'image/gif')
1.13      casties   668: 
                    669:     def mark5(self):
                    670:         """mark image"""
1.18      casties   671:         return sendFile(self, 'images/mark5.gif', 'image/gif')
1.13      casties   672: 
                    673:     def mark6(self):
                    674:         """mark image"""
1.18      casties   675:         return sendFile(self, 'images/mark6.gif', 'image/gif')
1.13      casties   676: 
                    677:     def mark7(self):
                    678:         """mark image"""
1.18      casties   679:         return sendFile(self, 'images/mark7.gif', 'image/gif')
1.13      casties   680: 
                    681:     def mark8(self):
                    682:         """mark image"""
1.18      casties   683:         return sendFile(self, 'images/mark8.gif', 'image/gif')
1.13      casties   684: 
                    685:     def corner1(self):
                    686:         """mark image"""
1.18      casties   687:         return sendFile(self, 'images/olinks.gif', 'image/gif')
1.13      casties   688: 
                    689:     def corner2(self):
                    690:         """mark image"""
1.18      casties   691:         return sendFile(self, 'images/orechts.gif', 'image/gif')
1.13      casties   692: 
                    693:     def corner3(self):
                    694:         """mark image"""
1.18      casties   695:         return sendFile(self, 'images/ulinks.gif', 'image/gif')
1.13      casties   696: 
                    697:     def corner4(self):
                    698:         """mark image"""
1.18      casties   699:         return sendFile(self, 'images/urechts.gif', 'image/gif')
1.13      casties   700: 
1.22      casties   701:     def up_img(self):
                    702:         """mark image"""
                    703:         return sendFile(self, 'images/up.gif', 'image/gif')
                    704: 
                    705:     def down_img(self):
                    706:         """mark image"""
                    707:         return sendFile(self, 'images/down.gif', 'image/gif')
                    708: 
                    709:     def left_img(self):
                    710:         """mark image"""
                    711:         return sendFile(self, 'images/left.gif', 'image/gif')
                    712: 
                    713:     def right_img(self):
                    714:         """mark image"""
                    715:         return sendFile(self, 'images/right.gif', 'image/gif')
1.13      casties   716: 
                    717: 
1.1       dwinter   718:             
                    719:     def index_html(self):
                    720:         """main action"""
1.26      casties   721:    self.checkQuery()
                    722:    bt = self.REQUEST.SESSION['browserType']
1.18      casties   723:         tp = "zogiLibMainTemplate"
1.32      dwinter   724:         
1.18      casties   725:         if hasattr(self, tp):
                    726:        pt = getattr(self, tp)
                    727:         else:
1.26      casties   728:             tpt = self.layout
1.32      dwinter   729:             
1.26      casties   730:             if bt['staticHTML']:
                    731:                 tpt = "static"
                    732:                 
                    733:             pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/zogiLibMain_%s'%tpt)).__of__(self)
                    734:             
1.18      casties   735:         return pt()
                    736: 
1.1       dwinter   737: 
1.21      casties   738:     def storeQuery(self, more = None):
1.1       dwinter   739:         """storeQuery in session"""
1.18      casties   740:         dlParams = {}
1.1       dwinter   741:         for fm in self.REQUEST.form.keys():
1.18      casties   742:             dlParams[fm] = self.REQUEST.form[fm]
1.21      casties   743:         # look for more
                    744:         if more:
                    745:             for fm in more.split('&'):
                    746:                 try:
                    747:                     pv = fm.split('=')
                    748:                     dlParams[pv[0]] = pv[1]
                    749:                 except:
1.26      casties   750:                     pass
                    751:                 
1.21      casties   752:         # parse digilib mode parameter
1.18      casties   753:         if 'mo' in dlParams:
                    754:             if len(dlParams['mo']) > 0:
                    755:                 modes=dlParams['mo'].split(',')
                    756:         else:
                    757:             modes=[]
1.44      casties   758:             
                    759:         wid = self.getWID()
                    760:         self.REQUEST.set('wid', wid)
                    761:         self.setSubSession('dlQuery', dlParams)
                    762:         self.setSubSession('dlModes', modes)
                    763:         self.setSubSession('dlInfo', self.getDLInfo())
1.26      casties   764:         if not self.REQUEST.SESSION.has_key('browserType'):
                    765:             self.REQUEST.SESSION['browserType'] = browserCheck(self)
                    766:             
                    767:         return
1.1       dwinter   768: 
1.20      casties   769:     def checkQuery(self):
                    770:    """check if the query has been stored"""
1.44      casties   771:    if not (self.REQUEST.SESSION and self.getSubSession('dlQuery')) :
1.20      casties   772:        print "ZOGILIB: have to store query!!"
1.26      casties   773:        self.storeQuery()
1.24      casties   774:         return
1.23      casties   775: 
1.24      casties   776:     def zogilibPath(self, otherbase=None):
1.23      casties   777:         """returns an URL to the zogiLib instance"""
                    778:         url = self.REQUEST['URL1']
1.24      casties   779:         # should end with "/"
                    780:         if len(url) > 0 and url[-1] != '/':
                    781:             url += '/'
                    782:         if type(otherbase) is str:
                    783:             url += otherbase
                    784:         else:
                    785:             url += self.basePath
1.23      casties   786:         # should end with "/"
                    787:         if len(url) > 0 and url[-1] != '/':
                    788:             url += '/'
                    789:         return url
1.44      casties   790: 
                    791:     def zogilibAction(self, action, otherbase=None, wid=None):
                    792:         """returns a URL with zogilib path, action and wid"""
                    793:         url = self.zogilibPath(otherbase)
                    794:         url += action
                    795:         if wid:
                    796:             url += '?wid=' + wid
                    797:         else:
                    798:             url += '?wid=' + self.getWID()
                    799:         return url
                    800: 
                    801:     def getSubSession(self, key, default=None):
                    802:         """returns an element from a session with a wid"""
                    803:         wid = self.getWID()
                    804:         return self.REQUEST.SESSION.get(key+'_'+wid, default)
                    805: 
                    806:     def setSubSession(self, key, value):
                    807:         """puts an element in a session with a wid"""
                    808:         wid = self.getWID()
                    809:         self.REQUEST.SESSION.set(key+'_'+wid, value)
                    810:         return
                    811: 
                    812:     def getWID(self):
                    813:         """returns a (new) window id"""
                    814:         wid = self.REQUEST.get('wid')
                    815:         if not wid:
                    816:             wid = 'digi_'+str(int(random.random()*10000))
                    817:             print "new WID:", wid
                    818:         return wid
1.3       dwinter   819:         
1.22      casties   820:     def getDLParam(self, param):
1.18      casties   821:         """returns parameter"""
1.3       dwinter   822:         try:
1.44      casties   823:             return self.getSubSession('dlQuery').get(param)
1.3       dwinter   824:         except:
1.24      casties   825:             return
1.3       dwinter   826: 
1.18      casties   827:     def setDLParam(self, param, value):
                    828:         """sets parameter"""
1.44      casties   829:         dlParams = self.getSubSession('dlQuery')
                    830:         #try:
                    831:         dlParams[param] = value
                    832:         #except:
                    833:         #    self.setSubSession('dlQuery', {param: value})
1.18      casties   834:         return
                    835: 
                    836:     def getAllDLParams(self):
                    837:         """parameter string for digilib"""
1.44      casties   838:         dlParams = self.getSubSession('dlQuery')
1.18      casties   839:         # save modes
1.44      casties   840:         modes = self.getSubSession('dlModes')
1.18      casties   841:         dlParams['mo'] = string.join(modes, ',')
                    842:         # assemble query string
                    843:         ret = ""
                    844:         for param in dlParams.keys():
1.29      casties   845:             if dlParams[param] is None: continue
1.18      casties   846:             val = str(dlParams[param])
                    847:             if val != "":
                    848:                 ret += param + "=" + val + "&"
1.28      casties   849: 
1.18      casties   850:         # omit trailing "&"
                    851:         return ret.rstrip('&')
                    852: 
                    853:         
                    854:     def setDLParams(self,pn=None,ws=None,rot=None,brgt=None,cont=None):
                    855:         """setze Parameter"""
                    856: 
1.23      casties   857:         self.setDLParam('brgt', brgt)
                    858:         self.setDLParam('cont', cont)
                    859:         self.setDLParam('ws', ws)
                    860:         self.setDLParam('rot', rot)
1.18      casties   861: 
                    862:         if pn:
1.21      casties   863:             # unmark
                    864:             self.setDLParam('mk', None)
1.18      casties   865:             self.setDLParam('pn', pn)
                    866:             
                    867:         return self.display()
                    868: 
                    869: 
                    870:     def display(self):
                    871:         """(re)display page"""
1.44      casties   872:         if not self.getDLParam('wid'):
                    873:             wid = self.getWID()
                    874:             self.setDLParam('wid', wid)
                    875:             
1.18      casties   876:         params = self.getAllDLParams()
1.44      casties   877:             
1.21      casties   878:         if self.basePath:
                    879:             self.REQUEST.RESPONSE.redirect(self.REQUEST['URL2']+'?'+params)
                    880:         else:
                    881:             self.REQUEST.RESPONSE.redirect(self.REQUEST['URL1']+'?'+params)
1.18      casties   882: 
1.32      dwinter   883:     def getMetaFileName(self):
1.34      casties   884:         url=self.dlServerURL+'/dlContext-xml.jsp?'+self.getAllDLParams()
                    885:         return urlbase
1.26      casties   886: 
1.34      casties   887:     def getToolbarPageURL(self):
                    888:         """returns a toolbar-enabled page URL"""
1.37      casties   889:         url=self.dlToolbarBaseURL+self.getAllDLParams()
1.34      casties   890:         return url
1.32      dwinter   891:     
1.30      casties   892:     def getDLTarget(self):
                    893:         """returns dlTarget"""
                    894:         self.checkQuery()
                    895:         s = self.dlTarget
1.44      casties   896:         if s == None:
                    897:             s = ""
1.30      casties   898: #         s = 'dl'
                    899: #         if self.getDLParam('fn'):
                    900: #             s += "_" + self.getDLParam('fn')
                    901: #         if self.getDLParam('pn'):
                    902: #             s += "_" + self.getDLParam('pn')
                    903:         return s
                    904: 
1.26      casties   905:     def setStaticHTML(self, static=True):
                    906:         """sets the preference to static HTML"""
                    907:         self.checkQuery()
                    908:    self.REQUEST.SESSION['browserType']['staticHTML'] = static
                    909:         return
                    910: 
                    911:     def isStaticHTML(self):
                    912:         """returns if the page is using static HTML only"""
                    913:         self.checkQuery()
                    914:    return self.REQUEST.SESSION['browserType']['staticHTML']
                    915: 
1.18      casties   916:     def getPT(self):
                    917:         """pagenums"""
1.44      casties   918:         di = self.getSubSession('dlInfo_')
1.18      casties   919:         if di:
                    920:             return int(di['pt'])
                    921:         else:
                    922:             return 1
                    923:     
                    924:     def getPN(self):
                    925:         """Pagenum"""
                    926:         pn = self.getDLParam('pn')
1.25      casties   927:         try:
1.18      casties   928:             return int(pn)
1.25      casties   929:         except:
1.3       dwinter   930:             return 1
                    931: 
1.18      casties   932:     def getBiggerWS(self):
1.3       dwinter   933:         """ws+1"""
1.23      casties   934:         ws = self.getDLParam('ws')
1.25      casties   935:         try:
1.26      casties   936:             return float(ws)+0.5
1.25      casties   937:         except:
1.26      casties   938:             return 1.5
1.3       dwinter   939:         
1.18      casties   940:     def getSmallerWS(self):
                    941:         """ws-1"""
                    942:         ws=self.getDLParam('ws')
1.25      casties   943:         try:
1.26      casties   944:             return max(float(ws)-0.5, 1)
1.25      casties   945:         except:
1.3       dwinter   946:             return 1
1.1       dwinter   947: 
1.18      casties   948:     def hasMode(self, mode):
                    949:         """returns if mode is in the diglib mo parameter"""
1.44      casties   950:         wid = self.getWID()
                    951:         return (mode in self.REQUEST.SESSION['dlModes_'+wid])
1.18      casties   952: 
                    953:     def hasNextPage(self):
                    954:         """returns if there is a next page"""
                    955:         pn = self.getPN()
                    956:         pt = self.getPT()
                    957:         return (pn < pt)
                    958:    
                    959:     def hasPrevPage(self):
                    960:         """returns if there is a previous page"""
                    961:         pn = self.getPN()
                    962:         return (pn > 1)
1.1       dwinter   963: 
1.22      casties   964:     def canMoveLeft(self):
                    965:         """returns if its possible to move left"""
                    966:         wx = float(self.getDLParam('wx') or 0)
                    967:         return (wx > 0)
                    968: 
                    969:     def canMoveRight(self):
                    970:         """returns if its possible to move right"""
                    971:         wx = float(self.getDLParam('wx') or 0)
                    972:         ww = float(self.getDLParam('ww') or 1)
                    973:         return (wx + ww < 1)
                    974: 
                    975:     def canMoveUp(self):
                    976:         """returns if its possible to move up"""
                    977:         wy = float(self.getDLParam('wy') or 0)
                    978:         return (wy > 0)
                    979: 
                    980:     def canMoveDown(self):
                    981:         """returns if its possible to move down"""
                    982:         wy = float(self.getDLParam('wy') or 0)
                    983:         wh = float(self.getDLParam('wh') or 1)
                    984:         return (wy + wh < 1)
                    985: 
1.26      casties   986: 
                    987:     def dl_StaticHTML(self):
                    988:         """set rendering to static HTML"""
                    989:         self.checkQuery()
                    990:         self.REQUEST.SESSION['browserType']['staticHTML'] = True
                    991:         return self.display()
                    992: 
                    993:     def dl_DynamicHTML(self):
                    994:         """set rendering to dynamic HTML"""
                    995:         self.checkQuery()
                    996:         self.REQUEST.SESSION['browserType']['staticHTML'] = False
                    997:         return self.display()
1.1       dwinter   998:         
1.18      casties   999:     def dl_HMirror(self):
                   1000:         """mirror action"""
1.44      casties  1001:         modes = self.getSubSession('dlModes')
1.18      casties  1002:         if 'hmir' in modes:
                   1003:             modes.remove('hmir')
                   1004:         else:
                   1005:             modes.append('hmir')
1.1       dwinter  1006: 
1.18      casties  1007:         return self.display()
                   1008:        
                   1009:     def dl_VMirror(self):
                   1010:         """mirror action"""
1.44      casties  1011:         modes = self.getSubSession('dlModes')
1.18      casties  1012:         if 'vmir' in modes:
                   1013:             modes.remove('vmir')
                   1014:         else:
                   1015:             modes.append('vmir')
1.1       dwinter  1016: 
1.18      casties  1017:         return self.display()
1.1       dwinter  1018: 
1.22      casties  1019:     def dl_Zoom(self, z):
                   1020:         """general zoom action"""
                   1021:         ww1 = float(self.getDLParam('ww') or 1)
                   1022:         wh1 = float(self.getDLParam('wh') or 1)
                   1023:         wx = float(self.getDLParam('wx') or 0)
                   1024:         wy = float(self.getDLParam('wy') or 0)
                   1025:         ww2 = ww1 * z
                   1026:         wh2 = wh1 * z
                   1027:         wx += (ww1 - ww2) / 2
                   1028:         wy += (wh1 - wh2) / 2
                   1029:         ww2 = max(min(ww2, 1), 0)
                   1030:         wh2 = max(min(wh2, 1), 0)
                   1031:         wx = max(min(wx, 1), 0)
                   1032:         wy = max(min(wy, 1), 0)
1.30      casties  1033:         self.setDLParam('ww', cropf(ww2))
                   1034:         self.setDLParam('wh', cropf(wh2))
                   1035:         self.setDLParam('wx', cropf(wx))
                   1036:         self.setDLParam('wy', cropf(wy))
1.22      casties  1037:         return self.display()
                   1038:         
                   1039:     def dl_ZoomIn(self):
                   1040:         """zoom in action"""
                   1041:         z = 0.7071
                   1042:         return self.dl_Zoom(z)
                   1043: 
                   1044:     def dl_ZoomOut(self):
                   1045:         """zoom out action"""
                   1046:         z = 1.4142
                   1047:         return self.dl_Zoom(z)
                   1048: 
                   1049:     def dl_Move(self, dx, dy):
                   1050:         """general move action"""
                   1051:         ww = float(self.getDLParam('ww') or 1)
                   1052:         wh = float(self.getDLParam('wh') or 1)
                   1053:         wx = float(self.getDLParam('wx') or 0)
                   1054:         wy = float(self.getDLParam('wy') or 0)
                   1055:         wx += dx * 0.5 * ww
                   1056:         wy += dy * 0.5 * wh
                   1057:         wx = max(min(wx, 1), 0)
                   1058:         wy = max(min(wy, 1), 0)
1.30      casties  1059:         self.setDLParam('wx', cropf(wx))
                   1060:         self.setDLParam('wy', cropf(wy))
1.22      casties  1061:         return self.display()
                   1062:         
                   1063:     def dl_MoveLeft(self):
                   1064:         """move left action"""
                   1065:         return self.dl_Move(-1, 0)
                   1066:     
                   1067:     def dl_MoveRight(self):
                   1068:         """move left action"""
                   1069:         return self.dl_Move(1, 0)
                   1070:     
                   1071:     def dl_MoveUp(self):
                   1072:         """move left action"""
                   1073:         return self.dl_Move(0, -1)
                   1074:     
                   1075:     def dl_MoveDown(self):
                   1076:         """move left action"""
                   1077:         return self.dl_Move(0, 1)
                   1078:     
1.18      casties  1079:     def dl_WholePage(self):
                   1080:         """zoom out action"""
                   1081:         self.setDLParam('ww', 1)
                   1082:         self.setDLParam('wh', 1)
                   1083:         self.setDLParam('wx', 0)
                   1084:         self.setDLParam('wy', 0)
                   1085:         return self.display()
                   1086:         
                   1087:     def dl_PrevPage(self):
                   1088:         """next page action"""
                   1089:         pn = self.getPN() - 1
                   1090:         if pn < 1:
                   1091:             pn = 1
                   1092:         self.setDLParam('pn', pn)
                   1093:         # unmark
                   1094:         self.setDLParam('mk', None)
                   1095:         return self.display()
                   1096:         
                   1097:     def dl_NextPage(self):
                   1098:         """next page action"""
                   1099:         pn = self.getPN() + 1
                   1100:         pt = self.getPT()
                   1101:         if pn > pt:
                   1102:             pn = pt
                   1103:         self.setDLParam('pn', pn)
                   1104:         # unmark
                   1105:         self.setDLParam('mk', None)
                   1106:         return self.display()
                   1107: 
                   1108:     def dl_FirstPage(self):
                   1109:         """first page action"""
                   1110:         self.setDLParam('pn', 1)
                   1111:         # unmark
                   1112:         self.setDLParam('mk', None)
                   1113:         return self.display()
                   1114:     
                   1115:     def dl_LastPage(self):
                   1116:         """last page action"""
                   1117:         self.setDLParam('pn', self.getPT())
                   1118:         # unmark
                   1119:         self.setDLParam('mk', None)
                   1120:         return self.display()
                   1121: 
                   1122:     def dl_Unmark(self):
                   1123:         """action to remove last mark"""
                   1124:         mk = self.getDLParam('mk')
                   1125:         if mk:
                   1126:             marks = mk.split(',')
                   1127:             marks.pop()
                   1128:             mk = string.join(marks, ',')
                   1129:             self.setDLParam('mk', mk)
                   1130:         return self.display()
1.1       dwinter  1131: 
1.32      dwinter  1132:     def dl_db(self,db):
                   1133:         """set db"""
                   1134:         self.setDLParam('db',db)
                   1135:         self.display()
1.1       dwinter  1136: 
1.18      casties  1137:     def changeZogiLibForm(self):
                   1138:         """Main configuration"""
                   1139:         pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/changeZogiLibForm.zpt')).__of__(self)
                   1140:         return pt()
1.1       dwinter  1141:     
1.37      casties  1142:     def changeZogiLib(self,title,dlServerURL, version, basePath, dlTarget, dlToolbarBaseURL, RESPONSE=None):
1.18      casties  1143:         """change it"""
                   1144:         self.title=title
1.35      casties  1145:         self.dlServerURL=dlServerURL
1.21      casties  1146:         self.basePath = basePath
1.18      casties  1147:         self.layout=version
1.44      casties  1148:         self.dlTarget = dlTarget
1.3       dwinter  1149: 
1.37      casties  1150:         if dlToolbarBaseURL:
                   1151:             self.dlToolbarBaseURL = dlToolbarBaseURL
                   1152:         else:
                   1153:             self.dlToolbarBaseURL = dlServerURL + "/digimage.jsp?"
                   1154: 
1.18      casties  1155:         if RESPONSE is not None:
                   1156:             RESPONSE.redirect('manage_main')
1.8       dwinter  1157: 
1.35      casties  1158: 
                   1159: 
                   1160:     ##
1.44      casties  1161:     ## odds and ends
1.35      casties  1162:     ##
                   1163: 
                   1164:     def repairZogilib(self, obj=None):
                   1165:         """change stuff that broke on upgrading"""
                   1166: 
                   1167:         msg = ""
                   1168: 
                   1169:         if not obj:
                   1170:             obj = self.getPhysicalRoot()
                   1171: 
                   1172:         print "starting in ", obj
                   1173:         
                   1174:         entries=obj.ZopeFind(obj,obj_metatypes=['zogiLib'],search_sub=1)
                   1175: 
                   1176:         for entry in entries:
                   1177:             print "  found ", entry
1.37      casties  1178:             #
                   1179:             # replace digilibBaseUrl by dlServerURL
1.35      casties  1180:             if hasattr(entry[1], 'digilibBaseUrl'):
1.37      casties  1181:                 msg += "  fixing digilibBaseUrl in "+entry[0]+"\n"
1.36      casties  1182:                 entry[1].dlServerURL = re.sub('/servlet/Scaler\?','',entry[1].digilibBaseUrl)
1.35      casties  1183:                 del entry[1].digilibBaseUrl
                   1184:                 
1.37      casties  1185:             #
                   1186:             # add dlToolbarBaseURL
                   1187:             if not hasattr(entry[1], 'dlToolbarBaseURL'):
                   1188:                 msg += "  fixing dlToolbarBaseURL in "+entry[0]+"\n"
                   1189:                 entry[1].dlToolbarBaseURL = entry[1].dlServerURL + "/digimage.jsp?"
                   1190:                 
1.35      casties  1191:         return msg+"\n\nfixed all zogilib instances in: "+obj.title
                   1192: 
1.8       dwinter  1193:           
1.1       dwinter  1194: def manage_addZogiLibForm(self):
                   1195:     """interface for adding zogilib"""
1.18      casties  1196:     pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/addZogiLibForm')).__of__(self)
1.1       dwinter  1197:     return pt()
                   1198: 
1.44      casties  1199: def manage_addZogiLib(self,id,title,dlServerURL,version="book",basePath="",dlTarget=None,dlToolbarBaseURL=None,RESPONSE=None):
1.1       dwinter  1200:     """add dgilib"""
1.43      casties  1201:     newObj=zogiLib(id,title,dlServerURL, version, basePath, dlTarget, dlToolbarBaseURL)
1.1       dwinter  1202:     self.Destination()._setObject(id,newObj)
                   1203:     if RESPONSE is not None:
                   1204:         RESPONSE.redirect('manage_main')
1.29      casties  1205: 
                   1206: 
                   1207: class zogiLibPageTemplate(ZopePageTemplate):
                   1208:     """pageTemplate Objekt"""
                   1209:     meta_type="zogiLib_pageTemplate"
                   1210: 
                   1211: 
                   1212: ## def __init__(self, id, text=None, contentType=None):
                   1213: ##         self.id = str(id)
                   1214: ##         self.ZBindings_edit(self._default_bindings)
                   1215: ##         if text is None:
                   1216: ##             text = open(self._default_cont).read()
                   1217: ##         self.pt_edit(text, contentType)
                   1218: 
                   1219: def manage_addZogiLibPageTemplateForm(self):
                   1220:     """Form for adding"""
                   1221:     pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/addZogiLibPageTemplateForm')).__of__(self)
                   1222:     return pt()
                   1223: 
                   1224: def manage_addZogiLibPageTemplate(self, id='zogiLibMainTemplate', title=None, layout=None, text=None,
                   1225:                            REQUEST=None, submit=None):
                   1226:     "Add a Page Template with optional file content."
                   1227: 
                   1228:     id = str(id)
                   1229:     self._setObject(id, zogiLibPageTemplate(id))
                   1230:     ob = getattr(self, id)
                   1231:     if not layout: layout = "book"
                   1232:     ob.pt_edit(open(os.path.join(package_home(globals()),'zpt/zogiLibMain_%s.zpt'%layout)).read(),None)
                   1233:     if title:
                   1234:         ob.pt_setTitle(title)
                   1235:     try:
                   1236:         u = self.DestinationURL()
                   1237:     except AttributeError:
                   1238:         u = REQUEST['URL1']
                   1239:         
                   1240:     u = "%s/%s" % (u, urllib.quote(id))
                   1241:     REQUEST.RESPONSE.redirect(u+'/manage_main')
                   1242:     return ''
1.35      casties  1243: 

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