Annotation of zogiLib/zogiLib.py, revision 1.65

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.64      casties    21: ZOGIVERSION = "0.10.3b ROC 13.7.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.65    ! casties   392:     def createScalerImg(self, requestString=None, bottom=0, side=0, width=500, height=500, options=None):
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.65    ! casties   403:         # take insets from options if present
        !           404:         if options is not None:
        !           405:             side = options.get('side', side)
        !           406:             bottom = options.get('bottom', bottom)
1.24      casties   407:         # construct bottom and side insets
                    408:         b_par = ""
                    409:         s_par = ""
                    410:         if (bottom != 0) or (side != 0):
                    411:             b_par = "-" + str(int(bottom))
                    412:             s_par = "-" + str(int(side))
1.18      casties   413:         tag = ""
1.26      casties   414:         if bt['staticHTML']:
                    415:             tag += '<div id="scaler"><img id="pic" src="%s&dw=%i&dh=%i" /></div>'%(url, int(width-side), int(height-bottom))
1.18      casties   416:         else:
1.26      casties   417:             if bt['isN4']:
                    418:                 # N4 needs layers
                    419:                 tag += '<ilayer id="scaler">'
                    420:             else:
                    421:                 tag += '<div id="scaler">'
                    422:             tag += '<script type="text/javascript">'
                    423:             tag += "var ps = bestPicSize(getElement('scaler'));"
                    424:             # write img tag with javascript
                    425:             tag += 'document.write(\'<img id="pic" src="%s&dw=\'+(ps.width%s)+\'&dh=\'+(ps.height%s)+\'" />\');'%(url, s_par, b_par)
                    426:             tag += '</script>'
                    427:             if bt['isN4']:
                    428:                 tag += '</ilayer>'
                    429:             else:
                    430:                 tag += '</div>'
1.18      casties   431:         return tag
1.1       dwinter   432: 
1.26      casties   433:     def createScalerDiv(self, requestString = None, bottom = 0, side = 0, width=500, height=500):
1.23      casties   434:         """generate scaler img and table with navigation arrows"""
1.58      dwinter   435:         self.checkQuery()
1.24      casties   436:         if requestString != None or bottom != 0 or side != 0:
1.26      casties   437:             self.REQUEST.SESSION['scalerDiv'] = (requestString, bottom, side, width, height)
1.24      casties   438:         else:
                    439:             if self.REQUEST.SESSION.has_key('scalerDiv'):
1.26      casties   440:                 # make shure to remove unused parameter
1.24      casties   441:                 del self.REQUEST.SESSION['scalerDiv']
1.26      casties   442:                 
1.23      casties   443:         pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt/zogilib_img_div')).__of__(self)
                    444:         return pt()
                    445: 
1.1       dwinter   446:     def index_html(self):
                    447:         """main action"""
1.58      dwinter   448:         self.checkQuery()
1.59      casties   449:         tp = "main_template"
                    450:         tpt = self.layout
1.32      dwinter   451:         
1.60      casties   452:         if not hasattr(self, 'template'):
                    453:             # create template folder if it doesn't exist
1.61      casties   454:             print "no template folder -- creating"
1.60      casties   455:             self.manage_addFolder('template')
1.26      casties   456:             
1.60      casties   457:         pt = getattr(self.template, 'main_'+tpt)
1.18      casties   458:         return pt()
                    459: 
1.59      casties   460:     def checkQuery(self):
                    461:         """make shure that the query has been saved"""
                    462:         if not self.REQUEST.has_key('dlParams'):
                    463:             self.storeQuery()
1.1       dwinter   464: 
1.59      casties   465:     def storeQuery(self, more=None, withpt=False):
                    466:         """parse query parameters into a hash in REQUEST"""
                    467:         params = {}
1.1       dwinter   468:         for fm in self.REQUEST.form.keys():
1.59      casties   469:             params[fm] = self.REQUEST.form[fm]
1.21      casties   470:         # look for more
                    471:         if more:
                    472:             for fm in more.split('&'):
                    473:                 try:
                    474:                     pv = fm.split('=')
1.59      casties   475:                     params[pv[0]] = pv[1]
1.21      casties   476:                 except:
1.26      casties   477:                     pass
                    478:                 
1.21      casties   479:         # parse digilib mode parameter
1.59      casties   480:         if 'mo' in params:
                    481:             if len(params['mo']) > 0:
                    482:                 modes=params['mo'].split(',')
1.18      casties   483:         else:
1.59      casties   484:             modes = [];
                    485: 
                    486:         self.REQUEST.set('dlParams', params)
                    487:         self.REQUEST.set('dlModes', modes)
                    488:         
                    489:         # trigger get pt (from dlInfo) if requested
                    490:         if withpt:
                    491:             pt = self.getPT()
1.44      casties   492:             
1.59      casties   493:         return params
                    494:         
1.44      casties   495: 
1.53      casties   496:     def getDLParam(self, param, default=None):
                    497:         """returns parameter or default"""
1.59      casties   498:         self.checkQuery()
                    499:         dlParams = self.REQUEST.get('dlParams')
1.3       dwinter   500:         try:
1.59      casties   501:             return dlParams[param]
1.3       dwinter   502:         except:
1.53      casties   503:             return default
1.3       dwinter   504: 
1.18      casties   505:     def setDLParam(self, param, value):
                    506:         """sets parameter"""
1.59      casties   507:         self.checkQuery()
                    508:         dlParams = self.REQUEST.get('dlParams')
1.44      casties   509:         dlParams[param] = value
1.18      casties   510:         return
                    511: 
                    512:     def getAllDLParams(self):
                    513:         """parameter string for digilib"""
1.59      casties   514:         self.checkQuery()
                    515:         dlParams = self.REQUEST.get('dlParams')
1.18      casties   516:         # save modes
1.59      casties   517:         modes = self.REQUEST.get('dlModes')
                    518:         if modes:
                    519:             dlParams['mo'] = string.join(modes, ',')
1.18      casties   520:         # assemble query string
                    521:         ret = ""
                    522:         for param in dlParams.keys():
1.29      casties   523:             if dlParams[param] is None: continue
1.18      casties   524:             val = str(dlParams[param])
                    525:             if val != "":
                    526:                 ret += param + "=" + val + "&"
1.28      casties   527: 
1.18      casties   528:         # omit trailing "&"
                    529:         return ret.rstrip('&')
                    530:         
                    531:     def setDLParams(self,pn=None,ws=None,rot=None,brgt=None,cont=None):
                    532:         """setze Parameter"""
                    533: 
1.23      casties   534:         self.setDLParam('brgt', brgt)
                    535:         self.setDLParam('cont', cont)
                    536:         self.setDLParam('ws', ws)
                    537:         self.setDLParam('rot', rot)
1.18      casties   538: 
                    539:         if pn:
1.21      casties   540:             # unmark
                    541:             self.setDLParam('mk', None)
1.18      casties   542:             self.setDLParam('pn', pn)
                    543:             
                    544:         return self.display()
                    545: 
1.63      casties   546:     def getBrowserType(self):
                    547:         """get browser type object"""
                    548:         if self.REQUEST.SESSION.has_key('browserType'):
                    549:             return self.REQUEST.SESSION['browserType']
                    550:         else:
                    551:             bt = browserCheck(self)
                    552:             self.REQUEST.SESSION.set('browserType', bt)                        
                    553:             return bt
                    554: 
1.18      casties   555: 
                    556:     def display(self):
                    557:         """(re)display page"""
                    558:         params = self.getAllDLParams()
1.44      casties   559:             
1.21      casties   560:         if self.basePath:
                    561:             self.REQUEST.RESPONSE.redirect(self.REQUEST['URL2']+'?'+params)
                    562:         else:
                    563:             self.REQUEST.RESPONSE.redirect(self.REQUEST['URL1']+'?'+params)
1.18      casties   564: 
1.32      dwinter   565:     def getMetaFileName(self):
1.34      casties   566:         url=self.dlServerURL+'/dlContext-xml.jsp?'+self.getAllDLParams()
                    567:         return urlbase
1.26      casties   568: 
1.34      casties   569:     def getToolbarPageURL(self):
                    570:         """returns a toolbar-enabled page URL"""
1.37      casties   571:         url=self.dlToolbarBaseURL+self.getAllDLParams()
1.34      casties   572:         return url
1.32      dwinter   573:     
1.30      casties   574:     def getDLTarget(self):
                    575:         """returns dlTarget"""
                    576:         self.checkQuery()
                    577:         s = self.dlTarget
1.61      casties   578:         if (s is None) or (s == ""):
                    579: #            s = ""
                    580:             s = 'dl'
                    581:             if self.getDLParam('fn'):
                    582:                 s += "_" + self.getDLParam('fn')
                    583:             if self.getDLParam('pn'):
                    584:                 s += "_" + self.getDLParam('pn')
                    585: 
1.30      casties   586:         return s
                    587: 
1.59      casties   588:     def getPN(self):
1.61      casties   589:         """pagenumber"""
1.59      casties   590:         pn = int(self.getDLParam('pn', 1))
                    591:         return pn
                    592:     
