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 0 : TYPEINIT1( OTableStyleContext, XMLPropStyleContext );
59 0 : TYPEINIT1( OTableStylesContext, SvXMLStylesContext );
60 : DBG_NAME(OTableStyleContext)
61 :
62 0 : 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 0 : ,m_nNumberFormat(-1)
70 : {
71 : DBG_CTOR(OTableStyleContext,NULL);
72 :
73 0 : }
74 : // -----------------------------------------------------------------------------
75 :
76 0 : OTableStyleContext::~OTableStyleContext()
77 : {
78 :
79 : DBG_DTOR(OTableStyleContext,NULL);
80 0 : }
81 : // -----------------------------------------------------------------------------
82 :
83 0 : void OTableStyleContext::FillPropertySet(
84 : const Reference< XPropertySet > & rPropSet )
85 : {
86 0 : if ( !IsDefaultStyle() )
87 : {
88 0 : if ( GetFamily() == XML_STYLE_FAMILY_TABLE_TABLE )
89 : {
90 0 : if ( !sPageStyle.isEmpty() )
91 : {
92 0 : uno::Any aAny;
93 0 : aAny <<= sPageStyle;
94 0 : AddProperty(CTF_DB_MASTERPAGENAME, aAny);
95 : }
96 : }
97 0 : else if ( GetFamily() == XML_STYLE_FAMILY_TABLE_COLUMN )
98 : {
99 0 : if ((m_nNumberFormat == -1) && !m_sDataStyleName.isEmpty())
100 : {
101 0 : SvXMLNumFormatContext* pStyle = PTR_CAST(SvXMLNumFormatContext,pStyles->FindStyleChildContext(
102 : XML_STYLE_FAMILY_DATA_STYLE, m_sDataStyleName, sal_True));
103 0 : if ( !pStyle )
104 : {
105 0 : OTableStylesContext* pMyStyles = PTR_CAST(OTableStylesContext,GetOwnImport().GetAutoStyles());
106 0 : if ( pMyStyles )
107 0 : pStyle = PTR_CAST(SvXMLNumFormatContext,pMyStyles->
108 0 : FindStyleChildContext(XML_STYLE_FAMILY_DATA_STYLE, m_sDataStyleName, sal_True));
109 : else {
110 : OSL_FAIL("not possible to get style");
111 : }
112 : }
113 0 : if ( pStyle )
114 : {
115 0 : uno::Any aNumberFormat;
116 0 : m_nNumberFormat = pStyle->GetKey();
117 0 : aNumberFormat <<= m_nNumberFormat;
118 0 : AddProperty(CTF_DB_NUMBERFORMAT, aNumberFormat);
119 : }
120 : }
121 : }
122 : }
123 0 : XMLPropStyleContext::FillPropertySet(rPropSet);
124 0 : }
125 : // -----------------------------------------------------------------------------
126 :
127 0 : void OTableStyleContext::SetDefaults()
128 : {
129 0 : }
130 : // -----------------------------------------------------------------------------
131 :
132 0 : void OTableStyleContext::AddProperty(const sal_Int16 nContextID, const uno::Any& rValue)
133 : {
134 0 : sal_Int32 nIndex(static_cast<OTableStylesContext *>(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 OTableStyleContext::SetAttribute( sal_uInt16 nPrefixKey,
141 : const ::rtl::OUString& rLocalName,
142 : const ::rtl::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 : ODBFilter& OTableStyleContext::GetOwnImport()
154 : {
155 0 : return static_cast<ODBFilter&>(GetImport());
156 : }
157 : // -----------------------------------------------------------------------------
158 : DBG_NAME(OTableStylesContext)
159 :
160 0 : OTableStylesContext::OTableStylesContext( SvXMLImport& rImport,
161 : sal_uInt16 nPrfx ,
162 : const ::rtl::OUString& rLName ,
163 : const Reference< XAttributeList > & xAttrList,
164 : const sal_Bool bTempAutoStyles ) :
165 : SvXMLStylesContext( rImport, nPrfx, rLName, xAttrList ),
166 : sTableStyleServiceName( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( XML_STYLE_FAMILY_TABLE_TABLE_STYLES_NAME ))),
167 : sColumnStyleServiceName( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( XML_STYLE_FAMILY_TABLE_COLUMN_STYLES_NAME ))),
168 : sCellStyleServiceName( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( XML_STYLE_FAMILY_TABLE_CELL_STYLES_NAME ))),
169 : m_nNumberFormatIndex(-1),
170 0 : bAutoStyles(bTempAutoStyles)
171 : {
172 : DBG_CTOR(OTableStylesContext,NULL);
173 :
174 0 : }
175 : // -----------------------------------------------------------------------------
176 :
177 0 : OTableStylesContext::~OTableStylesContext()
178 : {
179 :
180 : DBG_DTOR(OTableStylesContext,NULL);
181 0 : }
182 : // -----------------------------------------------------------------------------
183 :
184 0 : void OTableStylesContext::EndElement()
185 : {
186 0 : SvXMLStylesContext::EndElement();
187 0 : if (bAutoStyles)
188 0 : GetImport().GetTextImport()->SetAutoStyles( this );
189 : else
190 0 : GetImport().GetStyles()->CopyStylesToDoc(sal_True);
191 0 : }
192 : // -----------------------------------------------------------------------------
193 :
194 : UniReference < SvXMLImportPropertyMapper >
195 0 : OTableStylesContext::GetImportPropertyMapper(
196 : sal_uInt16 nFamily ) const
197 : {
198 0 : UniReference < SvXMLImportPropertyMapper > xMapper = SvXMLStylesContext::GetImportPropertyMapper(nFamily);
199 :
200 0 : if (!xMapper.is())
201 : {
202 0 : switch( nFamily )
203 : {
204 : case XML_STYLE_FAMILY_TABLE_TABLE:
205 : {
206 0 : if ( !m_xTableImpPropMapper.is() )
207 0 : m_xTableImpPropMapper = new SvXMLImportPropertyMapper( const_cast<OTableStylesContext*>(this)->GetOwnImport().GetTableStylesPropertySetMapper(), const_cast<SvXMLImport&>(GetImport()) );
208 0 : xMapper = m_xTableImpPropMapper;
209 : }
210 0 : break;
211 : case XML_STYLE_FAMILY_TABLE_COLUMN:
212 : {
213 0 : if ( !m_xColumnImpPropMapper.is() )
214 0 : m_xColumnImpPropMapper = new SvXMLImportPropertyMapper( const_cast<OTableStylesContext*>(this)->GetOwnImport().GetColumnStylesPropertySetMapper(), const_cast<SvXMLImport&>(GetImport()) );
215 0 : xMapper = m_xColumnImpPropMapper;
216 : }
217 0 : break;
218 : case XML_STYLE_FAMILY_TABLE_CELL:
219 : {
220 0 : if ( !m_xCellImpPropMapper.is() )
221 0 : m_xCellImpPropMapper = new SvXMLImportPropertyMapper( const_cast<OTableStylesContext*>(this)->GetOwnImport().GetCellStylesPropertySetMapper(), const_cast<SvXMLImport&>(GetImport()) );
222 0 : xMapper = m_xCellImpPropMapper;
223 : }
224 0 : break;
225 : }
226 : }
227 :
228 0 : return xMapper;
229 : }
230 : // ----------------------------------------------------------------------------
231 0 : SvXMLStyleContext *OTableStylesContext::CreateStyleStyleChildContext(
232 : sal_uInt16 nFamily, sal_uInt16 nPrefix, const ::rtl::OUString& rLocalName,
233 : const Reference< xml::sax::XAttributeList > & xAttrList )
234 : {
235 : SvXMLStyleContext *pStyle = SvXMLStylesContext::CreateStyleStyleChildContext( nFamily, nPrefix,
236 : rLocalName,
237 0 : xAttrList );
238 0 : if (!pStyle)
239 : {
240 0 : switch( nFamily )
241 : {
242 : case XML_STYLE_FAMILY_TABLE_TABLE:
243 : case XML_STYLE_FAMILY_TABLE_COLUMN:
244 : case XML_STYLE_FAMILY_TABLE_CELL:
245 : pStyle = new OTableStyleContext( GetOwnImport(), nPrefix, rLocalName,
246 0 : xAttrList, *this, nFamily );
247 0 : break;
248 : }
249 : }
250 :
251 0 : return pStyle;
252 : }
253 : // -----------------------------------------------------------------------------
254 : Reference < XNameContainer >
255 0 : OTableStylesContext::GetStylesContainer( sal_uInt16 nFamily ) const
256 : {
257 0 : Reference < XNameContainer > xStyles = SvXMLStylesContext::GetStylesContainer(nFamily);
258 0 : return xStyles;
259 : }
260 : // -----------------------------------------------------------------------------
261 :
262 0 : ::rtl::OUString OTableStylesContext::GetServiceName( sal_uInt16 nFamily ) const
263 : {
264 0 : rtl::OUString sServiceName = SvXMLStylesContext::GetServiceName(nFamily);
265 0 : if (sServiceName.isEmpty())
266 : {
267 0 : switch( nFamily )
268 : {
269 : case XML_STYLE_FAMILY_TABLE_TABLE:
270 0 : sServiceName = sTableStyleServiceName;
271 0 : break;
272 : case XML_STYLE_FAMILY_TABLE_COLUMN:
273 0 : sServiceName = sColumnStyleServiceName;
274 0 : break;
275 : case XML_STYLE_FAMILY_TABLE_CELL:
276 0 : sServiceName = sCellStyleServiceName;
277 0 : break;
278 :
279 : }
280 : }
281 0 : return sServiceName;
282 : }
283 : // -----------------------------------------------------------------------------
284 :
285 0 : sal_Int32 OTableStylesContext::GetIndex(const sal_Int16 nContextID)
286 : {
287 0 : if ( nContextID == CTF_DB_NUMBERFORMAT )
288 : {
289 0 : if (m_nNumberFormatIndex == -1)
290 : m_nNumberFormatIndex =
291 0 : GetImportPropertyMapper(XML_STYLE_FAMILY_TABLE_COLUMN)->getPropertySetMapper()->FindEntryIndex(nContextID);
292 0 : return m_nNumberFormatIndex;
293 : }
294 0 : else if ( nContextID == CTF_DB_MASTERPAGENAME )
295 : {
296 0 : if (nMasterPageNameIndex == -1)
297 : nMasterPageNameIndex =
298 0 : GetImportPropertyMapper(XML_STYLE_FAMILY_TABLE_TABLE)->getPropertySetMapper()->FindEntryIndex(nContextID);
299 0 : return nMasterPageNameIndex;
300 : }
301 : else
302 0 : return -1;
303 : }
304 : // -----------------------------------------------------------------------------
305 0 : ODBFilter& OTableStylesContext::GetOwnImport()
306 : {
307 0 : return static_cast<ODBFilter&>(GetImport());
308 : }
309 : // -----------------------------------------------------------------------------
310 : } // dbaxml
311 : // -----------------------------------------------------------------------------
312 :
313 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|