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