1.18      casties   593:     def getPT(self):
1.61      casties   594:         """number of total pages"""
1.59      casties   595:         pt = self.getDLParam('pt', None)
                    596:         if pt is None:
                    597:             # get pt from dlInfo
                    598:             if self.REQUEST.has_key('dlInfo'):
                    599:                 info = self.REQUEST.get('dlInfo')
                    600:             else:
                    601:                 info = self.getDLInfo()
                    602:                 self.REQUEST.set('dlInfo', info)
                    603:             pt = int(info.get('pt', 1))
                    604:             self.setDLParam('pt', pt)
                    605:         return int(pt)
1.18      casties   606:     
                    607:     def hasMode(self, mode):
                    608:         """returns if mode is in the diglib mo parameter"""
1.59      casties   609:         return (mode in self.REQUEST.get('dlModes'))
1.18      casties   610: 
                    611:     def hasNextPage(self):
                    612:         """returns if there is a next page"""
                    613:         pn = self.getPN()
                    614:         pt = self.getPT()
                    615:         return (pn < pt)
                    616:    
                    617:     def hasPrevPage(self):
                    618:         """returns if there is a previous page"""
                    619:         pn = self.getPN()
                    620:         return (pn > 1)
1.1       dwinter   621: 
1.22      casties   622:     def canMoveLeft(self):
                    623:         """returns if its possible to move left"""
                    624:         wx = float(self.getDLParam('wx') or 0)
                    625:         return (wx > 0)
                    626: 
                    627:     def canMoveRight(self):
                    628:         """returns if its possible to move right"""
                    629:         wx = float(self.getDLParam('wx') or 0)
                    630:         ww = float(self.getDLParam('ww') or 1)
                    631:         return (wx + ww < 1)
                    632: 
                    633:     def canMoveUp(self):
                    634:         """returns if its possible to move up"""
                    635:         wy = float(self.getDLParam('wy') or 0)
                    636:         return (wy > 0)
                    637: 
                    638:     def canMoveDown(self):
                    639:         """returns if its possible to move down"""
                    640:         wy = float(self.getDLParam('wy') or 0)
                    641:         wh = float(self.getDLParam('wh') or 1)
                    642:         return (wy + wh < 1)
                    643: 
1.26      casties   644: 
                    645:     def dl_StaticHTML(self):
                    646:         """set rendering to static HTML"""
                    647:         self.checkQuery()
1.63      casties   648:         self.getBrowserType()['staticHTML'] = True
1.26      casties   649:         return self.display()
                    650: 
                    651:     def dl_DynamicHTML(self):
                    652:         """set rendering to dynamic HTML"""
                    653:         self.checkQuery()
1.63      casties   654:         self.getBrowserType()['staticHTML'] = False
1.26      casties   655:         return self.display()
1.1       dwinter   656:         
1.18      casties   657:     def dl_HMirror(self):
                    658:         """mirror action"""
1.44      casties   659:         modes = self.getSubSession('dlModes')
1.18      casties   660:         if 'hmir' in modes:
                    661:             modes.remove('hmir')
                    662:         else:
                    663:             modes.append('hmir')
1.1       dwinter   664: 
1.18      casties   665:         return self.display()
                    666:        
                    667:     def dl_VMirror(self):
                    668:         """mirror action"""
1.44      casties   669:         modes = self.getSubSession('dlModes')
1.18      casties   670:         if 'vmir' in modes:
                    671:             modes.remove('vmir')
                    672:         else:
                    673:             modes.append('vmir')
1.1       dwinter   674: 
1.18      casties   675:         return self.display()
1.1       dwinter   676: 
1.22      casties   677:     def dl_Zoom(self, z):
                    678:         """general zoom action"""
                    679:         ww1 = float(self.getDLParam('ww') or 1)
                    680:         wh1 = float(self.getDLParam('wh') or 1)
                    681:         wx = float(self.getDLParam('wx') or 0)
                    682:         wy = float(self.getDLParam('wy') or 0)
                    683:         ww2 = ww1 * z
                    684:         wh2 = wh1 * z
                    685:         wx += (ww1 - ww2) / 2
                    686:         wy += (wh1 - wh2) / 2
                    687:         ww2 = max(min(ww2, 1), 0)
                    688:         wh2 = max(min(wh2, 1), 0)
                    689:         wx = max(min(wx, 1), 0)
                    690:         wy = max(min(wy, 1), 0)
1.30      casties   691:         self.setDLParam('ww', cropf(ww2))
                    692:         self.setDLParam('wh', cropf(wh2))
                    693:         self.setDLParam('wx', cropf(wx))
                    694:         self.setDLParam('wy', cropf(wy))
