--- ECHO_content/ECHO_helpers.py 2012/09/03 14:48:22 1.103.2.7 +++ ECHO_content/ECHO_helpers.py 2012/01/03 13:02:31 1.104 @@ -11,7 +11,6 @@ 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 @@ -20,7 +19,8 @@ import bz2 import xmlrpclib import sys import logging -#import amara +import amara +from xml.sax.saxutils import escape #erstzt logging def logger(txt,method,txt2): @@ -34,7 +34,7 @@ def normalizeCt(str): #str= str.replace(" ","_") return str.replace("-"," ").lower() -#decode and compress for xmlrpc communication +#decode and compress for xmlrpc communication with OSAS_server def encodeRPC(string): return base64.encodestring(bz2.compress(string)) @@ -132,9 +132,6 @@ 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) @@ -147,8 +144,8 @@ class ECHO_basis: def showRDF(self): """showrdf""" self.REQUEST.RESPONSE.setHeader('Content-Type','text/xml') - ret="""\n\n""" + ret="""\n\n""" ret+=self.getRDF(urn="echo:collectionroot")+"\n" @@ -160,7 +157,7 @@ class ECHO_basis: def RDF(self): """showrdf""" self.REQUEST.RESPONSE.setHeader('Content-Type','text/xml') - ret="""\n\n""" + ret="""\n\n""" ret+=self.getRDF(urn=self.absolute_url())+"\n" @@ -252,7 +249,6 @@ class ECHO_basis: return self.unicodify(getattr(self,'description','')); - def getTitle(self): """title""" if hasattr(self,'getLanguage'): @@ -265,9 +261,12 @@ class ECHO_basis: locale=self.ZopeFind(self,obj_ids=["locale_"+lang]) if locale: - return unicodify(locale[0][1].title) - - return unicodify(self.title) + return self.decode(locale[0][1].title) + else: + try: + return self.decode(self.title) + except: + return self.title def getLabel(self): """title""" @@ -294,7 +293,7 @@ class ECHO_basis: ret=self.getId() return ret - return unicodify(self.label) + return self.decode(self.label) def changeECHOEntriesForm(self): """change Entries for the ECHO Navigation environment""" @@ -326,7 +325,9 @@ class ECHO_basis: def getOverview(self): """map overview graphics""" #return self.aq_parent.ZopeFind(self.aq_parent,obj_ids=['overview'])[0][1] - return getattr(self, 'overview', None) + if self.hasOverview(): + return getattr(self, 'overview') + return None def getMapAreas(self): """returns the list of MapAreas""" @@ -371,7 +372,7 @@ class ECHO_basis: res = self.ZopeFind(self, obj_metatypes=('ECHO_mapText')) if len(res) > 0: text = res[0][1] - return unicodify(text) + return text return None def ECHO_graphicEntry(self): @@ -441,10 +442,10 @@ class ECHO_basis: def createMapImg(self): """generate img-tag for map""" - bt = browserType(self) + bt = BrowserCheck(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 +459,7 @@ class ECHO_basis: def createMapLink(self, ob, text=None, target="_blank"): """generate map link""" - bt = browserType(self) + bt = BrowserCheck(self) id = ob.getFullId() url = ob.getTargetUrl() if url == "": @@ -479,9 +480,8 @@ class ECHO_basis: text = "link" tiptext = ob.getTip() - tag = "" - if bt['isN4']: + if bt.isN4: # N4 needs layer for highlighting tag += '" @@ -490,15 +490,12 @@ class ECHO_basis: tag = '" return tag 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 = browserType(self) + bt = BrowserCheck(self) id = ob.getFullId() link = ob.getLinkId() url = ob.getTargetUrl() @@ -513,9 +510,9 @@ class ECHO_basis: else: targetattr = 'target="%s"'%target tiptext = ob.getTip() - tag = "" - if bt['isN4']: + + if bt.isN4: # # N4 needs layer and img elements # @@ -578,7 +575,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: @@ -593,7 +590,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""" @@ -882,11 +863,11 @@ def getRDFDescription(self,linkURL,urn=N about2=about%urn if not nameDef: if hasattr(self,'label') and not (self.label==""): - name2=name%self.label + name2=name%escape(self.label) elif not self.title=="": - name2=name%self.title + name2=name%escape(self.title) else: - name2=name%self.getId() + name2=name%escape(self.getId()) name2=re.sub('&','&',name2) else: @@ -1035,30 +1016,28 @@ def sendFile(self, filename, type): return -def browserType(zope): +class BrowserCheck: """check the browsers request to find out the browser type""" - 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 __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 def writeMetadata(url,metadict,project=None,startpage=None,xslt=None,thumbtemplate=None,topbar=None,digiLibTemplate=None,xmlfrag=None,digiliburlprefix=None): @@ -1103,12 +1082,13 @@ def writeMetadata(url,metadict,project=N try: dom=xml.dom.minidom.parseString(geturl) + except: logger("ECHO writeMetadata",logging.ERROR,"Cannot parse: "+url+"
"+geturl) return (None,"Cannot parse: "+url+"
"+geturl) - + logging.debug("getting:"+geturl) metanodes=dom.getElementsByTagName('bib') if not metanodes: @@ -1180,7 +1160,52 @@ 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""" + logging.debug("getting:" +url) + 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[node.tagName]=getText(node.childNodes) + + except: + """nothing""" + + return (metadict,"") class MapArea(SimpleItem): @@ -1275,23 +1300,16 @@ class MapArea(SimpleItem): if self.tip is None: if hasattr(self, 'aq_parent'): parent = self.aq_parent - # text-popup type if parent.contentType == 'text-popup': - return unicodify(parent.description) - - # use map-text - text = parent.getMapText() - if text is not None: - return text() - - return unicodify(self.tip) + return parent.description + return self.tip def setTip(self, text): """sets the text""" self.tiptext = text def getText(self): - """returns the text for the area""" + """returns the text fpr the area""" if hasattr(self, 'aq_parent'): parent = self.aq_parent text = parent.getMapText() @@ -1304,8 +1322,8 @@ class MapArea(SimpleItem): """returns the link label""" if self.label is None: if hasattr(self, 'aq_parent'): - return unicodify(self.aq_parent.label or self.aq_parent.id) - return unicodify(self.label) + return self.aq_parent.label or self.aq_parent.id + return self.label def getTargetUrl(self): """returns the URL of the linked object"""