From dc9029c0c058f65f81e405e2f86b0df1ad7da850 Mon Sep 17 00:00:00 2001 From: Scott Cantor Date: Thu, 29 Mar 2012 21:14:19 +0000 Subject: [PATCH] Add xml:lang support to XMLObject --- .../AbstractAttributeExtensibleXMLObject.cpp | 7 +++ xmltooling/AbstractAttributeExtensibleXMLObject.h | 1 + xmltooling/AbstractXMLObject.cpp | 55 ++++++++++++---------- xmltooling/XMLObject.h | 7 +++ 4 files changed, 45 insertions(+), 25 deletions(-) diff --git a/xmltooling/AbstractAttributeExtensibleXMLObject.cpp b/xmltooling/AbstractAttributeExtensibleXMLObject.cpp index a89d8a1..166e96c 100644 --- a/xmltooling/AbstractAttributeExtensibleXMLObject.cpp +++ b/xmltooling/AbstractAttributeExtensibleXMLObject.cpp @@ -135,6 +135,13 @@ const XMLCh* AbstractAttributeExtensibleXMLObject::getAttribute(const xmltooling return (i != m_attributeMap.end()) ? i->second : nullptr; } +const XMLCh* AbstractAttributeExtensibleXMLObject::getLang() const +{ + static const XMLCh _lang[] = UNICODE_LITERAL_4(l,a,n,g); + static xmltooling::QName qname(xmlconstants::XML_NS, _lang); + return getAttribute(qname); +} + void AbstractAttributeExtensibleXMLObject::setAttribute(const xmltooling::QName& qualifiedName, const XMLCh* value, bool ID) { map::iterator i=m_attributeMap.find(qualifiedName); diff --git a/xmltooling/AbstractAttributeExtensibleXMLObject.h b/xmltooling/AbstractAttributeExtensibleXMLObject.h index c09d711..3881dee 100644 --- a/xmltooling/AbstractAttributeExtensibleXMLObject.h +++ b/xmltooling/AbstractAttributeExtensibleXMLObject.h @@ -54,6 +54,7 @@ namespace xmltooling { void setAttribute(const QName& qualifiedName, const XMLCh* value, bool ID=false); const std::map& getExtensionAttributes() const; const XMLCh* getXMLID() const; + const XMLCh* getLang() const; protected: AbstractAttributeExtensibleXMLObject(); diff --git a/xmltooling/AbstractXMLObject.cpp b/xmltooling/AbstractXMLObject.cpp index cb2d7f4..4ba5d7c 100644 --- a/xmltooling/AbstractXMLObject.cpp +++ b/xmltooling/AbstractXMLObject.cpp @@ -56,6 +56,36 @@ void XMLObject::releaseThisAndChildrenDOM() const releaseDOM(); } +const XMLCh* XMLObject::getLang() const +{ + return nullptr; +} + +void XMLObject::setNil(const XMLCh* value) +{ + if (value) { + switch (*value) { + case xercesc::chLatin_t: + nil(xmlconstants::XML_BOOL_TRUE); + break; + case xercesc::chLatin_f: + nil(xmlconstants::XML_BOOL_FALSE); + break; + case xercesc::chDigit_1: + nil(xmlconstants::XML_BOOL_ONE); + break; + case xercesc::chDigit_0: + nil(xmlconstants::XML_BOOL_ZERO); + break; + default: + nil(xmlconstants::XML_BOOL_NULL); + } + } + else { + nil(xmlconstants::XML_BOOL_NULL); + } +} + AbstractXMLObject::AbstractXMLObject(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const QName* schemaType) : m_log(logging::Category::getInstance(XMLTOOLING_LOGCAT".XMLObject")), m_schemaLocation(nullptr), m_noNamespaceSchemaLocation(nullptr), m_nil(xmlconstants::XML_BOOL_NULL), @@ -105,31 +135,6 @@ const set& AbstractXMLObject::getNamespaces() const return m_namespaces; } -void XMLObject::setNil(const XMLCh* value) -{ - if (value) { - switch (*value) { - case xercesc::chLatin_t: - nil(xmlconstants::XML_BOOL_TRUE); - break; - case xercesc::chLatin_f: - nil(xmlconstants::XML_BOOL_FALSE); - break; - case xercesc::chDigit_1: - nil(xmlconstants::XML_BOOL_ONE); - break; - case xercesc::chDigit_0: - nil(xmlconstants::XML_BOOL_ZERO); - break; - default: - nil(xmlconstants::XML_BOOL_NULL); - } - } - else { - nil(xmlconstants::XML_BOOL_NULL); - } -} - void AbstractXMLObject::addNamespace(const Namespace& ns) const { for (set::const_iterator n = m_namespaces.begin(); n != m_namespaces.end(); ++n) { diff --git a/xmltooling/XMLObject.h b/xmltooling/XMLObject.h index e0391ad..8ebb607 100644 --- a/xmltooling/XMLObject.h +++ b/xmltooling/XMLObject.h @@ -131,6 +131,13 @@ namespace xmltooling { virtual const XMLCh* getXMLID() const=0; /** + * Returns the xml:lang property of the object, if any. + * + * @return an xml:lang value, or nullptr + */ + virtual const XMLCh* getLang() const; + + /** * Returns the xsi:nil property of the object, or false if not set. * * @return the xsi:nil property -- 2.1.4