update ooo310-m15
[ooovba.git] / sc / source / filter / xml / xmlnexpi.cxx
blobb74d5024a5f176b8906a851cb3af4a86aa8c8794
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
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 const formula::FormulaGrammar::Grammar eStorageGrammar = pNamedExpression->eGrammar =
200 GetScImport().GetDocument()->GetStorageGrammar();
201 sal_Int16 nAttrCount(xAttrList.is() ? xAttrList->getLength() : 0);
202 const SvXMLTokenMap& rAttrTokenMap(GetScImport().GetNamedExpressionAttrTokenMap());
203 for( sal_Int16 i=0; i < nAttrCount; ++i )
205 const rtl::OUString& sAttrName(xAttrList->getNameByIndex( i ));
206 rtl::OUString aLocalName;
207 USHORT nPrefix(GetScImport().GetNamespaceMap().GetKeyByAttrName(
208 sAttrName, &aLocalName ));
209 const rtl::OUString& sValue(xAttrList->getValueByIndex( i ));
211 switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
213 case XML_TOK_NAMED_EXPRESSION_ATTR_NAME :
215 pNamedExpression->sName = sValue;
217 break;
218 case XML_TOK_NAMED_EXPRESSION_ATTR_EXPRESSION :
220 rtl::OUString sFormula;
221 sal_uInt16 nFormulaPrefix = GetImport().GetNamespaceMap().
222 _GetKeyByAttrName( sValue, &sFormula, sal_False );
224 if (ScXMLImport::IsAcceptedFormulaNamespace( nFormulaPrefix,
225 sValue, pNamedExpression->eGrammar,
226 eStorageGrammar))
227 pNamedExpression->sContent = sFormula;
228 else
229 pNamedExpression->sContent = sValue;
231 break;
232 case XML_TOK_NAMED_EXPRESSION_ATTR_BASE_CELL_ADDRESS :
234 pNamedExpression->sBaseCellAddress = sValue;
236 break;
239 pNamedExpression->bIsExpression = sal_True;
240 GetScImport().AddNamedExpression(pNamedExpression);
243 ScXMLNamedExpressionContext::~ScXMLNamedExpressionContext()
247 SvXMLImportContext *ScXMLNamedExpressionContext::CreateChildContext( USHORT nPrefix,
248 const ::rtl::OUString& rLName,
249 const ::com::sun::star::uno::Reference<
250 ::com::sun::star::xml::sax::XAttributeList>& /* xAttrList */ )
252 /* const SvXMLTokenMap& rTokenMap = GetScImport().GetTableElemTokenMap();
253 switch( rTokenMap.Get( nPrefix, rLName ) )
256 return new SvXMLImportContext( GetImport(), nPrefix, rLName );;
259 void ScXMLNamedExpressionContext::EndElement()