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 13229 : XclExpRecordBase::~XclExpRecordBase()
28 : {
29 13229 : }
30 :
31 34 : void XclExpRecordBase::Save( XclExpStream& /*rStrm*/ )
32 : {
33 34 : }
34 :
35 81 : void XclExpRecordBase::SaveXml( XclExpXmlStream& /*rStrm*/ )
36 : {
37 81 : }
38 :
39 : // ----------------------------------------------------------------------------
40 :
41 9 : XclExpDelegatingRecord::XclExpDelegatingRecord( XclExpRecordBase* pRecord ) :
42 9 : mpRecord( pRecord )
43 : {
44 9 : }
45 :
46 18 : XclExpDelegatingRecord::~XclExpDelegatingRecord()
47 : {
48 : // Do Nothing; we use Delegating Record for other objects we "know" will
49 : // survive...
50 18 : }
51 :
52 9 : void XclExpDelegatingRecord::SaveXml( XclExpXmlStream& rStrm )
53 : {
54 9 : if( mpRecord )
55 9 : mpRecord->SaveXml( rStrm );
56 9 : }
57 :
58 : // ----------------------------------------------------------------------------
59 :
60 101 : XclExpXmlElementRecord::XclExpXmlElementRecord(sal_Int32 const nElement)
61 101 : : mnElement( nElement )
62 : {
63 101 : }
64 :
65 101 : XclExpXmlElementRecord::~XclExpXmlElementRecord()
66 : {
67 101 : }
68 :
69 : // ----------------------------------------------------------------------------
70 :
71 18 : XclExpXmlStartElementRecord::XclExpXmlStartElementRecord(sal_Int32 const nElement)
72 18 : : XclExpXmlElementRecord(nElement)
73 : {
74 18 : }
75 :
76 36 : XclExpXmlStartElementRecord::~XclExpXmlStartElementRecord()
77 : {
78 36 : }
79 :
80 12 : void XclExpXmlStartElementRecord::SaveXml( XclExpXmlStream& rStrm )
81 : {
82 12 : sax_fastparser::FSHelperPtr& rStream = rStrm.GetCurrentStream();
83 : // TODO: no generic way to add attributes here, but it appears to
84 : // not be needed yet
85 12 : rStream->startElement( mnElement, FSEND );
86 12 : }
87 :
88 : // ----------------------------------------------------------------------------
89 :
90 27 : XclExpXmlEndElementRecord::XclExpXmlEndElementRecord( sal_Int32 nElement )
91 27 : : XclExpXmlElementRecord( nElement )
92 : {
93 27 : }
94 :
95 45 : XclExpXmlEndElementRecord::~XclExpXmlEndElementRecord()
96 : {
97 45 : }
98 :
99 21 : void XclExpXmlEndElementRecord::SaveXml( XclExpXmlStream& rStrm )
100 : {
101 21 : rStrm.GetCurrentStream()->endElement( mnElement );
102 21 : }
103 :
104 : // ----------------------------------------------------------------------------
105 :
106 47 : XclExpXmlStartSingleElementRecord::XclExpXmlStartSingleElementRecord(
107 : sal_Int32 const nElement)
108 47 : : XclExpXmlElementRecord( nElement )
109 : {
110 47 : }
111 :
112 76 : XclExpXmlStartSingleElementRecord::~XclExpXmlStartSingleElementRecord()
113 : {
114 76 : }
115 :
116 36 : void XclExpXmlStartSingleElementRecord::SaveXml( XclExpXmlStream& rStrm )
117 : {
118 36 : sax_fastparser::FSHelperPtr& rStream = rStrm.GetCurrentStream();
119 36 : rStream->write( "<" )->writeId( mnElement );
120 36 : }
121 :
122 : // ----------------------------------------------------------------------------
123 :
124 47 : XclExpXmlEndSingleElementRecord::XclExpXmlEndSingleElementRecord()
125 : {
126 47 : }
127 :
128 76 : XclExpXmlEndSingleElementRecord::~XclExpXmlEndSingleElementRecord()
129 : {
130 76 : }
131 :
132 36 : void XclExpXmlEndSingleElementRecord::SaveXml( XclExpXmlStream& rStrm )
133 : {
134 36 : rStrm.GetCurrentStream()->write( "/>" );
135 36 : }
136 :
137 : // ----------------------------------------------------------------------------
138 :
139 12181 : XclExpRecord::XclExpRecord( sal_uInt16 nRecId, sal_Size nRecSize ) :
140 : mnRecSize( nRecSize ),
141 12181 : mnRecId( nRecId )
142 : {
143 12181 : }
144 :
145 12352 : XclExpRecord::~XclExpRecord()
146 : {
147 12352 : }
148 :
149 113 : void XclExpRecord::SetRecHeader( sal_uInt16 nRecId, sal_Size nRecSize )
150 : {
151 113 : SetRecId( nRecId );
152 113 : SetRecSize( nRecSize );
153 113 : }
154 :
155 3 : void XclExpRecord::WriteBody( XclExpStream& /*rStrm*/ )
156 : {
157 3 : }
158 :
159 344 : void XclExpRecord::Save( XclExpStream& rStrm )
160 : {
161 : OSL_ENSURE( mnRecId != EXC_ID_UNKNOWN, "XclExpRecord::Save - record ID uninitialized" );
162 344 : rStrm.StartRecord( mnRecId, mnRecSize );
163 344 : WriteBody( rStrm );
164 344 : rStrm.EndRecord();
165 344 : }
166 :
167 : // ----------------------------------------------------------------------------
168 :
169 : template<>
170 54 : void XclExpValueRecord<double>::SaveXml( XclExpXmlStream& rStrm )
171 : {
172 54 : if( mnAttribute == -1 )
173 54 : return;
174 : rStrm.WriteAttributes(
175 : mnAttribute, OString::valueOf( maValue ).getStr(),
176 54 : FSEND );
177 : }
178 :
179 : // ----------------------------------------------------------------------------
180 :
181 56 : void XclExpBoolRecord::WriteBody( XclExpStream& rStrm )
182 : {
183 56 : rStrm << static_cast< sal_uInt16 >( mbValue ? 1 : 0 );
184 56 : }
185 :
186 105 : void XclExpBoolRecord::SaveXml( XclExpXmlStream& rStrm )
187 : {
188 105 : if( mnAttribute == -1 )
189 153 : return;
190 :
191 : rStrm.WriteAttributes(
192 : // HACK: HIDEOBJ (excdoc.cxx) should be its own object to handle XML_showObjects
193 108 : mnAttribute, mnAttribute == XML_showObjects ? "all" : XclXmlUtils::ToPsz( mbValue ),
194 108 : FSEND );
195 : }
196 :
197 : // ----------------------------------------------------------------------------
198 :
199 18 : XclExpDummyRecord::XclExpDummyRecord( sal_uInt16 nRecId, const void* pRecData, sal_Size nRecSize ) :
200 18 : XclExpRecord( nRecId )
201 : {
202 18 : SetData( pRecData, nRecSize );
203 18 : }
204 :
205 18 : void XclExpDummyRecord::SetData( const void* pRecData, sal_Size nRecSize )
206 : {
207 18 : mpData = pRecData;
208 18 : SetRecSize( pRecData ? nRecSize : 0 );
209 18 : }
210 :
211 6 : void XclExpDummyRecord::WriteBody( XclExpStream& rStrm )
212 : {
213 6 : rStrm.Write( mpData, GetRecSize() );
214 6 : }
215 :
216 : // Future records =============================================================
217 :
218 0 : XclExpFutureRecord::XclExpFutureRecord( XclFutureRecType eRecType, sal_uInt16 nRecId, sal_Size nRecSize ) :
219 : XclExpRecord( nRecId, nRecSize ),
220 0 : meRecType( eRecType )
221 : {
222 0 : }
223 :
224 0 : void XclExpFutureRecord::Save( XclExpStream& rStrm )
225 : {
226 0 : rStrm.StartRecord( GetRecId(), GetRecSize() + ((meRecType == EXC_FUTUREREC_UNUSEDREF) ? 12 : 4) );
227 0 : rStrm << GetRecId() << sal_uInt16( 0 );
228 0 : if( meRecType == EXC_FUTUREREC_UNUSEDREF )
229 0 : rStrm.WriteZeroBytes( 8 );
230 0 : WriteBody( rStrm );
231 0 : rStrm.EndRecord();
232 0 : }
233 :
234 : // ============================================================================
235 :
236 2 : XclExpSubStream::XclExpSubStream( sal_uInt16 nSubStrmType ) :
237 2 : mnSubStrmType( nSubStrmType )
238 : {
239 2 : }
240 :
241 0 : void XclExpSubStream::Save( XclExpStream& rStrm )
242 : {
243 : // BOF record
244 0 : switch( rStrm.GetRoot().GetBiff() )
245 : {
246 : case EXC_BIFF2:
247 0 : rStrm.StartRecord( EXC_ID2_BOF, 4 );
248 0 : rStrm << sal_uInt16( 7 ) << mnSubStrmType;
249 0 : rStrm.EndRecord();
250 0 : break;
251 : case EXC_BIFF3:
252 0 : rStrm.StartRecord( EXC_ID3_BOF, 6 );
253 0 : rStrm << sal_uInt16( 0 ) << mnSubStrmType << sal_uInt16( 2104 );
254 0 : rStrm.EndRecord();
255 0 : break;
256 : case EXC_BIFF4:
257 0 : rStrm.StartRecord( EXC_ID4_BOF, 6 );
258 0 : rStrm << sal_uInt16( 0 ) << mnSubStrmType << sal_uInt16( 1705 );
259 0 : rStrm.EndRecord();
260 0 : break;
261 : case EXC_BIFF5:
262 0 : rStrm.StartRecord( EXC_ID5_BOF, 8 );
263 0 : rStrm << EXC_BOF_BIFF5 << mnSubStrmType << sal_uInt16( 4915 ) << sal_uInt16( 1994 );
264 0 : rStrm.EndRecord();
265 0 : break;
266 : case EXC_BIFF8:
267 0 : rStrm.StartRecord( EXC_ID5_BOF, 16 );
268 0 : rStrm << EXC_BOF_BIFF8 << mnSubStrmType << sal_uInt16( 3612 ) << sal_uInt16( 1996 );
269 0 : rStrm << sal_uInt32( 1 ) << sal_uInt32( 6 );
270 0 : rStrm.EndRecord();
271 0 : break;
272 : default:
273 : DBG_ERROR_BIFF();
274 : }
275 :
276 : // substream records
277 0 : XclExpRecordList<>::Save( rStrm );
278 :
279 : // EOF record
280 0 : rStrm.StartRecord( EXC_ID_EOF, 0 );
281 0 : rStrm.EndRecord();
282 15 : }
283 :
284 : // ============================================================================
285 :
286 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|