xmlifBase.py
Go to the documentation of this file.
00001 #
00002 # genxmlif, Release 0.9.0
00003 # file: xmlifbase.py
00004 #
00005 # XML interface base classes
00006 #
00007 # history:
00008 # 2005-04-25 rl   created
00009 # 2006-08-18 rl   some methods for XML schema validation support added
00010 # 2007-05-25 rl   performance optimization (caching) added, bugfixes for XPath handling
00011 # 2007-07-04 rl   complete re-design, API classes moved to xmlifApi.py
00012 #
00013 # Copyright (c) 2005-2008 by Roland Leuthe.  All rights reserved.
00014 #
00015 # --------------------------------------------------------------------
00016 # The generic XML interface is
00017 #
00018 # Copyright (c) 2005-2008 by Roland Leuthe
00019 #
00020 # By obtaining, using, and/or copying this software and/or its
00021 # associated documentation, you agree that you have read, understood,
00022 # and will comply with the following terms and conditions:
00023 #
00024 # Permission to use, copy, modify, and distribute this software and
00025 # its associated documentation for any purpose and without fee is
00026 # hereby granted, provided that the above copyright notice appears in
00027 # all copies, and that both that copyright notice and this permission
00028 # notice appear in supporting documentation, and that the name of
00029 # the author not be used in advertising or publicity
00030 # pertaining to distribution of the software without specific, written
00031 # prior permission.
00032 #
00033 # THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
00034 # TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANT-
00035 # ABILITY AND FITNESS.  IN NO EVENT SHALL THE AUTHOR
00036 # BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
00037 # DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
00038 # WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
00039 # ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
00040 # OF THIS SOFTWARE.
00041 # --------------------------------------------------------------------
00042 
00043 __author__  = "Roland Leuthe <roland@leuthe-net.de>"
00044 __date__    = "28 July 2008"
00045 __version__ = "0.9"
00046 
00047 from xml.dom    import XML_NAMESPACE, XMLNS_NAMESPACE
00048 from xmlifUtils import NsNameTupleFactory, convertToAbsUrl
00049 
00050 
00051 
00052 ########################################
00053 # XmlIf builder extension base class
00054 # All not implemented methods have to be overloaded by the derived class!!
00055 #
00056 
00057 class XmlIfBuilderExtensionBase:
00058     """XmlIf builder extension base class.
00059     
00060     This class provides additional data (e.g. line numbers or caches) 
00061     for an element node which are stored in the element node object during parsing.
00062     """
00063 
00064     def __init__ (self, filePath, absUrl, treeWrapper, elementWrapperClass):
00065         """Constructor for this class
00066         
00067         Input parameter:
00068             filePath:      contains the file path of the corresponding XML file
00069             absUrl:        contains the absolute URL of the corresponding XML file
00070         """
00071         self.filePath            = filePath
00072         self.absUrl              = absUrl
00073         self.baseUrlStack        = [absUrl, ]
00074         self.treeWrapper         = treeWrapper
00075         self.elementWrapperClass = elementWrapperClass
00076 
00077 
00078     def startElementHandler (self, curNode, startLineNumber, curNs, attributes=[]):
00079         """Called by the XML parser at creation of an element node.
00080         
00081         Input parameter:
00082             curNode:          current element node
00083             startLineNumber:  first line number of the element tag in XML file
00084             curNs:            namespaces visible for this element node
00085             attributes:       list of attributes and their values for this element node 
00086                               (same sequence as int he XML file)
00087         """
00088         
00089         elementWrapper              = self.elementWrapperClass(curNode, self.treeWrapper, curNs, initAttrSeq=0)
00090         
00091         elementWrapper.baseUrl = self.__getBaseUrl(elementWrapper)
00092         elementWrapper.absUrl  = self.absUrl
00093         elementWrapper.filePath = self.filePath
00094         elementWrapper.startLineNumber = startLineNumber
00095         elementWrapper.curNs.extend ([("xml", XML_NAMESPACE), ("xmlns", XMLNS_NAMESPACE)])
00096 
00097         if attributes != []:
00098             for i in range (0, len(attributes), 2):
00099                 elementWrapper.attributeSequence.append(attributes[i])
00100         else:
00101             attrList = elementWrapper.getAttributeDict().keys()
00102             attrList.sort()
00103             elementWrapper.attributeSequence.extend (attrList)
00104 
00105         self.baseUrlStack.insert (0, elementWrapper.baseUrl)
00106 
00107 
00108     def endElementHandler (self, curNode, endLineNumber):
00109         """Called by the XML parser after creation of an element node.
00110         
00111         Input parameter:
00112             curNode:          current element node
00113             endLineNumber:    last line number of the element tag in XML file
00114         """
00115         curNode.xmlIfExtElementWrapper.endLineNumber = endLineNumber
00116         self.baseUrlStack.pop (0)
00117 
00118 
00119     def __getBaseUrl (self, elementWrapper):
00120         """Retrieve base URL for the given element node.
00121         
00122         Input parameter:
00123             elementWrapper:    wrapper of current element node
00124         """
00125         nsNameBaseAttr = NsNameTupleFactory ((XML_NAMESPACE, "base"))
00126         if elementWrapper.hasAttribute(nsNameBaseAttr):
00127             return convertToAbsUrl (elementWrapper.getAttribute(nsNameBaseAttr), self.baseUrlStack[0])
00128         else:
00129             return self.baseUrlStack[0]
00130 


mavlink
Author(s): Lorenz Meier
autogenerated on Wed Sep 9 2015 18:06:17