Mercurial > hg > documentViewer
diff documentViewer.py @ 561:9255acc4518d
CLOSED - # 256: display texts from different backends (sandbox)
https://it-dev.mpiwg-berlin.mpg.de/tracs/mpdl-project-software/ticket/256
author | casties |
---|---|
date | Mon, 01 Oct 2012 18:09:01 +0200 |
parents | 04c330b92cab |
children | 60f5a636bc57 |
line wrap: on
line diff
--- a/documentViewer.py Mon Oct 01 15:33:22 2012 +0200 +++ b/documentViewer.py Mon Oct 01 18:09:01 2012 +0200 @@ -33,6 +33,13 @@ # stream.close() return s +def getMDText(node): + """returns the @text content from the MetaDataProvider metadata node""" + if isinstance(node, dict): + return node.get('@text', None) + + return node + def browserCheck(self): """check the browsers request to find out the browser type""" bt = {} @@ -219,6 +226,10 @@ """returns one page of the table of contents""" return self.template.fulltextclient.getTocPage(**args) + def getRepositoryType(self, **args): + """get repository type""" + return self.template.fulltextclient.getRepositoryType(**args) + def getTextDownloadUrl(self, **args): """get list of gis places on one page""" return self.template.fulltextclient.getTextDownloadUrl(**args) @@ -570,7 +581,7 @@ docinfo = self.getDocinfoFromResource(docinfo, resource) # texttool info - texttool = self.metadataService.getTexttoolData(dom=metaDom) + texttool = self.metadataService.getTexttoolData(dom=metaDom, recursive=1, all=True) if texttool: docinfo = self.getDocinfoFromTexttool(docinfo, texttool) # document info (including toc) from full text @@ -675,9 +686,14 @@ def getDocinfoFromTexttool(self, docinfo, texttool): """reads contents of texttool element into docinfo""" + logging.debug("texttool=%s"%repr(texttool)) + # unpack list if necessary + if isinstance(texttool, list): + texttool = texttool[0] + # image dir - imageDir = texttool.get('image', None) - docPath = docinfo.get('documentPath', None) + imageDir = getMDText(texttool.get('image', None)) + docPath = getMDText(docinfo.get('documentPath', None)) if imageDir and docPath: #print "image: ", imageDir, " archivepath: ", archivePath imageDir = os.path.join(docPath, imageDir) @@ -685,29 +701,44 @@ docinfo['imagePath'] = imageDir # old style text URL - textUrl = texttool.get('text', None) + textUrl = getMDText(texttool.get('text', None)) if textUrl and docPath: if urlparse.urlparse(textUrl)[0] == "": #keine url textUrl = os.path.join(docPath, textUrl) docinfo['textURL'] = textUrl - # new style text-url-path - textUrl = texttool.get('text-url-path', None) - if textUrl: - docinfo['textURLPath'] = textUrl + # new style text-url-path (can be more than one with "repository" attribute) + textUrlNode = texttool.get('text-url-path', None) + if not isinstance(textUrlNode, list): + textUrlNode = [textUrlNode] + + for tun in textUrlNode: + textUrl = getMDText(tun) + if textUrl: + textUrlAtts = tun.get('@attr') + if (textUrlAtts and 'repository' in textUrlAtts): + textRepo = textUrlAtts['repository'] + # use matching repository + if self.getRepositoryType() == textRepo: + docinfo['textURLPath'] = textUrl + docinfo['textURLRepository'] = textRepo + + else: + # no repo attribute - use always + docinfo['textURLPath'] = textUrl # page flow - docinfo['pageFlow'] = texttool.get('page-flow', 'ltr') + docinfo['pageFlow'] = getMDText(texttool.get('page-flow', 'ltr')) # odd pages are left - docinfo['oddPage'] = texttool.get('odd-scan-position', 'left') + docinfo['oddPage'] = getMDText(texttool.get('odd-scan-position', 'left')) # number of title page (default 1) - docinfo['titlePage'] = texttool.get('title-scan-no', 1) + docinfo['titlePage'] = getMDText(texttool.get('title-scan-no', 1)) # old presentation stuff - presentation = texttool.get('presentation', None) + presentation = getMDText(texttool.get('presentation', None)) if presentation and docPath: if presentation.startswith('http:'): docinfo['presentationUrl'] = presentation