Mercurial > hg > documentViewer
comparison 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 |
comparison
equal
deleted
inserted
replaced
560:04c330b92cab | 561:9255acc4518d |
---|---|
30 # stream = cStringIO.StringIO() | 30 # stream = cStringIO.StringIO() |
31 # Ft.Xml.Domlette.Print(node, stream=stream, encoding=encoding) | 31 # Ft.Xml.Domlette.Print(node, stream=stream, encoding=encoding) |
32 # s = stream.getvalue() | 32 # s = stream.getvalue() |
33 # stream.close() | 33 # stream.close() |
34 return s | 34 return s |
35 | |
36 def getMDText(node): | |
37 """returns the @text content from the MetaDataProvider metadata node""" | |
38 if isinstance(node, dict): | |
39 return node.get('@text', None) | |
40 | |
41 return node | |
35 | 42 |
36 def browserCheck(self): | 43 def browserCheck(self): |
37 """check the browsers request to find out the browser type""" | 44 """check the browsers request to find out the browser type""" |
38 bt = {} | 45 bt = {} |
39 ua = self.REQUEST.get_header("HTTP_USER_AGENT") | 46 ua = self.REQUEST.get_header("HTTP_USER_AGENT") |
217 | 224 |
218 def getTocPage(self, **args): | 225 def getTocPage(self, **args): |
219 """returns one page of the table of contents""" | 226 """returns one page of the table of contents""" |
220 return self.template.fulltextclient.getTocPage(**args) | 227 return self.template.fulltextclient.getTocPage(**args) |
221 | 228 |
229 def getRepositoryType(self, **args): | |
230 """get repository type""" | |
231 return self.template.fulltextclient.getRepositoryType(**args) | |
232 | |
222 def getTextDownloadUrl(self, **args): | 233 def getTextDownloadUrl(self, **args): |
223 """get list of gis places on one page""" | 234 """get list of gis places on one page""" |
224 return self.template.fulltextclient.getTextDownloadUrl(**args) | 235 return self.template.fulltextclient.getTextDownloadUrl(**args) |
225 | 236 |
226 def getPlacesOnPage(self, **args): | 237 def getPlacesOnPage(self, **args): |
568 resource = self.metadataService.getResourceData(dom=metaDom) | 579 resource = self.metadataService.getResourceData(dom=metaDom) |
569 if resource: | 580 if resource: |
570 docinfo = self.getDocinfoFromResource(docinfo, resource) | 581 docinfo = self.getDocinfoFromResource(docinfo, resource) |
571 | 582 |
572 # texttool info | 583 # texttool info |
573 texttool = self.metadataService.getTexttoolData(dom=metaDom) | 584 texttool = self.metadataService.getTexttoolData(dom=metaDom, recursive=1, all=True) |
574 if texttool: | 585 if texttool: |
575 docinfo = self.getDocinfoFromTexttool(docinfo, texttool) | 586 docinfo = self.getDocinfoFromTexttool(docinfo, texttool) |
576 # document info (including toc) from full text | 587 # document info (including toc) from full text |
577 if docinfo.get('textURLPath', None): | 588 if docinfo.get('textURLPath', None): |
578 docinfo = self.getTextInfo(mode=tocMode, docinfo=docinfo) | 589 docinfo = self.getTextInfo(mode=tocMode, docinfo=docinfo) |
673 docinfo['documentPath'] = docPath | 684 docinfo['documentPath'] = docPath |
674 return docinfo | 685 return docinfo |
675 | 686 |
676 def getDocinfoFromTexttool(self, docinfo, texttool): | 687 def getDocinfoFromTexttool(self, docinfo, texttool): |
677 """reads contents of texttool element into docinfo""" | 688 """reads contents of texttool element into docinfo""" |
689 logging.debug("texttool=%s"%repr(texttool)) | |
690 # unpack list if necessary | |
691 if isinstance(texttool, list): | |
692 texttool = texttool[0] | |
693 | |
678 # image dir | 694 # image dir |
679 imageDir = texttool.get('image', None) | 695 imageDir = getMDText(texttool.get('image', None)) |
680 docPath = docinfo.get('documentPath', None) | 696 docPath = getMDText(docinfo.get('documentPath', None)) |
681 if imageDir and docPath: | 697 if imageDir and docPath: |
682 #print "image: ", imageDir, " archivepath: ", archivePath | 698 #print "image: ", imageDir, " archivepath: ", archivePath |
683 imageDir = os.path.join(docPath, imageDir) | 699 imageDir = os.path.join(docPath, imageDir) |
684 imageDir = imageDir.replace('/mpiwg/online', '', 1) | 700 imageDir = imageDir.replace('/mpiwg/online', '', 1) |
685 docinfo['imagePath'] = imageDir | 701 docinfo['imagePath'] = imageDir |
686 | 702 |
687 # old style text URL | 703 # old style text URL |
688 textUrl = texttool.get('text', None) | 704 textUrl = getMDText(texttool.get('text', None)) |
689 if textUrl and docPath: | 705 if textUrl and docPath: |
690 if urlparse.urlparse(textUrl)[0] == "": #keine url | 706 if urlparse.urlparse(textUrl)[0] == "": #keine url |
691 textUrl = os.path.join(docPath, textUrl) | 707 textUrl = os.path.join(docPath, textUrl) |
692 | 708 |
693 docinfo['textURL'] = textUrl | 709 docinfo['textURL'] = textUrl |
694 | 710 |
695 # new style text-url-path | 711 # new style text-url-path (can be more than one with "repository" attribute) |
696 textUrl = texttool.get('text-url-path', None) | 712 textUrlNode = texttool.get('text-url-path', None) |
697 if textUrl: | 713 if not isinstance(textUrlNode, list): |
698 docinfo['textURLPath'] = textUrl | 714 textUrlNode = [textUrlNode] |
715 | |
716 for tun in textUrlNode: | |
717 textUrl = getMDText(tun) | |
718 if textUrl: | |
719 textUrlAtts = tun.get('@attr') | |
720 if (textUrlAtts and 'repository' in textUrlAtts): | |
721 textRepo = textUrlAtts['repository'] | |
722 # use matching repository | |
723 if self.getRepositoryType() == textRepo: | |
724 docinfo['textURLPath'] = textUrl | |
725 docinfo['textURLRepository'] = textRepo | |
726 | |
727 else: | |
728 # no repo attribute - use always | |
729 docinfo['textURLPath'] = textUrl | |
699 | 730 |
700 # page flow | 731 # page flow |
701 docinfo['pageFlow'] = texttool.get('page-flow', 'ltr') | 732 docinfo['pageFlow'] = getMDText(texttool.get('page-flow', 'ltr')) |
702 | 733 |
703 # odd pages are left | 734 # odd pages are left |
704 docinfo['oddPage'] = texttool.get('odd-scan-position', 'left') | 735 docinfo['oddPage'] = getMDText(texttool.get('odd-scan-position', 'left')) |
705 | 736 |
706 # number of title page (default 1) | 737 # number of title page (default 1) |
707 docinfo['titlePage'] = texttool.get('title-scan-no', 1) | 738 docinfo['titlePage'] = getMDText(texttool.get('title-scan-no', 1)) |
708 | 739 |
709 # old presentation stuff | 740 # old presentation stuff |
710 presentation = texttool.get('presentation', None) | 741 presentation = getMDText(texttool.get('presentation', None)) |
711 if presentation and docPath: | 742 if presentation and docPath: |
712 if presentation.startswith('http:'): | 743 if presentation.startswith('http:'): |
713 docinfo['presentationUrl'] = presentation | 744 docinfo['presentationUrl'] = presentation |
714 else: | 745 else: |
715 docinfo['presentationUrl'] = os.path.join(docPath, presentation) | 746 docinfo['presentationUrl'] = os.path.join(docPath, presentation) |