LibreOffice Module lotuswordpro (master) 1
bencont.cxx
Go to the documentation of this file.
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#include "first.hxx"
57#include "tocread.hxx"
58#include <algorithm>
59#include <osl/diagnose.h>
60#include <rtl/string.hxx>
61
63{
64
65// String definitions
67
74sal_uLong BenOpenContainer(LwpSvStream * pStream, std::unique_ptr<LtcBenContainer>* ppContainer)
75{
76 *ppContainer = nullptr;
77
78 if (nullptr == pStream)
79 {
81 }
82
83 std::unique_ptr<LtcBenContainer> pContainer(new LtcBenContainer(pStream));
84 if (pContainer->Open() != BenErr_OK) // delete two inputs
85 {
86 return BenErr_InvalidTOC;
87 }
88
89 *ppContainer = std::move(pContainer);
90 return BenErr_OK;
91}
92
94{
95}
96
98LtcBenContainer::Open() // delete two inputs
99{
100 BenError Err;
101 CBenTOCReader TOCReader(this);
102 if ((Err = TOCReader.ReadLabelAndTOC()) != BenErr_OK)
103 {
104 return Err;
105 }
106 return BenErr_OK;
107}
108
109void
110LtcBenContainer::RegisterPropertyName(const char * sPropertyName,
111 CBenPropertyName ** ppPropertyName)
112{
113 CUtListElmt * pPrevNamedObjectListElmt;
115 sPropertyName, &pPrevNamedObjectListElmt);
116
117 if (pNamedObject != nullptr)
118 {
119 if (! pNamedObject->IsPropertyName())
120 return;
121 else *ppPropertyName = static_cast<CBenPropertyName *>(pNamedObject);
122 }
123 else
124 {
125 CUtListElmt * pPrevObject;
126 if (FindID(&cObjects, cNextAvailObjectID, &pPrevObject) != nullptr)
127 return;
128
129 *ppPropertyName = new CBenPropertyName(this, cNextAvailObjectID,
130 pPrevObject, sPropertyName, pPrevNamedObjectListElmt);
132 }
133}
134
137{
138 return static_cast<CBenObject *>(cObjects.GetNextOrNULL(pCurrObject));
139}
140
143 BenObjectID PropertyID)
144{
145 while ((pCurrObject = GetNextObject(pCurrObject)) != nullptr)
146 if (pCurrObject->UseProperty(PropertyID) != nullptr)
147 return pCurrObject;
148
149 return nullptr;
150}
151
158 : cNextAvailObjectID(0)
159{
160 cpStream = pStream;
161 pStream->Seek(STREAM_SEEK_TO_END);
162 m_ulLength = pStream->Tell();
163 pStream->Seek(STREAM_SEEK_TO_BEGIN);
164}
165
172void LtcBenContainer::Read(void * pBuffer, size_t MaxSize,
173 size_t* pAmtRead)
174{
175 *pAmtRead = cpStream->Read(pBuffer, MaxSize);
176}
183BenError LtcBenContainer::ReadKnownSize(void * pBuffer, size_t Amt)
184{
185 size_t ulLength = cpStream->Read(pBuffer, Amt);
186 if (ulLength == Amt)
187 {
188 return BenErr_OK;
189 }
191}
197{
198 cpStream->Seek(Pos);
199}
205{
208}
215{
217 RegisterPropertyName(sPropertyName, &pPropertyName); // Get property name object
218
219 if (nullptr == pPropertyName)
220 return nullptr; // Property not exist
221
222 // Get current object
223 CBenObject * pObj =FindNextObjectWithProperty(nullptr, pPropertyName->GetID()); // Get next object with same property name
224 if (nullptr == pObj)
225 return nullptr;
226
227 CBenValue * pValue;
228 LtcUtBenValueStream * pValueStream;
229
230 pValue = pObj->UseValue(pPropertyName->GetID());
231
232 pValueStream = new LtcUtBenValueStream(pValue);
233
234 return pValueStream;
235}
236
243{
244 return FindNextValueStreamWithPropertyName(sPropertyName);
245}
246
247namespace
248{
249 void readDataInBlocks(SvStream& rSt, sal_uInt64 nDLen, std::vector<sal_uInt8>& rData)
250 {
251 //read data in blocks as it's more likely large values are simply broken
252 //and we'll run out of data before we need to realloc
253 for (sal_uInt64 i = 0; i < nDLen; i+= SAL_MAX_UINT16)
254 {
255 size_t nOldSize = rData.size();
256 size_t nBlock = std::min<size_t>(SAL_MAX_UINT16, nDLen - nOldSize);
257 rData.resize(nOldSize + nBlock);
258 size_t nReadBlock = rSt.ReadBytes(rData.data() + nOldSize, nBlock);
259 if (nBlock != nReadBlock)
260 {
261 rData.resize(nOldSize + nReadBlock);
262 break;
263 }
264 }
265 }
266}
267
272std::vector<sal_uInt8> LtcBenContainer::GetGraphicData(const char *pObjectName)
273{
274 std::vector<sal_uInt8> aData;
275 if (!pObjectName)
276 {
277 return aData;
278 }
279 // construct the string of property name
280 OString sSName=OString::Concat(pObjectName) + "-S";
281 OString sDName=OString::Concat(pObjectName) + "-D";
282
283 /* traverse the found properties and construct the stream vectors */
284 // get S&D's stream and merge them together
285 std::unique_ptr<SvStream> xS(FindValueStreamWithPropertyName(sSName.getStr()));
286 std::unique_ptr<SvStream> xD(FindValueStreamWithPropertyName(sDName.getStr()));
287
288 sal_uInt64 nDLen = 0;
289 if (xD)
290 {
291 nDLen = xD->TellEnd();
292 }
293 sal_uInt64 nSLen = 0;
294 if (xS)
295 {
296 nSLen = xS->TellEnd();
297 }
298
299 sal_uInt64 nLen = nDLen + nSLen;
300 OSL_ENSURE(nLen > 0, "expected a non-0 length");
301 // the 'D' stream is NULL or it has invalid length
302 if (nLen <= 0)
303 {
304 return aData;
305 }
306
307 if (xD)
308 {
309 readDataInBlocks(*xD, nDLen, aData);
310 xD.reset();
311 }
312 if (xS)
313 {
314 readDataInBlocks(*xS, nSLen, aData);
315 xS.reset();
316 }
317
318 return aData;
319}
320
322{
323 return m_ulLength - cpStream->Tell();
324}
325
326}// end namespace OpenStormBento
327
328/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const char * pPropertyName
#define BEN_MAGIC_BYTES
Definition: bento.hxx:85
encapsulate XInputStream to provide SvStream like interfaces
Definition: lwpsvstream.hxx:69
sal_Int64 Seek(sal_Int64 pos)
@descr Seek to pos
void SeekRel(sal_Int64 pos)
@descr SeekRel in stream
Definition: lwpsvstream.cxx:98
sal_Int64 Tell()
@descr Get the current position in stream
size_t Read(void *bytes, size_t nBytesToRead)
@descr read nBytesToRead bytes to buf
Definition: lwpsvstream.cxx:70
virtual bool IsPropertyName()
Definition: benname.cxx:73
CBenProperty * UseProperty(BenObjectID PropertyID)
Definition: benobj.cxx:61
CBenValue * UseValue(BenObjectID PropertyID)
Definition: benobj.cxx:67
CUtListElmt * GetNextOrNULL(CUtListElmt const *pCurr)
Definition: utlist.cxx:92
std::vector< sal_uInt8 > GetGraphicData(const char *pObjectName)
Find hazily according to object ID.
Definition: bencont.cxx:272
sal_uLong remainingSize() const
Definition: bencont.cxx:321
BenError ReadKnownSize(void *pBuffer, size_t Amt)
Read buffer from bento file with specified size.
Definition: bencont.cxx:183
LtcUtBenValueStream * FindNextValueStreamWithPropertyName(const char *sPropertyName)
Find the next value stream with property name.
Definition: bencont.cxx:214
LtcBenContainer(LwpSvStream *pStream)
Construction.
Definition: bencont.cxx:157
LtcUtBenValueStream * FindValueStreamWithPropertyName(const char *sPropertyName)
Find the unique value stream with property name.
Definition: bencont.cxx:242
CBenObject * GetNextObject(CBenObject const *pCurrObject)
Definition: bencont.cxx:136
void SeekToPosition(BenContainerPos Pos)
Seek to position from the beginning of the bento file.
Definition: bencont.cxx:196
CBenObject * FindNextObjectWithProperty(CBenObject *pCurrObject, BenObjectID PropertyID)
Definition: bencont.cxx:142
void RegisterPropertyName(const char *sPropertyName, CBenPropertyName **ppPropertyName)
Definition: bencont.cxx:110
void Read(void *pBuffer, size_t MaxSize, size_t *pAmtRead)
Read buffer for bento file with specified buffer.
Definition: bencont.cxx:172
void SeekFromEnd(tools::Long Offset)
Seek to position compare to end of bento file.
Definition: bencont.cxx:204
std::size_t ReadBytes(void *pData, std::size_t nSize)
CBenIDListElmt * FindID(CUtList *pList, BenObjectID ObjectID, CUtListElmt **ppPrev)
Definition: benlist.cxx:87
const char gsBenMagicBytes[]
Definition: bencont.cxx:66
sal_uLong BenOpenContainer(LwpSvStream *pStream, std::unique_ptr< LtcBenContainer > *ppContainer)
New bento container from file stream.
Definition: bencont.cxx:74
@ BenErr_InvalidTOC
Definition: bento.hxx:95
@ BenErr_ContainerWithNoObjects
Definition: bento.hxx:98
@ BenErr_ReadPastEndOfContainer
Definition: bento.hxx:107
CBenNamedObject * FindNamedObject(CUtList *pList, std::string_view rName, CUtListElmt **ppPrev)
Definition: benlist.cxx:59
sal_uInt32 BenContainerPos
Definition: bento.hxx:134
sal_uInt32 BenObjectID
Definition: bento.hxx:135
constexpr OUStringLiteral aData
int i
long Long
sal_uIntPtr sal_uLong
#define STREAM_SEEK_TO_END
#define STREAM_SEEK_TO_BEGIN
#define SAL_MAX_UINT16