# Methoden und Classen zum Hinzufuegen von Dokumenten from OSAS_helpers import readArchimedesXML, getISO, getText import os import xml.dom.minidom import re import urllib import OSAS_add import OSAS_show import string from OFS.Folder import Folder from AccessControl import ClassSecurityInfo from Globals import InitializeClass from Products.PageTemplates.PageTemplateFile import PageTemplateFile 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() def __init__(self,id): """initialize a new instance""" self.id = id meta_type='OSAS_add_Document' manage_options = Folder.manage_options+( {'label':'Main Config','action':'add_Document_config'}, ) security.declarePublic('add_Document_config') def add_Document_config(self): """Main configuration""" pt=PageTemplateFile('Products/OSA_system/zpt/ChangeOSAS_addDocument.zpt').__of__(self) return pt() security.declarePublic('change_OSAS_add_Document') def change_OSAS_add_Document(self,RESPONSE=None): """Change""" # self.RootFolderName=RootFolderName if RESPONSE is not None: RESPONSE.redirect('manage_main') security.declarePublic('index_html') def index_html(self): """stantard aufruf""" return OSAS_add.add(self.standardMD,no_upload=1) security.declarePublic('add2') def add2(self): """ anlegen naechster schritt""" return OSAS_add.add2(self.standardMD) def add3(self): """Foldername""" return OSAS_add.add3(self) def add4(self): """Applet""" return OSAS_add.add4(self) def add5(self): """Foldername""" return OSAS_add.add5(self) def add6(self): """write new index.meta file""" return OSAS_add.add6(self) def addImages(self,path): """Hinzufügen eines neuen Imagesfolders""" return OSAS_add.addImages(self,path) def addImages2(self): """Upload des neuen Imagefolders""" return OSAS_add.addImages2(self) def manage_AddOSAS_add_DocumentForm(self): """interface for adding the OSAS_add_Metadata""" pt=PageTemplateFile('Products/OSA_system/zpt/AddOSAS_document.zpt').__of__(self) return pt() def manage_AddOSAS_add_Document(self,id,RESPONSE=None): """add the OSAS_root""" newObj=OSAS_add_Document(id) self.Destination()._setObject(id,newObj) if RESPONSE is not None: RESPONSE.redirect('manage_main') InitializeClass(OSAS_add_Document) class OSAS_add_Text(Folder): """Hinzufuegen eines Text-Dokumentes zum Storage""" security=ClassSecurityInfo() def __init__(self,id): """initialize a new instance""" self.id = id meta_type='OSAS_add_Text' manage_options = Folder.manage_options+( {'label':'Main Config','action':'add_Text_config'}, ) security.declarePublic('add_Text_config') def add_Text_config(self): """Main configuration""" pt=PageTemplateFile('Products/OSA_system/zpt/ChangeOSAS_addText.zpt').__of__(self) return pt() security.declarePublic('change_OSAS_add_Text') def change_OSAS_add_Text(self,RESPONSE=None): """Change""" # self.RootFolderName=RootFolderName if RESPONSE is not None: RESPONSE.redirect('manage_main') def addText(self,path): """Add a fulltext""" return OSAS_add.addText(self,path) def addText2(self): """Read the file and store it""" return OSAS_add.addText2(self) def manage_AddOSAS_add_TextForm(self): """interface for adding the OSAS_add_Metadata""" pt=PageTemplateFile('Products/OSA_system/zpt/AddOSAS_text.zpt').__of__(self) return pt() def manage_AddOSAS_add_Text(self,id,RESPONSE=None): """add the OSAS_root""" newObj=OSAS_add_Text(id) self.Destination()._setObject(id,newObj) if RESPONSE is not None: RESPONSE.redirect('manage_main') InitializeClass(OSAS_add_Text) class OSAS_add_contextData(Folder): """Einfuegen eines Documentes in eine Collection""" security=ClassSecurityInfo() 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 getPartners(self,URL): """Zeige Partnerliste""" class requestHandler(ContentHandler): def __init__(self): self.ret=[] def startElement(self,name,attrs): if name=="partner": self.ret.append((attrs.get('id'),attrs.get('title'))) 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 addContextData(self,path): """Hinzufügen zu einer Sammlung""" try: urllib.urlopen(self.REQUEST['SERVER_URL']+path+"/index.meta") except: return self.REQUEST['SERVER_URL']+path+"/index.meta file has to exist!" links=[(path,'standard storage')] links+=OSAS_show.readContexts(path) # auslesen von contexten für den link #print "LINK",links #return links self.REQUEST.SESSION['links']=links pt=PageTemplateFile('Products/OSA_system/zpt/contextDataMain.zpt').__of__(self) return pt() def addContextData2(self,path,collection,link,label,description,content_type,responsible,weight,credits=None): """Hinzufuegen der Resource""" splitted=path.split("/") #print "BLU" id=splitted[len(splitted)-1] title=splitted[len(splitted)-1] metalink=self.REQUEST['SERVER_URL']+path+"/index.meta" #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) #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""" #return "BLUByy" return self.REQUEST.RESPONSE.redirect(self.REQUEST['URL2']+'?path='+path) manage_options = Folder.manage_options+( {'label':'Main Config','action':'add_contextData_config'}, ) def add_contextData_config(self): """Main configuration""" pt=PageTemplateFile('Products/OSA_system/zpt/ChangeOSAS_add_contextData.zpt').__of__(self) return pt() def change_OSAS_add_contextData(self,collection,RESPONSE=None): """Change""" self.collection=collection if RESPONSE is not None: RESPONSE.redirect('manage_main') def manage_AddOSAS_add_contextDataForm(self): """interface for adding the OSAS_add_Metadata""" pt=PageTemplateFile('Products/OSA_system/zpt/AddOSAS_contextData.zpt').__of__(self) return pt() def manage_AddOSAS_add_contextData(self,id,collection,RESPONSE=None): """add the OSAS_root""" newObj=OSAS_add_contextData(id,collection) self.Destination()._setObject(id,newObj) if RESPONSE is not None: RESPONSE.redirect('manage_main') InitializeClass(OSAS_add_contextData) class OSAS_add_Presentation(Folder): """Hinzufügen der Presentationsinformationen""" security=ClassSecurityInfo() def __init__(self,id): """initialize a new instance""" self.id = id meta_type='OSAS_add_Presentation' manage_options = Folder.manage_options+( {'label':'Main Config','action':'add_Presentation_config'}, ) security.declarePublic('add_Presentation_config') def add_Presentation_config(self): """Main configuration""" pt=PageTemplateFile('Products/OSA_system/zpt/ChangeOSAS_addPresentation.zpt').__of__(self) return pt() security.declarePublic('change_OSAS_add_Presentation') def change_OSAS_add_Presentation(self,RESPONSE=None): """Change""" # self.RootFolderName=RootFolderName if RESPONSE is not None: RESPONSE.redirect('manage_main') def addPresentation(self,path): """Hinzufügen der Presenationsinformation""" return OSAS_add.addPresentation(self,path) def addPresentation2(self): """Eingabe von Metadateninformationen""" return OSAS_add.addPresentation2(self) def manage_AddOSAS_add_PresentationForm(self): """interface for adding the OSAS_add_Metadata""" pt=PageTemplateFile('Products/OSA_system/zpt/AddOSAS_presentation.zpt').__of__(self) return pt() def manage_AddOSAS_add_Presentation(self,id,RESPONSE=None): """add the OSAS_root""" newObj=OSAS_add_Presentation(id) self.Destination()._setObject(id,newObj) if RESPONSE is not None: RESPONSE.redirect('manage_main') InitializeClass(OSAS_add_Presentation) class OSAS_combineTextImage(Folder): """Hinzufüge der Combine Text und Image""" security=ClassSecurityInfo() def __init__(self,id): """initialize a new instance""" self.id = id meta_type='OSAS_combineTextImage' manage_options = Folder.manage_options+( {'label':'Main Config','action':'combineTextImage_config'}, ) security.declarePublic('combineTextImage_config') def combineTextImage_config(self): """Main configuration""" pt=PageTemplateFile('Products/OSA_system/zpt/ChangeOSAS_combineTextImage.zpt').__of__(self) return pt() security.declarePublic('change_OSAS_combineTextImage') def change_OSAS_combineTextImage(self,RESPONSE=None): """Change""" # self.RootFolderName=RootFolderName if RESPONSE is not None: RESPONSE.redirect('manage_main') security.declarePublic('combineTextImage') def combineTextImage(self,path): """Hinzufügen der Presenationsinformation""" """gibt input formular zur erstellung des texttools meta tag aus""" files = os.listdir(path) texts=[] imagefolders=[] presentationfolders=[] splitted=path.split("/") externxml=readArchimedesXML(splitted[len(splitted)-1]) for filename in files: #print "FN",filename if archive.isdigilib2(path+"/"+filename): imagefolders.append(filename) if archive.isFullText(path,filename): #print "HI" texts.append(filename) if archive.isPresentation(path,filename): presentationfolders.append(filename) dom=xml.dom.minidom.parse(path+"/index.meta") try: filelanguage=archive.getText(dom.getElementsByTagName('lang')[0].childNodes) except: filelanguage="" self.REQUEST.SESSION['isolist']=getISO() tmp=getISO().keys() tmp.sort() self.REQUEST.SESSION['isolistsort']=tmp self.REQUEST.SESSION['path']=path self.REQUEST.SESSION['texts']=texts self.REQUEST.SESSION['imagefolders']=imagefolders self.REQUEST.SESSION['presentationfolders']=presentationfolders self.REQUEST.SESSION['filelanguage']=filelanguage self.REQUEST.SESSION['externxml']=externxml newtemplate=PageTemplateFile('Products/OSA_system/zpt/ImageandText').__of__(self) return newtemplate() def getProjects(self,obj_ids=None): """Get the Project title for configuration""" ret=[] print "HI" try: projects=self.ZopeFind(self.projects,obj_metatypes=['OSAS_project'],obj_ids=obj_ids)#assumes projects folder somewhere in the hierarchie. print "pr" for project in projects: ret.append((project[1].title,project[0],project[1])) print ret return ret except: return [('no Projectfolders','')] def getTextToolsField(self,path,name,default=''): """Lese Textoolsfelder aus index.meta im path aus""" try: dom=xml.dom.minidom.parse(path+"/index.meta") node=dom.getElementsByTagName('texttool')[0] #getNode subnode=node.getElementsByTagName(name)[0] print getText(subnode.childNodes) return getText(subnode.childNodes) except: return default def combineTextImage2(self,path): """Eingabe von Metadateninformationen""" OSAS_add.combineTextImage2(self,path) # Add images splitted=path.split("/") linkPath=splitted[len(splitted)-1] 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",unique="yes") pt=PageTemplateFile('Products/OSA_system/zpt/AddOSAS_combineTextImageFinal.zpt').__of__(self) return pt() def isSelectedProject(self,obj,id): """is ausgewählt""" if self.REQUEST['project']==id: return 1 else: return None 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') namelinknode=dom.createTextNode(link) linknode.appendChild(namelinknode) subnode.appendChild(linknode) linknode=dom.createElement('name') namelinknode=dom.createTextNode(description) linknode.appendChild(namelinknode) subnode.appendChild(linknode) node.appendChild(subnode) writefile=file(path+"/index.meta","w") #print path+"/index.meta" writefile.write(dom.toxml().encode('utf-8')) writefile.close() def manage_AddOSAS_combineTextImageForm(self): """interface for adding the OSAS_add_Metadata""" pt=PageTemplateFile('Products/OSA_system/zpt/AddOSAS_combineTextImage.zpt').__of__(self) return pt() def manage_AddOSAS_combineTextImage(self,id,RESPONSE=None): """add the OSAS_root""" newObj=OSAS_combineTextImage(id) self.Destination()._setObject(id,newObj) if RESPONSE is not None: RESPONSE.redirect('manage_main') InitializeClass(OSAS_combineTextImage)