tdf#154285 Check upper bound of arguments in SbRtl_Minute function
[LibreOffice.git] / xmloff / source / style / xmlaustp.cxx
blobf9c6408bf7728941e5f0d627a9c739b2655970c7
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <com/sun/star/container/XIndexReplace.hpp>
21 #include "impastpl.hxx"
22 #include <xmloff/xmlaustp.hxx>
23 #include <xmloff/families.hxx>
24 #include <xmloff/xmlnamespace.hxx>
25 #include <xmloff/xmltoken.hxx>
26 #include <xmloff/xmlexp.hxx>
27 #include <xmloff/xmlprhdl.hxx>
28 #include <xmloff/xmlprmap.hxx>
29 #include <xmloff/XMLTextListAutoStylePool.hxx>
31 #include <PageMasterStyleMap.hxx>
32 #include <osl/diagnose.h>
35 using namespace ::com::sun::star;
36 using namespace ::xmloff::token;
39 namespace
41 void lcl_exportDataStyle( SvXMLExport& _rExport, const rtl::Reference< XMLPropertySetMapper >& _rxMapper,
42 const XMLPropertyState& _rProperty )
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!");
50 // add the attribute
51 _rExport.AddAttribute(
52 _rxMapper->GetEntryNameSpace( _rProperty.mnIndex ),
53 _rxMapper->GetEntryXMLName( _rProperty.mnIndex ),
54 sDataStyleName );
58 void SvXMLAutoStylePoolP::exportStyleAttributes(
59 comphelper::AttributeList&,
60 XmlStyleFamily nFamily,
61 const std::vector< XMLPropertyState >& rProperties,
62 const SvXMLExportPropertyMapper& rPropExp,
63 const SvXMLUnitConverter&,
64 const SvXMLNamespaceMap&
65 ) const
67 if ( XmlStyleFamily::CONTROL_ID == nFamily )
68 { // it's a control-related style
69 const rtl::Reference< XMLPropertySetMapper >& aPropertyMapper = rPropExp.getPropertySetMapper();
71 for (const auto& rProp : rProperties)
73 if ( ( rProp.mnIndex > -1 )
74 && ( CTF_FORMS_DATA_STYLE == aPropertyMapper->GetEntryContextId( rProp.mnIndex ) )
76 { // it's the data-style for a grid column
77 lcl_exportDataStyle( GetExport(), aPropertyMapper, rProp );
82 if( (XmlStyleFamily::SD_GRAPHICS_ID == nFamily) || (XmlStyleFamily::SD_PRESENTATION_ID == nFamily) )
83 { // it's a graphics style
84 const rtl::Reference< XMLPropertySetMapper >& aPropertyMapper = rPropExp.getPropertySetMapper();
85 assert(aPropertyMapper.is());
87 bool bFoundControlShapeDataStyle = false;
88 bool bFoundNumberingRulesName = false;
90 for (const auto& rProp : rProperties)
92 if (rProp.mnIndex > -1)
93 { // it's a valid property
94 switch( aPropertyMapper->GetEntryContextId(rProp.mnIndex) )
96 case CTF_SD_CONTROL_SHAPE_DATA_STYLE:
97 { // it's the control shape data style property
99 if (bFoundControlShapeDataStyle)
101 OSL_FAIL("SvXMLAutoStylePoolP::exportStyleAttributes: found two properties with the ControlShapeDataStyle context id!");
102 // already added the attribute for the first occurrence
103 break;
106 lcl_exportDataStyle( GetExport(), aPropertyMapper, rProp );
108 // check if there is another property with the special context id we're handling here
109 bFoundControlShapeDataStyle = true;
110 break;
112 case CTF_SD_NUMBERINGRULES_NAME:
114 if (bFoundNumberingRulesName)
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;
121 uno::Reference< container::XIndexReplace > xNumRule;
122 rProp.maValue >>= xNumRule;
123 if( xNumRule.is() && (xNumRule->getCount() > 0 ) )
125 const OUString sName(const_cast<XMLTextListAutoStylePool*>(&GetExport().GetTextParagraphExport()->GetListAutoStylePool())->Add( xNumRule ));
127 GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_LIST_STYLE_NAME, GetExport().EncodeStyleName( sName ) );
130 bFoundNumberingRulesName = true;
131 break;
138 if( nFamily != XmlStyleFamily::PAGE_MASTER )
139 return;
141 for( const auto& rProp : rProperties )
143 if (rProp.mnIndex > -1)
145 const rtl::Reference< XMLPropertySetMapper >& aPropMapper = rPropExp.getPropertySetMapper();
146 sal_Int32 nIndex = rProp.mnIndex;
147 sal_Int16 nContextID = aPropMapper->GetEntryContextId( nIndex );
148 switch( nContextID )
150 case CTF_PM_PAGEUSAGE:
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 ) ) )
159 GetExport().AddAttribute( aPropMapper->GetEntryNameSpace( nIndex ), aPropMapper->GetEntryXMLName( nIndex ), sValue );
162 break;
168 void SvXMLAutoStylePoolP::exportStyleContent(
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
177 if( nFamily != XmlStyleFamily::PAGE_MASTER )
178 return;
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);
189 const rtl::Reference< XMLPropertySetMapper >& aPropMapper = rPropExp.getPropertySetMapper();
191 sal_Int32 nIndex(0);
192 while(nIndex < aPropMapper->GetEntryCount())
194 switch( aPropMapper->GetEntryContextId( nIndex ) & CTF_PM_FLAGMASK )
196 case CTF_PM_HEADERFLAG:
198 if (!bHeaderStartIndex)
200 nHeaderStartIndex = nIndex;
201 bHeaderStartIndex = true;
203 if (bFooterStartIndex && !bFooterEndIndex)
205 nFooterEndIndex = nIndex;
206 bFooterEndIndex = true;
209 break;
210 case CTF_PM_FOOTERFLAG:
212 if (!bFooterStartIndex)
214 nFooterStartIndex = nIndex;
215 bFooterStartIndex = true;
217 if (bHeaderStartIndex && !bHeaderEndIndex)
219 nHeaderEndIndex = nIndex;
220 bHeaderEndIndex = true;
223 break;
225 nIndex++;
227 if (!bHeaderEndIndex)
228 nHeaderEndIndex = nIndex;
229 if (!bFooterEndIndex)
230 nFooterEndIndex = nIndex;
232 // export header style element
234 SvXMLElementExport aElem(
235 GetExport(), XML_NAMESPACE_STYLE, XML_HEADER_STYLE,
236 true, true );
238 rPropExp.exportXML(
239 GetExport(), rProperties,
240 nHeaderStartIndex, nHeaderEndIndex, SvXmlExportFlags::IGN_WS);
243 // export footer style
245 SvXMLElementExport aElem(
246 GetExport(), XML_NAMESPACE_STYLE, XML_FOOTER_STYLE,
247 true, true );
249 rPropExp.exportXML(
250 GetExport(), rProperties,
251 nFooterStartIndex, nFooterEndIndex, SvXmlExportFlags::IGN_WS);
256 SvXMLAutoStylePoolP::SvXMLAutoStylePoolP( SvXMLExport& rExport )
257 : m_pImpl( new SvXMLAutoStylePoolP_Impl( rExport ) )
261 SvXMLAutoStylePoolP::~SvXMLAutoStylePoolP()
265 SvXMLExport& SvXMLAutoStylePoolP::GetExport() const
267 return m_pImpl->GetExport();
270 // TODO: remove this
271 void SvXMLAutoStylePoolP::AddFamily(
272 XmlStyleFamily nFamily,
273 const OUString& rStrName,
274 SvXMLExportPropertyMapper* pMapper,
275 const OUString& aStrPrefix )
277 rtl::Reference <SvXMLExportPropertyMapper> xTmp = pMapper;
278 AddFamily( nFamily, rStrName, xTmp, aStrPrefix );
281 void SvXMLAutoStylePoolP::AddFamily(
282 XmlStyleFamily nFamily,
283 const OUString& rStrName,
284 const rtl::Reference < SvXMLExportPropertyMapper > & rMapper,
285 const OUString& rStrPrefix,
286 bool bAsFamily )
288 m_pImpl->AddFamily( nFamily, rStrName, rMapper, rStrPrefix, bAsFamily );
291 void SvXMLAutoStylePoolP::SetFamilyPropSetMapper(
292 XmlStyleFamily nFamily,
293 const rtl::Reference < SvXMLExportPropertyMapper > & rMapper )
295 m_pImpl->SetFamilyPropSetMapper( nFamily, rMapper );
298 void SvXMLAutoStylePoolP::RegisterName( XmlStyleFamily nFamily,
299 const OUString& rName )
301 m_pImpl->RegisterName( nFamily, rName );
304 void SvXMLAutoStylePoolP::RegisterDefinedName( XmlStyleFamily nFamily,
305 const OUString& rName )
307 m_pImpl->RegisterDefinedName( nFamily, rName );
310 void SvXMLAutoStylePoolP::GetRegisteredNames(
311 uno::Sequence<sal_Int32>& rFamilies,
312 uno::Sequence<OUString>& rNames )
314 m_pImpl->GetRegisteredNames( rFamilies, rNames );
317 void SvXMLAutoStylePoolP::RegisterNames(
318 uno::Sequence<sal_Int32> const & aFamilies,
319 uno::Sequence<OUString> const & aNames )
321 assert(aFamilies.getLength() == aNames.getLength());
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] );
331 OUString SvXMLAutoStylePoolP::Add( XmlStyleFamily nFamily,
332 std::vector< XMLPropertyState >&& rProperties )
334 OUString sName;
335 m_pImpl->Add(sName, nFamily, u""_ustr, std::move(rProperties) );
336 return sName;
339 OUString SvXMLAutoStylePoolP::Add( XmlStyleFamily nFamily,
340 const OUString& rParent,
341 std::vector< XMLPropertyState >&& rProperties, bool bDontSeek )
343 OUString sName;
344 m_pImpl->Add(sName, nFamily, rParent, std::move(rProperties), bDontSeek);
345 return sName;
348 bool SvXMLAutoStylePoolP::Add(OUString& rName, XmlStyleFamily nFamily, const OUString& rParent, ::std::vector< XMLPropertyState >&& rProperties )
350 return m_pImpl->Add(rName, nFamily, rParent, std::move(rProperties));
353 bool SvXMLAutoStylePoolP::AddNamed( const OUString& rName, XmlStyleFamily nFamily, const OUString& rParent,
354 std::vector< XMLPropertyState > rProperties )
357 return m_pImpl->AddNamed(rName, nFamily, rParent, std::move(rProperties));
360 OUString SvXMLAutoStylePoolP::Find( XmlStyleFamily nFamily,
361 const OUString& rParent,
362 const std::vector< XMLPropertyState >& rProperties ) const
364 return m_pImpl->Find( nFamily, rParent, rProperties );
367 void SvXMLAutoStylePoolP::exportXML( XmlStyleFamily nFamily ) const
369 m_pImpl->exportXML( nFamily, this );
372 void SvXMLAutoStylePoolP::ClearEntries()
374 m_pImpl->ClearEntries();
377 std::vector<xmloff::AutoStyleEntry> SvXMLAutoStylePoolP::GetAutoStyleEntries() const
379 return m_pImpl->GetAutoStyleEntries();
382 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */