Annotation of zogiLib/zogiLib.py, revision 1.63

1.59      casties     1: from AccessControl import ClassSecurityInfo
                      2: from Globals import package_home
                      3: from OFS.Folder import Folder
                      4: from OFS.Image import Image
                      5: from OFS.Image import File
1.56      dwinter     6: from OFS.SimpleItem import SimpleItem
1.59      casties     7: from Products.PageTemplates.PageTemplate import PageTemplate
1.1       dwinter     8: from Products.PageTemplates.PageTemplateFile import PageTemplateFile
                      9: from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate
1.59      casties    10: from types import *
                     11: from Globals import package_home, ImageFile
1.32      dwinter    12: from xml_helpers import getUniqueElementText,getText
1.59      casties    13: import cgi
1.1       dwinter    14: import os
1.59      casties    15: import random
1.1       dwinter    16: import re
                     17: import string
                     18: import urllib
1.59      casties    19: import xml.dom.minidom
1.1       dwinter    20: 
1.63    ! casties    21: ZOGIVERSION = "0.10.2b ROC 15.6.2006"
1.30      casties    22: 
                     23: def cropf(f):
                     24:     """returns a float with reduced precision"""
                     25:     return float(int(f * 10000)/10000.0)
                     26: 
1.28      casties    27: 
1.26      casties    28: def browserCheck(self):
1.18      casties    29:     """check the browsers request to find out the browser type"""
1.26      casties    30:     bt = {}
                     31:     ua = self.REQUEST.get_header("HTTP_USER_AGENT")
                     32:     bt['ua'] = ua
1.51      casties    33:     bt['isIE'] = False
                     34:     bt['isN4'] = False
1.50      casties    35:     if string.find(ua, 'MSIE') > -1:
                     36:         bt['isIE'] = True
                     37:     else:
                     38:         bt['isN4'] = (string.find(ua, 'Mozilla/4.') > -1)
                     39:         
                     40:     try:
                     41:         nav = ua[string.find(ua, '('):]
                     42:         ie = string.split(nav, "; ")[1]
                     43:         if string.find(ie, "MSIE") > -1:
                     44:             bt['versIE'] = string.split(ie, " ")[1]
                     45:     except: pass
                     46:     
1.26      casties    47:     bt['isMac'] = string.find(ua, 'Macintosh') > -1
                     48:     bt['isWin'] = string.find(ua, 'Windows') > -1
                     49:     bt['isIEWin'] = bt['isIE'] and bt['isWin']
                     50:     bt['isIEMac'] = bt['isIE'] and bt['isMac']
                     51:     bt['staticHTML'] = False
1.5       dwinter    52: 
1.26      casties    53:     return bt
1.5       dwinter    54: 
1.1       dwinter    55:     
1.56      dwinter    56: class zogiImage(SimpleItem):
1.4       dwinter    57:     """einzelnes Image"""
                     58:     meta_type="zogiImage"
                     59: 
1.56      dwinter    60:     manage_options=SimpleItem.manage_options+(
1.18      casties    61:         {'label':'Main config','action':'changeZogiImageForm'},
                     62:        )
1.4       dwinter    63:     
                     64:     
                     65:     def __init__(self,id,title,baseUrl,queryString,content_type='',precondition=''):
                     66:         """init"""
                     67:         self.id=id
                     68:         self.title=title
1.46      casties    69:         if baseUrl:
                     70:             self.baseUrl=baseUrl
                     71:         else:
                     72:             self.baseUrl="http://nausikaa.mpiwg-berlin.mpg.de/digitallibrary/servlet/Scaler?"
                     73:             
1.4       dwinter    74:         self.queryString=queryString
                     75:         self.content_type=content_type
                     76:         self.precondition=precondition
                     77: 
1.56      dwinter    78:     #def getData(self):
                     79:     #    """getUrlData"""
                     80:     #    return urllib.urlopen(self.baseUrl+self.queryString)
1.4       dwinter    81: 
                     82:     def changeZogiImageForm(self):
                     83:         """Main configuration"""
1.18      casties    84:         pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/changeZogiImageForm.zpt')).__of__(self)
1.4       dwinter    85:         return pt()
                     86:     
                     87:     def changeZogiImage(self,title,baseUrl, queryString,RESPONSE=None):
                     88:         """change it"""
                     89:         self.title=title
                     90:         self.baseUrl=baseUrl
                     91:         self.queryString=queryString
                     92: 
                     93:         if RESPONSE is not None:
                     94:             RESPONSE.redirect('manage_main')
                     95: 
1.46      casties    96:     def index_html(self, REQUEST, RESPONSE):
                     97:         """service the request by redirecting to digilib server"""
                     98:         RESPONSE.redirect(self.baseUrl+self.queryString)
                     99:         return ''
1.4       dwinter   100:         
1.57      dwinter   101:     def rescale(self,width=None,height=None):
                    102:         """andere parameter im querystring"""
                    103:         qs=cgi.parse_qs(self.queryString)
                    104:         for x in qs.keys():
                    105:             if type(qs[x]) is ListType:
                    106:                 qs[x]=qs[x][0]
                    107:         
                    108:         if width:
                    109:             qs['dw']=width
                    110:         if height:
                    111:             qs['dh']=height
1.4       dwinter   112: 
1.57      dwinter   113:         
                    114:         qsneu=urllib.urlencode(qs)
                    115:         self.queryString=qsneu
                    116:         return "done"
                    117:     
1.4       dwinter   118: def manage_addZogiImageForm(self):
                    119:     """Form for adding"""
1.18      casties   120:     pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/addZogiImage.zpt')).__of__(self)
1.4       dwinter   121:     return pt()
                    122: 
                    123: 
                    124: def manage_addZogiImage(self,id,title,baseUrl, queryString,RESPONSE=None):
1.46      casties   125:     """add zogiimage"""
1.4       dwinter   126:     newObj=zogiImage(id,title,baseUrl, queryString)
                    127:     self.Destination()._setObject(id,newObj)
                    128:     if RESPONSE is not None:
                    129:         RESPONSE.redirect('manage_main')
                    130: 
                    131: 
                    132: 
1.1       dwinter   133: class zogiLib(Folder):
1.50      casties   134:     """digilib frontend with ZOPE"""
1.1       dwinter   135: 
                    136:     meta_type="zogiLib"
1.32      dwinter   137:     #xxxx
1.54      dwinter   138:     security=ClassSecurityInfo()
                    139:     
1.18      casties   140:     manage_options = Folder.manage_options+(
                    141:             {'label':'Main Config','action':'changeZogiLibForm'},
                    142:             )
1.1       dwinter   143: 
1.37      casties   144:     def __init__(self, id, title, dlServerURL, layout="book", basePath="", dlTarget=None, dlToolbarBaseURL=None):
1.1       dwinter   145:         """init"""
                    146: 
1.63    ! casties   147:         self.id = id
        !           148:         self.title = title
1.34      casties   149:         self.dlServerURL = dlServerURL
1.63    ! casties   150:         self.basePath = basePath
        !           151:         self.layout = layout
1.44      casties   152:         self.dlTarget = dlTarget
1.1       dwinter   153: 
1.37      casties   154:         if dlToolbarBaseURL:
                    155:             self.dlToolbarBaseURL = dlToolbarBaseURL
                    156:         else:
                    157:             self.dlToolbarBaseURL = dlServerURL + "/digimage.jsp?"
1.59      casties   158:             
                    159:         self.manage_addFolder('template')
                    160: 
                    161: 
                    162: # form templates
                    163:     main_book      = PageTemplateFile('zpt/main_book', globals())
                    164:     main_image     = PageTemplateFile('zpt/main_image', globals())
                    165:     main_metaData  = PageTemplateFile('zpt/main_metadata', globals())
1.61      casties   166:     #main_static    = PageTemplateFile('zpt/main_static', globals())
1.59      casties   167:     options        = PageTemplateFile('zpt/options', globals())
                    168:     changeForm     = PageTemplateFile('zpt/changeForm', globals())
                    169: 
                    170: # display templates
1.61      casties   171:     aux_divs       = PageTemplateFile('zpt/aux_divs', globals())
                    172:     #aux_divsN4     = PageTemplateFile('zpt/aux_divsN4', globals())
1.59      casties   173:     img_div        = PageTemplateFile('zpt/img_div', globals())
                    174:     
                    175: # javascripts
                    176:     head_js        = PageTemplateFile('zpt/head_js', globals())
                    177:     jslib_js       = PageTemplateFile('js/baselib.js', globals())
                    178:     dllib_js       = PageTemplateFile('js/dllib.js', globals())
                    179:     
                    180: # graphic files
                    181:     arr_right = ImageFile('images/right.gif', globals())
                    182:     arr_left  = ImageFile('images/left.gif', globals())
                    183:     arr_up    = ImageFile('images/up.gif', globals())
1.61      casties   184:     arr_down  = ImageFile('images/down.gif', globals())
1.59      casties   185:     mark1     = ImageFile('images/mark1.gif', globals())
                    186:     mark2     = ImageFile('images/mark2.gif', globals())
                    187:     mark3     = ImageFile('images/mark3.gif', globals())
                    188:     mark4     = ImageFile('images/mark4.gif', globals())
                    189:     mark5     = ImageFile('images/mark5.gif', globals())
                    190:     mark6     = ImageFile('images/mark6.gif', globals())
                    191:     mark7     = ImageFile('images/mark7.gif', globals())
                    192:     mark8     = ImageFile('images/mark8.gif', globals())
                    193:     corner1   = ImageFile('images/olinks.gif', globals())
                    194:     corner2   = ImageFile('images/orechts.gif', globals())
                    195:     corner3   = ImageFile('images/ulinks.gif', globals())
                    196:     corner4   = ImageFile('images/urechts.gif', globals())    
                    197: 
1.37      casties   198: 
1.54      dwinter   199:     security.declareProtected('View','getLayout')
                    200:     def getLayout(self):
                    201:         """get Layout"""
                    202:         return self.layout
                    203:     
1.28      casties   204:     def version(self):
                    205:         """version information"""
                    206:         return ZOGIVERSION
                    207: 
1.32      dwinter   208:     def getContextStatic(self):
                    209:         """get all the contexts which go to static pages"""
                    210:         
1.33      dwinter   211:         try:
                    212:             dom=xml.dom.minidom.parse(urllib.urlopen(self.getMetaFileName()))
                    213:             contexts=dom.getElementsByTagName("context")
                    214: 
                    215:             ret=[]
                    216:             for context in contexts:
                    217:                 name=getUniqueElementText(context.getElementsByTagName("name"))
                    218: 
                    219:                 link=getUniqueElementText(context.getElementsByTagName("link"))
                    220:                 if name or link:
                    221:                     ret.append((name,link))
                    222:             return ret
                    223:         except:
                    224:             return []
1.32      dwinter   225: 
                    226:     def getContextDatabases(self):
                    227:         """get all dynamic contexts"""
1.33      dwinter   228:         try:
                    229:             dom=xml.dom.minidom.parse(urllib.urlopen(self.getMetaFileName()))
                    230:             contexts=dom.getElementsByTagName("context")
                    231:             ret=[]
                    232:             for context in contexts:
                    233:                 metaDataLinks=context.getElementsByTagName("meta-datalink")
                    234:                 for metaDataLink in metaDataLinks:
                    235:                     db=metaDataLink.getAttribute("db")
                    236:                     link=self.REQUEST['URL1']+"/dl_db?db=%s"%db
                    237:                     if db:
                    238:                         ret.append((db,link))
                    239:                 metaDataLinks=context.getElementsByTagName("meta-baselink")
                    240: 
                    241:                 for metaDataLink in metaDataLinks:
                    242:                     db=metaDataLink.getAttribute("db")
                    243:                     link=self.REQUEST['URL1']+"/dl_db?db=%s"%db
                    244:                     if db:
                    245:                         ret.append((db,link))
                    246: 
                    247:             return ret
                    248:         except:
1.45      casties   249: 
                    250:             return []
1.32      dwinter   251: 
1.39      casties   252: 
1.32      dwinter   253:     def formatHTML(self,url,label=None,viewUrl=None):
                    254: 
                    255:         sets=xml.dom.minidom.parse(urllib.urlopen(url)).getElementsByTagName('dataset')
                    256:         ret=""
1.59      casties   257:         #print label
1.32      dwinter   258:         if label:
                    259:             ret+="""<a href="%s">%s</a>"""%(viewUrl,label)
                    260:         for set in sets:
                    261:             ret+="<table>"
                    262:             for node in set.childNodes:
                    263:                 if hasattr(node,'tagName'):
                    264:                     tag=node.tagName
                    265:                     label=node.getAttribute("label")
                    266:                     if not label:
                    267:                         label=tag
                    268:                     text=getText(node.childNodes)
                    269:                     ret+="""<tr><td><b>%s:</b></td><td>%s</td></tr>"""%(label,text)
                    270:             ret+="</table>"
                    271:         return ret
1.39      casties   272: 
1.32      dwinter   273:     
                    274:     def getMetaData(self):
                    275:         """getMetaData"""
1.33      dwinter   276:         try:
                    277:             dom=xml.dom.minidom.parse(urllib.urlopen(self.getMetaFileName()))
                    278:         except:
                    279:             return "error metadata"
                    280:         
1.32      dwinter   281:         contexts=dom.getElementsByTagName("context")
                    282:         ret=[]
                    283:         db=self.getDLParam("db")
                    284:         ob=self.getDLParam("object")
                    285:         
                    286:         fn=self.getDLParam("fn")
                    287:         pn=self.getDLParam("pn")
                    288:         if not fn:
                    289:             fn=""
                    290:         if not pn:
                    291:             pn=""
                    292:         if not ob:
                    293:             ob=""
                    294:             
                    295:         for context in contexts:
                    296:             metaDataLinks=context.getElementsByTagName("meta-datalink")
                    297:             for metaDataLink in metaDataLinks:
                    298:                  
                    299:                 if (db==metaDataLink.getAttribute("db")) or (len(metaDataLinks)==1):
                    300:                     
                    301:                     link=getUniqueElementText(metaDataLink.getElementsByTagName("metadata-url"))
                    302:                     label=getUniqueElementText(metaDataLink.getElementsByTagName("label"))
                    303:                     url=getUniqueElementText(metaDataLink.getElementsByTagName("url"))
                    304: 
                    305:                     return self.formatHTML(link,label,url)
                    306: 
                    307:             metaDataLinks=context.getElementsByTagName("meta-baselink")
                    308:              
                    309:             for metaDataLink in metaDataLinks:
                    310:                 
                    311:                 if db==metaDataLink.getAttribute("db") or (len(metaDataLinks)==1):
                    312:                     
                    313:                     link=getUniqueElementText(metaDataLink.getElementsByTagName("metadata-url"))
                    314:                     label=getUniqueElementText(metaDataLink.getElementsByTagName("label"))
                    315:                     url=getUniqueElementText(metaDataLink.getElementsByTagName("url"))
                    316: 
                    317:                     return self.formatHTML(link+'fn=%s&pn=%s&object=%s'%(fn,pn,ob),label,url)
                    318:         return ret
                    319: 
1.39      casties   320: 
1.18      casties   321:     def getDLInfo(self):
                    322:         """get DLInfo from digilib server"""
                    323:         paramH={}
