Line data Source code
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 : #include <tools/debug.hxx>
21 : #include <xmloff/xmlprhdl.hxx>
22 : #include "xmlbahdl.hxx"
23 : #include <xmloff/xmlprmap.hxx>
24 : #include <xmloff/xmltypes.hxx>
25 : #include <com/sun/star/beans/XPropertySet.hpp>
26 : #include <com/sun/star/beans/XPropertyState.hpp>
27 : #include <com/sun/star/uno/Any.hxx>
28 : #include <xmloff/xmltoken.hxx>
29 :
30 :
31 : using namespace ::std;
32 : using ::rtl::OUString;
33 : using ::rtl::OUStringBuffer;
34 :
35 : using namespace ::com::sun::star::uno;
36 : using namespace ::com::sun::star::beans;
37 : using ::xmloff::token::GetXMLToken;
38 :
39 286758 : XMLPropertySetMapperEntry_Impl::XMLPropertySetMapperEntry_Impl(
40 : const XMLPropertyMapEntry& rMapEntry,
41 : const UniReference< XMLPropertyHandlerFactory >& rFactory ) :
42 286758 : sXMLAttributeName( GetXMLToken(rMapEntry.meXMLName) ),
43 : sAPIPropertyName( OUString(rMapEntry.msApiName, rMapEntry.nApiNameLength,
44 : RTL_TEXTENCODING_ASCII_US ) ),
45 : nXMLNameSpace( rMapEntry.mnNameSpace ),
46 : nType( rMapEntry.mnType ),
47 : nContextId( rMapEntry.mnContextId ),
48 : nEarliestODFVersionForExport( rMapEntry.mnEarliestODFVersionForExport ),
49 286758 : pHdl( rFactory->GetPropertyHandler( rMapEntry.mnType & MID_FLAG_MASK ) )
50 : {
51 286758 : }
52 :
53 952973 : XMLPropertySetMapperEntry_Impl::XMLPropertySetMapperEntry_Impl(
54 : const XMLPropertySetMapperEntry_Impl& rEntry ) :
55 : sXMLAttributeName( rEntry.sXMLAttributeName),
56 : sAPIPropertyName( rEntry.sAPIPropertyName),
57 : nXMLNameSpace( rEntry.nXMLNameSpace),
58 : nType( rEntry.nType),
59 : nContextId( rEntry.nContextId),
60 : nEarliestODFVersionForExport( rEntry.nEarliestODFVersionForExport ),
61 952973 : pHdl( rEntry.pHdl)
62 : {
63 : DBG_ASSERT( pHdl, "Unknown XML property type handler!" );
64 952973 : }
65 :
66 : ///////////////////////////////////////////////////////////////////////////
67 : //
68 : // Ctor
69 : //
70 4315 : XMLPropertySetMapper::XMLPropertySetMapper(
71 : const XMLPropertyMapEntry* pEntries,
72 4315 : const UniReference< XMLPropertyHandlerFactory >& rFactory )
73 : {
74 4315 : aHdlFactories.push_back( rFactory );
75 4315 : if( pEntries )
76 : {
77 4315 : const XMLPropertyMapEntry* pIter = pEntries;
78 :
79 : // count entries
80 295388 : while( pIter->msApiName )
81 : {
82 286758 : XMLPropertySetMapperEntry_Impl aEntry( *pIter, rFactory );
83 286758 : aMapEntries.push_back( aEntry );
84 286758 : pIter++;
85 286758 : }
86 : }
87 4315 : }
88 :
89 5705 : XMLPropertySetMapper::~XMLPropertySetMapper()
90 : {
91 5705 : }
92 :
93 870 : void XMLPropertySetMapper::AddMapperEntry(
94 : const UniReference < XMLPropertySetMapper >& rMapper )
95 : {
96 5874 : for( vector < UniReference < XMLPropertyHandlerFactory > >::iterator
97 870 : aFIter = rMapper->aHdlFactories.begin();
98 3916 : aFIter != rMapper->aHdlFactories.end();
99 : ++aFIter )
100 : {
101 1088 : aHdlFactories.push_back( *aFIter );
102 : }
103 :
104 284808 : for( vector < XMLPropertySetMapperEntry_Impl >::iterator
105 870 : aEIter = rMapper->aMapEntries.begin();
106 189872 : aEIter != rMapper->aMapEntries.end();
107 : ++aEIter )
108 : {
109 94066 : aMapEntries.push_back( *aEIter );
110 : }
111 870 : }
112 :
113 : ///////////////////////////////////////////////////////////////////////////
114 : //
115 : // Export a Property
116 : //
117 848 : sal_Bool XMLPropertySetMapper::exportXML(
118 : OUString& rStrExpValue,
119 : const XMLPropertyState& rProperty,
120 : const SvXMLUnitConverter& rUnitConverter ) const
121 : {
122 848 : sal_Bool bRet = sal_False;
123 :
124 848 : const XMLPropertyHandler* pHdl = GetPropertyHandler( rProperty.mnIndex );
125 :
126 : DBG_ASSERT( pHdl, "Unknown XML Type!" );
127 848 : if( pHdl )
128 : bRet = pHdl->exportXML( rStrExpValue, rProperty.maValue,
129 848 : rUnitConverter );
130 :
131 848 : return bRet;
132 : }
133 :
134 : ///////////////////////////////////////////////////////////////////////////
135 : //
136 : // Import a Property
137 : //
138 14200 : sal_Bool XMLPropertySetMapper::importXML(
139 : const OUString& rStrImpValue,
140 : XMLPropertyState& rProperty,
141 : const SvXMLUnitConverter& rUnitConverter ) const
142 : {
143 14200 : sal_Bool bRet = sal_False;
144 :
145 14200 : const XMLPropertyHandler* pHdl = GetPropertyHandler( rProperty.mnIndex );
146 :
147 14200 : if( pHdl )
148 : bRet = pHdl->importXML( rStrImpValue, rProperty.maValue,
149 14200 : rUnitConverter );
150 :
151 14200 : return bRet;
152 : }
153 :
154 : ///////////////////////////////////////////////////////////////////////////
155 : //
156 : // Search for the given name and the namespace in the list and return
157 : // the index of the entry
158 : // If there is no matching entry the method returns -1
159 : //
160 16442 : sal_Int32 XMLPropertySetMapper::GetEntryIndex(
161 : sal_uInt16 nNamespace,
162 : const OUString& rStrName,
163 : sal_uInt32 nPropType,
164 : sal_Int32 nStartAt /* = -1 */ ) const
165 : {
166 16442 : sal_Int32 nEntries = GetEntryCount();
167 16442 : sal_Int32 nIndex= nStartAt == - 1? 0 : nStartAt+1;
168 :
169 16442 : if ( nEntries )
170 : {
171 1055305 : do
172 : {
173 1070557 : const XMLPropertySetMapperEntry_Impl& rEntry = aMapEntries[nIndex];
174 1313312 : if( (!nPropType || nPropType == rEntry.GetPropType()) &&
175 : rEntry.nXMLNameSpace == nNamespace &&
176 242755 : rStrName == rEntry.sXMLAttributeName )
177 15252 : return nIndex;
178 : else
179 1055305 : nIndex++;
180 :
181 : } while( nIndex<nEntries );
182 : }
183 :
184 1190 : return -1;
185 : }
186 :
187 :
188 : /** searches for an entry that matches the given api name, namespace and local name or -1 if nothing found */
189 20 : sal_Int32 XMLPropertySetMapper::FindEntryIndex(
190 : const sal_Char* sApiName,
191 : sal_uInt16 nNameSpace,
192 : const OUString& sXMLName ) const
193 : {
194 20 : sal_Int32 nIndex = 0;
195 20 : sal_Int32 nEntries = GetEntryCount();
196 :
197 1284 : do
198 : {
199 1304 : const XMLPropertySetMapperEntry_Impl& rEntry = aMapEntries[nIndex];
200 2340 : if( rEntry.nXMLNameSpace == nNameSpace &&
201 1000 : rEntry.sXMLAttributeName.equals( sXMLName ) &&
202 36 : 0 == rEntry.sAPIPropertyName.compareToAscii( sApiName ) )
203 20 : return nIndex;
204 : else
205 1284 : nIndex++;
206 :
207 : } while( nIndex < nEntries );
208 :
209 0 : return -1;
210 : }
211 :
212 858 : sal_Int32 XMLPropertySetMapper::FindEntryIndex( const sal_Int16 nContextId ) const
213 : {
214 858 : const sal_Int32 nEntries = GetEntryCount();
215 :
216 858 : if ( nEntries )
217 : {
218 858 : sal_Int32 nIndex = 0;
219 34986 : do
220 : {
221 35844 : const XMLPropertySetMapperEntry_Impl& rEntry = aMapEntries[nIndex];
222 35844 : if( rEntry.nContextId == nContextId )
223 858 : return nIndex;
224 : else
225 34986 : nIndex++;
226 :
227 : } while( nIndex < nEntries );
228 : }
229 :
230 0 : return -1;
231 : }
232 :
233 0 : void XMLPropertySetMapper::RemoveEntry( sal_Int32 nIndex )
234 : {
235 0 : const sal_Int32 nEntries = GetEntryCount();
236 0 : if( nIndex>=nEntries || nIndex<0 )
237 0 : return;
238 0 : vector < XMLPropertySetMapperEntry_Impl >::iterator aEIter = aMapEntries.begin();
239 0 : for( sal_Int32 nN=0; nN<nIndex; nN++ )
240 0 : ++aEIter;
241 0 : aMapEntries.erase( aEIter );
242 : }
243 :
244 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|