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 #include "xmlnexpi.hxx"
21 #include "xmlimprt.hxx"
22 #include <document.hxx>
24 #include <xmloff/xmlnmspe.hxx>
26 using namespace com::sun::star
;
27 using namespace xmloff::token
;
29 ScXMLNamedExpressionsContext::GlobalInserter::GlobalInserter(ScXMLImport
& rImport
) : mrImport(rImport
) {}
31 void ScXMLNamedExpressionsContext::GlobalInserter::insert(ScMyNamedExpression
* pExp
)
34 mrImport
.AddNamedExpression(pExp
);
37 ScXMLNamedExpressionsContext::SheetLocalInserter::SheetLocalInserter(ScXMLImport
& rImport
, SCTAB nTab
) :
38 mrImport(rImport
), mnTab(nTab
) {}
40 void ScXMLNamedExpressionsContext::SheetLocalInserter::insert(ScMyNamedExpression
* pExp
)
42 mrImport
.AddNamedExpression(mnTab
, pExp
);
45 ScXMLNamedExpressionsContext::ScXMLNamedExpressionsContext(
47 Inserter
* pInserter
) :
48 ScXMLImportContext( rImport
),
51 rImport
.LockSolarMutex();
54 ScXMLNamedExpressionsContext::~ScXMLNamedExpressionsContext()
56 GetScImport().UnlockSolarMutex();
59 uno::Reference
< xml::sax::XFastContextHandler
> SAL_CALL
ScXMLNamedExpressionsContext::createFastChildContext(
60 sal_Int32 nElement
, const uno::Reference
< xml::sax::XFastAttributeList
>& xAttrList
)
62 SvXMLImportContext
*pContext(nullptr);
63 sax_fastparser::FastAttributeList
*pAttribList
=
64 sax_fastparser::FastAttributeList::castToFastAttributeList( xAttrList
);
68 case XML_ELEMENT( TABLE
, XML_NAMED_RANGE
):
69 pContext
= new ScXMLNamedRangeContext(
70 GetScImport(), pAttribList
, mpInserter
.get() );
72 case XML_ELEMENT( TABLE
, XML_NAMED_EXPRESSION
):
73 pContext
= new ScXMLNamedExpressionContext(
74 GetScImport(), pAttribList
, mpInserter
.get() );
79 pContext
= new SvXMLImportContext( GetImport() );
84 ScXMLNamedRangeContext::ScXMLNamedRangeContext(
86 const rtl::Reference
<sax_fastparser::FastAttributeList
>& rAttrList
,
87 ScXMLNamedExpressionsContext::Inserter
* pInserter
) :
88 ScXMLImportContext( rImport
)
93 ScMyNamedExpression
* pNamedExpression(new ScMyNamedExpression
);
94 // A simple table:cell-range-address is not a formula expression, stored
95 // without [] brackets but with dot, .A1
96 pNamedExpression
->eGrammar
= formula::FormulaGrammar::mergeToGrammar(
97 GetScImport().GetDocument()->GetStorageGrammar(),
98 formula::FormulaGrammar::CONV_OOO
);
100 if ( rAttrList
.is() )
102 for (auto &aIter
: *rAttrList
)
104 switch (aIter
.getToken())
106 case XML_ELEMENT( TABLE
, XML_NAME
):
107 pNamedExpression
->sName
= aIter
.toString();
109 case XML_ELEMENT( TABLE
, XML_CELL_RANGE_ADDRESS
):
110 pNamedExpression
->sContent
= aIter
.toString();
112 case XML_ELEMENT( TABLE
, XML_BASE_CELL_ADDRESS
):
113 pNamedExpression
->sBaseCellAddress
= aIter
.toString();
115 case XML_ELEMENT( TABLE
, XML_RANGE_USABLE_AS
):
116 pNamedExpression
->sRangeType
= aIter
.toString();
121 pNamedExpression
->bIsExpression
= false;
122 pInserter
->insert(pNamedExpression
);
125 ScXMLNamedRangeContext::~ScXMLNamedRangeContext()
129 ScXMLNamedExpressionContext::ScXMLNamedExpressionContext(
130 ScXMLImport
& rImport
,
131 const rtl::Reference
<sax_fastparser::FastAttributeList
>& rAttrList
,
132 ScXMLNamedExpressionsContext::Inserter
* pInserter
) :
133 ScXMLImportContext( rImport
)
138 ScMyNamedExpression
* pNamedExpression(new ScMyNamedExpression
);
140 if ( rAttrList
.is() )
142 for (auto &aIter
: *rAttrList
)
144 switch (aIter
.getToken())
146 case XML_ELEMENT( TABLE
, XML_NAME
):
147 pNamedExpression
->sName
= aIter
.toString();
149 case XML_ELEMENT( TABLE
, XML_EXPRESSION
):
150 GetScImport().ExtractFormulaNamespaceGrammar(
151 pNamedExpression
->sContent
, pNamedExpression
->sContentNmsp
,
152 pNamedExpression
->eGrammar
, aIter
.toString() );
154 case XML_ELEMENT( TABLE
, XML_BASE_CELL_ADDRESS
):
155 pNamedExpression
->sBaseCellAddress
= aIter
.toString();
160 pNamedExpression
->bIsExpression
= true;
161 pInserter
->insert(pNamedExpression
);
164 ScXMLNamedExpressionContext::~ScXMLNamedExpressionContext()
168 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */