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 116482 : XMLPropertySetMapperEntry_Impl::XMLPropertySetMapperEntry_Impl(
40 : const XMLPropertyMapEntry& rMapEntry,
41 : const UniReference< XMLPropertyHandlerFactory >& rFactory ) :
42 116482 : 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 116482 : pHdl( rFactory->GetPropertyHandler( rMapEntry.mnType & MID_FLAG_MASK ) )
50 : {
51 116482 : }
52 :
53 388488 : 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 388488 : pHdl( rEntry.pHdl)
62 : {
63 : DBG_ASSERT( pHdl, "Unknown XML property type handler!" );
64 388488 : }
65 :
66 : ///////////////////////////////////////////////////////////////////////////
67 : //
68 : // Ctor
69 : //
70 1716 : XMLPropertySetMapper::XMLPropertySetMapper(
71 : const XMLPropertyMapEntry* pEntries,
72 1716 : const UniReference< XMLPropertyHandlerFactory >& rFactory )
73 : {
74 1716 : aHdlFactories.push_back( rFactory );
75 1716 : if( pEntries )
76 : {
77 1716 : const XMLPropertyMapEntry* pIter = pEntries;
78 :
79 : // count entries
80 119914 : while( pIter->msApiName )
81 : {
82 116482 : XMLPropertySetMapperEntry_Impl aEntry( *pIter, rFactory );
83 116482 : aMapEntries.push_back( aEntry );
84 116482 : pIter++;
85 116482 : }
86 : }
87 1716 : }
88 :
89 2212 : XMLPropertySetMapper::~XMLPropertySetMapper()
90 : {
91 2212 : }
92 :
93 351 : void XMLPropertySetMapper::AddMapperEntry(
94 : const UniReference < XMLPropertySetMapper >& rMapper )
95 : {
96 2364 : for( vector < UniReference < XMLPropertyHandlerFactory > >::iterator
97 351 : aFIter = rMapper->aHdlFactories.begin();
98 1576 : aFIter != rMapper->aHdlFactories.end();
99 : ++aFIter )
100 : {
101 437 : aHdlFactories.push_back( *aFIter );
102 : }
103 :
104 114243 : for( vector < XMLPropertySetMapperEntry_Impl >::iterator
105 351 : aEIter = rMapper->aMapEntries.begin();
106 76162 : aEIter != rMapper->aMapEntries.end();
107 : ++aEIter )
108 : {
109 37730 : aMapEntries.push_back( *aEIter );
110 : }
111 351 : }
112 :
113 : ///////////////////////////////////////////////////////////////////////////
114 : //
115 : // Export a Property
116 : //
117 424 : sal_Bool XMLPropertySetMapper::exportXML(
118 : OUString& rStrExpValue,
119 : const XMLPropertyState& rProperty,
120 : const SvXMLUnitConverter& rUnitConverter ) const
121 : {
122 424 : sal_Bool bRet = sal_False;
123 :
124 424 : const XMLPropertyHandler* pHdl = GetPropertyHandler( rProperty.mnIndex );
125 :
126 : DBG_ASSERT( pHdl, "Unknown XML Type!" );
127 424 : if( pHdl )
128 : bRet = pHdl->exportXML( rStrExpValue, rProperty.maValue,
129 424 : rUnitConverter );
130 :
131 424 : return bRet;
132 : }
133 :
134 : ///////////////////////////////////////////////////////////////////////////
135 : //
136 : // Import a Property
137 : //
138 5616 : sal_Bool XMLPropertySetMapper::importXML(
139 : const OUString& rStrImpValue,
140 : XMLPropertyState& rProperty,
141 : const SvXMLUnitConverter& rUnitConverter ) const
142 : {
143 5616 : sal_Bool bRet = sal_False;
144 :
145 5616 : const XMLPropertyHandler* pHdl = GetPropertyHandler( rProperty.mnIndex );
146 :
147 5616 : if( pHdl )
148 : bRet = pHdl->importXML( rStrImpValue, rProperty.maValue,
149 5616 : rUnitConverter );
150 :
151 5616 : 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 6556 : sal_Int32 XMLPropertySetMapper::GetEntryIndex(
161 : sal_uInt16 nNamespace,
162 : const OUString& rStrName,
163 : sal_uInt32 nPropType,
164 : sal_Int32 nStartAt /* = -1 */ ) const
165 : {
166 6556 : sal_Int32 nEntries = GetEntryCount();
167 6556 : sal_Int32 nIndex= nStartAt == - 1? 0 : nStartAt+1;
168 :
169 6556 : if ( nEntries )
170 : {
171 457433 : do
172 : {
173 463458 : const XMLPropertySetMapperEntry_Impl& rEntry = aMapEntries[nIndex];
174 564534 : if( (!nPropType || nPropType == rEntry.GetPropType()) &&
175 : rEntry.nXMLNameSpace == nNamespace &&
176 101076 : rStrName == rEntry.sXMLAttributeName )
177 6025 : return nIndex;
178 : else
179 457433 : nIndex++;
180 :
181 : } while( nIndex<nEntries );
182 : }
183 :
184 531 : 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 10 : sal_Int32 XMLPropertySetMapper::FindEntryIndex(
190 : const sal_Char* sApiName,
191 : sal_uInt16 nNameSpace,
192 : const OUString& sXMLName ) const
193 : {
194 10 : sal_Int32 nIndex = 0;
195 10 : sal_Int32 nEntries = GetEntryCount();
196 :
197 642 : do
198 : {
199 652 : const XMLPropertySetMapperEntry_Impl& rEntry = aMapEntries[nIndex];
200 1170 : if( rEntry.nXMLNameSpace == nNameSpace &&
201 500 : rEntry.sXMLAttributeName.equals( sXMLName ) &&
202 18 : 0 == rEntry.sAPIPropertyName.compareToAscii( sApiName ) )
203 10 : return nIndex;
204 : else
205 642 : nIndex++;
206 :
207 : } while( nIndex < nEntries );
208 :
209 0 : return -1;
210 : }
211 :
212 320 : sal_Int32 XMLPropertySetMapper::FindEntryIndex( const sal_Int16 nContextId ) const
213 : {
214 320 : const sal_Int32 nEntries = GetEntryCount();
215 :
216 320 : if ( nEntries )
217 : {
218 320 : sal_Int32 nIndex = 0;
219 13244 : do
220 : {
221 13564 : const XMLPropertySetMapperEntry_Impl& rEntry = aMapEntries[nIndex];
222 13564 : if( rEntry.nContextId == nContextId )
223 320 : return nIndex;
224 : else
225 13244 : 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: */
|