LibreOffice Module reportdesign (master) 1
xmlStyleImport.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#include "xmlStyleImport.hxx"
20#include <xmloff/maptype.hxx>
22#include <xmloff/xmlimppr.hxx>
23#include <xmloff/txtimppr.hxx>
24#include <xmloff/families.hxx>
25#include <xmloff/xmlnumfi.hxx>
26#include <xmloff/xmltoken.hxx>
27#include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
28#include <com/sun/star/container/XNameContainer.hpp>
29#include <xmloff/xmluconv.hxx>
31#include "xmlfilter.hxx"
32#include "xmlHelper.hxx"
33#include <osl/diagnose.h>
34
35namespace rptxml
36{
37
38using namespace ::com::sun::star;
39using namespace ::com::sun::star::uno;
40using namespace ::com::sun::star::xml::sax;
41using namespace ::com::sun::star::style;
42using namespace ::com::sun::star::beans;
43using namespace ::com::sun::star::container;
44using namespace xmloff::token;
45
46namespace {
47
48class OSpecialHandleXMLImportPropertyMapper : public SvXMLImportPropertyMapper
49{
50public:
51 OSpecialHandleXMLImportPropertyMapper(const rtl::Reference< XMLPropertySetMapper >& rMapper,SvXMLImport& _rImport) : SvXMLImportPropertyMapper(rMapper ,_rImport)
52 {
53 }
55 virtual bool handleSpecialItem(
56 XMLPropertyState& /*rProperty*/,
57 ::std::vector< XMLPropertyState >& /*rProperties*/,
58 const OUString& /*rValue*/,
59 const SvXMLUnitConverter& /*rUnitConverter*/,
60 const SvXMLNamespaceMap& /*rNamespaceMap*/ ) const override
61 {
62 // nothing to do here
63 return true;
64 }
65};
66
67}
68
70 SvXMLStylesContext& rStyles, XmlStyleFamily nFamily ) :
71 XMLPropStyleContext( rImport, rStyles, nFamily, false/*bDefaultStyle*/ ),
72 pStyles(&rStyles),
73 m_nNumberFormat(-1),
74 m_rImport(rImport)
75{
76
77}
78
79
81{
82
83}
84
85
86void OControlStyleContext::FillPropertySet(const Reference< XPropertySet > & rPropSet )
87{
88 if ( !IsDefaultStyle() )
89 {
90 if ( GetFamily() == XmlStyleFamily::TABLE_CELL )
91 {
92 if ((m_nNumberFormat == -1) && !m_sDataStyleName.isEmpty())
93 {
95 XmlStyleFamily::DATA_STYLE, m_sDataStyleName)));
96 if ( !pStyle )
97 {
98 OReportStylesContext* pMyStyles = dynamic_cast< OReportStylesContext *>(m_rImport.GetAutoStyles());
99 if ( pMyStyles )
100 pStyle = const_cast<SvXMLNumFormatContext*>(dynamic_cast< const SvXMLNumFormatContext *>(pMyStyles->
101 FindStyleChildContext(XmlStyleFamily::DATA_STYLE, m_sDataStyleName, true)));
102 else {
103 OSL_FAIL("not possible to get style");
104 }
105 }
106 if ( pStyle )
107 {
108 m_nNumberFormat = pStyle->GetKey();
110 }
111 }
112 }
113 }
115}
116
118{
119}
120
121
122void OControlStyleContext::AddProperty(const sal_Int16 nContextID, const uno::Any& rValue)
123{
124 sal_Int32 nIndex(static_cast<OReportStylesContext *>(pStyles)->GetIndex(nContextID));
125 OSL_ENSURE(nIndex != -1, "Property not found in Map");
126 XMLPropertyState aPropState(nIndex, rValue);
127 GetProperties().push_back(aPropState); // has to be inserted in a sort order later
128}
129
130void OControlStyleContext::SetAttribute( sal_Int32 nElement,
131 const OUString& rValue )
132{
133 switch(nElement & TOKEN_MASK)
134 {
136 m_sDataStyleName = rValue;
137 break;
139 break;
140 default:
141 XMLPropStyleContext::SetAttribute( nElement, rValue );
142 }
143}
144
145
147 const bool bTempAutoStyles ) :
148 SvXMLStylesContext( rImport ),
149 m_rImport(rImport),
150 m_nNumberFormatIndex(-1),
151 bAutoStyles(bTempAutoStyles)
152{
153
154}
155
156
158{
159
160}
161
162
164{
165 if (bAutoStyles)
166 GetImport().GetTextImport()->SetAutoStyles( this );
167 else
168 GetImport().GetStyles()->CopyStylesToDoc(true);
169}
170
171
174 XmlStyleFamily nFamily ) const
175{
177
178 if (!xMapper.is())
179 {
180 ORptFilter& rImport = GetOwnImport();
181 switch( nFamily )
182 {
183 case XmlStyleFamily::TABLE_CELL:
184 {
185 if( !m_xCellImpPropMapper.is() )
186 {
188 new XMLTextImportPropertyMapper/*OSpecialHandleXMLImportPropertyMapper*/( rImport.GetCellStylesPropertySetMapper(), m_rImport );
189
191 }
192 xMapper = m_xCellImpPropMapper;
193 }
194 break;
195 case XmlStyleFamily::TABLE_COLUMN:
196 {
197 if( !m_xColumnImpPropMapper.is() )
200
201 xMapper = m_xColumnImpPropMapper;
202 }
203 break;
204 case XmlStyleFamily::TABLE_ROW:
205 {
206 if( !m_xRowImpPropMapper.is() )
207 m_xRowImpPropMapper =new OSpecialHandleXMLImportPropertyMapper( rImport.GetRowStylesPropertySetMapper(), m_rImport );
208 xMapper = m_xRowImpPropMapper;
209 }
210 break;
211 case XmlStyleFamily::TABLE_TABLE:
212 {
213 if( !m_xTableImpPropMapper.is() )
214 {
215 rtl::Reference < XMLPropertyHandlerFactory> xFac = new ::xmloff::OControlPropertyHandlerFactory();
217 }
218 xMapper = m_xTableImpPropMapper;
219 }
220 break;
221 default:
222 break;
223 }
224 }
225
226 return xMapper;
227}
228
230 XmlStyleFamily nFamily, sal_Int32 /*nElement*/,
231 const uno::Reference< xml::sax::XFastAttributeList > & /*xAttrList*/ )
232{
233 switch( nFamily )
234 {
235 case XmlStyleFamily::SD_GRAPHICS_ID:
236 // There are no writer specific defaults for graphic styles!
237 return new XMLGraphicsDefaultStyle( GetImport(), *this );
238 default:
239 return nullptr;
240 }
241}
242
244 XmlStyleFamily nFamily, sal_Int32 nElement,
245 const Reference< xml::sax::XFastAttributeList > & xAttrList )
246{
248 xAttrList );
249 if (!pStyle)
250 {
251 switch( nFamily )
252 {
253 case XmlStyleFamily::TABLE_TABLE:
254 case XmlStyleFamily::TABLE_COLUMN:
255 case XmlStyleFamily::TABLE_ROW:
256 case XmlStyleFamily::TABLE_CELL:
257 pStyle = new OControlStyleContext( GetOwnImport(), *this, nFamily );
258 break;
259 default:
260 OSL_FAIL("OReportStylesContext::CreateStyleStyleChildContext: Unknown style family. Please check.");
261 break;
262 }
263 }
264
265 return pStyle;
266}
267
268Reference < XNameContainer >
270{
271 Reference < XNameContainer > xStyles(SvXMLStylesContext::GetStylesContainer(nFamily));
272 if (!xStyles.is())
273 {
274 OUString sName;
275 switch( nFamily )
276 {
277 case XmlStyleFamily::TABLE_TABLE:
278 {
279 if( m_xTableStyles.is() )
280 xStyles.set(m_xTableStyles);
281 else
282 sName = "TableStyles";
283 }
284 break;
285 case XmlStyleFamily::TABLE_CELL:
286 {
287 if( m_xCellStyles.is() )
288 xStyles.set(m_xCellStyles);
289 else
290 sName = "CellStyles";
291 }
292 break;
293 case XmlStyleFamily::TABLE_COLUMN:
294 {
295 if( m_xColumnStyles.is() )
296 xStyles.set(m_xColumnStyles);
297 else
298 sName = "ColumnStyles";
299 }
300 break;
301 case XmlStyleFamily::TABLE_ROW:
302 {
303 if( m_xRowStyles.is() )
304 xStyles.set(m_xRowStyles);
305 else
306 sName = "RowStyles";
307 }
308 break;
309 case XmlStyleFamily::SD_GRAPHICS_ID:
310 xStyles = const_cast<SvXMLImport *>(&GetImport())->GetTextImport()->GetFrameStyles();
311 break;
312 default:
313 OSL_FAIL("OReportStylesContext::CreateStyleStyleChildContext: Unknown style family. Please check.");
314 break;
315 }
316 if( !xStyles.is() && !sName.isEmpty() && GetOwnImport().GetModel().is() )
317 {
318 Reference< XStyleFamiliesSupplier > xFamiliesSupp(
319 GetOwnImport().GetModel(), UNO_QUERY );
320 if (xFamiliesSupp.is())
321 {
322 Reference< XNameAccess > xFamilies(xFamiliesSupp->getStyleFamilies());
323
324 xStyles.set(xFamilies->getByName( sName ), uno::UNO_QUERY);
325 switch( nFamily )
326 {
327 case XmlStyleFamily::TABLE_TABLE:
328 m_xTableStyles.set(xStyles);
329 break;
330 case XmlStyleFamily::TABLE_CELL:
331 m_xCellStyles.set(xStyles);
332 break;
333 case XmlStyleFamily::TABLE_COLUMN:
334 m_xColumnStyles.set(xStyles);
335 break;
336 case XmlStyleFamily::TABLE_ROW:
337 m_xRowStyles.set(xStyles);
338 break;
339 default:
340 break;
341 }
342 }
343 }
344 }
345
346 return xStyles;
347}
348
349
351{
353 if (sServiceName.isEmpty())
354 {
355 switch( nFamily )
356 {
357 case XmlStyleFamily::TABLE_TABLE:
359 break;
360 case XmlStyleFamily::TABLE_COLUMN:
362 break;
363 case XmlStyleFamily::TABLE_ROW:
365 break;
366 case XmlStyleFamily::TABLE_CELL:
368 break;
369 default:
370 break;
371 }
372 }
373 return sServiceName;
374}
375
376
377sal_Int32 OReportStylesContext::GetIndex(const sal_Int16 nContextID)
378{
379 if ( nContextID == CTF_RPT_NUMBERFORMAT )
380 {
381 if (m_nNumberFormatIndex == -1)
383 GetImportPropertyMapper(XmlStyleFamily::TABLE_CELL)->getPropertySetMapper()->FindEntryIndex(nContextID);
385 }
386 return -1;
387}
388
389
390} // rptxml
391
392
393/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const SvXMLImport & m_rImport
constexpr OUStringLiteral sServiceName
SvXMLImport & GetImport()
friend friend class SvXMLImport
XmlStyleFamily GetFamily() const
bool IsDefaultStyle() const
const SvXMLStyleContext * FindStyleChildContext(XmlStyleFamily nFamily, const OUString &rName, bool bCreateIndex=false) const
virtual css::uno::Reference< css::container::XNameContainer > GetStylesContainer(XmlStyleFamily nFamily) const
virtual rtl::Reference< SvXMLImportPropertyMapper > GetImportPropertyMapper(XmlStyleFamily nFamily) const
virtual SvXMLStyleContext * CreateStyleStyleChildContext(XmlStyleFamily nFamily, sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
virtual OUString GetServiceName(XmlStyleFamily nFamily) const
virtual void FillPropertySet(const css::uno::Reference< css::beans::XPropertySet > &rPropSet)
const ::std::vector< XMLPropertyState > & GetProperties() const
virtual void SetAttribute(sal_Int32 nElement, const OUString &rValue) override
static SvXMLImportPropertyMapper * CreateParaExtPropMapper(SvXMLImport &)
virtual void SetDefaults() override
OControlStyleContext(const OControlStyleContext &)=delete
virtual void FillPropertySet(const css::uno::Reference< css::beans::XPropertySet > &rPropSet) override
void AddProperty(sal_Int16 nContextID, const css::uno::Any &aValue)
virtual void SetAttribute(sal_Int32 nElement, const OUString &rValue) override
SvXMLStylesContext * pStyles
virtual ~OControlStyleContext() override
virtual OUString GetServiceName(XmlStyleFamily nFamily) const override
virtual css::uno::Reference< css::container::XNameContainer > GetStylesContainer(XmlStyleFamily nFamily) const override
rtl::Reference< SvXMLImportPropertyMapper > m_xColumnImpPropMapper
css::uno::Reference< css::container::XNameContainer > m_xTableStyles
virtual void SAL_CALL endFastElement(sal_Int32 nElement) override
virtual SvXMLStyleContext * CreateStyleStyleChildContext(XmlStyleFamily nFamily, sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override
virtual SvXMLStyleContext * CreateDefaultStyleStyleChildContext(XmlStyleFamily nFamily, sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override
virtual ~OReportStylesContext() override
virtual rtl::Reference< SvXMLImportPropertyMapper > GetImportPropertyMapper(XmlStyleFamily nFamily) const override
ORptFilter & GetOwnImport() const
css::uno::Reference< css::container::XNameContainer > m_xCellStyles
rtl::Reference< SvXMLImportPropertyMapper > m_xTableImpPropMapper
sal_Int32 GetIndex(const sal_Int16 nContextID)
css::uno::Reference< css::container::XNameContainer > m_xRowStyles
rtl::Reference< SvXMLImportPropertyMapper > m_xCellImpPropMapper
OReportStylesContext(const OReportStylesContext &)=delete
rtl::Reference< SvXMLImportPropertyMapper > m_xRowImpPropMapper
css::uno::Reference< css::container::XNameContainer > m_xColumnStyles
const rtl::Reference< XMLPropertySetMapper > & GetColumnStylesPropertySetMapper() const
Definition: xmlfilter.hxx:103
const rtl::Reference< XMLPropertySetMapper > & GetCellStylesPropertySetMapper() const
Definition: xmlfilter.hxx:100
const rtl::Reference< XMLPropertySetMapper > & GetRowStylesPropertySetMapper() const
Definition: xmlfilter.hxx:106
static const XMLPropertyMapEntry * GetTableStyleProps()
Definition: xmlHelper.cxx:153
XmlStyleFamily
constexpr OUStringLiteral XML_STYLE_FAMILY_TABLE_COLUMN_STYLES_NAME
constexpr OUStringLiteral XML_STYLE_FAMILY_TABLE_ROW_STYLES_NAME
constexpr OUStringLiteral XML_STYLE_FAMILY_TABLE_CELL_STYLES_NAME
constexpr OUStringLiteral XML_STYLE_FAMILY_TABLE_TABLE_STYLES_NAME
OUString sName
sal_Int32 nIndex
XML_MASTER_PAGE_NAME
XML_DATA_STYLE_NAME
#define CTF_RPT_NUMBERFORMAT
Definition: xmlHelper.hxx:29
constexpr sal_Int32 TOKEN_MASK