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 #include "oox/xls/scenariocontext.hxx"
25
26 #include "oox/xls/scenariobuffer.hxx"
27
28 namespace oox {
29 namespace xls {
30
31 // ============================================================================
32
33 using ::oox::core::ContextHandlerRef;
34
35 // ============================================================================
36
ScenarioContext(WorksheetContextBase & rParent,SheetScenarios & rSheetScenarios)37 ScenarioContext::ScenarioContext( WorksheetContextBase& rParent, SheetScenarios& rSheetScenarios ) :
38 WorksheetContextBase( rParent ),
39 mrScenario( rSheetScenarios.createScenario() )
40 {
41 }
42
onCreateContext(sal_Int32 nElement,const AttributeList & rAttribs)43 ContextHandlerRef ScenarioContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
44 {
45 switch( getCurrentElement() )
46 {
47 case XLS_TOKEN( scenario ):
48 if( nElement == XLS_TOKEN( inputCells ) ) mrScenario.importInputCells( rAttribs );
49 break;
50 }
51 return 0;
52 }
53
onStartElement(const AttributeList & rAttribs)54 void ScenarioContext::onStartElement( const AttributeList& rAttribs )
55 {
56 if( isRootElement() )
57 mrScenario.importScenario( rAttribs );
58 }
59
onCreateRecordContext(sal_Int32 nRecId,SequenceInputStream & rStrm)60 ContextHandlerRef ScenarioContext::onCreateRecordContext( sal_Int32 nRecId, SequenceInputStream& rStrm )
61 {
62 switch( getCurrentElement() )
63 {
64 case BIFF12_ID_SCENARIO:
65 if( nRecId == BIFF12_ID_INPUTCELLS ) mrScenario.importInputCells( rStrm );
66 break;
67 }
68 return 0;
69 }
70
onStartRecord(SequenceInputStream & rStrm)71 void ScenarioContext::onStartRecord( SequenceInputStream& rStrm )
72 {
73 if( isRootElement() )
74 mrScenario.importScenario( rStrm );
75 }
76
77 // ============================================================================
78
ScenariosContext(WorksheetFragmentBase & rFragment)79 ScenariosContext::ScenariosContext( WorksheetFragmentBase& rFragment ) :
80 WorksheetContextBase( rFragment ),
81 mrSheetScenarios( getScenarios().createSheetScenarios( getSheetIndex() ) )
82 {
83 }
84
onCreateContext(sal_Int32 nElement,const AttributeList &)85 ContextHandlerRef ScenariosContext::onCreateContext( sal_Int32 nElement, const AttributeList& )
86 {
87 switch( getCurrentElement() )
88 {
89 case XLS_TOKEN( scenarios ):
90 if( nElement == XLS_TOKEN( scenario ) ) return new ScenarioContext( *this, mrSheetScenarios );
91 break;
92 }
93 return 0;
94 }
95
onStartElement(const AttributeList & rAttribs)96 void ScenariosContext::onStartElement( const AttributeList& rAttribs )
97 {
98 if( isRootElement() )
99 mrSheetScenarios.importScenarios( rAttribs );
100 }
101
onCreateRecordContext(sal_Int32 nRecId,SequenceInputStream &)102 ContextHandlerRef ScenariosContext::onCreateRecordContext( sal_Int32 nRecId, SequenceInputStream& )
103 {
104 switch( getCurrentElement() )
105 {
106 case BIFF12_ID_SCENARIOS:
107 if( nRecId == BIFF12_ID_SCENARIO ) return new ScenarioContext( *this, mrSheetScenarios );
108 break;
109 }
110 return 0;
111 }
112
onStartRecord(SequenceInputStream & rStrm)113 void ScenariosContext::onStartRecord( SequenceInputStream& rStrm )
114 {
115 if( isRootElement() )
116 mrSheetScenarios.importScenarios( rStrm );
117 }
118
119 // ============================================================================
120
121 } // namespace xls
122 } // namespace oox
123