diff documentViewer_old.py @ 455:0a53fea83df7 elementtree

more work renovating
author casties
date Fri, 15 Jul 2011 21:34:41 +0200
parents beb7ccb92564
children
line wrap: on
line diff
--- a/documentViewer_old.py	Fri Jul 15 11:02:26 2011 +0200
+++ b/documentViewer_old.py	Fri Jul 15 21:34:41 2011 +0200
@@ -9,9 +9,6 @@
 
 from Ft.Xml import EMPTY_NAMESPACE, Parse 
 import Ft.Xml.Domlette
-
-import xml.etree.ElementTree as ET
-
 import os.path
 import sys
 import urllib
@@ -35,35 +32,25 @@
     except:
         return int(default)
 
-def getTextFromNode(node):
+def getTextFromNode(nodename):
     """get the cdata content of a node"""
-    if node is None:
+    if nodename is None:
         return ""
-    # ET:
-    text = node.text or ""
-    for e in node:
-        text += gettext(e)
-        if e.tail:
-            text += e.tail
-
-    # 4Suite:
-    #nodelist=node.childNodes
-    #text = ""
-    #for n in nodelist:
-    #    if n.nodeType == node.TEXT_NODE:
-    #       text = text + n.data
-    
-    return text
+    nodelist=nodename.childNodes
+    rc = ""
+    for node in nodelist:
+        if node.nodeType == node.TEXT_NODE:
+           rc = rc + node.data
+    return rc
 
 def serializeNode(node, encoding="utf-8"):
     """returns a string containing node as XML"""
-    s = ET.tostring(node)
-    
-    # 4Suite:
-    #    stream = cStringIO.StringIO()
-    #    Ft.Xml.Domlette.Print(node, stream=stream, encoding=encoding)
-    #    s = stream.getvalue()
-    #    stream.close()
+    stream = cStringIO.StringIO()
+    #logging.debug("BUF: %s"%(stream))
+    Ft.Xml.Domlette.Print(node, stream=stream, encoding=encoding)
+    s = stream.getvalue()
+    #logging.debug("BUF: %s"%(s))
+    stream.close()
     return s
 
 def browserCheck(self):
@@ -509,10 +496,8 @@
         if txt is None:
             raise IOError("Unable to get dir-info from %s"%(infoUrl))
 
-        dom = ET.fromstring(txt).getroot()
-        #dom = Parse(txt)
-        sizes=dom.find("//dir/size")
-        #sizes=dom.xpath("//dir/size")
+        dom = Parse(txt)
+        sizes=dom.xpath("//dir/size")
         logging.debug("documentViewer (getparamfromdigilib) dirInfo:size"%sizes)
         
         if sizes:
@@ -561,8 +546,7 @@
         if txt is None:
             raise IOError("Unable to read index meta from %s"%(url))
         
-        dom = ET.fromstring(txt).getroot()
-        #dom = Parse(txt)
+        dom = Parse(txt)
         return dom
     
     def getPresentationInfoXML(self, url):
@@ -581,8 +565,7 @@
         if txt is None:
             raise IOError("Unable to read infoXMLfrom %s"%(url))
             
-        dom = ET.fromstring(txt).getroot()
-        #dom = Parse(txt)
+        dom = Parse(txt)
         return dom
                         
         
@@ -600,8 +583,7 @@
                 path=getParentDir(path)
             dom = self.getDomFromIndexMeta(path)
        
-        acctype = dom.find("//access-conditions/access/@type")
-        #acctype = dom.xpath("//access-conditions/access/@type")
+        acctype = dom.xpath("//access-conditions/access/@type")
         if acctype and (len(acctype)>0):
             access=acctype[0].value
             if access in ['group', 'institution']:
@@ -627,8 +609,7 @@
         
         logging.debug("documentViewer (getbibinfofromindexmeta cutted) path: %s"%(path))
         # put in all raw bib fields as dict "bib"
-        bib = dom.find("//bib/*")
-        #bib = dom.xpath("//bib/*")
+        bib = dom.xpath("//bib/*")
         if bib and len(bib)>0:
             bibinfo = {}
             for e in bib:
@@ -637,8 +618,7 @@
         
         # extract some fields (author, title, year) according to their mapping
         metaData=self.metadata.main.meta.bib
-        bibtype=dom.find("//bib/@type")
-        #bibtype=dom.xpath("//bib/@type")
+        bibtype=dom.xpath("//bib/@type")
         if bibtype and (len(bibtype)>0):
             bibtype=bibtype[0].value
         else: