LibreOffice Module xmloff (master)  1
nmspmap.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 
36 const sal_uInt16 XML_NAMESPACE_XMLNS = USHRT_MAX-2;
37 const sal_uInt16 XML_NAMESPACE_NONE = USHRT_MAX-1;
38 const sal_uInt16 XML_NAMESPACE_UNKNOWN = USHRT_MAX;
39 const sal_uInt16 XML_NAMESPACE_UNKNOWN_FLAG = 0x8000;
40 
42 {
43 public:
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 
52 typedef ::std::pair < sal_uInt16, OUString > QNamePair;
53 
55 {
56  size_t operator()( const QNamePair &r1 ) const
57  {
58  size_t hash = 17;
59  hash = hash * 37 + r1.first;
60  hash = hash * 37 + r1.second.hashCode();
61  return hash;
62  }
63 };
64 
65 typedef std::unordered_map < QNamePair, OUString, QNamePairHash > QNameCache;
66 typedef std::unordered_map < OUString, ::rtl::Reference <NameSpaceEntry > > NameSpaceHash;
67 typedef std::unordered_map < sal_uInt16, ::rtl::Reference < NameSpaceEntry > > NameSpaceMap;
68 
70 {
71  OUString sXMLNS;
72 
77  SAL_DLLPRIVATE sal_uInt16 Add_( const OUString& rPrefix, const OUString &rName, sal_uInt16 nKey );
78 
79 public:
80 
83 
85 
86  SvXMLNamespaceMap& operator =( const SvXMLNamespaceMap& rCmp );
87  bool operator ==( const SvXMLNamespaceMap& rCmp ) const;
88 
89  sal_uInt16 Add( const OUString& rPrefix,
90  const OUString& rName,
91  sal_uInt16 nKey = XML_NAMESPACE_UNKNOWN );
92  sal_uInt16 AddIfKnown( const OUString& rPrefix,
93  const OUString& rName );
94 
95  sal_uInt16 GetKeyByName( const OUString& rName ) const;
96  const OUString& GetNameByKey( sal_uInt16 nKey ) const;
97 
98  sal_uInt16 GetKeyByPrefix( const OUString& rPrefix ) const;
99  const OUString& GetPrefixByKey( sal_uInt16 nKey ) const;
100 
101  OUString GetQNameByKey( sal_uInt16 nKey,
102  const OUString& rLocalName,
103  bool bCache = true) const;
104 
105  OUString GetAttrNameByKey( sal_uInt16 nKey ) const;
106 
107  enum class QNameMode { AttrNameCached, AttrValue };
108  sal_uInt16 GetKeyByQName(const OUString& rQName,
109  OUString *pPrefix,
110  OUString *pLocalName,
111  OUString *pNamespace,
112  QNameMode eMode) const;
113 
114  sal_uInt16 GetKeyByAttrValueQName(const OUString& rAttrName,
115  OUString *pLocalName) const;
116 
117  sal_uInt16 GetFirstKey() const;
118  sal_uInt16 GetNextKey( sal_uInt16 nOldKey ) const;
119 
120  /* Give access to all namespace definitions, including multiple entries
121  for the same key (needed for saving sheets separately in Calc).
122  This might be replaced by a better interface later. */
123  const NameSpaceHash& GetAllEntries() const { return aNameHash; }
124 
125  static bool NormalizeOasisURN( OUString& rName );
126  static bool NormalizeW3URI( OUString& rName );
127  static bool NormalizeURI( OUString& rName );
128 
129 /* deprecated */ void AddAtIndex( const OUString& rPrefix,
130  const OUString& rName, sal_uInt16 nKey );
131 /* deprecated */ static sal_uInt16 GetIndexByKey( sal_uInt16 nKey );
132 /* deprecated */ sal_uInt16 GetIndexByPrefix( const OUString& rPrefix ) const;
133 /* deprecated */ sal_uInt16 GetFirstIndex() const;
134 /* deprecated */ sal_uInt16 GetNextIndex( sal_uInt16 nOldIdx ) const;
135 /* deprecated */ const OUString& GetPrefixByIndex( sal_uInt16 nIdx ) const;
136 /* deprecated */ const OUString& GetNameByIndex( sal_uInt16 nIdx ) const;
137 /* deprecated */ OUString GetAttrNameByIndex( sal_uInt16 nIdx ) const;
138 /* deprecated */ OUString GetQNameByIndex( sal_uInt16 nIdx,
139  const OUString& rLocalName ) const;
140  sal_uInt16 GetKeyByAttrName( const OUString& rAttrName,
141  OUString *pPrefix,
142  OUString *pLocalName,
143  OUString *pNamespace ) const;
144 /* deprecated */ sal_uInt16 GetKeyByAttrName( const OUString& rAttrName,
145  OUString *pLocalName = nullptr ) const;
146 };
147 
148 #endif // INCLUDED_XMLOFF_NMSPMAP_HXX
149 
150 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
OUString sXMLNS
Definition: nmspmap.hxx:71
const sal_uInt16 XML_NAMESPACE_XMLNS
Definition: nmspmap.hxx:36
std::unordered_map< OUString,::rtl::Reference< NameSpaceEntry > > NameSpaceHash
Definition: nmspmap.hxx:66
::std::pair< sal_uInt16, OUString > QNamePair
Definition: nmspmap.hxx:52
const NameSpaceHash & GetAllEntries() const
Definition: nmspmap.hxx:123
NameSpaceHash aNameCache
Definition: nmspmap.hxx:74
const sal_uInt16 XML_NAMESPACE_NONE
Definition: nmspmap.hxx:37
const sal_uInt16 XML_NAMESPACE_UNKNOWN
Definition: nmspmap.hxx:38
std::unordered_map< QNamePair, OUString, QNamePairHash > QNameCache
Definition: nmspmap.hxx:65
OUString sPrefix
Definition: nmspmap.hxx:47
const sal_uInt16 XML_NAMESPACE_UNKNOWN_FLAG
Definition: nmspmap.hxx:39
size_t operator()(const QNamePair &r1) const
Definition: nmspmap.hxx:56
sal_uInt16 nKey
Definition: nmspmap.hxx:49
QNameCache aQNameCache
Definition: nmspmap.hxx:76
std::unordered_map< sal_uInt16,::rtl::Reference< NameSpaceEntry > > NameSpaceMap
Definition: nmspmap.hxx:67
NameSpaceHash aNameHash
Definition: nmspmap.hxx:73
const o3tl::enumarray< SvxAdjust, unsigned short > aSvxToUnoAdjust USHRT_MAX
OUString sName
Definition: nmspmap.hxx:45
#define XMLOFF_DLLPUBLIC
Definition: dllapi.h:29
bool operator==(const AttributeDescription &i_lhs, const AttributeDescription &i_rhs)
NameSpaceMap aNameMap
Definition: nmspmap.hxx:75