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