|
|
| version 1.167, 2004/08/31 17:20:31 | version 1.176, 2004/10/06 13:02:56 |
|---|---|
| Line 32 from Acquisition import Implicit | Line 32 from Acquisition import Implicit |
| from ECHO_helpers import displayTypes | from ECHO_helpers import displayTypes |
| import urllib | import urllib |
| import time | import time |
| from Ft.Xml.Domlette import NonvalidatingReader | |
| from Ft.Xml.Domlette import PrettyPrint | |
| from Ft.Xml import EMPTY_NAMESPACE | |
| import Ft.Xml.XPath | |
| import cStringIO | |
| try: | try: |
| from psycopg import libpq | from psycopg import libpq |
| Line 390 def writeMetadata(url,metadict,project=N | Line 396 def writeMetadata(url,metadict,project=N |
| metanode.removeChild(nodeOld[0]).unlink() | metanode.removeChild(nodeOld[0]).unlink() |
| metanodeneu=dom.createElement(metaData) | metanodeneu=dom.createElement(metaData) |
| try: | metanodetext=dom.createTextNode(metadict[metaData]) |
| metanodetext=dom.createTextNode(unicode(metadict[metaData],"utf-8")) | #try: |
| except: | #metanodetext=dom.createTextNode(unicode(metadict[metaData],"utf-8")) |
| metanodetext=dom.createTextNode(metadict[metaData].encode('utf-8')) | #except: |
| #metanodetext=dom.createTextNode(metadict[metaData].encode('utf-8')) | |
| metanodeneu.appendChild(metanodetext) | metanodeneu.appendChild(metanodetext) |
| metanode.appendChild(metanodeneu) | metanode.appendChild(metanodeneu) |
| Line 420 def writeMetadata(url,metadict,project=N | Line 427 def writeMetadata(url,metadict,project=N |
| if digiliburlprefix: | if digiliburlprefix: |
| updateTextToolNode('digiliburlprefix',digiliburlprefix) | updateTextToolNode('digiliburlprefix',digiliburlprefix) |
| try: | |
| return dom.toxml().encode('utf-8') | return dom.toxml().encode('utf-8') |
| except: | |
| return dom.toxml('utf-8') | |
| Line 1028 class ECHO_resource(Folder,Persistent): | Line 1038 class ECHO_resource(Folder,Persistent): |
| path=re.sub('http://content.mpiwg-berlin.mpg.de','',path) # falls content als server | path=re.sub('http://content.mpiwg-berlin.mpg.de','',path) # falls content als server |
| path=re.sub('http://foxridge.rz-berlin.mpg.de','',path) # falls foxridge als server | path=re.sub('http://foxridge.rz-berlin.mpg.de','',path) # falls foxridge als server |
| path=re.sub('http://vision.rz-berlin.mpg.de','',path) # falls vision als server | path=re.sub('http://vision.rz-berlin.mpg.de','',path) # falls vision als server |
| path=re.sub('http://echo.mpiwg-berlin.mpg.de','',path) # falls echo | |
| path=re.sub('/index.meta','',path) | path=re.sub('/index.meta','',path) |
| Line 1091 class ECHO_resource(Folder,Persistent): | Line 1102 class ECHO_resource(Folder,Persistent): |
| path=re.sub('http://foxridge.rz-berlin.mpg.de:8080','',path) # falls foxridge als server | path=re.sub('http://foxridge.rz-berlin.mpg.de:8080','',path) # falls foxridge als server |
| path=re.sub('http://foxridge.rz-berlin.mpg.de','',path) # falls foxridge als server | path=re.sub('http://foxridge.rz-berlin.mpg.de','',path) # falls foxridge als server |
| path=re.sub('http://content.mpiwg-berlin.mpg.de','',path) # falls content als server | path=re.sub('http://content.mpiwg-berlin.mpg.de','',path) # falls content als server |
| path=re.sub('http://echo.mpiwg-berlin.mpg.de','',path) # falls echo | |
| path=re.sub('http://vision.rz-berlin.mpg.de','',path) # falls vision als server | path=re.sub('http://vision.rz-berlin.mpg.de','',path) # falls vision als server |
| Line 1135 class ECHO_resource(Folder,Persistent): | Line 1147 class ECHO_resource(Folder,Persistent): |
| texttools=dom.getElementsByTagName('texttool') | texttools=dom.getElementsByTagName('texttool') |
| text=texttools[0].getElementsByTagName('text') | text=texttools[0].getElementsByTagName('text') |
| texturl=getText(text[0].childNodes) | texturl=getText(text[0].childNodes) |
| if not (texturl.split(":")[0] in ['http','ftp','file']): | |
| texturl=re.sub("//","/",texturl) | |
| #return texturl+"::"+texturl.split(":")[0] | |
| if not noredirect: | if not noredirect: |
| self.REQUEST.RESPONSE.setHeader('Content-Type','text/xml') | self.REQUEST.RESPONSE.setHeader('Content-Type','text/xml') |
| self.REQUEST.RESPONSE.redirect(texturl) | self.REQUEST.RESPONSE.redirect(texturl) |
| Line 2089 class ECHO_collection(Folder, Persistent | Line 2103 class ECHO_collection(Folder, Persistent |
| pt=PageTemplateFile('Products/ECHO_content/zpt/changeViewerTemplateSet').__of__(self) | pt=PageTemplateFile('Products/ECHO_content/zpt/changeViewerTemplateSet').__of__(self) |
| return pt() | return pt() |
| def getViewerTemplateSets(self,obj_ids=None): | def getViewerTemplateSets(self,obj_ids=None,RESPONSE=None): |
| """Get the ViewerTemplateSet title for configuration""" | """Get the ViewerTemplateSet title for configuration""" |
| ret=[] | ret=[] |
| Line 2278 class ECHO_collection(Folder, Persistent | Line 2292 class ECHO_collection(Folder, Persistent |
| def getCollectionTreeXML(self): | def getCollectionTreeXML(self): |
| """Tree as XML""" | """Tree as XML""" |
| def addPassWd(str): | |
| """adds a user/passwd to an url""" | |
| txt2=re.sub(r"(http://)(.*?)","\g<1>www:3333@\g<2>",str) | |
| return txt2 | |
| def getCollection(object,depth=0): | def getCollection(object,depth=0): |
| depth+=1 | depth+=1 |
| collections="" | collections="" |
| Line 2285 class ECHO_collection(Folder, Persistent | Line 2304 class ECHO_collection(Folder, Persistent |
| element=getattr(object,entry) | element=getattr(object,entry) |
| try: | try: |
| if element.meta_type in ["ECHO_collection","ECHO_group"]: | if element.meta_type in ["ECHO_collection","ECHO_group"]: |
| collections+="<element name=\""+quote(element.title)+"\" url=\""+element.absolute_url()+"\">" | collections+="<element name=\""+quote(element.title)+"\" url=\""+addPassWd(element.absolute_url())+"\">" |
| collections+=getCollection(element,depth)+"</element>\n" | collections+=getCollection(element,depth)+"</element>\n" |
| except: | except: |
| """nothing""" | """nothing""" |
| Line 2542 class ECHO_collection(Folder, Persistent | Line 2561 class ECHO_collection(Folder, Persistent |
| else: | else: |
| return "#dddddd" | return "#dddddd" |
| def changeECHO_collection(self,title,label,description,contentType,responsible,weight,secondaryLink,secondaryLinkTitle,credits=None,sortfield="weight",coords=None,RESPONSE=None,imageTag="",bgcolour="",viewClassification=None,location=None): | def changeECHO_collection(self,title,label,description,contentType,responsible,weight,secondaryLink,secondaryLinkTitle,credits=None,sortfield="weight",coords=None,RESPONSE=None,imageTag="",bgcolour="",viewClassification=None,location=None,isAlwaysClickable=None): |
| """Aenderung der Properties""" | """Aenderung der Properties""" |
| self.secondaryLink=secondaryLink | self.secondaryLink=secondaryLink |
| Line 2551 class ECHO_collection(Folder, Persistent | Line 2570 class ECHO_collection(Folder, Persistent |
| self.bgcolour=bgcolour | self.bgcolour=bgcolour |
| self.viewClassification=viewClassification | self.viewClassification=viewClassification |
| self.location=location | self.location=location |
| self.isAlwaysClickable=isAlwaysClickable | |
| if coords: | if coords: |
| coordsnew=[ string.split(x,",") for x in coords] | coordsnew=[ string.split(x,",") for x in coords] |
| Line 2570 class ECHO_collection(Folder, Persistent | Line 2590 class ECHO_collection(Folder, Persistent |
| if RESPONSE is not None: | if RESPONSE is not None: |
| RESPONSE.redirect('manage_main') | RESPONSE.redirect('manage_main') |
| def setAlwaysClickable(self,flag="yes"): | |
| """set clickable""" | |
| if flag=="yes": | |
| self.isAlwaysClickable="yes" | |
| else: | |
| self.isAlwaysClickable=None | |
| return flag | |
| def showOverview(self): | def showOverview(self): |
| """overview""" | """overview""" |
| Line 3478 class ECHO_root(Folder,Persistent,Implic | Line 3506 class ECHO_root(Folder,Persistent,Implic |
| for link in links: | for link in links: |
| link.tagName="a" | link.tagName="a" |
| ref=link.getAttribute("ref") | ref=link.getAttribute("ref") |
| pn=link.getAttribute("page") | |
| if self.checkRef(ref): | if self.checkRef(ref): |
| if pn: | |
| link.setAttribute("href",self.aq_parent.absolute_url()+"/vlp_coll?id="+ref+"&p="+pn) | |
| else: | |
| link.setAttribute("href",self.aq_parent.absolute_url()+"/vlp_coll?id="+ref) | link.setAttribute("href",self.aq_parent.absolute_url()+"/vlp_coll?id="+ref) |
| newxml=dom.toxml('utf-8') | newxml=dom.toxml('utf-8') |
| retStr=regexpTXT.search(newxml) | retStr=regexpTXT.search(newxml) |
| Line 3492 class ECHO_root(Folder,Persistent,Implic | Line 3526 class ECHO_root(Folder,Persistent,Implic |
| def xml2html(self,str,quote="yes"): | def xml2html(self,str,quote="yes"): |
| """link2html fuer VLP muss hier noch raus""" | """link2html fuer VLP muss hier noch raus""" |
| #print str | |
| if str: | if str: |
| if quote=="yes2": | if quote=="yes2": |
| str=re.sub("\&","&",str) | str=re.sub("\&","&",str) |
| dom=xml.dom.minidom.parseString(str) | #dom=xml.dom.minidom.parseString(str) |
| links=dom.getElementsByTagName("link") | dom = NonvalidatingReader.parseString(str,"http://www.mpiwg-berlin.mpg.de/") |
| #links=dom.getElementsByTagName("link") | |
| links=Ft.Xml.XPath.Evaluate(".//link", contextNode=dom) | |
| for link in links: | |
| #link.tagName="a" | |
| ref=link.getAttributeNS(EMPTY_NAMESPACE,"ref") | |
| pn=link.getAttributeNS(EMPTY_NAMESPACE,"page") | |
| cns=link.childNodes[0:] | |
| newLink=dom.createElementNS(EMPTY_NAMESPACE,"a") | |
| for x in cns: | |
| newLink.appendChild(x) | |
| for link in links: | |
| link.tagName="a" | |
| ref=link.getAttribute("ref") | |
| if self.checkRef(ref): | |
| link.setAttribute("href",self.aq_parent.absolute_url()+"/vlp_coll?id="+ref) | |
| str= dom.toxml() | |
| link.parentNode.replaceChild(newLink,link) | |
| if self.checkRef(ref): | |
| if pn: | |
| newLink.setAttributeNS(EMPTY_NAMESPACE,"href",self.aq_parent.absolute_url()+"/vlp_coll?id="+ref+"&p="+pn) | |
| else: | |
| newLink.setAttributeNS(EMPTY_NAMESPACE,"href",self.aq_parent.absolute_url()+"/vlp_coll?id="+ref) | |
| #str= dom.toxml('utf-8') | |
| buf = cStringIO.StringIO() | |
| PrettyPrint(dom, stream=buf, encoding='UTF-8') | |
| str = buf.getvalue() | |
| buf.close() | |
| #str=PrettyPrint(dom.documentElement,encoding='UTF-8') | |
| #print link.toxml('utf-8') | #print link.toxml('utf-8') |
| #print type(str) | |
| retStr=regexpPage.search(str) | retStr=regexpPage.search(str) |
| try: # hack warum fehtl manchmal page?? | |
| return retStr.group(1) | return retStr.group(1) |
| except: | |
| return str | |
| return "" | return "" |
| def checkRef(self,ref): | def checkRef(self,ref): |
| dbs={'vl_literature':'AND CD LIKE \'%lise%\'','vl_technology':'','vl_people':''} | if ref[0:3]=='lit': |
| if len(self.library_data({ 'id':ref}))>0: | |
| return 1 | |
| try: | |
| if ref[0:7]=="tec_cat": | |
| return 1 | |
| except: | |
| """nothing""" | |
| dbs={'vl_technology':'','vl_people':'','vl_sites':''} | |
| res=None | res=None |
| for db in dbs.keys(): | for db in dbs.keys(): |
| res=res or self.search(var=str("select reference from %s where reference =\'%s\' %s"%(db,ref,dbs[db]))) | res=res or self.search(var=str("select reference from %s where reference =\'%s\' %s"%(db,ref,dbs[db]))) |
| return res | return res |
| Line 3548 class ECHO_root(Folder,Persistent,Implic | Line 3612 class ECHO_root(Folder,Persistent,Implic |
| <partners>""" | <partners>""" |
| for partner in partners: | for partner in partners: |
| ret+="""<partner id="%s" title="%s"/>\n"""%(partner.getId(),unicode(partner.title,'utf-8','replace')) | ret+="""<partner id="%s" title="%s"/>\n"""%(partner.getId(),partner.title) |
| return ret+"\n</partners>" | return ret+"\n</partners>" |
| Line 3655 class ECHO_root(Folder,Persistent,Implic | Line 3719 class ECHO_root(Folder,Persistent,Implic |
| def getMetaDatasXML(self,viewerType=None,filter=None): | def getMetaDatasXML(self,viewerType=None,filter=None): |
| """gebe all ressourcen aus""" | """gebe all ressourcen aus""" |
| # check if the request's host part was OK | |
| http_host = self.REQUEST['HTTP_HOST'] | |
| host_port = self.REQUEST['SERVER_PORT'] | |
| fix_host = None | |
| if http_host and http_host.rfind(host_port) == -1: | |
| print "HTTP_HOST needs fixing!" | |
| fix_host = http_host + ":" + host_port | |
| ret="""<?xml version="1.0" ?> | ret="""<?xml version="1.0" ?> |
| <index>""" | <index>""" |
| for resource in self.ZopeFind(self,obj_metatypes=['ECHO_resource'],search_sub=1): | for resource in self.ZopeFind(self,obj_metatypes=['ECHO_resource'],search_sub=1): |
| echo_url=resource[1].absolute_url() | echo_url=resource[1].absolute_url() |
| if fix_host: | |
| #print "replacing ", http_host, " by ", fix_host | |
| echo_url = string.replace(echo_url, http_host, fix_host, 1) | |
| if hasattr(resource[1],'link'): | if hasattr(resource[1],'link'): |
| meta_url=echo_url+"/getMetaDataXML" | meta_url=echo_url+"/getMetaDataXML" |
| Line 3678 class ECHO_root(Folder,Persistent,Implic | Line 3753 class ECHO_root(Folder,Persistent,Implic |
| ret +="""\n</index>""" | ret +="""\n</index>""" |
| self.REQUEST.RESPONSE.setHeader("Content-Type", "text/xml") | self.REQUEST.RESPONSE.setHeader("Content-Type", "text/xml") |
| self.REQUEST.RESPONSE.write(ret) | self.REQUEST.RESPONSE.write(ret) |