Changeset 561:9255acc4518d in documentViewer for documentViewer.py


Ignore:
Timestamp:
Oct 1, 2012, 4:09:01 PM (12 years ago)
Author:
casties
Branch:
default
Message:

CLOSED - # 256: display texts from different backends (sandbox)
https://it-dev.mpiwg-berlin.mpg.de/tracs/mpdl-project-software/ticket/256

File:
1 edited

Legend:

Unmodified
Added
Removed
  • documentViewer.py

    r560 r561  
    3333    #    stream.close()
    3434    return s
     35
     36def 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
    3542
    3643def browserCheck(self):
     
    220227        return self.template.fulltextclient.getTocPage(**args)
    221228
     229    def getRepositoryType(self, **args):
     230        """get repository type"""
     231        return self.template.fulltextclient.getRepositoryType(**args)
     232
    222233    def getTextDownloadUrl(self, **args):
    223234        """get list of gis places on one page"""
     
    571582
    572583            # texttool info
    573             texttool = self.metadataService.getTexttoolData(dom=metaDom)
     584            texttool = self.metadataService.getTexttoolData(dom=metaDom, recursive=1, all=True)
    574585            if texttool:
    575586                docinfo = self.getDocinfoFromTexttool(docinfo, texttool)
     
    676687    def getDocinfoFromTexttool(self, docinfo, texttool):
    677688        """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                                   
    678694        # image dir
    679         imageDir = texttool.get('image', None)
    680         docPath = docinfo.get('documentPath', None)
     695        imageDir = getMDText(texttool.get('image', None))
     696        docPath = getMDText(docinfo.get('documentPath', None))
    681697        if imageDir and docPath:
    682698            #print "image: ", imageDir, " archivepath: ", archivePath
     
    686702       
    687703        # old style text URL
    688         textUrl = texttool.get('text', None)
     704        textUrl = getMDText(texttool.get('text', None))
    689705        if textUrl and docPath:
    690706            if urlparse.urlparse(textUrl)[0] == "": #keine url
     
    693709            docinfo['textURL'] = textUrl
    694710   
    695         # new style text-url-path
    696         textUrl = texttool.get('text-url-path', None)
    697         if textUrl:
    698             docinfo['textURLPath'] = textUrl
     711        # new style text-url-path (can be more than one with "repository" attribute)
     712        textUrlNode = texttool.get('text-url-path', None)
     713        if not isinstance(textUrlNode, list):
     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
    699730           
    700731        # page flow
    701         docinfo['pageFlow'] = texttool.get('page-flow', 'ltr')
     732        docinfo['pageFlow'] = getMDText(texttool.get('page-flow', 'ltr'))
    702733           
    703734        # odd pages are left
    704         docinfo['oddPage'] = texttool.get('odd-scan-position', 'left')
     735        docinfo['oddPage'] = getMDText(texttool.get('odd-scan-position', 'left'))
    705736           
    706737        # 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))
    708739           
    709740        # old presentation stuff
    710         presentation = texttool.get('presentation', None)
     741        presentation = getMDText(texttool.get('presentation', None))
    711742        if presentation and docPath:
    712743            if presentation.startswith('http:'):
Note: See TracChangeset for help on using the changeset viewer.