LibreOffice Module sc (master)  1
xerecord.cxx
Go to the documentation of this file.
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 #include <xltools.hxx>
23 
24 #include <oox/token/tokens.hxx>
25 #include <oox/export/utils.hxx>
26 #include <osl/diagnose.h>
27 
28 using namespace ::oox;
29 
30 // Base classes to export Excel records =======================================
31 
33 {
34 }
35 
37 {
38 }
39 
41 {
42 }
43 
45  mpRecord( pRecord )
46 {
47 }
48 
50 {
51  // Do Nothing; we use Delegating Record for other objects we "know" will
52  // survive...
53 }
54 
56 {
57  if( mpRecord )
58  mpRecord->SaveXml( rStrm );
59 }
60 
62  : mnElement( nElement )
63 {
64 }
65 
67 {
68 }
69 
71  : XclExpXmlElementRecord(nElement)
72 {
73 }
74 
76 {
77 }
78 
80 {
82  // TODO: no generic way to add attributes here, but it appears to
83  // not be needed yet
84  rStream->startElement(mnElement);
85 }
86 
88  : XclExpXmlElementRecord( nElement )
89 {
90 }
91 
93 {
94 }
95 
97 {
98  rStrm.GetCurrentStream()->endElement( mnElement );
99 }
100 
102  sal_Int32 const nElement)
103  : XclExpXmlElementRecord( nElement )
104 {
105 }
106 
108 {
109 }
110 
112 {
114  rStream->write( "<" )->writeId( mnElement );
115 }
116 
118 {
119 }
120 
122 {
123 }
124 
126 {
127  rStrm.GetCurrentStream()->write( "/>" );
128 }
129 
130 XclExpRecord::XclExpRecord( sal_uInt16 nRecId, std::size_t nRecSize ) :
131  mnRecSize( nRecSize ),
132  mnRecId( nRecId )
133 {
134 }
135 
137 {
138 }
139 
140 void XclExpRecord::SetRecHeader( sal_uInt16 nRecId, std::size_t nRecSize )
141 {
142  SetRecId( nRecId );
143  SetRecSize( nRecSize );
144 }
145 
147 {
148 }
149 
151 {
152  OSL_ENSURE( mnRecId != EXC_ID_UNKNOWN, "XclExpRecord::Save - record ID uninitialized" );
153  rStrm.StartRecord( mnRecId, mnRecSize );
154  WriteBody( rStrm );
155  rStrm.EndRecord();
156 }
157 
158 template<>
160 {
161  if( mnAttribute == -1 )
162  return;
163  rStrm.WriteAttributes(mnAttribute, OUString::number(maValue));
164 }
165 
167 {
168  rStrm << static_cast< sal_uInt16 >( mbValue ? 1 : 0 );
169 }
170 
172 {
173  if( mnAttribute == -1 )
174  return;
175 
176  rStrm.WriteAttributes(
177  // HACK: HIDEOBJ (excdoc.cxx) should be its own object to handle XML_showObjects
178  mnAttribute, mnAttribute == XML_showObjects ? "all" : ToPsz( mbValue ));
179 }
180 
181 XclExpDummyRecord::XclExpDummyRecord( sal_uInt16 nRecId, const void* pRecData, std::size_t nRecSize ) :
182  XclExpRecord( nRecId )
183 {
184  SetData( pRecData, nRecSize );
185 }
186 
187 void XclExpDummyRecord::SetData( const void* pRecData, std::size_t nRecSize )
188 {
189  mpData = pRecData;
190  SetRecSize( pRecData ? nRecSize : 0 );
191 }
192 
194 {
195  rStrm.Write( mpData, GetRecSize() );
196 }
197 
198 // Future records =============================================================
199 
200 XclExpFutureRecord::XclExpFutureRecord( XclFutureRecType eRecType, sal_uInt16 nRecId, std::size_t nRecSize ) :
201  XclExpRecord( nRecId, nRecSize ),
202  meRecType( eRecType )
203 {
204 }
205 
207 {
208  rStrm.StartRecord( GetRecId(), GetRecSize() + ((meRecType == EXC_FUTUREREC_UNUSEDREF) ? 12 : 4) );
209  rStrm << GetRecId() << sal_uInt16( 0 );
211  rStrm.WriteZeroBytes( 8 );
212  WriteBody( rStrm );
213  rStrm.EndRecord();
214 }
215 
216 XclExpSubStream::XclExpSubStream( sal_uInt16 nSubStrmType ) :
217  mnSubStrmType( nSubStrmType )
218 {
219 }
220 
222 {
223  // BOF record
224  switch( rStrm.GetRoot().GetBiff() )
225  {
226  case EXC_BIFF2:
227  rStrm.StartRecord( EXC_ID2_BOF, 4 );
228  rStrm << sal_uInt16( 7 ) << mnSubStrmType;
229  rStrm.EndRecord();
230  break;
231  case EXC_BIFF3:
232  rStrm.StartRecord( EXC_ID3_BOF, 6 );
233  rStrm << sal_uInt16( 0 ) << mnSubStrmType << sal_uInt16( 2104 );
234  rStrm.EndRecord();
235  break;
236  case EXC_BIFF4:
237  rStrm.StartRecord( EXC_ID4_BOF, 6 );
238  rStrm << sal_uInt16( 0 ) << mnSubStrmType << sal_uInt16( 1705 );
239  rStrm.EndRecord();
240  break;
241  case EXC_BIFF5:
242  rStrm.StartRecord( EXC_ID5_BOF, 8 );
243  rStrm << EXC_BOF_BIFF5 << mnSubStrmType << sal_uInt16( 4915 ) << sal_uInt16( 1994 );
244  rStrm.EndRecord();
245  break;
246  case EXC_BIFF8:
247  rStrm.StartRecord( EXC_ID5_BOF, 16 );
248  rStrm << EXC_BOF_BIFF8 << mnSubStrmType << sal_uInt16( 3612 ) << sal_uInt16( 1996 );
249  rStrm << sal_uInt32( 1 ) << sal_uInt32( 6 );
250  rStrm.EndRecord();
251  break;
252  default:
253  DBG_ERROR_BIFF();
254  }
255 
256  // substream records
257  XclExpRecordList<>::Save( rStrm );
258 
259  // EOF record
260  rStrm.StartRecord( EXC_ID_EOF, 0 );
261  rStrm.EndRecord();
262 }
263 
264 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
XclExpDummyRecord(sal_uInt16 nRecId, const void *pRecData, std::size_t nRecSize)
Definition: xerecord.cxx:181
void WriteAttributes(sal_Int32 nAttribute, Str &&value, Args &&...rest)
Definition: xestream.hxx:299
virtual void Save(XclExpStream &rStrm) override
Writes the complete substream, including leading BOF and trailing EOF.
Definition: xerecord.cxx:221
virtual void Save(XclExpStream &rStrm) override
Writes the complete record list.
Definition: xerecord.hxx:376
#define DBG_ERROR_BIFF()
Definition: xltools.hxx:31
std::size_t Write(const void *pData, std::size_t nBytes)
Writes nBytes bytes from memory.
Definition: xestream.cxx:215
virtual ~XclExpXmlElementRecord() override
Definition: xerecord.cxx:66
XclExpXmlStartElementRecord(sal_Int32 nElement)
Definition: xerecord.cxx:70
sal_Int32 mnAttribute
The record data.
Definition: xerecord.hxx:274
This class is used to export Excel record streams.
Definition: xestream.hxx:71
void SetData(const void *pRecData, std::size_t nRecSize)
Sets a data array.
Definition: xerecord.cxx:187
Record identifier and empty flags field.
Definition: xlconst.hxx:245
XclExpFutureRecord(XclFutureRecType eRecType, sal_uInt16 nRecId, std::size_t nRecSize)
Definition: xerecord.cxx:200
void SetRecSize(std::size_t nRecSize)
Sets a new record size prediction.
Definition: xerecord.hxx:164
virtual ~XclExpXmlEndSingleElementRecord() override
Definition: xerecord.cxx:121
std::size_t GetRecSize() const
Returns the current record size prediction.
Definition: xerecord.hxx:159
virtual void WriteBody(XclExpStream &rStrm) override
Writes the body of the record.
Definition: xerecord.cxx:166
const sal_uInt16 EXC_ID5_BOF
Definition: xlconst.hxx:156
const sal_uInt16 EXC_BOF_BIFF5
Definition: xlconst.hxx:161
XclFutureRecType
Enumerates different header types of future records.
Definition: xlconst.hxx:242
sal_uInt16 GetRecId() const
Returns the current record ID.
Definition: xerecord.hxx:157
MS Excel 4.0.
Definition: xlconst.hxx:35
XclExpSubStream(sal_uInt16 nSubStrmType)
Definition: xerecord.cxx:216
Base class for all Excel records.
Definition: xerecord.hxx:39
sax_fastparser::FSHelperPtr & GetCurrentStream()
Definition: xestream.cxx:910
virtual void Save(XclExpStream &rStrm)
Overwrite this method to do any operation while saving the record.
Definition: xerecord.cxx:36
MS Excel 5.0, MS Excel 7.0 (95)
Definition: xlconst.hxx:36
const sal_uInt16 EXC_ID4_BOF
Definition: xlconst.hxx:155
XclExpXmlElementRecord(sal_Int32 nElement)
Definition: xerecord.cxx:61
const sal_uInt16 EXC_ID_UNKNOWN
Definition: xlstream.hxx:36
virtual void SaveXml(XclExpXmlStream &rStrm) override
Ends the element nElement.
Definition: xerecord.cxx:96
void EndRecord()
Checks and corrects real record length.
Definition: xestream.cxx:120
XclExpRecordBase * mpRecord
Definition: xerecord.hxx:81
MS Excel 3.0.
Definition: xlconst.hxx:34
virtual ~XclExpRecordBase()
Definition: xerecord.cxx:32
virtual void SaveXml(XclExpXmlStream &rStrm) override
Definition: xerecord.cxx:171
sal_uInt16 mnRecId
The predicted record size.
Definition: xerecord.hxx:180
std::shared_ptr< FastSerializerHelper > FSHelperPtr
virtual ~XclExpXmlStartSingleElementRecord() override
Definition: xerecord.cxx:107
XclFutureRecType meRecType
Definition: xerecord.hxx:310
virtual void SaveXml(XclExpXmlStream &rStrm) override
Ends the single element nElement.
Definition: xerecord.cxx:125
virtual void WriteBody(XclExpStream &rStrm)
Writes the body of the record (without record header).
Definition: xerecord.cxx:146
void SetRecHeader(sal_uInt16 nRecId, std::size_t nRecSize)
Sets record ID and size with one call.
Definition: xerecord.cxx:140
XclExpRecord(sal_uInt16 nRecId=EXC_ID_UNKNOWN, std::size_t nRecSize=0)
Definition: xerecord.cxx:130
XclExpDelegatingRecord(XclExpRecordBase *pRecord)
Definition: xerecord.cxx:44
void SaveXml(XclExpXmlStream &rStrm) override
Write the OOXML attribute and its value.
Definition: xerecord.hxx:230
sal_uInt16 mnSubStrmType
Definition: xerecord.hxx:405
XclBiff GetBiff() const
Returns the current BIFF version of the importer/exporter.
Definition: xlroot.hxx:141
std::size_t mnRecSize
Definition: xerecord.hxx:179
const sal_uInt16 EXC_BOF_BIFF8
Definition: xlconst.hxx:162
virtual ~XclExpXmlEndElementRecord() override
Definition: xerecord.cxx:92
void StartRecord(sal_uInt16 nRecId, std::size_t nRecSize)
Starts a new record: writes header data, stores calculated record size.
Definition: xestream.cxx:108
const void * mpData
Definition: xerecord.hxx:295
virtual void Save(XclExpStream &rStrm) override
Writes the extended record header and calls WriteBody().
Definition: xerecord.cxx:206
const sal_uInt16 EXC_ID3_BOF
Definition: xlconst.hxx:154
virtual ~XclExpXmlStartElementRecord() override
Definition: xerecord.cxx:75
virtual ~XclExpDelegatingRecord() override
Definition: xerecord.cxx:49
MS Excel 2.1.
Definition: xlconst.hxx:33
const XclExpRoot & GetRoot() const
Returns the filter root data.
Definition: xestream.hxx:86
XclExpXmlEndElementRecord(sal_Int32 nElement)
Definition: xerecord.cxx:87
virtual void WriteBody(XclExpStream &rStrm) override
Writes the body of the record.
Definition: xerecord.cxx:193
virtual void SaveXml(XclExpXmlStream &rStrm) override
Definition: xerecord.cxx:55
virtual void Save(XclExpStream &rStrm) override
Writes the record header and calls WriteBody().
Definition: xerecord.cxx:150
XclExpXmlStartSingleElementRecord(sal_Int32 nElement)
Definition: xerecord.cxx:101
void SetRecId(sal_uInt16 nRecId)
Sets a new record ID.
Definition: xerecord.hxx:162
virtual void SaveXml(XclExpXmlStream &rStrm) override
Starts the single element nElement.
Definition: xerecord.cxx:111
const sal_uInt16 EXC_ID2_BOF
Text rotation: vertically stacked.
Definition: xlconst.hxx:153
virtual void SaveXml(XclExpXmlStream &rStrm)
Definition: xerecord.cxx:40
double maValue
Base class for single records with any content.
Definition: xerecord.hxx:143
virtual void SaveXml(XclExpXmlStream &rStrm) override
Starts the element nElement.
Definition: xerecord.cxx:79
void WriteZeroBytes(std::size_t nBytes)
Writes a sequence of nBytes zero bytes (respects slice setting).
Definition: xestream.cxx:256
virtual ~XclExpRecord() override
Definition: xerecord.cxx:136
const sal_uInt16 EXC_ID_EOF
Internal use only.
Definition: xlconst.hxx:173