1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_SC_SOURCE_FILTER_XML_XMLIMPRT_HXX
21 #define INCLUDED_SC_SOURCE_FILTER_XML_XMLIMPRT_HXX
23 #include <xmloff/xmlimp.hxx>
24 #include <xmloff/xmlprmap.hxx>
25 #include "xmlsubti.hxx"
26 #include <formula/grammar.hxx>
27 #include <dociter.hxx>
29 #include <com/sun/star/sheet/ValidationAlertStyle.hpp>
30 #include <com/sun/star/sheet/ValidationType.hpp>
31 #include <com/sun/star/sheet/ConditionOperator.hpp>
38 namespace com
{ namespace sun
{ namespace star
{ namespace beans
{ class XPropertySet
; } } } }
39 namespace com
{ namespace sun
{ namespace star
{ namespace sheet
{ class XSheetCellRangeContainer
; } } } }
40 namespace com
{ namespace sun
{ namespace star
{ namespace table
{ struct CellRangeAddress
; } } } }
41 namespace com
{ namespace sun
{ namespace star
{ namespace util
{ class XNumberFormatTypes
; } } } }
42 namespace com
{ namespace sun
{ namespace star
{ namespace util
{ class XNumberFormats
; } } } }
43 namespace sax_fastparser
{ class FastAttributeList
; }
47 class ScMyStyleNumberFormats
;
48 class XMLNumberFormatAttributesExportHelper
;
49 class ScEditEngineDefaulter
;
50 class ScDocumentImport
;
51 class ScMyImpDetectiveOpArray
;
55 struct ImportPostProcessData
;
56 struct PivotTableSources
;
62 XML_TOK_DOC_FONTDECLS
,
64 XML_TOK_DOC_AUTOSTYLES
,
65 XML_TOK_DOC_MASTERSTYLES
,
72 enum ScXMLContentValidationElemTokens
74 XML_TOK_CONTENT_VALIDATION_ELEM_HELP_MESSAGE
,
75 XML_TOK_CONTENT_VALIDATION_ELEM_ERROR_MESSAGE
,
76 XML_TOK_CONTENT_VALIDATION_ELEM_ERROR_MACRO
,
77 XML_TOK_CONTENT_VALIDATION_ELEM_EVENT_LISTENERS
80 enum ScXMLContentValidationMessageElemTokens
87 XML_TOK_TABLE_NAMED_EXPRESSIONS
,
88 XML_TOK_TABLE_COL_GROUP
,
89 XML_TOK_TABLE_HEADER_COLS
,
92 XML_TOK_TABLE_ROW_GROUP
,
93 XML_TOK_TABLE_HEADER_ROWS
,
94 XML_TOK_TABLE_PROTECTION
,
95 XML_TOK_TABLE_PROTECTION_EXT
,
99 XML_TOK_TABLE_SCENARIO
,
100 XML_TOK_TABLE_SHAPES
,
102 XML_TOK_TABLE_EVENT_LISTENERS
,
103 XML_TOK_TABLE_EVENT_LISTENERS_EXT
,
104 XML_TOK_TABLE_CONDFORMATS
107 enum ScXMLTableRowsTokens
109 XML_TOK_TABLE_ROWS_ROW_GROUP
,
110 XML_TOK_TABLE_ROWS_HEADER_ROWS
,
111 XML_TOK_TABLE_ROWS_ROWS
,
112 XML_TOK_TABLE_ROWS_ROW
115 enum ScXMLTableRowTokens
117 XML_TOK_TABLE_ROW_CELL
,
118 XML_TOK_TABLE_ROW_COVERED_CELL
121 enum ScXMLTableRowAttrTokens
123 XML_TOK_TABLE_ROW_ATTR_STYLE_NAME
,
124 XML_TOK_TABLE_ROW_ATTR_VISIBILITY
,
125 XML_TOK_TABLE_ROW_ATTR_REPEATED
,
126 XML_TOK_TABLE_ROW_ATTR_DEFAULT_CELL_STYLE_NAME
127 // XML_TOK_TABLE_ROW_ATTR_USE_OPTIMAL_HEIGHT
130 enum ScXMLTableRowCellTokens
132 XML_TOK_TABLE_ROW_CELL_P
,
133 XML_TOK_TABLE_ROW_CELL_TABLE
,
134 XML_TOK_TABLE_ROW_CELL_ANNOTATION
,
135 XML_TOK_TABLE_ROW_CELL_DETECTIVE
,
136 XML_TOK_TABLE_ROW_CELL_CELL_RANGE_SOURCE
139 enum ScXMLTableRowCellAttrTokens
141 XML_TOK_TABLE_ROW_CELL_ATTR_STYLE_NAME
,
142 XML_TOK_TABLE_ROW_CELL_ATTR_CONTENT_VALIDATION_NAME
,
143 XML_TOK_TABLE_ROW_CELL_ATTR_SPANNED_ROWS
,
144 XML_TOK_TABLE_ROW_CELL_ATTR_SPANNED_COLS
,
145 XML_TOK_TABLE_ROW_CELL_ATTR_SPANNED_MATRIX_COLS
,
146 XML_TOK_TABLE_ROW_CELL_ATTR_SPANNED_MATRIX_ROWS
,
147 XML_TOK_TABLE_ROW_CELL_ATTR_REPEATED
,
148 XML_TOK_TABLE_ROW_CELL_ATTR_VALUE_TYPE
,
149 XML_TOK_TABLE_ROW_CELL_ATTR_NEW_VALUE_TYPE
,
150 XML_TOK_TABLE_ROW_CELL_ATTR_VALUE
,
151 XML_TOK_TABLE_ROW_CELL_ATTR_DATE_VALUE
,
152 XML_TOK_TABLE_ROW_CELL_ATTR_TIME_VALUE
,
153 XML_TOK_TABLE_ROW_CELL_ATTR_STRING_VALUE
,
154 XML_TOK_TABLE_ROW_CELL_ATTR_BOOLEAN_VALUE
,
155 XML_TOK_TABLE_ROW_CELL_ATTR_FORMULA
,
156 XML_TOK_TABLE_ROW_CELL_ATTR_CURRENCY
159 enum ScXMLAnnotationAttrTokens
161 XML_TOK_TABLE_ANNOTATION_ATTR_AUTHOR
,
162 XML_TOK_TABLE_ANNOTATION_ATTR_CREATE_DATE
,
163 XML_TOK_TABLE_ANNOTATION_ATTR_CREATE_DATE_STRING
,
164 XML_TOK_TABLE_ANNOTATION_ATTR_DISPLAY
,
165 XML_TOK_TABLE_ANNOTATION_ATTR_X
,
166 XML_TOK_TABLE_ANNOTATION_ATTR_Y
170 class XMLShapeImportHelper
;
171 class ScXMLChangeTrackingImportHelper
;
172 class SolarMutexGuard
;
174 struct ScMyNamedExpression
178 OUString sContentNmsp
;
179 OUString sBaseCellAddress
;
181 formula::FormulaGrammar::Grammar eGrammar
;
185 typedef ::std::list
<std::unique_ptr
<ScMyNamedExpression
>> ScMyNamedExpressions
;
187 struct ScMyLabelRange
189 OUString
const sLabelRangeStr
;
190 OUString
const sDataRangeStr
;
191 bool const bColumnOrientation
;
194 typedef std::list
< std::unique_ptr
<const ScMyLabelRange
> > ScMyLabelRanges
;
196 struct ScMyImportValidation
199 OUString sImputTitle
;
200 OUString sImputMessage
;
201 OUString sErrorTitle
;
202 OUString sErrorMessage
;
205 OUString sFormulaNmsp1
;
206 OUString sFormulaNmsp2
;
207 OUString sBaseCellAddress
; // string is used directly
208 css::sheet::ValidationAlertStyle aAlertStyle
;
209 css::sheet::ValidationType aValidationType
;
210 css::sheet::ConditionOperator aOperator
;
211 formula::FormulaGrammar::Grammar eGrammar1
;
212 formula::FormulaGrammar::Grammar eGrammar2
;
214 bool bShowErrorMessage
;
215 bool bShowImputMessage
;
219 typedef std::vector
<ScMyImportValidation
> ScMyImportValidations
;
220 class ScMyStylesImportHelper
;
221 class ScXMLEditAttributeMap
;
223 class ScXMLImport
: public SvXMLImport
225 ScXMLImport(const ScXMLImport
&) = delete;
226 const ScXMLImport
& operator=(const ScXMLImport
&) = delete;
228 typedef ::std::map
<SCTAB
, std::unique_ptr
<ScMyNamedExpressions
>> SheetNamedExpMap
;
231 std::unique_ptr
<ScDocumentImport
> mpDocImport
;
232 std::unique_ptr
<ScCompiler
> mpComp
; // For error-checking of cached string cell values.
233 std::unique_ptr
<ScEditEngineDefaulter
> mpEditEngine
;
234 std::unique_ptr
<sc::PivotTableSources
> mpPivotSources
;
236 mutable std::unique_ptr
<ScXMLEditAttributeMap
> mpEditAttrMap
;
237 std::unique_ptr
<ScXMLChangeTrackingImportHelper
> pChangeTrackingImportHelper
;
238 std::unique_ptr
<ScMyStylesImportHelper
> pStylesImportHelper
;
240 rtl::Reference
< XMLPropertyHandlerFactory
> xScPropHdlFactory
;
241 rtl::Reference
< XMLPropertySetMapper
> xCellStylesPropertySetMapper
;
242 rtl::Reference
< XMLPropertySetMapper
> xColumnStylesPropertySetMapper
;
243 rtl::Reference
< XMLPropertySetMapper
> xRowStylesPropertySetMapper
;
244 rtl::Reference
< XMLPropertySetMapper
> xTableStylesPropertySetMapper
;
246 std::unique_ptr
<SvXMLTokenMap
> pDocElemTokenMap
;
247 std::unique_ptr
<SvXMLTokenMap
> pContentValidationElemTokenMap
;
248 std::unique_ptr
<SvXMLTokenMap
> pContentValidationMessageElemTokenMap
;
249 std::unique_ptr
<SvXMLTokenMap
> pTableElemTokenMap
;
250 std::unique_ptr
<SvXMLTokenMap
> pTableRowsElemTokenMap
;
251 std::unique_ptr
<SvXMLTokenMap
> pTableRowElemTokenMap
;
252 std::unique_ptr
<SvXMLTokenMap
> pTableRowAttrTokenMap
;
253 std::unique_ptr
<SvXMLTokenMap
> pTableRowCellElemTokenMap
;
254 std::unique_ptr
<SvXMLTokenMap
> pTableRowCellAttrTokenMap
;
255 std::unique_ptr
<SvXMLTokenMap
> pTableAnnotationAttrTokenMap
;
257 sc::ImportPostProcessData
* mpPostProcessData
; /// Lift cycle managed elsewhere, no need to delete.
261 std::vector
<ScDocRowHeightUpdater::TabRanges
> maRecalcRowRanges
;
263 std::unique_ptr
<ScMyNamedExpressions
> m_pMyNamedExpressions
;
264 SheetNamedExpMap m_SheetNamedExpressions
;
266 std::unique_ptr
<ScMyLabelRanges
> pMyLabelRanges
;
267 std::unique_ptr
<ScMyImportValidations
> pValidations
;
268 std::unique_ptr
<ScMyImpDetectiveOpArray
> pDetectiveOpArray
;
269 std::unique_ptr
<SolarMutexGuard
> pSolarMutexGuard
;
271 std::unique_ptr
<XMLNumberFormatAttributesExportHelper
> pNumberFormatAttributesExportHelper
;
272 std::unique_ptr
<ScMyStyleNumberFormats
> pStyleNumberFormats
;
273 css::uno::Reference
<css::util::XNumberFormats
> xNumberFormats
;
274 css::uno::Reference
<css::util::XNumberFormatTypes
> xNumberFormatTypes
;
276 css::uno::Reference
<css::sheet::XSheetCellRangeContainer
> xSheetCellRanges
;
278 OUString sPrevStyleName
;
279 OUString sPrevCurrency
;
280 sal_uInt32 nSolarMutexLocked
;
281 sal_Int32 nProgressCount
;
282 sal_Int16 nPrevCellType
;
283 bool bLoadDoc
; // Load doc or styles only
284 bool bNullDateSetted
;
285 bool bSelfImportingXMLSet
;
286 bool mbLockSolarMutex
;
288 bool mbHasNewCondFormatData
;
292 // This method is called after the namespace map has been updated, but
293 // before a context for the current element has been pushed.
294 virtual SvXMLImportContext
*CreateFastContext( sal_Int32 nElement
,
295 const ::css::uno::Reference
< ::css::xml::sax::XFastAttributeList
>& xAttrList
) override
;
297 virtual XMLShapeImportHelper
* CreateShapeImport() override
;
301 const css::uno::Reference
< css::uno::XComponentContext
>& rContext
,
302 OUString
const & implementationName
, SvXMLImportFlags nImportFlag
);
304 virtual ~ScXMLImport() throw() override
;
307 virtual void SAL_CALL
initialize( const css::uno::Sequence
<css::uno::Any
>& aArguments
) override
;
310 // NB: in contrast to other CreateFooContexts, this particular one handles
311 // the root element (i.e. office:document-meta)
312 SvXMLImportContext
*CreateMetaContext(
313 const sal_Int32 nElement
);
314 SvXMLImportContext
*CreateFontDeclsContext(const sal_uInt16 nPrefix
, const OUString
& rLocalName
,
315 const css::uno::Reference
<css::xml::sax::XAttributeList
>& xAttrList
);
316 SvXMLImportContext
*CreateScriptContext(
317 const OUString
& rLocalName
);
318 SvXMLImportContext
*CreateStylesContext(const OUString
& rLocalName
,
319 const css::uno::Reference
<css::xml::sax::XAttributeList
>& xAttrList
,
322 SvXMLImportContext
*CreateBodyContext(
323 const rtl::Reference
<sax_fastparser::FastAttributeList
>& rAttrList
);
325 virtual void SetStatistics( const css::uno::Sequence
< css::beans::NamedValue
> & i_rStats
) override
;
327 ScDocumentImport
& GetDoc();
329 ScDocument
* GetDocument() { return pDoc
; }
330 const ScDocument
* GetDocument() const { return pDoc
; }
332 ScMyTables
& GetTables() { return aTables
; }
334 std::vector
<ScDocRowHeightUpdater::TabRanges
>& GetRecalcRowRanges() { return maRecalcRowRanges
; }
336 bool IsStylesOnlyMode() const { return !bLoadDoc
; }
338 static sal_Int16
GetCellType(const char* rStrValue
, const sal_Int32 nStrLength
);
340 const rtl::Reference
< XMLPropertySetMapper
>& GetCellStylesPropertySetMapper() const { return xCellStylesPropertySetMapper
; }
341 const rtl::Reference
< XMLPropertySetMapper
>& GetColumnStylesPropertySetMapper() const { return xColumnStylesPropertySetMapper
; }
342 const rtl::Reference
< XMLPropertySetMapper
>& GetRowStylesPropertySetMapper() const { return xRowStylesPropertySetMapper
; }
343 const rtl::Reference
< XMLPropertySetMapper
>& GetTableStylesPropertySetMapper() const { return xTableStylesPropertySetMapper
; }
345 const SvXMLTokenMap
& GetDocElemTokenMap();
346 const SvXMLTokenMap
& GetContentValidationElemTokenMap();
347 const SvXMLTokenMap
& GetContentValidationMessageElemTokenMap();
348 const SvXMLTokenMap
& GetTableElemTokenMap();
349 const SvXMLTokenMap
& GetTableRowsElemTokenMap();
350 const SvXMLTokenMap
& GetTableRowElemTokenMap();
351 const SvXMLTokenMap
& GetTableRowAttrTokenMap();
352 const SvXMLTokenMap
& GetTableRowCellElemTokenMap();
353 const SvXMLTokenMap
& GetTableRowCellAttrTokenMap();
354 const SvXMLTokenMap
& GetTableAnnotationAttrTokenMap();
356 void SetPostProcessData( sc::ImportPostProcessData
* p
);
357 sc::ImportPostProcessData
* GetPostProcessData() { return mpPostProcessData
;}
359 sc::PivotTableSources
& GetPivotTableSources();
361 void AddNamedExpression(ScMyNamedExpression
* pMyNamedExpression
)
363 if (!m_pMyNamedExpressions
)
364 m_pMyNamedExpressions
.reset(new ScMyNamedExpressions
);
365 m_pMyNamedExpressions
->push_back(std::unique_ptr
<ScMyNamedExpression
>(pMyNamedExpression
));
368 void AddNamedExpression(SCTAB nTab
, ScMyNamedExpression
* pNamedExp
);
370 void AddLabelRange(std::unique_ptr
<const ScMyLabelRange
> pMyLabelRange
) {
372 pMyLabelRanges
.reset(new ScMyLabelRanges
);
373 pMyLabelRanges
->push_back(std::move(pMyLabelRange
)); }
375 void AddValidation(const ScMyImportValidation
& rValidation
) {
377 pValidations
.reset(new ScMyImportValidations
);
378 pValidations
->push_back(rValidation
); }
379 bool GetValidation(const OUString
& sName
, ScMyImportValidation
& aValidation
);
381 ScMyImpDetectiveOpArray
* GetDetectiveOpArray();
383 ScXMLChangeTrackingImportHelper
* GetChangeTrackingImportHelper();
386 void SetChangeTrackingViewSettings(const css::uno::Sequence
<css::beans::PropertyValue
>& rChangeProps
);
387 virtual void SetViewSettings(const css::uno::Sequence
<css::beans::PropertyValue
>& aViewProps
) override
;
388 virtual void SetConfigurationSettings(const css::uno::Sequence
<css::beans::PropertyValue
>& aConfigProps
) override
;
390 ScMyStylesImportHelper
* GetStylesImportHelper() { return pStylesImportHelper
.get(); }
391 sal_Int32
SetCurrencySymbol(const sal_Int32 nKey
, const OUString
& rCurrency
);
392 bool IsCurrencySymbol(const sal_Int32 nNumberFormat
, const OUString
& sCurrencySymbol
, const OUString
& sBankSymbol
);
393 void SetType(const css::uno::Reference
<css::beans::XPropertySet
>& rProperties
,
394 sal_Int32
& rNumberFormat
,
395 const sal_Int16 nCellType
,
396 const OUString
& rCurrency
);
398 void ProgressBarIncrement();
400 void SetNewCondFormatData() { mbHasNewCondFormatData
= true; }
401 bool HasNewCondFormatData() const { return mbHasNewCondFormatData
; }
404 void AddStyleRange(const css::table::CellRangeAddress
& rCellRange
);
405 void SetStyleToRanges();
407 void ExamineDefaultStyle();
409 void SetStyleToRange(const ScRange
& rRange
, const OUString
* pStyleName
,
410 const sal_Int16 nCellType
, const OUString
* pCurrency
);
411 bool SetNullDateOnUnitConverter();
412 XMLNumberFormatAttributesExportHelper
* GetNumberFormatAttributesExportHelper();
413 ScMyStyleNumberFormats
* GetStyleNumberFormats();
415 void SetStylesToRangesFinished();
418 virtual void SAL_CALL
setTargetDocument( const css::uno::Reference
< css::lang::XComponent
>& xDoc
) override
;
420 virtual void SAL_CALL
startDocument() override
;
421 virtual void SAL_CALL
endDocument() override
;
423 virtual void DisposingModel() override
;
426 * Use this class to manage solar mutex locking instead of calling
427 * LockSolarMutex() and UnlockSolarMutex() directly.
432 explicit MutexGuard(ScXMLImport
& rImport
);
435 ScXMLImport
& mrImport
;
437 void LockSolarMutex();
438 void UnlockSolarMutex();
440 sal_Int32
GetByteOffset() const;
442 void SetRangeOverflowType(ErrCode nType
);
444 static sal_Int32
GetRangeType(const OUString
& sRangeType
);
445 void SetNamedRanges();
446 void SetSheetNamedRanges();
447 void SetLabelRanges();
448 void SetStringRefSyntaxIfMissing();
450 /** Extracts the formula string, the formula grammar namespace URL, and a
451 grammar enum value from the passed formula attribute value.
454 (out-parameter) Returns the plain formula string with the leading
455 equality sign if existing.
458 (out-parameter) Returns the URL of the formula grammar namespace if
459 the attribute value contains the prefix of an unknown namespace.
462 (out-parameter) Returns the exact formula grammar if the formula
463 is in a supported ODF format (e.g. FormulaGrammar::GRAM_PODF for
464 ODF 1.0/1.1 formulas, or FormulaGrammar::GRAM_ODFF for ODF 1.2
465 formulas a.k.a. OpenFormula). Returns the default storage grammar,
466 if the attribute value does not contain a namespace prefix. Returns
467 the special value FormulaGrammar::GRAM_EXTERNAL, if an unknown
468 namespace could be extracted from the formula which will be
469 contained in the parameter rFormulaNmsp then.
472 The value of the processed formula attribute.
474 @param bRestrictToExternalNmsp
475 If set to true, only namespaces of external formula grammars will
476 be recognized. Internal namespace prefixes (e.g. 'oooc:' or 'of:'
477 will be considered to be part of the formula, e.g. an expression
480 void ExtractFormulaNamespaceGrammar(
482 OUString
& rFormulaNmsp
,
483 ::formula::FormulaGrammar::Grammar
& reGrammar
,
484 const OUString
& rAttrValue
,
485 bool bRestrictToExternalNmsp
= false ) const;
487 FormulaError
GetFormulaErrorConstant( const OUString
& rStr
) const;
489 ScEditEngineDefaulter
* GetEditEngine();
490 const ScXMLEditAttributeMap
& GetEditAttributeMap() const;
491 virtual void NotifyEmbeddedFontRead() override
;
496 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */