File:  [Repository] / OSAS / OSA_system / OSAS_addfiles.py
Revision 1.28: download - view: text, annotated - select for diffs - revision graph
Thu Apr 15 12:56:41 2004 UTC (20 years, 2 months ago) by dwinter
Branches: MAIN
CVS tags: HEAD
links auf echo environment im falle nur text korrigiert

    1: # Methoden und Classen zum Hinzufuegen von Dokumenten
    2: 
    3: 
    4: from OSAS_helpers import readArchimedesXML, getText
    5: import os
    6: import xml.dom.minidom
    7: import re
    8: import urllib
    9: import OSAS_add
   10: import OSAS_show
   11: import string
   12: from OFS.Folder import Folder
   13: from AccessControl import ClassSecurityInfo
   14: from Globals import InitializeClass
   15: from Products.PageTemplates.PageTemplateFile import PageTemplateFile
   16: from Products.PageTemplates.PageTemplate import PageTemplate
   17: import archive # check if this is necessary
   18: 
   19: 
   20: from xml.sax import make_parser
   21: from xml.sax.handler import ContentHandler
   22: 
   23: def spaces(depth):
   24:     """needed in XMLtoTree"""
   25:     tmp=""
   26:     k=0
   27:     while k<2*depth:
   28:         k+=1
   29:         tmp=tmp+"&nbsp;"+"&nbsp;"
   30:     return tmp
   31: 
   32: 
   33: class OSAS_add_Document(Folder):
   34:     """Hinzufuegen eines Dokumentes zum Storage"""
   35:     security=ClassSecurityInfo()
   36: 
   37:     def __init__(self,id):
   38:         """initialize a new instance"""
   39:         self.id = id
   40:         
   41:         
   42:     meta_type='OSAS_add_Document'    
   43:     manage_options = Folder.manage_options+(
   44:             {'label':'Main Config','action':'add_Document_config'},
   45:             )
   46:         
   47:      
   48:         
   49:     security.declarePublic('add_Document_config')
   50:     def add_Document_config(self):
   51:         """Main configuration"""
   52:         pt=PageTemplateFile('Products/OSA_system/zpt/ChangeOSAS_addDocument.zpt').__of__(self)
   53:         return pt()
   54:     
   55:     security.declarePublic('change_OSAS_add_Document')
   56:     def change_OSAS_add_Document(self,RESPONSE=None):
   57:         """Change"""
   58: #        self.RootFolderName=RootFolderName
   59:         if RESPONSE is not None:
   60:             RESPONSE.redirect('manage_main')
   61: 
   62:     security.declarePublic('index_html')
   63:     def index_html(self):
   64:         """stantard aufruf"""
   65:         return OSAS_add.add(self.standardMD,no_upload=1)
   66: 
   67: 
   68:     security.declarePublic('add2')
   69:     def add2(self):
   70:         """ anlegen naechster schritt"""
   71:         return OSAS_add.add2(self.standardMD)
   72: 
   73:     def add3(self):
   74:         """Foldername"""
   75:         return OSAS_add.add3(self)
   76: 
   77:     def add4(self):
   78:         """Applet"""
   79:         return OSAS_add.add4(self)
   80: 
   81:     def add5(self):
   82:         """Foldername"""
   83:         return OSAS_add.add5(self)
   84: 
   85:     def add6(self):
   86:         """write new index.meta file"""
   87:         return OSAS_add.add6(self)
   88: 
   89:     def addText2(self):
   90:         """add only a text"""
   91:         metadata=OSAS_add.parse_query_string(self.REQUEST['QUERY_STRING'])
   92:         metadata['archive-creation-date']=OSAS_add.date(self)
   93:         metadata['creator']=self.REQUEST['creator']
   94:         metadata['description']=self.REQUEST['content_description']
   95: 	metadata['archive-path']=os.path.split(self.REQUEST.SESSION['path'])[0]
   96: 	#metadata['folder_name']=self.REQUEST.SESSION['folder_name']
   97: 	metadata['folder_name']=os.path.split(self.REQUEST.SESSION['path'])[1]
   98: 	metadata['content-type']="fulltext document"
   99: 	self.reftype=self.REQUEST.SESSION['reftype']
  100: 	self.REQUEST.SESSION['add_metadata']=metadata	
  101: 	self.add_metadata=metadata
  102: 	self.metadata=self.REQUEST.SESSION['metadata']
  103: 	self.metadataprint=""
  104: 	for tag in self.metadata.keys():
  105: 		self.metadataprint=self.metadataprint+"<"+tag+">"+self.metadata[tag]+"</"+tag+">\n"
  106: 
  107: 	newtemplate=PageTemplateFile('Products/OSA_system/zpt/index_meta').__of__(self)
  108: 	newtemplate.content_type="text/plain"
  109: 	renderxml = newtemplate()
  110:         metapath=self.REQUEST.SESSION['path']+"/index.meta"
  111: 	
  112: 	
  113: 	f=open(metapath,'w')
  114: 	f.writelines(renderxml)
  115: 	f.close()
  116: 	os.chmod(metapath,0664)
  117: 	os.popen('chmod -R 0775 %s'%self.add_metadata['archive-path']+"/"+self.add_metadata['folder_name']) 
  118: 	
  119:         return OSAS_add.addText2(self)
  120: 
  121:     def addImages(self,path):
  122:         """Hinzufügen eines neuen Imagesfolders"""
  123:         return OSAS_add.addImages(self,path)
  124: 
  125:     def addImages2(self):
  126:         """Upload des neuen Imagefolders"""
  127:         return OSAS_add.addImages2(self)
  128: 
  129:     
  130: def manage_AddOSAS_add_DocumentForm(self):
  131:     """interface for adding the OSAS_add_Metadata"""
  132:     pt=PageTemplateFile('Products/OSA_system/zpt/AddOSAS_document.zpt').__of__(self)
  133:     return pt()
  134: 
  135: def manage_AddOSAS_add_Document(self,id,RESPONSE=None):
  136:     """add the OSAS_root"""
  137:     newObj=OSAS_add_Document(id)
  138:     self.Destination()._setObject(id,newObj)
  139:     if RESPONSE is not None:
  140:         RESPONSE.redirect('manage_main')
  141: 
  142:             
  143: InitializeClass(OSAS_add_Document)
  144: 
  145: 
  146: class OSAS_add_Text(Folder):
  147:     """Hinzufuegen eines Text-Dokumentes zum Storage"""
  148:     security=ClassSecurityInfo()
  149: 
  150:     def __init__(self,id):
  151:         """initialize a new instance"""
  152:         self.id = id
  153:         
  154:         
  155:     meta_type='OSAS_add_Text'    
  156:     manage_options = Folder.manage_options+(
  157:             {'label':'Main Config','action':'add_Text_config'},
  158:             )
  159:         
  160:      
  161:         
  162:     security.declarePublic('add_Text_config')
  163:     def add_Text_config(self):
  164:         """Main configuration"""
  165:         pt=PageTemplateFile('Products/OSA_system/zpt/ChangeOSAS_addText.zpt').__of__(self)
  166:         return pt()
  167:     
  168:     security.declarePublic('change_OSAS_add_Text')
  169:     def change_OSAS_add_Text(self,RESPONSE=None):
  170:         """Change"""
  171: #        self.RootFolderName=RootFolderName
  172:         if RESPONSE is not None:
  173:             RESPONSE.redirect('manage_main')
  174: 
  175:     def addText(self,path):
  176:         """Add a fulltext"""
  177:         return OSAS_add.addText(self,path)
  178: 
  179:     def addText2(self):
  180:         """Read the file and store it"""
  181:         return OSAS_add.addText2(self)
  182: def manage_AddOSAS_add_TextForm(self):
  183:     """interface for adding the OSAS_add_Metadata"""
  184:     pt=PageTemplateFile('Products/OSA_system/zpt/AddOSAS_text.zpt').__of__(self)
  185:     return pt()
  186: 
  187: def manage_AddOSAS_add_Text(self,id,RESPONSE=None):
  188:     """add the OSAS_root"""
  189:     newObj=OSAS_add_Text(id)
  190:     self.Destination()._setObject(id,newObj)
  191:     if RESPONSE is not None:
  192:         RESPONSE.redirect('manage_main')
  193: 
  194:             
  195: InitializeClass(OSAS_add_Text)
  196: 
  197: 
  198: class OSAS_add_contextData(Folder):
  199:     """Einfuegen eines Documentes in eine Collection"""
  200:     
  201:     security=ClassSecurityInfo()
  202: 
  203:             
  204:     meta_type='OSAS_add_contextData'    
  205: 
  206:     def XmlToTree(self,URL):
  207:         """Collection XML to Tree"""
  208:         
  209:         
  210:         class requestHandler(ContentHandler):
  211:             def __init__(self):
  212:                 self.depth=0
  213:                 self.retStr=""
  214:                 
  215:             def startElement(self,name,attrs):
  216:                 if name=="element":
  217:                     self.depth+=1
  218:                     begin=""
  219:                     end=""
  220:                     if self.depth==1:
  221:                         begin="<b>"
  222:                         end="</b>"
  223:                         
  224:                     self.retStr+=spaces(self.depth)+"<input type='radio' name='collection' value='%s'>%s</input>"%(attrs.get('url'),begin+attrs.get('name')+end)+"<br>\n"
  225: 
  226: 
  227:                     
  228:             def endElement(self,name):
  229:                 if name=="element":
  230:                     self.depth-=1
  231: 
  232: 
  233:         try:
  234:             URL+="/getCollectionTreeXML"
  235:             parser=make_parser()
  236:             curHandler=requestHandler()
  237:             parser.setContentHandler(curHandler)
  238: 
  239:             parser.parse(urllib.urlopen(URL))
  240:             return curHandler.retStr
  241:         except:
  242:             return urllib.urlopen(URL).read()
  243:         
  244:     def __init__(self,id,collection):
  245:         self.id=id
  246:         self.collection=collection
  247: 
  248:   
  249:    
  250: 
  251:     def getPartners(self,URL):
  252:         """Zeige Partnerliste"""
  253:         class requestHandler(ContentHandler):
  254:             def __init__(self):
  255:                 self.ret=[]
  256:                 
  257:             def startElement(self,name,attrs):
  258:                 if name=="partner":
  259:                     self.ret.append((attrs.get('id'),attrs.get('title')))
  260: 
  261: 
  262:         URL+="/getPartnersXML"
  263:             
  264:         try:
  265:             
  266:             parser=make_parser()
  267:             curHandler=requestHandler()
  268:             parser.setContentHandler(curHandler)
  269:             
  270:             parser.parse(urllib.urlopen(URL))
  271:             return curHandler.ret
  272:         except:
  273:             return [("",urllib.urlopen(URL).read())]
  274: 
  275:     
  276:     def addContextData(self,path):
  277:         """Hinzufügen zu einer Sammlung"""
  278:         try:
  279:             urllib.urlopen(self.REQUEST['SERVER_URL']+path+"/index.meta")
  280:             
  281:         except:
  282:             return self.REQUEST['SERVER_URL']+path+"/index.meta file has to exist!"
  283: 
  284:         links=[(path,'standard storage')]
  285:         
  286:         links+=OSAS_show.readContexts(path) # auslesen von contexten für den link
  287:         #print "LINK",links
  288:         #return links
  289:         self.REQUEST.SESSION['links']=links
  290:         pt=PageTemplateFile('Products/OSA_system/zpt/contextDataMain.zpt').__of__(self)
  291:         return pt()
  292:     
  293:     
  294:     def addContextData2(self,path,collection,link,label,description,content_type,responsible,weight,credits=None):
  295:         """Hinzufuegen der Resource"""
  296:         splitted=path.split("/")
  297:         #print "BLU"
  298:         id=splitted[len(splitted)-1]
  299:         title=splitted[len(splitted)-1]
  300:         metalink=self.REQUEST['SERVER_URL']+path+"/index.meta"
  301:         
  302:         #link=TOBEDONE"
  303:         """Hinzufügen der Ressource"""
  304: 
  305:         params=urllib.urlencode({'id':id,'title':title,'link':link,'label':label,'description':description,'contentType':content_type,'responsible':responsible,'weight':weight,'credits':credits,'metalink':metalink})
  306: 
  307:         retStr=urllib.urlopen(collection+"/addResource",params).read()
  308:         return retStr
  309: 	if not retStr:
  310:             return "An Error occured adding the resource\n"
  311: 
  312:         urllib.urlopen(collection+"/"+id+"/ECHO_getResourceMD").read()
  313:         #exec("collection_object=self"+collection)
  314:         
  315: 
  316:         
  317:         #ECHO_collection.manage_addECHO_resource(collection_object,id,title,label,description,content_type,responsible,link,metalink,credits,weight,RESPONSE=None)
  318:         #print "HI5"
  319:         #try:
  320:         #    getattr(collection_object,id).ECHO_getResourceMD()
  321:         #except:
  322:         #    """nothing"""
  323:         #return "BLUByy"
  324:         return self.REQUEST.RESPONSE.redirect(self.REQUEST['URL2']+'?path='+path)
  325:         
  326:     manage_options = Folder.manage_options+(
  327:             {'label':'Main Config','action':'add_contextData_config'},
  328:             )
  329:         
  330:      
  331:     def add_contextData_config(self):
  332:         """Main configuration"""
  333:         pt=PageTemplateFile('Products/OSA_system/zpt/ChangeOSAS_add_contextData.zpt').__of__(self)
  334:         return pt()
  335:     
  336:     
  337:     def change_OSAS_add_contextData(self,collection,RESPONSE=None):
  338:         """Change"""
  339:         self.collection=collection
  340:         if RESPONSE is not None:
  341:             RESPONSE.redirect('manage_main')
  342:             
  343: def manage_AddOSAS_add_contextDataForm(self):
  344:     """interface for adding the OSAS_add_Metadata"""
  345:     pt=PageTemplateFile('Products/OSA_system/zpt/AddOSAS_contextData.zpt').__of__(self)
  346:     return pt()
  347: 
  348: def manage_AddOSAS_add_contextData(self,id,collection,RESPONSE=None):
  349:     """add the OSAS_root"""
  350:     newObj=OSAS_add_contextData(id,collection)
  351:     self.Destination()._setObject(id,newObj)
  352:     if RESPONSE is not None:
  353:         RESPONSE.redirect('manage_main')
  354: 
  355:             
  356: InitializeClass(OSAS_add_contextData)
  357: 
  358: class OSAS_add_Presentation(Folder):
  359:     """Hinzufügen der Presentationsinformationen"""
  360:     security=ClassSecurityInfo()
  361: 
  362:     def __init__(self,id):
  363:         """initialize a new instance"""
  364:         self.id = id
  365:         
  366:         
  367:     meta_type='OSAS_add_Presentation'    
  368:     manage_options = Folder.manage_options+(
  369:             {'label':'Main Config','action':'add_Presentation_config'},
  370:             )
  371:         
  372:      
  373:         
  374:     security.declarePublic('add_Presentation_config')
  375:     def add_Presentation_config(self):
  376:         """Main configuration"""
  377:         pt=PageTemplateFile('Products/OSA_system/zpt/ChangeOSAS_addPresentation.zpt').__of__(self)
  378:         return pt()
  379:     
  380:     security.declarePublic('change_OSAS_add_Presentation')
  381:     def change_OSAS_add_Presentation(self,RESPONSE=None):
  382:         """Change"""
  383: #        self.RootFolderName=RootFolderName
  384:         if RESPONSE is not None:
  385:             RESPONSE.redirect('manage_main')
  386: 
  387:     def addPresentation(self,path):
  388:         """Hinzufügen der Presenationsinformation"""
  389:         return OSAS_add.addPresentation(self,path)
  390: 
  391:     def addPresentation2(self):
  392:         """Eingabe von Metadateninformationen"""
  393:         return OSAS_add.addPresentation2(self)
  394:     
  395: def manage_AddOSAS_add_PresentationForm(self):
  396:     """interface for adding the OSAS_add_Metadata"""
  397:     pt=PageTemplateFile('Products/OSA_system/zpt/AddOSAS_presentation.zpt').__of__(self)
  398:     return pt()
  399: 
  400: def manage_AddOSAS_add_Presentation(self,id,RESPONSE=None):
  401:     """add the OSAS_root"""
  402:     newObj=OSAS_add_Presentation(id)
  403:     self.Destination()._setObject(id,newObj)
  404:     if RESPONSE is not None:
  405:         RESPONSE.redirect('manage_main')
  406: 
  407:             
  408: InitializeClass(OSAS_add_Presentation)
  409: 
  410: class OSAS_combineTextImage(Folder):
  411:     """Hinzufüge der Combine Text und Image"""
  412:     security=ClassSecurityInfo()
  413: 
  414:     def __init__(self,id):
  415:         """initialize a new instance"""
  416:         self.id = id
  417:         
  418:         
  419:     meta_type='OSAS_combineTextImage'    
  420:     manage_options = Folder.manage_options+(
  421:             {'label':'Main Config','action':'combineTextImage_config'},
  422:             )
  423:         
  424: 
  425:         
  426:     security.declarePublic('combineTextImage_config')
  427:     def combineTextImage_config(self):
  428:         """Main configuration"""
  429:         pt=PageTemplateFile('Products/OSA_system/zpt/ChangeOSAS_combineTextImage.zpt').__of__(self)
  430:         return pt()
  431:     
  432:     security.declarePublic('change_OSAS_combineTextImage')
  433:     def change_OSAS_combineTextImage(self,RESPONSE=None):
  434:         """Change"""
  435: #        self.RootFolderName=RootFolderName
  436:         if RESPONSE is not None:
  437:             RESPONSE.redirect('manage_main')
  438:             
  439:     security.declarePublic('combineTextImage')
  440:     def combineTextImage(self,path):
  441:         """Hinzufügen der Presenationsinformation"""
  442:         """gibt input formular zur erstellung des texttools meta tag aus"""
  443: 	files = os.listdir(path)
  444: 	
  445: 	texts=[]
  446: 	imagefolders=[]
  447: 	presentationfolders=[]
  448: 
  449: 	splitted=path.split("/")
  450: 	externxml=readArchimedesXML(splitted[len(splitted)-1])
  451: 	
  452: 	for filename in files:
  453: 		#print "FN",filename
  454: 		if archive.isdigilib2(path+"/"+filename):
  455: 			imagefolders.append(filename)
  456: 			
  457: 		if archive.isFullText(path,filename):
  458: 			#print "HI"
  459: 			texts.append(filename)
  460: 		if archive.isPresentation(path,filename):
  461: 			presentationfolders.append(filename)
  462: 	
  463: 	dom=xml.dom.minidom.parse(path+"/index.meta")
  464: 	try:
  465: 		filelanguage=archive.getText(dom.getElementsByTagName('lang')[0].childNodes)
  466: 	except:
  467: 		filelanguage=""
  468:                 
  469: 	self.REQUEST.SESSION['isolist']=OSAS_add.getISO()
  470:         
  471: 	tmp=self.REQUEST.SESSION['isolist'].keys()
  472: 	tmp.sort()
  473: 	self.REQUEST.SESSION['isolistsort']=tmp
  474: 	self.REQUEST.SESSION['path']=path
  475: 	self.REQUEST.SESSION['texts']=texts
  476: 	self.REQUEST.SESSION['imagefolders']=imagefolders
  477: 	self.REQUEST.SESSION['presentationfolders']=presentationfolders
  478: 	self.REQUEST.SESSION['filelanguage']=filelanguage
  479: 	self.REQUEST.SESSION['externxml']=externxml
  480: 
  481: 	newtemplate=PageTemplateFile('Products/OSA_system/zpt/ImageandText').__of__(self)
  482: 	return newtemplate()
  483: 	
  484:     def getProjects(self,obj_ids=None):
  485:         """Get the Project title for configuration"""
  486:         ret=[]
  487:         
  488:         try:
  489:             projects=self.ZopeFind(self.projects,obj_metatypes=['OSAS_project'],obj_ids=obj_ids)#assumes projects folder somewhere in the hierarchie.
  490:             
  491:             for project in projects:
  492:                 ret.append((project[1].title,project[0],project[1]))
  493:             
  494:             return ret
  495:         
  496:         except:
  497:             return [('no Projectfolders','')]
  498: 
  499:     def getTextToolsField(self,path,name,default=''):
  500:         """Lese Textoolsfelder aus index.meta im path aus"""
  501:         
  502:         try:
  503:             dom=xml.dom.minidom.parse(path+"/index.meta")
  504:             node=dom.getElementsByTagName('texttool')[0] #getNode
  505:             subnode=node.getElementsByTagName(name)[0]
  506:             
  507:             return getText(subnode.childNodes)
  508:         except:
  509:             return default
  510:             
  511: 
  512:     def combineTextImage2(self,path):
  513:         """Eingabe von Metadateninformationen"""
  514:         OSAS_add.combineTextImage2(self,path) # Add images
  515:         splitted=path.split("/")
  516:         linkPath=splitted[len(splitted)-1]
  517:         linkViewerEnvironmentImages="http://nausikaa2.mpiwg-berlin.mpg.de/cgi-bin/toc/toc.x.cgi?dir=%s&step=thumb" % linkPath
  518:         linkViewerEnvironmentOnlyText="http://nausikaa2.mpiwg-berlin.mpg.de/cgi-bin/toc/toc.x.cgi?dir=%s&step=textonly" % linkPath
  519: 
  520:         if self.REQUEST.has_key('image'): # bilder vorhanden
  521:             linkViewerEnvironment=linkViewerEnvironmentImages
  522:         else:
  523:             linkViewerEnvironment=linkViewerEnvironmentOnlyText
  524:             
  525:         self.REQUEST.SESSION['linkViewerEnvironment']=linkViewerEnvironment
  526:         
  527:         writeToContext(path,linkViewerEnvironment,"ECHO standard environment",unique="yes")
  528:         
  529:         pt=PageTemplateFile('Products/OSA_system/zpt/AddOSAS_combineTextImageFinal.zpt').__of__(self)
  530: 
  531:         return pt()
  532: 
  533:     def isSelectedProject(self,obj,id):
  534:         """is ausgewählt"""
  535:         
  536:         if self.REQUEST['project']==id:
  537:             return 1
  538:         else:
  539:             return None
  540: 
  541: def writeToContext(path,link,description,unique="no"):
  542:     """Created an additional entry to the index.meta file of path"""
  543:     dom=xml.dom.minidom.parse(path+"/index.meta")
  544:     node=dom.getElementsByTagName('resource')[0]
  545: 
  546:     if unique=="yes":
  547:         
  548:         contexts=node.getElementsByTagName('context')
  549:         for context in contexts:
  550:             nameTag=getText(context.getElementsByTagName('name')[0].childNodes)
  551:             linkTag=getText(context.getElementsByTagName('link')[0].childNodes)
  552:             
  553:             
  554:             linkTag=re.sub("\:86","",linkTag) # alter port 86 gleich ohne port nummer (hack)
  555:             if (nameTag==description) and (linkTag==link):
  556:                 node.removeChild(context).unlink()
  557:                     
  558:     subnode=dom.createElement('context')
  559: 
  560:     linknode=dom.createElement('link')
  561:     namelinknode=dom.createTextNode(link)
  562:     linknode.appendChild(namelinknode)
  563:     subnode.appendChild(linknode)
  564: 
  565:     linknode=dom.createElement('name')
  566:     namelinknode=dom.createTextNode(description)
  567:     linknode.appendChild(namelinknode)
  568:     subnode.appendChild(linknode)
  569: 
  570:     node.appendChild(subnode)
  571:     
  572:     writefile=file(path+"/index.meta","w")
  573:     #print path+"/index.meta"
  574:     writefile.write(dom.toxml().encode('utf-8'))
  575:     writefile.close()
  576: 
  577: def manage_AddOSAS_combineTextImageForm(self):
  578:     """interface for adding the OSAS_add_Metadata"""
  579:     pt=PageTemplateFile('Products/OSA_system/zpt/AddOSAS_combineTextImage.zpt').__of__(self)
  580:     return pt()
  581: 
  582: def manage_AddOSAS_combineTextImage(self,id,RESPONSE=None):
  583:     """add the OSAS_root"""
  584:     newObj=OSAS_combineTextImage(id)
  585:     self.Destination()._setObject(id,newObj)
  586:     if RESPONSE is not None:
  587:         RESPONSE.redirect('manage_main')
  588: 
  589:             
  590: InitializeClass(OSAS_combineTextImage)

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>