def fromXML(element, theclass=None):
        from xml.dom import Node
        from comoonics import XmlTools
        localmap = globals()
        objecttype = None
        instance = None
        if not theclass:
            ot_elements = element.getElementsByTagName("objecttype")
            if len(ot_elements) == 1:
                objecttype = XmlTools.getTextFromElement(ot_elements[0])
                #mylogger.debug("objecttype: %s, %s" %(objecttype, localmap))
        if localmap.has_key("HP_EVA_%s" % (element.nodeName.capitalize())
                            ) and not theclass and not objecttype:
            myclass = localmap["HP_EVA_%s" % (element.nodeName.capitalize())]
            #mylogger.debug("theclass: %s" %(myclass))
            instance = HP_EVA_Object.fromXML(element, myclass)
        elif objecttype and localmap.has_key(
                "HP_EVA_%s" % (objecttype.capitalize())) and not theclass:
            myclass = localmap["HP_EVA_%s" % (objecttype.capitalize())]
            #mylogger.debug("theclass: %s" %(myclass))
            instance = HP_EVA_Object.fromXML(element, myclass)
        elif theclass:
            #mylogger.debug("theclass: %s" %(theclass))
            instance = object.__new__(theclass)
            instance.__init__()
            for child in element.childNodes:
                if child.nodeType == Node.ELEMENT_NODE:
                    paramname = child.nodeName
                    paramvalue = XmlTools.getTextFromElement(child)
                    if paramvalue:
                        paramvalue = paramvalue.strip()
                    if paramname and paramvalue and paramvalue != "":
                        #mylogger.debug("setattr(%s, %s, %s)" %(theclass, paramname, paramvalue))
                        setattr(instance, paramname, paramvalue)
                    elif paramname == "parentstoragecellinfo":
                        ids = child.getElementsByTagName("storagecellid")
                        if len(ids) == 1:
                            id = XmlTools.getTextFromElement(ids[0])
                            if HP_EVA_Storagecells.has_key(id):
                                #mylogger.debug("storagecellkey: %s, keys: %s, has_key:%u" %(id, HP_EVA_Storagecells.names(), HP_EVA_Storagecells.has_key(id)))
                                instance.setParent(HP_EVA_Storagecells.get(id))
                    elif paramname:
                        setattr(instance, paramname,
                                HP_EVA_Object.fromXML(child))

        return instance
    def fromXML(element, theclass=None):
        from xml.dom import Node
        from comoonics import XmlTools
        localmap=globals()
        objecttype=None
        instance=None
        if not theclass:
            ot_elements=element.getElementsByTagName("objecttype")
            if len(ot_elements)==1:
                objecttype=XmlTools.getTextFromElement(ot_elements[0])
                #mylogger.debug("objecttype: %s, %s" %(objecttype, localmap))
        if localmap.has_key("HP_EVA_%s" %(element.nodeName.capitalize())) and not theclass and not objecttype:
            myclass=localmap["HP_EVA_%s" %(element.nodeName.capitalize())]
            #mylogger.debug("theclass: %s" %(myclass))
            instance=HP_EVA_Object.fromXML(element, myclass)
        elif objecttype and localmap.has_key("HP_EVA_%s" %(objecttype.capitalize())) and not theclass:
            myclass=localmap["HP_EVA_%s" %(objecttype.capitalize())]
            #mylogger.debug("theclass: %s" %(myclass))
            instance=HP_EVA_Object.fromXML(element, myclass)
        elif theclass:
            #mylogger.debug("theclass: %s" %(theclass))
            instance=object.__new__(theclass)
            instance.__init__()
            for child in element.childNodes:
                if child.nodeType == Node.ELEMENT_NODE:
                    paramname=child.nodeName
                    paramvalue=XmlTools.getTextFromElement(child)
                    if paramvalue:
                        paramvalue=paramvalue.strip()
                    if paramname and paramvalue and paramvalue!="":
                        #mylogger.debug("setattr(%s, %s, %s)" %(theclass, paramname, paramvalue))
                        setattr(instance, paramname, paramvalue)
                    elif paramname == "parentstoragecellinfo":
                        ids=child.getElementsByTagName("storagecellid")
                        if len(ids)==1:
                            id=XmlTools.getTextFromElement(ids[0])
                            if HP_EVA_Storagecells.has_key(id):
                                #mylogger.debug("storagecellkey: %s, keys: %s, has_key:%u" %(id, HP_EVA_Storagecells.names(), HP_EVA_Storagecells.has_key(id)))
                                instance.setParent(HP_EVA_Storagecells.get(id))
                    elif paramname:
                        setattr(instance, paramname, HP_EVA_Object.fromXML(child))

        return instance
 def _do(self):
     _message = ""
     if self.parent.hasAttribute("message"):
         _message = self.parent.getAttribute("message")
         _message += "\n"
     else:
         _textelements = self.parent.getElement().getElementsByTagName(
             "text")
         for _textelement in _textelements:
             _message += XmlTools.getTextFromElement(_textelement)
             _message += "\n"
     self.out.write(_message)
    def _do(self):
        _message=""
        if self.parent.hasAttribute("message"):
            _message=self.parent.getAttribute("message")
            _message+="\n"
        else:
            _textelements=self.parent.getElement().getElementsByTagName("text")
            for _textelement in _textelements:
                _message+=XmlTools.getTextFromElement(_textelement)
                _message+="\n"
        self.out.write(_message)

###################
# $Log: ComMessage.py,v $
# Revision 1.2  2010-03-08 12:30:48  marc
# version for comoonics4.6-rc1
#
# Revision 1.1  2007/09/07 14:37:56  marc
# initial revision
#
 def testGetTextFromElement(self):
     doc=self.docs[3][0]
     self.assertEquals(None, XmlTools.getTextFromElement(doc.documentElement))
 def testGetTextFromElement1(self):
     doc=self.docs[2][0]
     self.assertEquals("abcd", XmlTools.getTextFromElement(doc.documentElement))
 def testGetTextFromElement(self):
     doc = self.docs[3][0]
     self.assertEquals(None,
                       XmlTools.getTextFromElement(doc.documentElement))
 def testGetTextFromElement1(self):
     doc = self.docs[2][0]
     self.assertEquals("abcd",
                       XmlTools.getTextFromElement(doc.documentElement))
Exemple #9
0
 def _parse_dateformat(self, cursect, child):
     _format=XmlTools.getTextFromElement(child)
     cursect["dateformat"]=_format