Changeset 463:89ad327b4bbd in documentViewer


Ignore:
Timestamp:
Jul 28, 2011, 1:00:07 PM (13 years ago)
Author:
casties
Branch:
elementtree
Message:

more renovation

File:
1 edited

Legend:

Unmodified
Added
Removed
  • documentViewer.py

    r462 r463  
    103103    return '/'.join(path.split('/')[0:-1])
    104104       
    105 def normalizeBibField(bt, underscore=True):
    106     """returns normalised bib type for looking up mappings"""
    107     bt = bt.strip().replace(' ', '-').lower()
    108     if underscore:
    109         bt = bt.replace('_', '-')
    110        
    111     return bt
    112 
    113 def getBibdataFromDom(dom):
    114     """returns dict with all elements from bib-tag"""
    115     bibinfo = {}
    116     bib = dom.find(".//meta/bib")
    117     if bib is not None:
    118         # put type in @type
    119         type = bib.get('type')
    120         bibinfo['@type'] = normalizeBibField(type)
    121         # put all subelements in dict
    122         for e in bib:
    123             bibinfo[normalizeBibField(e.tag)] = getText(e)
    124            
    125     return bibinfo
    126 
    127105
    128106##
     
    137115        {'label':'main config','action':'changeDocumentViewerForm'},
    138116        )
     117   
     118    metadataService = None
     119    """MetaDataFolder instance"""
    139120
    140121    # templates and forms
     
    156137   
    157138    thumbs_main_rss = PageTemplateFile('zpt/thumbs_main_rss', globals())
    158     security.declareProtected('View management screens','changeDocumentViewerForm')   
    159     changeDocumentViewerForm = PageTemplateFile('zpt/changeDocumentViewer', globals())
    160139
    161140   
     
    180159        except Exception, e:
    181160            logging.error("Unable to create MpdlXmlTextServer for fulltextclient: "+str(e))
     161           
    182162        try:
    183163            from Products.zogiLib.zogiLib import zogiLib
     
    187167        except Exception, e:
    188168            logging.error("Unable to create zogiLib for zogilib: "+str(e))
    189        
     169           
     170        try:
     171            # assume MetaDataFolder instance is called metadata
     172            self.metadataService = getattr(self, 'metadata')
     173        except Exception, e:
     174            logging.error("Unable to find MetaDataFolder 'metadata': "+str(e))
     175           
    190176       
    191177    # proxy text server methods to fulltextclient
     
    582568       
    583569        logging.debug("documentViewer (getbibinfofromindexmeta cutted) path: %s"%(path))
    584         # try to get MetaDataFolder
    585         metadata = getattr(self, 'metadata')
    586         if metadata is not None:
     570        if self.metadataService is not None:
    587571            # put all raw bib fields in dict "bib"
    588             bib = metadata.getBibdataFromDom(dom)
     572            bib = self.metadataService.getBibData(dom=dom)
    589573            docinfo['bib'] = bib
    590574            bibtype = bib.get('@type', None)
    591575            docinfo['bib_type'] = bibtype
    592576            # also store DC metadata for convenience
    593             dc = metadata.getDCMappedData(bib)
     577            dc = self.metadataService.getDCMappedData(bib)
    594578            docinfo['creator'] = dc.get('creator',None)
    595579            docinfo['title'] = dc.get('title',None)
    596580            docinfo['date'] = dc.get('date',None)
    597581        else:
    598             logging.error("MetaDataFolder 'metadata' not found!")
    599             #TODO: remove
    600             bib = getBibdataFromDom(dom)
     582            logging.error("MetadataService not found!")
    601583        return docinfo
    602584   
     
    616598        logging.debug("documentViewer docinfo[name] %s"%docinfo['name'])
    617599        return docinfo
     600
    618601   
    619602    def getDocinfoFromTextTool(self, url, dom=None, docinfo=None):
     
    626609        if dom is None:
    627610            dom = self.getDomFromIndexMeta(url)
     611           
     612        texttool = self.metadata.getTexttoolData(dom=dom)
    628613       
    629614        archivePath = None
     
    651636            raise IOError("Missing archive-path (for text-tool) in %s" % (url))
    652637       
    653         imageDir = getText(dom.find(".//texttool/image"))
     638        imageDir = texttool.get('image', None)
    654639           
    655640        if not imageDir:
     
    670655            docinfo['imageURL'] = self.digilibBaseUrl + "/servlet/Scaler?fn=" + imageDir
    671656           
    672         viewerUrl = getText(dom.find(".//texttool/digiliburlprefix"))
     657        viewerUrl = texttool.get('digiliburlprefix', None)
    673658        if viewerUrl:
    674659            docinfo['viewerURL'] = viewerUrl
    675660       
    676661        # old style text URL
    677         textUrl = getText(dom.find(".//texttool/text"))
     662        textUrl = texttool.get('text', None)
    678663        if textUrl:
    679664            if urlparse.urlparse(textUrl)[0] == "": #keine url
     
    686671   
    687672        # new style text-url-path
    688         textUrl = getText(dom.find(".//texttool/text-url-path"))
     673        textUrl = texttool.get('text-url-path', None)
    689674        if textUrl:
    690675            docinfo['textURLPath'] = textUrl
     
    695680                #docinfo = self.getNumTextPages(docinfo)
    696681                 
    697          
    698         presentationUrl = getText(dom.find(".//texttool/presentation"))
     682        # get bib info
    699683        docinfo = self.getBibinfoFromIndexMeta(url, docinfo=docinfo, dom=dom)   # get info von bib tag
    700684        # TODO: is this needed here?
    701685        docinfo = self.getNameFromIndexMeta(url, docinfo=docinfo, dom=dom)
    702686       
    703        
     687        # TODO: what to do with presentation?
     688        presentationUrl = texttool.get('presentation', None)
    704689        if presentationUrl: # ueberschreibe diese durch presentation informationen
    705690             # presentation url ergiebt sich ersetzen von index.meta in der url der fuer die Metadaten
     
    713698            docinfo = self.getBibinfoFromTextToolPresentation(presentationUrl, docinfo=docinfo, dom=dom)
    714699   
     700        # get authorization
    715701        docinfo = self.getAuthinfoFromIndexMeta(url, docinfo=docinfo, dom=dom)   # get access info
    716702       
     
    840826        return pageinfo
    841827
     828
     829    security.declareProtected('View management screens','changeDocumentViewerForm')   
     830    changeDocumentViewerForm = PageTemplateFile('zpt/changeDocumentViewer', globals())
    842831   
    843832    def changeDocumentViewer(self,title="",digilibBaseUrl=None,thumbrows=2,thumbcols=5,authgroups='mpiwg',RESPONSE=None):
     
    848837        self.thumbcols = thumbcols
    849838        self.authgroups = [s.strip().lower() for s in authgroups.split(',')]
     839        try:
     840            # assume MetaDataFolder instance is called metadata
     841            self.metadataService = getattr(self, 'metadata')
     842        except Exception, e:
     843            logging.error("Unable to find MetaDataFolder 'metadata': "+str(e))
     844
    850845        if RESPONSE is not None:
    851846            RESPONSE.redirect('manage_main')
Note: See TracChangeset for help on using the changeset viewer.