tdf#154285 Check upper bound of arguments in SbRtl_Minute function
[LibreOffice.git] / sc / source / filter / xml / xmlnexpi.cxx
blobb25920f1f54b778d1f66b46b77cc9217d49e4ae9
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 ScDocument* pDoc = GetScImport().GetDocument();
91 if (!pDoc)
92 return;
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();
108 break;
109 case XML_ELEMENT( TABLE, XML_CELL_RANGE_ADDRESS ):
110 aNamedExpression.sContent = aIter.toString();
111 break;
112 case XML_ELEMENT( TABLE, XML_BASE_CELL_ADDRESS ):
113 aNamedExpression.sBaseCellAddress = aIter.toString();
114 break;
115 case XML_ELEMENT( TABLE, XML_RANGE_USABLE_AS ):
116 aNamedExpression.sRangeType = aIter.toString();
117 break;
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 )
135 if (!pInserter)
136 return;
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();
148 break;
149 case XML_ELEMENT( TABLE, XML_EXPRESSION ):
150 GetScImport().ExtractFormulaNamespaceGrammar(
151 aNamedExpression.sContent, aNamedExpression.sContentNmsp,
152 aNamedExpression.eGrammar, aIter.toString() );
153 break;
154 case XML_ELEMENT( TABLE, XML_BASE_CELL_ADDRESS ):
155 aNamedExpression.sBaseCellAddress = aIter.toString();
156 break;
157 case XML_ELEMENT(LO_EXT, XML_HIDDEN):
158 if (aIter.toString() == GetXMLToken(XML_TRUE))
159 aNamedExpression.sRangeType = GetXMLToken(XML_HIDDEN);
160 break;
164 aNamedExpression.bIsExpression = true;
165 pInserter->insert(std::move(aNamedExpression));
168 ScXMLNamedExpressionContext::~ScXMLNamedExpressionContext()
172 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */