update dev300-m58
[ooovba.git] / sc / source / filter / xml / XMLConsolidationContext.cxx
blob985a2822ab47fffabeb924a5a9a7580081e31ea9
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: XMLConsolidationContext.cxx,v $
10 * $Revision: 1.12 $
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 //___________________________________________________________________
37 #include "XMLConsolidationContext.hxx"
38 #include "document.hxx"
39 #include "rangeutl.hxx"
40 #include "xmlimprt.hxx"
41 #include "XMLConverter.hxx"
42 #include <xmloff/nmspmap.hxx>
43 #include <xmloff/xmltoken.hxx>
45 using ::rtl::OUString;
46 using namespace ::com::sun::star;
47 using namespace xmloff::token;
50 //___________________________________________________________________
52 ScXMLConsolidationContext::ScXMLConsolidationContext(
53 ScXMLImport& rImport,
54 USHORT nPrfx,
55 const OUString& rLName,
56 const uno::Reference< xml::sax::XAttributeList >& xAttrList ) :
57 SvXMLImportContext( rImport, nPrfx, rLName ),
58 eFunction( SUBTOTAL_FUNC_NONE ),
59 bLinkToSource( sal_False ),
60 bTargetAddr(sal_False)
62 rImport.LockSolarMutex();
63 if( !xAttrList.is() ) return;
65 sal_Int16 nAttrCount = xAttrList->getLength();
66 const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetConsolidationAttrTokenMap();
68 for( sal_Int16 nIndex = 0; nIndex < nAttrCount; ++nIndex )
70 const rtl::OUString& sAttrName (xAttrList->getNameByIndex( nIndex ));
71 const rtl::OUString& sValue (xAttrList->getValueByIndex( nIndex ));
72 OUString aLocalName;
73 USHORT nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
75 switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
77 case XML_TOK_CONSOLIDATION_ATTR_FUNCTION:
78 eFunction = ScXMLConverter::GetSubTotalFuncFromString( sValue );
79 break;
80 case XML_TOK_CONSOLIDATION_ATTR_SOURCE_RANGES:
81 sSourceList = sValue;
82 break;
83 case XML_TOK_CONSOLIDATION_ATTR_TARGET_ADDRESS:
85 sal_Int32 nOffset(0);
86 bTargetAddr = ScRangeStringConverter::GetAddressFromString(
87 aTargetAddr, sValue, GetScImport().GetDocument(), ::formula::FormulaGrammar::CONV_OOO, nOffset );
89 break;
90 case XML_TOK_CONSOLIDATION_ATTR_USE_LABEL:
91 sUseLabel = sValue;
92 break;
93 case XML_TOK_CONSOLIDATION_ATTR_LINK_TO_SOURCE:
94 bLinkToSource = IsXMLToken(sValue, XML_TRUE);
95 break;
100 ScXMLConsolidationContext::~ScXMLConsolidationContext()
104 SvXMLImportContext *ScXMLConsolidationContext::CreateChildContext(
105 USHORT nPrefix,
106 const OUString& rLName,
107 const uno::Reference< xml::sax::XAttributeList>& /* xAttrList */ )
109 return new SvXMLImportContext( GetImport(), nPrefix, rLName );
112 void ScXMLConsolidationContext::EndElement()
114 if (bTargetAddr)
116 ScConsolidateParam aConsParam;
117 aConsParam.nCol = aTargetAddr.Col();
118 aConsParam.nRow = aTargetAddr.Row();
119 aConsParam.nTab = aTargetAddr.Tab();
120 aConsParam.eFunction = eFunction;
122 sal_Bool bError = sal_False;
123 USHORT nCount = (USHORT) Min( ScRangeStringConverter::GetTokenCount( sSourceList ), (sal_Int32)0xFFFF );
124 ScArea** ppAreas = nCount ? new ScArea*[ nCount ] : NULL;
125 if( ppAreas )
127 sal_Int32 nOffset = 0;
128 USHORT nIndex;
129 for( nIndex = 0; nIndex < nCount; ++nIndex )
131 ppAreas[ nIndex ] = new ScArea;
132 if ( !ScRangeStringConverter::GetAreaFromString(
133 *ppAreas[ nIndex ], sSourceList, GetScImport().GetDocument(), ::formula::FormulaGrammar::CONV_OOO, nOffset ) )
135 bError = sal_True; //! handle error
139 aConsParam.SetAreas( ppAreas, nCount );
141 // array is copied in SetAreas
142 for( nIndex = 0; nIndex < nCount; ++nIndex )
143 delete ppAreas[nIndex];
144 delete[] ppAreas;
147 aConsParam.bByCol = aConsParam.bByRow = FALSE;
148 if( IsXMLToken(sUseLabel, XML_COLUMN ) )
149 aConsParam.bByCol = TRUE;
150 else if( IsXMLToken( sUseLabel, XML_ROW ) )
151 aConsParam.bByRow = TRUE;
152 else if( IsXMLToken( sUseLabel, XML_BOTH ) )
153 aConsParam.bByCol = aConsParam.bByRow = TRUE;
155 aConsParam.bReferenceData = bLinkToSource;
157 ScDocument* pDoc = GetScImport().GetDocument();
158 if( pDoc )
159 pDoc->SetConsolidateDlgData( &aConsParam );
161 GetScImport().UnlockSolarMutex();