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: pivottablefragment.cxx,v $
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 #include "oox/xls/pivottablefragment.hxx"
32 #include "oox/xls/biffinputstream.hxx"
33 #include "oox/xls/pivottablebuffer.hxx"
35 using ::rtl::OUString
;
36 using ::oox::core::ContextHandlerRef
;
37 using ::oox::core::RecordInfo
;
42 // ============================================================================
44 OoxPivotTableFieldContext::OoxPivotTableFieldContext( OoxWorksheetFragmentBase
& rFragment
, PivotTableField
& rTableField
) :
45 OoxWorksheetContextBase( rFragment
),
46 mrTableField( rTableField
)
50 ContextHandlerRef
OoxPivotTableFieldContext::onCreateContext( sal_Int32 nElement
, const AttributeList
& rAttribs
)
52 switch( getCurrentElement() )
54 case XLS_TOKEN( pivotField
):
57 case XLS_TOKEN( items
): return this;
58 case XLS_TOKEN( autoSortScope
): return this;
61 case XLS_TOKEN( items
):
62 if( nElement
== XLS_TOKEN( item
) ) mrTableField
.importItem( rAttribs
);
64 case XLS_TOKEN( autoSortScope
):
65 if( nElement
== XLS_TOKEN( pivotArea
) ) return this;
67 case XLS_TOKEN( pivotArea
):
68 if( nElement
== XLS_TOKEN( references
) ) return this;
70 case XLS_TOKEN( references
):
71 if( nElement
== XLS_TOKEN( reference
) ) { mrTableField
.importReference( rAttribs
); return this; }
73 case XLS_TOKEN( reference
):
74 if( nElement
== XLS_TOKEN( x
) ) mrTableField
.importReferenceItem( rAttribs
);
80 void OoxPivotTableFieldContext::onStartElement( const AttributeList
& rAttribs
)
83 mrTableField
.importPivotField( rAttribs
);
86 ContextHandlerRef
OoxPivotTableFieldContext::onCreateRecordContext( sal_Int32 nRecId
, RecordInputStream
& rStrm
)
88 switch( getCurrentElement() )
90 case OOBIN_ID_PTFIELD
:
93 case OOBIN_ID_PTFITEMS
: return this;
94 case OOBIN_ID_AUTOSORTSCOPE
: return this;
97 case OOBIN_ID_PTFITEMS
:
98 if( nRecId
== OOBIN_ID_PTFITEM
) mrTableField
.importPTFItem( rStrm
);
100 case OOBIN_ID_AUTOSORTSCOPE
:
101 if( nRecId
== OOBIN_ID_PIVOTAREA
) return this;
103 case OOBIN_ID_PIVOTAREA
:
104 if( nRecId
== OOBIN_ID_PTREFERENCES
) return this;
106 case OOBIN_ID_PTREFERENCES
:
107 if( nRecId
== OOBIN_ID_PTREFERENCE
) { mrTableField
.importPTReference( rStrm
); return this; }
109 case OOBIN_ID_PTREFERENCE
:
110 if( nRecId
== OOBIN_ID_PTREFERENCEITEM
) mrTableField
.importPTReferenceItem( rStrm
);
116 void OoxPivotTableFieldContext::onStartRecord( RecordInputStream
& rStrm
)
118 if( isRootElement() )
119 mrTableField
.importPTField( rStrm
);
122 // ============================================================================
124 OoxPivotTableFilterContext::OoxPivotTableFilterContext( OoxWorksheetFragmentBase
& rFragment
, PivotTableFilter
& rTableFilter
) :
125 OoxWorksheetContextBase( rFragment
),
126 mrTableFilter( rTableFilter
)
130 ContextHandlerRef
OoxPivotTableFilterContext::onCreateContext( sal_Int32 nElement
, const AttributeList
& rAttribs
)
132 switch( getCurrentElement() )
134 case XLS_TOKEN( filter
):
135 if( nElement
== XLS_TOKEN( autoFilter
) ) return this;
137 case XLS_TOKEN( autoFilter
):
138 if( nElement
== XLS_TOKEN( filterColumn
) ) return this;
140 case XLS_TOKEN( filterColumn
):
141 if( nElement
== XLS_TOKEN( top10
) ) mrTableFilter
.importTop10( rAttribs
);
147 void OoxPivotTableFilterContext::onStartElement( const AttributeList
& rAttribs
)
149 if( isRootElement() )
150 mrTableFilter
.importFilter( rAttribs
);
153 ContextHandlerRef
OoxPivotTableFilterContext::onCreateRecordContext( sal_Int32 nRecId
, RecordInputStream
& rStrm
)
155 switch( getCurrentElement() )
157 case OOBIN_ID_PTFILTER
:
158 if( nRecId
== OOBIN_ID_AUTOFILTER
) return this;
160 case OOBIN_ID_AUTOFILTER
:
161 if( nRecId
== OOBIN_ID_FILTERCOLUMN
) return this;
163 case OOBIN_ID_FILTERCOLUMN
:
164 if( nRecId
== OOBIN_ID_TOP10FILTER
) mrTableFilter
.importTop10Filter( rStrm
);
170 void OoxPivotTableFilterContext::onStartRecord( RecordInputStream
& rStrm
)
172 if( isRootElement() )
173 mrTableFilter
.importPTFilter( rStrm
);
176 // ============================================================================
178 OoxPivotTableFragment::OoxPivotTableFragment( const WorksheetHelper
& rHelper
, const OUString
& rFragmentPath
) :
179 OoxWorksheetFragmentBase( rHelper
, rFragmentPath
),
180 mrPivotTable( rHelper
.getPivotTables().createPivotTable() )
184 ContextHandlerRef
OoxPivotTableFragment::onCreateContext( sal_Int32 nElement
, const AttributeList
& rAttribs
)
186 switch( getCurrentElement() )
188 case XML_ROOT_CONTEXT
:
189 if( nElement
== XLS_TOKEN( pivotTableDefinition
) ) { mrPivotTable
.importPivotTableDefinition( rAttribs
); return this; }
192 case XLS_TOKEN( pivotTableDefinition
):
195 case XLS_TOKEN( location
): mrPivotTable
.importLocation( rAttribs
, getSheetIndex() ); break;
196 case XLS_TOKEN( pivotFields
): return this;
197 case XLS_TOKEN( rowFields
): return this;
198 case XLS_TOKEN( colFields
): return this;
199 case XLS_TOKEN( pageFields
): return this;
200 case XLS_TOKEN( dataFields
): return this;
201 case XLS_TOKEN( filters
): return this;
205 case XLS_TOKEN( pivotFields
):
206 if( nElement
== XLS_TOKEN( pivotField
) ) return new OoxPivotTableFieldContext( *this, mrPivotTable
.createTableField() );
208 case XLS_TOKEN( rowFields
):
209 if( nElement
== XLS_TOKEN( field
) ) mrPivotTable
.importRowField( rAttribs
);
211 case XLS_TOKEN( colFields
):
212 if( nElement
== XLS_TOKEN( field
) ) mrPivotTable
.importColField( rAttribs
);
214 case XLS_TOKEN( pageFields
):
215 if( nElement
== XLS_TOKEN( pageField
) ) mrPivotTable
.importPageField( rAttribs
);
217 case XLS_TOKEN( dataFields
):
218 if( nElement
== XLS_TOKEN( dataField
) ) mrPivotTable
.importDataField( rAttribs
);
220 case XLS_TOKEN( filters
):
221 if( nElement
== XLS_TOKEN( filter
) ) return new OoxPivotTableFilterContext( *this, mrPivotTable
.createTableFilter() );
227 ContextHandlerRef
OoxPivotTableFragment::onCreateRecordContext( sal_Int32 nRecId
, RecordInputStream
& rStrm
)
229 switch( getCurrentElement() )
231 case XML_ROOT_CONTEXT
:
232 if( nRecId
== OOBIN_ID_PTDEFINITION
) { mrPivotTable
.importPTDefinition( rStrm
); return this; }
235 case OOBIN_ID_PTDEFINITION
:
238 case OOBIN_ID_PTLOCATION
: mrPivotTable
.importPTLocation( rStrm
, getSheetIndex() ); break;
239 case OOBIN_ID_PTFIELDS
: return this;
240 case OOBIN_ID_PTROWFIELDS
: mrPivotTable
.importPTRowFields( rStrm
); break;
241 case OOBIN_ID_PTCOLFIELDS
: mrPivotTable
.importPTColFields( rStrm
); break;
242 case OOBIN_ID_PTPAGEFIELDS
: return this;
243 case OOBIN_ID_PTDATAFIELDS
: return this;
244 case OOBIN_ID_PTFILTERS
: return this;
248 case OOBIN_ID_PTFIELDS
:
249 if( nRecId
== OOBIN_ID_PTFIELD
) return new OoxPivotTableFieldContext( *this, mrPivotTable
.createTableField() );
251 case OOBIN_ID_PTPAGEFIELDS
:
252 if( nRecId
== OOBIN_ID_PTPAGEFIELD
) mrPivotTable
.importPTPageField( rStrm
);
254 case OOBIN_ID_PTDATAFIELDS
:
255 if( nRecId
== OOBIN_ID_PTDATAFIELD
) mrPivotTable
.importPTDataField( rStrm
);
257 case OOBIN_ID_PTFILTERS
:
258 if( nRecId
== OOBIN_ID_PTFILTER
) return new OoxPivotTableFilterContext( *this, mrPivotTable
.createTableFilter() );
264 const RecordInfo
* OoxPivotTableFragment::getRecordInfos() const
266 static const RecordInfo spRecInfos
[] =
268 { OOBIN_ID_AUTOFILTER
, OOBIN_ID_AUTOFILTER
+ 1 },
269 { OOBIN_ID_AUTOSORTSCOPE
, OOBIN_ID_AUTOSORTSCOPE
+ 1 },
270 { OOBIN_ID_FILTERCOLUMN
, OOBIN_ID_FILTERCOLUMN
+ 1 },
271 { OOBIN_ID_PIVOTAREA
, OOBIN_ID_PIVOTAREA
+ 1 },
272 { OOBIN_ID_PTCOLFIELDS
, OOBIN_ID_PTCOLFIELDS
+ 1 },
273 { OOBIN_ID_PTDATAFIELD
, OOBIN_ID_PTDATAFIELD
+ 1 },
274 { OOBIN_ID_PTDATAFIELDS
, OOBIN_ID_PTDATAFIELDS
+ 1 },
275 { OOBIN_ID_PTDEFINITION
, OOBIN_ID_PTDEFINITION
+ 35 },
276 { OOBIN_ID_PTFIELD
, OOBIN_ID_PTFIELD
+ 1 },
277 { OOBIN_ID_PTFIELDS
, OOBIN_ID_PTFIELDS
+ 1 },
278 { OOBIN_ID_PTFILTER
, OOBIN_ID_PTFILTER
+ 1 },
279 { OOBIN_ID_PTFILTERS
, OOBIN_ID_PTFILTERS
+ 1 },
280 { OOBIN_ID_PTFITEM
, OOBIN_ID_PTFITEM
- 1 },
281 { OOBIN_ID_PTFITEMS
, OOBIN_ID_PTFITEMS
+ 1 },
282 { OOBIN_ID_PTLOCATION
, OOBIN_ID_PTLOCATION
- 1 },
283 { OOBIN_ID_PTPAGEFIELD
, OOBIN_ID_PTPAGEFIELD
+ 1 },
284 { OOBIN_ID_PTPAGEFIELDS
, OOBIN_ID_PTPAGEFIELDS
+ 1 },
285 { OOBIN_ID_PTREFERENCE
, OOBIN_ID_PTREFERENCE
+ 1 },
286 { OOBIN_ID_PTREFERENCEITEM
, OOBIN_ID_PTREFERENCEITEM
+ 1 },
287 { OOBIN_ID_PTREFERENCES
, OOBIN_ID_PTREFERENCES
+ 1 },
288 { OOBIN_ID_PTROWFIELDS
, OOBIN_ID_PTROWFIELDS
+ 1 },
294 // ============================================================================
295 // ============================================================================
297 BiffPivotTableContext::BiffPivotTableContext( const BiffWorksheetFragmentBase
& rFragment
, PivotTable
& rPivotTable
) :
298 BiffWorksheetContextBase( rFragment
),
299 mrPivotTable( rPivotTable
)
303 void BiffPivotTableContext::importRecord()
305 switch( mrStrm
.getRecId() )
307 case BIFF_ID_PTDEFINITION
: mrPivotTable
.importPTDefinition( mrStrm
, getSheetIndex() ); break;
308 case BIFF_ID_PTDEFINITION2
: mrPivotTable
.importPTDefinition2( mrStrm
); break;
309 case BIFF_ID_PTFIELD
: mrPivotTable
.createTableField().importPTField( mrStrm
); break;
310 case BIFF_ID_PTROWCOLFIELDS
: mrPivotTable
.importPTRowColFields( mrStrm
); break;
311 case BIFF_ID_PTPAGEFIELDS
: mrPivotTable
.importPTPageFields( mrStrm
); break;
312 case BIFF_ID_PTDATAFIELD
: mrPivotTable
.importPTDataField( mrStrm
); break;
316 // ============================================================================