Annotation of zogiLib/zogiLib.py, revision 1.33

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.30      casties    17: ZOGIVERSION = "0.9.5 ROC:25.6.2004"
                     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.32      dwinter   391:     def __init__(self, id, title, digilibBaseUrl,localFileBase, version="book", basePath="", dlTarget=None):
1.1       dwinter   392:         """init"""
                    393: 
                    394:         self.id=id
                    395:         self.title=title
1.2       dwinter   396:         self.digilibBaseUrl=digilibBaseUrl
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={}
                    523:         baseUrl=re.sub("servlet/Scaler","dlInfo-xml.jsp",self.digilibBaseUrl)
                    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:
                    532:             return null
                    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.18      casties   566:         url = self.digilibBaseUrl+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"""
                    626:         return sendFile(self, 'js/dl_lib.js', 'text/plain')
                    627: 
                    628:     def js_lib_js(self):
                    629:         """javascript"""
                    630:         return sendFile(self, 'js/js_lib.js', 'text/plain')
1.1       dwinter   631: 
1.18      casties   632:     def optionwindow(self):
                    633:         """showoptions"""
1.26      casties   634:    self.checkQuery()
                    635:    bt = self.REQUEST.SESSION['browserType']
                    636:         if bt['staticHTML']:
                    637:             pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/optionwindow_static.zpt')).__of__(self)
                    638:         else:
1.31      dwinter   639:        finds=self.ZopeFind(self,obj_ids=['viewingTools.zpt'])
                    640:        if finds:
                    641:                 
                    642:        return finds[0][1]()
                    643:        else:
                    644:                 pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/optionwindow.zpt')).__of__(self)
                    645:                 return pt()
1.13      casties   646: 
                    647:     def mark1(self):
                    648:         """mark image"""
1.18      casties   649:         return sendFile(self, 'images/mark1.gif', 'image/gif')
1.13      casties   650: 
                    651:     def mark2(self):
                    652:         """mark image"""
1.18      casties   653:         return sendFile(self, 'images/mark2.gif', 'image/gif')
1.13      casties   654: 
                    655:     def mark3(self):
                    656:         """mark image"""
1.18      casties   657:         return sendFile(self, 'images/mark3.gif', 'image/gif')
1.13      casties   658: 
                    659:     def mark4(self):
                    660:         """mark image"""
1.18      casties   661:         return sendFile(self, 'images/mark4.gif', 'image/gif')
1.13      casties   662: 
                    663:     def mark5(self):
                    664:         """mark image"""
1.18      casties   665:         return sendFile(self, 'images/mark5.gif', 'image/gif')
1.13      casties   666: 
                    667:     def mark6(self):
                    668:         """mark image"""
1.18      casties   669:         return sendFile(self, 'images/mark6.gif', 'image/gif')
1.13      casties   670: 
                    671:     def mark7(self):
                    672:         """mark image"""
1.18      casties   673:         return sendFile(self, 'images/mark7.gif', 'image/gif')
1.13      casties   674: 
                    675:     def mark8(self):
                    676:         """mark image"""
1.18      casties   677:         return sendFile(self, 'images/mark8.gif', 'image/gif')
1.13      casties   678: 
                    679:     def corner1(self):
                    680:         """mark image"""
1.18      casties   681:         return sendFile(self, 'images/olinks.gif', 'image/gif')
1.13      casties   682: 
                    683:     def corner2(self):
                    684:         """mark image"""
1.18      casties   685:         return sendFile(self, 'images/orechts.gif', 'image/gif')
1.13      casties   686: 
                    687:     def corner3(self):
                    688:         """mark image"""
1.18      casties   689:         return sendFile(self, 'images/ulinks.gif', 'image/gif')
1.13      casties   690: 
                    691:     def corner4(self):
                    692:         """mark image"""
1.18      casties   693:         return sendFile(self, 'images/urechts.gif', 'image/gif')
1.13      casties   694: 
1.22      casties   695:     def up_img(self):
                    696:         """mark image"""
                    697:         return sendFile(self, 'images/up.gif', 'image/gif')
                    698: 
                    699:     def down_img(self):
                    700:         """mark image"""
                    701:         return sendFile(self, 'images/down.gif', 'image/gif')
                    702: 
                    703:     def left_img(self):
                    704:         """mark image"""
                    705:         return sendFile(self, 'images/left.gif', 'image/gif')
                    706: 
                    707:     def right_img(self):
                    708:         """mark image"""
                    709:         return sendFile(self, 'images/right.gif', 'image/gif')
1.13      casties   710: 
                    711: 
1.1       dwinter   712:             
                    713:     def index_html(self):
                    714:         """main action"""
1.26      casties   715:    self.checkQuery()
                    716:    bt = self.REQUEST.SESSION['browserType']
1.18      casties   717:         tp = "zogiLibMainTemplate"
1.32      dwinter   718:         
1.18      casties   719:         if hasattr(self, tp):
                    720:        pt = getattr(self, tp)
                    721:         else:
1.26      casties   722:             tpt = self.layout
1.32      dwinter   723:             
1.26      casties   724:             if bt['staticHTML']:
                    725:                 tpt = "static"
                    726:                 
                    727:             pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/zogiLibMain_%s'%tpt)).__of__(self)
                    728:             
1.18      casties   729:         return pt()
                    730: 
1.1       dwinter   731: 
                    732: 
1.21      casties   733:     def storeQuery(self, more = None):
1.1       dwinter   734:         """storeQuery in session"""
1.18      casties   735:         dlParams = {}
1.1       dwinter   736:         for fm in self.REQUEST.form.keys():
1.18      casties   737:             dlParams[fm] = self.REQUEST.form[fm]
1.21      casties   738:         # look for more
                    739:         if more:
                    740:             for fm in more.split('&'):
                    741:                 try:
                    742:                     pv = fm.split('=')
                    743:                     dlParams[pv[0]] = pv[1]
                    744:                 except:
1.26      casties   745:                     pass
                    746:                 
1.21      casties   747:         # parse digilib mode parameter
1.18      casties   748:         if 'mo' in dlParams:
                    749:             if len(dlParams['mo']) > 0:
                    750:                 modes=dlParams['mo'].split(',')
                    751:         else:
                    752:             modes=[]
                    753: 
                    754:         self.REQUEST.SESSION['query'] = dlParams
                    755:         self.REQUEST.SESSION['dlModes'] = modes
                    756:         self.REQUEST.SESSION['dlInfo'] = self.getDLInfo()
1.26      casties   757:         if not self.REQUEST.SESSION.has_key('browserType'):
                    758:             self.REQUEST.SESSION['browserType'] = browserCheck(self)
                    759:             
                    760:         return
1.1       dwinter   761: 
1.20      casties   762:     def checkQuery(self):
                    763:    """check if the query has been stored"""
1.26      casties   764:    if not (self.REQUEST.SESSION and self.REQUEST.SESSION.has_key('query')) :
1.20      casties   765:        print "ZOGILIB: have to store query!!"
1.26      casties   766:        self.storeQuery()
1.24      casties   767:         return
1.23      casties   768: 
1.24      casties   769:     def zogilibPath(self, otherbase=None):
1.23      casties   770:         """returns an URL to the zogiLib instance"""
                    771:         url = self.REQUEST['URL1']
1.24      casties   772:         # should end with "/"
                    773:         if len(url) > 0 and url[-1] != '/':
                    774:             url += '/'
                    775:         if type(otherbase) is str:
                    776:             url += otherbase
                    777:         else:
                    778:             url += self.basePath
1.23      casties   779:         # should end with "/"
                    780:         if len(url) > 0 and url[-1] != '/':
                    781:             url += '/'
                    782:         return url
1.3       dwinter   783:         
1.22      casties   784:     def getDLParam(self, param):
1.18      casties   785:         """returns parameter"""
1.3       dwinter   786:         try:
                    787:             return self.REQUEST.SESSION['query'][param]
                    788:         except:
1.24      casties   789:             return
1.3       dwinter   790: 
1.18      casties   791:     def setDLParam(self, param, value):
                    792:         """sets parameter"""
                    793:         self.REQUEST.SESSION['query'][param] = value
                    794:         return
                    795: 
                    796:     def getAllDLParams(self):
                    797:         """parameter string for digilib"""
                    798:         dlParams = self.REQUEST.SESSION['query']
                    799:         # save modes
                    800:         modes = self.REQUEST.SESSION['dlModes']
                    801:         dlParams['mo'] = string.join(modes, ',')
                    802:         # assemble query string
                    803:         ret = ""
                    804:         for param in dlParams.keys():
1.29      casties   805:             if dlParams[param] is None: continue
1.18      casties   806:             val = str(dlParams[param])
                    807:             if val != "":
                    808:                 ret += param + "=" + val + "&"
1.28      casties   809: 
1.18      casties   810:         # omit trailing "&"
                    811:         return ret.rstrip('&')
                    812: 
                    813:         
                    814:     def setDLParams(self,pn=None,ws=None,rot=None,brgt=None,cont=None):
                    815:         """setze Parameter"""
                    816: 
1.23      casties   817:         self.setDLParam('brgt', brgt)
                    818:         self.setDLParam('cont', cont)
                    819:         self.setDLParam('ws', ws)
                    820:         self.setDLParam('rot', rot)
1.18      casties   821: 
                    822:         if pn:
1.21      casties   823:             # unmark
                    824:             self.setDLParam('mk', None)
1.18      casties   825:             self.setDLParam('pn', pn)
                    826:             
                    827:         return self.display()
                    828: 
                    829: 
                    830:     def display(self):
                    831:         """(re)display page"""
                    832:         params = self.getAllDLParams()
1.21      casties   833:         if self.basePath:
                    834:             self.REQUEST.RESPONSE.redirect(self.REQUEST['URL2']+'?'+params)
                    835:         else:
                    836:             self.REQUEST.RESPONSE.redirect(self.REQUEST['URL1']+'?'+params)
1.18      casties   837: 
1.32      dwinter   838:     def getMetaFileName(self):
                    839:         urlbase=re.sub('/servlet/Scaler','/dlContext-xml.jsp',self.digilibBaseUrl)
                    840:         
                    841:     
                    842:         return urlbase+self.getAllDLParams()
                    843: 
1.26      casties   844: 
1.32      dwinter   845:     
1.30      casties   846:     def getDLTarget(self):
                    847:         """returns dlTarget"""
                    848:         self.checkQuery()
                    849:         s = self.dlTarget
                    850: #         s = 'dl'
                    851: #         if self.getDLParam('fn'):
                    852: #             s += "_" + self.getDLParam('fn')
                    853: #         if self.getDLParam('pn'):
                    854: #             s += "_" + self.getDLParam('pn')
                    855:         return s
                    856: 
1.26      casties   857:     def setStaticHTML(self, static=True):
                    858:         """sets the preference to static HTML"""
                    859:         self.checkQuery()
                    860:    self.REQUEST.SESSION['browserType']['staticHTML'] = static
                    861:         return
                    862: 
                    863:     def isStaticHTML(self):
                    864:         """returns if the page is using static HTML only"""
                    865:         self.checkQuery()
                    866:    return self.REQUEST.SESSION['browserType']['staticHTML']
                    867: 
1.18      casties   868:     def getPT(self):
                    869:         """pagenums"""
                    870:         di = self.REQUEST.SESSION['dlInfo']
                    871:         if di:
                    872:             return int(di['pt'])
                    873:         else:
                    874:             return 1
                    875:     
                    876:     def getPN(self):
                    877:         """Pagenum"""
                    878:         pn = self.getDLParam('pn')
1.25      casties   879:         try:
1.18      casties   880:             return int(pn)
1.25      casties   881:         except:
1.3       dwinter   882:             return 1
                    883: 
1.18      casties   884:     def getBiggerWS(self):
1.3       dwinter   885:         """ws+1"""
1.23      casties   886:         ws = self.getDLParam('ws')
1.25      casties   887:         try:
1.26      casties   888:             return float(ws)+0.5
1.25      casties   889:         except:
1.26      casties   890:             return 1.5
1.3       dwinter   891:         
1.18      casties   892:     def getSmallerWS(self):
                    893:         """ws-1"""
                    894:         ws=self.getDLParam('ws')
1.25      casties   895:         try:
1.26      casties   896:             return max(float(ws)-0.5, 1)
1.25      casties   897:         except:
1.3       dwinter   898:             return 1
1.1       dwinter   899: 
1.18      casties   900:     def hasMode(self, mode):
                    901:         """returns if mode is in the diglib mo parameter"""
                    902:         return (mode in self.REQUEST.SESSION['dlModes'])
                    903: 
                    904:     def hasNextPage(self):
                    905:         """returns if there is a next page"""
                    906:         pn = self.getPN()
                    907:         pt = self.getPT()
                    908:         return (pn < pt)
                    909:    
                    910:     def hasPrevPage(self):
                    911:         """returns if there is a previous page"""
                    912:         pn = self.getPN()
                    913:         return (pn > 1)
1.1       dwinter   914: 
1.22      casties   915:     def canMoveLeft(self):
                    916:         """returns if its possible to move left"""
                    917:         wx = float(self.getDLParam('wx') or 0)
                    918:         return (wx > 0)
                    919: 
                    920:     def canMoveRight(self):
                    921:         """returns if its possible to move right"""
                    922:         wx = float(self.getDLParam('wx') or 0)
                    923:         ww = float(self.getDLParam('ww') or 1)
                    924:         return (wx + ww < 1)
                    925: 
                    926:     def canMoveUp(self):
                    927:         """returns if its possible to move up"""
                    928:         wy = float(self.getDLParam('wy') or 0)
                    929:         return (wy > 0)
                    930: 
                    931:     def canMoveDown(self):
                    932:         """returns if its possible to move down"""
                    933:         wy = float(self.getDLParam('wy') or 0)
                    934:         wh = float(self.getDLParam('wh') or 1)
                    935:         return (wy + wh < 1)
                    936: 
1.26      casties   937: 
                    938:     def dl_StaticHTML(self):
                    939:         """set rendering to static HTML"""
                    940:         self.checkQuery()
                    941:         self.REQUEST.SESSION['browserType']['staticHTML'] = True
                    942:         return self.display()
                    943: 
                    944:     def dl_DynamicHTML(self):
                    945:         """set rendering to dynamic HTML"""
                    946:         self.checkQuery()
                    947:         self.REQUEST.SESSION['browserType']['staticHTML'] = False
                    948:         return self.display()
1.1       dwinter   949:         
1.18      casties   950:     def dl_HMirror(self):
                    951:         """mirror action"""
                    952:         modes = self.REQUEST.SESSION['dlModes']
                    953:         if 'hmir' in modes:
                    954:             modes.remove('hmir')
                    955:         else:
                    956:             modes.append('hmir')
1.1       dwinter   957: 
1.18      casties   958:         return self.display()
                    959:        
                    960:     def dl_VMirror(self):
                    961:         """mirror action"""
                    962:         modes = self.REQUEST.SESSION['dlModes']
                    963:         if 'vmir' in modes:
                    964:             modes.remove('vmir')
                    965:         else:
                    966:             modes.append('vmir')
1.1       dwinter   967: 
1.18      casties   968:         return self.display()
1.1       dwinter   969: 
1.22      casties   970:     def dl_Zoom(self, z):
                    971:         """general zoom action"""
                    972:         ww1 = float(self.getDLParam('ww') or 1)
                    973:         wh1 = float(self.getDLParam('wh') or 1)
                    974:         wx = float(self.getDLParam('wx') or 0)
                    975:         wy = float(self.getDLParam('wy') or 0)
                    976:         ww2 = ww1 * z
                    977:         wh2 = wh1 * z
                    978:         wx += (ww1 - ww2) / 2
                    979:         wy += (wh1 - wh2) / 2
                    980:         ww2 = max(min(ww2, 1), 0)
                    981:         wh2 = max(min(wh2, 1), 0)
                    982:         wx = max(min(wx, 1), 0)
                    983:         wy = max(min(wy, 1), 0)
1.30      casties   984:         self.setDLParam('ww', cropf(ww2))
                    985:         self.setDLParam('wh', cropf(wh2))
                    986:         self.setDLParam('wx', cropf(wx))
                    987:         self.setDLParam('wy', cropf(wy))
1.22      casties   988:         return self.display()
                    989:         
                    990:     def dl_ZoomIn(self):
                    991:         """zoom in action"""
                    992:         z = 0.7071
                    993:         return self.dl_Zoom(z)
                    994: 
                    995:     def dl_ZoomOut(self):
                    996:         """zoom out action"""
                    997:         z = 1.4142
                    998:         return self.dl_Zoom(z)
                    999: 
                   1000:     def dl_Move(self, dx, dy):
                   1001:         """general move action"""
                   1002:         ww = float(self.getDLParam('ww') or 1)
                   1003:         wh = float(self.getDLParam('wh') or 1)
                   1004:         wx = float(self.getDLParam('wx') or 0)
                   1005:         wy = float(self.getDLParam('wy') or 0)
                   1006:         wx += dx * 0.5 * ww
                   1007:         wy += dy * 0.5 * wh
                   1008:         wx = max(min(wx, 1), 0)
                   1009:         wy = max(min(wy, 1), 0)
1.30      casties  1010:         self.setDLParam('wx', cropf(wx))
                   1011:         self.setDLParam('wy', cropf(wy))
1.22      casties  1012:         return self.display()
                   1013:         
                   1014:     def dl_MoveLeft(self):
                   1015:         """move left action"""
                   1016:         return self.dl_Move(-1, 0)
                   1017:     
                   1018:     def dl_MoveRight(self):
                   1019:         """move left action"""
                   1020:         return self.dl_Move(1, 0)
                   1021:     
                   1022:     def dl_MoveUp(self):
                   1023:         """move left action"""
                   1024:         return self.dl_Move(0, -1)
                   1025:     
                   1026:     def dl_MoveDown(self):
                   1027:         """move left action"""
                   1028:         return self.dl_Move(0, 1)
                   1029:     
1.18      casties  1030:     def dl_WholePage(self):
                   1031:         """zoom out action"""
                   1032:         self.setDLParam('ww', 1)
                   1033:         self.setDLParam('wh', 1)
                   1034:         self.setDLParam('wx', 0)
                   1035:         self.setDLParam('wy', 0)
                   1036:         return self.display()
                   1037:         
                   1038:     def dl_PrevPage(self):
                   1039:         """next page action"""
                   1040:         pn = self.getPN() - 1
                   1041:         if pn < 1:
                   1042:             pn = 1
                   1043:         self.setDLParam('pn', pn)
                   1044:         # unmark
                   1045:         self.setDLParam('mk', None)
                   1046:         return self.display()
                   1047:         
                   1048:     def dl_NextPage(self):
                   1049:         """next page action"""
                   1050:         pn = self.getPN() + 1
                   1051:         pt = self.getPT()
                   1052:         if pn > pt:
                   1053:             pn = pt
                   1054:         self.setDLParam('pn', pn)
                   1055:         # unmark
                   1056:         self.setDLParam('mk', None)
                   1057:         return self.display()
                   1058: 
                   1059:     def dl_FirstPage(self):
                   1060:         """first page action"""
                   1061:         self.setDLParam('pn', 1)
                   1062:         # unmark
                   1063:         self.setDLParam('mk', None)
                   1064:         return self.display()
                   1065:     
                   1066:     def dl_LastPage(self):
                   1067:         """last page action"""
                   1068:         self.setDLParam('pn', self.getPT())
                   1069:         # unmark
                   1070:         self.setDLParam('mk', None)
                   1071:         return self.display()
                   1072: 
                   1073:     def dl_Unmark(self):
                   1074:         """action to remove last mark"""
                   1075:         mk = self.getDLParam('mk')
                   1076:         if mk:
                   1077:             marks = mk.split(',')
                   1078:             marks.pop()
                   1079:             mk = string.join(marks, ',')
                   1080:             self.setDLParam('mk', mk)
                   1081:         return self.display()
1.1       dwinter  1082: 
1.32      dwinter  1083:     def dl_db(self,db):
                   1084:         """set db"""
                   1085:         self.setDLParam('db',db)
                   1086:         self.display()
1.1       dwinter  1087: 
1.18      casties  1088:     def changeZogiLibForm(self):
                   1089:         """Main configuration"""
                   1090:         pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/changeZogiLibForm.zpt')).__of__(self)
                   1091:         return pt()
1.1       dwinter  1092:     
1.27      casties  1093:     def changeZogiLib(self,title,digilibBaseUrl, localFileBase, version, basePath, dlTarget, RESPONSE=None):
1.18      casties  1094:         """change it"""
                   1095:         self.title=title
                   1096:         self.digilibBaseUrl=digilibBaseUrl
                   1097:         self.localFileBase=localFileBase
1.21      casties  1098:         self.basePath = basePath
1.18      casties  1099:         self.layout=version
1.27      casties  1100:         if dlTarget:
                   1101:             self.dlTarget = dlTarget
                   1102:         else:
                   1103:             self.dlTarget = "digilib"
1.3       dwinter  1104: 
1.18      casties  1105:         if RESPONSE is not None:
                   1106:             RESPONSE.redirect('manage_main')
1.8       dwinter  1107: 
                   1108:           
1.1       dwinter  1109: def manage_addZogiLibForm(self):
                   1110:     """interface for adding zogilib"""
1.18      casties  1111:     pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/addZogiLibForm')).__of__(self)
1.1       dwinter  1112:     return pt()
                   1113: 
1.27      casties  1114: def manage_addZogiLib(self,id,title,digilibBaseUrl, localFileBase,version="book",basePath="",dlTarget="digilib",RESPONSE=None):
1.1       dwinter  1115:     """add dgilib"""
1.27      casties  1116:     newObj=zogiLib(id,title,digilibBaseUrl, localFileBase, version, basePath, dlTarget)
1.1       dwinter  1117:     self.Destination()._setObject(id,newObj)
                   1118:     if RESPONSE is not None:
                   1119:         RESPONSE.redirect('manage_main')
1.29      casties  1120: 
                   1121: 
                   1122: class zogiLibPageTemplate(ZopePageTemplate):
                   1123:     """pageTemplate Objekt"""
                   1124:     meta_type="zogiLib_pageTemplate"
                   1125: 
                   1126: 
                   1127: ## def __init__(self, id, text=None, contentType=None):
                   1128: ##         self.id = str(id)
                   1129: ##         self.ZBindings_edit(self._default_bindings)
                   1130: ##         if text is None:
                   1131: ##             text = open(self._default_cont).read()
                   1132: ##         self.pt_edit(text, contentType)
                   1133: 
                   1134: def manage_addZogiLibPageTemplateForm(self):
                   1135:     """Form for adding"""
                   1136:     pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/addZogiLibPageTemplateForm')).__of__(self)
                   1137:     return pt()
                   1138: 
                   1139: def manage_addZogiLibPageTemplate(self, id='zogiLibMainTemplate', title=None, layout=None, text=None,
                   1140:                            REQUEST=None, submit=None):
                   1141:     "Add a Page Template with optional file content."
                   1142: 
                   1143:     id = str(id)
                   1144:     self._setObject(id, zogiLibPageTemplate(id))
                   1145:     ob = getattr(self, id)
                   1146:     if not layout: layout = "book"
                   1147:     ob.pt_edit(open(os.path.join(package_home(globals()),'zpt/zogiLibMain_%s.zpt'%layout)).read(),None)
                   1148:     if title:
                   1149:         ob.pt_setTitle(title)
                   1150:     try:
                   1151:         u = self.DestinationURL()
                   1152:     except AttributeError:
                   1153:         u = REQUEST['URL1']
                   1154:         
                   1155:     u = "%s/%s" % (u, urllib.quote(id))
                   1156:     REQUEST.RESPONSE.redirect(u+'/manage_main')
                   1157:     return ''

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