--- ECHO_content/ECHO_helpers.py 2010/10/11 13:15:00 1.103 +++ ECHO_content/ECHO_helpers.py 2012/01/19 19:03:28 1.103.2.4 @@ -11,6 +11,7 @@ from OFS.SimpleItem import SimpleItem from Globals import package_home import Globals from AccessControl import ClassSecurityInfo +from Acquisition import aq_parent,aq_chain,aq_base import os.path from OFS.Folder import Folder import ECHO_collection @@ -19,7 +20,7 @@ import bz2 import xmlrpclib import sys import logging -import amara +#import amara #erstzt logging def logger(txt,method,txt2): @@ -131,6 +132,9 @@ class ECHO_basis: """return utf-8 encoded string object for string or unicode object s""" return utf8ify(s) + def getBrowserType(self): + """returns browserType object""" + return browserType(self) def manage_addECHO_locale(self,lang,title,label,text=None,content_type=None,RESPONSE=None): return ECHO_collection.manage_addECHO_locale(self,lang,title,label) @@ -324,9 +328,7 @@ class ECHO_basis: def getOverview(self): """map overview graphics""" #return self.aq_parent.ZopeFind(self.aq_parent,obj_ids=['overview'])[0][1] - if self.hasOverview(): - return getattr(self, 'overview') - return None + return getattr(self, 'overview', None) def getMapAreas(self): """returns the list of MapAreas""" @@ -441,10 +443,10 @@ class ECHO_basis: def createMapImg(self): """generate img-tag for map""" - bt = BrowserCheck(self) + bt = browserType(self) tag = "" src = self.getOverview().absolute_url() - if bt.isN4: + if bt['isN4']: # N4 needs ilayer to create an id tag += ''%src else: @@ -458,7 +460,7 @@ class ECHO_basis: def createMapLink(self, ob, text=None, target="_blank"): """generate map link""" - bt = BrowserCheck(self) + bt = browserType(self) id = ob.getFullId() url = ob.getTargetUrl() if url == "": @@ -480,7 +482,7 @@ class ECHO_basis: tiptext = ob.getTip() tag = "" - if bt.isN4: + if bt['isN4']: # N4 needs layer for highlighting tag += '" @@ -494,7 +496,7 @@ class ECHO_basis: def createMapAux(self, ob, arrowsrc="http://nausikaa2.rz-berlin.mpg.de/digitallibrary/servlet/Scaler/?dw=15&fn=icons/pfeil", circlesrc="http://nausikaa2.rz-berlin.mpg.de/digitallibrary/servlet/Scaler/?dw=15&fn=icons/kreis", target="_blank",backLink=None,alternativArrowsrc="http://nausikaa2.rz-berlin.mpg.de/digitallibrary/servlet/Scaler/?dw=15&fn=icons/pfeil_blau"): """generate map link image, text and other stuff""" - bt = BrowserCheck(self) + bt = browserType(self) id = ob.getFullId() link = ob.getLinkId() url = ob.getTargetUrl() @@ -511,7 +513,7 @@ class ECHO_basis: tiptext = ob.getTip() tag = "" - if bt.isN4: + if bt['isN4']: # # N4 needs layer and img elements # @@ -574,7 +576,7 @@ class ECHO_basis: if float(rot) < 0: marksrc = circlesrc - if bt.isIEWin and bt.versIE > 5: + if bt['isIEWin'] and bt['versIE'] > 5: # IE/Win 5.5 has "feature" for PNG transparency tag += ''%(id,marksrc,rot,marksrc,rot) else: @@ -589,7 +591,7 @@ class ECHO_basis: tag += '' else: # DOM - Area - if bt.isIE: + if bt['isIE']: # IE needs transparent img for area tag += '"+ret+"Rerenderd all links to resources in: "+self.title+"" -def reloadMetaDataFromStorage(self,RESPONSE=None): - """copy metadata from the storage to ECHO""" - ret="" - resources=self.ZopeFind(self,obj_metatypes=['ECHO_resource'],search_sub=1) - if RESPONSE is not None: - RESPONSE.setHeader("Content-Type", type) - RESPONSE.write("\n") - - for resource in resources: - x=str(resource[1].copyIndex_meta2echo_resource())+"
" - if RESPONSE is not None: - RESPONSE.write(x+"\n") - - ret+=x - if RESPONSE is not None: - #RESPONSE.redirect('./manage_main') - RESPONSE.write( "") - - return ret def getRDFDescription(self,linkURL,urn=None,nameDef=None,typeName=None,ap=""): """rdf""" @@ -1015,28 +1033,30 @@ def sendFile(self, filename, type): return -class BrowserCheck: +def browserType(zope): """check the browsers request to find out the browser type""" - - def __init__(self, zope): - """initialisiere""" - self.ua = zope.REQUEST.get_header("HTTP_USER_AGENT") - self.isN4 = False - self.isIE = False - if string.find(self.ua, 'MSIE') > -1: - self.isIE = True - else: - self.isN4 = string.find(self.ua, 'Mozilla/4.') > -1 - try: - self.nav = self.ua[string.find(self.ua, '('):] - ie = string.split(self.nav, "; ")[1] - if string.find(ie, "MSIE") > -1: - self.versIE = string.split(ie, " ")[1] - except: pass - self.isMac = string.find(self.ua, 'Macintosh') > -1 - self.isWin = string.find(self.ua, 'Windows') > -1 - self.isIEWin = self.isIE and self.isWin - self.isIEMac = self.isIE and self.isMac + bt = {} + ua = zope.REQUEST.get_header("HTTP_USER_AGENT") + bt['ua'] = ua + bt['isN4'] = False + bt['isIE'] = False + if string.find(ua, 'MSIE') > -1: + bt['isIE'] = True + else: + bt['isN4'] = string.find(ua, 'Mozilla/4.') > -1 + try: + nav = ua[string.find(ua, '('):] + bt['nav'] = nav + ie = string.split(nav, "; ")[1] + if string.find(ie, "MSIE") > -1: + bt['versIE'] = string.split(ie, " ")[1] + except: pass + + bt['isMac'] = string.find(ua, 'Macintosh') > -1 + bt['isWin'] = string.find(ua, 'Windows') > -1 + bt['isIEWin'] = bt['isIE'] and bt['isWin'] + bt['isIEMac'] = bt['isIE'] and bt['isMac'] + return bt def writeMetadata(url,metadict,project=None,startpage=None,xslt=None,thumbtemplate=None,topbar=None,digiLibTemplate=None,xmlfrag=None,digiliburlprefix=None): @@ -1158,51 +1178,7 @@ def writeMetadata(url,metadict,project=N return dom.toxml(encoding='utf-8') -def readMetadata(url): - """Methode zum Auslesen der Metadateninformation zu einer Resource - Vorerst noch Typ bib""" - - metadict={} - try: - geturl="" - for line in urlopen(url).readlines(): - geturl=geturl+line - - - except: - return (None,"Cannot open: "+url) - - try: - dom=xml.dom.minidom.parseString(geturl) - except: - return (None,"Cannot parse: "+url+"
"+geturl) - - metanode=dom.getElementsByTagName('bib') - metadict['bib_type']='Book' - if len(metanode)==0: - metanode=dom.getElementsByTagName('archimedes') - metadict['bib_type']='Archimedes' - - - if not len(metanode)==0: - metacontent=metanode[0].childNodes - - try: - metadict['bib_type']=getText(dom.getElementsByTagName('bib')[0].attributes['type'].childNodes) - except: - """nothing""" - - for node in metacontent: - try: - #print urllib.unquote(getText(node.childNodes)),getText(node.childNodes) - #metadict[re.sub('-','_',node.tagName.lower())]=urllib.unquote(getText(node.childNodes)) - metadict[re.sub('-','_',node.tagName.lower())]=getText(node.childNodes) - - except: - """nothing""" - - return (metadict,"") class MapArea(SimpleItem):