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