LibreOffice Module xmloff (master) 1
xmlaustp.cxx
Go to the documentation of this file.
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 <com/sun/star/container/XIndexReplace.hpp>
21#include "impastpl.hxx"
22#include <xmloff/xmlaustp.hxx>
23#include <xmloff/families.hxx>
25#include <xmloff/xmltoken.hxx>
26#include <xmloff/xmlexp.hxx>
27#include <xmloff/xmlprhdl.hxx>
28#include <xmloff/xmlprmap.hxx>
30
32#include <osl/diagnose.h>
33
34
35using namespace ::com::sun::star;
36using namespace ::xmloff::token;
37
38
39namespace
40{
41 void lcl_exportDataStyle( SvXMLExport& _rExport, const rtl::Reference< XMLPropertySetMapper >& _rxMapper,
42 const XMLPropertyState& _rProperty )
43 {
44 assert(_rxMapper.is());
45 // obtain the data style name
46 OUString sDataStyleName;
47 _rProperty.maValue >>= sDataStyleName;
48 assert(!sDataStyleName.isEmpty() && "xmloff::lcl_exportDataStyle: invalid property value for the data style name!");
49
50 // add the attribute
51 _rExport.AddAttribute(
52 _rxMapper->GetEntryNameSpace( _rProperty.mnIndex ),
53 _rxMapper->GetEntryXMLName( _rProperty.mnIndex ),
54 sDataStyleName );
55 }
56}
57
60 XmlStyleFamily nFamily,
61 const std::vector< XMLPropertyState >& rProperties,
62 const SvXMLExportPropertyMapper& rPropExp,
63 const SvXMLUnitConverter&,
65 ) const
66{
67 if ( XmlStyleFamily::CONTROL_ID == nFamily )
68 { // it's a control-related style
69 const rtl::Reference< XMLPropertySetMapper >& aPropertyMapper = rPropExp.getPropertySetMapper();
70
71 for (const auto& rProp : rProperties)
72 {
73 if ( ( rProp.mnIndex > -1 )
74 && ( CTF_FORMS_DATA_STYLE == aPropertyMapper->GetEntryContextId( rProp.mnIndex ) )
75 )
76 { // it's the data-style for a grid column
77 lcl_exportDataStyle( GetExport(), aPropertyMapper, rProp );
78 }
79 }
80 }
81
83 { // it's a graphics style
84 const rtl::Reference< XMLPropertySetMapper >& aPropertyMapper = rPropExp.getPropertySetMapper();
85 assert(aPropertyMapper.is());
86
87 bool bFoundControlShapeDataStyle = false;
88 bool bFoundNumberingRulesName = false;
89
90 for (const auto& rProp : rProperties)
91 {
92 if (rProp.mnIndex > -1)
93 { // it's a valid property
94 switch( aPropertyMapper->GetEntryContextId(rProp.mnIndex) )
95 {
97 { // it's the control shape data style property
98
99 if (bFoundControlShapeDataStyle)
100 {
101 OSL_FAIL("SvXMLAutoStylePoolP::exportStyleAttributes: found two properties with the ControlShapeDataStyle context id!");
102 // already added the attribute for the first occurrence
103 break;
104 }
105
106 lcl_exportDataStyle( GetExport(), aPropertyMapper, rProp );
107
108 // check if there is another property with the special context id we're handling here
109 bFoundControlShapeDataStyle = true;
110 break;
111 }
113 {
114 if (bFoundNumberingRulesName)
115 {
116 OSL_FAIL("SvXMLAutoStylePoolP::exportStyleAttributes: found two properties with the numbering rules name context id!");
117 // already added the attribute for the first occurrence
118 break;
119 }
120
121 uno::Reference< container::XIndexReplace > xNumRule;
122 rProp.maValue >>= xNumRule;
123 if( xNumRule.is() && (xNumRule->getCount() > 0 ) )
124 {
125 const OUString sName(const_cast<XMLTextListAutoStylePool*>(&GetExport().GetTextParagraphExport()->GetListAutoStylePool())->Add( xNumRule ));
126
128 }
129
130 bFoundNumberingRulesName = true;
131 break;
132 }
133 }
134 }
135 }
136 }
137
138 if( nFamily != XmlStyleFamily::PAGE_MASTER )
139 return;
140
141 for( const auto& rProp : rProperties )
142 {
143 if (rProp.mnIndex > -1)
144 {
145 const rtl::Reference< XMLPropertySetMapper >& aPropMapper = rPropExp.getPropertySetMapper();
146 sal_Int32 nIndex = rProp.mnIndex;
147 sal_Int16 nContextID = aPropMapper->GetEntryContextId( nIndex );
148 switch( nContextID )
149 {
150 case CTF_PM_PAGEUSAGE:
151 {
152 OUString sValue;
153 const XMLPropertyHandler* pPropHdl = aPropMapper->GetPropertyHandler( nIndex );
154 if( pPropHdl &&
155 pPropHdl->exportXML( sValue, rProp.maValue,
156 GetExport().GetMM100UnitConverter() ) &&
157 ( ! IsXMLToken( sValue, XML_ALL ) ) )
158 {
159 GetExport().AddAttribute( aPropMapper->GetEntryNameSpace( nIndex ), aPropMapper->GetEntryXMLName( nIndex ), sValue );
160 }
161 }
162 break;
163 }
164 }
165 }
166}
167
169 const css::uno::Reference< css::xml::sax::XDocumentHandler > &,
170 XmlStyleFamily nFamily,
171 const std::vector< XMLPropertyState >& rProperties,
172 const SvXMLExportPropertyMapper& rPropExp,
173 const SvXMLUnitConverter&,
174 const SvXMLNamespaceMap&
175 ) const
176{
177 if( nFamily != XmlStyleFamily::PAGE_MASTER )
178 return;
179
180 sal_Int32 nHeaderStartIndex(-1);
181 sal_Int32 nHeaderEndIndex(-1);
182 sal_Int32 nFooterStartIndex(-1);
183 sal_Int32 nFooterEndIndex(-1);
184 bool bHeaderStartIndex(false);
185 bool bHeaderEndIndex(false);
186 bool bFooterStartIndex(false);
187 bool bFooterEndIndex(false);
188
189 const rtl::Reference< XMLPropertySetMapper >& aPropMapper = rPropExp.getPropertySetMapper();
190
191 sal_Int32 nIndex(0);
192 while(nIndex < aPropMapper->GetEntryCount())
193 {
194 switch( aPropMapper->GetEntryContextId( nIndex ) & CTF_PM_FLAGMASK )
195 {
197 {
198 if (!bHeaderStartIndex)
199 {
200 nHeaderStartIndex = nIndex;
201 bHeaderStartIndex = true;
202 }
203 if (bFooterStartIndex && !bFooterEndIndex)
204 {
205 nFooterEndIndex = nIndex;
206 bFooterEndIndex = true;
207 }
208 }
209 break;
211 {
212 if (!bFooterStartIndex)
213 {
214 nFooterStartIndex = nIndex;
215 bFooterStartIndex = true;
216 }
217 if (bHeaderStartIndex && !bHeaderEndIndex)
218 {
219 nHeaderEndIndex = nIndex;
220 bHeaderEndIndex = true;
221 }
222 }
223 break;
224 }
225 nIndex++;
226 }
227 if (!bHeaderEndIndex)
228 nHeaderEndIndex = nIndex;
229 if (!bFooterEndIndex)
230 nFooterEndIndex = nIndex;
231
232 // export header style element
233 {
234 SvXMLElementExport aElem(
236 true, true );
237
238 rPropExp.exportXML(
239 GetExport(), rProperties,
240 nHeaderStartIndex, nHeaderEndIndex, SvXmlExportFlags::IGN_WS);
241 }
242
243 // export footer style
244 {
245 SvXMLElementExport aElem(
247 true, true );
248
249 rPropExp.exportXML(
250 GetExport(), rProperties,
251 nFooterStartIndex, nFooterEndIndex, SvXmlExportFlags::IGN_WS);
252 }
253
254}
255
257 : m_pImpl( new SvXMLAutoStylePoolP_Impl( rExport ) )
258{
259}
260
262{
263}
264
266{
267 return m_pImpl->GetExport();
268}
269
270// TODO: remove this
272 XmlStyleFamily nFamily,
273 const OUString& rStrName,
275 const OUString& aStrPrefix )
276{
278 AddFamily( nFamily, rStrName, xTmp, aStrPrefix );
279}
280
282 XmlStyleFamily nFamily,
283 const OUString& rStrName,
285 const OUString& rStrPrefix,
286 bool bAsFamily )
287{
288 m_pImpl->AddFamily( nFamily, rStrName, rMapper, rStrPrefix, bAsFamily );
289}
290
292 XmlStyleFamily nFamily,
294{
295 m_pImpl->SetFamilyPropSetMapper( nFamily, rMapper );
296}
297
299 const OUString& rName )
300{
301 m_pImpl->RegisterName( nFamily, rName );
302}
303
305 const OUString& rName )
306{
307 m_pImpl->RegisterDefinedName( nFamily, rName );
308}
309
311 uno::Sequence<sal_Int32>& rFamilies,
312 uno::Sequence<OUString>& rNames )
313{
314 m_pImpl->GetRegisteredNames( rFamilies, rNames );
315}
316
318 uno::Sequence<sal_Int32> const & aFamilies,
319 uno::Sequence<OUString> const & aNames )
320{
321 assert(aFamilies.getLength() == aNames.getLength());
322
323 // iterate over sequence(s) and call RegisterName(..) for each pair
324 const sal_Int32* pFamilies = aFamilies.getConstArray();
325 const OUString* pNames = aNames.getConstArray();
326 sal_Int32 nCount = std::min( aFamilies.getLength(), aNames.getLength() );
327 for( sal_Int32 n = 0; n < nCount; n++ )
328 RegisterName( static_cast<XmlStyleFamily>(pFamilies[n]), pNames[n] );
329}
330
332 std::vector< XMLPropertyState >&& rProperties )
333{
334 OUString sName;
335 m_pImpl->Add(sName, nFamily, "", std::move(rProperties) );
336 return sName;
337}
338
340 const OUString& rParent,
341 std::vector< XMLPropertyState >&& rProperties, bool bDontSeek )
342{
343 OUString sName;
344 m_pImpl->Add(sName, nFamily, rParent, std::move(rProperties), bDontSeek);
345 return sName;
346}
347
348bool SvXMLAutoStylePoolP::Add(OUString& rName, XmlStyleFamily nFamily, const OUString& rParent, ::std::vector< XMLPropertyState >&& rProperties )
349{
350 return m_pImpl->Add(rName, nFamily, rParent, std::move(rProperties));
351}
352
353bool SvXMLAutoStylePoolP::AddNamed( const OUString& rName, XmlStyleFamily nFamily, const OUString& rParent,
354 std::vector< XMLPropertyState > rProperties )
355
356{
357 return m_pImpl->AddNamed(rName, nFamily, rParent, std::move(rProperties));
358}
359
361 const OUString& rParent,
362 const std::vector< XMLPropertyState >& rProperties ) const
363{
364 return m_pImpl->Find( nFamily, rParent, rProperties );
365}
366
368{
369 m_pImpl->exportXML( nFamily, this );
370}
371
373{
374 m_pImpl->ClearEntries();
375}
376
377std::vector<xmloff::AutoStyleEntry> SvXMLAutoStylePoolP::GetAutoStyleEntries() const
378{
379 return m_pImpl->GetAutoStyleEntries();
380}
381
382/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
::std::unique_ptr< XmlIdRegistry_Impl > m_pImpl
#define CTF_PM_HEADERFLAG
#define CTF_PM_FLAGMASK
#define CTF_PM_PAGEUSAGE
#define CTF_PM_FOOTERFLAG
void RegisterNames(css::uno::Sequence< sal_Int32 > const &aFamilies, css::uno::Sequence< OUString > const &aNames)
register (families + names)
Definition: xmlaustp.cxx:317
SvXMLAutoStylePoolP(SvXMLExport &rExport)
Definition: xmlaustp.cxx:256
void AddFamily(XmlStyleFamily nFamily, const OUString &rStrName, SvXMLExportPropertyMapper *pMapper, const OUString &aStrPrefix)
register a new family with its appropriate instance of a derivation of XMLPropertySetMapper for famil...
Definition: xmlaustp.cxx:271
std::unique_ptr< SvXMLAutoStylePoolP_Impl > m_pImpl
Definition: xmlaustp.hxx:54
OUString Find(XmlStyleFamily nFamily, const OUString &rParent, const ::std::vector< XMLPropertyState > &rProperties) const
Find an item set's name.
Definition: xmlaustp.cxx:360
void RegisterName(XmlStyleFamily nFamily, const OUString &rName)
Register a name that must not be used as a generated name.
Definition: xmlaustp.cxx:298
void GetRegisteredNames(css::uno::Sequence< sal_Int32 > &aFamilies, css::uno::Sequence< OUString > &aNames)
retrieve the registered names (names + families)
Definition: xmlaustp.cxx:310
virtual ~SvXMLAutoStylePoolP() override
Definition: xmlaustp.cxx:261
SvXMLExport & GetExport() const
Definition: xmlaustp.cxx:265
virtual void exportStyleContent(const css::uno::Reference< css::xml::sax::XDocumentHandler > &rHandler, XmlStyleFamily nFamily, const ::std::vector< XMLPropertyState > &rProperties, const SvXMLExportPropertyMapper &rPropExp, const SvXMLUnitConverter &rUnitConverter, const SvXMLNamespaceMap &rNamespaceMap) const
Definition: xmlaustp.cxx:168
std::vector< xmloff::AutoStyleEntry > GetAutoStyleEntries() const
Definition: xmlaustp.cxx:377
OUString Add(XmlStyleFamily nFamily, ::std::vector< XMLPropertyState > &&rProperties)
Add an item set to the pool and return its generated name.
void exportXML(XmlStyleFamily nFamily) const
Export all item sets ofs a certain class in the order in that they have been added.
Definition: xmlaustp.cxx:367
void RegisterDefinedName(XmlStyleFamily nFamily, const OUString &rName)
Register a name that may only be used through AddNamed.
Definition: xmlaustp.cxx:304
virtual void exportStyleAttributes(comphelper::AttributeList &rAttrList, XmlStyleFamily nFamily, const ::std::vector< XMLPropertyState > &rProperties, const SvXMLExportPropertyMapper &rPropExp, const SvXMLUnitConverter &rUnitConverter, const SvXMLNamespaceMap &rNamespaceMap) const
Definition: xmlaustp.cxx:58
void SetFamilyPropSetMapper(XmlStyleFamily nFamily, const rtl::Reference< SvXMLExportPropertyMapper > &rMapper)
Definition: xmlaustp.cxx:291
bool AddNamed(const OUString &rName, XmlStyleFamily nFamily, const OUString &rParent, std::vector< XMLPropertyState > aProperties)
Add an item set with a pre-defined name (needed for saving sheets separately in Calc).
Definition: xmlaustp.cxx:353
void exportXML(SvXMLExport &rExport, const ::std::vector< XMLPropertyState > &rProperties, SvXmlExportFlags nFlags, bool bUseExtensionNamespaceForGraphicProperties=false) const
fills the given attribute list with the items in the given set void SvXMLExportPropertyMapper::export...
Definition: xmlexppr.cxx:790
const rtl::Reference< XMLPropertySetMapper > & getPropertySetMapper() const
Definition: xmlexppr.cxx:1110
void AddAttribute(sal_uInt16 nPrefix, const OUString &rName, const OUString &rValue)
Definition: xmlexp.cxx:907
the SvXMLTypeConverter converts values of various types from their internal representation to the tex...
Definition: xmluconv.hxx:83
Abstract base-class for different XML-types.
Definition: xmlprhdl.hxx:36
virtual bool exportXML(OUString &rStrExpValue, const css::uno::Any &rValue, const SvXMLUnitConverter &rUnitConverter) const =0
Exports the given value according to the XML-data-type corresponding to the derived class.
#define CTF_SD_CONTROL_SHAPE_DATA_STYLE
Definition: contextid.hxx:35
#define CTF_SD_NUMBERINGRULES_NAME
Definition: contextid.hxx:36
#define CTF_FORMS_DATA_STYLE
Definition: contextid.hxx:39
int nCount
XmlStyleFamily
Definition: families.hxx:50
OUString sName
sal_Int32 nIndex
sal_Int64 n
Handling of tokens in XML:
bool IsXMLToken(std::u16string_view rString, enum XMLTokenEnum eToken)
compare eToken to the string
Definition: xmltoken.cxx:3597
Smart struct to transport an Any with an index to the appropriate property-name.
Definition: maptype.hxx:140
css::uno::Any maValue
Definition: maptype.hxx:142
sal_Int32 mnIndex
Definition: maptype.hxx:141
constexpr sal_uInt16 XML_NAMESPACE_STYLE