LibreOffice Module dbaccess (master) 1
xmlStyleImport.cxx
Go to the documentation of this file.
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/maptype.hxx>
23#include <xmloff/xmlimppr.hxx>
24#include <xmloff/families.hxx>
25#include <xmloff/xmlnumfi.hxx>
26#include <xmloff/xmltoken.hxx>
27#include <osl/diagnose.h>
28#include "xmlfilter.hxx"
29#include "xmlHelper.hxx"
30
31namespace dbaxml
32{
33
34using namespace ::com::sun::star;
35using namespace ::com::sun::star::uno;
36using namespace ::com::sun::star::xml::sax;
37using namespace ::com::sun::star::style;
38using namespace ::com::sun::star::beans;
39using namespace ::com::sun::star::container;
40using namespace xmloff::token;
41
42
44 SvXMLStylesContext& rStyles, XmlStyleFamily nFamily )
45 :XMLPropStyleContext( rImport, rStyles, nFamily, false )
46 ,pStyles(&rStyles)
47 ,m_nNumberFormat(-1)
48{
49
50}
51
53{
54
55}
56
58 const Reference< XPropertySet > & rPropSet )
59{
60 if ( !IsDefaultStyle() )
61 {
62 if ( GetFamily() == XmlStyleFamily::TABLE_TABLE )
63 {
64 if ( !sPageStyle.isEmpty() )
65 {
67 }
68 }
69 else if ( GetFamily() == XmlStyleFamily::TABLE_COLUMN )
70 {
71 if ((m_nNumberFormat == -1) && !m_sDataStyleName.isEmpty())
72 {
74 XmlStyleFamily::DATA_STYLE, m_sDataStyleName, true)));
75 if ( !pStyle )
76 {
77 OTableStylesContext* pMyStyles = dynamic_cast<OTableStylesContext* >(GetOwnImport().GetAutoStyles());
78 if ( pMyStyles )
79 pStyle = const_cast<SvXMLNumFormatContext*>(dynamic_cast< const SvXMLNumFormatContext* >(pMyStyles->
80 FindStyleChildContext(XmlStyleFamily::DATA_STYLE, m_sDataStyleName, true)));
81 else {
82 OSL_FAIL("not possible to get style");
83 }
84 }
85 if ( pStyle )
86 {
87 uno::Any aNumberFormat;
88 m_nNumberFormat = pStyle->GetKey();
89 aNumberFormat <<= m_nNumberFormat;
90 AddProperty(CTF_DB_NUMBERFORMAT, aNumberFormat);
91 }
92 }
93 }
94 }
96}
97
99{
100}
101
102void OTableStyleContext::AddProperty(const sal_Int16 nContextID, const uno::Any& rValue)
103{
104 sal_Int32 nIndex(static_cast<OTableStylesContext *>(pStyles)->GetIndex(nContextID));
105 OSL_ENSURE(nIndex != -1, "Property not found in Map");
106 XMLPropertyState aPropState(nIndex, rValue);
107 GetProperties().push_back(aPropState); // has to be inserted in a sort order later
108}
109
110void OTableStyleContext::SetAttribute( sal_Int32 nElement,
111 const OUString& rValue )
112{
113 switch(nElement & TOKEN_MASK)
114 {
116 m_sDataStyleName = rValue;
117 break;
119 sPageStyle = rValue;
120 break;
121 default:
122 XMLPropStyleContext::SetAttribute( nElement, rValue );
123 }
124}
125
127{
128 return static_cast<ODBFilter&>(GetImport());
129}
130
131
133 bool bTempAutoStyles )
134 : SvXMLStylesContext( rImport )
135 , m_nNumberFormatIndex(-1)
136 , m_nMasterPageNameIndex(-1)
137 , bAutoStyles(bTempAutoStyles)
138{
139
140}
141
143{
144
145}
146
148{
149 if (bAutoStyles)
150 GetImport().GetTextImport()->SetAutoStyles( this );
151 else
152 GetImport().GetStyles()->CopyStylesToDoc(true);
153}
154
157 XmlStyleFamily nFamily ) const
158{
160
161 if (!xMapper.is())
162 {
163 switch( nFamily )
164 {
165 case XmlStyleFamily::TABLE_TABLE:
166 {
167 if ( !m_xTableImpPropMapper.is() )
168 m_xTableImpPropMapper = new SvXMLImportPropertyMapper( const_cast<OTableStylesContext*>(this)->GetOwnImport().GetTableStylesPropertySetMapper(), const_cast<SvXMLImport&>(GetImport()) );
169 xMapper = m_xTableImpPropMapper;
170 }
171 break;
172 case XmlStyleFamily::TABLE_COLUMN:
173 {
174 if ( !m_xColumnImpPropMapper.is() )
175 m_xColumnImpPropMapper = new SvXMLImportPropertyMapper( const_cast<OTableStylesContext*>(this)->GetOwnImport().GetColumnStylesPropertySetMapper(), const_cast<SvXMLImport&>(GetImport()) );
176 xMapper = m_xColumnImpPropMapper;
177 }
178 break;
179 case XmlStyleFamily::TABLE_CELL:
180 {
181 if ( !m_xCellImpPropMapper.is() )
182 m_xCellImpPropMapper = new SvXMLImportPropertyMapper( const_cast<OTableStylesContext*>(this)->GetOwnImport().GetCellStylesPropertySetMapper(), const_cast<SvXMLImport&>(GetImport()) );
183 xMapper = m_xCellImpPropMapper;
184 }
185 break;
186 default: break;
187 }
188 }
189
190 return xMapper;
191}
192
194 XmlStyleFamily nFamily, sal_Int32 nElement,
195 const Reference< xml::sax::XFastAttributeList > & xAttrList )
196{
198 xAttrList );
199 if (pStyle)
200 return pStyle;
201
202 switch( nFamily )
203 {
204 case XmlStyleFamily::TABLE_TABLE:
205 case XmlStyleFamily::TABLE_COLUMN:
206 case XmlStyleFamily::TABLE_CELL:
207 return new OTableStyleContext( GetOwnImport(), *this, nFamily );
208 default: break;
209 }
210
211 return nullptr;
212}
213
215{
217 if (sServiceName.isEmpty())
218 {
219 switch( nFamily )
220 {
221 case XmlStyleFamily::TABLE_TABLE:
223 break;
224 case XmlStyleFamily::TABLE_COLUMN:
226 break;
227 case XmlStyleFamily::TABLE_CELL:
229 break;
230 default: break;
231 }
232 }
233 return sServiceName;
234}
235
236sal_Int32 OTableStylesContext::GetIndex(const sal_Int16 nContextID)
237{
238 if ( nContextID == CTF_DB_NUMBERFORMAT )
239 {
240 if (m_nNumberFormatIndex == -1)
242 GetImportPropertyMapper(XmlStyleFamily::TABLE_COLUMN)->getPropertySetMapper()->FindEntryIndex(nContextID);
244 }
245 else if ( nContextID == CTF_DB_MASTERPAGENAME )
246 {
247 if (m_nMasterPageNameIndex == -1)
249 GetImportPropertyMapper(XmlStyleFamily::TABLE_TABLE)->getPropertySetMapper()->FindEntryIndex(nContextID);
251 }
252 else
253 return -1;
254}
255
257{
258 return static_cast<ODBFilter&>(GetImport());
259}
260
261} // dbaxml
262
263/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
constexpr OUStringLiteral sServiceName
SvXMLImport & GetImport()
friend friend class SvXMLImport
XmlStyleFamily GetFamily() const
bool IsDefaultStyle() const
const SvXMLStyleContext * FindStyleChildContext(XmlStyleFamily nFamily, const OUString &rName, bool bCreateIndex=false) const
virtual rtl::Reference< SvXMLImportPropertyMapper > GetImportPropertyMapper(XmlStyleFamily nFamily) const
virtual SvXMLStyleContext * CreateStyleStyleChildContext(XmlStyleFamily nFamily, sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
virtual OUString GetServiceName(XmlStyleFamily nFamily) const
virtual void FillPropertySet(const css::uno::Reference< css::beans::XPropertySet > &rPropSet)
const ::std::vector< XMLPropertyState > & GetProperties() const
virtual void SetAttribute(sal_Int32 nElement, const OUString &rValue) override
virtual void FillPropertySet(const css::uno::Reference< css::beans::XPropertySet > &rPropSet) override
virtual void SetAttribute(sal_Int32 nElement, const OUString &rValue) override
SvXMLStylesContext * pStyles
virtual ~OTableStyleContext() override
void AddProperty(sal_Int16 nContextID, const css::uno::Any &aValue)
virtual void SetDefaults() override
OTableStyleContext(ODBFilter &rImport, SvXMLStylesContext &rStyles, XmlStyleFamily nFamily)
sal_Int32 GetIndex(const sal_Int16 nContextID)
rtl::Reference< SvXMLImportPropertyMapper > m_xTableImpPropMapper
virtual OUString GetServiceName(XmlStyleFamily nFamily) const override
virtual rtl::Reference< SvXMLImportPropertyMapper > GetImportPropertyMapper(XmlStyleFamily nFamily) const override
virtual ~OTableStylesContext() override
virtual SvXMLStyleContext * CreateStyleStyleChildContext(XmlStyleFamily nFamily, sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override
rtl::Reference< SvXMLImportPropertyMapper > m_xCellImpPropMapper
OTableStylesContext(SvXMLImport &rImport, bool bAutoStyles)
rtl::Reference< SvXMLImportPropertyMapper > m_xColumnImpPropMapper
virtual void SAL_CALL endFastElement(sal_Int32 nElement) override
XmlStyleFamily
constexpr OUStringLiteral XML_STYLE_FAMILY_TABLE_COLUMN_STYLES_NAME
constexpr OUStringLiteral XML_STYLE_FAMILY_TABLE_CELL_STYLES_NAME
constexpr OUStringLiteral XML_STYLE_FAMILY_TABLE_TABLE_STYLES_NAME
sal_Int32 nIndex
XML_MASTER_PAGE_NAME
XML_DATA_STYLE_NAME
#define CTF_DB_MASTERPAGENAME
Definition: xmlHelper.hxx:29
#define CTF_DB_NUMBERFORMAT
Definition: xmlHelper.hxx:30
constexpr sal_Int32 TOKEN_MASK