Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*************************************************************************
3 : *
4 : * The Contents of this file are made available subject to the terms of
5 : * either of the following licenses
6 : *
7 : * - GNU Lesser General Public License Version 2.1
8 : * - Sun Industry Standards Source License Version 1.1
9 : *
10 : * Sun Microsystems Inc., October, 2000
11 : *
12 : * GNU Lesser General Public License Version 2.1
13 : * =============================================
14 : * Copyright 2000 by Sun Microsystems, Inc.
15 : * 901 San Antonio Road, Palo Alto, CA 94303, USA
16 : *
17 : * This library is free software; you can redistribute it and/or
18 : * modify it under the terms of the GNU Lesser General Public
19 : * License version 2.1, as published by the Free Software Foundation.
20 : *
21 : * This library is distributed in the hope that it will be useful,
22 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24 : * Lesser General Public License for more details.
25 : *
26 : * You should have received a copy of the GNU Lesser General Public
27 : * License along with this library; if not, write to the Free Software
28 : * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
29 : * MA 02111-1307 USA
30 : *
31 : *
32 : * Sun Industry Standards Source License Version 1.1
33 : * =================================================
34 : * The contents of this file are subject to the Sun Industry Standards
35 : * Source License Version 1.1 (the "License"); You may not use this file
36 : * except in compliance with the License. You may obtain a copy of the
37 : * License at http://www.openoffice.org/license.html.
38 : *
39 : * Software provided under this License is provided on an "AS IS" basis,
40 : * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
41 : * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
42 : * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
43 : * See the License for the specific provisions governing your rights and
44 : * obligations concerning the Software.
45 : *
46 : * The Initial Developer of the Original Code is: IBM Corporation
47 : *
48 : * Copyright: 2008 by IBM Corporation
49 : *
50 : * All Rights Reserved.
51 : *
52 : * Contributor(s): _______________________________________
53 : *
54 : *
55 : ************************************************************************/
56 : #ifndef INCLUDED_LOTUSWORDPRO_SOURCE_FILTER_BENTO_HXX
57 : #define INCLUDED_LOTUSWORDPRO_SOURCE_FILTER_BENTO_HXX
58 :
59 : #include <string>
60 : #include <vector>
61 : #include "lwpsvstream.hxx"
62 :
63 : #define BEN_CC __stdcall
64 : #ifdef COMP_BENTO
65 : #define BEN_EXPORT __declspec(dllexport)
66 : #else
67 : #define BEN_EXPORT
68 : #endif
69 :
70 : #include "ut.hxx"
71 : #include "utlist.hxx"
72 : #include <tools/stream.hxx>
73 : #include <sot/storage.hxx>
74 :
75 : namespace OpenStormBento
76 : {
77 :
78 : #define BEN_CURR_MAJOR_VERSION 2
79 : #define BEN_CURR_MINOR_VERSION 0
80 : #define BEN_MAGIC_BYTES_SIZE 8
81 : #define BEN_LABEL_SIZE 24
82 :
83 : #define BEN_MAGIC_BYTES "\xA4""CM""\xA5""Hdr""\xD7"
84 :
85 : enum BenError
86 : {
87 : BenErr_OK = 0,
88 : BenErr_NameConflict = 1,
89 : BenErr_DuplicateObjectID = 2,
90 : BenErr_UnknownBentoFormatVersion = 3,
91 : BenErr_NamedObjectError = 4,
92 : BenErr_NamedObjectIllegalValue = 5,
93 : BenErr_InvalidTOC = 6,
94 : BenErr_64BitOffsetNotSupported = 7,
95 : BenErr_ReadPastEndOfTOC = 8,
96 : BenErr_ContainerWithNoObjects = 9,
97 : BenErr_ObjectWithNoProperties = 10,
98 : BenErr_PropertyWithNoValues = 11,
99 : BenErr_IllegalInMemoryTOC = 12,
100 : BenErr_PropertyAlreadyExists = 13,
101 : BenErr_UnexpectedEndOfFile = 14,
102 : BenErr_InvalidWriteOffset = 15,
103 : BenErr_InvalidImmediateWrite = 16,
104 : BenErr_TOCSeedError = 17,
105 : BenErr_ReadPastEndOfContainer = 18,
106 : BenErr_DuplicateName = 19,
107 : BenErr_BadReferencedList = 20,
108 : BenErr_IllegalContinuedImmediate = 21,
109 : BenErr_NotBentoContainer = 22,
110 : BenErr_PropertyWithMoreThanOneValue = 23
111 :
112 : // IMPORTANT - UtStream errors (UtErr_....) are also valid Bento
113 : // errors. They have codes of 100 and higher. When, say, a Bento
114 : // container open fails due to an access violation (somebody else, say,
115 : // has it open exclusive), will get a UtErr code. If define own
116 : // subclass of UtStream (custom handler), can define own error codes--
117 : // those should start at 200
118 : };
119 :
120 : UtDefClassP(LtcBenContainer);
121 : UtDefClassP(CBenIDListElmt);
122 : UtDefClassP(CBenObject);
123 : UtDefClassP(CBenProperty);
124 : UtDefClassP(CBenReference);
125 : UtDefClassP(CBenValue);
126 : UtDefClassP(CBenValueSegment);
127 : UtDefClassP(CBenNamedObjectListElmt);
128 : UtDefClassP(CBenNamedObject);
129 : UtDefClassP(CBenPropertyName);
130 : UtDefClassP(CBenTypeName);
131 :
132 : typedef unsigned char BenByte;
133 : typedef unsigned short BenWord;
134 : typedef unsigned long BenDWord;
135 : typedef void * BenDataPtr;
136 : typedef const void * BenConstDataPtr;
137 :
138 : typedef unsigned long BenContainerPos;
139 : typedef unsigned long BenObjectID;
140 : typedef unsigned long BenGeneration;
141 :
142 : sal_uLong BenOpenContainer(LwpSvStream * pStream, pLtcBenContainer * ppContainer);
143 :
144 550 : class CBenIDListElmt : public CUtListElmt
145 : {
146 : public: // Internal methods
147 377 : CBenIDListElmt(BenObjectID ID, pCUtListElmt pPrev) : CUtListElmt(pPrev)
148 377 : { cID = ID; }
149 173 : explicit CBenIDListElmt(BenObjectID ID) { cID = ID; }
150 592 : BenObjectID GetID() { return cID; }
151 :
152 : private: // Data
153 : BenObjectID cID;
154 : };
155 :
156 62 : class CBenNamedObjectListElmt : public CUtListElmt
157 : {
158 : public: // Methods
159 : // added to remove warning
160 62 : explicit CBenNamedObjectListElmt(pCUtListElmt pPrev) : CUtListElmt(pPrev)
161 62 : { cpNamedObject = NULL; }
162 62 : void SetNamedObject(pCBenNamedObject pObj)
163 : {
164 62 : cpNamedObject = pObj;
165 62 : }
166 :
167 : CBenNamedObjectListElmt(pCBenNamedObject pNamedObject,
168 : pCBenNamedObjectListElmt pPrev) : CUtListElmt(pPrev)
169 : { cpNamedObject = pNamedObject; }
170 275 : pCBenNamedObject GetNamedObject() { return cpNamedObject; }
171 :
172 : private: // Data
173 : pCBenNamedObject cpNamedObject;
174 : };
175 :
176 : class LtcUtBenValueStream : public SvStream
177 : {
178 : public:
179 : explicit LtcUtBenValueStream(pCBenValue pValue);
180 : virtual ~LtcUtBenValueStream();
181 :
182 : public: // Overridden methods
183 :
184 : /* added by */
185 0 : CBenValue * GetValue(){ return cpValue; };
186 0 : sal_uLong GetSize() { return m_ulValueLength; };
187 : protected: // Overridden methods
188 :
189 : virtual sal_uLong GetData( void* pData, sal_uLong nSize ) SAL_OVERRIDE;
190 : virtual sal_uLong PutData( const void* pData, sal_uLong nSize ) SAL_OVERRIDE;
191 : virtual sal_uInt64 SeekPos( sal_uInt64 nPos ) SAL_OVERRIDE;
192 : virtual void SetSize( sal_uInt64 nSize ) SAL_OVERRIDE;
193 : virtual void FlushData() SAL_OVERRIDE;
194 :
195 : private: // Data
196 : pCBenValue cpValue;
197 : unsigned long cCurrentPosition;
198 :
199 : sal_uLong m_ulValueLength; // Added by , sum of length of all sub-valuesegments
200 : // void GetAmountLeft(sal_uLong * pAmtLeft); useless in SODC
201 : };
202 :
203 : class LtcBenContainer
204 : {
205 : public:
206 : BenError Open();
207 : BenError RegisterPropertyName(const char * sPropertyName,
208 : pCBenPropertyName * ppPropertyName);
209 : // Pass NULL to begin iteration. Done when returns NULL.
210 : // Objects are returned in order of increasing ID
211 : pCBenObject GetNextObject(pCBenObject pCurrObject);
212 : pCBenObject FindNextObjectWithProperty(pCBenObject pCurrObject,
213 : BenObjectID PropertyID);
214 :
215 : public: // Internal methods
216 : explicit LtcBenContainer(LwpSvStream * pStream);
217 : ~LtcBenContainer();
218 :
219 : BenError Read(BenDataPtr pBuffer, unsigned long MaxSize,
220 : unsigned long * pAmtRead);
221 : BenError ReadKnownSize(BenDataPtr pBuffer, unsigned long Amt);
222 : BenError SeekToPosition(BenContainerPos Pos);
223 : BenError SeekFromEnd(long Offset);
224 :
225 : BenObjectID GetNextAvailObjectID() { return cNextAvailObjectID; }
226 4 : void SetNextAvailObjectID(BenObjectID ID) { cNextAvailObjectID = ID; }
227 196 : CUtList& GetObjects() { return cObjects; }
228 54 : CUtList& GetNamedObjects() { return cNamedObjects; }
229 :
230 : LtcUtBenValueStream * FindNextValueStreamWithPropertyName(const char * sPropertyName, LtcUtBenValueStream * pCurrentValueStream);
231 : LtcUtBenValueStream * FindValueStreamWithPropertyName(const char * sPropertyName);
232 : BenError CreateGraphicStream(SvStream * &pStream, const char *pObjectName);
233 :
234 : BenError GetSize(sal_uLong * pLength);
235 : LwpSvStream * GetStream()
236 : {
237 : return cpStream;
238 : };
239 : private: // Data
240 : CUtOwningList cObjects;
241 : CUtList cNamedObjects;
242 : LwpSvStream * cpStream;
243 : sal_uLong m_ulLength; // Added for TOCRead.cpp
244 : BenObjectID cNextAvailObjectID; // for new object
245 : };
246 :
247 346 : class CBenObject : public CBenIDListElmt
248 : {
249 : public:
250 : pCBenProperty UseProperty(BenObjectID PropertyID);
251 : pCBenValue UseValue(BenObjectID PropertyID);
252 : virtual bool IsNamedObject();
253 0 : pLtcBenContainer GetContainer() { return cpContainer; }
254 : BenObjectID GetObjectID() { return GetID(); }
255 : public: // Internal methods
256 204 : CBenObject(pLtcBenContainer pContainer, BenObjectID ObjectID,
257 204 : pCUtListElmt pPrev) : CBenIDListElmt(ObjectID, pPrev)
258 204 : { cpContainer = pContainer; }
259 173 : CUtList& GetProperties() { return cProperties; }
260 :
261 : private: // Data
262 : pLtcBenContainer cpContainer;
263 : CUtOwningList cProperties;
264 : };
265 :
266 173 : class CBenValue : public CBenIDListElmt
267 : {
268 : public:
269 : unsigned long GetValueSize();
270 : BenError ReadValueData(BenDataPtr pBuffer,
271 : unsigned long Offset, unsigned long MaxSize, unsigned long * pAmtRead);
272 :
273 0 : pCBenProperty BEN_EXPORT GetProperty() { return cpProperty; }
274 :
275 : public: // Internal methods
276 : // added to remove WARNING
277 173 : explicit CBenValue(BenObjectID TypeID):CBenIDListElmt(TypeID)
278 : {
279 173 : cpProperty = NULL;
280 173 : cpReferencedList = NULL;
281 173 : }
282 :
283 173 : void SetProperty(pCBenProperty pProperty)
284 : {
285 173 : cpProperty = pProperty;
286 173 : }
287 :
288 : CBenValue(pCBenProperty pProperty, BenObjectID TypeID) :
289 : CBenIDListElmt(TypeID)
290 : {
291 : cpProperty = pProperty;
292 : cpReferencedList = NULL;
293 : }
294 : BenObjectID GetTypeNameID() { return GetID(); }
295 : inline pCBenValueSegment GetNextValueSegment(pCBenValueSegment
296 : pCurrValueSegment);
297 : inline pLtcBenContainer GetContainer();
298 173 : CUtList& GetValueSegments() { return cValueSegments; }
299 :
300 : private: // Data
301 : pCBenProperty cpProperty;
302 : CUtOwningList cValueSegments;
303 : pCBenValue cpReferencedList;
304 : };
305 :
306 346 : class CBenProperty : public CBenIDListElmt
307 : {
308 : public:
309 : // In the Apple Bento, a property can have multiple values, each of a
310 : // different type. But we never use it that way, so in this code a
311 : // property has exactly one value
312 :
313 173 : CBenValue& UseValue() { return cValue; }
314 0 : pCBenObject GetBenObject() { return cpObject; }
315 0 : pLtcBenContainer GetContainer() { return GetBenObject()->GetContainer(); }
316 :
317 : public: // Internal methods
318 : // changed to remove WARNING here
319 173 : CBenProperty(pCBenObject pObject, BenObjectID PropertyID,
320 : BenObjectID TypeID, pCUtListElmt pPrevProperty) :
321 173 : CBenIDListElmt(PropertyID, pPrevProperty), cValue(TypeID)
322 : {
323 173 : cpObject = pObject;
324 173 : cValue.SetProperty(this);
325 173 : }
326 :
327 : BenObjectID GetPropertyNameID() { return GetID(); }
328 :
329 : private: // Data
330 : pCBenObject cpObject;
331 : CBenValue cValue;
332 : };
333 :
334 : // In our implementation, reference is always just the object ID for the
335 : // object referenced (but you shouldn't assume that)
336 : #define BEN_REFERENCE_SIZE 4
337 :
338 : class CBenReference
339 : {
340 : public: // Methods
341 : BenByte * GetData() { return cData; }
342 :
343 : private: // Data
344 : BenByte cData[BEN_REFERENCE_SIZE];
345 : };
346 :
347 346 : class CBenValueSegment : public CUtListElmt
348 : {
349 : public: // Internal methods
350 173 : CBenValueSegment(pCBenValue pValue, BenContainerPos Pos,
351 173 : unsigned long Size) : CUtListElmt(&pValue->GetValueSegments())
352 173 : { cpValue = pValue; cImmediate = false; cPos = Pos;
353 173 : cSize = Size; }
354 0 : CBenValueSegment(pCBenValue pValue, BenConstDataPtr pImmData,
355 0 : unsigned short Size) : CUtListElmt(&pValue->GetValueSegments())
356 0 : { cpValue = pValue; cImmediate = true;
357 0 : UtHugeMemcpy(cImmData, pImmData, Size); cSize = Size; }
358 : CBenValueSegment(BenContainerPos Pos, unsigned long Size)
359 : { cpValue = NULL; cImmediate = false; cPos = Pos;
360 : cSize = Size; }
361 : CBenValueSegment(BenConstDataPtr pImmData, unsigned short Size)
362 : { cpValue = NULL; cImmediate = true;
363 : UtHugeMemcpy(cImmData, pImmData, Size); cSize = Size; }
364 : bool IsLast()
365 : {
366 : return cpValue == NULL || cpValue->GetValueSegments().GetLast() ==
367 : this;
368 : }
369 0 : bool IsImmediate() { return cImmediate; }
370 0 : BenContainerPos GetPosition() { return cPos; }
371 0 : unsigned long GetSize() { return cSize; }
372 : void SetSize(unsigned long Size) { cSize = Size; }
373 0 : BenByte * GetImmediateData() { return cImmData; }
374 :
375 : private: // Data
376 : pCBenValue cpValue;
377 : bool cImmediate;
378 : union
379 : {
380 : BenContainerPos cPos;
381 : BenByte cImmData[4];
382 : };
383 : unsigned long cSize;
384 : };
385 :
386 0 : inline pCBenValueSegment CBenValue::GetNextValueSegment(pCBenValueSegment
387 : pCurrValueSegment)
388 0 : { return static_cast<pCBenValueSegment>( cValueSegments.GetNextOrNULL(pCurrValueSegment) ); }
389 :
390 0 : inline pLtcBenContainer CBenValue::GetContainer()
391 0 : { return GetProperty()->GetContainer(); }
392 :
393 62 : class CBenNamedObject : public CBenObject
394 : {
395 : public: // Methods
396 : virtual bool IsNamedObject() SAL_OVERRIDE;
397 : virtual bool IsPropertyName();
398 : virtual bool IsTypeName();
399 :
400 : public: // Internal methods
401 : CBenNamedObject(pLtcBenContainer pContainer, BenObjectID ObjectID,
402 : pCBenObject pPrevObject, const char * sName,
403 : pCUtListElmt pPrevNamedObjectListElmt);
404 : const char * GetName() { return csName.data(); }
405 :
406 275 : const char * GetNameCStr() { return csName.c_str(); }
407 :
408 : void SetPosition(BenContainerPos Pos) { cPos = Pos; }
409 : BenContainerPos GetPosition() { return cPos; }
410 : size_t GetLength() { return csName.length()+ 1; }
411 : CBenNamedObjectListElmt& GetNameListElmt() { return cNameListElmt; }
412 :
413 : private: // Data
414 : std::string csName;
415 : CBenNamedObjectListElmt cNameListElmt;
416 : BenContainerPos cPos;
417 : };
418 :
419 104 : class CBenPropertyName : public CBenNamedObject
420 : {
421 : public: // Internal methods
422 52 : CBenPropertyName(pLtcBenContainer pContainer, BenObjectID ObjectID,
423 : pCBenObject pPrevObject, const char * sName,
424 : pCUtListElmt pPrevNamedObjectListElmt) :
425 : CBenNamedObject(pContainer, ObjectID, pPrevObject, sName,
426 52 : pPrevNamedObjectListElmt) { ; }
427 : virtual bool IsPropertyName() SAL_OVERRIDE;
428 : };
429 :
430 20 : class CBenTypeName : public CBenNamedObject
431 : {
432 : public: // Internal methods
433 10 : CBenTypeName(pLtcBenContainer pContainer, BenObjectID ObjectID,
434 : pCBenObject pPrevObject, const char * sName,
435 : pCUtListElmt pPrevNamedObjectListElmt) :
436 : CBenNamedObject(pContainer, ObjectID, pPrevObject, sName,
437 10 : pPrevNamedObjectListElmt) { ; }
438 : virtual bool IsTypeName() SAL_OVERRIDE;
439 : };
440 :
441 : } // end namespace OpenStormBento
442 : #endif
443 :
444 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|