--- documentViewer/Attic/documentViewer_old.py 2011/07/14 17:43:56 1.1.2.1 +++ documentViewer/Attic/documentViewer_old.py 2011/07/15 19:34:41 1.1.2.2 @@ -9,9 +9,6 @@ from Products.zogiLib.zogiLib import bro 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 @@ def getInt(number, default=0): 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 @@ class documentViewer(Folder): 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 @@ class documentViewer(Folder): 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 @@ class documentViewer(Folder): 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 @@ class documentViewer(Folder): 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 @@ class documentViewer(Folder): 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 @@ class documentViewer(Folder): # 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: