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/xmlnamespace.hxx>
25 #include <xmloff/xmltoken.hxx>
27 using namespace com::sun::star
;
28 using namespace xmloff::token
;
30 ScXMLNamedExpressionsContext::GlobalInserter::GlobalInserter(ScXMLImport
& rImport
) : mrImport(rImport
) {}
32 void ScXMLNamedExpressionsContext::GlobalInserter::insert(ScMyNamedExpression aExp
)
34 mrImport
.AddNamedExpression(std::move(aExp
));
37 ScXMLNamedExpressionsContext::SheetLocalInserter::SheetLocalInserter(ScXMLImport
& rImport
, SCTAB nTab
) :
38 mrImport(rImport
), mnTab(nTab
) {}
40 void ScXMLNamedExpressionsContext::SheetLocalInserter::insert(ScMyNamedExpression aExp
)
42 mrImport
.AddNamedExpression(mnTab
, std::move(aExp
));
45 ScXMLNamedExpressionsContext::ScXMLNamedExpressionsContext(
47 std::shared_ptr
<Inserter
> pInserter
) :
48 ScXMLImportContext( rImport
),
49 mpInserter(std::move(pInserter
))
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::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() );
81 ScXMLNamedRangeContext::ScXMLNamedRangeContext(
83 const rtl::Reference
<sax_fastparser::FastAttributeList
>& rAttrList
,
84 ScXMLNamedExpressionsContext::Inserter
* pInserter
) :
85 ScXMLImportContext( rImport
)
90 ScDocument
* pDoc
= GetScImport().GetDocument();
93 ScMyNamedExpression aNamedExpression
;
94 // A simple table:cell-range-address is not a formula expression, stored
95 // without [] brackets but with dot, .A1
96 aNamedExpression
.eGrammar
= formula::FormulaGrammar::mergeToGrammar(
97 pDoc
->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 aNamedExpression
.sName
= aIter
.toString();
109 case XML_ELEMENT( TABLE
, XML_CELL_RANGE_ADDRESS
):
110 aNamedExpression
.sContent
= aIter
.toString();
112 case XML_ELEMENT( TABLE
, XML_BASE_CELL_ADDRESS
):
113 aNamedExpression
.sBaseCellAddress
= aIter
.toString();
115 case XML_ELEMENT( TABLE
, XML_RANGE_USABLE_AS
):
116 aNamedExpression
.sRangeType
= aIter
.toString();
121 aNamedExpression
.bIsExpression
= false;
122 pInserter
->insert(std::move(aNamedExpression
));
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 aNamedExpression
;
140 if ( rAttrList
.is() )
142 for (auto &aIter
: *rAttrList
)
144 switch (aIter
.getToken())
146 case XML_ELEMENT( TABLE
, XML_NAME
):
147 aNamedExpression
.sName
= aIter
.toString();
149 case XML_ELEMENT( TABLE
, XML_EXPRESSION
):
150 GetScImport().ExtractFormulaNamespaceGrammar(
151 aNamedExpression
.sContent
, aNamedExpression
.sContentNmsp
,
152 aNamedExpression
.eGrammar
, aIter
.toString() );
154 case XML_ELEMENT( TABLE
, XML_BASE_CELL_ADDRESS
):
155 aNamedExpression
.sBaseCellAddress
= aIter
.toString();
157 case XML_ELEMENT(LO_EXT
, XML_HIDDEN
):
158 if (aIter
.toString() == GetXMLToken(XML_TRUE
))
159 aNamedExpression
.sRangeType
= GetXMLToken(XML_HIDDEN
);
164 aNamedExpression
.bIsExpression
= true;
165 pInserter
->insert(std::move(aNamedExpression
));
168 ScXMLNamedExpressionContext::~ScXMLNamedExpressionContext()
172 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */