1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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>
32 using namespace ::std
;
34 using namespace ::com::sun::star
;
35 using namespace ::xmloff::token
;
37 //#############################################################################
39 // Class SvXMLAutoStylePool_Impl
42 ///////////////////////////////////////////////////////////////////////////////
44 // ctor/dtor class SvXMLAutoStylePool_Impl
47 SvXMLAutoStylePoolP_Impl::SvXMLAutoStylePoolP_Impl( SvXMLExport
& rExp
)
52 SvXMLAutoStylePoolP_Impl::~SvXMLAutoStylePoolP_Impl()
56 ///////////////////////////////////////////////////////////////////////////////
58 // Adds stylefamily-information to sorted list
61 void SvXMLAutoStylePoolP_Impl::AddFamily(
63 const OUString
& rStrName
,
64 const UniReference
< SvXMLExportPropertyMapper
> & rMapper
,
65 const OUString
& rStrPrefix
,
68 // store family in a list if not already stored
69 sal_uInt16 nExportFlags
= GetExport().getExportFlags();
70 sal_Bool bStylesOnly
= (nExportFlags
& EXPORT_STYLES
) != 0 && (nExportFlags
& EXPORT_CONTENT
) == 0;
72 OUString
aPrefix( rStrPrefix
);
75 aPrefix
= OUString( 'M' );
76 aPrefix
+= rStrPrefix
;
79 #if OSL_DEBUG_LEVEL > 0
80 XMLFamilyData_Impl
aTemporary( nFamily
);
81 XMLFamilyDataList_Impl::iterator aFind
= maFamilyList
.find(aTemporary
);
82 if( aFind
!= maFamilyList
.end() )
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() );
94 XMLFamilyData_Impl
*pFamily
= new XMLFamilyData_Impl( nFamily
, rStrName
, rMapper
, aPrefix
, bAsFamily
);
95 maFamilyList
.insert(pFamily
);
98 void SvXMLAutoStylePoolP_Impl::SetFamilyPropSetMapper(
100 const UniReference
< SvXMLExportPropertyMapper
> & rMapper
)
103 XMLFamilyData_Impl
aTemporary( nFamily
);
104 XMLFamilyDataList_Impl::iterator aFind
= maFamilyList
.find(aTemporary
);
105 if (aFind
!= maFamilyList
.end())
106 aFind
->mxMapper
= rMapper
;
108 ///////////////////////////////////////////////////////////////////////////////
110 // Adds a name to list
113 void SvXMLAutoStylePoolP_Impl::RegisterName( sal_Int32 nFamily
, const OUString
& rName
)
115 XMLFamilyData_Impl
aTmp( nFamily
);
116 XMLFamilyDataList_Impl::iterator aFind
= maFamilyList
.find(aTmp
);
117 DBG_ASSERT( aFind
!= maFamilyList
.end(),
118 "SvXMLAutoStylePool_Impl::RegisterName: unknown family" );
119 if (aFind
!= maFamilyList
.end())
120 aFind
->mpNameList
->insert(rName
);
123 ///////////////////////////////////////////////////////////////////////////////
125 // Retrieve the list of registered names
128 void SvXMLAutoStylePoolP_Impl::GetRegisteredNames(
129 uno::Sequence
<sal_Int32
>& rFamilies
,
130 uno::Sequence
<OUString
>& rNames
)
132 // collect registered names + families
133 vector
<sal_Int32
> aFamilies
;
134 vector
<OUString
> aNames
;
136 // iterate over families
137 for(XMLFamilyDataList_Impl::iterator aJ
= maFamilyList
.begin(); aJ
!= maFamilyList
.end(); ++aJ
)
139 XMLFamilyData_Impl
&rFamily
= *aJ
;
141 // iterate over names
142 SvXMLAutoStylePoolNamesP_Impl
* pNames
= rFamily
.mpNameList
;
145 for (SvXMLAutoStylePoolNamesP_Impl::const_iterator aI
= pNames
->begin(); aI
!= pNames
->end(); ++aI
)
147 aFamilies
.push_back( rFamily
.mnFamily
);
148 aNames
.push_back( *aI
);
152 // copy the families + names into the sequence types
153 DBG_ASSERT( aFamilies
.size() == aNames
.size(), "families != names" );
155 rFamilies
.realloc( aFamilies
.size() );
156 std::copy( aFamilies
.begin(), aFamilies
.end(), rFamilies
.getArray() );
158 rNames
.realloc( aNames
.size() );
159 std::copy( aNames
.begin(), aNames
.end(), rNames
.getArray() );
162 ///////////////////////////////////////////////////////////////////////////////
164 // Adds a array of XMLPropertyState ( vector< XMLPropertyState > ) to list
165 // if not added, yet.
168 sal_Bool
SvXMLAutoStylePoolP_Impl::Add(OUString
& rName
, sal_Int32 nFamily
,
169 const OUString
& rParent
,
170 const ::std::vector
< XMLPropertyState
>& rProperties
,
174 sal_Bool
bRet(sal_False
);
176 XMLFamilyData_Impl
aTemporary( nFamily
);
177 XMLFamilyDataList_Impl::iterator aFind
= maFamilyList
.find(aTemporary
);
178 DBG_ASSERT(aFind
!= maFamilyList
.end(), "SvXMLAutoStylePool_Impl::Add: unknown family");
180 if (aFind
!= maFamilyList
.end())
182 XMLFamilyData_Impl
&rFamily
= *aFind
;
184 SvXMLAutoStylePoolParentP_Impl
aTmp( rParent
);
185 SvXMLAutoStylePoolParentP_Impl
*pParent
= 0;
187 SvXMLAutoStylePoolParentsP_Impl
*pParents
= rFamily
.mpParentList
;
188 SvXMLAutoStylePoolParentsP_Impl::const_iterator
const it2
=
189 pParents
->find(&aTmp
);
190 if (it2
!= pParents
->end())
196 pParent
= new SvXMLAutoStylePoolParentP_Impl( rParent
);
197 pParents
->insert( pParent
);
200 if( pParent
->Add( rFamily
, rProperties
, rName
, bDontSeek
) )
208 if( !rFamily
.pCache
)
209 rFamily
.pCache
= new SvXMLAutoStylePoolCache_Impl();
210 if( rFamily
.pCache
->size() < MAX_CACHE_SIZE
)
211 rFamily
.pCache
->push_back( new OUString( rName
) );
218 sal_Bool
SvXMLAutoStylePoolP_Impl::AddNamed(const OUString
& rName
, sal_Int32 nFamily
,
219 const OUString
& rParent
, const ::std::vector
< XMLPropertyState
>& rProperties
)
221 // get family and parent the same way as in Add()
222 sal_Bool
bRet(sal_False
);
224 XMLFamilyData_Impl
aTemporary( nFamily
);
225 XMLFamilyDataList_Impl::iterator aFind
= maFamilyList
.find(aTemporary
);
226 DBG_ASSERT(aFind
!= maFamilyList
.end(), "SvXMLAutoStylePool_Impl::Add: unknown family");
228 if (aFind
!= maFamilyList
.end())
230 XMLFamilyData_Impl
&rFamily
= *aFind
;
232 SvXMLAutoStylePoolParentP_Impl
aTmp( rParent
);
233 SvXMLAutoStylePoolParentP_Impl
*pParent
= 0;
235 SvXMLAutoStylePoolParentsP_Impl
*pParents
= rFamily
.mpParentList
;
236 SvXMLAutoStylePoolParentsP_Impl::const_iterator
const it2
=
237 pParents
->find(&aTmp
);
238 if (it2
!= pParents
->end())
244 pParent
= new SvXMLAutoStylePoolParentP_Impl( rParent
);
245 pParents
->insert( pParent
);
248 if( pParent
->AddNamed( rFamily
, rProperties
, rName
) )
258 ///////////////////////////////////////////////////////////////////////////////
260 // Search for a array of XMLPropertyState ( vector< XMLPropertyState > ) in list
263 OUString
SvXMLAutoStylePoolP_Impl::Find( sal_Int32 nFamily
,
264 const OUString
& rParent
,
265 const vector
< XMLPropertyState
>& rProperties
) const
269 XMLFamilyData_Impl
aTemporary( nFamily
);
270 XMLFamilyDataList_Impl::const_iterator
const iter
=
271 maFamilyList
.find(aTemporary
);
272 OSL_ENSURE(iter
!= maFamilyList
.end(),
273 "SvXMLAutoStylePool_Impl::Find: unknown family");
275 if (iter
!= maFamilyList
.end())
277 XMLFamilyData_Impl
const& rFamily
= *iter
;
278 const SvXMLAutoStylePoolParentsP_Impl
* pParents
=
279 rFamily
.mpParentList
;
281 SvXMLAutoStylePoolParentP_Impl
aTmp( rParent
);
282 SvXMLAutoStylePoolParentsP_Impl::const_iterator
const it2
=
283 pParents
->find(&aTmp
);
284 if (it2
!= pParents
->end())
286 sName
= (*it2
)->Find( rFamily
, rProperties
);
293 ///////////////////////////////////////////////////////////////////////////////
298 void SvXMLAutoStylePoolP_Impl::exportXML(
300 const uno::Reference
< ::com::sun::star::xml::sax::XDocumentHandler
> &,
301 const SvXMLUnitConverter
&,
302 const SvXMLNamespaceMap
&,
303 const SvXMLAutoStylePoolP
*pAntiImpl
) const
305 // Get list of parents for current family (nFamily)
306 XMLFamilyData_Impl
aTmp( nFamily
);
307 XMLFamilyDataList_Impl::const_iterator aFind
= maFamilyList
.find(aTmp
);
308 DBG_ASSERT( aFind
!= maFamilyList
.end(),
309 "SvXMLAutoStylePool_Impl::exportXML: unknown family" );
310 if (aFind
== maFamilyList
.end())
313 const XMLFamilyData_Impl
&rFamily
= *aFind
;
314 sal_uInt32 nCount
= rFamily
.mnCount
;
319 /////////////////////////////////////////////////////////////////////////////////////
320 // create, initialize and fill helper-structure (SvXMLAutoStylePoolProperties_Impl)
321 // which contains a parent-name and a SvXMLAutoStylePoolProperties_Impl
323 const SvXMLAutoStylePoolParentsP_Impl
*pParents
=
324 rFamily
.mpParentList
;
326 SvXMLAutoStylePoolPExport_Impl
* aExpStyles
=
327 new SvXMLAutoStylePoolPExport_Impl
[nCount
];
330 for( i
=0; i
< nCount
; i
++ )
332 aExpStyles
[i
].mpParent
= 0;
333 aExpStyles
[i
].mpProperties
= 0;
336 for (size_t k
= 0; k
< pParents
->size(); k
++)
338 const SvXMLAutoStylePoolParentP_Impl
*const pParent
= (*pParents
)[k
];
339 size_t nProperties
= pParent
->GetPropertiesList().size();
340 for( size_t j
= 0; j
< nProperties
; j
++ )
342 const SvXMLAutoStylePoolPropertiesP_Impl
* pProperties
=
343 pParent
->GetPropertiesList()[ j
];
344 sal_uLong nPos
= pProperties
->GetPos();
345 DBG_ASSERT( nPos
< nCount
,
346 "SvXMLAutoStylePool_Impl::exportXML: wrong position" );
349 DBG_ASSERT( !aExpStyles
[nPos
].mpProperties
,
350 "SvXMLAutoStylePool_Impl::exportXML: double position" );
351 aExpStyles
[nPos
].mpProperties
= pProperties
;
352 aExpStyles
[nPos
].mpParent
= &pParent
->GetParent();
357 /////////////////////////////////////////////////////////////////////////////////////
359 // create string to export for each XML-style. That means for each property-list
361 OUString aStrFamilyName
= rFamily
.maStrFamilyName
;
363 for( i
=0; i
<nCount
; i
++ )
365 DBG_ASSERT( aExpStyles
[i
].mpProperties
,
366 "SvXMLAutoStylePool_Impl::exportXML: empty position" );
368 if( aExpStyles
[i
].mpProperties
)
370 GetExport().AddAttribute(
371 XML_NAMESPACE_STYLE
, XML_NAME
,
372 aExpStyles
[i
].mpProperties
->GetName() );
374 if( rFamily
.bAsFamily
)
376 GetExport().AddAttribute(
377 XML_NAMESPACE_STYLE
, XML_FAMILY
, aStrFamilyName
);
380 if( !aExpStyles
[i
].mpParent
->isEmpty() )
382 GetExport().AddAttribute(
383 XML_NAMESPACE_STYLE
, XML_PARENT_STYLE_NAME
,
384 GetExport().EncodeStyleName(
385 *aExpStyles
[i
].mpParent
) );
389 if( rFamily
.bAsFamily
)
390 sName
= GetXMLToken(XML_STYLE
);
392 sName
= rFamily
.maStrFamilyName
;
394 pAntiImpl
->exportStyleAttributes(
395 GetExport().GetAttrList(),
397 aExpStyles
[i
].mpProperties
->GetProperties(),
398 *rFamily
.mxMapper
.get()
399 , GetExport().GetMM100UnitConverter(),
400 GetExport().GetNamespaceMap()
403 SvXMLElementExport
aElem( GetExport(),
404 XML_NAMESPACE_STYLE
, sName
,
405 sal_True
, sal_True
);
407 sal_Int32
nStart(-1);
409 if (nFamily
== XML_STYLE_FAMILY_PAGE_MASTER
)
412 sal_Int32 nIndex
= 0;
413 UniReference
< XMLPropertySetMapper
> aPropMapper
=
414 rFamily
.mxMapper
->getPropertySetMapper();
415 sal_Int16 nContextID
;
416 while(nIndex
< aPropMapper
->GetEntryCount() && nEnd
== -1)
418 nContextID
= aPropMapper
->GetEntryContextId( nIndex
);
419 if (nContextID
&& ((nContextID
& CTF_PM_FLAGMASK
) != XML_PM_CTF_START
))
427 rFamily
.mxMapper
->exportXML(
429 aExpStyles
[i
].mpProperties
->GetProperties(),
430 nStart
, nEnd
, XML_EXPORT_FLAG_IGN_WS
);
432 pAntiImpl
->exportStyleContent(
433 GetExport().GetDocHandler(),
435 aExpStyles
[i
].mpProperties
->GetProperties(),
436 *rFamily
.mxMapper
.get(),
437 GetExport().GetMM100UnitConverter(),
438 GetExport().GetNamespaceMap()
446 void SvXMLAutoStylePoolP_Impl::ClearEntries()
448 for(XMLFamilyDataList_Impl::iterator aI
= maFamilyList
.begin(); aI
!= maFamilyList
.end(); ++aI
)
452 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */