Annotation of zogiLib/zogiLib.py, revision 1.35

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

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