File:  [Repository] / OSAS / OSA_system / OSAS_addfiles.py
Revision 1.30: download - view: text, annotated - select for diffs - revision graph
Fri Apr 16 07:52:00 2004 UTC (20 years, 2 months ago) by dwinter
Branches: MAIN
CVS tags: HEAD
bug fixed by using the back buttin during upload

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

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