version 1.230, 2005/07/20 14:46:05
|
version 1.242, 2005/10/26 17:09:20
|
Line 37 from Products.PageTemplates.PageTemplate
|
Line 37 from Products.PageTemplates.PageTemplate
|
from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate |
from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate |
from Globals import Persistent, package_home |
from Globals import Persistent, package_home |
from Acquisition import Implicit |
from Acquisition import Implicit |
|
from Products.ZCatalog.CatalogPathAwareness import CatalogAware |
|
|
import urllib |
import urllib |
import cgi |
import cgi |
import smtplib |
import smtplib |
import time |
import time |
from Ft.Xml.Domlette import NonvalidatingReader |
from Ft.Xml.Domlette import NonvalidatingReader |
from Ft.Xml.Domlette import PrettyPrint |
from Ft.Xml.Domlette import PrettyPrint, Print |
from Ft.Xml import EMPTY_NAMESPACE |
from Ft.Xml import EMPTY_NAMESPACE |
|
|
import Ft.Xml.XPath |
import Ft.Xml.XPath |
Line 66 import ECHO_helpers
|
Line 67 import ECHO_helpers
|
from ECHO_helpers import * |
from ECHO_helpers import * |
from ECHO_language import * |
from ECHO_language import * |
from ECHO_movie import * |
from ECHO_movie import * |
|
import vlp_xmlhelpers #TODO: vlp elemente aus echo herausnehmen |
#regexp for extracting elements from xml |
|
patternTXT=r"<\s*txt.*?>(.*?)</txt>" |
|
regexpTXT = re.compile(patternTXT, re.IGNORECASE + re.DOTALL) |
|
patternPage=r"<\s*page.*?>(.*?)</page>" |
|
regexpPage = re.compile(patternPage, re.IGNORECASE + re.DOTALL) |
|
|
|
|
|
|
|
Line 302 def manage_addECHO_fullText(self, id, ti
|
Line 298 def manage_addECHO_fullText(self, id, ti
|
return '' |
return '' |
|
|
|
|
class ECHO_resource(Folder,Persistent,ECHO_basis): |
class ECHO_resource(CatalogAware,Folder,Persistent,ECHO_basis): |
"""ECHO Ressource""" |
"""ECHO Ressource""" |
security=ClassSecurityInfo() |
security=ClassSecurityInfo() |
meta_type='ECHO_resource' |
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 |
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') |
security.declareProtected('View','createPDF') |
def createPDF(self,RESPONSE=None,local=None,dpi=150): |
def createPDF(self,RESPONSE=None,local=None,dpi=150): |
Line 1033 class ECHO_resource(Folder,Persistent,EC
|
Line 1059 class ECHO_resource(Folder,Persistent,EC
|
return writeMetadata(self.metalink,self.metaDataHash,project,startpage,xslt,thumbtemplate,topbar,digiLibTemplate,digiliburlprefix=digiliburlprefix) |
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): |
def showMetaDataXML(self,project=None,startpage=None,xslt=None,thumbtemplate=None,topbar=None,digiLibTemplate=None): |
"""schreibe md""" |
"""return bibliographical metadata as stored in the object""" |
|
|
try: |
try: |
|
|
Line 1041 class ECHO_resource(Folder,Persistent,EC
|
Line 1067 class ECHO_resource(Folder,Persistent,EC
|
except: |
except: |
return "<error> no metadata stored</error>" |
return "<error> no metadata stored</error>" |
|
|
|
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 |
|
|
def getMetaDataXML(self,project=None,startpage=None,xslt=None,thumbtemplate=None,topbar=None,digiLibTemplate=None): |
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""" |
"""prints out metadata as stored in the echo environment, format is the index.meta format""" |
self.REQUEST.RESPONSE.setHeader('Content-Type','text/xml') |
self.REQUEST.RESPONSE.setHeader('Content-Type','text/xml') |
Line 1446 class ECHO_link(ECHO_externalLink):
|
Line 1499 class ECHO_link(ECHO_externalLink):
|
"""external_link""" |
"""external_link""" |
|
|
meta_type="ECHO_link" |
meta_type="ECHO_link" |
|
manage_options = ECHO_externalLink.manage_options+( |
|
{'label':'add links config','action':'ECHO_link_addLinksForm'}, |
|
) |
|
|
|
def ECHO_link_addLinksForm(self): |
|
"""Main configuration""" |
|
|
|
pt=zptFile(self, 'zpt/ChangeECHO_link_addLinks.zpt') |
|
return pt() |
|
|
|
def ECHO_link_addLinks(self,addLinks,RESPONSE): |
|
"""add links""" |
|
self.addLinks=addLinks |
|
if RESPONSE is not None: |
|
RESPONSE.redirect('manage_main') |
|
|
def content_html(self): |
def content_html(self): |
"""template fuer link""" |
"""template fuer link""" |
|
|
if hasattr(self,"link_template"): |
if hasattr(self,"link_template"): |
return ECHO_basis.content_html(self,'link') |
ret=ECHO_basis.content_html(self,'link') |
else: |
else: |
return ECHO_basis.content_html(self,'collection') |
ret=ECHO_basis.content_html(self,'collection') |
|
|
|
try: |
|
return ret.decode('utf-8') |
|
except: |
|
return ret |
|
|
def index_html(self): |
def index_html(self): |
"""standard link""" |
"""standard link""" |
Line 1470 class ECHO_link(ECHO_externalLink):
|
Line 1543 class ECHO_link(ECHO_externalLink):
|
else: |
else: |
params={} |
params={} |
|
|
|
if getattr(self,'addLinks','yes')=="yes": |
params['backLink']=self.aq_parent.absolute_url() |
params['backLink']=self.aq_parent.absolute_url() |
params['startLink']=splitted[0]+"?"+urllib.urlencode(params) |
params['startLink']=splitted[0]+"?"+urllib.urlencode(params) |
|
|
Line 1491 def manage_addECHO_link(self,id,title,la
|
Line 1565 def manage_addECHO_link(self,id,title,la
|
|
|
self._setObject(id,newObj) |
self._setObject(id,newObj) |
|
|
|
getattr(self,id).addLinks='no' |
|
|
if RESPONSE is not None: |
if RESPONSE is not None: |
RESPONSE.redirect('manage_main') |
RESPONSE.redirect('manage_main') |
|
|
Line 1505 class ECHO_collection(Folder, Persistent
|
Line 1581 class ECHO_collection(Folder, Persistent
|
|
|
path="/mpiwg/online/permanent/shipbuilding" |
path="/mpiwg/online/permanent/shipbuilding" |
|
|
|
def getTitleAndLabel(self): |
|
"""gibt title und label zurueck""" |
|
return (getattr(self,'title',''),getattr(self,'label','')) |
|
|
def localizeObjects(self): |
def localizeObjects(self): |
"""localize all objects""" |
"""localize all objects""" |
contents=self.ZopeFind(self,obj_metatypes=['ECHO_link','ECHO_mapText']) |
contents=self.ZopeFind(self,obj_metatypes=['ECHO_externalLink','ECHO_link','ECHO_mapText']) |
|
|
find=self.ZopeFind(self,obj_ids=('locale_en')) |
find=self.ZopeFind(self,obj_ids=('locale_en')) |
if not find: |
if not find: |
self.manage_addECHO_locale("en",'','') |
self.manage_addECHO_locale("en",'','') |
for content in contents: |
for content in contents: |
if content[1].meta_type=='ECHO_link': |
|
|
if content[1].meta_type in ['ECHO_link','ECHO_externalLink']: |
|
|
find=content[1].ZopeFind(content[1],obj_metatypes=('ECHO_mapText')) |
find=content[1].ZopeFind(content[1],obj_metatypes=('ECHO_mapText')) |
if find: |
if find: |
root=find[0][1] |
root=find[0][1] |
Line 2089 class ECHO_collection(Folder, Persistent
|
Line 2172 class ECHO_collection(Folder, Persistent
|
|
|
|
|
security.declarePublic('changeECHO_collection') |
security.declarePublic('changeECHO_collection') |
def changeECHO_collection(self,title,label,description,contentType,responsible,weight,secondaryLink,secondaryLinkTitle,credits=None,sortfield="weight",coords=None,RESPONSE=None,imageTag="",bgcolour="",location=None,isAlwaysClickable=None): |
def changeECHO_collection(self,title,label,description,contentType,responsible,weight,secondaryLink,secondaryLinkTitle,credits=None,sortfield="weight",coords=None,RESPONSE=None,imageTag="",bgcolour="",location=None,isAlwaysClickable=None,prefix="",suffix=""): |
"""Aenderung der Properties""" |
"""Aenderung der Properties""" |
|
|
self.secondaryLink=secondaryLink |
self.secondaryLink=secondaryLink |
Line 2098 class ECHO_collection(Folder, Persistent
|
Line 2181 class ECHO_collection(Folder, Persistent
|
self.bgcolour=bgcolour |
self.bgcolour=bgcolour |
self.location=location |
self.location=location |
self.isAlwaysClickable=isAlwaysClickable |
self.isAlwaysClickable=isAlwaysClickable |
|
self.prefix=prefix[0:] |
|
self.suffix=suffix[0:] |
|
|
setECHO_collectionInformation(self,title,label,description,contentType,responsible,credits,weight) |
setECHO_collectionInformation(self,title,label,description,contentType,responsible,credits,weight) |
|
|
Line 2155 class ECHO_collection(Folder, Persistent
|
Line 2240 class ECHO_collection(Folder, Persistent
|
def content_html(self,**argv): |
def content_html(self,**argv): |
"""template fuer content""" |
"""template fuer content""" |
#print "NN",argv |
#print "NN",argv |
return ECHO_basis.content_html(self,'collection') |
ret = ECHO_basis.content_html(self,'collection') |
|
try: |
|
return ret.decode('utf-8') |
|
except: |
|
return ret |
|
|
def getCredits(self): |
def getCredits(self): |
"""Ausgabe der credits""" |
"""Ausgabe der credits""" |
Line 2513 class ECHO_root(Folder,Persistent,Implic
|
Line 2602 class ECHO_root(Folder,Persistent,Implic
|
|
|
meta_type="ECHO_root" |
meta_type="ECHO_root" |
|
|
|
|
|
def findObjectFromFulltext(self,existUri): |
|
''' |
|
|
|
@param url: |
|
@param existUri: |
|
''' |
|
|
|
if existUri: |
|
#TODO: at the moment assume that the filename is unique, the whole has to changed to a system of ids. |
|
filename=existUri.split("/")[-1] |
|
|
|
founds=self.resourceCatalog.search({'fullTextUrl':os.path.splitext(filename)[0]}) |
|
|
|
ret=[(found.title,found.getObject().absolute_url(),found.getObject().aq_parent.absolute_url()) for found in founds] |
|
|
|
return ret |
|
|
|
def reindex(self,RESPONSE=None): |
|
"""indiziere alle Objecte neu""" |
|
|
|
if RESPONSE: |
|
RESPONSE.write("<html><body>") |
|
|
|
resources=self.ZopeFind(self,obj_metatypes=["ECHO_resource"], search_sub=1) |
|
|
|
for resource in resources: |
|
resource[1].reindex() |
|
print "<p> done %s </p>\n" |
|
if RESPONSE: |
|
RESPONSE.write("<p> done %s </p>\n"%resource[0]) |
|
|
|
if RESPONSE: |
|
RESPONSE.write("<p> ok </p></html></body>\n") |
|
|
def printer(self,txt): |
def printer(self,txt): |
print txt |
print txt |
print txt[2] |
print txt[2] |
Line 2529 class ECHO_root(Folder,Persistent,Implic
|
Line 2653 class ECHO_root(Folder,Persistent,Implic
|
|
|
def setLanguage(self,lang): |
def setLanguage(self,lang): |
"""Set language cookie""" |
"""Set language cookie""" |
self.REQUEST.RESPONSE.setCookie('lang_exhibition',lang,path="") |
self.REQUEST.RESPONSE.setCookie('lang_exhibition',lang,path="/") |
|
|
def switchLanguage(self): |
def switchLanguage(self): |
"""Set language cookie""" |
"""Set language cookie""" |
Line 2538 class ECHO_root(Folder,Persistent,Implic
|
Line 2662 class ECHO_root(Folder,Persistent,Implic
|
else: |
else: |
lang="en" |
lang="en" |
|
|
self.REQUEST.RESPONSE.setCookie('lang_exhibition',lang,path="") |
self.REQUEST.RESPONSE.setCookie('lang_exhibition',lang,path="/") |
self.REQUEST.RESPONSE.redirect(self.REQUEST['URL1']) |
self.REQUEST.RESPONSE.redirect(self.REQUEST['URL1']) |
def getLanguage(self): |
def getLanguage(self): |
"""get language cookie""" |
"""get language cookie""" |
Line 3052 class ECHO_root(Folder,Persistent,Implic
|
Line 3176 class ECHO_root(Folder,Persistent,Implic
|
else: |
else: |
return "" |
return "" |
|
|
def link2html(self,str): |
link2html=vlp_xmlhelpers.link2html |
"""link2html fuer VLP muss hier noch raus""" |
|
if str: |
|
|
|
str=re.sub("\&","&",str) |
|
dom=xml.dom.minidom.parseString("<?xml version='1.0' encoding='utf-8'?><txt>"+str+"</txt>") |
|
links=dom.getElementsByTagName("link") |
|
|
|
|
|
for link in links: |
|
link.tagName="a" |
|
ref=link.getAttribute("ref") |
|
pn=link.getAttribute("page") |
|
|
|
if self.checkRef(ref): |
|
if pn: |
|
link.setAttribute("href",self.aq_parent.absolute_url()+"/references?id="+ref+"&page="+pn) |
|
else: |
|
link.setAttribute("href",self.aq_parent.absolute_url()+"/references?id="+ref) |
|
|
|
|
|
newxml=dom.toxml('utf-8') |
|
|
|
retStr=regexpTXT.search(newxml) |
|
|
|
return retStr.group(1) |
|
|
|
|
|
return "" |
xml2html=vlp_xmlhelpers.xml2html |
|
|
def xml2html(self,str,quote="yes"): |
|
"""link2html fuer VLP muss hier noch raus""" |
|
|
|
if str: |
|
if quote=="yes2": |
|
str=re.sub("\&","&",str) |
|
#dom=xml.dom.minidom.parseString(str) |
|
dom = NonvalidatingReader.parseString(str,"http://www.mpiwg-berlin.mpg.de/") |
|
#links=dom.getElementsByTagName("link") |
|
links=Ft.Xml.XPath.Evaluate(".//link", contextNode=dom) |
|
for link in links: |
|
#link.tagName="a" |
|
|
|
ref=link.getAttributeNS(EMPTY_NAMESPACE,"ref") |
|
pn=link.getAttributeNS(EMPTY_NAMESPACE,"page") |
|
|
|
cns=link.childNodes[0:] |
|
|
|
newLink=dom.createElementNS(EMPTY_NAMESPACE,"a") |
|
for x in cns: |
|
newLink.appendChild(x) |
|
|
|
|
|
|
|
link.parentNode.replaceChild(newLink,link) |
|
if self.checkRef(ref): |
|
if pn: |
|
newLink.setAttributeNS(EMPTY_NAMESPACE,"href",self.aq_parent.absolute_url()+"/vlp_coll?id="+ref+"&p="+pn) |
|
else: |
|
newLink.setAttributeNS(EMPTY_NAMESPACE,"href",self.aq_parent.absolute_url()+"/vlp_coll?id="+ref) |
|
|
|
#str= dom.toxml('utf-8') |
|
buf = cStringIO.StringIO() |
|
PrettyPrint(dom, stream=buf, encoding='UTF-8') |
|
str = buf.getvalue() |
|
buf.close() |
|
#str=PrettyPrint(dom.documentElement,encoding='UTF-8') |
|
#print link.toxml('utf-8') |
|
#print type(str) |
|
retStr=regexpPage.search(str) |
|
try: # hack warum fehtl manchmal page?? |
|
return retStr.group(1) |
|
except: |
|
return str |
|
return "" |
|
|
|
def checkRef(self,ref): |
|
if ref[0:3]=='lit': |
|
if len(self.library_data({ 'id':ref}))>0: |
|
return 1 |
|
try: |
|
if ref[0:7]=="tec_cat": |
|
return 1 |
|
except: |
|
"""nothing""" |
|
|
|
dbs={'vl_technology':'','vl_people':'','vl_sites':''} |
checkRef=vlp_xmlhelpers.checkRef |
res=None |
|
for db in dbs.keys(): |
|
res=res or self.search(var=str("select reference from %s where reference =\'%s\' %s"%(db,ref,dbs[db]))) |
|
return res |
|
|
|
#Ende Methode fuer vlp |
# def checkRef(self,ref): |
|
# if ref[0:3]=='lit': |
|
# if len(self.library_data({ 'id':ref}))>0: |
|
# return 1 |
|
# try: |
|
# if ref[0:7]=="tec_cat": |
|
# return 1 |
|
# except: |
|
# """nothing""" |
|
# |
|
# dbs={'vl_technology':'','vl_people':" AND complete='yes'",'vl_sites':''} |
|
# res=None |
|
# for db in dbs.keys(): |
|
# res=res or self.search(var=str("select reference from %s where reference =\'%s\' %s"%(db,ref,dbs[db]))) |
|
# return res |
|
# |
|
# #Ende Methode fuer vlp |
|
|
def PgQuoteString(self,string): |
def PgQuoteString(self,string): |
"""Quote string""" |
"""Quote string""" |