summaryrefslogtreecommitdiffstats
path: root/include/xmloff/namespacemap.hxx
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:06:44 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:06:44 +0000
commited5640d8b587fbcfed7dd7967f3de04b37a76f26 (patch)
tree7a5f7c6c9d02226d7471cb3cc8fbbf631b415303 /include/xmloff/namespacemap.hxx
parentInitial commit. (diff)
downloadlibreoffice-ed5640d8b587fbcfed7dd7967f3de04b37a76f26.tar.xz
libreoffice-ed5640d8b587fbcfed7dd7967f3de04b37a76f26.zip
Adding upstream version 4:7.4.7.upstream/4%7.4.7upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'include/xmloff/namespacemap.hxx')
-rw-r--r--include/xmloff/namespacemap.hxx164
1 files changed, 164 insertions, 0 deletions
diff --git a/include/xmloff/namespacemap.hxx b/include/xmloff/namespacemap.hxx
new file mode 100644
index 000000000..51e741fb8
--- /dev/null
+++ b/include/xmloff/namespacemap.hxx
@@ -0,0 +1,164 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#ifndef INCLUDED_XMLOFF_NMSPMAP_HXX
+#define INCLUDED_XMLOFF_NMSPMAP_HXX
+
+#include <sal/config.h>
+
+#include <unordered_map>
+#include <utility>
+
+#include <xmloff/dllapi.h>
+#include <sal/types.h>
+#include <rtl/ustring.hxx>
+#include <rtl/ref.hxx>
+#include <salhelper/simplereferenceobject.hxx>
+
+#include <limits.h>
+
+const sal_uInt16 XML_NAMESPACE_XMLNS = USHRT_MAX-2;
+const sal_uInt16 XML_NAMESPACE_NONE = USHRT_MAX-1;
+const sal_uInt16 XML_NAMESPACE_UNKNOWN = USHRT_MAX;
+const sal_uInt16 XML_NAMESPACE_UNKNOWN_FLAG = 0x8000;
+
+class NameSpaceEntry final
+{
+public:
+ // sName refers to the full namespace name
+ OUString sName;
+ // sPrefix is the prefix used to declare a given item to be from a given namespace
+ OUString sPrefix;
+ // nKey is the unique identifier of a namespace
+ sal_uInt16 nKey;
+
+ bool operator==(NameSpaceEntry const & rhs) const
+ {
+ return sName == rhs.sName && sPrefix == rhs.sPrefix && nKey == rhs.nKey;
+ }
+};
+
+class KeyToNameSpaceMapEntry final
+{
+public:
+ // sName refers to the full namespace name
+ OUString sName;
+ // sPrefix is the prefix used to declare a given item to be from a given namespace
+ OUString sPrefix;
+};
+
+typedef ::std::pair < sal_uInt16, OUString > QNamePair;
+
+struct QNamePairHash
+{
+ size_t operator()( const QNamePair &r1 ) const
+ {
+ size_t hash = 17;
+ hash = hash * 37 + r1.first;
+ hash = hash * 37 + r1.second.hashCode();
+ return hash;
+ }
+};
+
+typedef std::unordered_map < QNamePair, OUString, QNamePairHash > QNameCache;
+typedef std::unordered_map < OUString, NameSpaceEntry > NameSpaceHash;
+typedef std::unordered_map < sal_uInt16, KeyToNameSpaceMapEntry > KeyToNameSpaceMap;
+
+class XMLOFF_DLLPUBLIC SvXMLNamespaceMap
+{
+ OUString sXMLNS;
+
+ NameSpaceHash aNameHash;
+ mutable NameSpaceHash aNameCache;
+ KeyToNameSpaceMap maKeyToNamespaceMap;
+ mutable QNameCache aQNameCache;
+ SAL_DLLPRIVATE sal_uInt16 Add_( const OUString& rPrefix, const OUString &rName, sal_uInt16 nKey );
+
+public:
+
+ SvXMLNamespaceMap();
+ ~SvXMLNamespaceMap();
+
+ SvXMLNamespaceMap( const SvXMLNamespaceMap& );
+
+ SvXMLNamespaceMap& operator =( const SvXMLNamespaceMap& rCmp );
+ bool operator ==( const SvXMLNamespaceMap& rCmp ) const;
+
+ sal_uInt16 Add( const OUString& rPrefix,
+ const OUString& rName,
+ sal_uInt16 nKey = XML_NAMESPACE_UNKNOWN );
+ sal_uInt16 AddIfKnown( const OUString& rPrefix,
+ const OUString& rName );
+
+ sal_uInt16 GetKeyByName( const OUString& rName ) const;
+ const OUString& GetNameByKey( sal_uInt16 nKey ) const;
+
+ sal_uInt16 GetKeyByPrefix( const OUString& rPrefix ) const;
+ const OUString& GetPrefixByKey( sal_uInt16 nKey ) const;
+
+ OUString GetQNameByKey( sal_uInt16 nKey,
+ const OUString& rLocalName,
+ bool bCache = true) const;
+
+ OUString GetAttrNameByKey( sal_uInt16 nKey ) const;
+
+ enum class QNameMode { AttrNameCached, AttrValue };
+ sal_uInt16 GetKeyByQName(const OUString& rQName,
+ OUString *pPrefix,
+ OUString *pLocalName,
+ OUString *pNamespace,
+ QNameMode eMode) const;
+
+ sal_uInt16 GetKeyByAttrValueQName(const OUString& rAttrName,
+ OUString *pLocalName) const;
+
+ sal_uInt16 GetFirstKey() const;
+ sal_uInt16 GetNextKey( sal_uInt16 nOldKey ) const;
+
+ /* Give access to all namespace definitions, including multiple entries
+ for the same key (needed for saving sheets separately in Calc).
+ This might be replaced by a better interface later. */
+ const NameSpaceHash& GetAllEntries() const { return aNameHash; }
+
+ void Clear();
+
+ static bool NormalizeOasisURN( OUString& rName );
+ static bool NormalizeW3URI( OUString& rName );
+ static bool NormalizeURI( OUString& rName );
+
+/* deprecated */ void AddAtIndex( const OUString& rPrefix,
+ const OUString& rName, sal_uInt16 nKey );
+/* deprecated */ static sal_uInt16 GetIndexByKey( sal_uInt16 nKey );
+/* deprecated */ sal_uInt16 GetIndexByPrefix( const OUString& rPrefix ) const;
+/* deprecated */ sal_uInt16 GetFirstIndex() const;
+/* deprecated */ sal_uInt16 GetNextIndex( sal_uInt16 nOldIdx ) const;
+/* deprecated */ const OUString& GetPrefixByIndex( sal_uInt16 nIdx ) const;
+/* deprecated */ const OUString& GetNameByIndex( sal_uInt16 nIdx ) const;
+/* deprecated */ OUString GetAttrNameByIndex( sal_uInt16 nIdx ) const;
+ sal_uInt16 GetKeyByAttrName( const OUString& rAttrName,
+ OUString *pPrefix,
+ OUString *pLocalName,
+ OUString *pNamespace ) const;
+/* deprecated */ sal_uInt16 GetKeyByAttrName( const OUString& rAttrName,
+ OUString *pLocalName = nullptr ) const;
+};
+
+#endif // INCLUDED_XMLOFF_NMSPMAP_HXX
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */