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,
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 ************************************************************************/
59 #include <osl/diagnose.h>
60 #include <sot/storinfo.hxx>
61 namespace OpenStormBento
65 const char gsBenMagicBytes
[] = BEN_MAGIC_BYTES
;
68 * New bento container from file stream
69 * @param pointer to length of bento file
70 * @param pointer to pointer of Bento Container object
73 sal_uLong
BenOpenContainer(LwpSvStream
* pStream
, pLtcBenContainer
* ppContainer
)
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
88 return BenErr_InvalidTOC
;
91 *ppContainer
= pContainer
;
95 LtcBenContainer::~LtcBenContainer()
100 LtcBenContainer::Open() // delete two inputs
103 CBenTOCReader
TOCReader(this);
104 if ((Err
= TOCReader
.ReadLabelAndTOC()) != BenErr_OK
)
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())
123 else *ppPropertyName
= static_cast<pCBenPropertyName
>(pNamedObject
);
127 pCUtListElmt pPrevObject
;
128 if (FindID(&cObjects
, cNextAvailObjectID
, &pPrevObject
) != nullptr)
131 *ppPropertyName
= new CBenPropertyName(this, cNextAvailObjectID
,
132 static_cast<pCBenObject
>(pPrevObject
), sPropertyName
, pPrevNamedObjectListElmt
);
133 ++cNextAvailObjectID
;
138 LtcBenContainer::GetNextObject(pCBenObject pCurrObject
)
140 return static_cast<pCBenObject
>(cObjects
.GetNextOrNULL(pCurrObject
));
144 LtcBenContainer::FindNextObjectWithProperty(pCBenObject pCurrObject
,
145 BenObjectID PropertyID
)
147 while ((pCurrObject
= GetNextObject(pCurrObject
)) != nullptr)
148 if (pCurrObject
->UseProperty(PropertyID
) != nullptr)
156 * @param Bento file stream pointer
159 LtcBenContainer::LtcBenContainer(LwpSvStream
* pStream
)
160 : cNextAvailObjectID(0)
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
172 * @param number of bytes read
175 BenError
LtcBenContainer::Read(void * pBuffer
, unsigned long MaxSize
,
176 unsigned long * pAmtRead
)
178 *pAmtRead
= cpStream
->Read(pBuffer
, MaxSize
);
182 * Read buffer from bento file with specified size
183 * @param buffer pointer
184 * @param number of bytes to be read
187 BenError
LtcBenContainer::ReadKnownSize(void * pBuffer
, unsigned long Amt
)
190 ulLength
= cpStream
->Read(pBuffer
, Amt
);
195 return BenErr_ReadPastEndOfContainer
;
198 * Seek to position from the beginning of the bento file
199 * @param position in container file from beginning
202 BenError
LtcBenContainer::SeekToPosition(BenContainerPos Pos
)
208 * Seek to position compare to end of bento file
209 * @param position in container file from end
212 BenError
LtcBenContainer::SeekFromEnd(long Offset
)
214 cpStream
->Seek(STREAM_SEEK_TO_END
);
215 cpStream
->SeekRel(Offset
);
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
240 LtcUtBenValueStream
* pValueStream
;
242 pValue
= pObj
->UseValue(pPropertyName
->GetID());
244 pValueStream
= new LtcUtBenValueStream(pValue
);
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
);
260 * @param pointer to length of bento file
263 BenError
LtcBenContainer::GetSize(sal_uLong
* pLength
)
265 *pLength
= m_ulLength
;
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
);
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
)
290 // construct the string of property name
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;
308 nDLen
= GetSvStreamSize(pD
);
310 sal_uInt32 nLen
= nDLen
;
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
324 char * pBuf
= new char[nLen
];
325 assert(pBuf
!= nullptr);
326 char * pPointer
= pBuf
;
329 pD
->ReadBytes(pPointer
, nDLen
);
335 pS
->ReadBytes(pPointer
, nLen
- nDLen
);
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: */