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