LibreOffice Module sc (master)  1
xmlnexpi.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #include "xmlnexpi.hxx"
21 #include "xmlimprt.hxx"
22 #include <document.hxx>
23 
24 #include <xmloff/xmlnmspe.hxx>
25 
26 using namespace com::sun::star;
27 using namespace xmloff::token;
28 
30 
32 {
33  if (pExp)
34  mrImport.AddNamedExpression(pExp);
35 }
36 
38  mrImport(rImport), mnTab(nTab) {}
39 
41 {
42  mrImport.AddNamedExpression(mnTab, pExp);
43 }
44 
46  ScXMLImport& rImport,
47  std::shared_ptr<Inserter> pInserter ) :
48  ScXMLImportContext( rImport ),
49  mpInserter(std::move(pInserter))
50 {
51  rImport.LockSolarMutex();
52 }
53 
55 {
57 }
58 
59 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLNamedExpressionsContext::createFastChildContext(
60  sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
61 {
62  SvXMLImportContext *pContext(nullptr);
65 
66  switch (nElement)
67  {
69  pContext = new ScXMLNamedRangeContext(
70  GetScImport(), pAttribList, mpInserter.get() );
71  break;
73  pContext = new ScXMLNamedExpressionContext(
74  GetScImport(), pAttribList, mpInserter.get() );
75  break;
76  }
77 
78  return pContext;
79 }
80 
82  ScXMLImport& rImport,
85  ScXMLImportContext( rImport )
86 {
87  if (!pInserter)
88  return;
89 
90  ScMyNamedExpression* pNamedExpression(new ScMyNamedExpression);
91  // A simple table:cell-range-address is not a formula expression, stored
92  // without [] brackets but with dot, .A1
94  GetScImport().GetDocument()->GetStorageGrammar(),
96 
97  if ( rAttrList.is() )
98  {
99  for (auto &aIter : *rAttrList)
100  {
101  switch (aIter.getToken())
102  {
103  case XML_ELEMENT( TABLE, XML_NAME ):
104  pNamedExpression->sName = aIter.toString();
105  break;
107  pNamedExpression->sContent = aIter.toString();
108  break;
110  pNamedExpression->sBaseCellAddress = aIter.toString();
111  break;
113  pNamedExpression->sRangeType = aIter.toString();
114  break;
115  }
116  }
117  }
118  pNamedExpression->bIsExpression = false;
119  pInserter->insert(pNamedExpression);
120 }
121 
123 {
124 }
125 
127  ScXMLImport& rImport,
130  ScXMLImportContext( rImport )
131 {
132  if (!pInserter)
133  return;
134 
135  ScMyNamedExpression* pNamedExpression(new ScMyNamedExpression);
136 
137  if ( rAttrList.is() )
138  {
139  for (auto &aIter : *rAttrList)
140  {
141  switch (aIter.getToken())
142  {
143  case XML_ELEMENT( TABLE, XML_NAME ):
144  pNamedExpression->sName = aIter.toString();
145  break;
148  pNamedExpression->sContent, pNamedExpression->sContentNmsp,
149  pNamedExpression->eGrammar, aIter.toString() );
150  break;
152  pNamedExpression->sBaseCellAddress = aIter.toString();
153  break;
154  }
155  }
156  }
157  pNamedExpression->bIsExpression = true;
158  pInserter->insert(pNamedExpression);
159 }
160 
162 {
163 }
164 
165 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
XML_NAMED_EXPRESSION
SvXMLImport & mrImport
XML_NAME
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
OUString sBaseCellAddress
Definition: xmlimprt.hxx:153
ScXMLNamedExpressionContext(ScXMLImport &rImport, const rtl::Reference< sax_fastparser::FastAttributeList > &rAttrList, ScXMLNamedExpressionsContext::Inserter *pInserter)
Definition: xmlnexpi.cxx:126
std::shared_ptr< Inserter > mpInserter
Definition: xmlnexpi.hxx:80
virtual ~ScXMLNamedRangeContext() override
Definition: xmlnexpi.cxx:122
XML_CELL_RANGE_ADDRESS
void LockSolarMutex()
Definition: xmlimprt.cxx:1699
static Grammar mergeToGrammar(const Grammar eGrammar, const AddressConvention eConv)
XML_RANGE_USABLE_AS
virtual ~ScXMLNamedExpressionContext() override
Definition: xmlnexpi.cxx:161
OUString sContentNmsp
Definition: xmlimprt.hxx:152
This class exists only to provide GetScImport() to its derived classes.
SheetLocalInserter(ScXMLImport &rImport, SCTAB nTab)
Definition: xmlnexpi.cxx:37
virtual void insert(ScMyNamedExpression *pExp) override
Definition: xmlnexpi.cxx:40
ScXMLImport & GetScImport()
void ExtractFormulaNamespaceGrammar(OUString &rFormula, OUString &rFormulaNmsp,::formula::FormulaGrammar::Grammar &reGrammar, const OUString &rAttrValue, bool bRestrictToExternalNmsp=false) const
Extracts the formula string, the formula grammar namespace URL, and a grammar enum value from the pas...
Definition: xmlimprt.cxx:1760
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override
Definition: xmlnexpi.cxx:59
TABLE
virtual void insert(ScMyNamedExpression *pExp) override
Definition: xmlnexpi.cxx:31
virtual ~ScXMLNamedExpressionsContext() override
Definition: xmlnexpi.cxx:54
void UnlockSolarMutex()
Definition: xmlimprt.cxx:1717
#define XML_ELEMENT(prefix, name)
formula::FormulaGrammar::Grammar eGrammar
Definition: xmlimprt.hxx:155
XML_BASE_CELL_ADDRESS
ScXMLNamedRangeContext(ScXMLImport &rImport, const rtl::Reference< sax_fastparser::FastAttributeList > &rAttrList, ScXMLNamedExpressionsContext::Inserter *pInserter)
Definition: xmlnexpi.cxx:81
XML_EXPRESSION
virtual void insert(ScMyNamedExpression *pExp)=0
XML_NAMED_RANGE
sal_Int16 SCTAB
Definition: types.hxx:23
ScXMLNamedExpressionsContext(ScXMLImport &rImport, std::shared_ptr< Inserter > pInserter)
Definition: xmlnexpi.cxx:45