--- ECHO_content/ECHO_collection.py 2004/06/08 15:25:11 1.108
+++ ECHO_content/ECHO_collection.py 2005/10/23 09:46:26 1.238
@@ -9,11 +9,20 @@ class ECHO_externalLink contains informa
"""
+try:
+ from reportlab.pdfgen import canvas
+ from reportlab.lib.pagesizes import A4
+except:
+ print "PDF generation will not work"
+
+
import string
+import tempfile
import re
import os
import OFS.Image
from types import *
+from OFS.Cache import Cacheable
from OFS.Image import Image
from Globals import DTMLFile
from OFS.Folder import Folder
@@ -28,269 +37,49 @@ from Products.PageTemplates.PageTemplate
from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate
from Globals import Persistent, package_home
from Acquisition import Implicit
-from ECHO_helpers import displayTypes
+from Products.ZCatalog.CatalogPathAwareness import CatalogAware
+import urllib
+import cgi
+import smtplib
+import time
+from Ft.Xml.Domlette import NonvalidatingReader
+from Ft.Xml.Domlette import PrettyPrint, Print
+from Ft.Xml import EMPTY_NAMESPACE
+
+import Ft.Xml.XPath
+import cStringIO
+import zLOG
try:
- from psycopg import libpq
+ from psycopg import libpq
except:
- try:
- from pyPgSQL import libpq
- except:
- print "ECHO_collection: Warning - No libpq imported!"
-
+ try:
+ from pyPgSQL import libpq
+ except:
+ print "ECHO_collection: Warning - No libpq imported!"
+
import xml.dom.minidom
import urllib
import xml.dom.minidom
-from ECHO_graphicalOverview import javaHandler,javaScriptMain
import ECHO_helpers
+from ECHO_helpers import *
+from ECHO_language import *
+from ECHO_movie import *
-def getCopyrightsFromForm(self,argv):
- medias={}
- partners={}
- copyrights={}
-
- copyrightsFinal=[]
- for arg in argv.keys():
-
- if arg[0:5]=='media':
- nm=int(arg[5:])
- medias[nm]=argv[arg]
- elif arg[0:5]=='partn':
- nm=int(arg[5:])
- partners[nm]=argv[arg]
- elif arg[0:5]=='copyr':
- nm=int(arg[5:])
- copyrights[nm]=argv[arg]
-
-
-
- copyrightsList=[(medias[nm],partners[nm],copyrights[nm]) for nm in medias.keys()]
- for copyright in copyrightsList:
-
- if copyright[2]=='institution0000':
- copyrightsFinal.append((copyright[0],copyright[1],self.getPartnerCopyright(copyright[1],'')))
- else:
- if not copyright[0]=='':
- copyrightsFinal.append(copyright)
-
-
- return copyrightsFinal
-
-#List of different types for the graphical linking viewer
-viewClassificationListMaster=['view point','area']
-
-
-def checkDiffs(self,metadict):
- """check differences"""
-
-
-
-
- def NoneToEmpty(obj):
- if obj:
- return obj
- else:
- return ""
-
-
-
- diffs={}
-
- tags=self.findTagsFromMapping(self.contentType)
- self.referencetypes=tags[2]
- self.fields=tags[3]
-
-
- for field in tags[1]:
- try:
- if (NoneToEmpty(self.getFieldValue(self.getFieldTag(tags,field)))==metadict[self.getFieldTag(tags,field)]):
- diffs[self.getFieldTag(tags,field)]=1
- else:
-
- diffs[self.getFieldTag(tags,field)]=0
- except:
- diffs[self.getFieldTag(tags,field)]=0
-
- return diffs
-
-def content_html(self,type):
- """template fuer content"""
- #templates = self.ZopeFind(self.aq_parent,obj_ids=[type+"_template"])
- #
- #if templates:
- # return templates[0][1]()
-
- if hasattr(self,type+"_template"):
- obj=getattr(self,type+"_template")
- return obj()
- else:
- pt=PageTemplateFile('Products/ECHO_content/zpt/ECHO_%s_template_standard.zpt'%type).__of__(self)
- pt.content_type="text/html"
- return pt()
-
-def toList(field):
- """Einzelfeld in Liste umwandeln"""
- if type(field)==StringType:
- return [field]
- else:
- return field
-
-def getText(nodelist):
+#regexp for extracting elements from xml
+patternTXT=r"<\s*txt.*?>(.*?)"
+regexpTXT = re.compile(patternTXT, re.IGNORECASE + re.DOTALL)
+patternPage=r"<\s*page.*?>(.*?)"
+regexpPage = re.compile(patternPage, re.IGNORECASE + re.DOTALL)
- rc = ""
- for node in nodelist:
- if node.nodeType == node.TEXT_NODE:
- rc = rc + node.data
- return rc
-
-
-def sendFile(self, filename, type):
- """sends an object or a local file (in the product) as response"""
- paths = filename.split('/')
- object = self
- # look for an object called filename
- for path in paths:
- if hasattr(object, path):
- object = getattr(object, path)
- else:
- object = None
- break
- if object:
- # if the object exists then send it
- return object.index_html(self.REQUEST.REQUEST, self.REQUEST.RESPONSE)
- else:
- # send a local file with the given content-type
- fn = os.path.join(package_home(globals()), filename)
- self.REQUEST.RESPONSE.setHeader("Content-Type", type)
- self.REQUEST.RESPONSE.write(file(fn).read())
- return
-
-class BrowserCheck:
- """check the browsers request to find out the browser type"""
-
- def __init__(self, zope):
- self.ua = zope.REQUEST.get_header("HTTP_USER_AGENT")
- self.isN4 = (string.find(self.ua, 'Mozilla/4.') > -1) and (string.find(self.ua, 'MSIE') < 0)
- self.isIE = string.find(self.ua, 'MSIE') > -1
- self.nav = self.ua[string.find(self.ua, '('):]
- ie = string.split(self.nav, "; ")[1]
- if string.find(ie, "MSIE") > -1:
- self.versIE = string.split(ie, " ")[1]
- self.isMac = string.find(self.ua, 'Macintosh') > -1
- self.isWin = string.find(self.ua, 'Windows') > -1
- self.isIEWin = self.isIE and self.isWin
- self.isIEMac = self.isIE and self.isMac
-
-
-def writeMetadata(url,metadict):
- """Einlesen der Metadaten und und erstellen des geaenderten XML file"""
-
- try:
- geturl=""
- for line in urllib.urlopen(url).readlines():
- geturl=geturl+line
-
-
- except:
- return (None,"Cannot open: "+url)
-
- try:
- dom=xml.dom.minidom.parseString(geturl)
- except:
- return (None,"Cannot parse: "+url+"
"+geturl)
-
- metanodes=dom.getElementsByTagName('bib')
-
- if not metanodes:
- metanodes=dom.getElementsByTagName('archimedes')
-
- metanode=metanodes[0]
-
- for metaData in metadict.keys():
-
- try:
- nodeOld=metanode.getElementsByTagName(metaData)
- except:
- nodeOld=None
-
- if nodeOld:
- metanode.removeChild(nodeOld[0]).unlink()
- else:
- # try also old writing rule - instead of _:
- try:
- nodeOld=metanode.getElementsByTagName(re.sub('_','-',metaData))
- except:
- nodeOld=None
-
- if nodeOld:
- metanode.removeChild(nodeOld[0]).unlink()
-
- metanodeneu=dom.createElement(metaData)
- try:
- metanodetext=dom.createTextNode(unicode(metadict[metaData],"utf-8"))
- except:
- metanodetext=dom.createTextNode(metadict[metaData].encode('utf-8'))
- metanodeneu.appendChild(metanodetext)
- metanode.appendChild(metanodeneu)
-
-
- return dom.toxml().encode('utf-8')
-
-
-
-def readMetadata(url):
- """Methode zum Auslesen der Metadateninformation zu einer Resource
- Vorerst noch Typ bib"""
-
- metadict={}
- try:
- geturl=""
- for line in urllib.urlopen(url).readlines():
- geturl=geturl+line
-
-
- except:
- return (None,"Cannot open: "+url)
-
- try:
- dom=xml.dom.minidom.parseString(geturl)
- except:
- return (None,"Cannot parse: "+url+"
"+geturl)
-
- metanode=dom.getElementsByTagName('bib')
- metadict['bib_type']='Book'
- if len(metanode)==0:
- metanode=dom.getElementsByTagName('archimedes')
- metadict['bib_type']='Archimedes'
-
-
- if not len(metanode)==0:
- metacontent=metanode[0].childNodes
-
- try:
- metadict['bib_type']=getText(dom.getElementsByTagName('bib')[0].attributes['type'].childNodes)
- except:
- """nothing"""
-
- for node in metacontent:
- try:
- #print urllib.unquote(getText(node.childNodes)),getText(node.childNodes)
- metadict[re.sub('-','_',node.tagName.lower())]=urllib.unquote(getText(node.childNodes))
- except:
- """nothing"""
-
-
- return metadict,""
-
+
-def setECHO_collectionInformation(self,title,label,description,contentType,responsible,credits,weight,coordstrs,viewClassification=""):
+def setECHO_collectionInformation(self,title,label,description,contentType,responsible,credits,weight,coordstrs=""):
"""Allegemeine Informationen zu einer ECHO Collection"""
- self.viewClassification=viewClassification
-
self.label = label
self.title=title
self.description=description
@@ -299,79 +88,112 @@ def setECHO_collectionInformation(self,t
self.credits=toList(credits)
self.weight=weight
- coords=[]
- #coordinates of for rectangles
+class ECHO_locale(ZopePageTemplate):
+ """localisierung"""
+
+ meta_type="ECHO_locale"
+
+ def __init__(self,id,lang,title,label,text=None,content_type=None):
+ self.lang=lang
+ self.title=title
+ self.label=label
+ if text:
+ self.pt_edit(text, content_type)
+ self.id=id
+
+ manage_options = ZopePageTemplate.manage_options+(
+ {'label':'Main Config','action':'change_ECHO_localeForm'},
+ )
+
+ def change_ECHO_localeForm(self):
+ """change form"""
+ pt=zptFile(self, 'zpt/ChangeECHO_localeForm.zpt')
+ return pt()
+
+ def change_ECHO_locale(self,lang,title,label,text=None,content_type=None,RESPONSE=None):
+ """change echo locale"""
+ self.lang=lang
+ self.title=title
+ self.label=label
+ if not text is None:
+ self.pt_edit(text, content_type)
+
+ if RESPONSE is not None:
+ RESPONSE.redirect('manage_main')
+
+
+def manage_addECHO_localeForm(self):
+ """Form for adding"""
+ pt=zptFile(self, 'zpt/AddECHO_localeForm.zpt')
+ return pt()
+def manage_addECHO_locale(self,lang,title,label,text=None,content_type=None,RESPONSE=None):
+ """add echo locale"""
+
+ id="locale_"+lang
- if coordstrs:
- for coordstr in coordstrs:
+ self._setObject(id, ECHO_locale(id,lang,title,label,text,content_type))
+ if RESPONSE is not None:
+ RESPONSE.redirect('manage_main')
+
+
+class ECHO_copyright(Folder,ECHO_basis):
+ """Copyright informationen"""
+ meta_type="ECHO_copyright"
- try:
- temco=coordstr.split(",")
- except:
- temco=[]
- coords.append(temco)
-
+
+ def __init__(self,id,title,copyrights):
+ """init"""
+ self.title=title
+ self.id=id
+ self.copyrights=copyrights[0:]
- self.coords=coords[0:]
-
-class ECHO_copyright(Folder):
- """Copyright informationen"""
- meta_type="ECHO_copyright"
-
-
-
- def __init__(self,id,title,copyrights):
- """init"""
- self.title=title
- self.id=id
- self.copyrights=copyrights[0:]
-
- def getCopyrights(self):
- """return coyprights"""
- return self.copyrights
-
- manage_options = Folder.manage_options+(
- {'label':'Main Config','action':'ECHO_copyright_configForm'},
- )
-
- def ECHO_copyright_configForm(self):
- """change form"""
- pt=PageTemplateFile('Products/ECHO_content/zpt/ChangeECHO_copyright').__of__(self)
- pt.content_type="text/html"
- return pt()
-
- def ECHO_copyright_config(self,title,RESPONSE):
- """change"""
- self.title=title
- self.copyrights=[]
- self.copyrights=getCopyrightsFromForm(self,self.REQUEST.form)[0:]
+ def getCopyrights(self):
+ """return coyprights"""
+ return self.copyrights
+
+ manage_options = Folder.manage_options+(
+ {'label':'Main Config','action':'ECHO_copyright_configForm'},
+ )
+
+
+ def ECHO_copyright_configForm(self):
+ """change form"""
+ pt=zptFile(self, 'zpt/ChangeECHO_copyright')
+ pt.content_type="text/html"
+ return pt()
+
+ def ECHO_copyright_config(self,title,RESPONSE=None):
+ """change"""
+ self.title=title
+ self.copyrights=[]
+ self.copyrights=getCopyrightsFromForm(self,self.REQUEST.form)[0:]
- if RESPONSE is not None:
- RESPONSE.redirect('manage_main')
+ if RESPONSE is not None:
+ RESPONSE.redirect('manage_main')
-
+
def manage_addECHO_copyrightForm(self):
"""Form for adding"""
- pt=PageTemplateFile('Products/ECHO_content/zpt/AddECHO_copyright.zpt').__of__(self)
+ pt=zptFile(self, 'zpt/AddECHO_copyright.zpt')
return pt()
def manage_addECHO_copyright(self, id,title,RESPONSE=None):
- """add the copyright"""
+ """add the copyright"""
- meta_type="ECHO_copyright"
-
- #first generate copyrights as list of tripels (mediaType,partner,copyrightType)
-
-
-
- self._setObject(id, ECHO_copyright(id, title,getCopyrightsFromForm(self,self.REQUEST.form)))
-
- if RESPONSE is not None:
- RESPONSE.redirect('manage_main')
-
-class ECHO_layoutTemplate(ZopePageTemplate):
+ meta_type="ECHO_copyright"
+
+ #first generate copyrights as list of tripels (mediaType,partner,copyrightType)
+
+
+
+ self._setObject(id, ECHO_copyright(id, title,getCopyrightsFromForm(self,self.REQUEST.form)))
+
+ if RESPONSE is not None:
+ RESPONSE.redirect('manage_main')
+
+class ECHO_layoutTemplate(ZopePageTemplate,ECHO_basis):
"""Create a layout Template for different purposes"""
meta_type="ECHO_layoutTemplate"
@@ -379,26 +201,18 @@ class ECHO_layoutTemplate(ZopePageTempla
def __init__(self, id, text=None, content_type=None,EchoType=None):
self.id = str(id)
-
-
self.ZBindings_edit(self._default_bindings)
if text is None:
- self._default_content_fn = os.path.join(package_home(globals()),
- 'zpt/ECHO_%s_template_standard.zpt'%EchoType)
+ self._default_content_fn = os.path.join(package_home(globals()),'zpt','ECHO_%s_template_standard.zpt'%EchoType)
text = open(self._default_content_fn).read()
self.pt_edit(text, content_type)
-
- """change form"""
-
def manage_addECHO_layoutTemplateForm(self):
"""Form for adding"""
- pt=PageTemplateFile('Products/ECHO_content/zpt/AddECHO_layoutTemplate.zpt').__of__(self)
+ pt=zptFile(self, 'zpt/AddECHO_layoutTemplate.zpt')
return pt()
-from urllib import quote
-
def manage_addECHO_layoutTemplate(self, EchoType,title=None,REQUEST=None):
"Add a Page Template with optional file content."
@@ -439,75 +253,614 @@ def manage_addECHO_layoutTemplate(self,
REQUEST.RESPONSE.redirect(u+'/manage_main')
return ''
-class ECHO_resource(Folder,Persistent):
+class ECHO_fullText(ZopePageTemplate,ECHO_basis,ECHO_language):
+ """echo fulltext in xml"""
+
+ meta_type="ECHO_fullText"
+
+
+ def getPage(self,nr='1'):
+ """get page n"""
+ #return self().encode('latin-1','ignore')
+ dom=xml.dom.minidom.parseString(self().encode('utf-8','ignore'))
+ pages=dom.getElementsByTagName('page')
+
+ return pages[int(nr)-1].toxml()
+
+# Product registration and Add support
+manage_addECHO_fullTextForm = PageTemplateFile(
+ 'zpt/AddECHO_fullText.zpt', globals())
+
+def manage_addECHO_fullText(self, id, title=None, text=None,
+ REQUEST=None, submit=None):
+ "Add a Page Template with optional file content."
+
+ id = str(id)
+ if REQUEST is None:
+ self._setObject(id, ECHO_fullText(id, text))
+ ob = getattr(self, id)
+ if title:
+ ob.pt_setTitle(title)
+ return ob
+ else:
+ file = REQUEST.form.get('file')
+ headers = getattr(file, 'headers', None)
+ if headers is None or not file.filename:
+ zpt = ECHO_fullText(id)
+ else:
+ zpt = ECHO_fullText(id, file, headers.get('content_type'))
+
+ self._setObject(id, zpt)
+
+ try:
+ u = self.DestinationURL()
+ except AttributeError:
+ u = REQUEST['URL1']
+
+ if submit == " Add and Edit ":
+ u = "%s/%s" % (u, urllib.quote(id))
+ REQUEST.RESPONSE.redirect(u+'/manage_main')
+ return ''
+
+
+class ECHO_resource(CatalogAware,Folder,Persistent,ECHO_basis):
"""ECHO Ressource"""
+ security=ClassSecurityInfo()
meta_type='ECHO_resource'
+ default_catalog='resourceCatalog'
+
+# viewClassificationList=viewClassificationListMaster
- viewClassificationList=viewClassificationListMaster
+ def PrincipiaSearchSource(self):
+ """Return cataloguable key for ourselves."""
+ return str(self)
getSubCols = ECHO_helpers.getSubCols
+ def reindex(self):
+ """generate fields for indexing and reindex"""
+ import urlparse
+ #TODO: korrigieren des metalink pfades konfigurierbar machen
+ splitted= [x for x in urlparse.urlparse(self.metalink)]
+ splitted[1]="foxridge.mpiwg-berlin.mpg.de"[0:]
+
+ if splitted[0]=="http":
+ self.metalink=urlparse.urlunparse(splitted)
+
+
+ self.fullTextUrl=self.getFullTextXML(noredirect="yes")
+
+ #TODO: korrigieren relative url to absoluter url volltexten, konfigurierbar?
+ splitted= [x for x in urlparse.urlparse(self.fullTextUrl)]
+ if splitted[0]=="":
+ splitted[0]="http"
+ splitted[1]="foxridge.mpiwg-berlin.mpg.de"[0:]
+
+ self.fullTextUrl=urlparse.urlunparse(splitted)
+
+ self.imagePath=self.getImagePath()
+
+ self.reindex_object()
+
+
+ security.declareProtected('View','createPDF')
+ def createPDF(self,RESPONSE=None,local=None,dpi=150):
+ """erzeuge pdf file"""
+ pages=1
+ dpi=float(dpi)
+ imagePath=self.getImagePath().replace("/mpiwg/online","")
+
+
+ image="http://nausikaa2.mpiwg-berlin.mpg.de/digitallibrary/servlet/Scaler?fn="+imagePath+"&dw=%i&dh=%i&pn=%i"
+ xmlInfo="http://nausikaa2.mpiwg-berlin.mpg.de/digitallibrary/dlInfo-xml.jsp?fn="+imagePath
+
+ dom=xml.dom.minidom.parse(urllib.urlopen(xmlInfo))
+ for parameter in dom.getElementsByTagName('parameter'):
+ if parameter.getAttribute('name')=="pt":
+ pages=int(parameter.getAttribute('value'))
+ break
+
+
+ tempdir="/tmp/archivesImageServer"
+ if not os.path.exists(tempdir):
+ os.mkdir(tempdir)
+
+ tmpPath=tempfile.mkdtemp(dir=tempdir)
+
+
+ tmpZip=tempfile.mktemp(dir=tempdir)
+
+ tmpFn=os.path.split(tmpZip)[1]
+
+
- def getTitle(self):
- """title"""
- return self.title.encode('utf-8')
- def getLabel(self):
- """title"""
- return self.label.encode('utf-8')
+ if RESPONSE:
+ RESPONSE.setHeader("Content-Type","text/html")
+ RESPONSE.write("
I am creating the pdf
")
+ txt="1. step: getting the images( %i pages)
"%pages
+ RESPONSE.write(txt)
+
+ c=canvas.Canvas(tmpZip)
+ for i in range(1,pages+1):
+ if RESPONSE:
+ RESPONSE.write(str("Get Page: %i
\n"%i))
+ faktor=dpi/72.0
+
+ fn=tmpPath+"/%i"%i
+
+ width,height=A4
+ #print image%(width*faktor,height*faktor,i)
+ url=urllib.urlopen(image%(width*faktor,height*faktor,i)).read()
+ fh=file(fn,"w")
+ fh.write(url)
+ fh.close()
+
+
+
+ c.drawImage(fn,0,0,width=width,height=height)
+ c.showPage()
+ c.save()
+ if RESPONSE:
+ RESPONSE.write("
finished
\n")
+
+ if RESPONSE:
+ len=os.stat(tmpZip)[6]
+ downloadUrl=self.absolute_url()+"/downloadPDF"
+ RESPONSE.write("""
\n"""%(tmpFn,len))
+ RESPONSE.write("""The file will be stored for a while, you can download it later, the URL is:
+ %s?fn=%s\n"""%(tmpFn,downloadUrl,tmpFn))
+ RESPONSE.close()
+
+
+ def downloadPDF(self,fn):
+ """download prepared set"""
+ filename="/tmp/archivesImageServer/"+fn
+ namePDF=self.getId()+".pdf"
+ self.REQUEST.RESPONSE.setHeader("Content-Disposition","""attachement; filename="%s" """%namePDF)
+ self.REQUEST.RESPONSE.setHeader("Content-Type","application/octet-stream")
+ len=os.stat(filename)[6]
+ self.REQUEST.RESPONSE.setHeader("Content-Length",len)
+ images=file(filename).read()
+ self.REQUEST.RESPONSE.write(images)
+ self.REQUEST.RESPONSE.close()
+
+
+ def getRDF(self,urn=None):
+ """rdf"""
+ ret=getRDFDescription(self,self.link,urn=urn)
+ return ret+self.createSubElementRDF(urn=urn)
+
+
+ def getAccessRightSelectorHTML(self,outlook="select"):
+ """htmlselector"""
+ values=['free','mpiwg']
+
+ if outlook=="select":
+ ret=""""
+
+ else:
+ ret=""
+ for value in values:
+
+ if value==self.getAccessRightMD():
+ ret+="""%s"""%(self.getId(),value,value)
+ else:
+ ret+="""%s"""%(self.getId(),value,value)
+ return ret
+
+
+
+ def getAccessRightMD(self):
+ """set accessright"""
+ url=self.metalink
+
+ try:
+ geturl=""
+ for line in ECHO_helpers.urlopen(url).readlines():
+ geturl=geturl+line
+
+ except:
+ return (None,"Cannot open: "+url)
+
+ try:
+ dom=xml.dom.minidom.parseString(geturl)
+ root=dom.getElementsByTagName('resource')[0]
+ except:
+ return (None,"Cannot parse: "+url+"
"+geturl)
+
+ internal=dom.getElementsByTagName('internal')
+ if internal:
+ institution=dom.getElementsByTagName('institution')
+ return getText(institution[0].childNodes)
+
+ free=dom.getElementsByTagName('free')
+ if free:
+ return "free"
+
+ return "free" #default free
+
+ def changeAccessRightMD(self,accessright,RESPONSE=None):
+ """change the rights"""
+
+ params="accessright=%s"%accessright
+
+
+ #print ECHO_helpers.urlopen(self.absolute_url()+'/setAccessRightXML'+'?'+params).read()
+
+
+ ECHO_helpers.urlopen('http://xserve02.mpiwg-berlin.mpg.de:18880/echo_nav/storage/downloadExternalXML?index_meta_url=%s&xml_url=%s'%(self.metalink,self.absolute_url()+'/setAccessRightXML'+urllib.quote('?'+params))).read()
+
+
+ if RESPONSE is not None:
+ RESPONSE.redirect('manage_main')
+
+
+ def setAccessRightXML(self,accessright):
+ """set accessright"""
+ url=self.metalink
+
+ try:
+ geturl=""
+ for line in ECHO_helpers.urlopen(url).readlines():
+ geturl=geturl+line
+
+
+ except:
+ return (None,"Cannot open: "+url)
+
+ try:
+ dom=xml.dom.minidom.parseString(geturl)
+ root=dom.getElementsByTagName('resource')[0]
+ except:
+ return (None,"Cannot parse: "+url+"
"+geturl)
+
+ metanodes=dom.getElementsByTagName('access-conditions')
+
+ if not metanodes:
+ nodenew=dom.createElement('access-conditions')
+ root.appendChild(nodenew)
+ metanode=nodenew
+ else:
+ metanode=metanodes[0]
+
+ accesses=metanode.getElementsByTagName('access')
+
+ if not accesses:
+ nodenew2=dom.createElement('access')
+ metanode.appendChild(nodenew2)
+ metanode2=nodenew2
+ else:
+ metanode2=accesses[0]
+
+ internal=metanode.getElementsByTagName('internal')
+
+ if internal:
+ metanode2.removeChild(internal[0]).unlink()
+
+ free=metanode.getElementsByTagName('free')
+
+ if free:
+ metanode2.removeChild(internal[0]).unlink()
+
+
+ if accessright=='free':
+ nodenew3=dom.createElement('free')
+ metanode2.appendChild(nodenew3)
+ elif accessright=='mpiwg':
+ nodenew3=dom.createElement('internal')
+ nodenew4=dom.createElement('institution')
+ metanodetext=dom.createTextNode('mpiwg')
+ nodenew4.appendChild(metanodetext)
+ nodenew3.appendChild(nodenew4)
+ metanode2.appendChild(nodenew3)
+
+ return dom.toxml().encode('utf-8')
+
+ def setStartPageForm(self):
+ """Form for changing the startpage"""
+
+
+ pt=zptFile(self, 'zpt/ChangeECHO_resourceStartPage.zpt')
+ pt.content_type="text/html"
+ return pt()
+
+
+ def createImageUrl(self,pn=1):
+ """create ImageUrl"""
+
+
+ resourcepath=readFieldFromXML(self.metalink,'resource','archive-path')
+
+ digiliburlprefix=readFieldFromXML(self.metalink,'texttool','digiliburlprefix')
+ images=readFieldFromXML(self.metalink,'texttool','image')
+
+
+ if (not resourcepath) or (not digiliburlprefix) or (not images):
+ zLOG.LOG("ECHO (createImageUrl)",zLOG.ERROR,"Cannot create ImageUrl for %s"%self.absolute_url())
+ return None
+ resourcepath=resourcepath.replace('/mpiwg/online','')
+ if not digiliburlprefix: digiliburlprefix="http://echo.mpiwg-berlin.mpg.de/zogilib?"
+
+ if (not images) or (not resourcepath): return None
+
+ return "%sfn=%s&pn=%i"%(digiliburlprefix,resourcepath+"/"+images,pn)
+
+ def copyTitleToInfoXML(self,RESPONSE=None):
+ """copy title from the resource"""
+ presentationXML=readFieldFromXML(self.metalink,'texttool','presentation')
+ resourcepath=readFieldFromXML(self.metalink,'resource','archive-path')
+ if (not presentationXML) or (not resourcepath):
+ if RESPONSE:
+ RESPONSE.write("Error: %s\n"%self.getId())
+ else:
+ return None,self.absolute_url()
+
+ try:
+ fh=file(os.path.join(resourcepath,presentationXML),'w')
+ fh.write("""
+
+ %s
+
+ yes
+ """%self.title)
+ fh.close()
+ return 1,self.getId()
+ except:
+ if RESPONSE:
+ RESPONSE.write("Error: %s\n"%self.getId())
+ else:
+ return None,self.absolute_url()
+
+
+ def setStartPage(self,startpage=None,RESPONSE=None):
+ """set start page, if no startpage defined use the generic one of the resource"""
+
+ if (not (type(startpage)==StringType)):
+ if ("__generic" in startpage): # checke ob generic in der liste
+ startpage=self.absolute_url()+"/startpage_html"
+ elif ("__firstPage" in startpage): # checke ob generic in der liste
+ startpage=self.createImageUrl()
+
+ if (not startpage):
+ startpage=self.absolute_url()+"/startpage_html"
+ elif (startpage=="__generic"):
+ startpage=self.absolute_url()+"/startpage_html"
+ elif (startpage=="__firstPage"):
+ startpage=self.createImageUrl()
+
+ params="startpage=%s"%startpage
+ #print 'http://xserve02.mpiwg-berlin.mpg.de:18880/echo_nav/storage/downloadExternalXML?index_meta_url=%s&xml_url=%s'%(self.metalink,self.absolute_url()+'/newMetaXML'+urllib.quote('?'+params))
+
+ ECHO_helpers.urlopen('http://xserve02.mpiwg-berlin.mpg.de:18880/echo_nav/storage/downloadExternalXML?index_meta_url=%s&xml_url=%s'%(self.metalink,self.absolute_url()+'/newMetaXML'+urllib.quote('?'+params))).read()
+
+
+ path=self.metalink
+
+ path=re.sub(self.REQUEST['SERVER_URL'],'',path)
+ path=re.sub('http://'+self.REQUEST['HTTP_HOST'],'',path)
+
+ path=re.sub('http://foxridge.mpiwg-berlin.mpg.de:8080','',path) # falls foxridge als server
+ path=re.sub('http://foxridge.mpiwg-berlin.mpg.de','',path) # falls foxridge als server
+ path=re.sub('http://foxridge.rz-berlin.mpg.de:8080','',path) # falls foxridge als server
+ path=re.sub('http://content.mpiwg-berlin.mpg.de','',path) # falls content als server
+ path=re.sub('http://foxridge.rz-berlin.mpg.de','',path) # falls foxridge als server
+ path=re.sub('http://vision.mpiwg-berlin.mpg.de','',path) # falls vision als server
+ path=re.sub('http://xserve02.mpiwg-berlin.mpg.de:18880','',path) # falls vision als server
+ path=re.sub('http://echo.mpiwg-berlin.mpg.de','',path) # falls echo
+ path=re.sub('/index.meta','',path)
+
+
+ ECHO_helpers.urlopen("http://nausikaa2.rz-berlin.mpg.de:86/cgi-bin/toc/admin/reg.cgi?path=%s"%path).readlines()
+
+ if RESPONSE is not None:
+ RESPONSE.redirect('manage_main')
+
+ def changeViewerTemplateSetForm(self):
+ """change the viewer template set"""
+ pt=zptFile(self, 'zpt/changeResourceViewerTemplateSet')
+ return pt()
+
+
+
+ def getTextToolsField(self,name,default=''):
+ """Lese Textoolsfelder aus index.meta im path aus"""
+
+ try:
+ dom=xml.dom.minidom.parse(self.metalink)
+ node=dom.getElementsByTagName('texttool')[0] #getNode
+ subnode=node.getElementsByTagName(name)[0]
+
+ # bei text wird nur der Folder gebraucht
+ if name=="text":
+ splitted=getText(subnode.childNodes).split("/")
+ return splitted[len(splitted)-2]
+ else:
+ return getText(subnode.childNodes)
+ except:
+ return default
+
+
+ def changeViewerTemplateSet(self,project,xslt,thumbtemplate,topbar,digiLibTemplate,digiliburlprefix,RESPONSE=None):
+ """changeit"""
+
+ paramList=['project','startpage','xslt','thumbtemplate','topbar','digiLibTemplate','digiliburlprefix']
+
+
+ #writeMetadata(self.metalink,self.metaDataHash,project,None,xslt,thumbtemplate,topbar,digiLibTemplate)
+
+ params="project=%s&xslt=%s&thumbtemplate=%s&topbar=%s&digiLibTemplate=%s&digiliburlprefix=%s"%(project,xslt,thumbtemplate,topbar,digiLibTemplate,digiliburlprefix)
+
+
+ ECHO_helpers.urlopen('http://echo.mpiwg-berlin.mpg.de/echo_nav/storage/downloadExternalXML?index_meta_url=%s&xml_url=%s'%(self.metalink,self.absolute_url()+'/newMetaXML'+urllib.quote('?'+params))).read()
+
+ #print self.absolute_url()+'/newMetaXML'+urllib.quote'?'+params)
+ # hack Pfad auf die Dokumente
+ path=self.metalink
+
+
+
+ path=re.sub('/index.meta','',path)
+
+ path=re.sub(self.REQUEST['SERVER_URL'],'',path)
+ path=re.sub('http://'+self.REQUEST['HTTP_HOST'],'',path)
+
+ path=re.sub('http://foxridge.mpiwg-berlin.mpg.de:8080','',path) # falls foxridge als server
+ path=re.sub('http://foxridge.mpiwg-berlin.mpg.de:8080','',path) # falls foxridge als server
+ path=re.sub('http://foxridge.mpiwg-berlin.mpg.de','',path) # falls foxridge als server
+
+ path=re.sub('http://foxridge.rz-berlin.mpg.de:8080','',path) # falls foxridge als server
+ path=re.sub('http://foxridge.rz-berlin.mpg.de','',path) # falls foxridge als server
+ path=re.sub('http://content.mpiwg-berlin.mpg.de','',path) # falls content als server
+ path=re.sub('http://echo.mpiwg-berlin.mpg.de','',path) # falls echo
+
+ path=re.sub('http://vision.rz-berlin.mpg.de','',path) # falls vision als server
+
+ return ECHO_helpers.urlopen("http://nausikaa2.rz-berlin.mpg.de:86/cgi-bin/toc/admin/reg.cgi?path=%s"%path).readlines()
+
+
+ if RESPONSE is not None:
+ RESPONSE.redirect('manage_main')
+
+
+
+ security.declarePublic('content_html')
def content_html(self):
"""template fuer content"""
- return content_html(self,'resource')
+ return ECHO_basis.content_html(self,'resource')
- def getViewClassification(self):
- if hasattr(self,'viewClassification'):
- return self.viewClassification
- else:
- return ""
+# def getViewClassification(self):
+# if hasattr(self,'viewClassification'):
+# return self.viewClassification
+# else:
+# return ""
def getFullTextXML(self,noredirect=None):
- """getFullTextXML; gives the FullText as an XML Document, and if somthing goes wrong."""
- try:
- fh=urllib.urlopen(self.metalink)
- dom=xml.dom.minidom.parse(fh)
- texttools=dom.getElementsByTagName('texttool')
- text=texttools[0].getElementsByTagName('text')
- texturl=getText(text[0].childNodes)
- self.REQUEST.RESPONSE.setHeader('Content-Type','text/xml')
- if not noredirect:
- self.REQUEST.RESPONSE.redirect(texturl)
- else:
- return texturl
- except:
-
- if not noredirect:
- self.REQUEST.RESPONSE.setHeader('Content-Type','text/xml')
- self.REQUEST.RESPONSE.write("no fulltext available")
- else:
- return "no fulltext available"
+ """getFullTextXML; gives the FullText as an XML Document, and if somthing goes wrong."""
+
+ try:
+ #zLOG.LOG("ECHO Fulltext",zLOG.INFO,"open %s"%self.metalink)
+ fh=ECHO_helpers.urlopen(self.metalink)
+ #zLOG.LOG("ECHO Fulltext",zLOG.INFO,"opened %s"%self.metalink)
+ dom=xml.dom.minidom.parse(fh)
+ texttools=dom.getElementsByTagName('texttool')
+ text=texttools[0].getElementsByTagName('text')
+ texturl=getText(text[0].childNodes)
+
+ #zLOG.LOG("ECHO Fulltext",zLOG.INFO,"found %s"%texturl)
+ fh.close()
+ #zLOG.LOG("ECHO Fulltext",zLOG.INFO,"closed fh")
+ #keine url
+ if not (texturl.split(":")[0] in ['http','ftp','file']):
+ if not noredirect:
+ return file(texturl).read()
+ else:
+ return texturl
+
+ if not noredirect:
+ self.REQUEST.RESPONSE.setHeader('Content-Type','text/xml')
+ zLOG.LOG("ECHO Fulltext",zLOG.INFO,"redirect to:%s"%texturl)
+ self.REQUEST.RESPONSE.redirect(texturl)
+ else:
+ return texturl
+ except:
+ if not noredirect:
+ self.REQUEST.RESPONSE.setHeader('Content-Type','text/xml')
+ self.REQUEST.RESPONSE.write("no fulltext available")
+ else:
+ return "no fulltext available"
+
+ def getImagePath(self):
+ """gibt pfad zum image aus"""
+ return self.getImageView(noredirect="yes",onlyPath="yes")
+
+ def getImageView(self,noredirect=None,onlyPath=None):
+ """getImages; give Imageviewr and if somthing goes wrong."""
+ try:
+ fh=ECHO_helpers.urlopen(self.metalink)
+ dom=xml.dom.minidom.parse(fh)
+ texttools=dom.getElementsByTagName('texttool')
+ text=texttools[0].getElementsByTagName('image')
+ imagetemp=getText(text[0].childNodes)
+
+ text=dom.getElementsByTagName('archive-path')
+ archivepath=getText(text[0].childNodes)
+ archivepath=re.sub('/mpiwg/online/','',archivepath)
+ imageurl="http://echo.mpiwg-berlin.mpg.de/zogilib?fn="+archivepath+"/"+imagetemp
+ fh.close()
+
+ if not noredirect:
+ self.REQUEST.RESPONSE.setHeader('Content-Type','text/xml')
+ self.REQUEST.RESPONSE.redirect(imageurl)
+ else:
+ if not onlyPath:
+ return imageurl
+ else:
+ return archivepath+"/"+imagetemp
+ except:
+
+ if not noredirect:
+ self.REQUEST.RESPONSE.setHeader('Content-Type','text/xml')
+ self.REQUEST.RESPONSE.write("no fulltext available")
+ else:
+ return "no images available"
+
+
def getCopyrightsHTML(self):
- """gib link auf copyright notiz aus"""
-
- if hasattr(self,'copyrightModell'):
- obj=self.copyrightModell
-
- else:
- return "ERROR"
- ret=[]
-
- for copyright in obj.getCopyrights():
-
- link="copyrightTypes/"+copyright[2]+'/copyright.html'
-
- try:
- label=getattr(self.copyrightTypes,copyright[2]).label
- ret.append(("""%s"""%(link,label),copyright[0],copyright[0],copyright[1],copyright[2]))
- except:
- """nothing"""
-
- return ret
+ """gib (link auf copyright link, mediatyp, institution, copyrightType, label von copyrightType) aus"""
+
+ if hasattr(self,'copyrightModel'):
+ obj=self.copyrightModel
+
+ else:
+ return "ERROR"
+ ret=[]
+
+ for copyright in obj.getCopyrights(): #copyright - media / partner / copyrightID
+
+
+ try:
+ if hasattr(self.copyrightTypes,copyright[2]):
+ copyrightTypeObj=getattr(self.copyrightTypes,copyright[2])
+ link="copyrightTypes/"+copyright[2]+'/copyright.html'
+ else:
+ copyrightTypeObj=getattr(obj,copyright[2])
+ link="copyrightModel/"+copyright[2]+'/copyright.html'
+
+ label=copyrightTypeObj.label
+ url=getattr(copyrightTypeObj, 'url', '')
+
+ if url!='':
+ ret.append((url,copyright[0],copyright[1],copyright[2],label))
+ else:
+ if hasattr(copyrightTypeObj, 'copyright.html'):
+ ret.append(("""%s?partner=%s"""%(link,copyright[1]),copyright[0],copyright[1],copyright[2],label))
+ else:
+ ret.append(('empty',copyright[0],copyright[1],copyright[2],label))
+ except:
+ """nothing"""
+
+ return ret
+
+ def getInstitutionsHTML(self):
+ """gibt Liste der foerdernden Institutionen aus"""
+
+ if hasattr(self,'support'):
+ obj=self.support
+ ret=obj.getSupporter()
+ return ret
+ else:
+ return ''
+
def getCredits(self):
"""Ausgabe der credits"""
@@ -515,6 +868,8 @@ class ECHO_resource(Folder,Persistent):
return self.credits
else:
return []
+
+
def __init__(self,id,link,metalink,resourceID,title,label,description,contentType,renderingType,copyrightType,responsible,credits,weight,coords):
@@ -529,47 +884,38 @@ class ECHO_resource(Folder,Persistent):
self.credits=toList(credits)
self.description=description
self.contentType=contentType
- self.copyrightType=copyrightType
- self.renderingType=renderingType
+ self.copyrightType=copyrightType
+ self.renderingType=renderingType
self.responsible=responsible
self.resourceID=resourceID
-
+
if coords:
coordsnew=[ string.split(x,",") for x in coords]
else:
coordsnew=[]
self.coords=coordsnew
+# self.viewClassification=""
- def getCoords(self):
- """gibt coordinaten als String zurück und löscht zugleich einträge die keine Koordinaten sind, letzteres zur korrektur der Eingabe der alten version"""
- retList=[]
- if hasattr(self,'coords'):
- for x in self.coords:
- if len(x)>1:
- retList.append(string.join(x,","))
- return retList
-
-
def getContentType(self):
- try:
- return self.contentType
- except:
- return ""
+ try:
+ return self.contentType
+ except:
+ return ""
def getCopyrightType(self):
- try:
- return self.copyrightType
- except:
- return ""
+ try:
+ return self.copyrightType
+ except:
+ return ""
def getRenderingType(self):
- try:
- return self.renderingType
- except:
- return ""
+ try:
+ return self.renderingType
+ except:
+ return ""
def ECHO_resource_config(self):
"""Main configuration"""
@@ -577,59 +923,55 @@ class ECHO_resource(Folder,Persistent):
if not hasattr(self,'weight'):
self.weight=""
- pt=PageTemplateFile('Products/ECHO_content/zpt/ChangeECHO_resource.zpt').__of__(self)
+ pt=zptFile(self, 'zpt/ChangeECHO_resource.zpt')
return pt()
def ECHO_resource_config_main(self):
"""Main configuration"""
-
if not hasattr(self,'weight'):
self.weight=""
-
- pt=PageTemplateFile('Products/ECHO_content/zpt/ChangeECHO_resource_main.zpt').__of__(self)
+ pt=zptFile(self, 'zpt/ChangeECHO_resource_main.zpt')
return pt()
def ECHO_resource_config_coords(self):
"""Coords configuration """
-
- pt=PageTemplateFile('Products/ECHO_content/zpt/ChangeECHO_resource_coords.zpt').__of__(self)
+ pt=zptFile(self, 'zpt/ChangeECHO_resource_coords.zpt')
return pt()
def ECHO_resource_config_credits(self):
"""Main configuration"""
-
- pt=PageTemplateFile('Products/ECHO_content/zpt/ChangeECHO_resource_credits.zpt').__of__(self)
+ pt=zptFile(self, 'zpt/ChangeECHO_resource_credits.zpt')
return pt()
def ECHO_resource_config_metadata(self):
"""Main configuration"""
+ if (hasattr(self,'metadata')) and not (hasattr(self,'metaDataHash')):
+ self.metaDataHash={}
+ self.contentType=self.bib_type
+ for data in self.metadata:
+ data_neu=re.sub('-','_',data)
+ self.meta
+ DataHash[data_neu]=getattr(self,data)[0:]
- if (hasattr(self,'metadata')) and not (hasattr(self,'metaDataHash')):
- self.metaDataHash={}
- self.contentType=self.bib_type
- for data in self.metadata:
- data_neu=re.sub('-','_',data)
- self.metaDataHash[data_neu]=getattr(self,data)
-
-
- pt=PageTemplateFile('Products/ECHO_content/zpt/ChangeECHO_resource_metadata.zpt').__of__(self)
+
+ pt=zptFile(self, 'zpt/ChangeECHO_resource_metadata.zpt')
return pt()
def changeECHO_resource_main(self,metalink,link,title,label,description,contentType,renderingType,weight,resourceID,RESPONSE=None):
- """Änderung der Properties"""
- self.resourceID=resourceID
- self.title=title
- self.label=label
- self.description=description
-
- self.contentType=contentType
- self.renderingType=renderingType
- self.weight=weight
-
+ """Aenderung der Properties"""
+ self.resourceID=resourceID
+ self.title=title
+ self.label=label
+ self.description=description
+
+ self.contentType=contentType
+ self.renderingType=renderingType
+ self.weight=weight
+
self.link=link
self.metalink=metalink
@@ -637,86 +979,135 @@ class ECHO_resource(Folder,Persistent):
RESPONSE.redirect('manage_main')
- def changeECHO_resource_coords(self,coords,viewClassification,RESPONSE=None):
- """Änderung der Properties - coords"""
-
- if type(coords)==StringType:
- coords=[coords]
-
- try:
- coordsnew=[ string.split(x,",") for x in coords]
- except:
- coordsnew=[]
-
- self.coords=coordsnew[0:]
- self.viewClassification=viewClassification
-
+ def changeECHO_resource_coords(self,RESPONSE=None):
+ """Aenderung der Properties - coords"""
+ #return self.REQUEST
+ for area in self.getMapAreas():
+ id = area.getId()
+ if self.REQUEST.has_key('del.'+id):
+ # delete this area
+ self._delObject(id)
+ # return to same menu
+ if RESPONSE is not None:
+ RESPONSE.redirect('ECHO_resource_config_coords')
+ return
+ # modify this area
+ coordstring = self.REQUEST.get('coords.'+id, '')
+ coords = string.split(coordstring, ',')
+ angle = self.REQUEST.get('angle.'+id, '0')
+ type = self.REQUEST.get('type.'+id, 'area')
+ if len(coords) == 4:
+ area.setCoordString(coordstring)
+ area.setAngle(angle)
+ area.setType(type)
+ # return to main menu
if RESPONSE is not None:
RESPONSE.redirect('manage_main')
+
def changeECHO_resource_credits(self,credits,responsible,copyrightType,RESPONSE=None):
- """Änderung der Properties"""
- self.credits=credits
- self.responsible=responsible
- self.copyrightType=copyrightType
+ """Aenderung der Properties"""
+ self.credits=credits
+ self.responsible=responsible
+ self.copyrightType=copyrightType
if RESPONSE is not None:
RESPONSE.redirect('manage_main')
def changeECHO_resource_metadata_local(self,RESPONSE=None):
- """change metadata"""
- tags=self.findTagsFromMapping(self.contentType)
- for field in tags[1]:
- self.metaDataHash[self.getFieldTag(tags,field)]=self.REQUEST.form[self.getFieldTag(tags,field)]
-
-
-
- if RESPONSE is not None:
- RESPONSE.redirect('manage_main')
+ """change metadata"""
+ tags=self.findTagsFromMapping(self.contentType)
+ for field in tags[1]:
+ self.metaDataHash[self.getFieldTag(tags,field)]=self.REQUEST.form[self.getFieldTag(tags,field)][0:]
+
+
+
+ if RESPONSE is not None:
+ RESPONSE.redirect('manage_main')
def changeECHO_resource_metadata(self,RESPONSE=None):
- """change metadata"""
- tags=self.findTagsFromMapping(self.contentType)
- self.OSAS_meta={}
- for field in tags[1]:
- try:
- self.metaDataHash[self.getFieldTag(tags,field)]=self.REQUEST.form[self.getFieldTag(tags,field)]
- self.OSAS_meta[self.getFieldTag(tags,field)]=self.REQUEST.form['OSAS_%s'%self.getFieldTag(tags,field)]
- except:
- """nothing"""
-
- return urllib.urlopen('http://xserve02.mpiwg-berlin.mpg.de:18880/echo_nav/storage/downloadExternalXML?index_meta_url=%s&xml_url=%s'%(self.metalink,self.absolute_url()+'/newMetaXML')).read()
-
- if RESPONSE is not None:
- RESPONSE.redirect('manage_main')
-
-
- def getMDValue(self,fieldName):
- return self.metaDataHash.get(fieldName,'!!NOT USED HERE in Type: %s'%self.contentType)
-
- def newMetaXML(self):
- """new index.meta"""
- self.REQUEST.RESPONSE.setHeader('Content-Type','text/xml')
- return writeMetadata(self.metalink,self.OSAS_meta)
-
-
- def getMetaDataXML(self):
- """prints out metadata as stored in the echo environment, format is the index.meta format"""
- self.REQUEST.RESPONSE.setHeader('Content-Type','text/xml')
- return writeMetadata(self.metalink,self.metaDataHash)
+ """change metadata"""
+ tags=self.findTagsFromMapping(self.contentType)
+ self.OSAS_meta={}
+ for field in tags[1]:
+ try:
+ self.metaDataHash[self.getFieldTag(tags,field)]=self.REQUEST.form[self.getFieldTag(tags,field)]
+ self.OSAS_meta[self.getFieldTag(tags,field)]=self.REQUEST.form['OSAS_%s'%self.getFieldTag(tags,field)]
+ except:
+ """nothing"""
+
+ ECHO_helpers.urlopen('http://xserve02.mpiwg-berlin.mpg.de:18880/echo_nav/storage/downloadExternalXML?index_meta_url=%s&xml_url=%s'%(self.metalink,self.absolute_url()+'/newMetaXML')).read()
+
+
+ if RESPONSE is not None:
+ RESPONSE.redirect('manage_main')
+
+
+ def getMDValue(self,fieldName,empty=None):
+ if not empty:
+ return self.metaDataHash.get(fieldName,'!!NOT USED HERE in Type: %s'%self.contentType)
+
+ else:
+ return self.metaDataHash.get(fieldName,empty)
+
+ def newMetaXML(self,project=None,startpage=None,xslt=None,thumbtemplate=None,topbar=None,digiLibTemplate=None,digiliburlprefix=None):
+ """new index.meta"""
+ self.REQUEST.RESPONSE.setHeader('Content-Type','text/xml')
- def changeECHO_resource(self,metalink,link,title,label,description,contentType,responsible,weight,viewClassification="",coords=None,credits=None,RESPONSE=None):
- """Änderung der Properties"""
+ if not hasattr(self,'metaDataHash'):
+
+ self.copyIndex_meta2echo_resource()
+ try:
+ return writeMetadata(self.metalink,self.OSAS_meta,project,startpage,xslt,thumbtemplate,topbar,digiLibTemplate,digiliburlprefix=digiliburlprefix)
+ except:
+ return writeMetadata(self.metalink,self.metaDataHash,project,startpage,xslt,thumbtemplate,topbar,digiLibTemplate,digiliburlprefix=digiliburlprefix)
+
+ def showMetaDataXML(self,project=None,startpage=None,xslt=None,thumbtemplate=None,topbar=None,digiLibTemplate=None):
+ """return bibliographical metadata as stored in the object"""
+
+ try:
+
+ return writeMetadata(self.metalink,self.metaDataHash,project,startpage,xslt,thumbtemplate,topbar,digiLibTemplate,xmlfrag="yes")
+ except:
+ return " no metadata stored"
+
+ def getXQueryMetaData(self,xquery):
+ '''
+ execute an xquery on the metadata and returns a list of tuples,
+ each tuple represent the content of the node as text and the whole node as xml-fragment
+ @param xquery: xquery auf den metadaten
+ '''
+
+ try:
+ md=writeMetadata(self.metalink,self.metaDataHash,xmlfrag="yes")
+ except:
+ return None
+
+ dom = NonvalidatingReader.parseString(md,"http://www.mpiwg-berlin.mpg.de/")
+
+ results=Ft.Xml.XPath.Evaluate(xquery, contextNode=dom)
+
+ ret=[]
+ for result in results:
+
+ buf = cStringIO.StringIO()
+ PrettyPrint(result, stream=buf)
+ str = buf.getvalue()[0:]
+ buf.close()
+ ret.append((getTextFromNode(result),str))
+
+ return ret
- try:
- coordsnew=[ string.split(x,",") for x in coords]
- except:
- coordsnew=[]
+ def getMetaDataXML(self,project=None,startpage=None,xslt=None,thumbtemplate=None,topbar=None,digiLibTemplate=None):
+ """prints out metadata as stored in the echo environment, format is the index.meta format"""
+ self.REQUEST.RESPONSE.setHeader('Content-Type','text/xml')
+ return writeMetadata(self.metalink,self.metaDataHash)
+
+ def changeECHO_resource(self,metalink,link,title,label,description,contentType,responsible,weight,coords=None,credits=None,RESPONSE=None):
+ """Aenderung der Properties"""
- setECHO_collectionInformation(self,title,label,description,contentType,responsible,credits,weight,coordsnew)
- self.viewClassification=viewClassification
- self.coords=coordsnew[0:]
+ setECHO_collectionInformation(self,title,label,description,contentType,responsible,credits,weight)
self.link=link
self.metalink=metalink
@@ -726,47 +1117,23 @@ class ECHO_resource(Folder,Persistent):
manage_options = Folder.manage_options+(
{'label':'Main Config','action':'ECHO_resource_config_main'},
- {'label':'Change Metadata','action':'ECHO_resource_config_metadata'},
- {'label':'Change Coords','action':'ECHO_resource_config_coords'},
- {'label':'Add coords','action':'ECHO_graphicEntry'},
+ {'label':'Change Metadata','action':'ECHO_resource_config_metadata'},
+ {'label':'Graphic Coords','action':'ECHO_graphicEntry'},
{'label':'Sync Metadata','action':'ECHO_getResourceMD'},
- )
-
- def getOverview(self):
- """overview graphics"""
-
- return self.aq_parent.ZopeFind(self.aq_parent,obj_ids=['overview'])[0][1]
-
- def ECHO_graphicEntry(self):
- """DO nothing"""
- overview = self.aq_parent.ZopeFind(self.aq_parent,obj_ids=['overview'])
- if overview:
- pt=PageTemplateFile('Products/ECHO_content/zpt/ECHO_draw.zpt').__of__(self)
- return pt()
- else:
- return "NO OVERVIEW GRAPHICS"
-
- def ECHO_enterCoords(self,coordstr,angle="",RESPONSE=None):
- """Enter coords"""
- coords=self.coords
- temco=coordstr.split(",")
- temco.append(angle)
- coords.append(temco)
-
- self.coords=coords[0:]
-
- if RESPONSE is not None:
- RESPONSE.redirect('ECHO_graphicEntry')
+ {'label':'Change TemplateSets and Image Viewer','action':'changeViewerTemplateSetForm'},
+ {'label':'set/change startpage','action':'setStartPageForm'},
+ {'label':'Copy MD for indexing and search','action':'copySearchFields'},
+ )
def isDefinedInThisSet(self,fields,field):
- """checks if field is defined in fields"""
- if (fields[0].has_key(field)) and not (fields[0][field]==""):
- return 1
- else:
-
- return 0
-
+ """checks if field is defined in fields"""
+ if (fields[0].has_key(field)) and not (fields[0][field]==""):
+ return 1
+ else:
+
+ return 0
+
def getFieldLabel(self,fields,field):
"""get labels"""
try:
@@ -795,58 +1162,67 @@ class ECHO_resource(Folder,Persistent):
def getFieldValue(self,field):
"""get value"""
-
+
try:
-
+
ret=self.metaDataHash[field]
if ret == "":
return None
else:
- return ret
+
+ return ret
except:
return None
def getMetaDataHash(self):
- """md hash"""
- return self.metaDataHash
+ """md hash"""
+ return self.metaDataHash
def setFieldValue(self,field,value):
"""get value"""
-
- if not hasattr(self,'metaDataHash'):
- setattr(self,'metaDataHash',{})
- self.metaDataHash[field]=value[0:]
-
+
+ if not hasattr(self,'metaDataHash'):
+ setattr(self,'metaDataHash',{})
+ self.metaDataHash[field]=value[0:]
+
+ def copySearchFields(self):
+ """copys metadatafields to the object"""
+ fields=['author','title','year']
+ for field in fields:
+ setattr(self,'MD_'+field,self.getFieldValue(field))
+
def findLabelsFromMapping(self,referenceType):
"""gib hash mit label -> generic zurueck"""
- #return {},[]
+ #return {},[]
temp=self.ZopeFind(self.standardMD)
- if referenceType=="":
- referenceType="book"
-
-
+ if referenceType=="":
+ referenceType="book"
+
+
bibdata={}
retdata={}
- fields=[]
+ fields=[]
fieldlist=self.standardMD.fieldList
-
- for referenceTypeF in self.referencetypes:
-
- if referenceTypeF[1].title.lower() == referenceType.lower():
- try:
- bibdata[referenceTypeF[1].title]=referenceTypeF[1].fields
- referenceType=referenceTypeF[1].title
- except:
- bibdata[referenceType]=referenceTypeF[1].fields
-
+ tags=self.findTagsFromMapping(self.contentType)
+ self.referencetypes=tags[2]
+ for referenceTypeF in self.referencetypes:
+
+ if referenceTypeF[1].title.lower() == referenceType.lower():
+
+ try:
+ bibdata[referenceTypeF[1].title]=referenceTypeF[1].fields
+ referenceType=referenceTypeF[1].title
+ except:
+ bibdata[referenceType]=referenceTypeF[1].fields
+
- bibdata['data']=referenceTypeF[1]
- fields=bibdata[referenceType]
+ bibdata['data']=referenceTypeF[1]
+ fields=bibdata[referenceType]
for field in fieldlist:
retdata[field]=referenceTypeF[1].getValue(field)[1]
@@ -854,157 +1230,190 @@ class ECHO_resource(Folder,Persistent):
def findTagsFromMapping(self,referenceType):
"""gib hash mit label -> generic zurueck"""
-
+
+
+ if referenceType=="":
+ referenceType="book"
+
+ temp = self.ZopeFind(self.standardMD)[0:]
- if referenceType=="":
- referenceType="book"
-
- temp = self.ZopeFind(self.standardMD)[0:]
-
-
- #self.referencetypes=temp[0:]
-
-
-
+
+ #self.referencetypes=temp[0:]
+
+
+
-
+
bibdata={}
retdata={}
fieldlist=self.standardMD.fieldList
-
- for referenceTypeF in temp:
-
- if referenceTypeF[1].title.lower() == referenceType.lower():
- try:
- bibdata[referenceTypeF[1].title]=referenceTypeF[1].fields
- referenceType=referenceTypeF[1].title
- except:
- bibdata[referenceType]=referenceTypeF[1].fields
- bibdata['data']=referenceTypeF[1]
- fields=bibdata[referenceType]
+ fields=[]
+ for referenceTypeF in temp:
+ #print referenceType
+
+ if referenceTypeF[1].title.lower() == referenceType.lower():
+ try:
+ bibdata[referenceTypeF[1].title]=referenceTypeF[1].fields
+ referenceType=referenceTypeF[1].title
+ except:
+ bibdata[referenceType]=referenceTypeF[1].fields
+ bibdata['data']=referenceTypeF[1]
+ fields=bibdata[referenceType]
for field in fieldlist:
retdata[field]=referenceTypeF[1].getValue(field)[0]
-
+
return retdata,fieldlist,temp,fields
-
+ security.declarePublic('copyIndex_meta2echo_resource') # has to be change, presentlyset because of OSAS koordination
def copyIndex_meta2echo_resource(self,RESPONSE=None):
- """copy MD von Index_meta to the echo_resource"""
-
- (metadict, error)=readMetadata(self.metalink)
-
- self.metaDataHash={}
- if not error=="": #Fehler beim Auslesen des Metafiles
- return "ERROR:",error
- fields=self.findTagsFromMapping(self.contentType)
-
- #fields=self.findLabelsFromMapping(self.contentType)
- for field in fields[1]:
-
- if self.isDefinedInThisSet(fields,field):
- #print urllib.unquote(metadict.get(self.getFieldTag(fields,field),''))
- self.setFieldValue(self.getFieldTag(fields,field),metadict.get(self.getFieldTag(fields,field),''))
-
-
-
- if RESPONSE:
- return RESPONSE.redirect('manage_main')
-
- def ECHO_getResourceMD(self,template="yes"):
+ """copy MD von Index_meta to the echo_resource"""
+
+ (metadict, error)=readMetadata(self.metalink)
+
+
+
+ self.metaDataHash={}
+ if not error=="": #Fehler beim Auslesen des Metafiles
+
+ return "ERROR:",error,self.absolute_url()
+
+ self.contentType=metadict['bib_type'][0:]
+ fields=self.findTagsFromMapping(self.contentType)
+
+ #fields=self.findLabelsFromMapping(self.contentType)
+ for field in fields[1]:
+
+ if self.isDefinedInThisSet(fields,field):
+ #print urllib.unquote(metadict.get(self.getFieldTag(fields,field),''))
+ self.setFieldValue(self.getFieldTag(fields,field),metadict.get(self.getFieldTag(fields,field),''))
+
+
+
+ if RESPONSE:
+ return RESPONSE.redirect('manage_main')
+
+ def ECHO_getResourceMD(self,template="yes",back=None):
"""Einlesen der Metadaten und Anlegen dieser Metadaten als Informationen zur Resource"""
(metadict, error)=readMetadata(self.metalink)
-
+ if back:
+ self.REQUEST.SESSION['back']=back
if not error=="": #Fehler beim Auslesen des Metafiles
- return "ERROR:",error
-
-
- if not (metadict['bib_type'].lower()==self.contentType.lower()):
- self.REQUEST.SESSION['contentStorage']=metadict['bib_type']
- self.REQUEST.SESSION['contentZope']=self.contentType
+ return "ERROR:",error
+
+ if not self.contentType:
+ self.contentType=metadict['bib_type'].lower()
+
+ if not (metadict['bib_type'].lower()==self.contentType.lower()):
+ self.REQUEST.SESSION['contentStorage']=metadict['bib_type']
+ self.REQUEST.SESSION['contentZope']=self.contentType
- return PageTemplateFile('Products/ECHO_content/zpt/ECHO_getResourceMDErrorContentType.zpt').__of__(self)()
+ return zptFile(self, 'zpt/ECHO_getResourceMDErrorContentType.zpt')()
- self.REQUEST.SESSION['metadict']=metadict
+ self.REQUEST.SESSION['metadict']=metadict
-
-
- self.REQUEST.SESSION['diffs']=checkDiffs(self,self.REQUEST.SESSION['metadict'])
-
+
+
+ self.REQUEST.SESSION['diffs']=checkDiffs(self,self.REQUEST.SESSION['metadict'])
+
-
+
if template=="yes":
- pt=PageTemplateFile('Products/ECHO_content/zpt/ECHO_resourceMD.zpt').__of__(self)
- return pt()
+ pt=zptFile(self, 'zpt/ECHO_resourceMD.zpt')
+ return pt()
-
+
def ECHO_getMD(self,item):
"""Ausgabe der MD"""
return getattr(self,item)
-
+
+ def checkRDF(self,path):
+ """check if pdf in the path"""
+ try:
+ for fileName in os.listdir(path):
+ if os.path.splitext(fileName)[1]==".pdf":
+ return os.path.join(path,fileName)
+ return None
+ except:
+ return None
+
+
+ security.declareProtected('View','index_html')
def index_html(self):
"""standard page"""
-
+ pdf=self.checkRDF(self.link)
+ if pdf:
+ fh=file(pdf,'r').read()
+ self.REQUEST.RESPONSE.setHeader('Content-Type','application/pdf')
+ self.REQUEST.RESPONSE.write(fh)
+ self.REQUEST.RESPONSE.close()
+ return
return self.REQUEST.RESPONSE.redirect(self.link)
def startpage_html(self):
- """prints out a startpage for a resource for use e.g. in the BVE"""
+ """prints out a startpage for a resource for use e.g. in the BVE"""
- # suche ob startpage.html in dem Ordner vorhanden ist, dann wir diese angezeigt
+ # suche ob startpage.html in dem Ordner vorhanden ist, dann wir diese angezeigt
- sp=self.ZopeFind(self,obj_ids=['startpage.html'])
+ sp=self.ZopeFind(self,obj_ids=['startpage.html'])
- if sp:
- return sp[1]()
+ if sp:
+ return sp[1]()
- #prüfen ob irgendwo ein template
- if hasattr(self,'startpage_index_template'):
- return self.startpage_index_template()
+ #pruefen ob irgendwo ein template
+ if hasattr(self,'startpage_index_template'):
+ return self.startpage_index_template()
- #generisches template ausgeben
-
- pt=PageTemplateFile('Products/ECHO_content/zpt/ECHO_startpage_index_template_standard.zpt').__of__(self)
- pt.content_type="text/html"
- return pt()
+ #generisches template ausgeben
+
+ pt=zptFile(self, 'zpt/ECHO_startpage_index_template_standard.zpt')
+ pt.content_type="text/html"
+ return pt()
def toc_html(self):
-
- sp=self.ZopeFind(self,obj_ids=['toc.html'])
-
- if sp:
- return sp[0][1]()
+
+ sp=self.ZopeFind(self,obj_ids=['toc.html'])
+
+ if sp:
+ return sp[0][1]()
-
+ security.declarePublic('generate_label') # has to be change, presentlyset because of OSAS koordination
+
def generate_label(self):
"""Erzeugt_standard_Label aus Template"""
- pt=getattr(self,"label_template_"+self.bib_type)
+ pt=getattr(self,"label_template_"+self.contentType.lower())
+ self.label=pt()[0:]
return pt()
+ security.declarePublic('generate_title') # has to be change, presentlyset because of OSAS koordination
+
def generate_title(self,RESPONSE=None):
"""Erzeugt_standard_Label aus Template"""
- pt=getattr(self,"label_template_"+self.contentType)
+ pt=getattr(self,"label_template_"+self.contentType.lower())
- self.title=pt()
-
+ self.title=pt()[0:]
+
return pt()
+Globals.InitializeClass(ECHO_resource)
+
def manage_addECHO_resourceForm(self):
"""Form for adding a ressource"""
- pt=PageTemplateFile('Products/ECHO_content/zpt/AddECHO_resourceForm.zpt').__of__(self)
+ pt=zptFile(self, 'zpt/AddECHO_resourceForm.zpt')
return pt()
-def manage_addECHO_resource(self,id,title,label,description,responsible,link,metalink,weight,copyrightType=None,resourceID=None,contentType=None,renderingType=None,credits=None,coords=None,RESPONSE=None):
- """addaresource"""
+def manage_addECHO_resource(self,id,title,label,description="",responsible="",link="",metalink="",weight="",copyrightType=None,resourceID=None,contentType=None,renderingType=None,credits=None,coords=None,RESPONSE=None):
+ """addresource"""
newObj=ECHO_resource(id,link,metalink,resourceID,title,label,description,contentType,renderingType,copyrightType,responsible,credits,weight,coords)
@@ -1014,22 +1423,15 @@ def manage_addECHO_resource(self,id,titl
RESPONSE.redirect('manage_main')
-class ECHO_externalLink(Folder):
+class ECHO_externalLink(Folder,ECHO_basis):
"""Link zu einer externen Ressource"""
security=ClassSecurityInfo()
meta_type='ECHO_externalLink'
- def getTitle(self):
- """title"""
- return self.title.encode('utf-8')
-
- def getLabel(self):
- """title"""
- return self.label.encode('utf-8')
-
+ security.declarePublic('content_html')
def content_html(self):
"""template fuer content"""
- return content_html(self,'externalLink')
+ return ECHO_basis.content_html(self,'externalLink')
def __init__(self,id,link,title,label,description,contentType,responsible,credits,weight,coords):
@@ -1057,21 +1459,14 @@ class ECHO_externalLink(Folder):
self.coords=['']
- pt=PageTemplateFile('Products/ECHO_content/zpt/ChangeECHO_externalLink.zpt').__of__(self)
+ pt=zptFile(self, 'zpt/ChangeECHO_externalLink.zpt')
return pt()
def changeECHO_externalLink(self,link,title,label,description,contentType,responsible,weight,coords=None,credits=None,RESPONSE=None):
+ """Aenderung der Properties"""
+ setECHO_collectionInformation(self,title,label,description,contentType,responsible,credits,weight)
- """Änderung der Properties"""
- try:
- coordsnew=[ string.split(x,",") for x in coords]
- except:
- coordsnew=[]
-
- setECHO_collectionInformation(self,title,label,description,contentType,responsible,credits,weight,coords)
-
- self.coords=coordsnew[0:]
self.link=link
if RESPONSE is not None:
RESPONSE.redirect('manage_main')
@@ -1079,6 +1474,7 @@ class ECHO_externalLink(Folder):
manage_options = Folder.manage_options+(
{'label':'Main Config','action':'ECHO_externalLink_config'},
+ {'label':'Graphic Coords','action':'ECHO_graphicEntry'},
)
@@ -1089,7 +1485,7 @@ class ECHO_externalLink(Folder):
def manage_addECHO_externalLinkForm(self):
"""Form for external Links"""
- pt=PageTemplateFile('Products/ECHO_content/zpt/AddECHO_externalLinkForm.zpt').__of__(self)
+ pt=zptFile(self, 'zpt/AddECHO_externalLinkForm.zpt')
return pt()
@@ -1105,25 +1501,48 @@ def manage_addECHO_externalLink(self,id,
class ECHO_link(ECHO_externalLink):
- """external_link"""
+ """external_link"""
- meta_type="ECHO_link"
-
+ meta_type="ECHO_link"
+
+
+ def content_html(self):
+ """template fuer link"""
+ if hasattr(self,"link_template"):
+ return ECHO_basis.content_html(self,'link')
+ else:
+ return ECHO_basis.content_html(self,'collection')
+
+ def index_html(self):
+ """standard link"""
+ if self.link:
+ splitted=self.link.split("?")
+ if len(splitted)>1:
+ params=cgi.parse_qs(splitted[1])
+
+ for x in params.keys():
+ if type(params[x]) is ListType:
+ params[x]=params[x][0]
+
+
+ else:
+ params={}
+
+ params['backLink']=self.aq_parent.absolute_url()
+ params['startLink']=splitted[0]+"?"+urllib.urlencode(params)
+
+
+ return self.REQUEST.RESPONSE.redirect(splitted[0]+"?"+urllib.urlencode(params))
+ else:
+ return ""
- def content_html(self):
- """template fuer link"""
- if hasattr(self,"link_template"):
- return content_html(self,'link')
- else:
- return content_html(self,'collection')
-
def manage_addECHO_linkForm(self):
"""Form for external Links"""
- pt=PageTemplateFile('Products/ECHO_content/zpt/AddECHO_linkForm.zpt').__of__(self)
+ pt=zptFile(self, 'zpt/AddECHO_linkForm.zpt')
return pt()
-def manage_addECHO_link(self,id,title,label,description,contentType,responsible,link,weight,coords=None,credits=None,RESPONSE=None):
+def manage_addECHO_link(self,id,title,label,description="",contentType="",responsible="",link="",weight="",coords=[],credits=None,RESPONSE=None):
"""Add an external Link"""
newObj=ECHO_link(id,link,title,label,description,contentType,responsible,credits,weight,coords)
@@ -1132,79 +1551,429 @@ def manage_addECHO_link(self,id,title,la
if RESPONSE is not None:
RESPONSE.redirect('manage_main')
-
+
-class ECHO_collection(Folder, Persistent, Implicit):
+class ECHO_collection(Folder, Persistent, Implicit, Cacheable,ECHO_basis):
"""ECHO Collection"""
security=ClassSecurityInfo()
meta_type='ECHO_collection'
- viewClassificationList=viewClassificationListMaster
+# viewClassificationList=viewClassificationListMaster
displayTypes=displayTypes
- def getPartnerCopyright(self,name,sonst="generic"):
- """gibt generisches copyright eines partners aus, sonst behalte jetzige einsteillung"""
- #print "hi",name,sonst
- #print getattr(self.partners,name).copyrightType
- try:
- partner=getattr(self.partners,name)
- return partner.copyrightType
- except:
- print "error"
- return sonst
+ path="/mpiwg/online/permanent/shipbuilding"
- def partnerSelector_HTML(self,selected=None):
- """give type selector"""
- if not selected:
- retStr="