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