Annotation of zogiLib/zogiLib.py, revision 1.39

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

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