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