LibreOffice Module sc (master) 1
xmlimprt.hxx
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#pragma once
21
22#include <xmloff/xmlimp.hxx>
23#include <xmloff/xmlprmap.hxx>
24#include "xmlsubti.hxx"
25#include <formula/grammar.hxx>
26#include <vcl/svapp.hxx>
27#include <dociter.hxx>
28
29#include <com/sun/star/sheet/ValidationAlertStyle.hpp>
30#include <com/sun/star/sheet/ValidationType.hpp>
31#include <com/sun/star/sheet/ConditionOperator.hpp>
32
33#include <memory>
34#include <map>
35#include <vector>
36#include <list>
37
38namespace com::sun::star::beans { class XPropertySet; }
39namespace com::sun::star::sheet { class XSheetCellRangeContainer; }
40namespace com::sun::star::table { struct CellRangeAddress; }
41namespace com::sun::star::util { class XNumberFormatTypes; }
42namespace com::sun::star::util { class XNumberFormats; }
43namespace sax_fastparser { class FastAttributeList; }
44
45class ScCompiler;
46class ErrCode;
52class SdrPage;
53
54namespace sc {
55struct ImportPostProcessData;
56struct PivotTableSources;
57class ScDrawObjData;
58}
59
60
61class SvXMLTokenMap;
64
66{
67 OUString sName;
68 OUString sContent;
69 OUString sContentNmsp;
71 OUString sRangeType;
74};
75
76typedef ::std::list<ScMyNamedExpression> ScMyNamedExpressions;
77
79{
81 OUString sDataRangeStr;
83};
84
85typedef std::list<ScMyLabelRange> ScMyLabelRanges;
86
88{
89 OUString sName;
90 OUString sInputTitle;
91 OUString sInputMessage;
92 OUString sErrorTitle;
93 OUString sErrorMessage;
94 OUString sFormula1;
95 OUString sFormula2;
96 OUString sFormulaNmsp1;
97 OUString sFormulaNmsp2;
98 OUString sBaseCellAddress; // string is used directly
99 css::sheet::ValidationAlertStyle aAlertStyle;
100 css::sheet::ValidationType aValidationType;
101 css::sheet::ConditionOperator aOperator;
104 sal_Int16 nShowList;
108};
109
110typedef std::vector<ScMyImportValidation> ScMyImportValidations;
113
114class ScXMLImport: public SvXMLImport
115{
116 ScXMLImport(const ScXMLImport&) = delete;
117 const ScXMLImport& operator=(const ScXMLImport&) = delete;
118
119 typedef ::std::map<SCTAB, ScMyNamedExpressions> SheetNamedExpMap;
120
122 std::unique_ptr<ScDocumentImport> mpDocImport;
123 std::unique_ptr<ScCompiler> mpComp; // For error-checking of cached string cell values.
124 std::unique_ptr<ScEditEngineDefaulter> mpEditEngine;
125 std::unique_ptr<sc::PivotTableSources> mpPivotSources;
126
127 mutable std::unique_ptr<ScXMLEditAttributeMap> mpEditAttrMap;
128 std::unique_ptr<ScXMLChangeTrackingImportHelper> pChangeTrackingImportHelper;
129 std::unique_ptr<ScMyStylesImportHelper> pStylesImportHelper;
130
136
138
140
141 std::vector<ScDocRowHeightUpdater::TabRanges> maRecalcRowRanges;
142
145
148 std::unique_ptr<ScMyImpDetectiveOpArray> pDetectiveOpArray;
149 std::optional<SolarMutexGuard> moSolarMutexGuard;
150
151 std::unique_ptr<XMLNumberFormatAttributesExportHelper> pNumberFormatAttributesExportHelper;
152 std::unique_ptr<ScMyStyleNumberFormats> pStyleNumberFormats;
153 css::uno::Reference <css::util::XNumberFormats> xNumberFormats;
154 css::uno::Reference <css::util::XNumberFormatTypes> xNumberFormatTypes;
155
156 css::uno::Reference <css::sheet::XSheetCellRangeContainer> xSheetCellRanges;
157
161 sal_Int32 nProgressCount;
162 sal_Int16 nPrevCellType;
163 bool bLoadDoc; // Load doc or styles only
169
170protected:
171
172 // This method is called after the namespace map has been updated, but
173 // before a context for the current element has been pushed.
174 virtual SvXMLImportContext *CreateFastContext( sal_Int32 nElement,
175 const ::css::uno::Reference< ::css::xml::sax::XFastAttributeList >& xAttrList ) override;
176
177 virtual XMLShapeImportHelper* CreateShapeImport() override;
178
179public:
181 const css::uno::Reference< css::uno::XComponentContext >& rContext,
182 OUString const & implementationName, SvXMLImportFlags nImportFlag,
183 const css::uno::Sequence< OUString > & sSupportedServiceNames = {});
184
185 virtual ~ScXMLImport() noexcept override;
186
187 // XInitialization
188 virtual void SAL_CALL initialize( const css::uno::Sequence<css::uno::Any>& aArguments ) override;
189
190 // namespace office
191 // NB: in contrast to other CreateFooContexts, this particular one handles
192 // the root element (i.e. office:document-meta)
193 SvXMLImportContext *CreateMetaContext( sal_Int32 nElement );
196 SvXMLImportContext *CreateStylesContext( bool bAutoStyles );
197
199 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList );
200
201 virtual void SetStatistics( const css::uno::Sequence< css::beans::NamedValue> & i_rStats) override;
202
204
206 const ScDocument* GetDocument() const { return pDoc; }
207
209
210 std::vector<ScDocRowHeightUpdater::TabRanges>& GetRecalcRowRanges() { return maRecalcRowRanges; }
211
212 bool IsStylesOnlyMode() const { return !bLoadDoc; }
213
214 static sal_Int16 GetCellType(const char* rStrValue, const sal_Int32 nStrLength);
215
220
223
225
227 {
228 m_aMyNamedExpressions.push_back(std::move(aMyNamedExpression));
229 }
230
231 void AddNamedExpression(SCTAB nTab, ScMyNamedExpression aNamedExp);
232
233 void AddLabelRange(ScMyLabelRange aMyLabelRange)
234 {
235 maMyLabelRanges.push_back(std::move(aMyLabelRange));
236 }
237
238 void AddValidation(const ScMyImportValidation& rValidation) { maValidations.push_back(rValidation); }
239 bool GetValidation(const OUString& sName, ScMyImportValidation& aValidation);
240
242
244 void InsertStyles();
245
246 void SetChangeTrackingViewSettings(const css::uno::Sequence<css::beans::PropertyValue>& rChangeProps);
247 virtual void SetViewSettings(const css::uno::Sequence<css::beans::PropertyValue>& aViewProps) override;
248 virtual void SetConfigurationSettings(const css::uno::Sequence<css::beans::PropertyValue>& aConfigProps) override;
249
251 sal_Int32 SetCurrencySymbol(const sal_Int32 nKey, std::u16string_view rCurrency);
252 bool IsCurrencySymbol(const sal_Int32 nNumberFormat, std::u16string_view sCurrencySymbol, std::u16string_view sBankSymbol);
253 void SetType(const css::uno::Reference <css::beans::XPropertySet>& rProperties,
254 sal_Int32& rNumberFormat,
255 const sal_Int16 nCellType,
256 std::u16string_view rCurrency);
257
259
262
263private:
264 void SetStyleToRanges();
265
266 void ExamineDefaultStyle();
267public:
268 void SetStyleToRanges(const ScRangeList& rRanges, const OUString* pStyleName,
269 const sal_Int16 nCellType, const OUString* pCurrency);
273
275
276 // XImporter
277 virtual void SAL_CALL setTargetDocument( const css::uno::Reference< css::lang::XComponent >& xDoc ) override;
278
279 virtual void SAL_CALL startDocument() override;
280 virtual void SAL_CALL endDocument() override;
281
282 virtual void DisposingModel() override;
283
289 {
290 public:
291 explicit MutexGuard(ScXMLImport& rImport);
292 ~MutexGuard();
293 private:
295 };
296 void LockSolarMutex();
297 void UnlockSolarMutex();
298
299 sal_Int32 GetByteOffset() const;
300
302
303 static sal_Int32 GetRangeType(std::u16string_view sRangeType);
304 void SetNamedRanges();
305 void SetSheetNamedRanges();
306 void SetLabelRanges();
308
340 OUString& rFormula,
341 OUString& rFormulaNmsp,
343 const OUString& rAttrValue,
344 bool bRestrictToExternalNmsp = false ) const;
345
346 FormulaError GetFormulaErrorConstant( const OUString& rStr ) const;
347
350 virtual void NotifyContainsEmbeddedFont() override;
351};
352
353/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Accessor class to ScDocument.
Provide mapping from ODF text formatting styles to EditEngine's, for rich-text cell content import.
Use this class to manage solar mutex locking instead of calling LockSolarMutex() and UnlockSolarMutex...
Definition: xmlimprt.hxx:289
ScXMLImport & mrImport
Definition: xmlimprt.hxx:294
MutexGuard(ScXMLImport &rImport)
Definition: xmlimprt.cxx:1508
std::unique_ptr< ScMyStyleNumberFormats > pStyleNumberFormats
Definition: xmlimprt.hxx:152
bool mbImportStyles
Definition: xmlimprt.hxx:167
void ProgressBarIncrement()
Definition: xmlimprt.cxx:1570
ScMyStylesImportHelper * GetStylesImportHelper()
Definition: xmlimprt.hxx:250
ScDocumentImport & GetDoc()
Definition: xmlimprt.cxx:506
std::unique_ptr< ScMyStylesImportHelper > pStylesImportHelper
Definition: xmlimprt.hxx:129
const rtl::Reference< XMLPropertySetMapper > & GetRowStylesPropertySetMapper() const
Definition: xmlimprt.hxx:218
SvXMLImportContext * CreateBodyContext(const rtl::Reference< sax_fastparser::FastAttributeList > &rAttrList)
Definition: xmlimprt.cxx:444
virtual void NotifyContainsEmbeddedFont() override
Definition: xmlimprt.cxx:1668
sal_Int16 nPrevCellType
Definition: xmlimprt.hxx:162
bool SetNullDateOnUnitConverter()
Definition: xmlimprt.cxx:1089
OUString sPrevStyleName
Definition: xmlimprt.hxx:158
rtl::Reference< XMLPropertySetMapper > xCellStylesPropertySetMapper
Definition: xmlimprt.hxx:132
ScXMLImport(const ScXMLImport &)=delete
void LockSolarMutex()
Definition: xmlimprt.cxx:1519
const rtl::Reference< XMLPropertySetMapper > & GetTableStylesPropertySetMapper() const
Definition: xmlimprt.hxx:219
void SetNamedRanges()
Definition: xmlimprt.cxx:1311
std::unique_ptr< ScXMLChangeTrackingImportHelper > pChangeTrackingImportHelper
Definition: xmlimprt.hxx:128
virtual void SetViewSettings(const css::uno::Sequence< css::beans::PropertyValue > &aViewProps) override
Definition: xmlimprt.cxx:698
css::uno::Reference< css::util::XNumberFormatTypes > xNumberFormatTypes
Definition: xmlimprt.hxx:154
bool IsCurrencySymbol(const sal_Int32 nNumberFormat, std::u16string_view sCurrencySymbol, std::u16string_view sBankSymbol)
Definition: xmlimprt.cxx:847
bool bSelfImportingXMLSet
Definition: xmlimprt.hxx:165
virtual void SAL_CALL setTargetDocument(const css::uno::Reference< css::lang::XComponent > &xDoc) override
Definition: xmlimprt.cxx:1118
sc::ImportPostProcessData * GetPostProcessData()
Definition: xmlimprt.hxx:222
std::vector< ScDocRowHeightUpdater::TabRanges > & GetRecalcRowRanges()
Definition: xmlimprt.hxx:210
void InsertStyles()
Definition: xmlimprt.cxx:596
virtual SvXMLImportContext * CreateFastContext(sal_Int32 nElement, const ::css::uno::Reference< ::css::xml::sax::XFastAttributeList > &xAttrList) override
Definition: xmlimprt.cxx:320
std::unique_ptr< XMLNumberFormatAttributesExportHelper > pNumberFormatAttributesExportHelper
Definition: xmlimprt.hxx:151
void SetChangeTrackingViewSettings(const css::uno::Sequence< css::beans::PropertyValue > &rChangeProps)
Definition: xmlimprt.cxx:618
const ScDocument * GetDocument() const
Definition: xmlimprt.hxx:206
OUString sPrevCurrency
Definition: xmlimprt.hxx:159
rtl::Reference< XMLPropertySetMapper > xColumnStylesPropertySetMapper
Definition: xmlimprt.hxx:133
rtl::Reference< XMLPropertyHandlerFactory > xScPropHdlFactory
Definition: xmlimprt.hxx:131
std::unique_ptr< sc::PivotTableSources > mpPivotSources
Definition: xmlimprt.hxx:125
virtual void SAL_CALL initialize(const css::uno::Sequence< css::uno::Any > &aArguments) override
Definition: xmlimprt.cxx:403
::std::map< SCTAB, ScMyNamedExpressions > SheetNamedExpMap
Definition: xmlimprt.hxx:119
virtual void DisposingModel() override
Definition: xmlimprt.cxx:1502
void AddNamedExpression(ScMyNamedExpression aMyNamedExpression)
Definition: xmlimprt.hxx:226
static sal_Int32 GetRangeType(std::u16string_view sRangeType)
Definition: xmlimprt.cxx:1187
SheetNamedExpMap m_SheetNamedExpressions
Definition: xmlimprt.hxx:144
bool bNullDateSetted
Definition: xmlimprt.hxx:164
std::vector< ScDocRowHeightUpdater::TabRanges > maRecalcRowRanges
Definition: xmlimprt.hxx:141
sc::ImportPostProcessData * mpPostProcessData
Definition: xmlimprt.hxx:137
void SetLabelRanges()
Definition: xmlimprt.cxx:1213
virtual void SAL_CALL endDocument() override
Definition: xmlimprt.cxx:1358
FormulaError GetFormulaErrorConstant(const OUString &rStr) const
Definition: xmlimprt.cxx:1639
void AddLabelRange(ScMyLabelRange aMyLabelRange)
Definition: xmlimprt.hxx:233
sal_uInt32 nSolarMutexLocked
Definition: xmlimprt.hxx:160
virtual void SetStatistics(const css::uno::Sequence< css::beans::NamedValue > &i_rStats) override
Definition: xmlimprt.cxx:478
void SetStyleToRanges()
Definition: xmlimprt.cxx:977
sal_Int32 SetCurrencySymbol(const sal_Int32 nKey, std::u16string_view rCurrency)
Definition: xmlimprt.cxx:798
void ExamineDefaultStyle()
Definition: xmlimprt.cxx:605
const rtl::Reference< XMLPropertySetMapper > & GetCellStylesPropertySetMapper() const
Definition: xmlimprt.hxx:216
std::unique_ptr< ScEditEngineDefaulter > mpEditEngine
Definition: xmlimprt.hxx:124
void SetSheetNamedRanges()
Definition: xmlimprt.cxx:1325
ScDocument * pDoc
Definition: xmlimprt.hxx:121
SvXMLImportContext * CreateMetaContext(sal_Int32 nElement)
Definition: xmlimprt.cxx:449
std::unique_ptr< ScMyImpDetectiveOpArray > pDetectiveOpArray
Definition: xmlimprt.hxx:148
ScMyTables aTables
Lift cycle managed elsewhere, no need to delete.
Definition: xmlimprt.hxx:139
css::uno::Reference< css::util::XNumberFormats > xNumberFormats
Definition: xmlimprt.hxx:153
ScMyImpDetectiveOpArray * GetDetectiveOpArray()
Definition: xmlimprt.cxx:1674
ScMyImportValidations maValidations
Definition: xmlimprt.hxx:147
ScMyLabelRanges maMyLabelRanges
Definition: xmlimprt.hxx:146
bool mbLockSolarMutex
Definition: xmlimprt.hxx:166
virtual XMLShapeImportHelper * CreateShapeImport() override
Definition: xmlimprt.cxx:552
const ScXMLEditAttributeMap & GetEditAttributeMap() const
Definition: xmlimprt.cxx:1661
ScXMLChangeTrackingImportHelper * GetChangeTrackingImportHelper()
Definition: xmlimprt.cxx:589
ScDocument * GetDocument()
Definition: xmlimprt.hxx:205
void UnlockSolarMutex()
Definition: xmlimprt.cxx:1537
std::unique_ptr< ScCompiler > mpComp
Definition: xmlimprt.hxx:123
ScMyNamedExpressions m_aMyNamedExpressions
Definition: xmlimprt.hxx:143
const ScXMLImport & operator=(const ScXMLImport &)=delete
bool GetValidation(const OUString &sName, ScMyImportValidation &aValidation)
Definition: xmlimprt.cxx:557
virtual ~ScXMLImport() noexcept override
Definition: xmlimprt.cxx:385
std::optional< SolarMutexGuard > moSolarMutexGuard
Definition: xmlimprt.hxx:149
void SetStylesToRangesFinished()
Definition: xmlimprt.cxx:1111
SvXMLImportContext * CreateStylesContext(bool bAutoStyles)
Definition: xmlimprt.cxx:431
ScMyTables & GetTables()
Definition: xmlimprt.hxx:208
void SetRangeOverflowType(ErrCode nType)
Definition: xmlimprt.cxx:1560
rtl::Reference< XMLPropertySetMapper > xRowStylesPropertySetMapper
Definition: xmlimprt.hxx:134
virtual void SAL_CALL startDocument() override
Definition: xmlimprt.cxx:1141
void AddValidation(const ScMyImportValidation &rValidation)
Definition: xmlimprt.hxx:238
sc::PivotTableSources & GetPivotTableSources()
Definition: xmlimprt.cxx:312
bool mbHasNewCondFormatData
Definition: xmlimprt.hxx:168
void ExtractFormulaNamespaceGrammar(OUString &rFormula, OUString &rFormulaNmsp, ::formula::FormulaGrammar::Grammar &reGrammar, const OUString &rAttrValue, bool bRestrictToExternalNmsp=false) const
Extracts the formula string, the formula grammar namespace URL, and a grammar enum value from the pas...
Definition: xmlimprt.cxx:1580
bool bLoadDoc
Definition: xmlimprt.hxx:163
virtual void SetConfigurationSettings(const css::uno::Sequence< css::beans::PropertyValue > &aConfigProps) override
Definition: xmlimprt.cxx:739
const rtl::Reference< XMLPropertySetMapper > & GetColumnStylesPropertySetMapper() const
Definition: xmlimprt.hxx:217
sal_Int32 GetByteOffset() const
Definition: xmlimprt.cxx:1550
std::unique_ptr< ScXMLEditAttributeMap > mpEditAttrMap
Definition: xmlimprt.hxx:127
rtl::Reference< XMLPropertySetMapper > xTableStylesPropertySetMapper
Definition: xmlimprt.hxx:135
void SetType(const css::uno::Reference< css::beans::XPropertySet > &rProperties, sal_Int32 &rNumberFormat, const sal_Int16 nCellType, std::u16string_view rCurrency)
Definition: xmlimprt.cxx:899
sal_Int32 nProgressCount
Definition: xmlimprt.hxx:161
void SetStringRefSyntaxIfMissing()
Definition: xmlimprt.cxx:1342
bool IsStylesOnlyMode() const
Definition: xmlimprt.hxx:212
css::uno::Reference< css::sheet::XSheetCellRangeContainer > xSheetCellRanges
Definition: xmlimprt.hxx:156
ScMyStyleNumberFormats * GetStyleNumberFormats()
Definition: xmlimprt.cxx:1104
SvXMLImportContext * CreateScriptContext()
Definition: xmlimprt.cxx:466
XMLNumberFormatAttributesExportHelper * GetNumberFormatAttributesExportHelper()
Definition: xmlimprt.cxx:1097
static sal_Int16 GetCellType(const char *rStrValue, const sal_Int32 nStrLength)
Definition: xmlimprt.cxx:511
void SetPostProcessData(sc::ImportPostProcessData *p)
Definition: xmlimprt.cxx:307
ScEditEngineDefaulter * GetEditEngine()
Definition: xmlimprt.cxx:1647
SvXMLImportContext * CreateFontDeclsContext()
Definition: xmlimprt.cxx:422
bool HasNewCondFormatData() const
Definition: xmlimprt.hxx:261
std::unique_ptr< ScDocumentImport > mpDocImport
Definition: xmlimprt.hxx:122
void SetNewCondFormatData()
Definition: xmlimprt.hxx:260
FormulaError
class SAL_NO_VTABLE XPropertySet
CAUTION! The following defines must be in the same namespace as the respective type.
Definition: broadcast.cxx:15
QPRO_FUNC_TYPE nType
Definition: qproform.cxx:398
OUString sFormulaNmsp2
Definition: xmlimprt.hxx:97
formula::FormulaGrammar::Grammar eGrammar2
Definition: xmlimprt.hxx:103
css::sheet::ValidationType aValidationType
Definition: xmlimprt.hxx:100
OUString sErrorMessage
Definition: xmlimprt.hxx:93
css::sheet::ConditionOperator aOperator
Definition: xmlimprt.hxx:101
OUString sInputMessage
Definition: xmlimprt.hxx:91
css::sheet::ValidationAlertStyle aAlertStyle
Definition: xmlimprt.hxx:99
OUString sBaseCellAddress
Definition: xmlimprt.hxx:98
OUString sFormulaNmsp1
Definition: xmlimprt.hxx:96
OUString sInputTitle
Definition: xmlimprt.hxx:90
formula::FormulaGrammar::Grammar eGrammar1
Definition: xmlimprt.hxx:102
OUString sErrorTitle
Definition: xmlimprt.hxx:92
OUString sDataRangeStr
Definition: xmlimprt.hxx:81
OUString sLabelRangeStr
Definition: xmlimprt.hxx:80
bool bColumnOrientation
Definition: xmlimprt.hxx:82
OUString sBaseCellAddress
Definition: xmlimprt.hxx:70
formula::FormulaGrammar::Grammar eGrammar
Definition: xmlimprt.hxx:72
OUString sContentNmsp
Definition: xmlimprt.hxx:69
OUString sRangeType
Definition: xmlimprt.hxx:71
Stores data imported from the file that need to be processed at the end of the import process.
Store pivot table data that need to be post-processed at the end of the import.
Definition: pivotsource.hxx:26
sal_Int16 SCTAB
Definition: types.hxx:22
SvXMLImportFlags
std::list< ScMyLabelRange > ScMyLabelRanges
Definition: xmlimprt.hxx:85
std::vector< ScMyImportValidation > ScMyImportValidations
Definition: xmlimprt.hxx:110
::std::list< ScMyNamedExpression > ScMyNamedExpressions
Definition: xmlimprt.hxx:76