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 1652 : XclExpRecordBase::~XclExpRecordBase()
28 : {
29 1652 : }
30 :
31 0 : void XclExpRecordBase::Save( XclExpStream& /*rStrm*/ )
32 : {
33 0 : }
34 :
35 12 : void XclExpRecordBase::SaveXml( XclExpXmlStream& /*rStrm*/ )
36 : {
37 12 : }
38 :
39 : // ----------------------------------------------------------------------------
40 :
41 1 : XclExpDelegatingRecord::XclExpDelegatingRecord( XclExpRecordBase* pRecord ) :
42 1 : mpRecord( pRecord )
43 : {
44 1 : }
45 :
46 2 : XclExpDelegatingRecord::~XclExpDelegatingRecord()
47 : {
48 : // Do Nothing; we use Delegating Record for other objects we "know" will
49 : // survive...
50 2 : }
51 :
52 1 : void XclExpDelegatingRecord::SaveXml( XclExpXmlStream& rStrm )
53 : {
54 1 : if( mpRecord )
55 1 : mpRecord->SaveXml( rStrm );
56 1 : }
57 :
58 : // ----------------------------------------------------------------------------
59 :
60 11 : XclExpXmlElementRecord::XclExpXmlElementRecord( sal_Int32 nElement, void (*pAttributes)( XclExpXmlStream& rStrm) )
61 11 : : mnElement( nElement ), mpAttributes( pAttributes )
62 : {
63 11 : }
64 :
65 11 : XclExpXmlElementRecord::~XclExpXmlElementRecord()
66 : {
67 11 : }
68 :
69 : // ----------------------------------------------------------------------------
70 :
71 3 : XclExpXmlStartElementRecord::XclExpXmlStartElementRecord( sal_Int32 nElement, void (*pAttributes)( XclExpXmlStream& rStrm) )
72 3 : : XclExpXmlElementRecord( nElement, pAttributes )
73 : {
74 3 : }
75 :
76 5 : XclExpXmlStartElementRecord::~XclExpXmlStartElementRecord()
77 : {
78 5 : }
79 :
80 3 : void XclExpXmlStartElementRecord::SaveXml( XclExpXmlStream& rStrm )
81 : {
82 3 : sax_fastparser::FSHelperPtr& rStream = rStrm.GetCurrentStream();
83 3 : if( ! mpAttributes )
84 : {
85 2 : rStream->startElement( mnElement, FSEND );
86 : }
87 : else
88 : {
89 1 : rStream->write( "<" )->writeId( mnElement );
90 1 : (*mpAttributes)( rStrm );
91 : }
92 3 : }
93 :
94 : // ----------------------------------------------------------------------------
95 :
96 3 : XclExpXmlEndElementRecord::XclExpXmlEndElementRecord( sal_Int32 nElement )
97 3 : : XclExpXmlElementRecord( nElement )
98 : {
99 3 : }
100 :
101 5 : XclExpXmlEndElementRecord::~XclExpXmlEndElementRecord()
102 : {
103 5 : }
104 :
105 3 : void XclExpXmlEndElementRecord::SaveXml( XclExpXmlStream& rStrm )
106 : {
107 3 : rStrm.GetCurrentStream()->endElement( mnElement );
108 3 : }
109 :
110 : // ----------------------------------------------------------------------------
111 :
112 5 : XclExpXmlStartSingleElementRecord::XclExpXmlStartSingleElementRecord( sal_Int32 nElement, void (*pAttributes)( XclExpXmlStream& rStrm) )
113 5 : : XclExpXmlElementRecord( nElement, pAttributes )
114 : {
115 5 : }
116 :
117 8 : XclExpXmlStartSingleElementRecord::~XclExpXmlStartSingleElementRecord()
118 : {
119 8 : }
120 :
121 5 : void XclExpXmlStartSingleElementRecord::SaveXml( XclExpXmlStream& rStrm )
122 : {
123 5 : sax_fastparser::FSHelperPtr& rStream = rStrm.GetCurrentStream();
124 5 : rStream->write( "<" )->writeId( mnElement );
125 5 : if( mpAttributes )
126 0 : (*mpAttributes)( rStrm );
127 5 : }
128 :
129 : // ----------------------------------------------------------------------------
130 :
131 5 : XclExpXmlEndSingleElementRecord::XclExpXmlEndSingleElementRecord()
132 : {
133 5 : }
134 :
135 8 : XclExpXmlEndSingleElementRecord::~XclExpXmlEndSingleElementRecord()
136 : {
137 8 : }
138 :
139 5 : void XclExpXmlEndSingleElementRecord::SaveXml( XclExpXmlStream& rStrm )
140 : {
141 5 : rStrm.GetCurrentStream()->write( "/>" );
142 5 : }
143 :
144 : // ----------------------------------------------------------------------------
145 :
146 1528 : XclExpRecord::XclExpRecord( sal_uInt16 nRecId, sal_Size nRecSize ) :
147 : mnRecSize( nRecSize ),
148 1528 : mnRecId( nRecId )
149 : {
150 1528 : }
151 :
152 1547 : XclExpRecord::~XclExpRecord()
153 : {
154 1547 : }
155 :
156 14 : void XclExpRecord::SetRecHeader( sal_uInt16 nRecId, sal_Size nRecSize )
157 : {
158 14 : SetRecId( nRecId );
159 14 : SetRecSize( nRecSize );
160 14 : }
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 6 : void XclExpValueRecord<double>::SaveXml( XclExpXmlStream& rStrm )
178 : {
179 6 : if( mnAttribute == -1 )
180 6 : return;
181 : rStrm.WriteAttributes(
182 : mnAttribute, rtl::OString::valueOf( maValue ).getStr(),
183 6 : 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 15 : void XclExpBoolRecord::SaveXml( XclExpXmlStream& rStrm )
194 : {
195 15 : if( mnAttribute == -1 )
196 23 : return;
197 :
198 : rStrm.WriteAttributes(
199 : // HACK: HIDEOBJ (excdoc.cxx) should be its own object to handle XML_showObjects
200 6 : mnAttribute, mnAttribute == XML_showObjects ? "all" : XclXmlUtils::ToPsz( mbValue ),
201 13 : FSEND );
202 : }
203 :
204 : // ----------------------------------------------------------------------------
205 :
206 2 : XclExpDummyRecord::XclExpDummyRecord( sal_uInt16 nRecId, const void* pRecData, sal_Size nRecSize ) :
207 2 : XclExpRecord( nRecId )
208 : {
209 2 : SetData( pRecData, nRecSize );
210 2 : }
211 :
212 2 : void XclExpDummyRecord::SetData( const void* pRecData, sal_Size nRecSize )
213 : {
214 2 : mpData = pRecData;
215 2 : SetRecSize( pRecData ? nRecSize : 0 );
216 2 : }
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 9 : }
290 :
291 : // ============================================================================
292 :
293 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|