1.22      casties   695:         return self.display()
                    696:         
                    697:     def dl_ZoomIn(self):
                    698:         """zoom in action"""
                    699:         z = 0.7071
                    700:         return self.dl_Zoom(z)
                    701: 
                    702:     def dl_ZoomOut(self):
                    703:         """zoom out action"""
                    704:         z = 1.4142
                    705:         return self.dl_Zoom(z)
                    706: 
                    707:     def dl_Move(self, dx, dy):
                    708:         """general move action"""
                    709:         ww = float(self.getDLParam('ww') or 1)
                    710:         wh = float(self.getDLParam('wh') or 1)
                    711:         wx = float(self.getDLParam('wx') or 0)
                    712:         wy = float(self.getDLParam('wy') or 0)
                    713:         wx += dx * 0.5 * ww
                    714:         wy += dy * 0.5 * wh
                    715:         wx = max(min(wx, 1), 0)
                    716:         wy = max(min(wy, 1), 0)
1.30      casties   717:         self.setDLParam('wx', cropf(wx))
                    718:         self.setDLParam('wy', cropf(wy))
1.22      casties   719:         return self.display()
                    720:         
                    721:     def dl_MoveLeft(self):
                    722:         """move left action"""
                    723:         return self.dl_Move(-1, 0)
                    724:     
                    725:     def dl_MoveRight(self):
                    726:         """move left action"""
                    727:         return self.dl_Move(1, 0)
                    728:     
                    729:     def dl_MoveUp(self):
                    730:         """move left action"""
                    731:         return self.dl_Move(0, -1)
                    732:     
                    733:     def dl_MoveDown(self):
                    734:         """move left action"""
                    735:         return self.dl_Move(0, 1)
                    736:     
1.18      casties   737:     def dl_WholePage(self):
                    738:         """zoom out action"""
                    739:         self.setDLParam('ww', 1)
                    740:         self.setDLParam('wh', 1)
                    741:         self.setDLParam('wx', 0)
                    742:         self.setDLParam('wy', 0)
                    743:         return self.display()
                    744:         
                    745:     def dl_PrevPage(self):
                    746:         """next page action"""
                    747:         pn = self.getPN() - 1
                    748:         if pn < 1:
                    749:             pn = 1
                    750:         self.setDLParam('pn', pn)
                    751:         # unmark
                    752:         self.setDLParam('mk', None)
                    753:         return self.display()
                    754:         
                    755:     def dl_NextPage(self):
                    756:         """next page action"""
                    757:         pn = self.getPN() + 1
                    758:         pt = self.getPT()
                    759:         if pn > pt:
                    760:             pn = pt
                    761:         self.setDLParam('pn', pn)
                    762:         # unmark
                    763:         self.setDLParam('mk', None)
                    764:         return self.display()
                    765: 
                    766:     def dl_FirstPage(self):
                    767:         """first page action"""
                    768:         self.setDLParam('pn', 1)
                    769:         # unmark
                    770:         self.setDLParam('mk', None)
                    771:         return self.display()
                    772:     
                    773:     def dl_LastPage(self):
                    774:         """last page action"""
                    775:         self.setDLParam('pn', self.getPT())
                    776:         # unmark
                    777:         self.setDLParam('mk', None)
                    778:         return self.display()
                    779: 
1.32      dwinter   780:     def dl_db(self,db):
                    781:         """set db"""
                    782:         self.setDLParam('db',db)
                    783:         self.display()
1.1       dwinter   784: 
1.18      casties   785:     def changeZogiLibForm(self):
                    786:         """Main configuration"""
                    787:         pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/changeZogiLibForm.zpt')).__of__(self)
                    788:         return pt()
1.1       dwinter   789:     
1.37      casties   790:     def changeZogiLib(self,title,dlServerURL, version, basePath, dlTarget, dlToolbarBaseURL, RESPONSE=None):
1.18      casties   791:         """change it"""
                    792:         self.title=title
1.35      casties   793:         self.dlServerURL=dlServerURL
1.21      casties   794:         self.basePath = basePath
1.18      casties   795:         self.layout=version
1.44      casties   796:         self.dlTarget = dlTarget
1.3       dwinter   797: 
1.37      casties   798:         if dlToolbarBaseURL:
                    799:             self.dlToolbarBaseURL = dlToolbarBaseURL
                    800:         else:
                    801:             self.dlToolbarBaseURL = dlServerURL + "/digimage.jsp?"
                    802: 
1.18      casties   803:         if RESPONSE is not None:
                    804:             RESPONSE.redirect('manage_main')
1.8       dwinter   805: 
1.35      casties   806: 
                    807: 
                    808:     ##
1.44      casties   809:     ## odds and ends
1.35      casties   810:     ##
                    811: 
                    812:     def repairZogilib(self, obj=None):
                    813:         """change stuff that broke on upgrading"""
                    814: 
                    815:         msg = ""
                    816: 
                    817:         if not obj:
                    818:             obj = self.getPhysicalRoot()
                    819: 
                    820:         print "starting in ", obj
                    821:         
                    822:         entries=obj.ZopeFind(obj,obj_metatypes=['zogiLib'],search_sub=1)
                    823: 
                    824:         for entry in entries:
                    825:             print "  found ", entry
1.37      casties   826:             #
                    827:             # replace digilibBaseUrl by dlServerURL
1.35      casties   828:             if hasattr(entry[1], 'digilibBaseUrl'):
1.37      casties   829:                 msg += "  fixing digilibBaseUrl in "+entry[0]+"\n"
1.36      casties   830:                 entry[1].dlServerURL = re.sub('/servlet/Scaler\?','',entry[1].digilibBaseUrl)
1.35      casties   831:                 del entry[1].digilibBaseUrl
                    832:                 
1.37      casties   833:             #
                    834:             # add dlToolbarBaseURL
                    835:             if not hasattr(entry[1], 'dlToolbarBaseURL'):
                    836:                 msg += "  fixing dlToolbarBaseURL in "+entry[0]+"\n"
                    837:                 entry[1].dlToolbarBaseURL = entry[1].dlServerURL + "/digimage.jsp?"
                    838:                 
1.35      casties   839:         return msg+"\n\nfixed all zogilib instances in: "+obj.title
                    840: 
1.8       dwinter   841:           
1.1       dwinter   842: def manage_addZogiLibForm(self):
                    843:     """interface for adding zogilib"""
1.18      casties   844:     pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/addZogiLibForm')).__of__(self)
1.1       dwinter   845:     return pt()
                    846: 
1.44      casties   847: def manage_addZogiLib(self,id,title,dlServerURL,version="book",basePath="",dlTarget=None,dlToolbarBaseURL=None,RESPONSE=None):
1.1       dwinter   848:     """add dgilib"""
1.43      casties   849:     newObj=zogiLib(id,title,dlServerURL, version, basePath, dlTarget, dlToolbarBaseURL)
1.1       dwinter   850:     self.Destination()._setObject(id,newObj)
                    851:     if RESPONSE is not None:
                    852:         RESPONSE.redirect('manage_main')
1.29      casties   853: 
                    854: 
                    855: class zogiLibPageTemplate(ZopePageTemplate):
                    856:     """pageTemplate Objekt"""
                    857:     meta_type="zogiLib_pageTemplate"
                    858: 
                    859: 
                    860: ## def __init__(self, id, text=None, contentType=None):
                    861: ##         self.id = str(id)
                    862: ##         self.ZBindings_edit(self._default_bindings)
                    863: ##         if text is None:
                    864: ##             text = open(self._default_cont).read()
                    865: ##         self.pt_edit(text, contentType)
                    866: 
                    867: def manage_addZogiLibPageTemplateForm(self):
                    868:     """Form for adding"""
                    869:     pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/addZogiLibPageTemplateForm')).__of__(self)
                    870:     return pt()
                    871: 
1.63      casties   872: def manage_addZogiLibPageTemplate(self, title=None, layout=None, text=None,
1.29      casties   873:                            REQUEST=None, submit=None):
                    874:     "Add a Page Template with optional file content."
                    875: 
1.62      casties   876:     if not layout: layout = "book"
1.63      casties   877:     id = 'main_%s'%layout
1.29      casties   878:     self._setObject(id, zogiLibPageTemplate(id))
                    879:     ob = getattr(self, id)
1.62      casties   880:     ob.pt_edit(open(os.path.join(package_home(globals()),'zpt/main_%s.zpt'%layout)).read(),None)
1.29      casties   881:     if title:
                    882:         ob.pt_setTitle(title)
                    883:     try:
1.63      casties   884:         url = self.DestinationURL()
1.29      casties   885:     except AttributeError:
1.63      casties   886:         url = REQUEST['URL1']
1.29      casties   887:         
1.63      casties   888:     url = "%s/%s" % (url, urllib.quote(id))
                    889:     REQUEST.RESPONSE.redirect(url+'/manage_main')
1.29      casties   890:     return ''
1.35      casties   891: 

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