File:  [Repository] / OSAS / OSA_system / OSAS_addfiles.py
Revision 1.32: download - view: text, annotated - select for diffs - revision graph
Thu May 6 16:58:57 2004 UTC (20 years, 2 months ago) by dwinter
Branches: MAIN
CVS tags: HEAD
urllquote und utf eingefuegt bei xmlpartnes und xmlcollectionsn

    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['pathnew'])[0]
   96: 	#metadata['folder_name']=self.REQUEST.SESSION['folder_name']
   97: 	metadata['folder_name']=os.path.split(self.REQUEST.SESSION['pathnew'])[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['pathnew']+"/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+urllib.unquote(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 URL
  243:             return urllib.urlopen(URL).read()
  244: 	    
  245:       
  246:     def __init__(self,id,collection):
  247:         self.id=id
  248:         self.collection=collection
  249: 
  250:   
  251:    
  252: 
  253:     def getPartners(self,URL):
  254:         """Zeige Partnerliste"""
  255:         class requestHandler(ContentHandler):
  256:             def __init__(self):
  257:                 self.ret=[]
  258:                 
  259:             def startElement(self,name,attrs):
  260:                 if name=="partner":
  261:                     self.ret.append((attrs.get('id'),attrs.get('title')))
  262: 
  263: 
  264:         URL+="/getPartnersXML"
  265:             
  266:         try:
  267:             
  268:         	parser=make_parser()
  269:         	curHandler=requestHandler()
  270: 	        parser.setContentHandler(curHandler)
  271:             
  272:         	parser.parse(urllib.urlopen(URL))
  273: 	        return curHandler.ret
  274:         except:
  275:         	return [("",URL)]
  276: 	    
  277:     
  278:     def addContextData(self,path):
  279:         """Hinzufuegen zu einer Sammlung"""
  280:         try:
  281:             urllib.urlopen(self.REQUEST['SERVER_URL']+path+"/index.meta")
  282:             
  283:         except:
  284:             return self.REQUEST['SERVER_URL']+path+"/index.meta file has to exist!"
  285: 
  286:         links=[(path,'standard storage')]
  287:         
  288:         links+=OSAS_show.readContexts(path) # auslesen von contexten fuer den link
  289:         #print "LINK",links
  290:         #return links
  291:         self.REQUEST.SESSION['links']=links
  292:         pt=PageTemplateFile('Products/OSA_system/zpt/contextDataMain.zpt').__of__(self)
  293:         return pt()
  294:     
  295:     
  296:     def addContextData2(self,path,collection,link,label,description,content_type,responsible,weight,credits=None):
  297:         """Hinzufuegen der Resource"""
  298:         splitted=path.split("/")
  299:         #print "BLU"
  300:         id=splitted[len(splitted)-1]
  301:         title=splitted[len(splitted)-1]
  302:         metalink=self.REQUEST['SERVER_URL']+path+"/index.meta"
  303:         
  304:         #link=TOBEDONE"
  305:         """Hinzufügen der Ressource"""
  306: 
  307:         params=urllib.urlencode({'id':id,'title':title,'link':link,'label':label,'description':description,'contentType':content_type,'responsible':responsible,'weight':weight,'credits':credits,'metalink':metalink})
  308: 
  309:         retStr=urllib.urlopen(collection+"/addResource",params).read()
  310: 
  311: 	if not retStr:
  312:             return "An Error occured adding the resource\n"
  313: 	
  314: 
  315:         urllib.urlopen(collection+"/"+id+"/ECHO_getResourceMD").read()
  316: 
  317:         return self.REQUEST.RESPONSE.redirect(self.REQUEST['URL2']+'?path='+path)
  318:         
  319:     manage_options = Folder.manage_options+(
  320:             {'label':'Main Config','action':'add_contextData_config'},
  321:             )
  322:         
  323:      
  324:     def add_contextData_config(self):
  325:         """Main configuration"""
  326:         pt=PageTemplateFile('Products/OSA_system/zpt/ChangeOSAS_add_contextData.zpt').__of__(self)
  327:         return pt()
  328:     
  329:     
  330:     def change_OSAS_add_contextData(self,collection,RESPONSE=None):
  331:         """Change"""
  332:         self.collection=collection
  333:         if RESPONSE is not None:
  334:             RESPONSE.redirect('manage_main')
  335:             
  336: def manage_AddOSAS_add_contextDataForm(self):
  337:     """interface for adding the OSAS_add_Metadata"""
  338:     pt=PageTemplateFile('Products/OSA_system/zpt/AddOSAS_contextData.zpt').__of__(self)
  339:     return pt()
  340: 
  341: def manage_AddOSAS_add_contextData(self,id,collection,RESPONSE=None):
  342:     """add the OSAS_root"""
  343:     newObj=OSAS_add_contextData(id,collection)
  344:     self.Destination()._setObject(id,newObj)
  345:     if RESPONSE is not None:
  346:         RESPONSE.redirect('manage_main')
  347: 
  348:             
  349: InitializeClass(OSAS_add_contextData)
  350: 
  351: class OSAS_add_Presentation(Folder):
  352:     """Hinzufügen der Presentationsinformationen"""
  353:     security=ClassSecurityInfo()
  354: 
  355:     def __init__(self,id):
  356:         """initialize a new instance"""
  357:         self.id = id
  358:         
  359:         
  360:     meta_type='OSAS_add_Presentation'    
  361:     manage_options = Folder.manage_options+(
  362:             {'label':'Main Config','action':'add_Presentation_config'},
  363:             )
  364:         
  365:      
  366:         
  367:     security.declarePublic('add_Presentation_config')
  368:     def add_Presentation_config(self):
  369:         """Main configuration"""
  370:         pt=PageTemplateFile('Products/OSA_system/zpt/ChangeOSAS_addPresentation.zpt').__of__(self)
  371:         return pt()
  372:     
  373:     security.declarePublic('change_OSAS_add_Presentation')
  374:     def change_OSAS_add_Presentation(self,RESPONSE=None):
  375:         """Change"""
  376: #        self.RootFolderName=RootFolderName
  377:         if RESPONSE is not None:
  378:             RESPONSE.redirect('manage_main')
  379: 
  380:     def addPresentation(self,path):
  381:         """Hinzufügen der Presenationsinformation"""
  382:         return OSAS_add.addPresentation(self,path)
  383: 
  384:     def addPresentation2(self):
  385:         """Eingabe von Metadateninformationen"""
  386:         return OSAS_add.addPresentation2(self)
  387:     
  388: def manage_AddOSAS_add_PresentationForm(self):
  389:     """interface for adding the OSAS_add_Metadata"""
  390:     pt=PageTemplateFile('Products/OSA_system/zpt/AddOSAS_presentation.zpt').__of__(self)
  391:     return pt()
  392: 
  393: def manage_AddOSAS_add_Presentation(self,id,RESPONSE=None):
  394:     """add the OSAS_root"""
  395:     newObj=OSAS_add_Presentation(id)
  396:     self.Destination()._setObject(id,newObj)
  397:     if RESPONSE is not None:
  398:         RESPONSE.redirect('manage_main')
  399: 
  400:             
  401: InitializeClass(OSAS_add_Presentation)
  402: 
  403: class OSAS_combineTextImage(Folder):
  404:     """Hinzufüge der Combine Text und Image"""
  405:     security=ClassSecurityInfo()
  406: 
  407:     def __init__(self,id):
  408:         """initialize a new instance"""
  409:         self.id = id
  410:         
  411:         
  412:     meta_type='OSAS_combineTextImage'    
  413:     manage_options = Folder.manage_options+(
  414:             {'label':'Main Config','action':'combineTextImage_config'},
  415:             )
  416:         
  417: 
  418:         
  419:     security.declarePublic('combineTextImage_config')
  420:     def combineTextImage_config(self):
  421:         """Main configuration"""
  422:         pt=PageTemplateFile('Products/OSA_system/zpt/ChangeOSAS_combineTextImage.zpt').__of__(self)
  423:         return pt()
  424:     
  425:     security.declarePublic('change_OSAS_combineTextImage')
  426:     def change_OSAS_combineTextImage(self,RESPONSE=None):
  427:         """Change"""
  428: #        self.RootFolderName=RootFolderName
  429:         if RESPONSE is not None:
  430:             RESPONSE.redirect('manage_main')
  431:             
  432:     security.declarePublic('combineTextImage')
  433:     def combineTextImage(self,path):
  434:         """Hinzufügen der Presenationsinformation"""
  435:         """gibt input formular zur erstellung des texttools meta tag aus"""
  436: 	files = os.listdir(path)
  437: 	
  438: 	texts=[]
  439: 	imagefolders=[]
  440: 	presentationfolders=[]
  441: 
  442: 	splitted=path.split("/")
  443: 	externxml=readArchimedesXML(splitted[len(splitted)-1])
  444: 	
  445: 	for filename in files:
  446: 		#print "FN",filename
  447: 		if archive.isdigilib2(path+"/"+filename):
  448: 			imagefolders.append(filename)
  449: 			
  450: 		if archive.isFullText(path,filename):
  451: 			#print "HI"
  452: 			texts.append(filename)
  453: 		if archive.isPresentation(path,filename):
  454: 			presentationfolders.append(filename)
  455: 	
  456: 	dom=xml.dom.minidom.parse(path+"/index.meta")
  457: 	try:
  458: 		filelanguage=archive.getText(dom.getElementsByTagName('lang')[0].childNodes)
  459: 	except:
  460: 		filelanguage=""
  461:                 
  462: 	self.REQUEST.SESSION['isolist']=OSAS_add.getISO()
  463:         
  464: 	tmp=self.REQUEST.SESSION['isolist'].keys()
  465: 	tmp.sort()
  466: 	self.REQUEST.SESSION['isolistsort']=tmp
  467: 	self.REQUEST.SESSION['path']=path
  468: 	self.REQUEST.SESSION['texts']=texts
  469: 	self.REQUEST.SESSION['imagefolders']=imagefolders
  470: 	self.REQUEST.SESSION['presentationfolders']=presentationfolders
  471: 	self.REQUEST.SESSION['filelanguage']=filelanguage
  472: 	self.REQUEST.SESSION['externxml']=externxml
  473: 
  474: 	newtemplate=PageTemplateFile('Products/OSA_system/zpt/ImageandText').__of__(self)
  475: 	return newtemplate()
  476: 	
  477:     def getProjects(self,obj_ids=None):
  478:         """Get the Project title for configuration"""
  479:         ret=[]
  480:         
  481:         try:
  482:             projects=self.ZopeFind(self.projects,obj_metatypes=['OSAS_project'],obj_ids=obj_ids)#assumes projects folder somewhere in the hierarchie.
  483:             
  484:             for project in projects:
  485:                 ret.append((project[1].title,project[0],project[1]))
  486:             
  487:             return ret
  488:         
  489:         except:
  490:             return [('no Projectfolders','')]
  491: 
  492:     def getTextToolsField(self,path,name,default=''):
  493:         """Lese Textoolsfelder aus index.meta im path aus"""
  494:         
  495:         try:
  496:             dom=xml.dom.minidom.parse(path+"/index.meta")
  497:             node=dom.getElementsByTagName('texttool')[0] #getNode
  498:             subnode=node.getElementsByTagName(name)[0]
  499: 
  500:             # bei text wird nur der Folder gebraucht
  501:             if name=="text":
  502:                 splitted=getText(subnode.childNodes).split("/")
  503:                 return splitted[len(splitted)-2]
  504:             else:
  505:                 return getText(subnode.childNodes)
  506:         except:
  507:             return default
  508:    
  509: 
  510:     def combineTextImage2(self,path):
  511:         """Eingabe von Metadateninformationen"""
  512:         OSAS_add.combineTextImage2(self,path) # Add images
  513:         splitted=path.split("/")
  514:         linkPath=splitted[len(splitted)-1]
  515:         linkViewerEnvironmentImages="http://nausikaa2.mpiwg-berlin.mpg.de/cgi-bin/toc/toc.x.cgi?dir=%s&step=thumb" % linkPath
  516:         linkViewerEnvironmentOnlyText="http://nausikaa2.mpiwg-berlin.mpg.de/cgi-bin/toc/toc.x.cgi?dir=%s&step=textonly" % linkPath
  517: 
  518:         if self.REQUEST.has_key('image'): # bilder vorhanden
  519:             linkViewerEnvironment=linkViewerEnvironmentImages
  520:         else:
  521:             linkViewerEnvironment=linkViewerEnvironmentOnlyText
  522:             
  523:         self.REQUEST.SESSION['linkViewerEnvironment']=linkViewerEnvironment
  524:         
  525:         writeToContext(path,linkViewerEnvironment,"ECHO standard environment",unique="yes")
  526:         
  527:         pt=PageTemplateFile('Products/OSA_system/zpt/AddOSAS_combineTextImageFinal.zpt').__of__(self)
  528: 
  529:         return pt()
  530: 
  531:     def isSelectedProject(self,obj,id):
  532:         """is ausgewählt"""
  533:         
  534:         if self.REQUEST['project']==id:
  535:             return 1
  536:         else:
  537:             return None
  538: 
  539: def writeToContext(path,link,description,unique="no"):
  540:     """Created an additional entry to the index.meta file of path"""
  541:     dom=xml.dom.minidom.parse(path+"/index.meta")
  542:     node=dom.getElementsByTagName('resource')[0]
  543: 
  544:     if unique=="yes":
  545:         
  546:         contexts=node.getElementsByTagName('context')
  547:         for context in contexts:
  548:             nameTag=getText(context.getElementsByTagName('name')[0].childNodes)
  549:             linkTag=getText(context.getElementsByTagName('link')[0].childNodes)
  550:             
  551:             
  552:             linkTag=re.sub("\:86","",linkTag) # alter port 86 gleich ohne port nummer (hack)
  553:             if (nameTag==description) and (linkTag==link):
  554:                 node.removeChild(context).unlink()
  555:                     
  556:     subnode=dom.createElement('context')
  557: 
  558:     linknode=dom.createElement('link')
  559:     namelinknode=dom.createTextNode(link)
  560:     linknode.appendChild(namelinknode)
  561:     subnode.appendChild(linknode)
  562: 
  563:     linknode=dom.createElement('name')
  564:     namelinknode=dom.createTextNode(description)
  565:     linknode.appendChild(namelinknode)
  566:     subnode.appendChild(linknode)
  567: 
  568:     node.appendChild(subnode)
  569:     
  570:     writefile=file(path+"/index.meta","w")
  571:     #print path+"/index.meta"
  572:     writefile.write(dom.toxml().encode('utf-8'))
  573:     writefile.close()
  574: 
  575: def manage_AddOSAS_combineTextImageForm(self):
  576:     """interface for adding the OSAS_add_Metadata"""
  577:     pt=PageTemplateFile('Products/OSA_system/zpt/AddOSAS_combineTextImage.zpt').__of__(self)
  578:     return pt()
  579: 
  580: def manage_AddOSAS_combineTextImage(self,id,RESPONSE=None):
  581:     """add the OSAS_root"""
  582:     newObj=OSAS_combineTextImage(id)
  583:     self.Destination()._setObject(id,newObj)
  584:     if RESPONSE is not None:
  585:         RESPONSE.redirect('manage_main')
  586: 
  587:             
  588: InitializeClass(OSAS_combineTextImage)

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