1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_xmloff.hxx"
26 #include <tools/debug.hxx>
27 #include <rtl/ustring.hxx>
28 #include <svl/svarray.hxx>
29 #include <xmloff/xmltkmap.hxx>
30 #include <xmloff/xmltoken.hxx>
31
32 using namespace rtl;
33 using namespace ::xmloff::token;
34
35 class SvXMLTokenMapEntry_Impl
36 {
37 sal_uInt16 nPrefixKey;
38 OUString sLocalName;
39 sal_uInt16 nToken;
40
41 public:
42
GetToken() const43 sal_uInt16 GetToken() const { return nToken; }
44
SvXMLTokenMapEntry_Impl(sal_uInt16 nPrefix,const OUString & rLName,sal_uInt16 nTok=XML_TOK_UNKNOWN)45 SvXMLTokenMapEntry_Impl( sal_uInt16 nPrefix, const OUString& rLName,
46 sal_uInt16 nTok=XML_TOK_UNKNOWN ) :
47 nPrefixKey( nPrefix ),
48 sLocalName( rLName ),
49 nToken( nTok )
50 {}
51
SvXMLTokenMapEntry_Impl(const SvXMLTokenMapEntry & rEntry)52 SvXMLTokenMapEntry_Impl( const SvXMLTokenMapEntry& rEntry ) :
53 nPrefixKey( rEntry.nPrefixKey ),
54 sLocalName( GetXMLToken( rEntry.eLocalName ) ),
55 nToken( rEntry.nToken )
56 {}
57
operator ==(const SvXMLTokenMapEntry_Impl & r) const58 sal_Bool operator==( const SvXMLTokenMapEntry_Impl& r ) const
59 {
60 return nPrefixKey == r.nPrefixKey &&
61 sLocalName == r.sLocalName;
62 }
63
operator <(const SvXMLTokenMapEntry_Impl & r) const64 sal_Bool operator<( const SvXMLTokenMapEntry_Impl& r ) const
65 {
66 return nPrefixKey < r.nPrefixKey ||
67 ( nPrefixKey == r.nPrefixKey &&
68 sLocalName < r.sLocalName);
69 }
70 };
71
72 typedef SvXMLTokenMapEntry_Impl *SvXMLTokenMapEntry_ImplPtr;
73 SV_DECL_PTRARR_SORT_DEL( SvXMLTokenMap_Impl, SvXMLTokenMapEntry_ImplPtr, 5, 5 )
SV_IMPL_OP_PTRARR_SORT(SvXMLTokenMap_Impl,SvXMLTokenMapEntry_ImplPtr)74 SV_IMPL_OP_PTRARR_SORT( SvXMLTokenMap_Impl, SvXMLTokenMapEntry_ImplPtr )
75
76 // ---------------------------------------------------------------------
77
78 SvXMLTokenMapEntry_Impl *SvXMLTokenMap::_Find( sal_uInt16 nKeyPrefix,
79 const OUString& rLName ) const
80 {
81 SvXMLTokenMapEntry_Impl *pRet = 0;
82 SvXMLTokenMapEntry_Impl aTst( nKeyPrefix, rLName );
83
84 sal_uInt16 nPos;
85 if( pImpl->Seek_Entry( &aTst, &nPos ) )
86 {
87 pRet = (*pImpl)[nPos];
88 }
89
90 return pRet;
91 }
92
SvXMLTokenMap(const SvXMLTokenMapEntry * pMap)93 SvXMLTokenMap::SvXMLTokenMap( const SvXMLTokenMapEntry *pMap ) :
94 pImpl( new SvXMLTokenMap_Impl )
95 {
96 while( pMap->eLocalName != XML_TOKEN_INVALID )
97 {
98 pImpl->Insert( new SvXMLTokenMapEntry_Impl( *pMap ) );
99 pMap++;
100 }
101 }
102
~SvXMLTokenMap()103 SvXMLTokenMap::~SvXMLTokenMap()
104 {
105 delete pImpl;
106 }
107
Get(sal_uInt16 nKeyPrefix,const OUString & rLName) const108 sal_uInt16 SvXMLTokenMap::Get( sal_uInt16 nKeyPrefix,
109 const OUString& rLName ) const
110 {
111 SvXMLTokenMapEntry_Impl *pEntry = _Find( nKeyPrefix, rLName );
112 if( pEntry )
113 return pEntry->GetToken();
114 else
115 return XML_TOK_UNKNOWN;
116 }
117
118
119