1.59      casties   324:         baseUrl=self.getDLBaseUrl()+"/dlInfo-xml.jsp"
1.61      casties   325:         #print "getdlinfo: ", baseUrl
1.18      casties   326:         try:
1.59      casties   327:             url=urllib.urlopen(baseUrl+'?'+self.getAllDLParams())
1.18      casties   328:             dom=xml.dom.minidom.parse(url)
                    329:             params=dom.getElementsByTagName('parameter')
                    330:             for param in params:
                    331:                 paramH[param.getAttribute('name')]=param.getAttribute('value')
                    332:             return paramH
                    333:         except:
1.34      casties   334:             return {}
1.18      casties   335: 
1.1       dwinter   336: 
1.59      casties   337:     def zogilibPath(self, otherbase=None):
                    338:         """returns an URL to the zogiLib instance"""
                    339:         url = self.REQUEST['URL1']
                    340:         # should end with "/"
                    341:         if len(url) > 0 and url[-1] != '/':
                    342:             url += '/'
                    343:         if type(otherbase) is str:
                    344:             url += otherbase
                    345:         else:
                    346:             url += self.basePath
1.61      casties   347:         # should still end with "/"
1.59      casties   348:         if len(url) > 0 and url[-1] != '/':
                    349:             url += '/'
                    350:         return url
1.19      casties   351: 
1.59      casties   352:     def zogilibAction(self, action, otherbase=None):
                    353:         """returns a URL with zogilib path and action"""
                    354:         url = self.zogilibPath(otherbase)
                    355:         url += action
                    356:         url += '?' + self.getAllDLParams();
                    357:         return url
                    358:     
                    359:     def getDLBaseUrl(self):
                    360:         """returns digilib base URL (sans servlet path)"""
                    361:         if self.dlServerURL[-1] == '?':
                    362:             # full Servlet URL -- remove last part
                    363:             si = self.dlServerURL.rindex('/servlet/')
                    364:             if si > 0:
                    365:                 return self.dlServerURL[:si]
                    366:             else:
                    367:                 # no servlet part :-(
                    368:                 return "http://nausikaa.mpiwg-berlin.mpg.de/digitallibrary"
                    369:         else:
                    370:             return self.dlServerURL 
1.19      casties   371:         
1.58      dwinter   372: 
1.59      casties   373:     def getScalerUrl(self,requestString=""):
1.58      dwinter   374:         """send scaler url"""
1.59      casties   375:         if self.dlServerURL[-1] == '?':
                    376:             # full Servlet URL
                    377:             return self.dlServerURL + requestString
                    378:         else:
1.58      dwinter   379:             return self.dlServerURL+'/servlet/Scaler?'+requestString
                    380:     
                    381:     def scaledImage(self,requestString=None):
                    382:         """scaled Image"""
                    383:         
                    384:         if not requestString:
                    385:             requestString=self.REQUEST['QUERY_STRING']
                    386:             
                    387:         self.REQUEST.RESPONSE.redirect(self.getScalerUrl(requestString))
                    388:         
                    389:         return True
                    390:     
                    391:         
1.26      casties   392:     def createScalerImg(self, requestString=None, bottom=0, side=0, width=500, height=500):
1.18      casties   393:         """generate Scaler IMG Tag"""
1.58      dwinter   394:         self.checkQuery()
1.63    ! casties   395:         bt = self.getBrowserType()
1.24      casties   396:         # override with parameters from session
                    397:         if  self.REQUEST.SESSION.has_key('scalerDiv'):
1.26      casties   398:             (requestString, bottom, side, width, height) = self.REQUEST.SESSION['scalerDiv']
1.24      casties   399:         # if not explicitly defined take normal request
1.18      casties   400:         if not requestString:
1.21      casties   401:             requestString = self.getAllDLParams()
1.59      casties   402:         url = self.getScalerUrl(requestString=requestString)
1.24      casties   403:         # construct bottom and side insets
                    404:         b_par = ""
                    405:         s_par = ""
                    406:         if (bottom != 0) or (side != 0):
                    407:             b_par = "-" + str(int(bottom))
                    408:             s_par = "-" + str(int(side))
1.18      casties   409:         tag = ""
1.26      casties   410:         if bt['staticHTML']:
                    411:             tag += '<div id="scaler"><img id="pic" src="%s&dw=%i&dh=%i" /></div>'%(url, int(width-side), int(height-bottom))
1.18      casties   412:         else:
1.26      casties   413:             if bt['isN4']:
                    414:                 # N4 needs layers
                    415:                 tag += '<ilayer id="scaler">'
                    416:             else:
                    417:                 tag += '<div id="scaler">'
                    418:             tag += '<script type="text/javascript">'
                    419:             tag += "var ps = bestPicSize(getElement('scaler'));"
                    420:             # write img tag with javascript
                    421:             tag += 'document.write(\'<img id="pic" src="%s&dw=\'+(ps.width%s)+\'&dh=\'+(ps.height%s)+\'" />\');'%(url, s_par, b_par)
                    422:             tag += '</script>'
                    423:             if bt['isN4']:
                    424:                 tag += '</ilayer>'
                    425:             else:
                    426:                 tag += '</div>'
