Branch data 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 : :
20 : :
21 : : #include "xmlStyleImport.hxx"
22 : :
23 : : #include <xmloff/nmspmap.hxx>
24 : : #include <xmloff/xmlnmspe.hxx>
25 : : #include <xmloff/xmlimppr.hxx>
26 : : #include <xmloff/families.hxx>
27 : : #include <xmloff/xmlnumfi.hxx>
28 : : #include <xmloff/xmltoken.hxx>
29 : : #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
30 : : #include <com/sun/star/container/XNameContainer.hpp>
31 : : #include <com/sun/star/table/BorderLine.hpp>
32 : : #include <comphelper/extract.hxx>
33 : : #include <xmloff/xmlprcon.hxx>
34 : : #include <xmloff/xmluconv.hxx>
35 : : #include <osl/diagnose.h>
36 : : #include "xmlfilter.hxx"
37 : : #include "xmlHelper.hxx"
38 : :
39 : :
40 : : #define XML_LINE_LEFT 0
41 : : #define XML_LINE_RIGHT 1
42 : : #define XML_LINE_TOP 2
43 : : #define XML_LINE_BOTTOM 3
44 : :
45 : : namespace dbaxml
46 : : {
47 : :
48 : : using namespace ::com::sun::star;
49 : : using namespace ::com::sun::star::uno;
50 : : using namespace ::com::sun::star::xml::sax;
51 : : using namespace ::com::sun::star::style;
52 : : using namespace ::com::sun::star::frame;
53 : : using namespace ::com::sun::star::beans;
54 : : using namespace ::com::sun::star::container;
55 : : using namespace xmloff::token;
56 : :
57 : : // -----------------------------------------------------------------------------
58 [ + - ][ # # ]: 2880 : TYPEINIT1( OTableStyleContext, XMLPropStyleContext );
59 [ # # ][ # # ]: 0 : TYPEINIT1( OTableStylesContext, SvXMLStylesContext );
60 : : DBG_NAME(OTableStyleContext)
61 : :
62 : 144 : OTableStyleContext::OTableStyleContext( ODBFilter& rImport,
63 : : sal_uInt16 nPrfx, const ::rtl::OUString& rLName,
64 : : const Reference< XAttributeList > & xAttrList,
65 : : SvXMLStylesContext& rStyles, sal_uInt16 nFamily, sal_Bool bDefaultStyle )
66 : : :XMLPropStyleContext( rImport, nPrfx, rLName, xAttrList, rStyles, nFamily, bDefaultStyle )
67 : : ,sNumberFormat(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("NumberFormat")))
68 : : ,pStyles(&rStyles)
69 : : ,m_nNumberFormat(-1)
70 : : ,bConditionalFormatCreated(sal_False)
71 [ + - ]: 144 : ,bParentSet(sal_False)
72 : : {
73 : : DBG_CTOR(OTableStyleContext,NULL);
74 : :
75 : 144 : }
76 : : // -----------------------------------------------------------------------------
77 : :
78 : 144 : OTableStyleContext::~OTableStyleContext()
79 : : {
80 : :
81 : : DBG_DTOR(OTableStyleContext,NULL);
82 [ - + ]: 288 : }
83 : : // -----------------------------------------------------------------------------
84 : :
85 : 1080 : void OTableStyleContext::FillPropertySet(
86 : : const Reference< XPropertySet > & rPropSet )
87 : : {
88 [ + - ]: 1080 : if ( !IsDefaultStyle() )
89 : : {
90 [ - + ]: 1080 : if ( GetFamily() == XML_STYLE_FAMILY_TABLE_TABLE )
91 : : {
92 [ # # ]: 0 : if ( !sPageStyle.isEmpty() )
93 : : {
94 : 0 : uno::Any aAny;
95 [ # # ]: 0 : aAny <<= sPageStyle;
96 [ # # ]: 0 : AddProperty(CTF_DB_MASTERPAGENAME, aAny);
97 : : }
98 : : }
99 [ + + ]: 1080 : else if ( GetFamily() == XML_STYLE_FAMILY_TABLE_COLUMN )
100 : : {
101 [ + - ][ - + ]: 360 : if ((m_nNumberFormat == -1) && !m_sDataStyleName.isEmpty())
[ - + ]
102 : : {
103 [ # # ][ # # ]: 0 : SvXMLNumFormatContext* pStyle = PTR_CAST(SvXMLNumFormatContext,pStyles->FindStyleChildContext(
104 : : XML_STYLE_FAMILY_DATA_STYLE, m_sDataStyleName, sal_True));
105 [ # # ]: 0 : if ( !pStyle )
106 : : {
107 [ # # ][ # # ]: 0 : OTableStylesContext* pMyStyles = PTR_CAST(OTableStylesContext,GetOwnImport().GetAutoStyles());
108 [ # # ]: 0 : if ( pMyStyles )
109 : 0 : pStyle = PTR_CAST(SvXMLNumFormatContext,pMyStyles->
110 [ # # # # ]: 0 : FindStyleChildContext(XML_STYLE_FAMILY_DATA_STYLE, m_sDataStyleName, sal_True));
111 : : else {
112 : : OSL_FAIL("not possible to get style");
113 : : }
114 : : }
115 [ # # ]: 0 : if ( pStyle )
116 : : {
117 : 0 : uno::Any aNumberFormat;
118 [ # # ]: 0 : m_nNumberFormat = pStyle->GetKey();
119 [ # # ]: 0 : aNumberFormat <<= m_nNumberFormat;
120 [ # # ]: 0 : AddProperty(CTF_DB_NUMBERFORMAT, aNumberFormat);
121 : : }
122 : : }
123 : : }
124 : : }
125 : 1080 : XMLPropStyleContext::FillPropertySet(rPropSet);
126 : 1080 : }
127 : : // -----------------------------------------------------------------------------
128 : :
129 : 0 : void OTableStyleContext::SetDefaults()
130 : : {
131 : 0 : }
132 : : // -----------------------------------------------------------------------------
133 : :
134 : 0 : void OTableStyleContext::AddProperty(const sal_Int16 nContextID, const uno::Any& rValue)
135 : : {
136 [ # # ]: 0 : sal_Int32 nIndex(static_cast<OTableStylesContext *>(pStyles)->GetIndex(nContextID));
137 : : OSL_ENSURE(nIndex != -1, "Property not found in Map");
138 : 0 : XMLPropertyState aPropState(nIndex, rValue);
139 [ # # ]: 0 : GetProperties().push_back(aPropState); // has to be insertes in a sort order later
140 : 0 : }
141 : : // -----------------------------------------------------------------------------
142 : 288 : void OTableStyleContext::SetAttribute( sal_uInt16 nPrefixKey,
143 : : const ::rtl::OUString& rLocalName,
144 : : const ::rtl::OUString& rValue )
145 : : {
146 : : // TODO: use a map here
147 [ - + ]: 288 : if( IsXMLToken(rLocalName, XML_DATA_STYLE_NAME ) )
148 : 0 : m_sDataStyleName = rValue;
149 [ - + ]: 288 : else if ( IsXMLToken(rLocalName, XML_MASTER_PAGE_NAME ) )
150 : 0 : sPageStyle = rValue;
151 : : else
152 : 288 : XMLPropStyleContext::SetAttribute( nPrefixKey, rLocalName, rValue );
153 : 288 : }
154 : : // -----------------------------------------------------------------------------
155 : 0 : ODBFilter& OTableStyleContext::GetOwnImport()
156 : : {
157 : 0 : return static_cast<ODBFilter&>(GetImport());
158 : : }
159 : : // -----------------------------------------------------------------------------
160 : : DBG_NAME(OTableStylesContext)
161 : :
162 : 14 : OTableStylesContext::OTableStylesContext( SvXMLImport& rImport,
163 : : sal_uInt16 nPrfx ,
164 : : const ::rtl::OUString& rLName ,
165 : : const Reference< XAttributeList > & xAttrList,
166 : : const sal_Bool bTempAutoStyles ) :
167 : : SvXMLStylesContext( rImport, nPrfx, rLName, xAttrList ),
168 : : sTableStyleServiceName( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( XML_STYLE_FAMILY_TABLE_TABLE_STYLES_NAME ))),
169 : : sColumnStyleServiceName( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( XML_STYLE_FAMILY_TABLE_COLUMN_STYLES_NAME ))),
170 : : sCellStyleServiceName( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( XML_STYLE_FAMILY_TABLE_CELL_STYLES_NAME ))),
171 : : m_nNumberFormatIndex(-1),
172 [ + - ][ + - ]: 14 : bAutoStyles(bTempAutoStyles)
[ + - ]
173 : : {
174 : : DBG_CTOR(OTableStylesContext,NULL);
175 : :
176 : 14 : }
177 : : // -----------------------------------------------------------------------------
178 : :
179 [ + - ][ + - ]: 14 : OTableStylesContext::~OTableStylesContext()
[ + - ]
180 : : {
181 : :
182 : : DBG_DTOR(OTableStylesContext,NULL);
183 [ - + ]: 28 : }
184 : : // -----------------------------------------------------------------------------
185 : :
186 : 14 : void OTableStylesContext::EndElement()
187 : : {
188 : 14 : SvXMLStylesContext::EndElement();
189 [ + - ]: 14 : if (bAutoStyles)
190 [ + - ][ + - ]: 14 : GetImport().GetTextImport()->SetAutoStyles( this );
191 : : else
192 : 0 : GetImport().GetStyles()->CopyStylesToDoc(sal_True);
193 : 14 : }
194 : : // -----------------------------------------------------------------------------
195 : :
196 : : UniReference < SvXMLImportPropertyMapper >
197 : 1212 : OTableStylesContext::GetImportPropertyMapper(
198 : : sal_uInt16 nFamily ) const
199 : : {
200 : 1212 : UniReference < SvXMLImportPropertyMapper > xMapper = SvXMLStylesContext::GetImportPropertyMapper(nFamily);
201 : :
202 [ + - ]: 1212 : if (!xMapper.is())
203 : : {
204 [ - + + - ]: 1212 : switch( nFamily )
205 : : {
206 : : case XML_STYLE_FAMILY_TABLE_TABLE:
207 : : {
208 [ # # ]: 0 : if ( !m_xTableImpPropMapper.is() )
209 [ # # ][ # # ]: 0 : m_xTableImpPropMapper = new SvXMLImportPropertyMapper( const_cast<OTableStylesContext*>(this)->GetOwnImport().GetTableStylesPropertySetMapper(), const_cast<SvXMLImport&>(GetImport()) );
[ # # ][ # # ]
[ # # ]
210 [ # # ]: 0 : xMapper = m_xTableImpPropMapper;
211 : : }
212 : 0 : break;
213 : : case XML_STYLE_FAMILY_TABLE_COLUMN:
214 : : {
215 [ + + ]: 480 : if ( !m_xColumnImpPropMapper.is() )
216 [ + - ][ + - ]: 12 : m_xColumnImpPropMapper = new SvXMLImportPropertyMapper( const_cast<OTableStylesContext*>(this)->GetOwnImport().GetColumnStylesPropertySetMapper(), const_cast<SvXMLImport&>(GetImport()) );
[ + - ][ + - ]
[ + - ]
217 [ + - ]: 480 : xMapper = m_xColumnImpPropMapper;
218 : : }
219 : 480 : break;
220 : : case XML_STYLE_FAMILY_TABLE_CELL:
221 : : {
222 [ + + ]: 732 : if ( !m_xCellImpPropMapper.is() )
223 [ + - ][ + - ]: 12 : m_xCellImpPropMapper = new SvXMLImportPropertyMapper( const_cast<OTableStylesContext*>(this)->GetOwnImport().GetCellStylesPropertySetMapper(), const_cast<SvXMLImport&>(GetImport()) );
[ + - ][ + - ]
[ + - ]
224 [ + - ]: 732 : xMapper = m_xCellImpPropMapper;
225 : : }
226 : 1212 : break;
227 : : }
228 : : }
229 : :
230 : 1212 : return xMapper;
231 : : }
232 : : // ----------------------------------------------------------------------------
233 : 144 : SvXMLStyleContext *OTableStylesContext::CreateStyleStyleChildContext(
234 : : sal_uInt16 nFamily, sal_uInt16 nPrefix, const ::rtl::OUString& rLocalName,
235 : : const Reference< xml::sax::XAttributeList > & xAttrList )
236 : : {
237 : : SvXMLStyleContext *pStyle = SvXMLStylesContext::CreateStyleStyleChildContext( nFamily, nPrefix,
238 : : rLocalName,
239 : 144 : xAttrList );
240 [ + - ]: 144 : if (!pStyle)
241 : : {
242 [ + - ]: 144 : switch( nFamily )
243 : : {
244 : : case XML_STYLE_FAMILY_TABLE_TABLE:
245 : : case XML_STYLE_FAMILY_TABLE_COLUMN:
246 : : case XML_STYLE_FAMILY_TABLE_CELL:
247 : : pStyle = new OTableStyleContext( GetOwnImport(), nPrefix, rLocalName,
248 [ + - ]: 144 : xAttrList, *this, nFamily );
249 : 144 : break;
250 : : }
251 : : }
252 : :
253 : 144 : return pStyle;
254 : : }
255 : : // -----------------------------------------------------------------------------
256 : : Reference < XNameContainer >
257 : 0 : OTableStylesContext::GetStylesContainer( sal_uInt16 nFamily ) const
258 : : {
259 : 0 : Reference < XNameContainer > xStyles = SvXMLStylesContext::GetStylesContainer(nFamily);
260 : 0 : return xStyles;
261 : : }
262 : : // -----------------------------------------------------------------------------
263 : :
264 : 0 : ::rtl::OUString OTableStylesContext::GetServiceName( sal_uInt16 nFamily ) const
265 : : {
266 : 0 : rtl::OUString sServiceName = SvXMLStylesContext::GetServiceName(nFamily);
267 [ # # ]: 0 : if (sServiceName.isEmpty())
268 : : {
269 [ # # # # ]: 0 : switch( nFamily )
270 : : {
271 : : case XML_STYLE_FAMILY_TABLE_TABLE:
272 : 0 : sServiceName = sTableStyleServiceName;
273 : 0 : break;
274 : : case XML_STYLE_FAMILY_TABLE_COLUMN:
275 : 0 : sServiceName = sColumnStyleServiceName;
276 : 0 : break;
277 : : case XML_STYLE_FAMILY_TABLE_CELL:
278 : 0 : sServiceName = sCellStyleServiceName;
279 : 0 : break;
280 : :
281 : : }
282 : : }
283 : 0 : return sServiceName;
284 : : }
285 : : // -----------------------------------------------------------------------------
286 : :
287 : 0 : sal_Int32 OTableStylesContext::GetIndex(const sal_Int16 nContextID)
288 : : {
289 [ # # ]: 0 : if ( nContextID == CTF_DB_NUMBERFORMAT )
290 : : {
291 [ # # ]: 0 : if (m_nNumberFormatIndex == -1)
292 : : m_nNumberFormatIndex =
293 [ # # ][ # # ]: 0 : GetImportPropertyMapper(XML_STYLE_FAMILY_TABLE_COLUMN)->getPropertySetMapper()->FindEntryIndex(nContextID);
[ # # ]
294 : 0 : return m_nNumberFormatIndex;
295 : : }
296 [ # # ]: 0 : else if ( nContextID == CTF_DB_MASTERPAGENAME )
297 : : {
298 [ # # ]: 0 : if (nMasterPageNameIndex == -1)
299 : : nMasterPageNameIndex =
300 [ # # ][ # # ]: 0 : GetImportPropertyMapper(XML_STYLE_FAMILY_TABLE_TABLE)->getPropertySetMapper()->FindEntryIndex(nContextID);
[ # # ]
301 : 0 : return nMasterPageNameIndex;
302 : : }
303 : : else
304 : 0 : return -1;
305 : : }
306 : : // -----------------------------------------------------------------------------
307 : 168 : ODBFilter& OTableStylesContext::GetOwnImport()
308 : : {
309 : 168 : return static_cast<ODBFilter&>(GetImport());
310 : : }
311 : : // -----------------------------------------------------------------------------
312 : : } // dbaxml
313 : : // -----------------------------------------------------------------------------
314 : :
315 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|