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