Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #ifndef _XMLOFF_NMSPMAP_HXX
30 : : #define _XMLOFF_NMSPMAP_HXX
31 : :
32 : : #include "sal/config.h"
33 : :
34 : : #include <map>
35 : : #include <utility>
36 : :
37 : : #include "xmloff/dllapi.h"
38 : : #include "sal/types.h"
39 : : #include <rtl/ustring.hxx>
40 : : #include <boost/unordered_map.hpp>
41 : : #include <rtl/ref.hxx>
42 : : #include <cppuhelper/weak.hxx>
43 : :
44 : : #include <limits.h>
45 : :
46 : : const sal_uInt16 XML_NAMESPACE_XMLNS = (USHRT_MAX-2);
47 : : const sal_uInt16 XML_NAMESPACE_NONE = (USHRT_MAX-1);
48 : : const sal_uInt16 XML_NAMESPACE_UNKNOWN = (USHRT_MAX);
49 : : const sal_uInt16 XML_NAMESPACE_UNKNOWN_FLAG = 0x8000;
50 : :
51 : : class NameSpaceEntry : public cppu::OWeakObject
52 : : {
53 : : public:
54 : : // sName refers to the full namespace name
55 : : ::rtl::OUString sName;
56 : : // sPrefix is the prefix used to declare a given item to be from a given namespace
57 : : ::rtl::OUString sPrefix;
58 : : // nKey is the unique identifier of a namespace
59 : : sal_uInt16 nKey;
60 : : };
61 : :
62 : : struct OUStringEqFunc
63 : : {
64 : 0 : sal_Bool operator()( const rtl::OUString &r1,
65 : : const rtl::OUString &r2) const
66 : : {
67 : 0 : return r1 == r2;
68 : : }
69 : : };
70 : :
71 : : struct uInt32lt
72 : : {
73 : : sal_Bool operator()( const sal_uInt32 &r1,
74 : : const sal_uInt32 &r2) const
75 : : {
76 : : return r1 < r2;
77 : : }
78 : : };
79 : : typedef ::std::pair < sal_uInt16, rtl::OUString > QNamePair;
80 : :
81 : : struct QNamePairHash
82 : : {
83 : : size_t operator()( const QNamePair &r1 ) const
84 : : {
85 : : return (size_t) r1.second.hashCode() + r1.first;
86 : : }
87 : : };
88 : :
89 : : typedef ::boost::unordered_map < QNamePair, ::rtl::OUString, QNamePairHash > QNameCache;
90 : : typedef ::boost::unordered_map < ::rtl::OUString, ::rtl::Reference <NameSpaceEntry >, rtl::OUStringHash, OUStringEqFunc > NameSpaceHash;
91 : : typedef ::std::map < sal_uInt16, ::rtl::Reference < NameSpaceEntry >, uInt32lt > NameSpaceMap;
92 : :
93 : : class XMLOFF_DLLPUBLIC SvXMLNamespaceMap
94 : : {
95 : : const ::rtl::OUString sXMLNS;
96 : : const ::rtl::OUString sEmpty;
97 : :
98 : : NameSpaceHash aNameHash;
99 : : mutable NameSpaceHash aNameCache;
100 : : NameSpaceMap aNameMap;
101 : : mutable QNameCache aQNameCache;
102 : : SAL_DLLPRIVATE sal_uInt16 _Add( const rtl::OUString& rPrefix, const rtl::OUString &rName, sal_uInt16 nKey );
103 : :
104 : : public:
105 : :
106 : : SvXMLNamespaceMap();
107 : : ~SvXMLNamespaceMap();
108 : :
109 : : SvXMLNamespaceMap( const SvXMLNamespaceMap& );
110 : :
111 : : void operator =( const SvXMLNamespaceMap& rCmp );
112 : : int operator ==( const SvXMLNamespaceMap& rCmp ) const;
113 : :
114 : : sal_uInt16 Add( const ::rtl::OUString& rPrefix,
115 : : const ::rtl::OUString& rName,
116 : : sal_uInt16 nKey = XML_NAMESPACE_UNKNOWN );
117 : : sal_uInt16 AddIfKnown( const ::rtl::OUString& rPrefix,
118 : : const ::rtl::OUString& rName );
119 : :
120 : : sal_uInt16 GetKeyByName( const ::rtl::OUString& rName ) const;
121 : : const ::rtl::OUString& GetNameByKey( sal_uInt16 nKey ) const;
122 : :
123 : : sal_uInt16 GetKeyByPrefix( const ::rtl::OUString& rPrefix ) const;
124 : : const ::rtl::OUString& GetPrefixByKey( sal_uInt16 nKey ) const;
125 : :
126 : : ::rtl::OUString GetQNameByKey( sal_uInt16 nKey,
127 : : const ::rtl::OUString& rLocalName,
128 : : sal_Bool bCache = sal_True) const;
129 : :
130 : : ::rtl::OUString GetAttrNameByKey( sal_uInt16 nKey ) const;
131 : :
132 : : /* This will replace the version with the unused 5th default parameter */
133 : : sal_uInt16 _GetKeyByAttrName( const ::rtl::OUString& rAttrName,
134 : : ::rtl::OUString *pPrefix,
135 : : ::rtl::OUString *pLocalName,
136 : : ::rtl::OUString *pNamespace = 0,
137 : : sal_Bool bCache = sal_True) const;
138 : :
139 : : /* This will replace the version with the unused 3rd default parameter */
140 : : sal_uInt16 _GetKeyByAttrName( const ::rtl::OUString& rAttrName,
141 : : ::rtl::OUString *pLocalName = 0,
142 : : sal_Bool bCache = sal_True) const;
143 : :
144 : : sal_uInt16 GetFirstKey() const;
145 : : sal_uInt16 GetNextKey( sal_uInt16 nOldKey ) const;
146 : :
147 : : /* Give access to all namespace definitions, including multiple entries
148 : : for the same key (needed for saving sheets separately in Calc).
149 : : This might be replaced by a better interface later. */
150 : 186 : const NameSpaceHash& GetAllEntries() const { return aNameHash; }
151 : :
152 : : static sal_Bool NormalizeOasisURN( ::rtl::OUString& rName );
153 : : static sal_Bool NormalizeW3URI( ::rtl::OUString& rName );
154 : : static sal_Bool NormalizeURI( ::rtl::OUString& rName );
155 : :
156 : : /* deprecated */ sal_Bool AddAtIndex( sal_uInt16 nIdx, const ::rtl::OUString& rPrefix,
157 : : const ::rtl::OUString& rName, sal_uInt16 nKey = XML_NAMESPACE_UNKNOWN );
158 : : /* deprecated */ sal_uInt16 GetIndexByKey( sal_uInt16 nKey ) const;
159 : : /* deprecated */ sal_uInt16 GetIndexByPrefix( const ::rtl::OUString& rPrefix ) const;
160 : : /* deprecated */ sal_uInt16 GetFirstIndex() const;
161 : : /* deprecated */ sal_uInt16 GetNextIndex( sal_uInt16 nOldIdx ) const;
162 : : /* deprecated */ const ::rtl::OUString& GetPrefixByIndex( sal_uInt16 nIdx ) const;
163 : : /* deprecated */ const ::rtl::OUString& GetNameByIndex( sal_uInt16 nIdx ) const;
164 : : /* deprecated */ ::rtl::OUString GetAttrNameByIndex( sal_uInt16 nIdx ) const;
165 : : /* deprecated */ ::rtl::OUString GetQNameByIndex( sal_uInt16 nIdx,
166 : : const ::rtl::OUString& rLocalName ) const;
167 : : /* deprecated */ sal_uInt16 GetKeyByAttrName( const ::rtl::OUString& rAttrName,
168 : : ::rtl::OUString *pPrefix,
169 : : ::rtl::OUString *pLocalName,
170 : : ::rtl::OUString *pNamespace=0,
171 : : sal_uInt16 nIdxGuess = USHRT_MAX ) const;
172 : : /* deprecated */ sal_uInt16 GetKeyByAttrName( const ::rtl::OUString& rAttrName,
173 : : ::rtl::OUString *pLocalName = 0,
174 : : sal_uInt16 nIdxGuess = USHRT_MAX ) const;
175 : : };
176 : :
177 : : #endif // _XMLOFF_NMSPMAP_HXX
178 : :
179 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|