Update ooo320-m1
[ooovba.git] / sc / source / filter / xml / xmlnexpi.cxx
blob6254ad6e7b9dc6332daee8371c0f61d45da21455
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: xmlnexpi.cxx,v $
10 * $Revision: 1.18 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
36 // INCLUDE ---------------------------------------------------------------
37 #include <rtl/ustrbuf.hxx>
39 #include "xmlnexpi.hxx"
40 #include "xmlimprt.hxx"
41 #include "xmlcelli.hxx"
42 #include "docuno.hxx"
43 #include "global.hxx"
44 #include "document.hxx"
45 #include "XMLConverter.hxx"
47 #include <xmloff/xmltkmap.hxx>
48 #include <xmloff/nmspmap.hxx>
50 using namespace com::sun::star;
52 //------------------------------------------------------------------
54 ScXMLNamedExpressionsContext::ScXMLNamedExpressionsContext( ScXMLImport& rImport,
55 USHORT nPrfx,
56 const ::rtl::OUString& rLName,
57 const ::com::sun::star::uno::Reference<
58 ::com::sun::star::xml::sax::XAttributeList>& /* xAttrList */ ) :
59 SvXMLImportContext( rImport, nPrfx, rLName )
61 /* sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
62 for( sal_Int16 i=0; i < nAttrCount; ++i )
64 const rtl::OUString& sAttrName(xAttrList->getNameByIndex( i ));
65 rtl::OUString aLocalName;
66 USHORT nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
67 sAttrName, &aLocalName );
68 const rtl::OUString& sValue(xAttrList->getValueByIndex( i ));
70 const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetNamedRangeAttrTokenMap();
72 switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
75 }*/
76 rImport.LockSolarMutex();
79 ScXMLNamedExpressionsContext::~ScXMLNamedExpressionsContext()
81 GetScImport().UnlockSolarMutex();
84 SvXMLImportContext *ScXMLNamedExpressionsContext::CreateChildContext( USHORT nPrefix,
85 const ::rtl::OUString& rLName,
86 const ::com::sun::star::uno::Reference<
87 ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
89 SvXMLImportContext *pContext(0);
91 const SvXMLTokenMap& rTokenMap(GetScImport().GetNamedExpressionsElemTokenMap());
92 switch( rTokenMap.Get( nPrefix, rLName ) )
94 case XML_TOK_NAMED_EXPRESSIONS_NAMED_RANGE:
95 pContext = new ScXMLNamedRangeContext( GetScImport(), nPrefix,
96 rLName, xAttrList//,
97 //this
99 break;
100 case XML_TOK_NAMED_EXPRESSIONS_NAMED_EXPRESSION:
101 pContext = new ScXMLNamedExpressionContext( GetScImport(), nPrefix,
102 rLName, xAttrList//,
103 //this
105 break;
108 if( !pContext )
109 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
111 return pContext;
114 void ScXMLNamedExpressionsContext::EndElement()
116 // happends in ScXMLImport::EndDocument()
117 // because it has to be set after the Database Ranges
120 ScXMLNamedRangeContext::ScXMLNamedRangeContext( ScXMLImport& rImport,
121 USHORT nPrfx,
122 const ::rtl::OUString& rLName,
123 const ::com::sun::star::uno::Reference<
124 ::com::sun::star::xml::sax::XAttributeList>& xAttrList) :
125 SvXMLImportContext( rImport, nPrfx, rLName )
127 ScMyNamedExpression* pNamedExpression(new ScMyNamedExpression);
128 // A simple table:cell-range-address is not a formula expression, stored
129 // without [] brackets but with dot, .A1
130 pNamedExpression->eGrammar = formula::FormulaGrammar::mergeToGrammar(
131 GetScImport().GetDocument()->GetStorageGrammar(),
132 formula::FormulaGrammar::CONV_OOO);
133 sal_Int16 nAttrCount(xAttrList.is() ? xAttrList->getLength() : 0);
134 const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetNamedRangeAttrTokenMap();
135 for( sal_Int16 i=0; i < nAttrCount; ++i )
137 const rtl::OUString& sAttrName(xAttrList->getNameByIndex( i ));
138 rtl::OUString aLocalName;
139 USHORT nPrefix(GetScImport().GetNamespaceMap().GetKeyByAttrName(
140 sAttrName, &aLocalName ));
141 const rtl::OUString& sValue(xAttrList->getValueByIndex( i ));
143 switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
145 case XML_TOK_NAMED_RANGE_ATTR_NAME :
147 pNamedExpression->sName = sValue;
149 break;
150 case XML_TOK_NAMED_RANGE_ATTR_CELL_RANGE_ADDRESS :
152 pNamedExpression->sContent = sValue;
154 break;
155 case XML_TOK_NAMED_RANGE_ATTR_BASE_CELL_ADDRESS :
157 pNamedExpression->sBaseCellAddress = sValue;
159 break;
160 case XML_TOK_NAMED_RANGE_ATTR_RANGE_USABLE_AS :
162 pNamedExpression->sRangeType = sValue;
164 break;
167 pNamedExpression->bIsExpression = sal_False;
168 GetScImport().AddNamedExpression(pNamedExpression);
171 ScXMLNamedRangeContext::~ScXMLNamedRangeContext()
175 SvXMLImportContext *ScXMLNamedRangeContext::CreateChildContext( USHORT nPrefix,
176 const ::rtl::OUString& rLName,
177 const ::com::sun::star::uno::Reference<
178 ::com::sun::star::xml::sax::XAttributeList>& /* xAttrList */ )
180 /* const SvXMLTokenMap& rTokenMap = GetScImport().GetTableElemTokenMap();
181 switch( rTokenMap.Get( nPrefix, rLName ) )
184 return new SvXMLImportContext( GetImport(), nPrefix, rLName );
187 void ScXMLNamedRangeContext::EndElement()
191 ScXMLNamedExpressionContext::ScXMLNamedExpressionContext( ScXMLImport& rImport,
192 USHORT nPrfx,
193 const ::rtl::OUString& rLName,
194 const ::com::sun::star::uno::Reference<
195 ::com::sun::star::xml::sax::XAttributeList>& xAttrList) :
196 SvXMLImportContext( rImport, nPrfx, rLName )
198 ScMyNamedExpression* pNamedExpression(new ScMyNamedExpression);
199 sal_Int16 nAttrCount(xAttrList.is() ? xAttrList->getLength() : 0);
200 const SvXMLTokenMap& rAttrTokenMap(GetScImport().GetNamedExpressionAttrTokenMap());
201 for( sal_Int16 i=0; i < nAttrCount; ++i )
203 const rtl::OUString& sAttrName(xAttrList->getNameByIndex( i ));
204 rtl::OUString aLocalName;
205 USHORT nPrefix(GetScImport().GetNamespaceMap().GetKeyByAttrName(
206 sAttrName, &aLocalName ));
207 const rtl::OUString& sValue(xAttrList->getValueByIndex( i ));
209 switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
211 case XML_TOK_NAMED_EXPRESSION_ATTR_NAME :
213 pNamedExpression->sName = sValue;
215 break;
216 case XML_TOK_NAMED_EXPRESSION_ATTR_EXPRESSION :
218 GetScImport().ExtractFormulaNamespaceGrammar(
219 pNamedExpression->sContent, pNamedExpression->sContentNmsp,
220 pNamedExpression->eGrammar, sValue );
222 break;
223 case XML_TOK_NAMED_EXPRESSION_ATTR_BASE_CELL_ADDRESS :
225 pNamedExpression->sBaseCellAddress = sValue;
227 break;
230 pNamedExpression->bIsExpression = sal_True;
231 GetScImport().AddNamedExpression(pNamedExpression);
234 ScXMLNamedExpressionContext::~ScXMLNamedExpressionContext()
238 SvXMLImportContext *ScXMLNamedExpressionContext::CreateChildContext( USHORT nPrefix,
239 const ::rtl::OUString& rLName,
240 const ::com::sun::star::uno::Reference<
241 ::com::sun::star::xml::sax::XAttributeList>& /* xAttrList */ )
243 /* const SvXMLTokenMap& rTokenMap = GetScImport().GetTableElemTokenMap();
244 switch( rTokenMap.Get( nPrefix, rLName ) )
247 return new SvXMLImportContext( GetImport(), nPrefix, rLName );;
250 void ScXMLNamedExpressionContext::EndElement()