--- documentViewer/documentViewer.py 2009/03/06 15:36:38 1.38 +++ documentViewer/documentViewer.py 2010/03/08 15:02:33 1.42 @@ -1,5 +1,4 @@ - from OFS.Folder import Folder from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate from Products.PageTemplates.PageTemplateFile import PageTemplateFile @@ -11,8 +10,9 @@ from Ft.Xml.Domlette import Nonvalidatin from Ft.Xml.Domlette import PrettyPrint, Print from Ft.Xml import EMPTY_NAMESPACE, Parse -import Ft.Xml.XPath +import Ft.Xml.XPath +import xmlrpclib import os.path import sys import cgi @@ -213,6 +213,7 @@ class documentViewer(Folder): ps = "&".join(["%s=%s"%(k,urllib.quote(v)) for (k, v) in params.items()]) url=self.REQUEST['URL1']+"?"+ps return url + def getInfo_xml(self,url,mode): """returns info about the document as XML""" @@ -232,6 +233,11 @@ class documentViewer(Folder): else: return style + def getTextLanguage(self,url,docinfo): + docinfo['lang']=getTextFromNode(dom.xpath("//bib/lang")[0]) + lang = urlencode({'':docinfo['lang']}) + return lang + def isAccessible(self, docinfo): """returns if access to the resource is granted""" @@ -384,7 +390,8 @@ class documentViewer(Folder): for x in range(cut): path=getParentDir(path) dom = self.getIndexMeta(path) - + + logging.debug("documentViewer (getbibinfofromindexmeta cutted) path: %s"%(path)) # put in all raw bib fields as dict "bib" bib = dom.xpath("//bib/*") if bib and len(bib)>0: @@ -422,7 +429,13 @@ class documentViewer(Folder): docinfo['lang']='' return docinfo - + + + def getNumPages(self, xquery, docinfo=None): #New Method 24.02.2010 + text=self.viewerTemplates.query.eval("/mpdl/interface/xquery.xql","document="+ docinfo['textURLPath'] +"&xquery="+str(xquery)) + docinfo['numPages'] = text.count("0): imageDir=getTextFromNode(imageDirs[0]) + else: # we balk with no image tag / not necessary anymore because textmode is now standard #raise IOError("No text-tool info in %s"%(url)) imageDir="" - docinfo['numPages']=1 # im moment einfach auf eins setzen, navigation ueber die thumbs geht natuerlich nicht - + #xquery="//pb" docinfo['imagePath'] = "" # keine Bilder docinfo['imageURL'] = "" - + if imageDir and archivePath: #print "image: ", imageDir, " archivepath: ", archivePath imageDir=os.path.join(archivePath,imageDir) @@ -499,16 +512,27 @@ class documentViewer(Folder): docinfo['textURL'] = textUrl + textUrls=dom.xpath("//texttool/text-url-path") + if textUrls and (len(textUrls)>0): + textUrl=getTextFromNode(textUrls[0]) + docinfo['textURLPath'] = textUrl + presentationUrls=dom.xpath("//texttool/presentation") docinfo = self.getBibinfoFromIndexMeta(url,docinfo=docinfo,dom=dom) # get info von bib tag if presentationUrls and (len(presentationUrls)>0): # ueberschreibe diese durch presentation informationen # presentation url ergiebt sich ersetzen von index.meta in der url der fuer die Metadaten # durch den relativen Pfad auf die presentation infos - presentationUrl=url.replace('index.meta',getTextFromNode(presentationUrls[0])) + presentationPath = getTextFromNode(presentationUrls[0]) + if url.endswith("index.meta"): + presentationUrl=url.replace('index.meta',presentationPath) + else: + presentationUrl=url + "/" + presentationPath + docinfo=self.getNumPages('//pb', docinfo) #im moment einfach auf eins setzen, navigation ueber die thumbs geht natuerlich nicht docinfo = self.getBibinfoFromTextToolPresentation(presentationUrl,docinfo=docinfo,dom=dom) docinfo = self.getAuthinfoFromIndexMeta(url,docinfo=docinfo,dom=dom) # get access info + return docinfo @@ -539,14 +563,16 @@ class documentViewer(Folder): docinfo['imagePath'] = path docinfo=self.getDirinfoFromDigilib(path,docinfo=docinfo,cut=cut) + pathorig=path for x in range(cut): path=getParentDir(path) logging.error("PATH:"+path) imageUrl=self.digilibBaseUrl+"/servlet/Scaler?fn="+path docinfo['imageURL'] = imageUrl - docinfo = self.getBibinfoFromIndexMeta(path,docinfo=docinfo,cut=cut) - docinfo = self.getAuthinfoFromIndexMeta(path,docinfo=docinfo,cut=cut) + #path ist the path to the images it assumes that the index.meta file is one level higher. + docinfo = self.getBibinfoFromIndexMeta(pathorig,docinfo=docinfo,cut=cut+1) + docinfo = self.getAuthinfoFromIndexMeta(pathorig,docinfo=docinfo,cut=cut+1) return docinfo @@ -593,6 +619,7 @@ class documentViewer(Folder): pageinfo['start'] = start pageinfo['end'] = start + grpsize if docinfo is not None: + np = int(docinfo['numPages']) pageinfo['end'] = min(pageinfo['end'], np) pageinfo['numgroups'] = int(np / grpsize)