Annotation of zogiLib/zogiLib.py, revision 1.37

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.34      casties    17: ZOGIVERSION = "0.9.7 ROC:21.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: 
                    457:     def formatHTML(self,url,label=None,viewUrl=None):
                    458: 
                    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
                    477:     
                    478:     def getMetaData(self):
                    479:         """getMetaData"""
1.33      dwinter   480:         try:
                    481:             dom=xml.dom.minidom.parse(urllib.urlopen(self.getMetaFileName()))
                    482:         except:
                    483:             return "error metadata"
                    484:         
1.32      dwinter   485:         contexts=dom.getElementsByTagName("context")
                    486:         ret=[]
                    487:         db=self.getDLParam("db")
                    488:         ob=self.getDLParam("object")
                    489:         
                    490:         fn=self.getDLParam("fn")
                    491:         pn=self.getDLParam("pn")
                    492:         if not fn:
                    493:             fn=""
                    494:         if not pn:
                    495:             pn=""
                    496:         if not ob:
                    497:             ob=""
                    498:             
                    499:         for context in contexts:
                    500:             metaDataLinks=context.getElementsByTagName("meta-datalink")
                    501:             for metaDataLink in metaDataLinks:
                    502:                  
                    503:                 if (db==metaDataLink.getAttribute("db")) or (len(metaDataLinks)==1):
                    504:                     
                    505:                     link=getUniqueElementText(metaDataLink.getElementsByTagName("metadata-url"))
                    506:                     label=getUniqueElementText(metaDataLink.getElementsByTagName("label"))
                    507:                     url=getUniqueElementText(metaDataLink.getElementsByTagName("url"))
                    508: 
                    509:                     return self.formatHTML(link,label,url)
                    510: 
                    511:             metaDataLinks=context.getElementsByTagName("meta-baselink")
                    512:              
                    513:             for metaDataLink in metaDataLinks:
                    514:                 
                    515:                 if db==metaDataLink.getAttribute("db") or (len(metaDataLinks)==1):
                    516:                     
                    517:                     link=getUniqueElementText(metaDataLink.getElementsByTagName("metadata-url"))
                    518:                     label=getUniqueElementText(metaDataLink.getElementsByTagName("label"))
                    519:                     url=getUniqueElementText(metaDataLink.getElementsByTagName("url"))
                    520: 
                    521:                     return self.formatHTML(link+'fn=%s&pn=%s&object=%s'%(fn,pn,ob),label,url)
                    522:         return ret
                    523: 
1.18      casties   524:     def getDLInfo(self):
                    525:         """get DLInfo from digilib server"""
                    526:         paramH={}
1.34      casties   527:         baseUrl=self.dlServerURL+"/dlInfo-xml.jsp"
1.18      casties   528:         try:
                    529:             url=urllib.urlopen(baseUrl+self.REQUEST['QUERY_STRING'])
                    530:             dom=xml.dom.minidom.parse(url)
                    531:             params=dom.getElementsByTagName('parameter')
                    532:             for param in params:
                    533:                 paramH[param.getAttribute('name')]=param.getAttribute('value')
                    534:             return paramH
                    535:         except:
1.34      casties   536:             return {}
1.18      casties   537: 
1.1       dwinter   538: 
1.18      casties   539:     def createHeadJS(self):
1.19      casties   540:         """generate all javascript tags for head"""
1.26      casties   541:    self.checkQuery()
                    542:    bt = self.REQUEST.SESSION['browserType']
                    543:         if bt['staticHTML']:
                    544:             return
                    545:         
1.18      casties   546:         pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/zogilib_head_js')).__of__(self)
                    547:         return pt()
1.19      casties   548: 
                    549:     def createParamJS(self):
                    550:         """generate javascript for parameters only"""
1.26      casties   551:    self.checkQuery()
                    552:    bt = self.REQUEST.SESSION['browserType']
                    553:         if bt['staticHTML']:
                    554:             return
                    555: 
1.19      casties   556:         pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/zogilib_param_js')).__of__(self)
                    557:         return pt()
                    558:         
1.3       dwinter   559:                         
1.26      casties   560:     def createScalerImg(self, requestString=None, bottom=0, side=0, width=500, height=500):
1.18      casties   561:         """generate Scaler IMG Tag"""
1.20      casties   562:    self.checkQuery()
                    563:    bt = self.REQUEST.SESSION['browserType']
1.24      casties   564:         # override with parameters from session
                    565:         if  self.REQUEST.SESSION.has_key('scalerDiv'):
1.26      casties   566:             (requestString, bottom, side, width, height) = self.REQUEST.SESSION['scalerDiv']
1.24      casties   567:         # if not explicitly defined take normal request
1.18      casties   568:         if not requestString:
1.21      casties   569:             requestString = self.getAllDLParams()
1.35      casties   570:         url = self.dlServerURL+'/servlet/Scaler?'+requestString
1.24      casties   571:         # construct bottom and side insets
                    572:         b_par = ""
                    573:         s_par = ""
                    574:         if (bottom != 0) or (side != 0):
                    575:             b_par = "-" + str(int(bottom))
                    576:             s_par = "-" + str(int(side))
1.18      casties   577:         tag = ""
1.26      casties   578:         if bt['staticHTML']:
                    579:             tag += '<div id="scaler"><img id="pic" src="%s&dw=%i&dh=%i" /></div>'%(url, int(width-side), int(height-bottom))
1.18      casties   580:         else:
1.26      casties   581:             if bt['isN4']:
                    582:                 # N4 needs layers
                    583:                 tag += '<ilayer id="scaler">'
                    584:             else:
                    585:                 tag += '<div id="scaler">'
                    586:             tag += '<script type="text/javascript">'
                    587:             tag += "var ps = bestPicSize(getElement('scaler'));"
                    588:             # write img tag with javascript
                    589:             tag += 'document.write(\'<img id="pic" src="%s&dw=\'+(ps.width%s)+\'&dh=\'+(ps.height%s)+\'" />\');'%(url, s_par, b_par)
                    590:             tag += '</script>'
                    591:             if bt['isN4']:
                    592:                 tag += '</ilayer>'
                    593:             else:
                    594:                 tag += '</div>'
1.18      casties   595:         return tag
1.1       dwinter   596: 
1.26      casties   597:     def createScalerDiv(self, requestString = None, bottom = 0, side = 0, width=500, height=500):
1.23      casties   598:         """generate scaler img and table with navigation arrows"""
                    599:    self.checkQuery()
1.24      casties   600:         if requestString != None or bottom != 0 or side != 0:
1.26      casties   601:             self.REQUEST.SESSION['scalerDiv'] = (requestString, bottom, side, width, height)
1.24      casties   602:         else:
                    603:             if self.REQUEST.SESSION.has_key('scalerDiv'):
1.26      casties   604:                 # make shure to remove unused parameter
1.24      casties   605:                 del self.REQUEST.SESSION['scalerDiv']
1.26      casties   606:                 
1.23      casties   607:         pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt/zogilib_img_div')).__of__(self)
                    608:         return pt()
                    609: 
1.18      casties   610:     def createAuxDiv(self):
                    611:         """generate other divs"""
1.20      casties   612:    self.checkQuery()
                    613:    bt = self.REQUEST.SESSION['browserType']
1.26      casties   614:         if bt['staticHTML']:
                    615:             return
                    616:         if bt['isN4']:
1.18      casties   617:             f = 'zpt/zogilib_divsN4.zpt'
                    618:         else:
                    619:             f = 'zpt/zogilib_divs.zpt'
                    620:         pt=PageTemplateFile(os.path.join(package_home(globals()),f)).__of__(self)
                    621:         return pt()
1.3       dwinter   622: 
1.9       dwinter   623: 
1.18      casties   624:     def option_js(self):
1.28      casties   625:         """javascript"""
                    626:         return sendFile(self, 'js/option.js', 'text/plain')
1.1       dwinter   627: 
1.18      casties   628:     def dl_lib_js(self):
                    629:         """javascript"""
1.34      casties   630:         return sendFile(self, 'js/dllib.js', 'text/plain')
1.18      casties   631: 
                    632:     def js_lib_js(self):
                    633:         """javascript"""
1.34      casties   634:         return sendFile(self, 'js/baselib.js', 'text/plain')
1.1       dwinter   635: 
1.18      casties   636:     def optionwindow(self):
                    637:         """showoptions"""
1.26      casties   638:    self.checkQuery()
1.35      casties   639:         if self.REQUEST.has_key('frametarget'):
                    640:             self.dlTarget = self.REQUEST['frametarget']
1.26      casties   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: 
                    738: 
1.21      casties   739:     def storeQuery(self, more = None):
1.1       dwinter   740:         """storeQuery in session"""
1.18      casties   741:         dlParams = {}
1.1       dwinter   742:         for fm in self.REQUEST.form.keys():
1.18      casties   743:             dlParams[fm] = self.REQUEST.form[fm]
1.21      casties   744:         # look for more
                    745:         if more:
                    746:             for fm in more.split('&'):
                    747:                 try:
                    748:                     pv = fm.split('=')
                    749:                     dlParams[pv[0]] = pv[1]
                    750:                 except:
1.26      casties   751:                     pass
                    752:                 
1.21      casties   753:         # parse digilib mode parameter
1.18      casties   754:         if 'mo' in dlParams:
                    755:             if len(dlParams['mo']) > 0:
                    756:                 modes=dlParams['mo'].split(',')
                    757:         else:
                    758:             modes=[]
                    759: 
                    760:         self.REQUEST.SESSION['query'] = dlParams
                    761:         self.REQUEST.SESSION['dlModes'] = modes
                    762:         self.REQUEST.SESSION['dlInfo'] = self.getDLInfo()
1.26      casties   763:         if not self.REQUEST.SESSION.has_key('browserType'):
                    764:             self.REQUEST.SESSION['browserType'] = browserCheck(self)
                    765:             
                    766:         return
1.1       dwinter   767: 
1.20      casties   768:     def checkQuery(self):
                    769:    """check if the query has been stored"""
1.26      casties   770:    if not (self.REQUEST.SESSION and self.REQUEST.SESSION.has_key('query')) :
1.20      casties   771:        print "ZOGILIB: have to store query!!"
1.26      casties   772:        self.storeQuery()
1.24      casties   773:         return
1.23      casties   774: 
1.24      casties   775:     def zogilibPath(self, otherbase=None):
1.23      casties   776:         """returns an URL to the zogiLib instance"""
                    777:         url = self.REQUEST['URL1']
1.24      casties   778:         # should end with "/"
                    779:         if len(url) > 0 and url[-1] != '/':
                    780:             url += '/'
                    781:         if type(otherbase) is str:
                    782:             url += otherbase
                    783:         else:
                    784:             url += self.basePath
1.23      casties   785:         # should end with "/"
                    786:         if len(url) > 0 and url[-1] != '/':
                    787:             url += '/'
                    788:         return url
1.3       dwinter   789:         
1.22      casties   790:     def getDLParam(self, param):
1.18      casties   791:         """returns parameter"""
1.3       dwinter   792:         try:
                    793:             return self.REQUEST.SESSION['query'][param]
                    794:         except:
1.24      casties   795:             return
1.3       dwinter   796: 
1.18      casties   797:     def setDLParam(self, param, value):
                    798:         """sets parameter"""
                    799:         self.REQUEST.SESSION['query'][param] = value
                    800:         return
                    801: 
                    802:     def getAllDLParams(self):
                    803:         """parameter string for digilib"""
                    804:         dlParams = self.REQUEST.SESSION['query']
                    805:         # save modes
                    806:         modes = self.REQUEST.SESSION['dlModes']
                    807:         dlParams['mo'] = string.join(modes, ',')
                    808:         # assemble query string
                    809:         ret = ""
                    810:         for param in dlParams.keys():
1.29      casties   811:             if dlParams[param] is None: continue
1.18      casties   812:             val = str(dlParams[param])
                    813:             if val != "":
                    814:                 ret += param + "=" + val + "&"
1.28      casties   815: 
1.18      casties   816:         # omit trailing "&"
                    817:         return ret.rstrip('&')
                    818: 
                    819:         
                    820:     def setDLParams(self,pn=None,ws=None,rot=None,brgt=None,cont=None):
                    821:         """setze Parameter"""
                    822: 
1.23      casties   823:         self.setDLParam('brgt', brgt)
                    824:         self.setDLParam('cont', cont)
                    825:         self.setDLParam('ws', ws)
                    826:         self.setDLParam('rot', rot)
1.18      casties   827: 
                    828:         if pn:
1.21      casties   829:             # unmark
                    830:             self.setDLParam('mk', None)
