File:  [Repository] / OSAS / OSA_system / OSAS_addfiles.py
Revision 1.22: download - view: text, annotated - select for diffs - revision graph
Fri Apr 2 08:02:15 2004 UTC (20 years, 2 months ago) by dwinter
Branches: MAIN
CVS tags: HEAD
port 86 deleted

    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: 
    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,no_upload=1)
   66: 
   67: 
   68:     security.declarePublic('add2')
   69:     def add2(self):
   70:         """ anlegen naechster schritt"""
   71:         return OSAS_add.add2(self)
   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:                     self.retStr+=spaces(self.depth)+"<input type='checkbox' name='collection' value='%s'>%s</input>"%(attrs.get('url'),attrs.get('name'))+"<br>\n"
  188: 
  189: 
  190:                     
  191:             def endElement(self,name):
  192:                 if name=="element":
  193:                     self.depth-=1
  194: 
  195: 
  196:         parser=make_parser()
  197:         curHandler=requestHandler()
  198:         parser.setContentHandler(curHandler)
  199:         #return urllib.urlopen(URL).read()
  200:         parser.parse(urllib.urlopen(URL))
  201:         return curHandler.retStr
  202: 
  203:     def __init__(self,id,collection):
  204:         self.id=id
  205:         self.collection=collection
  206: 
  207:     def getChilds(self,id,depth,items):
  208:         list=[]
  209:         for object in items:
  210:             if (depth==object[2])&(id==object[0]):
  211:                 list.append(object)
  212:         return list
  213: 
  214:     
  215:     
  216:     def printChilds(self,startItem,depth,items,enddepth):
  217:         """NOT USED ANYMORE"""
  218:         def spaces(depth):
  219:             tmp=""
  220:             k=0
  221:             while k<2*depth:
  222:                 k+=1
  223:                 tmp=tmp+"&nbsp;"+"&nbsp;"
  224:             return tmp
  225: 
  226:         def retLink(object):
  227:             return "<input type='checkbox' name='collection' value='%s'>%s</input>"% (string.join(object.getPhysicalPath(),"."),object.title)
  228:              
  229:         depth+=1
  230:         childs=self.getChilds(startItem,depth,items)
  231:         tmp=""
  232:         for child in childs:
  233:             if depth < enddepth:
  234:                 tmp=tmp+spaces(depth)
  235:                 
  236:                 tmp= tmp+retLink(child[1])+"<br>"+self.printChilds(child[1],depth,items,enddepth)
  237:             else:
  238:                 tmp=tmp+spaces(2*depth)
  239:                 tmp = tmp+retLink(child[1])
  240: 
  241:         return tmp
  242: 
  243: 
  244:     def generateTree(self,depth=10):
  245:         """Erzeugt HTML-Tree der Collection NOTE USED ANYMORE"""
  246:     
  247:         exec("items=self.getPhysicalRoot()."+self.collection+".getCollectionTree()")
  248:         #print items[0][0]
  249: 
  250:         childs=self.printChilds(items[0][0],0,items,depth)
  251:         
  252:         return childs
  253: 
  254:     def getPartners(self):
  255:         """Zeige Partnerliste"""
  256:         exec("items=self.getPhysicalRoot()."+self.collection+".partners.getPartners()")
  257:         return items
  258:     
  259:     def addContextData(self,path):
  260:         """Hinzufügen zu einer Sammlung"""
  261:         try:
  262:             urllib.urlopen(self.REQUEST['SERVER_URL']+path+"/index.meta")
  263:             
  264:         except:
  265:             return self.REQUEST['SERVER_URL']+path+"/index.meta file has to exist!"
  266: 
  267:         links=[(path,'standard storage')]
  268:         
  269:         links+=OSAS_show.readContexts(path) # auslesen von contexten für den link
  270:         #print "LINK",links
  271:         #return links
  272:         self.REQUEST.SESSION['links']=links
  273:         pt=PageTemplateFile('Products/OSA_system/zpt/contextDataMain.zpt').__of__(self)
  274:         return pt()
  275:     
  276:     
  277:     def addContextData2(self,path,collection,context,link,label,description,content_type,responsible,weight,credits=None):
  278:         """Hinzufuegen der Resource"""
  279:         splitted=path.split("/")
  280:         #print "BLU"
  281:         id=splitted[len(splitted)-1]
  282:         title=splitted[len(splitted)-1]
  283:         metalink=self.REQUEST['SERVER_URL']+path+"/index.meta"
  284:         
  285:         #link=TOBEDONE"
  286:         """Hinzufügen der Ressource"""
  287: 
  288:         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})
  289: 
  290:         retStr=urllib.urlopen(collection+"/addResource",params).read()
  291:         if not retStr:
  292:             return "An Error occured adding the resource\n"
  293: 
  294:         urllib.urlopen(collection+"/"+id+"/ECHO_getResourceMD").read()
  295:         #exec("collection_object=self"+collection)
  296:         
  297: 
  298:         
  299:         #ECHO_collection.manage_addECHO_resource(collection_object,id,title,label,description,content_type,responsible,link,metalink,credits,weight,RESPONSE=None)
  300:         #print "HI5"
  301:         #try:
  302:         #    getattr(collection_object,id).ECHO_getResourceMD()
  303:         #except:
  304:         #    """nothing"""
  305:         #return "BLUByy"
  306:         return self.REQUEST.RESPONSE.redirect(self.REQUEST['URL2']+'?path='+path)
  307:         
  308:     manage_options = Folder.manage_options+(
  309:             {'label':'Main Config','action':'add_contextData_config'},
  310:             )
  311:         
  312:      
  313:     def add_contextData_config(self):
  314:         """Main configuration"""
  315:         pt=PageTemplateFile('Products/OSA_system/zpt/ChangeOSAS_add_contextData.zpt').__of__(self)
  316:         return pt()
  317:     
  318:     
  319:     def change_OSAS_add_contextData(self,collection,RESPONSE=None):
  320:         """Change"""
  321:         self.collection=collection
  322:         if RESPONSE is not None:
  323:             RESPONSE.redirect('manage_main')
  324:             
  325: def manage_AddOSAS_add_contextDataForm(self):
  326:     """interface for adding the OSAS_add_Metadata"""
  327:     pt=PageTemplateFile('Products/OSA_system/zpt/AddOSAS_contextData.zpt').__of__(self)
  328:     return pt()
  329: 
  330: def manage_AddOSAS_add_contextData(self,id,collection,RESPONSE=None):
  331:     """add the OSAS_root"""
  332:     newObj=OSAS_add_contextData(id,collection)
  333:     self.Destination()._setObject(id,newObj)
  334:     if RESPONSE is not None:
  335:         RESPONSE.redirect('manage_main')
  336: 
  337:             
  338: InitializeClass(OSAS_add_contextData)
  339: 
  340: class OSAS_add_Presentation(Folder):
  341:     """Hinzufügen der Presentationsinformationen"""
  342:     security=ClassSecurityInfo()
  343: 
  344:     def __init__(self,id):
  345:         """initialize a new instance"""
  346:         self.id = id
  347:         
  348:         
  349:     meta_type='OSAS_add_Presentation'    
  350:     manage_options = Folder.manage_options+(
  351:             {'label':'Main Config','action':'add_Presentation_config'},
  352:             )
  353:         
  354:      
  355:         
  356:     security.declarePublic('add_Presentation_config')
  357:     def add_Presentation_config(self):
  358:         """Main configuration"""
  359:         pt=PageTemplateFile('Products/OSA_system/zpt/ChangeOSAS_addPresentation.zpt').__of__(self)
  360:         return pt()
  361:     
  362:     security.declarePublic('change_OSAS_add_Presentation')
  363:     def change_OSAS_add_Presentation(self,RESPONSE=None):
  364:         """Change"""
  365: #        self.RootFolderName=RootFolderName
  366:         if RESPONSE is not None:
  367:             RESPONSE.redirect('manage_main')
  368: 
  369:     def addPresentation(self,path):
  370:         """Hinzufügen der Presenationsinformation"""
  371:         return OSAS_add.addPresentation(self,path)
  372: 
  373:     def addPresentation2(self):
  374:         """Eingabe von Metadateninformationen"""
  375:         return OSAS_add.addPresentation2(self)
  376:     
  377: def manage_AddOSAS_add_PresentationForm(self):
  378:     """interface for adding the OSAS_add_Metadata"""
  379:     pt=PageTemplateFile('Products/OSA_system/zpt/AddOSAS_presentation.zpt').__of__(self)
  380:     return pt()
  381: 
  382: def manage_AddOSAS_add_Presentation(self,id,RESPONSE=None):
  383:     """add the OSAS_root"""
  384:     newObj=OSAS_add_Presentation(id)
  385:     self.Destination()._setObject(id,newObj)
  386:     if RESPONSE is not None:
  387:         RESPONSE.redirect('manage_main')
  388: 
  389:             
  390: InitializeClass(OSAS_add_Presentation)
  391: 
  392: class OSAS_combineTextImage(Folder):
  393:     """Hinzufüge der Combine Text und Image"""
  394:     security=ClassSecurityInfo()
  395: 
  396:     def __init__(self,id):
  397:         """initialize a new instance"""
  398:         self.id = id
  399:         
  400:         
  401:     meta_type='OSAS_combineTextImage'    
  402:     manage_options = Folder.manage_options+(
  403:             {'label':'Main Config','action':'combineTextImage_config'},
  404:             )
  405:         
  406: 
  407:         
  408:     security.declarePublic('combineTextImage_config')
  409:     def combineTextImage_config(self):
  410:         """Main configuration"""
  411:         pt=PageTemplateFile('Products/OSA_system/zpt/ChangeOSAS_combineTextImage.zpt').__of__(self)
  412:         return pt()
  413:     
  414:     security.declarePublic('change_OSAS_combineTextImage')
  415:     def change_OSAS_combineTextImage(self,RESPONSE=None):
  416:         """Change"""
  417: #        self.RootFolderName=RootFolderName
  418:         if RESPONSE is not None:
  419:             RESPONSE.redirect('manage_main')
  420:             
  421:     security.declarePublic('combineTextImage')
  422:     def combineTextImage(self,path):
  423:         """Hinzufügen der Presenationsinformation"""
  424:         """gibt input formular zur erstellung des texttools meta tag aus"""
  425: 	files = os.listdir(path)
  426: 	
  427: 	texts=[]
  428: 	imagefolders=[]
  429: 	presentationfolders=[]
  430: 
  431: 	splitted=path.split("/")
  432: 	externxml=readArchimedesXML(splitted[len(splitted)-1])
  433: 	
  434: 	for filename in files:
  435: 		#print "FN",filename
  436: 		if archive.isdigilib2(path+"/"+filename):
  437: 			imagefolders.append(filename)
  438: 			
  439: 		if archive.isFullText(path,filename):
  440: 			#print "HI"
  441: 			texts.append(filename)
  442: 		if archive.isPresentation(path,filename):
  443: 			presentationfolders.append(filename)
  444: 	
  445: 	dom=xml.dom.minidom.parse(path+"/index.meta")
  446: 	try:
  447: 		filelanguage=archive.getText(dom.getElementsByTagName('lang')[0].childNodes)
  448: 	except:
  449: 		filelanguage=""
  450:                 
  451: 	self.REQUEST.SESSION['isolist']=getISO()
  452: 	tmp=getISO().keys()
  453: 	tmp.sort()
  454: 	self.REQUEST.SESSION['isolistsort']=tmp
  455: 	self.REQUEST.SESSION['path']=path
  456: 	self.REQUEST.SESSION['texts']=texts
  457: 	self.REQUEST.SESSION['imagefolders']=imagefolders
  458: 	self.REQUEST.SESSION['presentationfolders']=presentationfolders
  459: 	self.REQUEST.SESSION['filelanguage']=filelanguage
  460: 	self.REQUEST.SESSION['externxml']=externxml
  461: 
  462: 	newtemplate=PageTemplateFile('Products/OSA_system/zpt/ImageandText').__of__(self)
  463: 	return newtemplate()
  464: 	
  465:     def getProjects(self,obj_ids=None):
  466:         """Get the Project title for configuration"""
  467:         ret=[]
  468:         print "HI"
  469:         try:
  470:             projects=self.ZopeFind(self.projects,obj_metatypes=['OSAS_project'],obj_ids=obj_ids)#assumes projects folder somewhere in the hierarchie.
  471:             print "pr"
  472:             for project in projects:
  473:                 ret.append((project[1].title,project[0],project[1]))
  474:             print ret
  475:             return ret
  476:         
  477:         except:
  478:             return [('no Projectfolders','')]
  479: 
  480:     def getTextToolsField(self,path,name,default=''):
  481:         """Lese Textoolsfelder aus index.meta im path aus"""
  482:         
  483:         try:
  484:             dom=xml.dom.minidom.parse(path+"/index.meta")
  485:             node=dom.getElementsByTagName('texttool')[0] #getNode
  486:             subnode=node.getElementsByTagName(name)[0]
  487:             print getText(subnode.childNodes)
  488:             return getText(subnode.childNodes)
  489:         except:
  490:             return default
  491:             
  492: 
  493:     def combineTextImage2(self,path):
  494:         """Eingabe von Metadateninformationen"""
  495:         OSAS_add.combineTextImage2(self,path) # Add images
  496:         splitted=path.split("/")
  497:         linkPath=splitted[len(splitted)-1]
  498:         linkViewerEnvironment="http://nausikaa2.mpiwg-berlin.mpg.de/cgi-bin/toc/toc.x.cgi?dir=%s&step=thumb" % linkPath
  499:         self.REQUEST.SESSION['linkViewerEnvironment']=linkViewerEnvironment
  500: 
  501:         writeToContext(path,linkViewerEnvironment,"ECHO standard environment")
  502:         
  503:         pt=PageTemplateFile('Products/OSA_system/zpt/AddOSAS_combineTextImageFinal.zpt').__of__(self)
  504: 
  505:         return pt()
  506: 
  507:     def isSelectedProject(self,obj,id):
  508:         """is ausgewählt"""
  509:         
  510:         if self.REQUEST['project']==id:
  511:             return 1
  512:         else:
  513:             return None
  514: 
  515: def writeToContext(path,link,description):
  516:     """Created an additional entry to the index.meta file of path"""
  517:     dom=xml.dom.minidom.parse(path+"/index.meta")
  518:     node=dom.getElementsByTagName('resource')[0]
  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>