Line data Source code
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 <rtl/ustrbuf.hxx>
21 :
22 : #include "xmlnexpi.hxx"
23 : #include "xmlimprt.hxx"
24 : #include "xmlcelli.hxx"
25 : #include "docuno.hxx"
26 : #include "document.hxx"
27 :
28 : #include <xmloff/xmltkmap.hxx>
29 : #include <xmloff/nmspmap.hxx>
30 :
31 : using namespace com::sun::star;
32 :
33 88 : ScXMLNamedExpressionsContext::GlobalInserter::GlobalInserter(ScXMLImport& rImport) : mrImport(rImport) {}
34 :
35 56 : void ScXMLNamedExpressionsContext::GlobalInserter::insert(ScMyNamedExpression* pExp)
36 : {
37 56 : if (pExp)
38 56 : mrImport.AddNamedExpression(pExp);
39 56 : }
40 :
41 4 : ScXMLNamedExpressionsContext::SheetLocalInserter::SheetLocalInserter(ScXMLImport& rImport, SCTAB nTab) :
42 4 : mrImport(rImport), mnTab(nTab) {}
43 :
44 6 : void ScXMLNamedExpressionsContext::SheetLocalInserter::insert(ScMyNamedExpression* pExp)
45 : {
46 6 : mrImport.AddNamedExpression(mnTab, pExp);
47 6 : }
48 :
49 92 : 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 ),
54 92 : mpInserter(pInserter)
55 : {
56 92 : rImport.LockSolarMutex();
57 92 : }
58 :
59 276 : ScXMLNamedExpressionsContext::~ScXMLNamedExpressionsContext()
60 : {
61 92 : GetScImport().UnlockSolarMutex();
62 184 : }
63 :
64 62 : 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 )
68 : {
69 62 : SvXMLImportContext *pContext(0);
70 :
71 62 : const SvXMLTokenMap& rTokenMap(GetScImport().GetNamedExpressionsElemTokenMap());
72 62 : switch( rTokenMap.Get( nPrefix, rLName ) )
73 : {
74 : case XML_TOK_NAMED_EXPRESSIONS_NAMED_RANGE:
75 : pContext = new ScXMLNamedRangeContext(
76 37 : GetScImport(), nPrefix, rLName, xAttrList, mpInserter.get() );
77 37 : break;
78 : case XML_TOK_NAMED_EXPRESSIONS_NAMED_EXPRESSION:
79 : pContext = new ScXMLNamedExpressionContext(
80 25 : GetScImport(), nPrefix, rLName, xAttrList, mpInserter.get() );
81 25 : break;
82 : }
83 :
84 62 : if( !pContext )
85 0 : pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
86 :
87 62 : return pContext;
88 : }
89 :
90 92 : void ScXMLNamedExpressionsContext::EndElement()
91 : {
92 : // happends in ScXMLImport::EndDocument()
93 : // because it has to be set after the Database Ranges
94 92 : }
95 :
96 37 : ScXMLNamedRangeContext::ScXMLNamedRangeContext(
97 : ScXMLImport& rImport,
98 : sal_uInt16 nPrfx,
99 : const OUString& rLName,
100 : const uno::Reference<xml::sax::XAttributeList>& xAttrList,
101 : ScXMLNamedExpressionsContext::Inserter* pInserter ) :
102 : SvXMLImportContext( rImport, nPrfx, rLName ),
103 37 : mpInserter(pInserter)
104 : {
105 37 : if (!mpInserter)
106 37 : return;
107 :
108 37 : 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 37 : GetScImport().GetDocument()->GetStorageGrammar(),
113 37 : formula::FormulaGrammar::CONV_OOO);
114 37 : sal_Int16 nAttrCount(xAttrList.is() ? xAttrList->getLength() : 0);
115 37 : const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetNamedRangeAttrTokenMap();
116 148 : for( sal_Int16 i=0; i < nAttrCount; ++i )
117 : {
118 111 : const OUString& sAttrName(xAttrList->getNameByIndex( i ));
119 222 : OUString aLocalName;
120 111 : sal_uInt16 nPrefix(GetScImport().GetNamespaceMap().GetKeyByAttrName(
121 111 : sAttrName, &aLocalName ));
122 222 : const OUString& sValue(xAttrList->getValueByIndex( i ));
123 :
124 111 : switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
125 : {
126 : case XML_TOK_NAMED_RANGE_ATTR_NAME :
127 : {
128 37 : pNamedExpression->sName = sValue;
129 : }
130 37 : break;
131 : case XML_TOK_NAMED_RANGE_ATTR_CELL_RANGE_ADDRESS :
132 : {
133 37 : pNamedExpression->sContent = sValue;
134 : }
135 37 : break;
136 : case XML_TOK_NAMED_RANGE_ATTR_BASE_CELL_ADDRESS :
137 : {
138 37 : pNamedExpression->sBaseCellAddress = sValue;
139 : }
140 37 : break;
141 : case XML_TOK_NAMED_RANGE_ATTR_RANGE_USABLE_AS :
142 : {
143 0 : pNamedExpression->sRangeType = sValue;
144 : }
145 0 : break;
146 : }
147 111 : }
148 37 : pNamedExpression->bIsExpression = false;
149 37 : mpInserter->insert(pNamedExpression);
150 : }
151 :
152 74 : ScXMLNamedRangeContext::~ScXMLNamedRangeContext()
153 : {
154 74 : }
155 :
156 0 : 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 */ )
160 : {
161 0 : return new SvXMLImportContext( GetImport(), nPrefix, rLName );
162 : }
163 :
164 37 : void ScXMLNamedRangeContext::EndElement()
165 : {
166 37 : }
167 :
168 25 : 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 25 : mpInserter(pInserter)
174 : {
175 25 : if (!mpInserter)
176 25 : return;
177 :
178 25 : ScMyNamedExpression* pNamedExpression(new ScMyNamedExpression);
179 25 : sal_Int16 nAttrCount(xAttrList.is() ? xAttrList->getLength() : 0);
180 25 : const SvXMLTokenMap& rAttrTokenMap(GetScImport().GetNamedExpressionAttrTokenMap());
181 100 : for( sal_Int16 i=0; i < nAttrCount; ++i )
182 : {
183 75 : const OUString& sAttrName(xAttrList->getNameByIndex( i ));
184 150 : OUString aLocalName;
185 75 : sal_uInt16 nPrefix(GetScImport().GetNamespaceMap().GetKeyByAttrName(
186 75 : sAttrName, &aLocalName ));
187 150 : const OUString& sValue(xAttrList->getValueByIndex( i ));
188 :
189 75 : switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
190 : {
191 : case XML_TOK_NAMED_EXPRESSION_ATTR_NAME :
192 : {
193 25 : pNamedExpression->sName = sValue;
194 : }
195 25 : break;
196 : case XML_TOK_NAMED_EXPRESSION_ATTR_EXPRESSION :
197 : {
198 25 : GetScImport().ExtractFormulaNamespaceGrammar(
199 : pNamedExpression->sContent, pNamedExpression->sContentNmsp,
200 50 : pNamedExpression->eGrammar, sValue );
201 : }
202 25 : break;
203 : case XML_TOK_NAMED_EXPRESSION_ATTR_BASE_CELL_ADDRESS :
204 : {
205 25 : pNamedExpression->sBaseCellAddress = sValue;
206 : }
207 25 : break;
208 : }
209 75 : }
210 25 : pNamedExpression->bIsExpression = true;
211 25 : mpInserter->insert(pNamedExpression);
212 : }
213 :
214 50 : ScXMLNamedExpressionContext::~ScXMLNamedExpressionContext()
215 : {
216 50 : }
217 :
218 0 : 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 */ )
222 : {
223 0 : return new SvXMLImportContext( GetImport(), nPrefix, rLName );;
224 : }
225 :
226 25 : void ScXMLNamedExpressionContext::EndElement()
227 : {
228 25 : }
229 :
230 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|