1.18      casties   831:             self.setDLParam('pn', pn)
                    832:             
                    833:         return self.display()
                    834: 
                    835: 
                    836:     def display(self):
                    837:         """(re)display page"""
                    838:         params = self.getAllDLParams()
1.21      casties   839:         if self.basePath:
                    840:             self.REQUEST.RESPONSE.redirect(self.REQUEST['URL2']+'?'+params)
                    841:         else:
                    842:             self.REQUEST.RESPONSE.redirect(self.REQUEST['URL1']+'?'+params)
1.18      casties   843: 
1.32      dwinter   844:     def getMetaFileName(self):
1.34      casties   845:         url=self.dlServerURL+'/dlContext-xml.jsp?'+self.getAllDLParams()
                    846:         return urlbase
1.26      casties   847: 
1.34      casties   848:     def getToolbarPageURL(self):
                    849:         """returns a toolbar-enabled page URL"""
1.37    ! casties   850:         url=self.dlToolbarBaseURL+self.getAllDLParams()
1.34      casties   851:         return url
1.32      dwinter   852:     
1.30      casties   853:     def getDLTarget(self):
                    854:         """returns dlTarget"""
                    855:         self.checkQuery()
                    856:         s = self.dlTarget
                    857: #         s = 'dl'
                    858: #         if self.getDLParam('fn'):
                    859: #             s += "_" + self.getDLParam('fn')
                    860: #         if self.getDLParam('pn'):
                    861: #             s += "_" + self.getDLParam('pn')
                    862:         return s
                    863: 
1.26      casties   864:     def setStaticHTML(self, static=True):
                    865:         """sets the preference to static HTML"""
                    866:         self.checkQuery()
                    867:    self.REQUEST.SESSION['browserType']['staticHTML'] = static
                    868:         return
                    869: 
                    870:     def isStaticHTML(self):
                    871:         """returns if the page is using static HTML only"""
                    872:         self.checkQuery()
                    873:    return self.REQUEST.SESSION['browserType']['staticHTML']
                    874: 
1.18      casties   875:     def getPT(self):
                    876:         """pagenums"""
                    877:         di = self.REQUEST.SESSION['dlInfo']
                    878:         if di:
                    879:             return int(di['pt'])
                    880:         else:
                    881:             return 1
                    882:     
                    883:     def getPN(self):
                    884:         """Pagenum"""
                    885:         pn = self.getDLParam('pn')
1.25      casties   886:         try:
1.18      casties   887:             return int(pn)
1.25      casties   888:         except:
1.3       dwinter   889:             return 1
                    890: 
1.18      casties   891:     def getBiggerWS(self):
1.3       dwinter   892:         """ws+1"""
1.23      casties   893:         ws = self.getDLParam('ws')
1.25      casties   894:         try:
1.26      casties   895:             return float(ws)+0.5
1.25      casties   896:         except:
1.26      casties   897:             return 1.5
1.3       dwinter   898:         
1.18      casties   899:     def getSmallerWS(self):
                    900:         """ws-1"""
                    901:         ws=self.getDLParam('ws')
1.25      casties   902:         try:
1.26      casties   903:             return max(float(ws)-0.5, 1)
1.25      casties   904:         except:
1.3       dwinter   905:             return 1
1.1       dwinter   906: 
1.18      casties   907:     def hasMode(self, mode):
                    908:         """returns if mode is in the diglib mo parameter"""
                    909:         return (mode in self.REQUEST.SESSION['dlModes'])
                    910: 
                    911:     def hasNextPage(self):
                    912:         """returns if there is a next page"""
                    913:         pn = self.getPN()
                    914:         pt = self.getPT()
                    915:         return (pn < pt)
                    916:    
                    917:     def hasPrevPage(self):
                    918:         """returns if there is a previous page"""
                    919:         pn = self.getPN()
                    920:         return (pn > 1)
1.1       dwinter   921: 
1.22      casties   922:     def canMoveLeft(self):
                    923:         """returns if its possible to move left"""
                    924:         wx = float(self.getDLParam('wx') or 0)
                    925:         return (wx > 0)
                    926: 
                    927:     def canMoveRight(self):
                    928:         """returns if its possible to move right"""
                    929:         wx = float(self.getDLParam('wx') or 0)
                    930:         ww = float(self.getDLParam('ww') or 1)
                    931:         return (wx + ww < 1)
                    932: 
                    933:     def canMoveUp(self):
                    934:         """returns if its possible to move up"""
                    935:         wy = float(self.getDLParam('wy') or 0)
                    936:         return (wy > 0)
                    937: 
                    938:     def canMoveDown(self):
                    939:         """returns if its possible to move down"""
                    940:         wy = float(self.getDLParam('wy') or 0)
                    941:         wh = float(self.getDLParam('wh') or 1)
                    942:         return (wy + wh < 1)
                    943: 
1.26      casties   944: 
                    945:     def dl_StaticHTML(self):
                    946:         """set rendering to static HTML"""
                    947:         self.checkQuery()
                    948:         self.REQUEST.SESSION['browserType']['staticHTML'] = True
                    949:         return self.display()
                    950: 
                    951:     def dl_DynamicHTML(self):
                    952:         """set rendering to dynamic HTML"""
                    953:         self.checkQuery()
                    954:         self.REQUEST.SESSION['browserType']['staticHTML'] = False
                    955:         return self.display()
1.1       dwinter   956:         
1.18      casties   957:     def dl_HMirror(self):
                    958:         """mirror action"""
                    959:         modes = self.REQUEST.SESSION['dlModes']
                    960:         if 'hmir' in modes:
                    961:             modes.remove('hmir')
                    962:         else:
                    963:             modes.append('hmir')
1.1       dwinter   964: 
1.18      casties   965:         return self.display()
                    966:        
                    967:     def dl_VMirror(self):
                    968:         """mirror action"""
                    969:         modes = self.REQUEST.SESSION['dlModes']
                    970:         if 'vmir' in modes:
                    971:             modes.remove('vmir')
                    972:         else:
                    973:             modes.append('vmir')
1.1       dwinter   974: 
1.18      casties   975:         return self.display()
1.1       dwinter   976: 
1.22      casties   977:     def dl_Zoom(self, z):
                    978:         """general zoom action"""
                    979:         ww1 = float(self.getDLParam('ww') or 1)
                    980:         wh1 = float(self.getDLParam('wh') or 1)
                    981:         wx = float(self.getDLParam('wx') or 0)
                    982:         wy = float(self.getDLParam('wy') or 0)
                    983:         ww2 = ww1 * z
                    984:         wh2 = wh1 * z
                    985:         wx += (ww1 - ww2) / 2
                    986:         wy += (wh1 - wh2) / 2
                    987:         ww2 = max(min(ww2, 1), 0)
                    988:         wh2 = max(min(wh2, 1), 0)
                    989:         wx = max(min(wx, 1), 0)
                    990:         wy = max(min(wy, 1), 0)
1.30      casties   991:         self.setDLParam('ww', cropf(ww2))
                    992:         self.setDLParam('wh', cropf(wh2))
                    993:         self.setDLParam('wx', cropf(wx))
                    994:         self.setDLParam('wy', cropf(wy))
1.22      casties   995:         return self.display()
                    996:         
                    997:     def dl_ZoomIn(self):
                    998:         """zoom in action"""
                    999:         z = 0.7071
                   1000:         return self.dl_Zoom(z)
                   1001: 
                   1002:     def dl_ZoomOut(self):
                   1003:         """zoom out action"""
                   1004:         z = 1.4142
                   1005:         return self.dl_Zoom(z)
                   1006: 
                   1007:     def dl_Move(self, dx, dy):
                   1008:         """general move action"""
                   1009:         ww = float(self.getDLParam('ww') or 1)
                   1010:         wh = float(self.getDLParam('wh') or 1)
                   1011:         wx = float(self.getDLParam('wx') or 0)
                   1012:         wy = float(self.getDLParam('wy') or 0)
                   1013:         wx += dx * 0.5 * ww
                   1014:         wy += dy * 0.5 * wh
                   1015:         wx = max(min(wx, 1), 0)
                   1016:         wy = max(min(wy, 1), 0)
1.30      casties  1017:         self.setDLParam('wx', cropf(wx))
                   1018:         self.setDLParam('wy', cropf(wy))
1.22      casties  1019:         return self.display()
                   1020:         
                   1021:     def dl_MoveLeft(self):
                   1022:         """move left action"""
                   1023:         return self.dl_Move(-1, 0)
                   1024:     
                   1025:     def dl_MoveRight(self):
                   1026:         """move left action"""
                   1027:         return self.dl_Move(1, 0)
                   1028:     
                   1029:     def dl_MoveUp(self):
                   1030:         """move left action"""
                   1031:         return self.dl_Move(0, -1)
                   1032:     
                   1033:     def dl_MoveDown(self):
                   1034:         """move left action"""
                   1035:         return self.dl_Move(0, 1)
                   1036:     
1.18      casties  1037:     def dl_WholePage(self):
                   1038:         """zoom out action"""
                   1039:         self.setDLParam('ww', 1)
                   1040:         self.setDLParam('wh', 1)
                   1041:         self.setDLParam('wx', 0)
                   1042:         self.setDLParam('wy', 0)
                   1043:         return self.display()
                   1044:         
                   1045:     def dl_PrevPage(self):
                   1046:         """next page action"""
                   1047:         pn = self.getPN() - 1
                   1048:         if pn < 1:
                   1049:             pn = 1
                   1050:         self.setDLParam('pn', pn)
                   1051:         # unmark
                   1052:         self.setDLParam('mk', None)
                   1053:         return self.display()
                   1054:         
                   1055:     def dl_NextPage(self):
                   1056:         """next page action"""
                   1057:         pn = self.getPN() + 1
                   1058:         pt = self.getPT()
                   1059:         if pn > pt:
                   1060:             pn = pt
                   1061:         self.setDLParam('pn', pn)
                   1062:         # unmark
                   1063:         self.setDLParam('mk', None)
                   1064:         return self.display()
                   1065: 
                   1066:     def dl_FirstPage(self):
                   1067:         """first page action"""
                   1068:         self.setDLParam('pn', 1)
                   1069:         # unmark
                   1070:         self.setDLParam('mk', None)
                   1071:         return self.display()
                   1072:     
                   1073:     def dl_LastPage(self):
                   1074:         """last page action"""
                   1075:         self.setDLParam('pn', self.getPT())
                   1076:         # unmark
                   1077:         self.setDLParam('mk', None)
                   1078:         return self.display()
                   1079: 
                   1080:     def dl_Unmark(self):
                   1081:         """action to remove last mark"""
                   1082:         mk = self.getDLParam('mk')
                   1083:         if mk:
                   1084:             marks = mk.split(',')
                   1085:             marks.pop()
                   1086:             mk = string.join(marks, ',')
                   1087:             self.setDLParam('mk', mk)
                   1088:         return self.display()
1.1       dwinter  1089: 
1.32      dwinter  1090:     def dl_db(self,db):
                   1091:         """set db"""
                   1092:         self.setDLParam('db',db)
                   1093:         self.display()
1.1       dwinter  1094: 
1.18      casties  1095:     def changeZogiLibForm(self):
                   1096:         """Main configuration"""
                   1097:         pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/changeZogiLibForm.zpt')).__of__(self)
                   1098:         return pt()
1.1       dwinter  1099:     
1.37    ! casties  1100:     def changeZogiLib(self,title,dlServerURL, version, basePath, dlTarget, dlToolbarBaseURL, RESPONSE=None):
1.18      casties  1101:         """change it"""
                   1102:         self.title=title
1.35      casties  1103:         self.dlServerURL=dlServerURL
1.21      casties  1104:         self.basePath = basePath
1.18      casties  1105:         self.layout=version
1.27      casties  1106:         if dlTarget:
                   1107:             self.dlTarget = dlTarget
                   1108:         else:
                   1109:             self.dlTarget = "digilib"
1.3       dwinter  1110: 
1.37    ! casties  1111:         if dlToolbarBaseURL:
        !          1112:             self.dlToolbarBaseURL = dlToolbarBaseURL
        !          1113:         else:
        !          1114:             self.dlToolbarBaseURL = dlServerURL + "/digimage.jsp?"
        !          1115: 
1.18      casties  1116:         if RESPONSE is not None:
                   1117:             RESPONSE.redirect('manage_main')
