xref: /aoo4110/main/oox/inc/oox/xls/excelhandlers.hxx (revision b1cdbd2c)
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 #ifndef OOX_XLS_EXCELHANDLERS_HXX
25 #define OOX_XLS_EXCELHANDLERS_HXX
26 
27 #include "oox/core/fragmenthandler2.hxx"
28 #include "oox/xls/worksheethelper.hxx"
29 
30 namespace oox {
31 namespace xls {
32 
33 // ============================================================================
34 // ============================================================================
35 
36 /** Context handler derived from the WorkbookHelper helper class.
37 
38     Used to import contexts in global workbook fragments.
39  */
40 class WorkbookContextBase : public ::oox::core::ContextHandler2, public WorkbookHelper
41 {
42 public:
43     template< typename ParentType >
WorkbookContextBase(ParentType & rParent)44     inline explicit     WorkbookContextBase( ParentType& rParent ) :
45                             ::oox::core::ContextHandler2( rParent ), WorkbookHelper( rParent ) {}
46 };
47 
48 // ============================================================================
49 
50 /** Context handler derived from the WorksheetHelper helper class.
51 
52     Used to import contexts in sheet fragments.
53  */
54 class WorksheetContextBase : public ::oox::core::ContextHandler2, public WorksheetHelper
55 {
56 public:
57     template< typename ParentType >
WorksheetContextBase(ParentType & rParent)58     inline explicit     WorksheetContextBase( ParentType& rParent ) :
59                             ::oox::core::ContextHandler2( rParent ), WorksheetHelper( rParent ) {}
60 };
61 
62 // ============================================================================
63 
64 /** Fragment handler derived from the WorkbookHelper helper class.
65 
66     Used to import global workbook fragments.
67  */
68 class WorkbookFragmentBase : public ::oox::core::FragmentHandler2, public WorkbookHelper
69 {
70 public:
71     explicit            WorkbookFragmentBase(
72                             const WorkbookHelper& rHelper,
73                             const ::rtl::OUString& rFragmentPath );
74 };
75 
76 // ============================================================================
77 
78 /** Fragment handler derived from the WorksheetHelper helper class.
79 
80     Used to import sheet fragments.
81  */
82 class WorksheetFragmentBase : public ::oox::core::FragmentHandler2, public WorksheetHelper
83 {
84 public:
85     explicit            WorksheetFragmentBase(
86                             const WorksheetHelper& rHelper,
87                             const ::rtl::OUString& rFragmentPath );
88 };
89 
90 // ============================================================================
91 // ============================================================================
92 
93 /** Base class for all BIFF context handlers.
94 
95     Derived handlers have to implement the importRecord() function that has to
96     import the record the passed BIFF input stream currently points to.
97  */
98 class BiffContextHandler
99 {
100 public:
101     virtual             ~BiffContextHandler();
102 
103     /** Derived classes have to implement importing the current record. */
104     virtual void        importRecord( BiffInputStream& rStrm ) = 0;
105 };
106 
107 // ----------------------------------------------------------------------------
108 
109 /** Context handler derived from the WorkbookHelper helper class.
110 
111     Used to import contexts in global workbook fragments.
112  */
113 class BiffWorkbookContextBase : public BiffContextHandler, public WorkbookHelper
114 {
115 protected:
116     explicit            BiffWorkbookContextBase( const WorkbookHelper& rHelper );
117 };
118 
119 // ----------------------------------------------------------------------------
120 
121 /** Context handler derived from the WorksheetHelper helper class.
122 
123     Used to import contexts in sheet fragments.
124  */
125 class BiffWorksheetContextBase : public BiffContextHandler, public WorksheetHelper
126 {
127 protected:
128     explicit            BiffWorksheetContextBase( const WorksheetHelper& rHelper );
129 };
130 
131 // ============================================================================
132 
133 /** An enumeration for all types of fragments in a BIFF workbook stream. */
134 enum BiffFragmentType
135 {
136     BIFF_FRAGMENT_GLOBALS,      /// Workbook globals fragment.
137     BIFF_FRAGMENT_WORKSHEET,    /// Worksheet fragment.
138     BIFF_FRAGMENT_CHARTSHEET,   /// Chart sheet fragment.
139     BIFF_FRAGMENT_MACROSHEET,   /// Macro sheet fragment.
140     BIFF_FRAGMENT_MODULESHEET,  /// BIFF5 VB module fragment.
141     BIFF_FRAGMENT_EMPTYSHEET,   /// Sheet fragment of unsupported type.
142     BIFF_FRAGMENT_WORKSPACE,    /// BIFF4 workspace/workbook globals.
143     BIFF_FRAGMENT_UNKNOWN       /// Unknown fragment/error.
144 };
145 
146 // ----------------------------------------------------------------------------
147 
148 class BiffFragmentHandler
149 {
150 public:
151     /** Opens the stream with the passed full name. */
152     explicit            BiffFragmentHandler(
153                             const ::oox::core::FilterBase& rFilter,
154                             const ::rtl::OUString& rStrmName );
155 
156     virtual             ~BiffFragmentHandler();
157 
158     /** Imports the fragment, returns true, if EOF record has been reached. */
159     virtual bool        importFragment() = 0;
160 
161 protected:
162     /** Returns the BIFF input stream of this fragment. */
getInputStream()163     inline BiffInputStream& getInputStream() { return *mxBiffStrm; }
164 
165     /** Starts a new fragment in a workbbok stream and returns the fragment type.
166 
167         The passed stream must point before a BOF record. The function will
168         try to start the next record and read the contents of the BOF record,
169         if extant.
170 
171         @return  Fragment type according to the imported BOF record.
172      */
173     BiffFragmentType    startFragment( BiffType eBiff );
174 
175     /** Skips the current fragment up to its trailing EOF record.
176 
177         Skips all records until next EOF record. When this function returns,
178         stream points to the EOF record, and the next call of startNextRecord()
179         at the stream will start the record following the EOF record.
180 
181         Embedded fragments enclosed in BOF/EOF records (e.g. embedded chart
182         objects) are skipped correctly.
183 
184         @return  True = stream points to the EOF record of the current fragment.
185      */
186     bool                skipFragment();
187 
188 private:
189     typedef ::boost::shared_ptr< BinaryXInputStream >   XInputStreamRef;
190     typedef ::boost::shared_ptr< BiffInputStream >      BiffInputStreamRef;
191 
192     XInputStreamRef     mxXInStrm;
193     BiffInputStreamRef  mxBiffStrm;
194 };
195 
196 // ----------------------------------------------------------------------------
197 
198 /** Fragment handler derived from the WorkbookHelper helper class.
199 
200     Used to import global workbook fragments.
201  */
202 class BiffWorkbookFragmentBase : public BiffFragmentHandler, public WorkbookHelper
203 {
204 protected:
205     explicit            BiffWorkbookFragmentBase(
206                             const WorkbookHelper& rHelper,
207                             const ::rtl::OUString& rStrmName,
208                             bool bCloneDecoder = false );
209 };
210 
211 // ----------------------------------------------------------------------------
212 
213 /** Fragment handler derived from the WorksheetHelper helper class.
214 
215     Used to import sheet fragments.
216  */
217 class BiffWorksheetFragmentBase : public BiffFragmentHandler, public WorksheetHelper
218 {
219 protected:
220     explicit            BiffWorksheetFragmentBase(
221                             const WorksheetHelper& rHelper,
222                             const BiffWorkbookFragmentBase& rParent );
223 };
224 
225 // ----------------------------------------------------------------------------
226 
227 /** Special fragment handler for worksheets that have to be skipped.
228  */
229 class BiffSkipWorksheetFragment : public BiffWorksheetFragmentBase
230 {
231 public:
232     explicit            BiffSkipWorksheetFragment(
233                             const WorksheetHelper& rHelper,
234                             const BiffWorkbookFragmentBase& rParent );
235 
236     virtual bool        importFragment();
237 };
238 
239 // ============================================================================
240 // ============================================================================
241 
242 } // namespace xls
243 } // namespace oox
244 
245 #endif
246