Annotation of OSAS/OSA_system/OSAS_addfiles.py, revision 1.23

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

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