Version 6.4.0.3, tag libreoffice-6.4.0.3
[LibreOffice.git] / sc / source / filter / xml / xmlnexpi.cxx
blob737b3cda7a627bb4190893921a0427539e472162
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/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)
33 if (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(
46 ScXMLImport& rImport,
47 Inserter* pInserter ) :
48 ScXMLImportContext( rImport ),
49 mpInserter(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::FastAttributeList::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 if( !pContext )
79 pContext = new SvXMLImportContext( GetImport() );
81 return pContext;
84 ScXMLNamedRangeContext::ScXMLNamedRangeContext(
85 ScXMLImport& rImport,
86 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
87 ScXMLNamedExpressionsContext::Inserter* pInserter ) :
88 ScXMLImportContext( rImport )
90 if (!pInserter)
91 return;
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();
108 break;
109 case XML_ELEMENT( TABLE, XML_CELL_RANGE_ADDRESS ):
110 pNamedExpression->sContent = aIter.toString();
111 break;
112 case XML_ELEMENT( TABLE, XML_BASE_CELL_ADDRESS ):
113 pNamedExpression->sBaseCellAddress = aIter.toString();
114 break;
115 case XML_ELEMENT( TABLE, XML_RANGE_USABLE_AS ):
116 pNamedExpression->sRangeType = aIter.toString();
117 break;
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 )
135 if (!pInserter)
136 return;
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();
148 break;
149 case XML_ELEMENT( TABLE, XML_EXPRESSION ):
150 GetScImport().ExtractFormulaNamespaceGrammar(
151 pNamedExpression->sContent, pNamedExpression->sContentNmsp,
152 pNamedExpression->eGrammar, aIter.toString() );
153 break;
154 case XML_ELEMENT( TABLE, XML_BASE_CELL_ADDRESS ):
155 pNamedExpression->sBaseCellAddress = aIter.toString();
156 break;
160 pNamedExpression->bIsExpression = true;
161 pInserter->insert(pNamedExpression);
164 ScXMLNamedExpressionContext::~ScXMLNamedExpressionContext()
168 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */