build fix
[LibreOffice.git] / lotuswordpro / source / filter / bencont.cxx
blob506b2ed06d72cdc8794e095a0b9b78cfb079bda9
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 <osl/diagnose.h>
60 #include <sot/storinfo.hxx>
61 namespace OpenStormBento
64 // String definitions
65 const char gsBenMagicBytes[] = BEN_MAGIC_BYTES;
67 /**
68 * New bento container from file stream
69 * @param pointer to length of bento file
70 * @param pointer to pointer of Bento Container object
71 * @return error code
73 sal_uLong BenOpenContainer(LwpSvStream * pStream, pLtcBenContainer * ppContainer)
75 BenError Err;
77 *ppContainer = nullptr;
79 if (nullptr == pStream)
81 return BenErr_ContainerWithNoObjects;
84 pLtcBenContainer pContainer = new LtcBenContainer(pStream);
85 if ((Err = pContainer->Open()) != BenErr_OK) // delete two inputs
87 delete pContainer;
88 return BenErr_InvalidTOC;
91 *ppContainer = pContainer;
92 return BenErr_OK;
95 LtcBenContainer::~LtcBenContainer()
99 BenError
100 LtcBenContainer::Open() // delete two inputs
102 BenError Err;
103 CBenTOCReader TOCReader(this);
104 if ((Err = TOCReader.ReadLabelAndTOC()) != BenErr_OK)
106 return Err;
108 return BenErr_OK;
111 void
112 LtcBenContainer::RegisterPropertyName(const char * sPropertyName,
113 pCBenPropertyName * ppPropertyName)
115 pCUtListElmt pPrevNamedObjectListElmt;
116 pCBenNamedObject pNamedObject = FindNamedObject(&cNamedObjects,
117 sPropertyName, &pPrevNamedObjectListElmt);
119 if (pNamedObject != nullptr)
121 if (! pNamedObject->IsPropertyName())
122 return;
123 else *ppPropertyName = static_cast<pCBenPropertyName>(pNamedObject);
125 else
127 pCUtListElmt pPrevObject;
128 if (FindID(&cObjects, cNextAvailObjectID, &pPrevObject) != nullptr)
129 return;
131 *ppPropertyName = new CBenPropertyName(this, cNextAvailObjectID,
132 static_cast<pCBenObject>(pPrevObject), sPropertyName, pPrevNamedObjectListElmt);
133 ++cNextAvailObjectID;
137 pCBenObject
138 LtcBenContainer::GetNextObject(pCBenObject pCurrObject)
140 return static_cast<pCBenObject>(cObjects.GetNextOrNULL(pCurrObject));
143 pCBenObject
144 LtcBenContainer::FindNextObjectWithProperty(pCBenObject pCurrObject,
145 BenObjectID PropertyID)
147 while ((pCurrObject = GetNextObject(pCurrObject)) != nullptr)
148 if (pCurrObject->UseProperty(PropertyID) != nullptr)
149 return pCurrObject;
151 return nullptr;
155 * Construction
156 * @param Bento file stream pointer
157 * @return
159 LtcBenContainer::LtcBenContainer(LwpSvStream * pStream)
160 : cNextAvailObjectID(0)
162 cpStream = pStream;
163 pStream->Seek(STREAM_SEEK_TO_END);
164 m_ulLength = pStream->Tell();
165 pStream->Seek(STREAM_SEEK_TO_BEGIN);
169 * Read buffer fro bento file with specified buffer
170 * @param buffer pointer
171 * @param buffer size
172 * @param number of bytes read
173 * @return BenError
175 BenError LtcBenContainer::Read(void * pBuffer, unsigned long MaxSize,
176 unsigned long * pAmtRead)
178 *pAmtRead = cpStream->Read(pBuffer, MaxSize);
179 return BenErr_OK;
182 * Read buffer from bento file with specified size
183 * @param buffer pointer
184 * @param number of bytes to be read
185 * @return BenError
187 BenError LtcBenContainer::ReadKnownSize(void * pBuffer, unsigned long Amt)
189 sal_uLong ulLength;
190 ulLength = cpStream->Read(pBuffer, Amt);
191 if(ulLength == Amt)
193 return BenErr_OK;
195 return BenErr_ReadPastEndOfContainer;
198 * Seek to position from the beginning of the bento file
199 * @param position in container file from beginning
200 * @return BenError
202 BenError LtcBenContainer::SeekToPosition(BenContainerPos Pos)
204 cpStream->Seek(Pos);
205 return BenErr_OK;
208 * Seek to position compare to end of bento file
209 * @param position in container file from end
210 * @return BenError
212 BenError LtcBenContainer::SeekFromEnd(long Offset)
214 cpStream->Seek(STREAM_SEEK_TO_END);
215 cpStream->SeekRel(Offset);
217 return BenErr_OK;
220 * Find the next value stream with property name
221 * @param string of property name
222 * @return next value stream pointer with the property names
224 LtcUtBenValueStream * LtcBenContainer::FindNextValueStreamWithPropertyName(const char * sPropertyName)
226 CBenPropertyName * pPropertyName(nullptr);
227 RegisterPropertyName(sPropertyName, &pPropertyName); // Get property name object
229 if (nullptr == pPropertyName)
230 return nullptr; // Property not exist
232 // Get current object
233 CBenObject * pObj = nullptr;
235 pObj =FindNextObjectWithProperty(pObj, pPropertyName->GetID()); // Get next object with same property name
236 if (nullptr == pObj)
237 return nullptr;
239 CBenValue * pValue;
240 LtcUtBenValueStream * pValueStream;
242 pValue = pObj->UseValue(pPropertyName->GetID());
244 pValueStream = new LtcUtBenValueStream(pValue);
246 return pValueStream;
250 * Find the unique value stream with property name
251 * @param string of property name
252 * @return the only value stream pointer with the property names
254 LtcUtBenValueStream * LtcBenContainer::FindValueStreamWithPropertyName(const char * sPropertyName)
256 return FindNextValueStreamWithPropertyName(sPropertyName);
259 * <description>
260 * @param pointer to length of bento file
261 * @return BenError
263 BenError LtcBenContainer::GetSize(sal_uLong * pLength)
265 *pLength = m_ulLength;
266 return BenErr_OK;
269 sal_uInt32 GetSvStreamSize(SvStream * pStream)
271 sal_uInt32 nCurPos = pStream->Tell();
272 pStream->Seek(STREAM_SEEK_TO_END);
273 sal_uInt32 ulLength = pStream->Tell();
274 pStream->Seek(nCurPos);
276 return ulLength;
280 * Find hazily according to object ID
281 * @param pObjectname - format as "GrXX,XXXXXXXX" wherein XX is high part of object ID, and XXXXXXXX is low part
283 void LtcBenContainer::CreateGraphicStream(SvStream * &pStream, const char *pObjectName)
285 if (!pObjectName)
287 pStream = nullptr;
288 return;
290 // construct the string of property name
291 char sSName[64]="";
292 char sDName[64]="";
294 sprintf(sSName, "%s-S", pObjectName);
295 sprintf(sDName, "%s-D", pObjectName);
297 /* traverse the found properties and construct the stream vectors */
298 SvMemoryStream * pMemStream = nullptr;
299 // get S&D's stream and merge them together
300 SvStream *pD = nullptr, *pS = nullptr;
302 pS = FindValueStreamWithPropertyName(sSName);
303 pD = FindValueStreamWithPropertyName(sDName);
305 sal_uInt32 nDLen = 0;
306 if(pD)
308 nDLen = GetSvStreamSize(pD);
310 sal_uInt32 nLen = nDLen;
311 if(pS)
313 nLen += GetSvStreamSize(pS) ;
316 OSL_ENSURE(nLen > 0, "expected a non-0 length");
317 // the 'D' stream is NULL or it has invalid length
318 if (nLen <= 0)
320 pStream = nullptr;
321 return;
324 char * pBuf = new char[nLen];
325 assert(pBuf != nullptr);
326 char * pPointer = pBuf;
327 if(pD)
329 pD->ReadBytes(pPointer, nDLen);
330 delete pD;
332 pPointer += nDLen;
333 if(pS)
335 pS->ReadBytes(pPointer, nLen - nDLen);
336 delete pS;
339 pMemStream = new SvMemoryStream(pBuf, nLen, StreamMode::READ);
340 assert(pMemStream != nullptr);
342 pStream = pMemStream;
345 }// end namespace OpenStormBento
347 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */