--- documentViewer/documentViewer.py 2007/05/03 17:35:10 1.25 +++ documentViewer/documentViewer.py 2007/06/14 16:07:21 1.28 @@ -18,6 +18,7 @@ import sys import cgi import urllib import logging +import math import urlparse @@ -80,6 +81,7 @@ class documentViewer(Folder): image_main = PageTemplateFile('zpt/image_main', globals()) head_main = PageTemplateFile('zpt/head_main', globals()) docuviewer_css = PageTemplateFile('css/docuviewer.css', globals()) + info_xml = PageTemplateFile('zpt/info_xml', globals()) security.declareProtected('View management screens','changeDocumentViewerForm') changeDocumentViewerForm = PageTemplateFile('zpt/changeDocumentViewer', globals()) @@ -108,9 +110,9 @@ class documentViewer(Folder): def index_html(self,mode,url,viewMode="auto",start=None,pn=1): ''' view it - @param mode: defines which type of document is behind url (text,images or auto) + @param mode: defines how to access the document behind url @param url: url which contains display information - @param viewMode: if images display images, if text display text, default is images + @param viewMode: if images display images, if text display text, default is images (text,images or auto) ''' @@ -133,7 +135,6 @@ class documentViewer(Folder): else: viewMode="images" - return pt(docinfo=docinfo,pageinfo=pageinfo,viewMode=viewMode) @@ -152,6 +153,17 @@ class documentViewer(Folder): url=self.REQUEST['URL1']+"?"+ps return url + + def getInfo_xml(self,url,mode): + """returns info about the document as XML""" + + if not self.digilibBaseUrl: + self.digilibBaseUrl = self.findDigilibUrl() or "http://nausikaa.mpiwg-berlin.mpg.de/digitallibrary" + + docinfo = self.getDocinfo(mode=mode,url=url) + pt = getattr(self.template, 'info_xml') + return pt(docinfo=docinfo) + def getStyle(self, idx, selected, style=""): """returns a string with the given style and append 'sel' if path == selected.""" @@ -160,7 +172,7 @@ class documentViewer(Folder): return style + 'sel' else: return style - + def isAccessible(self, docinfo): """returns if access to the resource is granted""" @@ -298,7 +310,7 @@ class documentViewer(Folder): def getBibinfoFromIndexMeta(self,path,docinfo=None,dom=None): """gets bibliographical info from the index.meta file at path or given by dom""" - logger("documentViewer (getbibinfofromindexmeta)", logging.INFO,"path: %s"%(path)) + logging.debug("documentViewer (getbibinfofromindexmeta) path: %s"%(path)) if docinfo is None: docinfo = {} @@ -306,26 +318,36 @@ class documentViewer(Folder): if dom is None: dom = self.getIndexMeta(getParentDir(path)) + # put in all raw bib fields as dict "bib" + bib = dom.xpath("//bib/*") + if bib and len(bib)>0: + bibinfo = {} + for e in bib: + bibinfo[e.localName] = getTextFromNode(e) + docinfo['bib'] = bibinfo + + # extract some fields (author, title, year) according to their mapping metaData=self.metadata.main.meta.bib bibtype=dom.xpath("//bib/@type") if bibtype and (len(bibtype)>0): bibtype=bibtype[0].value else: bibtype="generic" + bibtype=bibtype.replace("-"," ") # wrong typesiin index meta "-" instead of " " (not wrong! ROC) + docinfo['bib_type'] = bibtype bibmap=metaData.generateMappingForType(bibtype) - #print "bibmap: ", bibmap, " for: ", bibtype # if there is no mapping bibmap is empty (mapping sometimes has empty fields) if len(bibmap) > 0 and len(bibmap['author'][0]) > 0: docinfo['author']=getTextFromNode(dom.xpath("//bib/%s"%bibmap['author'][0])[0]) docinfo['title']=getTextFromNode(dom.xpath("//bib/%s"%bibmap['title'][0])[0]) docinfo['year']=getTextFromNode(dom.xpath("//bib/%s"%bibmap['year'][0])[0]) - - logging.info("bla") + logging.debug("documentViewer (getbibinfofromindexmeta) using mapping for %s"%bibtype) try: docinfo['lang']=getTextFromNode(dom.xpath("//bib/lang")[0]) except: docinfo['lang']='' + return docinfo @@ -419,7 +441,7 @@ class documentViewer(Folder): 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]) + #docinfo['year']=getTextFromNode(dom.xpath("//date")[0]) return docinfo def getDocinfoFromImagePath(self,path,docinfo=None): @@ -474,7 +496,8 @@ class documentViewer(Folder): pageinfo['cols'] = cols grpsize = cols * rows pageinfo['groupsize'] = grpsize - start = getInt(start, default=(int(current / grpsize) * grpsize +1)) + start = getInt(start, default=(math.ceil(float(current)/float(grpsize))*grpsize-(grpsize-1))) + # int(current / grpsize) * grpsize +1)) pageinfo['start'] = start pageinfo['end'] = start + grpsize if docinfo is not None: