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 <dociter.hxx>
27 
28 #include <com/sun/star/sheet/ValidationAlertStyle.hpp>
29 #include <com/sun/star/sheet/ValidationType.hpp>
30 #include <com/sun/star/sheet/ConditionOperator.hpp>
31 
32 #include <memory>
33 #include <map>
34 #include <vector>
35 #include <list>
36 
37 namespace com::sun::star::beans { class XPropertySet; }
38 namespace com::sun::star::sheet { class XSheetCellRangeContainer; }
39 namespace com::sun::star::table { struct CellRangeAddress; }
40 namespace com::sun::star::util { class XNumberFormatTypes; }
41 namespace com::sun::star::util { class XNumberFormats; }
42 namespace sax_fastparser { class FastAttributeList; }
43 
44 class ScCompiler;
45 class ErrCode;
49 class ScDocumentImport;
51 class SdrPage;
52 
53 namespace sc {
54 struct ImportPostProcessData;
55 struct PivotTableSources;
56 class ScDrawObjData;
57 }
58 
59 
60 class SvXMLTokenMap;
63 class SolarMutexGuard;
64 
66 {
67  OUString sName;
68  OUString sContent;
69  OUString sContentNmsp;
70  OUString sBaseCellAddress;
71  OUString sRangeType;
74 };
75 
76 typedef ::std::list<ScMyNamedExpression> ScMyNamedExpressions;
77 
79 {
80  OUString sLabelRangeStr;
81  OUString sDataRangeStr;
83 };
84 
85 typedef 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 
110 typedef std::vector<ScMyImportValidation> ScMyImportValidations;
113 
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 
144  SheetNamedExpMap m_SheetNamedExpressions;
145 
148  std::unique_ptr<ScMyImpDetectiveOpArray> pDetectiveOpArray;
149  std::unique_ptr<SolarMutexGuard> pSolarMutexGuard;
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 
158  OUString sPrevStyleName;
159  OUString sPrevCurrency;
160  sal_uInt32 nSolarMutexLocked;
161  sal_Int32 nProgressCount;
162  sal_Int16 nPrevCellType;
163  bool bLoadDoc; // Load doc or styles only
169 
170 protected:
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 
179 public:
180  ScXMLImport(
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 
205  ScDocument* GetDocument() { return pDoc; }
206  const ScDocument* GetDocument() const { return pDoc; }
207 
208  ScMyTables& GetTables() { return aTables; }
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 
226  void AddNamedExpression(ScMyNamedExpression aMyNamedExpression)
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 
250  ScMyStylesImportHelper* GetStylesImportHelper() { return pStylesImportHelper.get(); }
251  sal_Int32 SetCurrencySymbol(const sal_Int32 nKey, std::u16string_view rCurrency);
252  bool IsCurrencySymbol(const sal_Int32 nNumberFormat, const OUString& 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 
258  void ProgressBarIncrement();
259 
260  void SetNewCondFormatData() { mbHasNewCondFormatData = true; }
262 
263 private:
264  void SetStyleToRanges();
265 
266  void ExamineDefaultStyle();
267 public:
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(const OUString& 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: */
void SetStringRefSyntaxIfMissing()
Definition: xmlimprt.cxx:1331
css::uno::Reference< css::sheet::XSheetCellRangeContainer > xSheetCellRanges
Definition: xmlimprt.hxx:156
virtual SvXMLImportContext * CreateFastContext(sal_Int32 nElement, const ::css::uno::Reference< ::css::xml::sax::XFastAttributeList > &xAttrList) override
Definition: xmlimprt.cxx:322
OUString sFormulaNmsp2
Definition: xmlimprt.hxx:97
OUString sDataRangeStr
Definition: xmlimprt.hxx:81
ScMyImportValidations maValidations
Definition: xmlimprt.hxx:147
virtual ~ScXMLImport() noexcept override
Definition: xmlimprt.cxx:387
SvXMLImportContext * CreateScriptContext()
Definition: xmlimprt.cxx:468
css::uno::Reference< css::util::XNumberFormatTypes > xNumberFormatTypes
Definition: xmlimprt.hxx:154
bool mbHasNewCondFormatData
Definition: xmlimprt.hxx:168
ScMyTables aTables
Lift cycle managed elsewhere, no need to delete.
Definition: xmlimprt.hxx:139
Provide mapping from ODF text formatting styles to EditEngine's, for rich-text cell content import...
std::vector< ScDocRowHeightUpdater::TabRanges > & GetRecalcRowRanges()
Definition: xmlimprt.hxx:210
sal_Int32 nProgressCount
Definition: xmlimprt.hxx:161
OUString sRangeType
Definition: xmlimprt.hxx:71
OUString sFormulaNmsp1
Definition: xmlimprt.hxx:96
ScDocument * pDoc
Definition: xmlimprt.hxx:121
Store pivot table data that need to be post-processed at the end of the import.
Definition: pivotsource.hxx:25
ScDocument * GetDocument()
Definition: xmlimprt.hxx:205
::std::list< ScMyNamedExpression > ScMyNamedExpressions
Definition: xmlimprt.hxx:76
ScMyTables & GetTables()
Definition: xmlimprt.hxx:208
Stores data imported from the file that need to be processed at the end of the import process...
std::vector< ScDocRowHeightUpdater::TabRanges > maRecalcRowRanges
Definition: xmlimprt.hxx:141
SvXMLImportContext * CreateFontDeclsContext()
Definition: xmlimprt.cxx:424
std::vector< ScMyImportValidation > ScMyImportValidations
Definition: xmlimprt.hxx:110
const ScXMLEditAttributeMap & GetEditAttributeMap() const
Definition: xmlimprt.cxx:1650
OUString sPrevCurrency
Definition: xmlimprt.hxx:159
ScMyStylesImportHelper * GetStylesImportHelper()
Definition: xmlimprt.hxx:250
bool mbLockSolarMutex
Definition: xmlimprt.hxx:166
Accessor class to ScDocument.
OUString sBaseCellAddress
Definition: xmlimprt.hxx:70
OUString sPrevStyleName
Definition: xmlimprt.hxx:158
ScMyLabelRanges maMyLabelRanges
Definition: xmlimprt.hxx:146
void AddLabelRange(ScMyLabelRange aMyLabelRange)
Definition: xmlimprt.hxx:233
css::sheet::ConditionOperator aOperator
Definition: xmlimprt.hxx:101
SvXMLImportContext * CreateMetaContext(sal_Int32 nElement)
Definition: xmlimprt.cxx:451
rtl::Reference< XMLPropertySetMapper > xRowStylesPropertySetMapper
Definition: xmlimprt.hxx:134
bool SetNullDateOnUnitConverter()
Definition: xmlimprt.cxx:1090
const ScXMLImport & operator=(const ScXMLImport &)=delete
SvXMLImportFlags
void LockSolarMutex()
Definition: xmlimprt.cxx:1508
std::unique_ptr< ScDocumentImport > mpDocImport
Definition: xmlimprt.hxx:122
sc::ImportPostProcessData * mpPostProcessData
Definition: xmlimprt.hxx:137
std::unique_ptr< sc::PivotTableSources > mpPivotSources
Definition: xmlimprt.hxx:125
bool bSelfImportingXMLSet
Definition: xmlimprt.hxx:165
const ScDocument * GetDocument() const
Definition: xmlimprt.hxx:206
FormulaError GetFormulaErrorConstant(const OUString &rStr) const
Definition: xmlimprt.cxx:1628
ScXMLImport(const ScXMLImport &)=delete
sal_Int32 SetCurrencySymbol(const sal_Int32 nKey, std::u16string_view rCurrency)
Definition: xmlimprt.cxx:799
virtual void SAL_CALL endDocument() override
Definition: xmlimprt.cxx:1347
SvXMLImportContext * CreateStylesContext(bool bAutoStyles)
Definition: xmlimprt.cxx:433
bool bNullDateSetted
Definition: xmlimprt.hxx:164
OUString sInputTitle
Definition: xmlimprt.hxx:90
void InsertStyles()
Definition: xmlimprt.cxx:598
SheetNamedExpMap m_SheetNamedExpressions
Definition: xmlimprt.hxx:144
OUString sContentNmsp
Definition: xmlimprt.hxx:69
bool GetValidation(const OUString &sName, ScMyImportValidation &aValidation)
Definition: xmlimprt.cxx:559
void ExamineDefaultStyle()
Definition: xmlimprt.cxx:607
const rtl::Reference< XMLPropertySetMapper > & GetTableStylesPropertySetMapper() const
Definition: xmlimprt.hxx:219
virtual void SetStatistics(const css::uno::Sequence< css::beans::NamedValue > &i_rStats) override
Definition: xmlimprt.cxx:480
const rtl::Reference< XMLPropertySetMapper > & GetRowStylesPropertySetMapper() const
Definition: xmlimprt.hxx:218
bool bColumnOrientation
Definition: xmlimprt.hxx:82
void SetPostProcessData(sc::ImportPostProcessData *p)
Definition: xmlimprt.cxx:309
virtual void SetConfigurationSettings(const css::uno::Sequence< css::beans::PropertyValue > &aConfigProps) override
Definition: xmlimprt.cxx:741
ScMyNamedExpressions m_aMyNamedExpressions
Definition: xmlimprt.hxx:143
std::unique_ptr< ScXMLEditAttributeMap > mpEditAttrMap
Definition: xmlimprt.hxx:127
class SAL_NO_VTABLE XPropertySet
virtual void SAL_CALL startDocument() override
Definition: xmlimprt.cxx:1142
std::unique_ptr< ScMyStyleNumberFormats > pStyleNumberFormats
Definition: xmlimprt.hxx:152
void SetStyleToRanges()
Definition: xmlimprt.cxx:978
std::list< ScMyLabelRange > ScMyLabelRanges
Definition: xmlimprt.hxx:85
std::unique_ptr< ScCompiler > mpComp
Definition: xmlimprt.hxx:123
bool IsCurrencySymbol(const sal_Int32 nNumberFormat, const OUString &sCurrencySymbol, std::u16string_view sBankSymbol)
Definition: xmlimprt.cxx:848
const rtl::Reference< XMLPropertySetMapper > & GetCellStylesPropertySetMapper() const
Definition: xmlimprt.hxx:216
css::sheet::ValidationType aValidationType
Definition: xmlimprt.hxx:100
const rtl::Reference< XMLPropertySetMapper > & GetColumnStylesPropertySetMapper() const
Definition: xmlimprt.hxx:217
sal_uInt32 nSolarMutexLocked
Definition: xmlimprt.hxx:160
Use this class to manage solar mutex locking instead of calling LockSolarMutex() and UnlockSolarMutex...
Definition: xmlimprt.hxx:288
static sal_Int16 GetCellType(const char *rStrValue, const sal_Int32 nStrLength)
Definition: xmlimprt.cxx:513
ScXMLImport & mrImport
Definition: xmlimprt.hxx:294
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:1569
OUString sLabelRangeStr
Definition: xmlimprt.hxx:80
FormulaError
XMLNumberFormatAttributesExportHelper * GetNumberFormatAttributesExportHelper()
Definition: xmlimprt.cxx:1098
void AddValidation(const ScMyImportValidation &rValidation)
Definition: xmlimprt.hxx:238
std::unique_ptr< ScEditEngineDefaulter > mpEditEngine
Definition: xmlimprt.hxx:124
static sal_Int32 GetRangeType(const OUString &sRangeType)
Definition: xmlimprt.cxx:1189
std::unique_ptr< XMLNumberFormatAttributesExportHelper > pNumberFormatAttributesExportHelper
Definition: xmlimprt.hxx:151
OUString sBaseCellAddress
Definition: xmlimprt.hxx:98
ScEditEngineDefaulter * GetEditEngine()
Definition: xmlimprt.cxx:1636
css::uno::Reference< css::util::XNumberFormats > xNumberFormats
Definition: xmlimprt.hxx:153
SvXMLImportContext * CreateBodyContext(const rtl::Reference< sax_fastparser::FastAttributeList > &rAttrList)
Definition: xmlimprt.cxx:446
formula::FormulaGrammar::Grammar eGrammar2
Definition: xmlimprt.hxx:103
sal_Int16 nPrevCellType
Definition: xmlimprt.hxx:162
virtual void SetViewSettings(const css::uno::Sequence< css::beans::PropertyValue > &aViewProps) override
Definition: xmlimprt.cxx:700
void SetNamedRanges()
Definition: xmlimprt.cxx:1301
void SetLabelRanges()
Definition: xmlimprt.cxx:1215
OUString sErrorMessage
Definition: xmlimprt.hxx:93
bool IsStylesOnlyMode() const
Definition: xmlimprt.hxx:212
bool HasNewCondFormatData() const
Definition: xmlimprt.hxx:261
std::unique_ptr< SolarMutexGuard > pSolarMutexGuard
Definition: xmlimprt.hxx:149
virtual void SAL_CALL initialize(const css::uno::Sequence< css::uno::Any > &aArguments) override
Definition: xmlimprt.cxx:405
ScMyStyleNumberFormats * GetStyleNumberFormats()
Definition: xmlimprt.cxx:1105
rtl::Reference< XMLPropertySetMapper > xColumnStylesPropertySetMapper
Definition: xmlimprt.hxx:133
std::unique_ptr< ScMyStylesImportHelper > pStylesImportHelper
Definition: xmlimprt.hxx:129
rtl::Reference< XMLPropertySetMapper > xTableStylesPropertySetMapper
Definition: xmlimprt.hxx:135
void UnlockSolarMutex()
Definition: xmlimprt.cxx:1526
css::sheet::ValidationAlertStyle aAlertStyle
Definition: xmlimprt.hxx:99
ScXMLChangeTrackingImportHelper * GetChangeTrackingImportHelper()
Definition: xmlimprt.cxx:591
std::unique_ptr< ScMyImpDetectiveOpArray > pDetectiveOpArray
Definition: xmlimprt.hxx:148
::std::map< SCTAB, ScMyNamedExpressions > SheetNamedExpMap
Definition: xmlimprt.hxx:119
virtual void DisposingModel() override
Definition: xmlimprt.cxx:1491
QPRO_FUNC_TYPE nType
Definition: qproform.cxx:398
bool bLoadDoc
Definition: xmlimprt.hxx:163
void SetType(const css::uno::Reference< css::beans::XPropertySet > &rProperties, sal_Int32 &rNumberFormat, const sal_Int16 nCellType, std::u16string_view rCurrency)
Definition: xmlimprt.cxx:900
formula::FormulaGrammar::Grammar eGrammar
Definition: xmlimprt.hxx:72
ScMyImpDetectiveOpArray * GetDetectiveOpArray()
Definition: xmlimprt.cxx:1663
OUString sInputMessage
Definition: xmlimprt.hxx:91
formula::FormulaGrammar::Grammar eGrammar1
Definition: xmlimprt.hxx:102
void SetChangeTrackingViewSettings(const css::uno::Sequence< css::beans::PropertyValue > &rChangeProps)
Definition: xmlimprt.cxx:620
void AddNamedExpression(ScMyNamedExpression aMyNamedExpression)
Definition: xmlimprt.hxx:226
bool mbImportStyles
Definition: xmlimprt.hxx:167
rtl::Reference< XMLPropertyHandlerFactory > xScPropHdlFactory
Definition: xmlimprt.hxx:131
rtl::Reference< XMLPropertySetMapper > xCellStylesPropertySetMapper
Definition: xmlimprt.hxx:132
sal_Int32 GetByteOffset() const
Definition: xmlimprt.cxx:1539
void ProgressBarIncrement()
Definition: xmlimprt.cxx:1559
sc::PivotTableSources & GetPivotTableSources()
Definition: xmlimprt.cxx:314
virtual void SAL_CALL setTargetDocument(const css::uno::Reference< css::lang::XComponent > &xDoc) override
Definition: xmlimprt.cxx:1119
MutexGuard(ScXMLImport &rImport)
Definition: xmlimprt.cxx:1497
virtual XMLShapeImportHelper * CreateShapeImport() override
Definition: xmlimprt.cxx:554
sc::ImportPostProcessData * GetPostProcessData()
Definition: xmlimprt.hxx:222
virtual void NotifyContainsEmbeddedFont() override
Definition: xmlimprt.cxx:1657
ScDocumentImport & GetDoc()
Definition: xmlimprt.cxx:508
sal_Int16 SCTAB
Definition: types.hxx:22
void SetStylesToRangesFinished()
Definition: xmlimprt.cxx:1112
OUString sErrorTitle
Definition: xmlimprt.hxx:92
void SetRangeOverflowType(ErrCode nType)
Definition: xmlimprt.cxx:1549
void SetSheetNamedRanges()
Definition: xmlimprt.cxx:1314
void SetNewCondFormatData()
Definition: xmlimprt.hxx:260
std::unique_ptr< ScXMLChangeTrackingImportHelper > pChangeTrackingImportHelper
Definition: xmlimprt.hxx:128