--- documentViewer/documentViewer.py 2008/06/25 10:47:58 1.32 +++ documentViewer/documentViewer.py 2008/11/04 22:03:56 1.37 @@ -21,7 +21,7 @@ import logging import math import urlparse - +from types import * def logger(txt,method,txt2): """logging""" logging.info(txt+ txt2) @@ -139,7 +139,7 @@ class documentViewer(Folder): return pt(docinfo=docinfo,pageinfo=pageinfo,viewMode=viewMode) security.declareProtected('View','index_html') - def index_html(self,mode,url,viewMode="auto",start=None,pn=1): + def index_html(self,mode,url,viewMode="auto",start=None,pn=1,mk=None): ''' view it @param mode: defines how to access the document behind url @@ -167,9 +167,19 @@ class documentViewer(Folder): else: viewMode="images" - return pt(docinfo=docinfo,pageinfo=pageinfo,viewMode=viewMode) - + return pt(docinfo=docinfo,pageinfo=pageinfo,viewMode=viewMode,mk=self.generateMarks(mk)) + def generateMarks(self,mk): + ret="" + if mk is None: + return "" + + if type(mk) is not ListType: + mk=[mk] + for m in mk: + ret+="mk=%s"%m + return ret + def getLink(self,param=None,val=None): """link to documentviewer with parameter param set to val""" params=self.REQUEST.form.copy() @@ -240,12 +250,14 @@ class documentViewer(Folder): return False - def getDirinfoFromDigilib(self,path,docinfo=None): + def getDirinfoFromDigilib(self,path,docinfo=None,cut=0): """gibt param von dlInfo aus""" num_retries = 3 if docinfo is None: docinfo = {} - + + for x in range(cut): + path=getParentDir(path) infoUrl=self.digilibBaseUrl+"/dirInfo-xml.jsp?mo=dir&fn="+path logger("documentViewer (getparamfromdigilib)", logging.INFO, "dirInfo from %s"%(infoUrl)) @@ -286,7 +298,7 @@ class documentViewer(Folder): metaUrl=server+url.replace("/mpiwg/online","") if not metaUrl.endswith("index.meta"): metaUrl += "/index.meta" - print metaUrl + logging.debug("METAURL: %s"%metaUrl) for cnt in range(num_retries): try: # patch dirk encoding fehler treten dann nicht mehr auf @@ -332,7 +344,7 @@ class documentViewer(Folder): return dom - def getAuthinfoFromIndexMeta(self,path,docinfo=None,dom=None): + def getAuthinfoFromIndexMeta(self,path,docinfo=None,dom=None,cut=0): """gets authorization info from the index.meta file at path or given by dom""" logger("documentViewer (getauthinfofromindexmeta)", logging.INFO,"path: %s"%(path)) @@ -342,7 +354,9 @@ class documentViewer(Folder): docinfo = {} if dom is None: - dom = self.getIndexMeta(getParentDir(path)) + for x in range(cut+1): + path=getParentDir(path) + dom = self.getIndexMeta(path) acctype = dom.xpath("//access-conditions/access/@type") if acctype and (len(acctype)>0): @@ -354,7 +368,7 @@ class documentViewer(Folder): return docinfo - def getBibinfoFromIndexMeta(self,path,docinfo=None,dom=None): + def getBibinfoFromIndexMeta(self,path,docinfo=None,dom=None,cut=0): """gets bibliographical info from the index.meta file at path or given by dom""" logging.debug("documentViewer (getbibinfofromindexmeta) path: %s"%(path)) @@ -362,7 +376,9 @@ class documentViewer(Folder): docinfo = {} if dom is None: - dom = self.getIndexMeta(getParentDir(path)) + for x in range(cut+1): + path=getParentDir(path) + dom = self.getIndexMeta(path) # put in all raw bib fields as dict "bib" bib = dom.xpath("//bib/*") @@ -508,19 +524,19 @@ class documentViewer(Folder): pass return docinfo - def getDocinfoFromImagePath(self,path,docinfo=None): + def getDocinfoFromImagePath(self,path,docinfo=None,cut=0): """path ist the path to the images it assumes that the index.meta file is one level higher.""" logger("documentViewer (getdocinfofromimagepath)", logging.INFO,"path: %s"%(path)) if docinfo is None: docinfo = {} path=path.replace("/mpiwg/online","") docinfo['imagePath'] = path - docinfo=self.getDirinfoFromDigilib(path,docinfo=docinfo) + docinfo=self.getDirinfoFromDigilib(path,docinfo=docinfo,cut=cut) imageUrl=self.digilibBaseUrl+"/servlet/Scaler?fn="+path docinfo['imageURL'] = imageUrl - docinfo = self.getBibinfoFromIndexMeta(path,docinfo=docinfo) - docinfo = self.getAuthinfoFromIndexMeta(path,docinfo=docinfo) + docinfo = self.getBibinfoFromIndexMeta(path,docinfo=docinfo,cut=cut) + docinfo = self.getAuthinfoFromIndexMeta(path,docinfo=docinfo,cut=cut) return docinfo @@ -540,6 +556,8 @@ class documentViewer(Folder): docinfo = self.getDocinfoFromTextTool(url, docinfo=docinfo) elif mode=="imagepath": docinfo = self.getDocinfoFromImagePath(url, docinfo=docinfo) + elif mode=="filepath": + docinfo = self.getDocinfoFromImagePath(url, docinfo=docinfo,cut=1) else: logger("documentViewer (getdocinfo)", logging.ERROR,"unknown mode!") raise ValueError("Unknown mode %s"%(mode)) @@ -570,7 +588,7 @@ class documentViewer(Folder): pageinfo['numgroups'] = int(np / grpsize) if np % grpsize > 0: pageinfo['numgroups'] += 1 - + logging.debug("getPageInfo: %s"%repr(pageinfo)) return pageinfo def text(self,mode,url,pn):