Bump version to 4.3-4
[LibreOffice.git] / lotuswordpro / source / filter / bencont.cxx
blob1033f67e98facb5c182ebd62446949c9b0d1916e
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * The Contents of this file are made available subject to the terms of
5 * either of the following licenses
7 * - GNU Lesser General Public License Version 2.1
8 * - Sun Industry Standards Source License Version 1.1
10 * Sun Microsystems Inc., October, 2000
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
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.
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.
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
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.
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.
46 * The Initial Developer of the Original Code is: IBM Corporation
48 * Copyright: 2008 by IBM Corporation
50 * All Rights Reserved.
52 * Contributor(s): _______________________________________
55 ************************************************************************/
56 #include "first.hxx"
57 #include "assert.h"
58 #include <stdio.h>
59 #include <sot/storinfo.hxx>
60 namespace OpenStormBento
63 // String definitions
64 const char gsBenMagicBytes[] = BEN_MAGIC_BYTES;
66 /**
67 * New bento container from file stream
68 * @param pointer to length of bento file
69 * @param pointer to pointer of Bento Container object
70 * @return error code
72 sal_uLong BenOpenContainer(LwpSvStream * pStream, pLtcBenContainer * ppContainer)
74 BenError Err;
76 *ppContainer = NULL;
78 if (NULL == pStream)
80 return BenErr_ContainerWithNoObjects;
83 pLtcBenContainer pContainer = new LtcBenContainer(pStream);
84 if ((Err = pContainer->Open()) != BenErr_OK) // delete two inputs
86 delete pContainer;
87 return BenErr_InvalidTOC;
90 *ppContainer = pContainer;
91 return BenErr_OK;
93 BenError
94 LtcBenContainer::Close()
96 return BenErr_OK;
99 LtcBenContainer::~LtcBenContainer()
101 Close();
104 BenError
105 LtcBenContainer::Open() // delete two inputs
107 BenError Err;
108 CBenTOCReader TOCReader(this);
109 if ((Err = TOCReader.ReadLabelAndTOC()) != BenErr_OK)
111 return Err;
113 return BenErr_OK;
116 BenError
117 LtcBenContainer::RegisterPropertyName(const char * sPropertyName,
118 pCBenPropertyName * ppPropertyName)
120 pCBenNamedObjectListElmt pPrevNamedObjectListElmt;
121 pCBenNamedObject pNamedObject = FindNamedObject(&cNamedObjects,
122 sPropertyName, &pPrevNamedObjectListElmt);
124 if (pNamedObject != NULL)
126 if (! pNamedObject->IsPropertyName())
127 return BenErr_NameConflict;
128 else *ppPropertyName = (pCBenPropertyName) pNamedObject;
130 else
132 pCBenIDListElmt pPrevObject;
133 if (FindID(&cObjects, cNextAvailObjectID, &pPrevObject) != NULL)
134 return BenErr_DuplicateObjectID;
136 *ppPropertyName = new CBenPropertyName(this, cNextAvailObjectID,
137 (pCBenObject) pPrevObject, sPropertyName, pPrevNamedObjectListElmt);
138 ++cNextAvailObjectID;
141 return BenErr_OK;
144 pCBenObject
145 LtcBenContainer::GetNextObject(pCBenObject pCurrObject)
147 return (pCBenObject) cObjects.GetNextOrNULL(pCurrObject);
150 pCBenObject
151 LtcBenContainer::FindNextObjectWithProperty(pCBenObject pCurrObject,
152 BenObjectID PropertyID)
154 while ((pCurrObject = GetNextObject(pCurrObject)) != NULL)
155 if (pCurrObject->UseProperty(PropertyID) != NULL)
156 return pCurrObject;
158 return NULL;
162 * Construction
163 * @param Bento file stream pointer
164 * @return
166 LtcBenContainer::LtcBenContainer(LwpSvStream * pStream)
167 : cNextAvailObjectID(0)
169 cpStream = pStream;
170 pStream->Seek(STREAM_SEEK_TO_END);
171 m_ulLength = pStream->Tell();
172 pStream->Seek(STREAM_SEEK_TO_BEGIN);
176 * Read buffer fro bento file with specified buffer
177 * @date 07/05/2004
178 * @param buffer pointer
179 * @param buffer size
180 * @param number of bytes read
181 * @return BenError
183 BenError LtcBenContainer::Read(BenDataPtr pBuffer, unsigned long MaxSize,
184 unsigned long * pAmtRead)
186 *pAmtRead = cpStream->Read(pBuffer, MaxSize);
187 return BenErr_OK;
190 * Read buffer from bento file with specified size
191 * @date 07/05/2004
192 * @param buffer pointer
193 * @param number of bytes to be read
194 * @return BenError
196 BenError LtcBenContainer::ReadKnownSize(BenDataPtr pBuffer, unsigned long Amt)
198 sal_uLong ulLength;
199 ulLength = cpStream->Read(pBuffer, Amt);
200 if(ulLength == Amt)
202 return BenErr_OK;
204 return BenErr_ReadPastEndOfContainer;
207 * Seek to position from the beginning of the bento file
208 * @date 07/05/2004
209 * @param position in container file from beginning
210 * @return BenError
212 BenError LtcBenContainer::SeekToPosition(BenContainerPos Pos)
214 cpStream->Seek(Pos);
215 return BenErr_OK;
218 * Seek to position compare to end of bento file
219 * @date 07/05/2004
220 * @param position in container file from end
221 * @return BenError
223 BenError LtcBenContainer::SeekFromEnd(long Offset)
225 cpStream->Seek(STREAM_SEEK_TO_END);
226 cpStream->SeekRel(Offset);
228 return BenErr_OK;
231 * Find the next value stream with property name
232 * @date 07/05/2004
233 * @param string of property name
234 * @param current value stream pointer with the property name
235 * @return next value stream pointer with the property names
237 LtcUtBenValueStream * LtcBenContainer::FindNextValueStreamWithPropertyName(const char * sPropertyName, LtcUtBenValueStream * pCurrentValueStream)
239 CBenPropertyName * pPropertyName;
240 RegisterPropertyName(sPropertyName, &pPropertyName); // Get property name object
242 if (NULL == pPropertyName)
243 return NULL; // Property not exist
245 // Get current object
246 CBenObject * pObj = NULL;
247 if (pCurrentValueStream != NULL)
249 pObj = pCurrentValueStream->GetValue()->GetProperty()->GetBenObject();
252 pObj =FindNextObjectWithProperty(pObj, pPropertyName->GetID()); // Get next object with same property name
253 if (NULL == pObj)
254 return NULL;
256 CBenValue * pValue;
257 LtcUtBenValueStream * pValueStream;
259 pValue = pObj->UseValue(pPropertyName->GetID());
261 pValueStream = new LtcUtBenValueStream(pValue);
263 return pValueStream;
267 * Find the unique value stream with property name
268 * @date 07/05/2004
269 * @param string of property name
270 * @return the only value stream pointer with the property names
272 LtcUtBenValueStream * LtcBenContainer::FindValueStreamWithPropertyName(const char * sPropertyName)
274 return FindNextValueStreamWithPropertyName(sPropertyName, NULL);
277 * <description>
278 * @date 07/05/2004
279 * @param pointer to length of bento file
280 * @return BenError
282 BenError LtcBenContainer::GetSize(sal_uLong * pLength)
284 *pLength = m_ulLength;
285 return BenErr_OK;
288 sal_uInt32 GetSvStreamSize(SvStream * pStream)
290 sal_uInt32 nCurPos = pStream->Tell();
291 pStream->Seek(STREAM_SEEK_TO_END);
292 sal_uInt32 ulLength = pStream->Tell();
293 pStream->Seek(nCurPos);
295 return ulLength;
299 * Find hazily according to object ID
300 * @date 01/31/2005
301 * @param pObjectname - format as "GrXX,XXXXXXXX" wherein XX is high part of object ID, and XXXXXXXX is low part
302 * @return the value stream pointers with the property names
304 BenError LtcBenContainer::CreateGraphicStream(SvStream * &pStream, const char *pObjectName)
306 if (!pObjectName)
308 pStream = NULL;
309 return BenErr_NamedObjectError;
311 // construct the string of property name
312 char sSName[64]="";
313 char sDName[64]="";
315 sprintf(sSName, "%s-S", pObjectName);
316 sprintf(sDName, "%s-D", pObjectName);
318 /* traverse the found properties and construct the stream vectors */
319 SvMemoryStream * pMemStream = NULL;
320 // get S&D's stream and merge them together
321 SvStream *pD = NULL, *pS = NULL;
323 pS = FindValueStreamWithPropertyName(sSName);
324 pD = FindValueStreamWithPropertyName(sDName);
326 sal_uInt32 nDLen = 0;
327 if(pD)
329 nDLen = GetSvStreamSize(pD);
331 sal_uInt32 nLen = nDLen;
332 if(pS)
334 nLen += GetSvStreamSize(pS) ;
337 OSL_ENSURE(nLen > 0, "expected a non-0 length");
338 // the 'D' stream is NULL or it has invalid length
339 if (nLen <= 0)
341 pStream = NULL;
342 return BenErr_NamedObjectError;
345 char * pBuf = new char[nLen];
346 assert(pBuf != NULL);
347 char * pPointer = pBuf;
348 if(pD)
350 pD->Read(pPointer, nDLen);
351 delete pD;
353 pPointer += nDLen;
354 if(pS)
356 pS->Read(pPointer, nLen - nDLen);
357 delete pS;
360 pMemStream = new SvMemoryStream(pBuf, nLen, STREAM_READ);
361 assert(pMemStream != NULL);
363 pStream = pMemStream;
364 return BenErr_OK;
367 }// end namespace OpenStormBento
369 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */