LibreOffice Module xmloff (master) 1
namespacemap.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#ifndef INCLUDED_XMLOFF_NMSPMAP_HXX
21#define INCLUDED_XMLOFF_NMSPMAP_HXX
22
23#include <sal/config.h>
24
25#include <unordered_map>
26#include <utility>
27
28#include <xmloff/dllapi.h>
29#include <sal/types.h>
30#include <rtl/ustring.hxx>
31#include <rtl/ref.hxx>
33
34#include <limits.h>
35
36const sal_uInt16 XML_NAMESPACE_XMLNS = USHRT_MAX-2;
37const sal_uInt16 XML_NAMESPACE_NONE = USHRT_MAX-1;
38const sal_uInt16 XML_NAMESPACE_UNKNOWN = USHRT_MAX;
39const sal_uInt16 XML_NAMESPACE_UNKNOWN_FLAG = 0x8000;
40
41class NameSpaceEntry final
42{
43public:
44 // sName refers to the full namespace name
45 OUString sName;
46 // sPrefix is the prefix used to declare a given item to be from a given namespace
47 OUString sPrefix;
48 // nKey is the unique identifier of a namespace
49 sal_uInt16 nKey;
50
51 bool operator==(NameSpaceEntry const & rhs) const
52 {
53 return sName == rhs.sName && sPrefix == rhs.sPrefix && nKey == rhs.nKey;
54 }
55};
56
58{
59public:
60 // sName refers to the full namespace name
61 OUString sName;
62 // sPrefix is the prefix used to declare a given item to be from a given namespace
63 OUString sPrefix;
64};
65
66typedef ::std::pair < sal_uInt16, OUString > QNamePair;
67
69{
70 size_t operator()( const QNamePair &r1 ) const
71 {
72 size_t hash = 17;
73 hash = hash * 37 + r1.first;
74 hash = hash * 37 + r1.second.hashCode();
75 return hash;
76 }
77};
78
79typedef std::unordered_map < QNamePair, OUString, QNamePairHash > QNameCache;
80typedef std::unordered_map < OUString, NameSpaceEntry > NameSpaceHash;
81typedef std::unordered_map < sal_uInt16, KeyToNameSpaceMapEntry > KeyToNameSpaceMap;
82
84{
85 OUString sXMLNS;
86
91 SAL_DLLPRIVATE sal_uInt16 Add_( const OUString& rPrefix, const OUString &rName, sal_uInt16 nKey );
92
93public:
94
97
99
100 SvXMLNamespaceMap& operator =( const SvXMLNamespaceMap& rCmp );
101 bool operator ==( const SvXMLNamespaceMap& rCmp ) const;
102
103 sal_uInt16 Add( const OUString& rPrefix,
104 const OUString& rName,
105 sal_uInt16 nKey = XML_NAMESPACE_UNKNOWN );
106 sal_uInt16 AddIfKnown( const OUString& rPrefix,
107 const OUString& rName );
108
109 sal_uInt16 GetKeyByName( const OUString& rName ) const;
110 const OUString& GetNameByKey( sal_uInt16 nKey ) const;
111
112 sal_uInt16 GetKeyByPrefix( const OUString& rPrefix ) const;
113 const OUString& GetPrefixByKey( sal_uInt16 nKey ) const;
114
115 OUString GetQNameByKey( sal_uInt16 nKey,
116 const OUString& rLocalName,
117 bool bCache = true) const;
118
119 OUString GetAttrNameByKey( sal_uInt16 nKey ) const;
120
121 enum class QNameMode { AttrNameCached, AttrValue };
122 sal_uInt16 GetKeyByQName(const OUString& rQName,
123 OUString *pPrefix,
124 OUString *pLocalName,
125 OUString *pNamespace,
126 QNameMode eMode) const;
127
128 sal_uInt16 GetKeyByAttrValueQName(const OUString& rAttrName,
129 OUString *pLocalName) const;
130
131 sal_uInt16 GetFirstKey() const;
132 sal_uInt16 GetNextKey( sal_uInt16 nOldKey ) const;
133
134 /* Give access to all namespace definitions, including multiple entries
135 for the same key (needed for saving sheets separately in Calc).
136 This might be replaced by a better interface later. */
137 const NameSpaceHash& GetAllEntries() const { return aNameHash; }
138
139 void Clear();
140
141 static bool NormalizeOasisURN( OUString& rName );
142 static bool NormalizeW3URI( OUString& rName );
143 static bool NormalizeURI( OUString& rName );
144
145/* deprecated */ void AddAtIndex( const OUString& rPrefix,
146 const OUString& rName, sal_uInt16 nKey );
147/* deprecated */ static sal_uInt16 GetIndexByKey( sal_uInt16 nKey );
148/* deprecated */ sal_uInt16 GetIndexByPrefix( const OUString& rPrefix ) const;
149/* deprecated */ sal_uInt16 GetFirstIndex() const;
150/* deprecated */ sal_uInt16 GetNextIndex( sal_uInt16 nOldIdx ) const;
151/* deprecated */ const OUString& GetPrefixByIndex( sal_uInt16 nIdx ) const;
152/* deprecated */ const OUString& GetNameByIndex( sal_uInt16 nIdx ) const;
153/* deprecated */ OUString GetAttrNameByIndex( sal_uInt16 nIdx ) const;
154 sal_uInt16 GetKeyByAttrName( const OUString& rAttrName,
155 OUString *pPrefix,
156 OUString *pLocalName,
157 OUString *pNamespace ) const;
158/* deprecated */ sal_uInt16 GetKeyByAttrName( const OUString& rAttrName,
159 OUString *pLocalName = nullptr ) const;
160};
161
162#endif // INCLUDED_XMLOFF_NMSPMAP_HXX
163
164/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
OUString sPrefix
bool operator==(NameSpaceEntry const &rhs) const
sal_uInt16 nKey
QNameCache aQNameCache
NameSpaceHash aNameHash
NameSpaceHash aNameCache
KeyToNameSpaceMap maKeyToNamespaceMap
const NameSpaceHash & GetAllEntries() const
#define XMLOFF_DLLPUBLIC
Definition: dllapi.h:29
void Clear(EHistoryType eHistory)
const sal_uInt16 XML_NAMESPACE_UNKNOWN_FLAG
::std::pair< sal_uInt16, OUString > QNamePair
std::unordered_map< sal_uInt16, KeyToNameSpaceMapEntry > KeyToNameSpaceMap
const sal_uInt16 XML_NAMESPACE_NONE
std::unordered_map< OUString, NameSpaceEntry > NameSpaceHash
const sal_uInt16 XML_NAMESPACE_UNKNOWN
const sal_uInt16 XML_NAMESPACE_XMLNS
std::unordered_map< QNamePair, OUString, QNamePairHash > QNameCache
bool operator==(const AttributeDescription &i_lhs, const AttributeDescription &i_rhs)
size_t operator()(const QNamePair &r1) const