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 1100 : class CBenIDListElmt : public CUtListElmt
145 : {
146 : public: // Internal methods
147 754 : CBenIDListElmt(BenObjectID ID, pCUtListElmt pPrev) : CUtListElmt(pPrev)
148 754 : { cID = ID; }
149 346 : CBenIDListElmt(BenObjectID ID) { cID = ID; }
150 1184 : BenObjectID GetID() { return cID; }
151 :
152 : private: // Data
153 : BenObjectID cID;
154 : };
155 :
156 124 : class CBenNamedObjectListElmt : public CUtListElmt
157 : {
158 : public: // Methods
159 : // added to remove warning
160 124 : CBenNamedObjectListElmt(pCUtListElmt pPrev) : CUtListElmt(pPrev)
161 124 : { cpNamedObject = NULL; }
162 124 : void SetNamedObject(pCBenNamedObject pObj)
163 : {
164 124 : cpNamedObject = pObj;
165 124 : }
166 :
167 : CBenNamedObjectListElmt(pCBenNamedObject pNamedObject,
168 : pCBenNamedObjectListElmt pPrev) : CUtListElmt(pPrev)
169 : { cpNamedObject = pNamedObject; }
170 550 : pCBenNamedObject GetNamedObject() { return cpNamedObject; }
171 :
172 : private: // Data
173 : pCBenNamedObject cpNamedObject;
174 : };
175 :
176 : class LtcUtBenValueStream : public SvStream
177 : {
178 : public:
179 : 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 Close();
208 : BenError RegisterPropertyName(const char * sPropertyName,
209 : pCBenPropertyName * ppPropertyName);
210 : // Pass NULL to begin iteration. Done when returns NULL.
211 : // Objects are returned in order of increasing ID
212 : pCBenObject GetNextObject(pCBenObject pCurrObject);
213 : pCBenObject FindNextObjectWithProperty(pCBenObject pCurrObject,
214 : BenObjectID PropertyID);
215 :
216 : public: // Internal methods
217 : LtcBenContainer(LwpSvStream * pStream);
218 : ~LtcBenContainer();
219 :
220 : BenError Read(BenDataPtr pBuffer, unsigned long MaxSize,
221 : unsigned long * pAmtRead);
222 : BenError ReadKnownSize(BenDataPtr pBuffer, unsigned long Amt);
223 : BenError SeekToPosition(BenContainerPos Pos);
224 : BenError SeekFromEnd(long Offset);
225 :
226 : BenObjectID GetNextAvailObjectID() { return cNextAvailObjectID; }
227 8 : void SetNextAvailObjectID(BenObjectID ID) { cNextAvailObjectID = ID; }
228 392 : CUtList& GetObjects() { return cObjects; }
229 108 : CUtList& GetNamedObjects() { return cNamedObjects; }
230 :
231 : LtcUtBenValueStream * FindNextValueStreamWithPropertyName(const char * sPropertyName, LtcUtBenValueStream * pCurrentValueStream);
232 : LtcUtBenValueStream * FindValueStreamWithPropertyName(const char * sPropertyName);
233 : BenError CreateGraphicStream(SvStream * &pStream, const char *pObjectName);
234 :
235 : BenError GetSize(sal_uLong * pLength);
236 : LwpSvStream * GetStream()
237 : {
238 : return cpStream;
239 : };
240 : private: // Data
241 : CUtOwningList cObjects;
242 : CUtList cNamedObjects;
243 : LwpSvStream * cpStream;
244 : sal_uLong m_ulLength; // Added for TOCRead.cpp
245 : BenObjectID cNextAvailObjectID; // for new object
246 : };
247 :
248 692 : class CBenObject : public CBenIDListElmt
249 : {
250 : public:
251 : pCBenProperty UseProperty(BenObjectID PropertyID);
252 : pCBenValue UseValue(BenObjectID PropertyID);
253 : virtual bool IsNamedObject();
254 0 : pLtcBenContainer GetContainer() { return cpContainer; }
255 : BenObjectID GetObjectID() { return GetID(); }
256 : public: // Internal methods
257 408 : CBenObject(pLtcBenContainer pContainer, BenObjectID ObjectID,
258 408 : pCUtListElmt pPrev) : CBenIDListElmt(ObjectID, pPrev)
259 408 : { cpContainer = pContainer; }
260 346 : CUtList& GetProperties() { return cProperties; }
261 :
262 : private: // Data
263 : pLtcBenContainer cpContainer;
264 : CUtOwningList cProperties;
265 : };
266 :
267 346 : class CBenValue : public CBenIDListElmt
268 : {
269 : public:
270 : unsigned long GetValueSize();
271 : BenError ReadValueData(BenDataPtr pBuffer,
272 : unsigned long Offset, unsigned long MaxSize, unsigned long * pAmtRead);
273 :
274 0 : pCBenProperty BEN_EXPORT GetProperty() { return cpProperty; }
275 :
276 : public: // Internal methods
277 : // added to remove WARNING
278 346 : CBenValue(BenObjectID TypeID):CBenIDListElmt(TypeID)
279 : {
280 346 : cpProperty = NULL;
281 346 : cpReferencedList = NULL;
282 346 : }
283 :
284 346 : void SetProperty(pCBenProperty pProperty)
285 : {
286 346 : cpProperty = pProperty;
287 346 : }
288 :
289 : CBenValue(pCBenProperty pProperty, BenObjectID TypeID) :
290 : CBenIDListElmt(TypeID)
291 : {
292 : cpProperty = pProperty;
293 : cpReferencedList = NULL;
294 : }
295 : BenObjectID GetTypeNameID() { return GetID(); }
296 : inline pCBenValueSegment GetNextValueSegment(pCBenValueSegment
297 : pCurrValueSegment);
298 : inline pLtcBenContainer GetContainer();
299 346 : CUtList& GetValueSegments() { return cValueSegments; }
300 : // Currently, no generation support
301 : BenGeneration GetGeneration() { return 1; }
302 :
303 : private: // Data
304 : pCBenProperty cpProperty;
305 : CUtOwningList cValueSegments;
306 : pCBenValue cpReferencedList;
307 : };
308 :
309 692 : class CBenProperty : public CBenIDListElmt
310 : {
311 : public:
312 : // In the Apple Bento, a property can have multiple values, each of a
313 : // different type. But we never use it that way, so in this code a
314 : // property has exactly one value
315 :
316 346 : CBenValue& UseValue() { return cValue; }
317 0 : pCBenObject GetBenObject() { return cpObject; }
318 0 : pLtcBenContainer GetContainer() { return GetBenObject()->GetContainer(); }
319 :
320 : public: // Internal methods
321 : // changed to remove WARNING here
322 346 : CBenProperty(pCBenObject pObject, BenObjectID PropertyID,
323 : BenObjectID TypeID, pCUtListElmt pPrevProperty) :
324 346 : CBenIDListElmt(PropertyID, pPrevProperty), cValue(TypeID)
325 : {
326 346 : cpObject = pObject;
327 346 : cValue.SetProperty(this);
328 346 : }
329 :
330 : BenObjectID GetPropertyNameID() { return GetID(); }
331 :
332 : private: // Data
333 : pCBenObject cpObject;
334 : CBenValue cValue;
335 : };
336 :
337 : // In our implementation, reference is always just the object ID for the
338 : // object referenced (but you shouldn't assume that)
339 : #define BEN_REFERENCE_SIZE 4
340 :
341 : class CBenReference
342 : {
343 : public: // Methods
344 : BenByte * GetData() { return cData; }
345 :
346 : private: // Data
347 : BenByte cData[BEN_REFERENCE_SIZE];
348 : };
349 :
350 692 : class CBenValueSegment : public CUtListElmt
351 : {
352 : public: // Internal methods
353 346 : CBenValueSegment(pCBenValue pValue, BenContainerPos Pos,
354 346 : unsigned long Size) : CUtListElmt(&pValue->GetValueSegments())
355 346 : { cpValue = pValue; cImmediate = false; cPos = Pos;
356 346 : cSize = Size; }
357 0 : CBenValueSegment(pCBenValue pValue, BenConstDataPtr pImmData,
358 0 : unsigned short Size) : CUtListElmt(&pValue->GetValueSegments())
359 0 : { cpValue = pValue; cImmediate = true;
360 0 : UtHugeMemcpy(cImmData, pImmData, Size); cSize = Size; }
361 : CBenValueSegment(BenContainerPos Pos, unsigned long Size)
362 : { cpValue = NULL; cImmediate = false; cPos = Pos;
363 : cSize = Size; }
364 : CBenValueSegment(BenConstDataPtr pImmData, unsigned short Size)
365 : { cpValue = NULL; cImmediate = true;
366 : UtHugeMemcpy(cImmData, pImmData, Size); cSize = Size; }
367 : bool IsLast()
368 : {
369 : return cpValue == NULL || cpValue->GetValueSegments().GetLast() ==
370 : this;
371 : }
372 0 : bool IsImmediate() { return cImmediate; }
373 0 : BenContainerPos GetPosition() { return cPos; }
374 0 : unsigned long GetSize() { return cSize; }
375 : void SetSize(unsigned long Size) { cSize = Size; }
376 0 : BenByte * GetImmediateData() { return cImmData; }
377 :
378 : private: // Data
379 : pCBenValue cpValue;
380 : bool cImmediate;
381 : union
382 : {
383 : BenContainerPos cPos;
384 : BenByte cImmData[4];
385 : };
386 : unsigned long cSize;
387 : };
388 :
389 0 : inline pCBenValueSegment CBenValue::GetNextValueSegment(pCBenValueSegment
390 : pCurrValueSegment)
391 0 : { return static_cast<pCBenValueSegment>( cValueSegments.GetNextOrNULL(pCurrValueSegment) ); }
392 :
393 0 : inline pLtcBenContainer CBenValue::GetContainer()
394 0 : { return GetProperty()->GetContainer(); }
395 :
396 124 : class CBenNamedObject : public CBenObject
397 : {
398 : public: // Methods
399 : virtual bool IsNamedObject() SAL_OVERRIDE;
400 : virtual bool IsPropertyName();
401 : virtual bool IsTypeName();
402 :
403 : public: // Internal methods
404 : CBenNamedObject(pLtcBenContainer pContainer, BenObjectID ObjectID,
405 : pCBenObject pPrevObject, const char * sName,
406 : pCUtListElmt pPrevNamedObjectListElmt);
407 : const char * GetName() { return csName.data(); }
408 :
409 550 : const char * GetNameCStr() { return csName.c_str(); }
410 :
411 : void SetPosition(BenContainerPos Pos) { cPos = Pos; }
412 : BenContainerPos GetPosition(void) { return cPos; }
413 : size_t GetLength(void) { return csName.length()+ 1; }
414 : CBenNamedObjectListElmt& GetNameListElmt() { return cNameListElmt; }
415 :
416 : private: // Data
417 : std::string csName;
418 : CBenNamedObjectListElmt cNameListElmt;
419 : BenContainerPos cPos;
420 : };
421 :
422 208 : class CBenPropertyName : public CBenNamedObject
423 : {
424 : public: // Internal methods
425 104 : CBenPropertyName(pLtcBenContainer pContainer, BenObjectID ObjectID,
426 : pCBenObject pPrevObject, const char * sName,
427 : pCUtListElmt pPrevNamedObjectListElmt) :
428 : CBenNamedObject(pContainer, ObjectID, pPrevObject, sName,
429 104 : pPrevNamedObjectListElmt) { ; }
430 : virtual bool IsPropertyName() SAL_OVERRIDE;
431 : };
432 :
433 40 : class CBenTypeName : public CBenNamedObject
434 : {
435 : public: // Internal methods
436 20 : CBenTypeName(pLtcBenContainer pContainer, BenObjectID ObjectID,
437 : pCBenObject pPrevObject, const char * sName,
438 : pCUtListElmt pPrevNamedObjectListElmt) :
439 : CBenNamedObject(pContainer, ObjectID, pPrevObject, sName,
440 20 : pPrevNamedObjectListElmt) { ; }
441 : virtual bool IsTypeName() SAL_OVERRIDE;
442 : };
443 :
444 : } // end namespace OpenStormBento
445 : #endif
446 :
447 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|