xref: /aoo4110/main/sc/source/filter/xml/xmlnexpi.cxx (revision b1cdbd2c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sc.hxx"
26 
27 
28 
29 // INCLUDE ---------------------------------------------------------------
30 #include <rtl/ustrbuf.hxx>
31 
32 #include "xmlnexpi.hxx"
33 #include "xmlimprt.hxx"
34 #include "xmlcelli.hxx"
35 #include "docuno.hxx"
36 #include "global.hxx"
37 #include "document.hxx"
38 #include "XMLConverter.hxx"
39 
40 #include <xmloff/xmltkmap.hxx>
41 #include <xmloff/nmspmap.hxx>
42 
43 using namespace com::sun::star;
44 
45 //------------------------------------------------------------------
46 
ScXMLNamedExpressionsContext(ScXMLImport & rImport,sal_uInt16 nPrfx,const::rtl::OUString & rLName,const::com::sun::star::uno::Reference<::com::sun::star::xml::sax::XAttributeList> &)47 ScXMLNamedExpressionsContext::ScXMLNamedExpressionsContext( ScXMLImport& rImport,
48 									  sal_uInt16 nPrfx,
49 									  const ::rtl::OUString& rLName,
50 									  const ::com::sun::star::uno::Reference<
51                                       ::com::sun::star::xml::sax::XAttributeList>& /* xAttrList */ ) :
52 	SvXMLImportContext( rImport, nPrfx, rLName ),
53 	nScopeOfNameRange( MAXTABCOUNT )	//aRangeNameScope( MAXTABCOUNT )
54 {
55 /*	sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
56 	for( sal_Int16 i=0; i < nAttrCount; ++i )
57 	{
58 		const rtl::OUString& sAttrName(xAttrList->getNameByIndex( i ));
59 		rtl::OUString aLocalName;
60 		sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
61 											sAttrName, &aLocalName );
62 		const rtl::OUString& sValue(xAttrList->getValueByIndex( i ));
63 
64 		const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetNamedRangeAttrTokenMap();
65 
66 		switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
67 		{
68 		}
69 	}*/
70 	rImport.LockSolarMutex();
71 }
72 
~ScXMLNamedExpressionsContext()73 ScXMLNamedExpressionsContext::~ScXMLNamedExpressionsContext()
74 {
75 	GetScImport().UnlockSolarMutex();
76 }
77 
CreateChildContext(sal_uInt16 nPrefix,const::rtl::OUString & rLName,const::com::sun::star::uno::Reference<::com::sun::star::xml::sax::XAttributeList> & xAttrList)78 SvXMLImportContext *ScXMLNamedExpressionsContext::CreateChildContext( sal_uInt16 nPrefix,
79 											const ::rtl::OUString& rLName,
80 											const ::com::sun::star::uno::Reference<
81 									  	::com::sun::star::xml::sax::XAttributeList>& xAttrList )
82 {
83 	SvXMLImportContext *pContext(0);
84 
85 	const SvXMLTokenMap& rTokenMap(GetScImport().GetNamedExpressionsElemTokenMap());
86 	switch( rTokenMap.Get( nPrefix, rLName ) )
87 	{
88 	case XML_TOK_NAMED_EXPRESSIONS_NAMED_RANGE:
89 		pContext = new ScXMLNamedRangeContext( GetScImport(), nPrefix,
90 													  rLName, xAttrList,nScopeOfNameRange//,
91 													  //this
92 													  );
93 		break;
94 	case XML_TOK_NAMED_EXPRESSIONS_NAMED_EXPRESSION:
95 		pContext = new ScXMLNamedExpressionContext( GetScImport(), nPrefix,
96 													  rLName, xAttrList, nScopeOfNameRange//,
97 													  //this
98 													  );
99 		break;
100 	}
101 
102 	if( !pContext )
103 		pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
104 
105 	return pContext;
106 }
107 
EndElement()108 void ScXMLNamedExpressionsContext::EndElement()
109 {
110     // happends in ScXMLImport::EndDocument()
111     // because it has to be set after the Database Ranges
112 }
113 
ScXMLNamedRangeContext(ScXMLImport & rImport,sal_uInt16 nPrfx,const::rtl::OUString & rLName,const::com::sun::star::uno::Reference<::com::sun::star::xml::sax::XAttributeList> & xAttrList,SCTAB nScopeOfNameRange)114 ScXMLNamedRangeContext::ScXMLNamedRangeContext( ScXMLImport& rImport,
115 									  sal_uInt16 nPrfx,
116 									  const ::rtl::OUString& rLName,
117 									  const ::com::sun::star::uno::Reference<
118 									  ::com::sun::star::xml::sax::XAttributeList>& xAttrList, SCTAB nScopeOfNameRange) :
119 	SvXMLImportContext( rImport, nPrfx, rLName )
120 {
121 	ScMyNamedExpression* pNamedExpression(new ScMyNamedExpression);
122 	pNamedExpression->nNameScope = nScopeOfNameRange;
123     // A simple table:cell-range-address is not a formula expression, stored
124     // without [] brackets but with dot, .A1
125     pNamedExpression->eGrammar = formula::FormulaGrammar::mergeToGrammar(
126             GetScImport().GetDocument()->GetStorageGrammar(),
127             formula::FormulaGrammar::CONV_OOO);
128 	sal_Int16 nAttrCount(xAttrList.is() ? xAttrList->getLength() : 0);
129 	const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetNamedRangeAttrTokenMap();
130 	for( sal_Int16 i=0; i < nAttrCount; ++i )
131 	{
132 		const rtl::OUString& sAttrName(xAttrList->getNameByIndex( i ));
133 		rtl::OUString aLocalName;
134 		sal_uInt16 nPrefix(GetScImport().GetNamespaceMap().GetKeyByAttrName(
135 											sAttrName, &aLocalName ));
136 		const rtl::OUString& sValue(xAttrList->getValueByIndex( i ));
137 
138 		switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
139 		{
140 			case XML_TOK_NAMED_RANGE_ATTR_NAME :
141 			{
142 				pNamedExpression->sName = sValue;
143 			}
144 			break;
145 			case XML_TOK_NAMED_RANGE_ATTR_CELL_RANGE_ADDRESS :
146 			{
147 				pNamedExpression->sContent = sValue;
148 			}
149 			break;
150 			case XML_TOK_NAMED_RANGE_ATTR_BASE_CELL_ADDRESS :
151 			{
152 				pNamedExpression->sBaseCellAddress = sValue;
153 			}
154 			break;
155 			case XML_TOK_NAMED_RANGE_ATTR_RANGE_USABLE_AS :
156 			{
157 				pNamedExpression->sRangeType = sValue;
158 			}
159 			break;
160 		}
161 	}
162 	pNamedExpression->bIsExpression = sal_False;
163 	GetScImport().AddNamedExpression(pNamedExpression);
164 }
165 
~ScXMLNamedRangeContext()166 ScXMLNamedRangeContext::~ScXMLNamedRangeContext()
167 {
168 }
169 
CreateChildContext(sal_uInt16 nPrefix,const::rtl::OUString & rLName,const::com::sun::star::uno::Reference<::com::sun::star::xml::sax::XAttributeList> &)170 SvXMLImportContext *ScXMLNamedRangeContext::CreateChildContext( sal_uInt16 nPrefix,
171 											const ::rtl::OUString& rLName,
172 											const ::com::sun::star::uno::Reference<
173                                         ::com::sun::star::xml::sax::XAttributeList>& /* xAttrList */ )
174 {
175 /*	const SvXMLTokenMap& rTokenMap = GetScImport().GetTableElemTokenMap();
176 	switch( rTokenMap.Get( nPrefix, rLName ) )
177 	{
178 	}*/
179 	return new SvXMLImportContext( GetImport(), nPrefix, rLName );
180 }
181 
EndElement()182 void ScXMLNamedRangeContext::EndElement()
183 {
184 }
185 
ScXMLNamedExpressionContext(ScXMLImport & rImport,sal_uInt16 nPrfx,const::rtl::OUString & rLName,const::com::sun::star::uno::Reference<::com::sun::star::xml::sax::XAttributeList> & xAttrList,SCTAB nScopeOfNameRange)186 ScXMLNamedExpressionContext::ScXMLNamedExpressionContext( ScXMLImport& rImport,
187 									  sal_uInt16 nPrfx,
188 									  const ::rtl::OUString& rLName,
189 									  const ::com::sun::star::uno::Reference<
190 									  ::com::sun::star::xml::sax::XAttributeList>& xAttrList, SCTAB nScopeOfNameRange) :
191 	SvXMLImportContext( rImport, nPrfx, rLName )
192 {
193 	ScMyNamedExpression* pNamedExpression(new ScMyNamedExpression);
194 	pNamedExpression->nNameScope = nScopeOfNameRange;
195 	sal_Int16 nAttrCount(xAttrList.is() ? xAttrList->getLength() : 0);
196 	const SvXMLTokenMap& rAttrTokenMap(GetScImport().GetNamedExpressionAttrTokenMap());
197 	for( sal_Int16 i=0; i < nAttrCount; ++i )
198 	{
199 		const rtl::OUString& sAttrName(xAttrList->getNameByIndex( i ));
200 		rtl::OUString aLocalName;
201 		sal_uInt16 nPrefix(GetScImport().GetNamespaceMap().GetKeyByAttrName(
202 											sAttrName, &aLocalName ));
203 		const rtl::OUString& sValue(xAttrList->getValueByIndex( i ));
204 
205 		switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
206 		{
207 			case XML_TOK_NAMED_EXPRESSION_ATTR_NAME :
208 			{
209 				pNamedExpression->sName = sValue;
210 			}
211 			break;
212 			case XML_TOK_NAMED_EXPRESSION_ATTR_EXPRESSION :
213 			{
214                 GetScImport().ExtractFormulaNamespaceGrammar(
215                     pNamedExpression->sContent, pNamedExpression->sContentNmsp,
216                     pNamedExpression->eGrammar, sValue );
217 			}
218 			break;
219 			case XML_TOK_NAMED_EXPRESSION_ATTR_BASE_CELL_ADDRESS :
220 			{
221 				pNamedExpression->sBaseCellAddress = sValue;
222 			}
223 			break;
224 		}
225 	}
226 	pNamedExpression->bIsExpression = sal_True;
227 	GetScImport().AddNamedExpression(pNamedExpression);
228 }
229 
~ScXMLNamedExpressionContext()230 ScXMLNamedExpressionContext::~ScXMLNamedExpressionContext()
231 {
232 }
233 
CreateChildContext(sal_uInt16 nPrefix,const::rtl::OUString & rLName,const::com::sun::star::uno::Reference<::com::sun::star::xml::sax::XAttributeList> &)234 SvXMLImportContext *ScXMLNamedExpressionContext::CreateChildContext( sal_uInt16 nPrefix,
235 											const ::rtl::OUString& rLName,
236 											const ::com::sun::star::uno::Reference<
237                                         ::com::sun::star::xml::sax::XAttributeList>& /* xAttrList */ )
238 {
239 /*	const SvXMLTokenMap& rTokenMap = GetScImport().GetTableElemTokenMap();
240 	switch( rTokenMap.Get( nPrefix, rLName ) )
241 	{
242 	}*/
243 	return new SvXMLImportContext( GetImport(), nPrefix, rLName );;
244 }
245 
EndElement()246 void ScXMLNamedExpressionContext::EndElement()
247 {
248 }
249 
250