1.18      casties   427:         return tag
1.1       dwinter   428: 
1.26      casties   429:     def createScalerDiv(self, requestString = None, bottom = 0, side = 0, width=500, height=500):
1.23      casties   430:         """generate scaler img and table with navigation arrows"""
1.58      dwinter   431:         self.checkQuery()
1.24      casties   432:         if requestString != None or bottom != 0 or side != 0:
1.26      casties   433:             self.REQUEST.SESSION['scalerDiv'] = (requestString, bottom, side, width, height)
1.24      casties   434:         else:
                    435:             if self.REQUEST.SESSION.has_key('scalerDiv'):
1.26      casties   436:                 # make shure to remove unused parameter
1.24      casties   437:                 del self.REQUEST.SESSION['scalerDiv']
1.26      casties   438:                 
1.23      casties   439:         pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt/zogilib_img_div')).__of__(self)
                    440:         return pt()
                    441: 
1.1       dwinter   442:     def index_html(self):
                    443:         """main action"""
1.58      dwinter   444:         self.checkQuery()
1.59      casties   445:         tp = "main_template"
                    446:         tpt = self.layout
1.32      dwinter   447:         
1.60      casties   448:         if not hasattr(self, 'template'):
                    449:             # create template folder if it doesn't exist
1.61      casties   450:             print "no template folder -- creating"
1.60      casties   451:             self.manage_addFolder('template')
1.26      casties   452:             
1.60      casties   453:         pt = getattr(self.template, 'main_'+tpt)
1.18      casties   454:         return pt()
                    455: 
1.59      casties   456:     def checkQuery(self):
                    457:         """make shure that the query has been saved"""
                    458:         if not self.REQUEST.has_key('dlParams'):
                    459:             self.storeQuery()
1.1       dwinter   460: 
1.59      casties   461:     def storeQuery(self, more=None, withpt=False):
                    462:         """parse query parameters into a hash in REQUEST"""
                    463:         params = {}
1.1       dwinter   464:         for fm in self.REQUEST.form.keys():
1.59      casties   465:             params[fm] = self.REQUEST.form[fm]
1.21      casties   466:         # look for more
                    467:         if more:
                    468:             for fm in more.split('&'):
                    469:                 try:
                    470:                     pv = fm.split('=')
1.59      casties   471:                     params[pv[0]] = pv[1]
1.21      casties   472:                 except:
1.26      casties   473:                     pass
                    474:                 
1.21      casties   475:         # parse digilib mode parameter
1.59      casties   476:         if 'mo' in params:
                    477:             if len(params['mo']) > 0:
                    478:                 modes=params['mo'].split(',')
1.18      casties   479:         else:
1.59      casties   480:             modes = [];
                    481: 
                    482:         self.REQUEST.set('dlParams', params)
                    483:         self.REQUEST.set('dlModes', modes)
                    484:         
                    485:         # trigger get pt (from dlInfo) if requested
                    486:         if withpt:
                    487:             pt = self.getPT()
1.44      casties   488:             
1.59      casties   489:         return params
                    490:         
1.44      casties   491: 
1.53      casties   492:     def getDLParam(self, param, default=None):
                    493:         """returns parameter or default"""
1.59      casties   494:         self.checkQuery()
                    495:         dlParams = self.REQUEST.get('dlParams')
1.3       dwinter   496:         try:
1.59      casties   497:             return dlParams[param]
1.3       dwinter   498:         except:
1.53      casties   499:             return default
1.3       dwinter   500: 
1.18      casties   501:     def setDLParam(self, param, value):
                    502:         """sets parameter"""
1.59      casties   503:         self.checkQuery()
                    504:         dlParams = self.REQUEST.get('dlParams')
1.44      casties   505:         dlParams[param] = value
1.18      casties   506:         return
                    507: 
                    508:     def getAllDLParams(self):
                    509:         """parameter string for digilib"""
1.59      casties   510:         self.checkQuery()
                    511:         dlParams = self.REQUEST.get('dlParams')
1.18      casties   512:         # save modes
1.59      casties   513:         modes = self.REQUEST.get('dlModes')
                    514:         if modes:
                    515:             dlParams['mo'] = string.join(modes, ',')
1.18      casties   516:         # assemble query string
                    517:         ret = ""
                    518:         for param in dlParams.keys():
1.29      casties   519:             if dlParams[param] is None: continue
1.18      casties   520:             val = str(dlParams[param])
                    521:             if val != "":
                    522:                 ret += param + "=" + val + "&"
1.28      casties   523: 
1.18      casties   524:         # omit trailing "&"
                    525:         return ret.rstrip('&')
                    526:         
                    527:     def setDLParams(self,pn=None,ws=None,rot=None,brgt=None,cont=None):
                    528:         """setze Parameter"""
                    529: 
1.23      casties   530:         self.setDLParam('brgt', brgt)
                    531:         self.setDLParam('cont', cont)
                    532:         self.setDLParam('ws', ws)
                    533:         self.setDLParam('rot', rot)
1.18      casties   534: 
                    535:         if pn:
1.21      casties   536:             # unmark
                    537:             self.setDLParam('mk', None)
1.18      casties   538:             self.setDLParam('pn', pn)
                    539:             
                    540:         return self.display()
                    541: 
1.63    ! casties   542:     def getBrowserType(self):
        !           543:         """get browser type object"""
        !           544:         if self.REQUEST.SESSION.has_key('browserType'):
        !           545:             return self.REQUEST.SESSION['browserType']
        !           546:         else:
        !           547:             bt = browserCheck(self)
        !           548:             self.REQUEST.SESSION.set('browserType', bt)                        
        !           549:             return bt
        !           550: 
1.18      casties   551: 
                    552:     def display(self):
                    553:         """(re)display page"""
                    554:         params = self.getAllDLParams()
1.44      casties   555:             
1.21      casties   556:         if self.basePath:
                    557:             self.REQUEST.RESPONSE.redirect(self.REQUEST['URL2']+'?'+params)
                    558:         else:
                    559:             self.REQUEST.RESPONSE.redirect(self.REQUEST['URL1']+'?'+params)
1.18      casties   560: 
1.32      dwinter   561:     def getMetaFileName(self):
1.34      casties   562:         url=self.dlServerURL+'/dlContext-xml.jsp?'+self.getAllDLParams()
                    563:         return urlbase
1.26      casties   564: 
1.34      casties   565:     def getToolbarPageURL(self):
                    566:         """returns a toolbar-enabled page URL"""
1.37      casties   567:         url=self.dlToolbarBaseURL+self.getAllDLParams()
1.34      casties   568:         return url
1.32      dwinter   569:     
1.30      casties   570:     def getDLTarget(self):
                    571:         """returns dlTarget"""
                    572:         self.checkQuery()
                    573:         s = self.dlTarget
1.61      casties   574:         if (s is None) or (s == ""):
                    575: #            s = ""
                    576:             s = 'dl'
                    577:             if self.getDLParam('fn'):
                    578:                 s += "_" + self.getDLParam('fn')
                    579:             if self.getDLParam('pn'):
                    580:                 s += "_" + self.getDLParam('pn')
                    581: 
1.30      casties   582:         return s
                    583: 
1.59      casties   584:     def getPN(self):
1.61      casties   585:         """pagenumber"""
1.59      casties   586:         pn = int(self.getDLParam('pn', 1))
                    587:         return pn
                    588:     
1.18      casties   589:     def getPT(self):
1.61      casties   590:         """number of total pages"""
1.59      casties   591:         pt = self.getDLParam('pt', None)
                    592:         if pt is None:
                    593:             # get pt from dlInfo
                    594:             if self.REQUEST.has_key('dlInfo'):
                    595:                 info = self.REQUEST.get('dlInfo')
                    596:             else:
                    597:                 info = self.getDLInfo()
                    598:                 self.REQUEST.set('dlInfo', info)
                    599:             pt = int(info.get('pt', 1))
                    600:             self.setDLParam('pt', pt)
                    601:         return int(pt)
1.18      casties   602:     
                    603:     def hasMode(self, mode):
                    604:         """returns if mode is in the diglib mo parameter"""
1.59      casties   605:         return (mode in self.REQUEST.get('dlModes'))
1.18      casties   606: 
                    607:     def hasNextPage(self):
                    608:         """returns if there is a next page"""
                    609:         pn = self.getPN()
                    610:         pt = self.getPT()
                    611:         return (pn < pt)
                    612:    
                    613:     def hasPrevPage(self):
                    614:         """returns if there is a previous page"""
                    615:         pn = self.getPN()
                    616:         return (pn > 1)
1.1       dwinter   617: 
1.22      casties   618:     def canMoveLeft(self):
                    619:         """returns if its possible to move left"""
                    620:         wx = float(self.getDLParam('wx') or 0)
                    621:         return (wx > 0)
                    622: 
                    623:     def canMoveRight(self):
                    624:         """returns if its possible to move right"""
                    625:         wx = float(self.getDLParam('wx') or 0)
                    626:         ww = float(self.getDLParam('ww') or 1)
                    627:         return (wx + ww < 1)
                    628: 
                    629:     def canMoveUp(self):
                    630:         """returns if its possible to move up"""
                    631:         wy = float(self.getDLParam('wy') or 0)
                    632:         return (wy > 0)
                    633: 
                    634:     def canMoveDown(self):
                    635:         """returns if its possible to move down"""
                    636:         wy = float(self.getDLParam('wy') or 0)
                    637:         wh = float(self.getDLParam('wh') or 1)
                    638:         return (wy + wh < 1)
                    639: 
1.26      casties   640: 
                    641:     def dl_StaticHTML(self):
                    642:         """set rendering to static HTML"""
                    643:         self.checkQuery()
1.63    ! casties   644:         self.getBrowserType()['staticHTML'] = True
1.26      casties   645:         return self.display()
                    646: 
                    647:     def dl_DynamicHTML(self):
                    648:         """set rendering to dynamic HTML"""
                    649:         self.checkQuery()
1.63    ! casties   650:         self.getBrowserType()['staticHTML'] = False
1.26      casties   651:         return self.display()
1.1       dwinter   652:         
1.18      casties   653:     def dl_HMirror(self):
                    654:         """mirror action"""
1.44      casties   655:         modes = self.getSubSession('dlModes')
1.18      casties   656:         if 'hmir' in modes:
                    657:             modes.remove('hmir')
                    658:         else:
                    659:             modes.append('hmir')
1.1       dwinter   660: 
1.18      casties   661:         return self.display()
                    662:        
                    663:     def dl_VMirror(self):
                    664:         """mirror action"""
1.44      casties   665:         modes = self.getSubSession('dlModes')
1.18      casties   666:         if 'vmir' in modes:
                    667:             modes.remove('vmir')
                    668:         else:
                    669:             modes.append('vmir')
1.1       dwinter   670: 
1.18      casties   671:         return self.display()
1.1       dwinter   672: 
1.22      casties   673:     def dl_Zoom(self, z):
                    674:         """general zoom action"""
                    675:         ww1 = float(self.getDLParam('ww') or 1)
                    676:         wh1 = float(self.getDLParam('wh') or 1)
                    677:         wx = float(self.getDLParam('wx') or 0)
                    678:         wy = float(self.getDLParam('wy') or 0)
                    679:         ww2 = ww1 * z
                    680:         wh2 = wh1 * z
                    681:         wx += (ww1 - ww2) / 2
                    682:         wy += (wh1 - wh2) / 2
                    683:         ww2 = max(min(ww2, 1), 0)
                    684:         wh2 = max(min(wh2, 1), 0)
                    685:         wx = max(min(wx, 1), 0)
                    686:         wy = max(min(wy, 1), 0)
1.30      casties   687:         self.setDLParam('ww', cropf(ww2))
                    688:         self.setDLParam('wh', cropf(wh2))
                    689:         self.setDLParam('wx', cropf(wx))
                    690:         self.setDLParam('wy', cropf(wy))
1.22      casties   691:         return self.display()
                    692:         
                    693:     def dl_ZoomIn(self):
                    694:         """zoom in action"""
                    695:         z = 0.7071
                    696:         return self.dl_Zoom(z)
                    697: 
                    698:     def dl_ZoomOut(self):
                    699:         """zoom out action"""
                    700:         z = 1.4142
                    701:         return self.dl_Zoom(z)
                    702: 
                    703:     def dl_Move(self, dx, dy):
                    704:         """general move action"""
                    705:         ww = float(self.getDLParam('ww') or 1)
                    706:         wh = float(self.getDLParam('wh') or 1)
                    707:         wx = float(self.getDLParam('wx') or 0)
                    708:         wy = float(self.getDLParam('wy') or 0)
                    709:         wx += dx * 0.5 * ww
                    710:         wy += dy * 0.5 * wh
                    711:         wx = max(min(wx, 1), 0)
                    712:         wy = max(min(wy, 1), 0)
1.30      casties   713:         self.setDLParam('wx', cropf(wx))
                    714:         self.setDLParam('wy', cropf(wy))
1.22      casties   715:         return self.display()
                    716:         
                    717:     def dl_MoveLeft(self):
                    718:         """move left action"""
                    719:         return self.dl_Move(-1, 0)
                    720:     
                    721:     def dl_MoveRight(self):
                    722:         """move left action"""
                    723:         return self.dl_Move(1, 0)
                    724:     
                    725:     def dl_MoveUp(self):
                    726:         """move left action"""
                    727:         return self.dl_Move(0, -1)
                    728:     
                    729:     def dl_MoveDown(self):
                    730:         """move left action"""
                    731:         return self.dl_Move(0, 1)
                    732:     
1.18      casties   733:     def dl_WholePage(self):
                    734:         """zoom out action"""
                    735:         self.setDLParam('ww', 1)
                    736:         self.setDLParam('wh', 1)
                    737:         self.setDLParam('wx', 0)
                    738:         self.setDLParam('wy', 0)
                    739:         return self.display()
                    740:         
                    741:     def dl_PrevPage(self):
                    742:         """next page action"""
                    743:         pn = self.getPN() - 1
                    744:         if pn < 1:
                    745:             pn = 1
                    746:         self.setDLParam('pn', pn)
                    747:         # unmark
                    748:         self.setDLParam('mk', None)
                    749:         return self.display()
                    750:         
                    751:     def dl_NextPage(self):
                    752:         """next page action"""
                    753:         pn = self.getPN() + 1
                    754:         pt = self.getPT()
                    755:         if pn > pt:
                    756:             pn = pt
                    757:         self.setDLParam('pn', pn)
                    758:         # unmark
                    759:         self.setDLParam('mk', None)
                    760:         return self.display()
                    761: 
                    762:     def dl_FirstPage(self):
                    763:         """first page action"""
                    764:         self.setDLParam('pn', 1)
                    765:         # unmark
                    766:         self.setDLParam('mk', None)
                    767:         return self.display()
                    768:     
                    769:     def dl_LastPage(self):
                    770:         """last page action"""
                    771:         self.setDLParam('pn', self.getPT())
                    772:         # unmark
                    773:         self.setDLParam('mk', None)
                    774:         return self.display()
                    775: 
1.32      dwinter   776:     def dl_db(self,db):
                    777:         """set db"""
                    778:         self.setDLParam('db',db)
                    779:         self.display()
1.1       dwinter   780: 
1.18      casties   781:     def changeZogiLibForm(self):
                    782:         """Main configuration"""
                    783:         pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/changeZogiLibForm.zpt')).__of__(self)
                    784:         return pt()
1.1       dwinter   785:     
1.37      casties   786:     def changeZogiLib(self,title,dlServerURL, version, basePath, dlTarget, dlToolbarBaseURL, RESPONSE=None):
1.18      casties   787:         """change it"""
                    788:         self.title=title
1.35      casties   789:         self.dlServerURL=dlServerURL
1.21      casties   790:         self.basePath = basePath
1.18      casties   791:         self.layout=version
1.44      casties   792:         self.dlTarget = dlTarget
1.3       dwinter   793: 
1.37      casties   794:         if dlToolbarBaseURL:
                    795:             self.dlToolbarBaseURL = dlToolbarBaseURL
                    796:         else:
                    797:             self.dlToolbarBaseURL = dlServerURL + "/digimage.jsp?"
                    798: 
1.18      casties   799:         if RESPONSE is not None:
                    800:             RESPONSE.redirect('manage_main')
1.8       dwinter   801: 
1.35      casties   802: 
                    803: 
                    804:     ##
1.44      casties   805:     ## odds and ends
1.35      casties   806:     ##
                    807: 
                    808:     def repairZogilib(self, obj=None):
                    809:         """change stuff that broke on upgrading"""
                    810: 
                    811:         msg = ""
                    812: 
                    813:         if not obj:
                    814:             obj = self.getPhysicalRoot()
                    815: 
                    816:         print "starting in ", obj
                    817:         
                    818:         entries=obj.ZopeFind(obj,obj_metatypes=['zogiLib'],search_sub=1)
                    819: 
                    820:         for entry in entries:
                    821:             print "  found ", entry
1.37      casties   822:             #
                    823:             # replace digilibBaseUrl by dlServerURL
1.35      casties   824:             if hasattr(entry[1], 'digilibBaseUrl'):
1.37      casties   825:                 msg += "  fixing digilibBaseUrl in "+entry[0]+"\n"
1.36      casties   826:                 entry[1].dlServerURL = re.sub('/servlet/Scaler\?','',entry[1].digilibBaseUrl)
1.35      casties   827:                 del entry[1].digilibBaseUrl
                    828:                 
1.37      casties   829:             #
                    830:             # add dlToolbarBaseURL
                    831:             if not hasattr(entry[1], 'dlToolbarBaseURL'):
                    832:                 msg += "  fixing dlToolbarBaseURL in "+entry[0]+"\n"
                    833:                 entry[1].dlToolbarBaseURL = entry[1].dlServerURL + "/digimage.jsp?"
                    834:                 
1.35      casties   835:         return msg+"\n\nfixed all zogilib instances in: "+obj.title
                    836: 
1.8       dwinter   837:           
1.1       dwinter   838: def manage_addZogiLibForm(self):
                    839:     """interface for adding zogilib"""
1.18      casties   840:     pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/addZogiLibForm')).__of__(self)
1.1       dwinter   841:     return pt()
                    842: 
1.44      casties   843: def manage_addZogiLib(self,id,title,dlServerURL,version="book",basePath="",dlTarget=None,dlToolbarBaseURL=None,RESPONSE=None):
1.1       dwinter   844:     """add dgilib"""
1.43      casties   845:     newObj=zogiLib(id,title,dlServerURL, version, basePath, dlTarget, dlToolbarBaseURL)
1.1       dwinter   846:     self.Destination()._setObject(id,newObj)
                    847:     if RESPONSE is not None:
                    848:         RESPONSE.redirect('manage_main')
1.29      casties   849: 
                    850: 
                    851: class zogiLibPageTemplate(ZopePageTemplate):
                    852:     """pageTemplate Objekt"""
                    853:     meta_type="zogiLib_pageTemplate"
                    854: 
                    855: 
                    856: ## def __init__(self, id, text=None, contentType=None):
                    857: ##         self.id = str(id)
                    858: ##         self.ZBindings_edit(self._default_bindings)
                    859: ##         if text is None:
                    860: ##             text = open(self._default_cont).read()
                    861: ##         self.pt_edit(text, contentType)
                    862: 
                    863: def manage_addZogiLibPageTemplateForm(self):
                    864:     """Form for adding"""
                    865:     pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/addZogiLibPageTemplateForm')).__of__(self)
                    866:     return pt()
                    867: 
1.63    ! casties   868: def manage_addZogiLibPageTemplate(self, title=None, layout=None, text=None,
1.29      casties   869:                            REQUEST=None, submit=None):
                    870:     "Add a Page Template with optional file content."
                    871: 
1.62      casties   872:     if not layout: layout = "book"
1.63    ! casties   873:     id = 'main_%s'%layout
1.29      casties   874:     self._setObject(id, zogiLibPageTemplate(id))
                    875:     ob = getattr(self, id)
1.62      casties   876:     ob.pt_edit(open(os.path.join(package_home(globals()),'zpt/main_%s.zpt'%layout)).read(),None)
1.29      casties   877:     if title:
                    878:         ob.pt_setTitle(title)
                    879:     try:
1.63    ! casties   880:         url = self.DestinationURL()
1.29      casties   881:     except AttributeError:
1.63    ! casties   882:         url = REQUEST['URL1']
1.29      casties   883:         
1.63    ! casties   884:     url = "%s/%s" % (url, urllib.quote(id))
        !           885:     REQUEST.RESPONSE.redirect(url+'/manage_main')
1.29      casties   886:     return ''
1.35      casties   887: 

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