Changeset 455:0a53fea83df7 in documentViewer for documentViewer_old.py


Ignore:
Timestamp:
Jul 15, 2011, 7:34:41 PM (13 years ago)
Author:
casties
Branch:
elementtree
Message:

more work renovating

File:
1 edited

Legend:

Unmodified
Added
Removed
  • documentViewer_old.py

    r453 r455  
    1010from Ft.Xml import EMPTY_NAMESPACE, Parse
    1111import Ft.Xml.Domlette
    12 
    13 import xml.etree.ElementTree as ET
    14 
    1512import os.path
    1613import sys
     
    3633        return int(default)
    3734
    38 def getTextFromNode(node):
     35def getTextFromNode(nodename):
    3936    """get the cdata content of a node"""
    40     if node is None:
     37    if nodename is None:
    4138        return ""
    42     # ET:
    43     text = node.text or ""
    44     for e in node:
    45         text += gettext(e)
    46         if e.tail:
    47             text += e.tail
    48 
    49     # 4Suite:
    50     #nodelist=node.childNodes
    51     #text = ""
    52     #for n in nodelist:
    53     #    if n.nodeType == node.TEXT_NODE:
    54     #       text = text + n.data
    55    
    56     return text
     39    nodelist=nodename.childNodes
     40    rc = ""
     41    for node in nodelist:
     42        if node.nodeType == node.TEXT_NODE:
     43           rc = rc + node.data
     44    return rc
    5745
    5846def serializeNode(node, encoding="utf-8"):
    5947    """returns a string containing node as XML"""
    60     s = ET.tostring(node)
    61    
    62     # 4Suite:
    63     #    stream = cStringIO.StringIO()
    64     #    Ft.Xml.Domlette.Print(node, stream=stream, encoding=encoding)
    65     #    s = stream.getvalue()
    66     #    stream.close()
     48    stream = cStringIO.StringIO()
     49    #logging.debug("BUF: %s"%(stream))
     50    Ft.Xml.Domlette.Print(node, stream=stream, encoding=encoding)
     51    s = stream.getvalue()
     52    #logging.debug("BUF: %s"%(s))
     53    stream.close()
    6754    return s
    6855
     
    510497            raise IOError("Unable to get dir-info from %s"%(infoUrl))
    511498
    512         dom = ET.fromstring(txt).getroot()
    513         #dom = Parse(txt)
    514         sizes=dom.find("//dir/size")
    515         #sizes=dom.xpath("//dir/size")
     499        dom = Parse(txt)
     500        sizes=dom.xpath("//dir/size")
    516501        logging.debug("documentViewer (getparamfromdigilib) dirInfo:size"%sizes)
    517502       
     
    562547            raise IOError("Unable to read index meta from %s"%(url))
    563548       
    564         dom = ET.fromstring(txt).getroot()
    565         #dom = Parse(txt)
     549        dom = Parse(txt)
    566550        return dom
    567551   
     
    582566            raise IOError("Unable to read infoXMLfrom %s"%(url))
    583567           
    584         dom = ET.fromstring(txt).getroot()
    585         #dom = Parse(txt)
     568        dom = Parse(txt)
    586569        return dom
    587570                       
     
    601584            dom = self.getDomFromIndexMeta(path)
    602585       
    603         acctype = dom.find("//access-conditions/access/@type")
    604         #acctype = dom.xpath("//access-conditions/access/@type")
     586        acctype = dom.xpath("//access-conditions/access/@type")
    605587        if acctype and (len(acctype)>0):
    606588            access=acctype[0].value
     
    628610        logging.debug("documentViewer (getbibinfofromindexmeta cutted) path: %s"%(path))
    629611        # put in all raw bib fields as dict "bib"
    630         bib = dom.find("//bib/*")
    631         #bib = dom.xpath("//bib/*")
     612        bib = dom.xpath("//bib/*")
    632613        if bib and len(bib)>0:
    633614            bibinfo = {}
     
    638619        # extract some fields (author, title, year) according to their mapping
    639620        metaData=self.metadata.main.meta.bib
    640         bibtype=dom.find("//bib/@type")
    641         #bibtype=dom.xpath("//bib/@type")
     621        bibtype=dom.xpath("//bib/@type")
    642622        if bibtype and (len(bibtype)>0):
    643623            bibtype=bibtype[0].value
Note: See TracChangeset for help on using the changeset viewer.