File:  [Repository] / OSAS / OSA_system / OSAS_addfiles.py
Revision 1.26: download - view: text, annotated - select for diffs - revision graph
Tue Apr 6 10:55:16 2004 UTC (20 years, 2 months ago) by dwinter
Branches: MAIN
CVS tags: HEAD
context_type in addfiles changed to contextType

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

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