1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#ifndef INCLUDED_SC_SOURCE_FILTER_XML_XMLIMPRT_HXX
#define INCLUDED_SC_SOURCE_FILTER_XML_XMLIMPRT_HXX
#include <xmloff/xmlimp.hxx>
#include <xmloff/xmlprmap.hxx>
#include "xmlsubti.hxx"
#include <formula/grammar.hxx>
#include <dociter.hxx>
#include <com/sun/star/sheet/ValidationAlertStyle.hpp>
#include <com/sun/star/sheet/ValidationType.hpp>
#include <com/sun/star/sheet/ConditionOperator.hpp>
#include <memory>
#include <map>
#include <vector>
#include <list>
namespace com::sun::star::beans { class XPropertySet; }
namespace com::sun::star::sheet { class XSheetCellRangeContainer; }
namespace com::sun::star::table { struct CellRangeAddress; }
namespace com::sun::star::util { class XNumberFormatTypes; }
namespace com::sun::star::util { class XNumberFormats; }
namespace sax_fastparser { class FastAttributeList; }
class ScCompiler;
class ErrCode;
class ScMyStyleNumberFormats;
class XMLNumberFormatAttributesExportHelper;
class ScEditEngineDefaulter;
class ScDocumentImport;
class ScMyImpDetectiveOpArray;
namespace sc {
struct ImportPostProcessData;
struct PivotTableSources;
}
enum ScXMLTableTokens
{
XML_TOK_TABLE_NAMED_EXPRESSIONS,
XML_TOK_TABLE_COL_GROUP,
XML_TOK_TABLE_HEADER_COLS,
XML_TOK_TABLE_COLS,
XML_TOK_TABLE_COL,
XML_TOK_TABLE_ROW_GROUP,
XML_TOK_TABLE_HEADER_ROWS,
XML_TOK_TABLE_PROTECTION,
XML_TOK_TABLE_PROTECTION_EXT,
XML_TOK_TABLE_ROWS,
XML_TOK_TABLE_ROW,
XML_TOK_TABLE_SOURCE,
XML_TOK_TABLE_SCENARIO,
XML_TOK_TABLE_SHAPES,
XML_TOK_TABLE_FORMS,
XML_TOK_TABLE_EVENT_LISTENERS,
XML_TOK_TABLE_EVENT_LISTENERS_EXT,
XML_TOK_TABLE_CONDFORMATS
};
enum ScXMLTableRowsTokens
{
XML_TOK_TABLE_ROWS_ROW_GROUP,
XML_TOK_TABLE_ROWS_HEADER_ROWS,
XML_TOK_TABLE_ROWS_ROWS,
XML_TOK_TABLE_ROWS_ROW
};
enum ScXMLTableRowTokens
{
XML_TOK_TABLE_ROW_CELL,
XML_TOK_TABLE_ROW_COVERED_CELL
};
enum ScXMLTableRowAttrTokens
{
XML_TOK_TABLE_ROW_ATTR_STYLE_NAME,
XML_TOK_TABLE_ROW_ATTR_VISIBILITY,
XML_TOK_TABLE_ROW_ATTR_REPEATED,
XML_TOK_TABLE_ROW_ATTR_DEFAULT_CELL_STYLE_NAME
// XML_TOK_TABLE_ROW_ATTR_USE_OPTIMAL_HEIGHT
};
enum ScXMLTableRowCellTokens
{
XML_TOK_TABLE_ROW_CELL_P,
XML_TOK_TABLE_ROW_CELL_TABLE,
XML_TOK_TABLE_ROW_CELL_ANNOTATION,
XML_TOK_TABLE_ROW_CELL_DETECTIVE,
XML_TOK_TABLE_ROW_CELL_CELL_RANGE_SOURCE
};
enum ScXMLTableRowCellAttrTokens
{
XML_TOK_TABLE_ROW_CELL_ATTR_STYLE_NAME,
XML_TOK_TABLE_ROW_CELL_ATTR_CONTENT_VALIDATION_NAME,
XML_TOK_TABLE_ROW_CELL_ATTR_SPANNED_ROWS,
XML_TOK_TABLE_ROW_CELL_ATTR_SPANNED_COLS,
XML_TOK_TABLE_ROW_CELL_ATTR_SPANNED_MATRIX_COLS,
XML_TOK_TABLE_ROW_CELL_ATTR_SPANNED_MATRIX_ROWS,
XML_TOK_TABLE_ROW_CELL_ATTR_REPEATED,
XML_TOK_TABLE_ROW_CELL_ATTR_VALUE_TYPE,
XML_TOK_TABLE_ROW_CELL_ATTR_NEW_VALUE_TYPE,
XML_TOK_TABLE_ROW_CELL_ATTR_VALUE,
XML_TOK_TABLE_ROW_CELL_ATTR_DATE_VALUE,
XML_TOK_TABLE_ROW_CELL_ATTR_TIME_VALUE,
XML_TOK_TABLE_ROW_CELL_ATTR_STRING_VALUE,
XML_TOK_TABLE_ROW_CELL_ATTR_BOOLEAN_VALUE,
XML_TOK_TABLE_ROW_CELL_ATTR_FORMULA,
XML_TOK_TABLE_ROW_CELL_ATTR_CURRENCY
};
enum ScXMLAnnotationAttrTokens
{
XML_TOK_TABLE_ANNOTATION_ATTR_AUTHOR,
XML_TOK_TABLE_ANNOTATION_ATTR_CREATE_DATE,
XML_TOK_TABLE_ANNOTATION_ATTR_CREATE_DATE_STRING,
XML_TOK_TABLE_ANNOTATION_ATTR_DISPLAY,
XML_TOK_TABLE_ANNOTATION_ATTR_X,
XML_TOK_TABLE_ANNOTATION_ATTR_Y
};
class SvXMLTokenMap;
class XMLShapeImportHelper;
class ScXMLChangeTrackingImportHelper;
class SolarMutexGuard;
struct ScMyNamedExpression
{
OUString sName;
OUString sContent;
OUString sContentNmsp;
OUString sBaseCellAddress;
OUString sRangeType;
formula::FormulaGrammar::Grammar eGrammar;
bool bIsExpression;
};
typedef ::std::list<std::unique_ptr<ScMyNamedExpression>> ScMyNamedExpressions;
struct ScMyLabelRange
{
OUString sLabelRangeStr;
OUString sDataRangeStr;
bool bColumnOrientation;
};
typedef std::list< std::unique_ptr<const ScMyLabelRange> > ScMyLabelRanges;
struct ScMyImportValidation
{
OUString sName;
OUString sImputTitle;
OUString sImputMessage;
OUString sErrorTitle;
OUString sErrorMessage;
OUString sFormula1;
OUString sFormula2;
OUString sFormulaNmsp1;
OUString sFormulaNmsp2;
OUString sBaseCellAddress; // string is used directly
css::sheet::ValidationAlertStyle aAlertStyle;
css::sheet::ValidationType aValidationType;
css::sheet::ConditionOperator aOperator;
formula::FormulaGrammar::Grammar eGrammar1;
formula::FormulaGrammar::Grammar eGrammar2;
sal_Int16 nShowList;
bool bShowErrorMessage;
bool bShowImputMessage;
bool bIgnoreBlanks;
};
typedef std::vector<ScMyImportValidation> ScMyImportValidations;
class ScMyStylesImportHelper;
class ScXMLEditAttributeMap;
class ScXMLImport: public SvXMLImport
{
ScXMLImport(const ScXMLImport&) = delete;
const ScXMLImport& operator=(const ScXMLImport&) = delete;
typedef ::std::map<SCTAB, std::unique_ptr<ScMyNamedExpressions>> SheetNamedExpMap;
ScDocument* pDoc;
std::unique_ptr<ScDocumentImport> mpDocImport;
std::unique_ptr<ScCompiler> mpComp; // For error-checking of cached string cell values.
std::unique_ptr<ScEditEngineDefaulter> mpEditEngine;
std::unique_ptr<sc::PivotTableSources> mpPivotSources;
mutable std::unique_ptr<ScXMLEditAttributeMap> mpEditAttrMap;
std::unique_ptr<ScXMLChangeTrackingImportHelper> pChangeTrackingImportHelper;
std::unique_ptr<ScMyStylesImportHelper> pStylesImportHelper;
rtl::Reference < XMLPropertyHandlerFactory > xScPropHdlFactory;
rtl::Reference < XMLPropertySetMapper > xCellStylesPropertySetMapper;
rtl::Reference < XMLPropertySetMapper > xColumnStylesPropertySetMapper;
rtl::Reference < XMLPropertySetMapper > xRowStylesPropertySetMapper;
rtl::Reference < XMLPropertySetMapper > xTableStylesPropertySetMapper;
std::unique_ptr<SvXMLTokenMap> pTableElemTokenMap;
std::unique_ptr<SvXMLTokenMap> pTableRowsElemTokenMap;
std::unique_ptr<SvXMLTokenMap> pTableRowElemTokenMap;
std::unique_ptr<SvXMLTokenMap> pTableRowAttrTokenMap;
std::unique_ptr<SvXMLTokenMap> pTableRowCellElemTokenMap;
std::unique_ptr<SvXMLTokenMap> pTableRowCellAttrTokenMap;
std::unique_ptr<SvXMLTokenMap> pTableAnnotationAttrTokenMap;
sc::ImportPostProcessData* mpPostProcessData; /// Lift cycle managed elsewhere, no need to delete.
ScMyTables aTables;
std::vector<ScDocRowHeightUpdater::TabRanges> maRecalcRowRanges;
std::unique_ptr<ScMyNamedExpressions> m_pMyNamedExpressions;
SheetNamedExpMap m_SheetNamedExpressions;
std::unique_ptr<ScMyLabelRanges> pMyLabelRanges;
std::unique_ptr<ScMyImportValidations> pValidations;
std::unique_ptr<ScMyImpDetectiveOpArray> pDetectiveOpArray;
std::unique_ptr<SolarMutexGuard> pSolarMutexGuard;
std::unique_ptr<XMLNumberFormatAttributesExportHelper> pNumberFormatAttributesExportHelper;
std::unique_ptr<ScMyStyleNumberFormats> pStyleNumberFormats;
css::uno::Reference <css::util::XNumberFormats> xNumberFormats;
css::uno::Reference <css::util::XNumberFormatTypes> xNumberFormatTypes;
css::uno::Reference <css::sheet::XSheetCellRangeContainer> xSheetCellRanges;
OUString sPrevStyleName;
OUString sPrevCurrency;
sal_uInt32 nSolarMutexLocked;
sal_Int32 nProgressCount;
sal_Int16 nPrevCellType;
bool bLoadDoc; // Load doc or styles only
bool bNullDateSetted;
bool bSelfImportingXMLSet;
bool mbLockSolarMutex;
bool mbImportStyles;
bool mbHasNewCondFormatData;
protected:
// This method is called after the namespace map has been updated, but
// before a context for the current element has been pushed.
virtual SvXMLImportContext *CreateFastContext( sal_Int32 nElement,
const ::css::uno::Reference< ::css::xml::sax::XFastAttributeList >& xAttrList ) override;
virtual XMLShapeImportHelper* CreateShapeImport() override;
public:
ScXMLImport(
const css::uno::Reference< css::uno::XComponentContext >& rContext,
OUString const & implementationName, SvXMLImportFlags nImportFlag);
virtual ~ScXMLImport() throw() override;
// XInitialization
virtual void SAL_CALL initialize( const css::uno::Sequence<css::uno::Any>& aArguments ) override;
// namespace office
// NB: in contrast to other CreateFooContexts, this particular one handles
// the root element (i.e. office:document-meta)
SvXMLImportContext *CreateMetaContext( sal_Int32 nElement );
SvXMLImportContext *CreateFontDeclsContext();
SvXMLImportContext *CreateScriptContext();
SvXMLImportContext *CreateStylesContext( bool bAutoStyles );
SvXMLImportContext *CreateBodyContext(
const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList );
virtual void SetStatistics( const css::uno::Sequence< css::beans::NamedValue> & i_rStats) override;
ScDocumentImport& GetDoc();
ScDocument* GetDocument() { return pDoc; }
const ScDocument* GetDocument() const { return pDoc; }
ScMyTables& GetTables() { return aTables; }
std::vector<ScDocRowHeightUpdater::TabRanges>& GetRecalcRowRanges() { return maRecalcRowRanges; }
bool IsStylesOnlyMode() const { return !bLoadDoc; }
static sal_Int16 GetCellType(const char* rStrValue, const sal_Int32 nStrLength);
const rtl::Reference < XMLPropertySetMapper >& GetCellStylesPropertySetMapper() const { return xCellStylesPropertySetMapper; }
const rtl::Reference < XMLPropertySetMapper >& GetColumnStylesPropertySetMapper() const { return xColumnStylesPropertySetMapper; }
const rtl::Reference < XMLPropertySetMapper >& GetRowStylesPropertySetMapper() const { return xRowStylesPropertySetMapper; }
const rtl::Reference < XMLPropertySetMapper >& GetTableStylesPropertySetMapper() const { return xTableStylesPropertySetMapper; }
const SvXMLTokenMap& GetTableElemTokenMap();
const SvXMLTokenMap& GetTableRowsElemTokenMap();
const SvXMLTokenMap& GetTableRowElemTokenMap();
const SvXMLTokenMap& GetTableRowAttrTokenMap();
const SvXMLTokenMap& GetTableRowCellElemTokenMap();
const SvXMLTokenMap& GetTableRowCellAttrTokenMap();
const SvXMLTokenMap& GetTableAnnotationAttrTokenMap();
void SetPostProcessData( sc::ImportPostProcessData* p );
sc::ImportPostProcessData* GetPostProcessData() { return mpPostProcessData;}
sc::PivotTableSources& GetPivotTableSources();
void AddNamedExpression(ScMyNamedExpression* pMyNamedExpression)
{
if (!m_pMyNamedExpressions)
m_pMyNamedExpressions.reset(new ScMyNamedExpressions);
m_pMyNamedExpressions->push_back(std::unique_ptr<ScMyNamedExpression>(pMyNamedExpression));
}
void AddNamedExpression(SCTAB nTab, ScMyNamedExpression* pNamedExp);
void AddLabelRange(std::unique_ptr<const ScMyLabelRange> pMyLabelRange) {
if (!pMyLabelRanges)
pMyLabelRanges.reset(new ScMyLabelRanges);
pMyLabelRanges->push_back(std::move(pMyLabelRange)); }
void AddValidation(const ScMyImportValidation& rValidation) {
if (!pValidations)
pValidations.reset(new ScMyImportValidations);
pValidations->push_back(rValidation); }
bool GetValidation(const OUString& sName, ScMyImportValidation& aValidation);
ScMyImpDetectiveOpArray* GetDetectiveOpArray();
ScXMLChangeTrackingImportHelper* GetChangeTrackingImportHelper();
void InsertStyles();
void SetChangeTrackingViewSettings(const css::uno::Sequence<css::beans::PropertyValue>& rChangeProps);
virtual void SetViewSettings(const css::uno::Sequence<css::beans::PropertyValue>& aViewProps) override;
virtual void SetConfigurationSettings(const css::uno::Sequence<css::beans::PropertyValue>& aConfigProps) override;
ScMyStylesImportHelper* GetStylesImportHelper() { return pStylesImportHelper.get(); }
sal_Int32 SetCurrencySymbol(const sal_Int32 nKey, const OUString& rCurrency);
bool IsCurrencySymbol(const sal_Int32 nNumberFormat, const OUString& sCurrencySymbol, const OUString& sBankSymbol);
void SetType(const css::uno::Reference <css::beans::XPropertySet>& rProperties,
sal_Int32& rNumberFormat,
const sal_Int16 nCellType,
const OUString& rCurrency);
void ProgressBarIncrement();
void SetNewCondFormatData() { mbHasNewCondFormatData = true; }
bool HasNewCondFormatData() const { return mbHasNewCondFormatData; }
private:
void AddStyleRange(const css::table::CellRangeAddress& rCellRange);
void SetStyleToRanges();
void ExamineDefaultStyle();
public:
void SetStyleToRange(const ScRange& rRange, const OUString* pStyleName,
const sal_Int16 nCellType, const OUString* pCurrency);
void SetStyleToRanges(const ScRangeList& rRanges, const OUString* pStyleName,
const sal_Int16 nCellType, const OUString* pCurrency);
bool SetNullDateOnUnitConverter();
XMLNumberFormatAttributesExportHelper* GetNumberFormatAttributesExportHelper();
ScMyStyleNumberFormats* GetStyleNumberFormats();
void SetStylesToRangesFinished();
// XImporter
virtual void SAL_CALL setTargetDocument( const css::uno::Reference< css::lang::XComponent >& xDoc ) override;
virtual void SAL_CALL startDocument() override;
virtual void SAL_CALL endDocument() override;
virtual void DisposingModel() override;
/**
* Use this class to manage solar mutex locking instead of calling
* LockSolarMutex() and UnlockSolarMutex() directly.
*/
class MutexGuard
{
public:
explicit MutexGuard(ScXMLImport& rImport);
~MutexGuard();
private:
ScXMLImport& mrImport;
};
void LockSolarMutex();
void UnlockSolarMutex();
sal_Int32 GetByteOffset() const;
void SetRangeOverflowType(ErrCode nType);
static sal_Int32 GetRangeType(const OUString& sRangeType);
void SetNamedRanges();
void SetSheetNamedRanges();
void SetLabelRanges();
void SetStringRefSyntaxIfMissing();
/** Extracts the formula string, the formula grammar namespace URL, and a
grammar enum value from the passed formula attribute value.
@param rFormula
(out-parameter) Returns the plain formula string with the leading
equality sign if existing.
@param rFormulaNmsp
(out-parameter) Returns the URL of the formula grammar namespace if
the attribute value contains the prefix of an unknown namespace.
@param reGrammar
(out-parameter) Returns the exact formula grammar if the formula
is in a supported ODF format (e.g. FormulaGrammar::GRAM_PODF for
ODF 1.0/1.1 formulas, or FormulaGrammar::GRAM_ODFF for ODF 1.2
formulas a.k.a. OpenFormula). Returns the default storage grammar,
if the attribute value does not contain a namespace prefix. Returns
the special value FormulaGrammar::GRAM_EXTERNAL, if an unknown
namespace could be extracted from the formula which will be
contained in the parameter rFormulaNmsp then.
@param rAttrValue
The value of the processed formula attribute.
@param bRestrictToExternalNmsp
If set to true, only namespaces of external formula grammars will
be recognized. Internal namespace prefixes (e.g. 'oooc:' or 'of:'
will be considered to be part of the formula, e.g. an expression
with range operator.
*/
void ExtractFormulaNamespaceGrammar(
OUString& rFormula,
OUString& rFormulaNmsp,
::formula::FormulaGrammar::Grammar& reGrammar,
const OUString& rAttrValue,
bool bRestrictToExternalNmsp = false ) const;
FormulaError GetFormulaErrorConstant( const OUString& rStr ) const;
ScEditEngineDefaulter* GetEditEngine();
const ScXMLEditAttributeMap& GetEditAttributeMap() const;
virtual void NotifyEmbeddedFontRead() override;
};
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|