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