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/xmlaustp.hxx>
31 : : #include <xmloff/xmltoken.hxx>
32 : : #include <xmloff/nmspmap.hxx>
33 : : #include "xmloff/xmlnmspe.hxx"
34 : : #include <xmloff/attrlist.hxx>
35 : : #include "impastpl.hxx"
36 : : #include <xmloff/xmlexppr.hxx>
37 : : #include <xmloff/xmlexp.hxx>
38 : : #include <xmloff/families.hxx>
39 : : #include <xmloff/PageMasterStyleMap.hxx>
40 : :
41 : : using namespace ::std;
42 : : using ::rtl::OUString;
43 : : using ::rtl::OUStringBuffer;
44 : :
45 : : using namespace ::com::sun::star;
46 : : using namespace ::xmloff::token;
47 : :
48 : : //#############################################################################
49 : : //
50 : : // Class SvXMLAutoStylePool_Impl
51 : : //
52 : :
53 : : ///////////////////////////////////////////////////////////////////////////////
54 : : //
55 : : // ctor/dtor class SvXMLAutoStylePool_Impl
56 : : //
57 : :
58 : 496 : SvXMLAutoStylePoolP_Impl::SvXMLAutoStylePoolP_Impl( SvXMLExport& rExp)
59 : 496 : : rExport( rExp )
60 : : {
61 : 496 : }
62 : :
63 : 496 : SvXMLAutoStylePoolP_Impl::~SvXMLAutoStylePoolP_Impl()
64 : : {
65 : 496 : }
66 : :
67 : : ///////////////////////////////////////////////////////////////////////////////
68 : : //
69 : : // Adds stylefamily-informations to sorted list
70 : : //
71 : :
72 : 2750 : void SvXMLAutoStylePoolP_Impl::AddFamily(
73 : : sal_Int32 nFamily,
74 : : const OUString& rStrName,
75 : : const UniReference < SvXMLExportPropertyMapper > & rMapper,
76 : : const OUString& rStrPrefix,
77 : : sal_Bool bAsFamily )
78 : : {
79 : : // store family in a list if not already stored
80 : 2750 : sal_uInt16 nExportFlags = GetExport().getExportFlags();
81 [ + + ][ + + ]: 2750 : sal_Bool bStylesOnly = (nExportFlags & EXPORT_STYLES) != 0 && (nExportFlags & EXPORT_CONTENT) == 0;
82 : :
83 : 2750 : OUString aPrefix( rStrPrefix );
84 [ + + ]: 2750 : if( bStylesOnly )
85 : : {
86 : 447 : aPrefix = OUString( 'M' );
87 : 447 : aPrefix += rStrPrefix;
88 : : }
89 : :
90 [ + - ][ + - ]: 2750 : XMLFamilyData_Impl *pFamily = new XMLFamilyData_Impl( nFamily, rStrName, rMapper, aPrefix, bAsFamily );
91 [ + - ]: 2750 : maFamilyList.insert(pFamily);
92 : 2750 : }
93 : :
94 : 0 : void SvXMLAutoStylePoolP_Impl::SetFamilyPropSetMapper(
95 : : sal_Int32 nFamily,
96 : : const UniReference < SvXMLExportPropertyMapper > & rMapper )
97 : : {
98 : :
99 [ # # ]: 0 : XMLFamilyData_Impl aTemporary( nFamily );
100 [ # # ]: 0 : XMLFamilyDataList_Impl::iterator aFind = maFamilyList.find(aTemporary);
101 [ # # ][ # # ]: 0 : if (aFind != maFamilyList.end())
[ # # ]
102 [ # # ][ # # ]: 0 : aFind->mxMapper = rMapper;
[ # # ]
103 : 0 : }
104 : : ///////////////////////////////////////////////////////////////////////////////
105 : : //
106 : : // Adds a name to list
107 : : //
108 : :
109 : 7748 : void SvXMLAutoStylePoolP_Impl::RegisterName( sal_Int32 nFamily, const OUString& rName )
110 : : {
111 [ + - ]: 7748 : XMLFamilyData_Impl aTmp( nFamily );
112 [ + - ]: 7748 : XMLFamilyDataList_Impl::iterator aFind = maFamilyList.find(aTmp);
113 : : DBG_ASSERT( aFind != maFamilyList.end(),
114 : : "SvXMLAutoStylePool_Impl::RegisterName: unknown family" );
115 [ + - ][ + - ]: 7748 : if (aFind != maFamilyList.end())
[ + - ]
116 [ + - ][ + - ]: 7748 : aFind->mpNameList->insert(rName);
[ + - ]
117 : 7748 : }
118 : :
119 : : ///////////////////////////////////////////////////////////////////////////////
120 : : //
121 : : // Retrieve the list of registered names
122 : : //
123 : :
124 : 33 : void SvXMLAutoStylePoolP_Impl::GetRegisteredNames(
125 : : uno::Sequence<sal_Int32>& rFamilies,
126 : : uno::Sequence<OUString>& rNames )
127 : : {
128 : : // collect registered names + families
129 [ + - ]: 33 : vector<sal_Int32> aFamilies;
130 [ + - ]: 33 : vector<OUString> aNames;
131 : :
132 : : // iterate over families
133 [ + - ][ + - ]: 328 : for(XMLFamilyDataList_Impl::iterator aJ = maFamilyList.begin(); aJ != maFamilyList.end(); ++aJ)
[ + - ][ + - ]
[ + + ]
134 : : {
135 [ + - ]: 295 : XMLFamilyData_Impl &rFamily = *aJ;
136 : :
137 : : // iterate over names
138 : 295 : SvXMLAutoStylePoolNamesP_Impl* pNames = rFamily.mpNameList;
139 [ - + ]: 295 : if (!pNames)
140 : 0 : continue;
141 [ + + ]: 4067 : for (SvXMLAutoStylePoolNamesP_Impl::const_iterator aI = pNames->begin(); aI != pNames->end(); ++aI)
142 : : {
143 [ + - ]: 3772 : aFamilies.push_back( rFamily.mnFamily );
144 [ + - ]: 3772 : aNames.push_back( *aI );
145 : : }
146 : : }
147 : :
148 : : // copy the families + names into the sequence types
149 : : DBG_ASSERT( aFamilies.size() == aNames.size(), "families != names" );
150 : :
151 [ + - ]: 33 : rFamilies.realloc( aFamilies.size() );
152 [ + - ][ + - ]: 33 : std::copy( aFamilies.begin(), aFamilies.end(), rFamilies.getArray() );
153 : :
154 [ + - ]: 33 : rNames.realloc( aNames.size() );
155 [ + - ][ + - ]: 33 : std::copy( aNames.begin(), aNames.end(), rNames.getArray() );
156 : 33 : }
157 : :
158 : : ///////////////////////////////////////////////////////////////////////////////
159 : : //
160 : : // Adds a array of XMLPropertyState ( vector< XMLPropertyState > ) to list
161 : : // if not added, yet.
162 : : //
163 : :
164 : 302 : sal_Bool SvXMLAutoStylePoolP_Impl::Add(OUString& rName, sal_Int32 nFamily,
165 : : const OUString& rParent,
166 : : const ::std::vector< XMLPropertyState >& rProperties,
167 : : sal_Bool bCache,
168 : : bool bDontSeek )
169 : : {
170 : 302 : sal_Bool bRet(sal_False);
171 : :
172 [ + - ]: 302 : XMLFamilyData_Impl aTemporary( nFamily );
173 [ + - ]: 302 : XMLFamilyDataList_Impl::iterator aFind = maFamilyList.find(aTemporary);
174 : : DBG_ASSERT(aFind != maFamilyList.end(), "SvXMLAutoStylePool_Impl::Add: unknown family");
175 : :
176 [ + - ][ + - ]: 302 : if (aFind != maFamilyList.end())
[ + - ]
177 : : {
178 [ + - ]: 302 : XMLFamilyData_Impl &rFamily = *aFind;
179 : :
180 [ + - ]: 302 : SvXMLAutoStylePoolParentP_Impl aTmp( rParent );
181 : 302 : SvXMLAutoStylePoolParentP_Impl *pParent = 0;
182 : :
183 : 302 : SvXMLAutoStylePoolParentsP_Impl *pParents = rFamily.mpParentList;
184 : : SvXMLAutoStylePoolParentsP_Impl::const_iterator const it2 =
185 [ + - ]: 302 : pParents->find(&aTmp);
186 [ + - ][ + + ]: 302 : if (it2 != pParents->end())
187 : : {
188 : 199 : pParent = *it2;
189 : : }
190 : : else
191 : : {
192 [ + - ][ + - ]: 103 : pParent = new SvXMLAutoStylePoolParentP_Impl( rParent );
193 [ + - ]: 103 : pParents->insert( pParent );
194 : : }
195 : :
196 [ + - ][ + + ]: 302 : if( pParent->Add( rFamily, rProperties, rName, bDontSeek ) )
197 : : {
198 : 246 : rFamily.mnCount++;
199 : 246 : bRet = sal_True;
200 : : }
201 : :
202 [ - + ]: 302 : if( bCache )
203 : : {
204 [ # # ]: 0 : if( !rFamily.pCache )
205 [ # # ][ # # ]: 0 : rFamily.pCache = new SvXMLAutoStylePoolCache_Impl();
206 [ # # ]: 0 : if( rFamily.pCache->size() < MAX_CACHE_SIZE )
207 [ # # ][ # # ]: 0 : rFamily.pCache->push_back( new OUString( rName ) );
208 [ + - ]: 302 : }
209 : : }
210 : :
211 [ + - ]: 302 : return bRet;
212 : : }
213 : :
214 : 0 : sal_Bool SvXMLAutoStylePoolP_Impl::AddNamed(const OUString& rName, sal_Int32 nFamily,
215 : : const OUString& rParent, const ::std::vector< XMLPropertyState >& rProperties )
216 : : {
217 : : // get family and parent the same way as in Add()
218 : 0 : sal_Bool bRet(sal_False);
219 : :
220 [ # # ]: 0 : XMLFamilyData_Impl aTemporary( nFamily );
221 [ # # ]: 0 : XMLFamilyDataList_Impl::iterator aFind = maFamilyList.find(aTemporary);
222 : : DBG_ASSERT(aFind != maFamilyList.end(), "SvXMLAutoStylePool_Impl::Add: unknown family");
223 : :
224 [ # # ][ # # ]: 0 : if (aFind != maFamilyList.end())
[ # # ]
225 : : {
226 [ # # ]: 0 : XMLFamilyData_Impl &rFamily = *aFind;
227 : :
228 [ # # ]: 0 : SvXMLAutoStylePoolParentP_Impl aTmp( rParent );
229 : 0 : SvXMLAutoStylePoolParentP_Impl *pParent = 0;
230 : :
231 : 0 : SvXMLAutoStylePoolParentsP_Impl *pParents = rFamily.mpParentList;
232 : : SvXMLAutoStylePoolParentsP_Impl::const_iterator const it2 =
233 [ # # ]: 0 : pParents->find(&aTmp);
234 [ # # ][ # # ]: 0 : if (it2 != pParents->end())
235 : : {
236 : 0 : pParent = *it2;
237 : : }
238 : : else
239 : : {
240 [ # # ][ # # ]: 0 : pParent = new SvXMLAutoStylePoolParentP_Impl( rParent );
241 [ # # ]: 0 : pParents->insert( pParent );
242 : : }
243 : :
244 [ # # ][ # # ]: 0 : if( pParent->AddNamed( rFamily, rProperties, rName ) )
245 : : {
246 : 0 : rFamily.mnCount++;
247 : 0 : bRet = sal_True;
248 [ # # ]: 0 : }
249 : : }
250 : :
251 [ # # ]: 0 : return bRet;
252 : : }
253 : :
254 : : ///////////////////////////////////////////////////////////////////////////////
255 : : //
256 : : // Search for a array of XMLPropertyState ( vector< XMLPropertyState > ) in list
257 : : //
258 : :
259 : 333 : OUString SvXMLAutoStylePoolP_Impl::Find( sal_Int32 nFamily,
260 : : const OUString& rParent,
261 : : const vector< XMLPropertyState >& rProperties ) const
262 : : {
263 : 333 : OUString sName;
264 : :
265 [ + - ]: 333 : XMLFamilyData_Impl aTemporary( nFamily );
266 : : XMLFamilyDataList_Impl::const_iterator const iter =
267 [ + - ]: 333 : maFamilyList.find(aTemporary);
268 : : OSL_ENSURE(iter != maFamilyList.end(),
269 : : "SvXMLAutoStylePool_Impl::Find: unknown family");
270 : :
271 [ + - ][ + - ]: 333 : if (iter != maFamilyList.end())
[ + - ]
272 : : {
273 [ + - ]: 333 : XMLFamilyData_Impl const& rFamily = *iter;
274 : : const SvXMLAutoStylePoolParentsP_Impl* pParents =
275 : 333 : rFamily.mpParentList;
276 : :
277 [ + - ]: 333 : SvXMLAutoStylePoolParentP_Impl aTmp( rParent );
278 : : SvXMLAutoStylePoolParentsP_Impl::const_iterator const it2 =
279 [ + - ]: 333 : pParents->find(&aTmp);
280 [ + - ][ + + ]: 333 : if (it2 != pParents->end())
281 : : {
282 [ + - ]: 266 : sName = (*it2)->Find( rFamily, rProperties );
283 [ + - ]: 333 : }
284 : : }
285 : :
286 [ + - ]: 333 : return sName;
287 : : }
288 : :
289 : : ///////////////////////////////////////////////////////////////////////////////
290 : : //
291 : : // export
292 : : //
293 : :
294 : 1408 : void SvXMLAutoStylePoolP_Impl::exportXML(
295 : : sal_Int32 nFamily,
296 : : const uno::Reference< ::com::sun::star::xml::sax::XDocumentHandler > &,
297 : : const SvXMLUnitConverter&,
298 : : const SvXMLNamespaceMap&,
299 : : const SvXMLAutoStylePoolP *pAntiImpl) const
300 : : {
301 : : // Get list of parents for current family (nFamily)
302 [ + - ]: 1408 : XMLFamilyData_Impl aTmp( nFamily );
303 [ + - ]: 1408 : XMLFamilyDataList_Impl::const_iterator aFind = maFamilyList.find(aTmp);
304 : : DBG_ASSERT( aFind != maFamilyList.end(),
305 : : "SvXMLAutoStylePool_Impl::exportXML: unknown family" );
306 [ + - ][ + - ]: 1408 : if (aFind == maFamilyList.end())
[ - + ]
307 : : return;
308 : :
309 [ + - ]: 1408 : const XMLFamilyData_Impl &rFamily = *aFind;
310 : 1408 : sal_uInt32 nCount = rFamily.mnCount;
311 : :
312 [ + + ]: 1408 : if (!nCount)
313 : : return;
314 : :
315 : : /////////////////////////////////////////////////////////////////////////////////////
316 : : // create, initialize and fill helper-structure (SvXMLAutoStylePoolProperties_Impl)
317 : : // wich contains a parent-name and a SvXMLAutoStylePoolProperties_Impl
318 : : //
319 : : const SvXMLAutoStylePoolParentsP_Impl *pParents =
320 : 97 : rFamily.mpParentList;
321 : :
322 : : SvXMLAutoStylePoolPExport_Impl* aExpStyles =
323 [ + - ]: 97 : new SvXMLAutoStylePoolPExport_Impl[nCount];
324 : :
325 : : sal_uInt32 i;
326 [ + + ]: 347 : for( i=0; i < nCount; i++ )
327 : : {
328 : 250 : aExpStyles[i].mpParent = 0;
329 : 250 : aExpStyles[i].mpProperties = 0;
330 : : }
331 : :
332 [ + + ]: 202 : for (size_t k = 0; k < pParents->size(); k++)
333 : : {
334 [ + - ]: 105 : const SvXMLAutoStylePoolParentP_Impl *const pParent = (*pParents)[k];
335 : 105 : size_t nProperties = pParent->GetPropertiesList().size();
336 [ + + ]: 355 : for( size_t j = 0; j < nProperties; j++ )
337 : : {
338 : : const SvXMLAutoStylePoolPropertiesP_Impl* pProperties =
339 : 250 : pParent->GetPropertiesList()[ j ];
340 : 250 : sal_uLong nPos = pProperties->GetPos();
341 : : DBG_ASSERT( nPos < nCount,
342 : : "SvXMLAutoStylePool_Impl::exportXML: wrong position" );
343 [ + - ]: 250 : if( nPos < nCount )
344 : : {
345 : : DBG_ASSERT( !aExpStyles[nPos].mpProperties,
346 : : "SvXMLAutoStylePool_Impl::exportXML: double position" );
347 : 250 : aExpStyles[nPos].mpProperties = pProperties;
348 : 250 : aExpStyles[nPos].mpParent = &pParent->GetParent();
349 : : }
350 : : }
351 : : }
352 : :
353 : : /////////////////////////////////////////////////////////////////////////////////////
354 : : //
355 : : // create string to export for each XML-style. That means for each property-list
356 : : //
357 : 97 : OUString aStrFamilyName = rFamily.maStrFamilyName;
358 : :
359 [ + + ]: 347 : for( i=0; i<nCount; i++ )
360 : : {
361 : : DBG_ASSERT( aExpStyles[i].mpProperties,
362 : : "SvXMLAutoStylePool_Impl::exportXML: empty position" );
363 : :
364 [ + - ]: 250 : if( aExpStyles[i].mpProperties )
365 : : {
366 : 250 : GetExport().AddAttribute(
367 : : XML_NAMESPACE_STYLE, XML_NAME,
368 [ + - ]: 500 : aExpStyles[i].mpProperties->GetName() );
369 : :
370 [ + + ]: 250 : if( rFamily.bAsFamily )
371 : : {
372 : 218 : GetExport().AddAttribute(
373 [ + - ]: 218 : XML_NAMESPACE_STYLE, XML_FAMILY, aStrFamilyName );
374 : : }
375 : :
376 [ + + ]: 250 : if( !aExpStyles[i].mpParent->isEmpty() )
377 : : {
378 : 39 : GetExport().AddAttribute(
379 : : XML_NAMESPACE_STYLE, XML_PARENT_STYLE_NAME,
380 : 39 : GetExport().EncodeStyleName(
381 [ + - + - ]: 78 : *aExpStyles[i].mpParent ) );
382 : : }
383 : :
384 : 250 : OUString sName;
385 [ + + ]: 250 : if( rFamily.bAsFamily )
386 [ + - ]: 218 : sName = GetXMLToken(XML_STYLE);
387 : : else
388 : 32 : sName = rFamily.maStrFamilyName;
389 : :
390 : : pAntiImpl->exportStyleAttributes(
391 : 250 : GetExport().GetAttrList(),
392 : : nFamily,
393 : 250 : aExpStyles[i].mpProperties->GetProperties(),
394 : 250 : *rFamily.mxMapper.get()
395 : 250 : , GetExport().GetMM100UnitConverter(),
396 : 250 : GetExport().GetNamespaceMap()
397 [ + - ]: 250 : );
398 : :
399 : 250 : SvXMLElementExport aElem( GetExport(),
400 : : XML_NAMESPACE_STYLE, sName,
401 [ + - ]: 250 : sal_True, sal_True );
402 : :
403 : 250 : sal_Int32 nStart(-1);
404 : 250 : sal_Int32 nEnd(-1);
405 [ + + ]: 250 : if (nFamily == XML_STYLE_FAMILY_PAGE_MASTER)
406 : : {
407 : 32 : nStart = 0;
408 : 32 : sal_Int32 nIndex = 0;
409 : : UniReference< XMLPropertySetMapper > aPropMapper =
410 [ + - ]: 32 : rFamily.mxMapper->getPropertySetMapper();
411 : : sal_Int16 nContextID;
412 [ + - ][ + - ]: 2432 : while(nIndex < aPropMapper->GetEntryCount() && nEnd == -1)
[ + + ][ + + ]
413 : : {
414 [ + - ][ + - ]: 2400 : nContextID = aPropMapper->GetEntryContextId( nIndex );
415 [ + + ][ + + ]: 2400 : if (nContextID && ((nContextID & CTF_PM_FLAGMASK) != XML_PM_CTF_START))
416 : 32 : nEnd = nIndex;
417 : 2400 : nIndex++;
418 : : }
419 [ - + ]: 32 : if (nEnd == -1)
420 [ + - ]: 32 : nEnd = nIndex;
421 : : }
422 : :
423 : : rFamily.mxMapper->exportXML(
424 : 250 : GetExport(),
425 : 250 : aExpStyles[i].mpProperties->GetProperties(),
426 [ + - ]: 250 : nStart, nEnd, XML_EXPORT_FLAG_IGN_WS );
427 : :
428 : : pAntiImpl->exportStyleContent(
429 : 250 : GetExport().GetDocHandler(),
430 : : nFamily,
431 : 250 : aExpStyles[i].mpProperties->GetProperties(),
432 : 250 : *rFamily.mxMapper.get(),
433 : 250 : GetExport().GetMM100UnitConverter(),
434 : 250 : GetExport().GetNamespaceMap()
435 [ + - ][ + - ]: 250 : );
436 : : }
437 : : }
438 : :
439 [ + - ][ + - ]: 1408 : delete[] aExpStyles;
[ + + ]
440 : : }
441 : :
442 : 4 : void SvXMLAutoStylePoolP_Impl::ClearEntries()
443 : : {
444 [ + - ][ + - ]: 20 : for(XMLFamilyDataList_Impl::iterator aI = maFamilyList.begin(); aI != maFamilyList.end(); ++aI)
[ + - ][ + - ]
[ + + ]
445 [ + - ][ + - ]: 16 : aI->ClearEntries();
446 : 4 : }
447 : :
448 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|