Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include "xerecord.hxx"
21 : #include "xeroot.hxx"
22 :
23 : using namespace ::oox;
24 :
25 : // Base classes to export Excel records =======================================
26 :
27 3306 : XclExpRecordBase::~XclExpRecordBase()
28 : {
29 3306 : }
30 :
31 0 : void XclExpRecordBase::Save( XclExpStream& /*rStrm*/ )
32 : {
33 0 : }
34 :
35 24 : void XclExpRecordBase::SaveXml( XclExpXmlStream& /*rStrm*/ )
36 : {
37 24 : }
38 :
39 : // ----------------------------------------------------------------------------
40 :
41 2 : XclExpDelegatingRecord::XclExpDelegatingRecord( XclExpRecordBase* pRecord ) :
42 2 : mpRecord( pRecord )
43 : {
44 2 : }
45 :
46 4 : XclExpDelegatingRecord::~XclExpDelegatingRecord()
47 : {
48 : // Do Nothing; we use Delegating Record for other objects we "know" will
49 : // survive...
50 4 : }
51 :
52 2 : void XclExpDelegatingRecord::SaveXml( XclExpXmlStream& rStrm )
53 : {
54 2 : if( mpRecord )
55 2 : mpRecord->SaveXml( rStrm );
56 2 : }
57 :
58 : // ----------------------------------------------------------------------------
59 :
60 22 : XclExpXmlElementRecord::XclExpXmlElementRecord( sal_Int32 nElement, void (*pAttributes)( XclExpXmlStream& rStrm) )
61 22 : : mnElement( nElement ), mpAttributes( pAttributes )
62 : {
63 22 : }
64 :
65 22 : XclExpXmlElementRecord::~XclExpXmlElementRecord()
66 : {
67 22 : }
68 :
69 : // ----------------------------------------------------------------------------
70 :
71 6 : XclExpXmlStartElementRecord::XclExpXmlStartElementRecord( sal_Int32 nElement, void (*pAttributes)( XclExpXmlStream& rStrm) )
72 6 : : XclExpXmlElementRecord( nElement, pAttributes )
73 : {
74 6 : }
75 :
76 10 : XclExpXmlStartElementRecord::~XclExpXmlStartElementRecord()
77 : {
78 10 : }
79 :
80 6 : void XclExpXmlStartElementRecord::SaveXml( XclExpXmlStream& rStrm )
81 : {
82 6 : sax_fastparser::FSHelperPtr& rStream = rStrm.GetCurrentStream();
83 6 : if( ! mpAttributes )
84 : {
85 4 : rStream->startElement( mnElement, FSEND );
86 : }
87 : else
88 : {
89 2 : rStream->write( "<" )->writeId( mnElement );
90 2 : (*mpAttributes)( rStrm );
91 : }
92 6 : }
93 :
94 : // ----------------------------------------------------------------------------
95 :
96 6 : XclExpXmlEndElementRecord::XclExpXmlEndElementRecord( sal_Int32 nElement )
97 6 : : XclExpXmlElementRecord( nElement )
98 : {
99 6 : }
100 :
101 10 : XclExpXmlEndElementRecord::~XclExpXmlEndElementRecord()
102 : {
103 10 : }
104 :
105 6 : void XclExpXmlEndElementRecord::SaveXml( XclExpXmlStream& rStrm )
106 : {
107 6 : rStrm.GetCurrentStream()->endElement( mnElement );
108 6 : }
109 :
110 : // ----------------------------------------------------------------------------
111 :
112 10 : XclExpXmlStartSingleElementRecord::XclExpXmlStartSingleElementRecord( sal_Int32 nElement, void (*pAttributes)( XclExpXmlStream& rStrm) )
113 10 : : XclExpXmlElementRecord( nElement, pAttributes )
114 : {
115 10 : }
116 :
117 16 : XclExpXmlStartSingleElementRecord::~XclExpXmlStartSingleElementRecord()
118 : {
119 16 : }
120 :
121 10 : void XclExpXmlStartSingleElementRecord::SaveXml( XclExpXmlStream& rStrm )
122 : {
123 10 : sax_fastparser::FSHelperPtr& rStream = rStrm.GetCurrentStream();
124 10 : rStream->write( "<" )->writeId( mnElement );
125 10 : if( mpAttributes )
126 0 : (*mpAttributes)( rStrm );
127 10 : }
128 :
129 : // ----------------------------------------------------------------------------
130 :
131 10 : XclExpXmlEndSingleElementRecord::XclExpXmlEndSingleElementRecord()
132 : {
133 10 : }
134 :
135 16 : XclExpXmlEndSingleElementRecord::~XclExpXmlEndSingleElementRecord()
136 : {
137 16 : }
138 :
139 10 : void XclExpXmlEndSingleElementRecord::SaveXml( XclExpXmlStream& rStrm )
140 : {
141 10 : rStrm.GetCurrentStream()->write( "/>" );
142 10 : }
143 :
144 : // ----------------------------------------------------------------------------
145 :
146 3058 : XclExpRecord::XclExpRecord( sal_uInt16 nRecId, sal_Size nRecSize ) :
147 : mnRecSize( nRecSize ),
148 3058 : mnRecId( nRecId )
149 : {
150 3058 : }
151 :
152 3096 : XclExpRecord::~XclExpRecord()
153 : {
154 3096 : }
155 :
156 28 : void XclExpRecord::SetRecHeader( sal_uInt16 nRecId, sal_Size nRecSize )
157 : {
158 28 : SetRecId( nRecId );
159 28 : SetRecSize( nRecSize );
160 28 : }
161 :
162 0 : void XclExpRecord::WriteBody( XclExpStream& /*rStrm*/ )
163 : {
164 0 : }
165 :
166 0 : void XclExpRecord::Save( XclExpStream& rStrm )
167 : {
168 : OSL_ENSURE( mnRecId != EXC_ID_UNKNOWN, "XclExpRecord::Save - record ID uninitialized" );
169 0 : rStrm.StartRecord( mnRecId, mnRecSize );
170 0 : WriteBody( rStrm );
171 0 : rStrm.EndRecord();
172 0 : }
173 :
174 : // ----------------------------------------------------------------------------
175 :
176 : template<>
177 12 : void XclExpValueRecord<double>::SaveXml( XclExpXmlStream& rStrm )
178 : {
179 12 : if( mnAttribute == -1 )
180 12 : return;
181 : rStrm.WriteAttributes(
182 : mnAttribute, rtl::OString::valueOf( maValue ).getStr(),
183 12 : FSEND );
184 : }
185 :
186 : // ----------------------------------------------------------------------------
187 :
188 0 : void XclExpBoolRecord::WriteBody( XclExpStream& rStrm )
189 : {
190 0 : rStrm << static_cast< sal_uInt16 >( mbValue ? 1 : 0 );
191 0 : }
192 :
193 30 : void XclExpBoolRecord::SaveXml( XclExpXmlStream& rStrm )
194 : {
195 30 : if( mnAttribute == -1 )
196 46 : return;
197 :
198 : rStrm.WriteAttributes(
199 : // HACK: HIDEOBJ (excdoc.cxx) should be its own object to handle XML_showObjects
200 12 : mnAttribute, mnAttribute == XML_showObjects ? "all" : XclXmlUtils::ToPsz( mbValue ),
201 26 : FSEND );
202 : }
203 :
204 : // ----------------------------------------------------------------------------
205 :
206 4 : XclExpDummyRecord::XclExpDummyRecord( sal_uInt16 nRecId, const void* pRecData, sal_Size nRecSize ) :
207 4 : XclExpRecord( nRecId )
208 : {
209 4 : SetData( pRecData, nRecSize );
210 4 : }
211 :
212 4 : void XclExpDummyRecord::SetData( const void* pRecData, sal_Size nRecSize )
213 : {
214 4 : mpData = pRecData;
215 4 : SetRecSize( pRecData ? nRecSize : 0 );
216 4 : }
217 :
218 0 : void XclExpDummyRecord::WriteBody( XclExpStream& rStrm )
219 : {
220 0 : rStrm.Write( mpData, GetRecSize() );
221 0 : }
222 :
223 : // Future records =============================================================
224 :
225 0 : XclExpFutureRecord::XclExpFutureRecord( XclFutureRecType eRecType, sal_uInt16 nRecId, sal_Size nRecSize ) :
226 : XclExpRecord( nRecId, nRecSize ),
227 0 : meRecType( eRecType )
228 : {
229 0 : }
230 :
231 0 : void XclExpFutureRecord::Save( XclExpStream& rStrm )
232 : {
233 0 : rStrm.StartRecord( GetRecId(), GetRecSize() + ((meRecType == EXC_FUTUREREC_UNUSEDREF) ? 12 : 4) );
234 0 : rStrm << GetRecId() << sal_uInt16( 0 );
235 0 : if( meRecType == EXC_FUTUREREC_UNUSEDREF )
236 0 : rStrm.WriteZeroBytes( 8 );
237 0 : WriteBody( rStrm );
238 0 : rStrm.EndRecord();
239 0 : }
240 :
241 : // ============================================================================
242 :
243 0 : XclExpSubStream::XclExpSubStream( sal_uInt16 nSubStrmType ) :
244 0 : mnSubStrmType( nSubStrmType )
245 : {
246 0 : }
247 :
248 0 : void XclExpSubStream::Save( XclExpStream& rStrm )
249 : {
250 : // BOF record
251 0 : switch( rStrm.GetRoot().GetBiff() )
252 : {
253 : case EXC_BIFF2:
254 0 : rStrm.StartRecord( EXC_ID2_BOF, 4 );
255 0 : rStrm << sal_uInt16( 7 ) << mnSubStrmType;
256 0 : rStrm.EndRecord();
257 0 : break;
258 : case EXC_BIFF3:
259 0 : rStrm.StartRecord( EXC_ID3_BOF, 6 );
260 0 : rStrm << sal_uInt16( 0 ) << mnSubStrmType << sal_uInt16( 2104 );
261 0 : rStrm.EndRecord();
262 0 : break;
263 : case EXC_BIFF4:
264 0 : rStrm.StartRecord( EXC_ID4_BOF, 6 );
265 0 : rStrm << sal_uInt16( 0 ) << mnSubStrmType << sal_uInt16( 1705 );
266 0 : rStrm.EndRecord();
267 0 : break;
268 : case EXC_BIFF5:
269 0 : rStrm.StartRecord( EXC_ID5_BOF, 8 );
270 0 : rStrm << EXC_BOF_BIFF5 << mnSubStrmType << sal_uInt16( 4915 ) << sal_uInt16( 1994 );
271 0 : rStrm.EndRecord();
272 0 : break;
273 : case EXC_BIFF8:
274 0 : rStrm.StartRecord( EXC_ID5_BOF, 16 );
275 0 : rStrm << EXC_BOF_BIFF8 << mnSubStrmType << sal_uInt16( 3612 ) << sal_uInt16( 1996 );
276 0 : rStrm << sal_uInt32( 1 ) << sal_uInt32( 6 );
277 0 : rStrm.EndRecord();
278 0 : break;
279 : default:
280 : DBG_ERROR_BIFF();
281 : }
282 :
283 : // substream records
284 0 : XclExpRecordList<>::Save( rStrm );
285 :
286 : // EOF record
287 0 : rStrm.StartRecord( EXC_ID_EOF, 0 );
288 0 : rStrm.EndRecord();
289 24 : }
290 :
291 : // ============================================================================
292 :
293 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|