aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/poco/XML/src/NamespaceSupport.cpp
diff options
context:
space:
mode:
authorDevtools Arcadia <arcadia-devtools@yandex-team.ru>2022-02-07 18:08:42 +0300
committerDevtools Arcadia <arcadia-devtools@mous.vla.yp-c.yandex.net>2022-02-07 18:08:42 +0300
commit1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch)
treee26c9fed0de5d9873cce7e00bc214573dc2195b7 /contrib/libs/poco/XML/src/NamespaceSupport.cpp
downloadydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'contrib/libs/poco/XML/src/NamespaceSupport.cpp')
-rw-r--r--contrib/libs/poco/XML/src/NamespaceSupport.cpp187
1 files changed, 187 insertions, 0 deletions
diff --git a/contrib/libs/poco/XML/src/NamespaceSupport.cpp b/contrib/libs/poco/XML/src/NamespaceSupport.cpp
new file mode 100644
index 0000000000..cfc752885f
--- /dev/null
+++ b/contrib/libs/poco/XML/src/NamespaceSupport.cpp
@@ -0,0 +1,187 @@
+//
+// NamespaceSupport.cpp
+//
+// Library: XML
+// Package: SAX
+// Module: SAX
+//
+// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
+// and Contributors.
+//
+// SPDX-License-Identifier: BSL-1.0
+//
+
+
+#include "Poco/SAX/NamespaceSupport.h"
+#include "Poco/XML/Name.h"
+
+
+namespace Poco {
+namespace XML {
+
+
+const XMLString NamespaceSupport::EMPTY_STRING;
+const XMLString NamespaceSupport::XML_NAMESPACE = toXMLString("http://www.w3.org/XML/1998/namespace");
+const XMLString NamespaceSupport::XML_NAMESPACE_PREFIX = toXMLString("xml");
+const XMLString NamespaceSupport::XMLNS_NAMESPACE = toXMLString("http://www.w3.org/xmlns/2000/");
+const XMLString NamespaceSupport::XMLNS_NAMESPACE_PREFIX = toXMLString("xmlns");
+
+
+NamespaceSupport::NamespaceSupport()
+{
+ reset();
+}
+
+
+NamespaceSupport::~NamespaceSupport()
+{
+}
+
+
+bool NamespaceSupport::declarePrefix(const XMLString& prefix, const XMLString& namespaceURI)
+{
+ poco_assert (_contexts.size() > 0);
+
+ Context& ctx = _contexts.back();
+ if (ctx.find(prefix) == ctx.end())
+ {
+ ctx.insert(Context::value_type(prefix, namespaceURI));
+ return true;
+ }
+ else return false;
+}
+
+
+bool NamespaceSupport::undeclarePrefix(const XMLString& prefix)
+{
+ for (ContextVec::reverse_iterator rit = _contexts.rbegin(); rit != _contexts.rend(); ++rit)
+ {
+ Context::iterator it = rit->find(prefix);
+ if (it != rit->end())
+ {
+ rit->erase(it);
+ return true;
+ }
+ }
+ return false;
+}
+
+
+void NamespaceSupport::getDeclaredPrefixes(PrefixSet& prefixes) const
+{
+ prefixes.clear();
+ const Context& ctx = _contexts.back();
+ for (Context::const_iterator it = ctx.begin(); it != ctx.end(); ++it)
+ prefixes.insert(it->first);
+}
+
+
+const XMLString& NamespaceSupport::getPrefix(const XMLString& namespaceURI) const
+{
+ for (ContextVec::const_reverse_iterator rit = _contexts.rbegin(); rit != _contexts.rend(); ++rit)
+ {
+ for (Context::const_iterator it = rit->begin(); it != rit->end(); ++it)
+ {
+ if (it->second == namespaceURI)
+ return it->first;
+ }
+ }
+ return EMPTY_STRING;
+}
+
+
+bool NamespaceSupport::isMapped(const XMLString& namespaceURI) const
+{
+ for (ContextVec::const_reverse_iterator rit = _contexts.rbegin(); rit != _contexts.rend(); ++rit)
+ {
+ for (Context::const_iterator it = rit->begin(); it != rit->end(); ++it)
+ {
+ if (it->second == namespaceURI)
+ return true;
+ }
+ }
+ return false;
+}
+
+
+void NamespaceSupport::getPrefixes(PrefixSet& prefixes) const
+{
+ prefixes.clear();
+ for (ContextVec::const_reverse_iterator rit = _contexts.rbegin(); rit != _contexts.rend(); ++rit)
+ {
+ for (Context::const_iterator it = rit->begin(); it != rit->end(); ++it)
+ {
+ const XMLString& prefix = it->first;
+ if (!prefix.empty() && prefixes.find(prefix) == prefixes.end())
+ prefixes.insert(it->first);
+ }
+ }
+}
+
+
+void NamespaceSupport::getPrefixes(const XMLString& namespaceURI, PrefixSet& prefixes) const
+{
+ prefixes.clear();
+ for (ContextVec::const_reverse_iterator rit = _contexts.rbegin(); rit != _contexts.rend(); ++rit)
+ {
+ for (Context::const_iterator it = rit->begin(); it != rit->end(); ++it)
+ {
+ const XMLString& prefix = it->first;
+ if (it->second == namespaceURI && !prefix.empty() && prefixes.find(prefix) == prefixes.end())
+ prefixes.insert(it->first);
+ }
+ }
+}
+
+
+const XMLString& NamespaceSupport::getURI(const XMLString& prefix) const
+{
+ for (ContextVec::const_reverse_iterator rit = _contexts.rbegin(); rit != _contexts.rend(); ++rit)
+ {
+ Context::const_iterator it = rit->find(prefix);
+ if (it != rit->end())
+ return it->second;
+ }
+ return EMPTY_STRING;
+}
+
+
+void NamespaceSupport::pushContext()
+{
+ _contexts.push_back(Context());
+}
+
+
+void NamespaceSupport::popContext()
+{
+ _contexts.pop_back();
+}
+
+
+bool NamespaceSupport::processName(const XMLString& qname, XMLString& namespaceURI, XMLString& localName, bool isAttribute) const
+{
+ XMLString prefix;
+ Name::split(qname, prefix, localName);
+ if (prefix.empty() && isAttribute)
+ {
+ namespaceURI.clear();
+ return true;
+ }
+ else
+ {
+ namespaceURI = getURI(prefix);
+ return !namespaceURI.empty() || prefix.empty();
+ }
+}
+
+
+void NamespaceSupport::reset()
+{
+ _contexts.clear();
+ pushContext();
+ declarePrefix(XML_NAMESPACE_PREFIX, XML_NAMESPACE);
+ declarePrefix(XMLNS_NAMESPACE_PREFIX, XMLNS_NAMESPACE);
+}
+
+
+} } // namespace Poco::XML