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 <rtl/ustrbuf.hxx>
22 #include "xmlnexpi.hxx"
23 #include "xmlimprt.hxx"
24 #include "xmlcelli.hxx"
26 #include "document.hxx"
28 #include <xmloff/xmltkmap.hxx>
29 #include <xmloff/nmspmap.hxx>
31 using namespace com::sun::star
;
33 ScXMLNamedExpressionsContext::GlobalInserter::GlobalInserter(ScXMLImport
& rImport
) : mrImport(rImport
) {}
35 void ScXMLNamedExpressionsContext::GlobalInserter::insert(ScMyNamedExpression
* pExp
)
38 mrImport
.AddNamedExpression(pExp
);
41 ScXMLNamedExpressionsContext::SheetLocalInserter::SheetLocalInserter(ScXMLImport
& rImport
, SCTAB nTab
) :
42 mrImport(rImport
), mnTab(nTab
) {}
44 void ScXMLNamedExpressionsContext::SheetLocalInserter::insert(ScMyNamedExpression
* pExp
)
46 mrImport
.AddNamedExpression(mnTab
, pExp
);
49 ScXMLNamedExpressionsContext::ScXMLNamedExpressionsContext(
50 ScXMLImport
& rImport
, sal_uInt16 nPrfx
, const OUString
& rLName
,
51 const uno::Reference
<xml::sax::XAttributeList
>& /* xAttrList */,
52 Inserter
* pInserter
) :
53 SvXMLImportContext( rImport
, nPrfx
, rLName
),
56 rImport
.LockSolarMutex();
59 ScXMLNamedExpressionsContext::~ScXMLNamedExpressionsContext()
61 GetScImport().UnlockSolarMutex();
64 SvXMLImportContext
*ScXMLNamedExpressionsContext::CreateChildContext( sal_uInt16 nPrefix
,
65 const OUString
& rLName
,
66 const ::com::sun::star::uno::Reference
<
67 ::com::sun::star::xml::sax::XAttributeList
>& xAttrList
)
69 SvXMLImportContext
*pContext(0);
71 const SvXMLTokenMap
& rTokenMap(GetScImport().GetNamedExpressionsElemTokenMap());
72 switch( rTokenMap
.Get( nPrefix
, rLName
) )
74 case XML_TOK_NAMED_EXPRESSIONS_NAMED_RANGE
:
75 pContext
= new ScXMLNamedRangeContext(
76 GetScImport(), nPrefix
, rLName
, xAttrList
, mpInserter
.get() );
78 case XML_TOK_NAMED_EXPRESSIONS_NAMED_EXPRESSION
:
79 pContext
= new ScXMLNamedExpressionContext(
80 GetScImport(), nPrefix
, rLName
, xAttrList
, mpInserter
.get() );
85 pContext
= new SvXMLImportContext( GetImport(), nPrefix
, rLName
);
90 void ScXMLNamedExpressionsContext::EndElement()
92 // happens in ScXMLImport::EndDocument()
93 // because it has to be set after the Database Ranges
96 ScXMLNamedRangeContext::ScXMLNamedRangeContext(
99 const OUString
& rLName
,
100 const uno::Reference
<xml::sax::XAttributeList
>& xAttrList
,
101 ScXMLNamedExpressionsContext::Inserter
* pInserter
) :
102 SvXMLImportContext( rImport
, nPrfx
, rLName
),
103 mpInserter(pInserter
)
108 ScMyNamedExpression
* pNamedExpression(new ScMyNamedExpression
);
109 // A simple table:cell-range-address is not a formula expression, stored
110 // without [] brackets but with dot, .A1
111 pNamedExpression
->eGrammar
= formula::FormulaGrammar::mergeToGrammar(
112 GetScImport().GetDocument()->GetStorageGrammar(),
113 formula::FormulaGrammar::CONV_OOO
);
114 sal_Int16
nAttrCount(xAttrList
.is() ? xAttrList
->getLength() : 0);
115 const SvXMLTokenMap
& rAttrTokenMap
= GetScImport().GetNamedRangeAttrTokenMap();
116 for( sal_Int16 i
=0; i
< nAttrCount
; ++i
)
118 const OUString
& sAttrName(xAttrList
->getNameByIndex( i
));
120 sal_uInt16
nPrefix(GetScImport().GetNamespaceMap().GetKeyByAttrName(
121 sAttrName
, &aLocalName
));
122 const OUString
& sValue(xAttrList
->getValueByIndex( i
));
124 switch( rAttrTokenMap
.Get( nPrefix
, aLocalName
) )
126 case XML_TOK_NAMED_RANGE_ATTR_NAME
:
128 pNamedExpression
->sName
= sValue
;
131 case XML_TOK_NAMED_RANGE_ATTR_CELL_RANGE_ADDRESS
:
133 pNamedExpression
->sContent
= sValue
;
136 case XML_TOK_NAMED_RANGE_ATTR_BASE_CELL_ADDRESS
:
138 pNamedExpression
->sBaseCellAddress
= sValue
;
141 case XML_TOK_NAMED_RANGE_ATTR_RANGE_USABLE_AS
:
143 pNamedExpression
->sRangeType
= sValue
;
148 pNamedExpression
->bIsExpression
= false;
149 mpInserter
->insert(pNamedExpression
);
152 ScXMLNamedRangeContext::~ScXMLNamedRangeContext()
156 SvXMLImportContext
*ScXMLNamedRangeContext::CreateChildContext( sal_uInt16 nPrefix
,
157 const OUString
& rLName
,
158 const ::com::sun::star::uno::Reference
<
159 ::com::sun::star::xml::sax::XAttributeList
>& /* xAttrList */ )
161 return new SvXMLImportContext( GetImport(), nPrefix
, rLName
);
164 void ScXMLNamedRangeContext::EndElement()
168 ScXMLNamedExpressionContext::ScXMLNamedExpressionContext(
169 ScXMLImport
& rImport
, sal_uInt16 nPrfx
, const OUString
& rLName
,
170 const uno::Reference
<xml::sax::XAttributeList
>& xAttrList
,
171 ScXMLNamedExpressionsContext::Inserter
* pInserter
) :
172 SvXMLImportContext( rImport
, nPrfx
, rLName
),
173 mpInserter(pInserter
)
178 ScMyNamedExpression
* pNamedExpression(new ScMyNamedExpression
);
179 sal_Int16
nAttrCount(xAttrList
.is() ? xAttrList
->getLength() : 0);
180 const SvXMLTokenMap
& rAttrTokenMap(GetScImport().GetNamedExpressionAttrTokenMap());
181 for( sal_Int16 i
=0; i
< nAttrCount
; ++i
)
183 const OUString
& sAttrName(xAttrList
->getNameByIndex( i
));
185 sal_uInt16
nPrefix(GetScImport().GetNamespaceMap().GetKeyByAttrName(
186 sAttrName
, &aLocalName
));
187 const OUString
& sValue(xAttrList
->getValueByIndex( i
));
189 switch( rAttrTokenMap
.Get( nPrefix
, aLocalName
) )
191 case XML_TOK_NAMED_EXPRESSION_ATTR_NAME
:
193 pNamedExpression
->sName
= sValue
;
196 case XML_TOK_NAMED_EXPRESSION_ATTR_EXPRESSION
:
198 GetScImport().ExtractFormulaNamespaceGrammar(
199 pNamedExpression
->sContent
, pNamedExpression
->sContentNmsp
,
200 pNamedExpression
->eGrammar
, sValue
);
203 case XML_TOK_NAMED_EXPRESSION_ATTR_BASE_CELL_ADDRESS
:
205 pNamedExpression
->sBaseCellAddress
= sValue
;
210 pNamedExpression
->bIsExpression
= true;
211 mpInserter
->insert(pNamedExpression
);
214 ScXMLNamedExpressionContext::~ScXMLNamedExpressionContext()
218 SvXMLImportContext
*ScXMLNamedExpressionContext::CreateChildContext( sal_uInt16 nPrefix
,
219 const OUString
& rLName
,
220 const ::com::sun::star::uno::Reference
<
221 ::com::sun::star::xml::sax::XAttributeList
>& /* xAttrList */ )
223 return new SvXMLImportContext( GetImport(), nPrefix
, rLName
);;
226 void ScXMLNamedExpressionContext::EndElement()
230 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */