1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include "xmlStyleImport.hxx"
#include <xmloff/maptype.hxx>
#include <xmloff/nmspmap.hxx>
#include <xmloff/xmlnmspe.hxx>
#include <xmloff/xmlimppr.hxx>
#include <xmloff/txtimppr.hxx>
#include <xmloff/families.hxx>
#include <xmloff/xmlnumfi.hxx>
#include <xmloff/xmltoken.hxx>
#include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
#include <com/sun/star/container/XNameContainer.hpp>
#include <xmloff/xmlprcon.hxx>
#include <xmloff/xmluconv.hxx>
#include <xmloff/XMLGraphicsDefaultStyle.hxx>
#include "xmlfilter.hxx"
#include "xmlHelper.hxx"
#include <osl/diagnose.h>
namespace rptxml
{
using namespace ::com::sun::star;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::xml::sax;
using namespace ::com::sun::star::style;
using namespace ::com::sun::star::beans;
using namespace ::com::sun::star::container;
using namespace xmloff::token;
namespace {
class OSpecialHanldeXMLImportPropertyMapper : public SvXMLImportPropertyMapper
{
public:
OSpecialHanldeXMLImportPropertyMapper(const rtl::Reference< XMLPropertySetMapper >& rMapper,SvXMLImport& _rImport) : SvXMLImportPropertyMapper(rMapper ,_rImport)
{
}
/** this method is called for every item that has the MID_FLAG_SPECIAL_ITEM_IMPORT flag set */
virtual bool handleSpecialItem(
XMLPropertyState& /*rProperty*/,
::std::vector< XMLPropertyState >& /*rProperties*/,
const OUString& /*rValue*/,
const SvXMLUnitConverter& /*rUnitConverter*/,
const SvXMLNamespaceMap& /*rNamespaceMap*/ ) const override
{
// nothing to do here
return true;
}
};
}
OControlStyleContext::OControlStyleContext( ORptFilter& rImport,
sal_uInt16 nPrfx, const OUString& rLName,
const Reference< XAttributeList > & xAttrList,
SvXMLStylesContext& rStyles, XmlStyleFamily nFamily ) :
XMLPropStyleContext( rImport, nPrfx, rLName, xAttrList, rStyles, nFamily, false/*bDefaultStyle*/ ),
pStyles(&rStyles),
m_nNumberFormat(-1),
m_rImport(rImport)
{
}
OControlStyleContext::~OControlStyleContext()
{
}
void OControlStyleContext::FillPropertySet(const Reference< XPropertySet > & rPropSet )
{
if ( !IsDefaultStyle() )
{
if ( GetFamily() == XmlStyleFamily::TABLE_CELL )
{
if ((m_nNumberFormat == -1) && !m_sDataStyleName.isEmpty())
{
SvXMLNumFormatContext* pStyle = const_cast< SvXMLNumFormatContext*>(dynamic_cast<const SvXMLNumFormatContext*>(pStyles->FindStyleChildContext(
XmlStyleFamily::DATA_STYLE, m_sDataStyleName)));
if ( !pStyle )
{
OReportStylesContext* pMyStyles = dynamic_cast< OReportStylesContext *>(m_rImport.GetAutoStyles());
if ( pMyStyles )
pStyle = const_cast<SvXMLNumFormatContext*>(dynamic_cast< const SvXMLNumFormatContext *>(pMyStyles->
FindStyleChildContext(XmlStyleFamily::DATA_STYLE, m_sDataStyleName, true)));
else {
OSL_FAIL("not possible to get style");
}
}
if ( pStyle )
{
m_nNumberFormat = pStyle->GetKey();
AddProperty(CTF_RPT_NUMBERFORMAT, uno::makeAny(m_nNumberFormat));
}
}
}
}
XMLPropStyleContext::FillPropertySet(rPropSet);
}
void OControlStyleContext::SetDefaults()
{
}
void OControlStyleContext::AddProperty(const sal_Int16 nContextID, const uno::Any& rValue)
{
sal_Int32 nIndex(static_cast<OReportStylesContext *>(pStyles)->GetIndex(nContextID));
OSL_ENSURE(nIndex != -1, "Property not found in Map");
XMLPropertyState aPropState(nIndex, rValue);
GetProperties().push_back(aPropState); // has to be inserted in a sort order later
}
void OControlStyleContext::SetAttribute( sal_uInt16 nPrefixKey,
const OUString& rLocalName,
const OUString& rValue )
{
// TODO: use a map here
if( IsXMLToken(rLocalName, XML_DATA_STYLE_NAME ) )
m_sDataStyleName = rValue;
else if ( IsXMLToken(rLocalName, XML_MASTER_PAGE_NAME ) )
;
else
XMLPropStyleContext::SetAttribute( nPrefixKey, rLocalName, rValue );
}
static const OUStringLiteral g_sTableStyleFamilyName( XML_STYLE_FAMILY_TABLE_TABLE_STYLES_NAME );
static const OUStringLiteral g_sColumnStyleFamilyName( XML_STYLE_FAMILY_TABLE_COLUMN_STYLES_NAME );
static const OUStringLiteral g_sRowStyleFamilyName( XML_STYLE_FAMILY_TABLE_ROW_STYLES_NAME );
static const OUStringLiteral g_sCellStyleFamilyName( XML_STYLE_FAMILY_TABLE_CELL_STYLES_NAME );
OReportStylesContext::OReportStylesContext( ORptFilter& rImport,
const bool bTempAutoStyles ) :
SvXMLStylesContext( rImport ),
m_rImport(rImport),
m_nNumberFormatIndex(-1),
bAutoStyles(bTempAutoStyles)
{
}
OReportStylesContext::~OReportStylesContext()
{
}
void OReportStylesContext::endFastElement(sal_Int32 nElement)
{
SvXMLStylesContext::endFastElement(nElement);
if (bAutoStyles)
GetImport().GetTextImport()->SetAutoStyles( this );
else
GetImport().GetStyles()->CopyStylesToDoc(true);
}
rtl::Reference < SvXMLImportPropertyMapper >
OReportStylesContext::GetImportPropertyMapper(
XmlStyleFamily nFamily ) const
{
rtl::Reference < SvXMLImportPropertyMapper > xMapper(SvXMLStylesContext::GetImportPropertyMapper(nFamily));
if (!xMapper.is())
{
ORptFilter& rImport = GetOwnImport();
switch( nFamily )
{
case XmlStyleFamily::TABLE_CELL:
{
if( !m_xCellImpPropMapper.is() )
{
m_xCellImpPropMapper =
new XMLTextImportPropertyMapper/*OSpecialHanldeXMLImportPropertyMapper*/( rImport.GetCellStylesPropertySetMapper(), m_rImport );
m_xCellImpPropMapper->ChainImportMapper(XMLTextImportHelper::CreateParaExtPropMapper(m_rImport));
}
xMapper = m_xCellImpPropMapper;
}
break;
case XmlStyleFamily::TABLE_COLUMN:
{
if( !m_xColumnImpPropMapper.is() )
m_xColumnImpPropMapper =
new SvXMLImportPropertyMapper( rImport.GetColumnStylesPropertySetMapper(), m_rImport );
xMapper = m_xColumnImpPropMapper;
}
break;
case XmlStyleFamily::TABLE_ROW:
{
if( !m_xRowImpPropMapper.is() )
m_xRowImpPropMapper =new OSpecialHanldeXMLImportPropertyMapper( rImport.GetRowStylesPropertySetMapper(), m_rImport );
xMapper = m_xRowImpPropMapper;
}
break;
case XmlStyleFamily::TABLE_TABLE:
{
if( !m_xTableImpPropMapper.is() )
{
rtl::Reference < XMLPropertyHandlerFactory> xFac = new ::xmloff::OControlPropertyHandlerFactory();
m_xTableImpPropMapper = new SvXMLImportPropertyMapper( new XMLPropertySetMapper(OXMLHelper::GetTableStyleProps(), xFac, false), m_rImport );
}
xMapper = m_xTableImpPropMapper;
}
break;
default:
break;
}
}
return xMapper;
}
SvXMLStyleContext *OReportStylesContext::CreateDefaultStyleStyleChildContext(
XmlStyleFamily nFamily, sal_uInt16 nPrefix, const OUString& rLocalName,
const uno::Reference< xml::sax::XAttributeList > & xAttrList )
{
SvXMLStyleContext *pStyle = nullptr;
switch( nFamily )
{
case XmlStyleFamily::SD_GRAPHICS_ID:
// There are no writer specific defaults for graphic styles!
pStyle = new XMLGraphicsDefaultStyle( GetImport(), nPrefix,
rLocalName, xAttrList, *this );
break;
default:
pStyle = SvXMLStylesContext::CreateDefaultStyleStyleChildContext( nFamily,
nPrefix,
rLocalName,
xAttrList );
break;
}
return pStyle;
}
SvXMLStyleContext *OReportStylesContext::CreateStyleStyleChildContext(
XmlStyleFamily nFamily, sal_uInt16 nPrefix, const OUString& rLocalName,
const Reference< xml::sax::XAttributeList > & xAttrList )
{
SvXMLStyleContext *pStyle = SvXMLStylesContext::CreateStyleStyleChildContext( nFamily, nPrefix,
rLocalName,
xAttrList );
if (!pStyle)
{
switch( nFamily )
{
case XmlStyleFamily::TABLE_TABLE:
case XmlStyleFamily::TABLE_COLUMN:
case XmlStyleFamily::TABLE_ROW:
case XmlStyleFamily::TABLE_CELL:
pStyle = new OControlStyleContext( GetOwnImport(), nPrefix, rLocalName,
xAttrList, *this, nFamily );
break;
default:
OSL_FAIL("OReportStylesContext::CreateStyleStyleChildContext: Unknown style family. Please check.");
break;
}
}
return pStyle;
}
Reference < XNameContainer >
OReportStylesContext::GetStylesContainer( XmlStyleFamily nFamily ) const
{
Reference < XNameContainer > xStyles(SvXMLStylesContext::GetStylesContainer(nFamily));
if (!xStyles.is())
{
OUString sName;
switch( nFamily )
{
case XmlStyleFamily::TABLE_TABLE:
{
if( m_xTableStyles.is() )
xStyles.set(m_xTableStyles);
else
sName = "TableStyles";
}
break;
case XmlStyleFamily::TABLE_CELL:
{
if( m_xCellStyles.is() )
xStyles.set(m_xCellStyles);
else
sName = "CellStyles";
}
break;
case XmlStyleFamily::TABLE_COLUMN:
{
if( m_xColumnStyles.is() )
xStyles.set(m_xColumnStyles);
else
sName = "ColumnStyles";
}
break;
case XmlStyleFamily::TABLE_ROW:
{
if( m_xRowStyles.is() )
xStyles.set(m_xRowStyles);
else
sName = "RowStyles";
}
break;
case XmlStyleFamily::SD_GRAPHICS_ID:
xStyles = const_cast<SvXMLImport *>(&GetImport())->GetTextImport()->GetFrameStyles();
break;
default:
OSL_FAIL("OReportStylesContext::CreateStyleStyleChildContext: Unknown style family. Please check.");
break;
}
if( !xStyles.is() && !sName.isEmpty() && GetOwnImport().GetModel().is() )
{
Reference< XStyleFamiliesSupplier > xFamiliesSupp(
GetOwnImport().GetModel(), UNO_QUERY );
if (xFamiliesSupp.is())
{
Reference< XNameAccess > xFamilies(xFamiliesSupp->getStyleFamilies());
xStyles.set(xFamilies->getByName( sName ), uno::UNO_QUERY);
switch( nFamily )
{
case XmlStyleFamily::TABLE_TABLE:
m_xTableStyles.set(xStyles);
break;
case XmlStyleFamily::TABLE_CELL:
m_xCellStyles.set(xStyles);
break;
case XmlStyleFamily::TABLE_COLUMN:
m_xColumnStyles.set(xStyles);
break;
case XmlStyleFamily::TABLE_ROW:
m_xRowStyles.set(xStyles);
break;
default:
break;
}
}
}
}
return xStyles;
}
OUString OReportStylesContext::GetServiceName( XmlStyleFamily nFamily ) const
{
OUString sServiceName = SvXMLStylesContext::GetServiceName(nFamily);
if (sServiceName.isEmpty())
{
switch( nFamily )
{
case XmlStyleFamily::TABLE_TABLE:
sServiceName = g_sTableStyleFamilyName;
break;
case XmlStyleFamily::TABLE_COLUMN:
sServiceName = g_sColumnStyleFamilyName;
break;
case XmlStyleFamily::TABLE_ROW:
sServiceName = g_sRowStyleFamilyName;
break;
case XmlStyleFamily::TABLE_CELL:
sServiceName = g_sCellStyleFamilyName;
break;
default:
break;
}
}
return sServiceName;
}
sal_Int32 OReportStylesContext::GetIndex(const sal_Int16 nContextID)
{
if ( nContextID == CTF_RPT_NUMBERFORMAT )
{
if (m_nNumberFormatIndex == -1)
m_nNumberFormatIndex =
GetImportPropertyMapper(XmlStyleFamily::TABLE_CELL)->getPropertySetMapper()->FindEntryIndex(nContextID);
return m_nNumberFormatIndex;
}
return -1;
}
} // rptxml
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|