--- documentViewer/documentViewer.py 2006/09/11 14:43:09 1.19 +++ documentViewer/documentViewer.py 2007/01/11 12:03:17 1.20 @@ -17,6 +17,7 @@ import os.path import sys import cgi import urllib +import logging import zLOG import urlparse @@ -59,7 +60,7 @@ def urlopen(url,timeout=2): ## class documentViewer(Folder): """document viewer""" - textViewerUrl="http://127.0.0.1:8080/HFQP/testXSLT/getPage?" + #textViewerUrl="http://127.0.0.1:8080/HFQP/testXSLT/getPage?" meta_type="Document viewer" @@ -229,6 +230,35 @@ class documentViewer(Folder): raise IOError("Unable to read index meta from %s"%(url)) return dom + + def getPresentationInfoXML(self, url): + """returns dom of info.xml document at url""" + num_retries = 3 + dom = None + metaUrl = None + if url.startswith("http://"): + # real URL + metaUrl = url + else: + # online path + server=self.digilibBaseUrl+"/servlet/Texter?fn=" + metaUrl=server+url.replace("/mpiwg/online","") + + + for cnt in range(num_retries): + try: + # patch dirk encoding fehler treten dann nicht mehr auf + # dom = NonvalidatingReader.parseUri(metaUrl) + txt=urllib.urlopen(metaUrl).read() + dom = Parse(txt) + break + except: + zLOG.LOG("ERROR documentViewer (getPresentationInfoXML)", zLOG.INFO,"%s (%s)"%sys.exc_info()[0:2]) + + if dom is None: + raise IOError("Unable to read infoXMLfrom %s"%(url)) + + return dom def getAuthinfoFromIndexMeta(self,path,docinfo=None,dom=None): @@ -345,11 +375,29 @@ class documentViewer(Folder): docinfo['textURL'] = textUrl - docinfo = self.getBibinfoFromIndexMeta(url,docinfo=docinfo,dom=dom) + + presentationUrls=dom.xpath("//texttool/presentation") + if presentationUrls and (len(presentationUrls)>0): + # presentation url ergiebt sich ersetzen von index.meta in der url der fŸr die Metadaten + # durch den relativen Pfad auf die presentation infos + presentationUrl=url.replace('index.meta',getTextFromNode(presentationUrls[0])) + + docinfo = self.getBibinfoFromTextToolPresentation(presentationUrl,docinfo=docinfo,dom=dom) + else: + docinfo = self.getBibinfoFromIndexMeta(url,docinfo=docinfo,dom=dom) docinfo = self.getAuthinfoFromIndexMeta(url,docinfo=docinfo,dom=dom) return docinfo - + + def getBibinfoFromTextToolPresentation(self,url,docinfo=None,dom=None): + """gets the bibliographical information from the preseantion entry in texttools + """ + dom=self.getPresentationInfoXML(url) + docinfo['author']=getTextFromNode(dom.xpath("//author")[0]) + docinfo['title']=getTextFromNode(dom.xpath("//title")[0]) + docinfo['year']=getTextFromNode(dom.xpath("//date")[0]) + return docinfo + def getDocinfoFromImagePath(self,path,docinfo=None): """path ist the path to the images it assumes that the index.meta file is one level higher.""" zLOG.LOG("documentViewer (getdocinfofromimagepath)", zLOG.INFO,"path: %s"%(path)) @@ -370,7 +418,8 @@ class documentViewer(Folder): """returns docinfo depending on mode""" zLOG.LOG("documentViewer (getdocinfo)", zLOG.INFO,"mode: %s, url: %s"%(mode,url)) # look for cached docinfo in session - if self.REQUEST.SESSION.has_key('docinfo'): + # XXXX Sesion abgeschaltet + if self.REQUEST.SESSION.has_key('docinfo_XX'): docinfo = self.REQUEST.SESSION['docinfo'] # check if its still current if docinfo is not None and docinfo.get('mode') == mode and docinfo.get('url') == url: @@ -471,8 +520,11 @@ class documentViewer(Folder): def findDigilibUrl(self): """try to get the digilib URL from zogilib""" url = self.imageViewerUrl[:-1] + "/getScalerUrl" - print urlparse.urlparse(url)[0] - print urlparse.urljoin(self.absolute_url(),url) + #print urlparse.urlparse(url)[0] + #print urlparse.urljoin(self.absolute_url(),url) + logging.info("finddigiliburl: %s"%urlparse.urlparse(url)[0]) + logging.info("finddigiliburl: %s"%urlparse.urljoin(self.absolute_url(),url)) + try: if urlparse.urlparse(url)[0]=='': #relative path url=urlparse.urljoin(self.absolute_url()+"/",url)