Version 7.5.1.1, tag libreoffice-7.5.1.1
[LibreOffice.git] / sc / source / filter / xml / xmlnexpi.cxx
blobcf2878032be3b4435fbf57ad775010f207e87cc4
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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(
46 ScXMLImport& rImport,
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 );
66 switch (nElement)
68 case XML_ELEMENT( TABLE, XML_NAMED_RANGE ):
69 pContext = new ScXMLNamedRangeContext(
70 GetScImport(), pAttribList, mpInserter.get() );
71 break;
72 case XML_ELEMENT( TABLE, XML_NAMED_EXPRESSION ):
73 pContext = new ScXMLNamedExpressionContext(
74 GetScImport(), pAttribList, mpInserter.get() );
75 break;
78 return pContext;
81 ScXMLNamedRangeContext::ScXMLNamedRangeContext(
82 ScXMLImport& rImport,
83 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
84 ScXMLNamedExpressionsContext::Inserter* pInserter ) :
85 ScXMLImportContext( rImport )
87 if (!pInserter)
88 return;
90 ScMyNamedExpression aNamedExpression;
91 // A simple table:cell-range-address is not a formula expression, stored
92 // without [] brackets but with dot, .A1
93 aNamedExpression.eGrammar = formula::FormulaGrammar::mergeToGrammar(
94 GetScImport().GetDocument()->GetStorageGrammar(),
95 formula::FormulaGrammar::CONV_OOO);
97 if ( rAttrList.is() )
99 for (auto &aIter : *rAttrList)
101 switch (aIter.getToken())
103 case XML_ELEMENT( TABLE, XML_NAME ):
104 aNamedExpression.sName = aIter.toString();
105 break;
106 case XML_ELEMENT( TABLE, XML_CELL_RANGE_ADDRESS ):
107 aNamedExpression.sContent = aIter.toString();
108 break;
109 case XML_ELEMENT( TABLE, XML_BASE_CELL_ADDRESS ):
110 aNamedExpression.sBaseCellAddress = aIter.toString();
111 break;
112 case XML_ELEMENT( TABLE, XML_RANGE_USABLE_AS ):
113 aNamedExpression.sRangeType = aIter.toString();
114 break;
118 aNamedExpression.bIsExpression = false;
119 pInserter->insert(std::move(aNamedExpression));
122 ScXMLNamedRangeContext::~ScXMLNamedRangeContext()
126 ScXMLNamedExpressionContext::ScXMLNamedExpressionContext(
127 ScXMLImport& rImport,
128 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
129 ScXMLNamedExpressionsContext::Inserter* pInserter ) :
130 ScXMLImportContext( rImport )
132 if (!pInserter)
133 return;
135 ScMyNamedExpression aNamedExpression;
137 if ( rAttrList.is() )
139 for (auto &aIter : *rAttrList)
141 switch (aIter.getToken())
143 case XML_ELEMENT( TABLE, XML_NAME ):
144 aNamedExpression.sName = aIter.toString();
145 break;
146 case XML_ELEMENT( TABLE, XML_EXPRESSION ):
147 GetScImport().ExtractFormulaNamespaceGrammar(
148 aNamedExpression.sContent, aNamedExpression.sContentNmsp,
149 aNamedExpression.eGrammar, aIter.toString() );
150 break;
151 case XML_ELEMENT( TABLE, XML_BASE_CELL_ADDRESS ):
152 aNamedExpression.sBaseCellAddress = aIter.toString();
153 break;
157 aNamedExpression.bIsExpression = true;
158 pInserter->insert(std::move(aNamedExpression));
161 ScXMLNamedExpressionContext::~ScXMLNamedExpressionContext()
165 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */