--- OSAS/OSA_system/OSAS_addfiles.py 2004/03/25 09:57:47 1.20
+++ OSAS/OSA_system/OSAS_addfiles.py 2004/04/06 10:45:59 1.25
@@ -4,11 +4,7 @@
from OSAS_helpers import readArchimedesXML, getISO, getText
import os
import xml.dom.minidom
-try:
- from Products.ECHO_content import ECHO_collection
-except:
- print "Ignoring ECHO_collection import...."
-
+import re
import urllib
import OSAS_add
import OSAS_show
@@ -20,6 +16,20 @@ from Products.PageTemplates.PageTemplate
from Products.PageTemplates.PageTemplate import PageTemplate
import archive # check if this is necessary
+
+from xml.sax import make_parser
+from xml.sax.handler import ContentHandler
+
+def spaces(depth):
+ """needed in XMLtoTree"""
+ tmp=""
+ k=0
+ while k<2*depth:
+ k+=1
+ tmp=tmp+" "+" "
+ return tmp
+
+
class OSAS_add_Document(Folder):
"""Hinzufuegen eines Dokumentes zum Storage"""
security=ClassSecurityInfo()
@@ -52,13 +62,13 @@ class OSAS_add_Document(Folder):
security.declarePublic('index_html')
def index_html(self):
"""stantard aufruf"""
- return OSAS_add.add(self,no_upload=1)
+ return OSAS_add.add(self.standardMD,no_upload=1)
security.declarePublic('add2')
def add2(self):
""" anlegen naechster schritt"""
- return OSAS_add.add2(self)
+ return OSAS_add.add2(self.standardMD)
def add3(self):
"""Foldername"""
@@ -153,6 +163,7 @@ def manage_AddOSAS_add_Text(self,id,RESP
InitializeClass(OSAS_add_Text)
+
class OSAS_add_contextData(Folder):
"""Einfuegen eines Documentes in eine Collection"""
@@ -161,58 +172,77 @@ class OSAS_add_contextData(Folder):
meta_type='OSAS_add_contextData'
+ def XmlToTree(self,URL):
+ """Collection XML to Tree"""
+
+
+ class requestHandler(ContentHandler):
+ def __init__(self):
+ self.depth=0
+ self.retStr=""
+
+ def startElement(self,name,attrs):
+ if name=="element":
+ self.depth+=1
+ begin=""
+ end=""
+ if self.depth==1:
+ print "hi"
+ begin=""
+ end=""
+
+ self.retStr+=spaces(self.depth)+"%s"%(attrs.get('url'),begin+attrs.get('name')+end)+"
\n"
+
+
+
+ def endElement(self,name):
+ if name=="element":
+ self.depth-=1
+
+
+ try:
+ URL+="/getCollectionTreeXML"
+ parser=make_parser()
+ curHandler=requestHandler()
+ parser.setContentHandler(curHandler)
+
+ parser.parse(urllib.urlopen(URL))
+ return curHandler.retStr
+ except:
+ return urllib.urlopen(URL).read()
+
def __init__(self,id,collection):
self.id=id
self.collection=collection
- def getChilds(self,id,depth,items):
- list=[]
- for object in items:
- if (depth==object[2])&(id==object[0]):
- list.append(object)
- return list
-
- def printChilds(self,startItem,depth,items,enddepth):
-
- def spaces(depth):
- tmp=""
- k=0
- while k<2*depth:
- k+=1
- tmp=tmp+" "+" "
- return tmp
-
- def retLink(object):
- return "%s"% (string.join(object.getPhysicalPath(),"."),object.title)
-
- depth+=1
- childs=self.getChilds(startItem,depth,items)
- tmp=""
- for child in childs:
- if depth < enddepth:
- tmp=tmp+spaces(depth)
+
+
+
+ def getPartners(self,URL):
+ """Zeige Partnerliste"""
+ class requestHandler(ContentHandler):
+ def __init__(self):
+ self.ret=[]
- tmp= tmp+retLink(child[1])+"
"+self.printChilds(child[1],depth,items,enddepth)
- else:
- tmp=tmp+spaces(2*depth)
- tmp = tmp+retLink(child[1])
+ def startElement(self,name,attrs):
+ if name=="partner":
+ self.ret.append((attrs.get('id'),attrs.get('title')))
- return tmp
-
- def generateTree(self,depth=10):
- """Erzeugt HTML-Tree der Collection"""
-
- exec("items=self.getPhysicalRoot()."+self.collection+".getCollectionTree()")
- #print items[0][0]
- childs=self.printChilds(items[0][0],0,items,depth)
-
- return childs
+ URL+="/getPartnersXML"
+
+ try:
+
+ parser=make_parser()
+ curHandler=requestHandler()
+ parser.setContentHandler(curHandler)
+
+ parser.parse(urllib.urlopen(URL))
+ return curHandler.ret
+ except:
+ return [("",urllib.urlopen(URL).read())]
- def getPartners(self):
- """Zeige Partnerliste"""
- exec("items=self.getPhysicalRoot()."+self.collection+".partners.getPartners()")
- return items
+
def addContextData(self,path):
"""Hinzufügen zu einer Sammlung"""
try:
@@ -231,7 +261,7 @@ class OSAS_add_contextData(Folder):
return pt()
- def addContextData2(self,path,collection,context,science,practice,source_type,period,link,label,description,content_type,responsible,weight,credits=None):
+ def addContextData2(self,path,collection,link,label,description,content_type,responsible,weight,credits=None):
"""Hinzufuegen der Resource"""
splitted=path.split("/")
#print "BLU"
@@ -242,15 +272,23 @@ class OSAS_add_contextData(Folder):
#link=TOBEDONE"
"""Hinzufügen der Ressource"""
+ params=urllib.urlencode({'id':id,'title':title,'link':link,'label':label,'description':description,'content_type':content_type,'responsible':responsible,'weight':weight,'credits':credits,'metalink':metalink})
+
+ retStr=urllib.urlopen(collection+"/addResource",params).read()
+ if not retStr:
+ return "An Error occured adding the resource\n"
+
+ urllib.urlopen(collection+"/"+id+"/ECHO_getResourceMD").read()
+ #exec("collection_object=self"+collection)
- exec("collection_object=self"+collection)
+
- ECHO_collection.manage_addECHO_resource(collection_object,id,title,label,description,content_type,responsible,link,metalink,credits,weight,RESPONSE=None)
+ #ECHO_collection.manage_addECHO_resource(collection_object,id,title,label,description,content_type,responsible,link,metalink,credits,weight,RESPONSE=None)
#print "HI5"
- try:
- getattr(collection_object,id).ECHO_getResourceMD()
- except:
- """nothing"""
+ #try:
+ # getattr(collection_object,id).ECHO_getResourceMD()
+ #except:
+ # """nothing"""
#return "BLUByy"
return self.REQUEST.RESPONSE.redirect(self.REQUEST['URL2']+'?path='+path)
@@ -444,10 +482,10 @@ class OSAS_combineTextImage(Folder):
OSAS_add.combineTextImage2(self,path) # Add images
splitted=path.split("/")
linkPath=splitted[len(splitted)-1]
- linkViewerEnvironment="http://nausikaa2.mpiwg-berlin.mpg.de:86/cgi-bin/toc/toc.x.cgi?dir=%s&step=thumb" % linkPath
+ linkViewerEnvironment="http://nausikaa2.mpiwg-berlin.mpg.de/cgi-bin/toc/toc.x.cgi?dir=%s&step=thumb" % linkPath
self.REQUEST.SESSION['linkViewerEnvironment']=linkViewerEnvironment
- writeToContext(path,linkViewerEnvironment,"ECHO standard environment")
+ writeToContext(path,linkViewerEnvironment,"ECHO standard environment",unique="yes")
pt=PageTemplateFile('Products/OSA_system/zpt/AddOSAS_combineTextImageFinal.zpt').__of__(self)
@@ -461,11 +499,23 @@ class OSAS_combineTextImage(Folder):
else:
return None
-def writeToContext(path,link,description):
+def writeToContext(path,link,description,unique="no"):
"""Created an additional entry to the index.meta file of path"""
dom=xml.dom.minidom.parse(path+"/index.meta")
node=dom.getElementsByTagName('resource')[0]
+ if unique=="yes":
+
+ contexts=node.getElementsByTagName('context')
+ for context in contexts:
+ nameTag=getText(context.getElementsByTagName('name')[0].childNodes)
+ linkTag=getText(context.getElementsByTagName('link')[0].childNodes)
+
+ print "unique",context,nameTag,description,linkTag,link
+ linkTag=re.sub("\:86","",linkTag) # alter port 86 gleich ohne port nummer (hack)
+ if (nameTag==description) and (linkTag==link):
+ node.removeChild(context).unlink()
+
subnode=dom.createElement('context')
linknode=dom.createElement('link')