Annotation of zogiLib/zogiLib.py, revision 1.48

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

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