1.8       dwinter  1118: 
1.35      casties  1119: 
                   1120: 
                   1121:     ##
                   1122:     ## odd stuff
                   1123:     ##
                   1124: 
                   1125:     def repairZogilib(self, obj=None):
                   1126:         """change stuff that broke on upgrading"""
                   1127: 
                   1128:         msg = ""
                   1129: 
                   1130:         if not obj:
                   1131:             obj = self.getPhysicalRoot()
                   1132: 
                   1133:         print "starting in ", obj
                   1134:         
                   1135:         entries=obj.ZopeFind(obj,obj_metatypes=['zogiLib'],search_sub=1)
                   1136: 
                   1137:         for entry in entries:
                   1138:             print "  found ", entry
1.37    ! casties  1139:             #
        !          1140:             # replace digilibBaseUrl by dlServerURL
1.35      casties  1141:             if hasattr(entry[1], 'digilibBaseUrl'):
1.37    ! casties  1142:                 msg += "  fixing digilibBaseUrl in "+entry[0]+"\n"
1.36      casties  1143:                 entry[1].dlServerURL = re.sub('/servlet/Scaler\?','',entry[1].digilibBaseUrl)
1.35      casties  1144:                 del entry[1].digilibBaseUrl
                   1145:                 
1.37    ! casties  1146:             #
        !          1147:             # add dlToolbarBaseURL
        !          1148:             if not hasattr(entry[1], 'dlToolbarBaseURL'):
        !          1149:                 msg += "  fixing dlToolbarBaseURL in "+entry[0]+"\n"
        !          1150:                 entry[1].dlToolbarBaseURL = entry[1].dlServerURL + "/digimage.jsp?"
        !          1151:                 
1.35      casties  1152:         return msg+"\n\nfixed all zogilib instances in: "+obj.title
                   1153: 
1.8       dwinter  1154:           
1.1       dwinter  1155: def manage_addZogiLibForm(self):
                   1156:     """interface for adding zogilib"""
1.18      casties  1157:     pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/addZogiLibForm')).__of__(self)
1.1       dwinter  1158:     return pt()
                   1159: 
1.37    ! casties  1160: def manage_addZogiLib(self,id,title,dlServerURL,layout="book",basePath="",dlTarget="digilib",dlToolbarBaseURL=None,RESPONSE=None):
1.1       dwinter  1161:     """add dgilib"""
1.37    ! casties  1162:     newObj=zogiLib(id,title,dlServerURL, localFileBase, version, basePath, dlTarget, dlToolbarBaseURL)
1.1       dwinter  1163:     self.Destination()._setObject(id,newObj)
                   1164:     if RESPONSE is not None:
                   1165:         RESPONSE.redirect('manage_main')
1.29      casties  1166: 
                   1167: 
                   1168: class zogiLibPageTemplate(ZopePageTemplate):
                   1169:     """pageTemplate Objekt"""
                   1170:     meta_type="zogiLib_pageTemplate"
                   1171: 
                   1172: 
                   1173: ## def __init__(self, id, text=None, contentType=None):
                   1174: ##         self.id = str(id)
                   1175: ##         self.ZBindings_edit(self._default_bindings)
                   1176: ##         if text is None:
                   1177: ##             text = open(self._default_cont).read()
                   1178: ##         self.pt_edit(text, contentType)
                   1179: 
                   1180: def manage_addZogiLibPageTemplateForm(self):
                   1181:     """Form for adding"""
                   1182:     pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/addZogiLibPageTemplateForm')).__of__(self)
                   1183:     return pt()
                   1184: 
                   1185: def manage_addZogiLibPageTemplate(self, id='zogiLibMainTemplate', title=None, layout=None, text=None,
                   1186:                            REQUEST=None, submit=None):
                   1187:     "Add a Page Template with optional file content."
                   1188: 
                   1189:     id = str(id)
                   1190:     self._setObject(id, zogiLibPageTemplate(id))
                   1191:     ob = getattr(self, id)
                   1192:     if not layout: layout = "book"
                   1193:     ob.pt_edit(open(os.path.join(package_home(globals()),'zpt/zogiLibMain_%s.zpt'%layout)).read(),None)
                   1194:     if title:
                   1195:         ob.pt_setTitle(title)
                   1196:     try:
                   1197:         u = self.DestinationURL()
                   1198:     except AttributeError:
                   1199:         u = REQUEST['URL1']
                   1200:         
                   1201:     u = "%s/%s" % (u, urllib.quote(id))
                   1202:     REQUEST.RESPONSE.redirect(u+'/manage_main')
                   1203:     return ''
1.35      casties  1204: 

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