Line data Source code
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/nmspmap.hxx>
21 : #include <xmloff/xmlnmspe.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 <comphelper/extract.hxx>
30 : #include <xmloff/xmlprcon.hxx>
31 : #include <xmloff/xmluconv.hxx>
32 : #include <xmloff/XMLGraphicsDefaultStyle.hxx>
33 : #include <tools/debug.hxx>
34 : #include "xmlfilter.hxx"
35 : #include "xmlHelper.hxx"
36 : #include <osl/diagnose.h>
37 :
38 : namespace rptxml
39 : {
40 :
41 : using namespace ::com::sun::star;
42 : using namespace ::com::sun::star::uno;
43 : using namespace ::com::sun::star::xml::sax;
44 : using namespace ::com::sun::star::style;
45 : using namespace ::com::sun::star::frame;
46 : using namespace ::com::sun::star::beans;
47 : using namespace ::com::sun::star::container;
48 : using namespace xmloff::token;
49 :
50 :
51 :
52 0 : class OSpecialHanldeXMLImportPropertyMapper : public SvXMLImportPropertyMapper
53 : {
54 : public:
55 0 : OSpecialHanldeXMLImportPropertyMapper(const UniReference< XMLPropertySetMapper >& rMapper,SvXMLImport& _rImport) : SvXMLImportPropertyMapper(rMapper ,_rImport)
56 : {
57 0 : }
58 : /** this method is called for every item that has the MID_FLAG_SPECIAL_ITEM_IMPORT flag set */
59 0 : virtual bool handleSpecialItem(
60 : XMLPropertyState& /*rProperty*/,
61 : ::std::vector< XMLPropertyState >& /*rProperties*/,
62 : const OUString& /*rValue*/,
63 : const SvXMLUnitConverter& /*rUnitConverter*/,
64 : const SvXMLNamespaceMap& /*rNamespaceMap*/ ) const SAL_OVERRIDE
65 : {
66 : // nothing to do here
67 0 : return true;
68 : }
69 : };
70 :
71 0 : TYPEINIT1( OControlStyleContext, XMLPropStyleContext );
72 0 : TYPEINIT1( OReportStylesContext, SvXMLStylesContext );
73 :
74 0 : OControlStyleContext::OControlStyleContext( ORptFilter& rImport,
75 : sal_uInt16 nPrfx, const OUString& rLName,
76 : const Reference< XAttributeList > & xAttrList,
77 : SvXMLStylesContext& rStyles, sal_uInt16 nFamily, sal_Bool bDefaultStyle ) :
78 : XMLPropStyleContext( rImport, nPrfx, rLName, xAttrList, rStyles, nFamily, bDefaultStyle ),
79 : sNumberFormat(OUString("NumberFormat")),
80 : pStyles(&rStyles),
81 : m_nNumberFormat(-1),
82 : m_rImport(rImport),
83 : bConditionalFormatCreated(sal_False),
84 0 : bParentSet(sal_False)
85 : {
86 :
87 0 : }
88 :
89 :
90 0 : OControlStyleContext::~OControlStyleContext()
91 : {
92 :
93 0 : }
94 :
95 :
96 0 : void OControlStyleContext::FillPropertySet(const Reference< XPropertySet > & rPropSet )
97 : {
98 0 : if ( !IsDefaultStyle() )
99 : {
100 0 : if ( GetFamily() == XML_STYLE_FAMILY_TABLE_CELL )
101 : {
102 0 : if ((m_nNumberFormat == -1) && !m_sDataStyleName.isEmpty())
103 : {
104 : SvXMLNumFormatContext* pStyle = const_cast< SvXMLNumFormatContext*>(dynamic_cast<const SvXMLNumFormatContext*>(pStyles->FindStyleChildContext(
105 0 : XML_STYLE_FAMILY_DATA_STYLE, m_sDataStyleName, false)));
106 0 : if ( !pStyle )
107 : {
108 0 : OReportStylesContext* pMyStyles = PTR_CAST(OReportStylesContext,GetOwnImport().GetAutoStyles());
109 0 : if ( pMyStyles )
110 0 : pStyle = PTR_CAST(SvXMLNumFormatContext,pMyStyles->
111 0 : FindStyleChildContext(XML_STYLE_FAMILY_DATA_STYLE, m_sDataStyleName, true));
112 : else {
113 : OSL_FAIL("not possible to get style");
114 : }
115 : }
116 0 : if ( pStyle )
117 : {
118 0 : m_nNumberFormat = pStyle->GetKey();
119 0 : AddProperty(CTF_RPT_NUMBERFORMAT, uno::makeAny(m_nNumberFormat));
120 : }
121 : }
122 : }
123 : }
124 0 : XMLPropStyleContext::FillPropertySet(rPropSet);
125 0 : }
126 :
127 0 : void OControlStyleContext::SetDefaults()
128 : {
129 0 : }
130 :
131 :
132 0 : void OControlStyleContext::AddProperty(const sal_Int16 nContextID, const uno::Any& rValue)
133 : {
134 0 : sal_Int32 nIndex(static_cast<OReportStylesContext *>(pStyles)->GetIndex(nContextID));
135 : OSL_ENSURE(nIndex != -1, "Property not found in Map");
136 0 : XMLPropertyState aPropState(nIndex, rValue);
137 0 : GetProperties().push_back(aPropState); // has to be insertes in a sort order later
138 0 : }
139 :
140 0 : void OControlStyleContext::SetAttribute( sal_uInt16 nPrefixKey,
141 : const OUString& rLocalName,
142 : const OUString& rValue )
143 : {
144 : // TODO: use a map here
145 0 : if( IsXMLToken(rLocalName, XML_DATA_STYLE_NAME ) )
146 0 : m_sDataStyleName = rValue;
147 0 : else if ( IsXMLToken(rLocalName, XML_MASTER_PAGE_NAME ) )
148 0 : sPageStyle = rValue;
149 : else
150 0 : XMLPropStyleContext::SetAttribute( nPrefixKey, rLocalName, rValue );
151 0 : }
152 :
153 0 : ORptFilter& OControlStyleContext::GetOwnImport() const
154 : {
155 0 : return m_rImport;
156 : }
157 :
158 :
159 0 : OReportStylesContext::OReportStylesContext( ORptFilter& rImport,
160 : sal_uInt16 nPrfx ,
161 : const OUString& rLName ,
162 : const Reference< XAttributeList > & xAttrList,
163 : const sal_Bool bTempAutoStyles ) :
164 : SvXMLStylesContext( rImport, nPrfx, rLName, xAttrList ),
165 : m_sTableStyleFamilyName( OUString( XML_STYLE_FAMILY_TABLE_TABLE_STYLES_NAME )),
166 : m_sColumnStyleFamilyName( OUString( XML_STYLE_FAMILY_TABLE_COLUMN_STYLES_NAME )),
167 : m_sRowStyleFamilyName( OUString( XML_STYLE_FAMILY_TABLE_ROW_STYLES_NAME )),
168 : m_sCellStyleFamilyName( OUString( XML_STYLE_FAMILY_TABLE_CELL_STYLES_NAME )),
169 : m_rImport(rImport),
170 : m_nNumberFormatIndex(-1),
171 0 : bAutoStyles(bTempAutoStyles)
172 : {
173 :
174 0 : }
175 :
176 :
177 0 : OReportStylesContext::~OReportStylesContext()
178 : {
179 :
180 0 : }
181 :
182 :
183 0 : void OReportStylesContext::EndElement()
184 : {
185 0 : SvXMLStylesContext::EndElement();
186 0 : if (bAutoStyles)
187 0 : GetImport().GetTextImport()->SetAutoStyles( this );
188 : else
189 0 : GetImport().GetStyles()->CopyStylesToDoc(true);
190 0 : }
191 :
192 :
193 : UniReference < SvXMLImportPropertyMapper >
194 0 : OReportStylesContext::GetImportPropertyMapper(
195 : sal_uInt16 nFamily ) const
196 : {
197 0 : UniReference < SvXMLImportPropertyMapper > xMapper(SvXMLStylesContext::GetImportPropertyMapper(nFamily));
198 :
199 0 : if (!xMapper.is())
200 : {
201 0 : ORptFilter& rImport = GetOwnImport();
202 0 : switch( nFamily )
203 : {
204 : case XML_STYLE_FAMILY_TABLE_CELL:
205 : {
206 0 : if( !m_xCellImpPropMapper.is() )
207 : {
208 0 : m_xCellImpPropMapper =
209 0 : new XMLTextImportPropertyMapper/*OSpecialHanldeXMLImportPropertyMapper*/( rImport.GetCellStylesPropertySetMapper(), m_rImport );
210 :
211 0 : m_xCellImpPropMapper->ChainImportMapper(XMLTextImportHelper::CreateParaExtPropMapper(m_rImport));
212 : }
213 0 : xMapper = m_xCellImpPropMapper;
214 : }
215 0 : break;
216 : case XML_STYLE_FAMILY_TABLE_COLUMN:
217 : {
218 0 : if( !m_xColumnImpPropMapper.is() )
219 0 : m_xColumnImpPropMapper =
220 0 : new SvXMLImportPropertyMapper( rImport.GetColumnStylesPropertySetMapper(), m_rImport );
221 :
222 0 : xMapper = m_xColumnImpPropMapper;
223 : }
224 0 : break;
225 : case XML_STYLE_FAMILY_TABLE_ROW:
226 : {
227 0 : if( !m_xRowImpPropMapper.is() )
228 0 : m_xRowImpPropMapper =new OSpecialHanldeXMLImportPropertyMapper( rImport.GetRowStylesPropertySetMapper(), m_rImport );
229 0 : xMapper = m_xRowImpPropMapper;
230 : }
231 0 : break;
232 : case XML_STYLE_FAMILY_TABLE_TABLE:
233 : {
234 0 : if( !m_xTableImpPropMapper.is() )
235 : {
236 0 : UniReference < XMLPropertyHandlerFactory> xFac = new ::xmloff::OControlPropertyHandlerFactory();
237 0 : m_xTableImpPropMapper = new SvXMLImportPropertyMapper( new XMLPropertySetMapper(OXMLHelper::GetTableStyleProps(), xFac, false), m_rImport );
238 : }
239 0 : xMapper = m_xTableImpPropMapper;
240 : }
241 0 : break;
242 : default:
243 0 : break;
244 : }
245 : }
246 :
247 0 : return xMapper;
248 : }
249 :
250 0 : SvXMLStyleContext *OReportStylesContext::CreateDefaultStyleStyleChildContext(
251 : sal_uInt16 nFamily, sal_uInt16 nPrefix, const OUString& rLocalName,
252 : const uno::Reference< xml::sax::XAttributeList > & xAttrList )
253 : {
254 0 : SvXMLStyleContext *pStyle = 0;
255 :
256 0 : switch( nFamily )
257 : {
258 : case XML_STYLE_FAMILY_SD_GRAPHICS_ID:
259 : // There are no writer specific defaults for graphic styles!
260 0 : pStyle = new XMLGraphicsDefaultStyle( GetImport(), nPrefix,
261 0 : rLocalName, xAttrList, *this );
262 0 : break;
263 : default:
264 : pStyle = SvXMLStylesContext::CreateDefaultStyleStyleChildContext( nFamily,
265 : nPrefix,
266 : rLocalName,
267 0 : xAttrList );
268 0 : break;
269 : }
270 0 : return pStyle;
271 : }
272 :
273 0 : SvXMLStyleContext *OReportStylesContext::CreateStyleStyleChildContext(
274 : sal_uInt16 nFamily, sal_uInt16 nPrefix, const OUString& rLocalName,
275 : const Reference< xml::sax::XAttributeList > & xAttrList )
276 : {
277 : SvXMLStyleContext *pStyle = SvXMLStylesContext::CreateStyleStyleChildContext( nFamily, nPrefix,
278 : rLocalName,
279 0 : xAttrList );
280 0 : if (!pStyle)
281 : {
282 0 : switch( nFamily )
283 : {
284 : case XML_STYLE_FAMILY_TABLE_TABLE:
285 : case XML_STYLE_FAMILY_TABLE_COLUMN:
286 : case XML_STYLE_FAMILY_TABLE_ROW:
287 : case XML_STYLE_FAMILY_TABLE_CELL:
288 : pStyle = new OControlStyleContext( GetOwnImport(), nPrefix, rLocalName,
289 0 : xAttrList, *this, nFamily );
290 0 : break;
291 : default:
292 : OSL_FAIL("OReportStylesContext::CreateStyleStyleChildContext: Unknown style family. PLease check.");
293 0 : break;
294 : }
295 : }
296 :
297 0 : return pStyle;
298 : }
299 :
300 : Reference < XNameContainer >
301 0 : OReportStylesContext::GetStylesContainer( sal_uInt16 nFamily ) const
302 : {
303 0 : Reference < XNameContainer > xStyles(SvXMLStylesContext::GetStylesContainer(nFamily));
304 0 : if (!xStyles.is())
305 : {
306 0 : OUString sName;
307 0 : switch( nFamily )
308 : {
309 : case XML_STYLE_FAMILY_TABLE_TABLE:
310 : {
311 0 : if( m_xTableStyles.is() )
312 0 : xStyles.set(m_xTableStyles);
313 : else
314 0 : sName =
315 0 : OUString( OUString( "TableStyles" ));
316 : }
317 0 : break;
318 : case XML_STYLE_FAMILY_TABLE_CELL:
319 : {
320 0 : if( m_xCellStyles.is() )
321 0 : xStyles.set(m_xCellStyles);
322 : else
323 0 : sName =
324 0 : OUString( OUString( "CellStyles" ));
325 : }
326 0 : break;
327 : case XML_STYLE_FAMILY_TABLE_COLUMN:
328 : {
329 0 : if( m_xColumnStyles.is() )
330 0 : xStyles.set(m_xColumnStyles);
331 : else
332 0 : sName =
333 0 : OUString( OUString( "ColumnStyles" ));
334 : }
335 0 : break;
336 : case XML_STYLE_FAMILY_TABLE_ROW:
337 : {
338 0 : if( m_xRowStyles.is() )
339 0 : xStyles.set(m_xRowStyles);
340 : else
341 0 : sName =
342 0 : OUString( OUString( "RowStyles" ));
343 : }
344 0 : break;
345 : case XML_STYLE_FAMILY_SD_GRAPHICS_ID:
346 0 : xStyles = ((SvXMLImport *)&GetImport())->GetTextImport()->GetFrameStyles();
347 0 : break;
348 : default:
349 : OSL_FAIL("OReportStylesContext::CreateStyleStyleChildContext: Unknown style family. PLease check.");
350 0 : break;
351 : }
352 0 : if( !xStyles.is() && !sName.isEmpty() && GetOwnImport().GetModel().is() )
353 : {
354 : Reference< XStyleFamiliesSupplier > xFamiliesSupp(
355 0 : GetOwnImport().GetModel(), UNO_QUERY );
356 0 : if (xFamiliesSupp.is())
357 : {
358 0 : Reference< XNameAccess > xFamilies(xFamiliesSupp->getStyleFamilies());
359 :
360 0 : xStyles.set(xFamilies->getByName( sName ), uno::UNO_QUERY);
361 0 : switch( nFamily )
362 : {
363 : case XML_STYLE_FAMILY_TABLE_TABLE:
364 0 : m_xTableStyles.set(xStyles);
365 0 : break;
366 : case XML_STYLE_FAMILY_TABLE_CELL:
367 0 : m_xCellStyles.set(xStyles);
368 0 : break;
369 : case XML_STYLE_FAMILY_TABLE_COLUMN:
370 0 : m_xColumnStyles.set(xStyles);
371 0 : break;
372 : case XML_STYLE_FAMILY_TABLE_ROW:
373 0 : m_xRowStyles.set(xStyles);
374 0 : break;
375 : default:
376 0 : break;
377 0 : }
378 0 : }
379 0 : }
380 : }
381 :
382 0 : return xStyles;
383 : }
384 :
385 :
386 0 : OUString OReportStylesContext::GetServiceName( sal_uInt16 nFamily ) const
387 : {
388 0 : OUString sServiceName = SvXMLStylesContext::GetServiceName(nFamily);
389 0 : if (sServiceName.isEmpty())
390 : {
391 0 : switch( nFamily )
392 : {
393 : case XML_STYLE_FAMILY_TABLE_TABLE:
394 0 : sServiceName = m_sTableStyleFamilyName;
395 0 : break;
396 : case XML_STYLE_FAMILY_TABLE_COLUMN:
397 0 : sServiceName = m_sColumnStyleFamilyName;
398 0 : break;
399 : case XML_STYLE_FAMILY_TABLE_ROW:
400 0 : sServiceName = m_sRowStyleFamilyName;
401 0 : break;
402 : case XML_STYLE_FAMILY_TABLE_CELL:
403 0 : sServiceName = m_sCellStyleFamilyName;
404 0 : break;
405 : default:
406 0 : break;
407 : }
408 : }
409 0 : return sServiceName;
410 : }
411 :
412 :
413 0 : sal_Int32 OReportStylesContext::GetIndex(const sal_Int16 nContextID)
414 : {
415 0 : if ( nContextID == CTF_RPT_NUMBERFORMAT )
416 : {
417 0 : if (m_nNumberFormatIndex == -1)
418 : m_nNumberFormatIndex =
419 0 : GetImportPropertyMapper(XML_STYLE_FAMILY_TABLE_CELL)->getPropertySetMapper()->FindEntryIndex(nContextID);
420 0 : return m_nNumberFormatIndex;
421 : }
422 0 : return -1;
423 : }
424 :
425 0 : ORptFilter& OReportStylesContext::GetOwnImport() const
426 : {
427 0 : return m_rImport;
428 : }
429 :
430 0 : sal_uInt16 OReportStylesContext::GetFamily( const OUString& rFamily ) const
431 : {
432 0 : sal_uInt16 nFamily = SvXMLStylesContext::GetFamily(rFamily);
433 0 : return nFamily;
434 : }
435 :
436 : } // rptxml
437 :
438 :
439 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|