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