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
)
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
!= NULL
)
121 if (! pNamedObject
->IsPropertyName())
122 return BenErr_NameConflict
;
123 else *ppPropertyName
= static_cast<pCBenPropertyName
>(pNamedObject
);
127 pCUtListElmt pPrevObject
;
128 if (FindID(&cObjects
, cNextAvailObjectID
, &pPrevObject
) != NULL
)
129 return BenErr_DuplicateObjectID
;
131 *ppPropertyName
= new CBenPropertyName(this, cNextAvailObjectID
,
132 static_cast<pCBenObject
>(pPrevObject
), sPropertyName
, pPrevNamedObjectListElmt
);
133 ++cNextAvailObjectID
;
140 LtcBenContainer::GetNextObject(pCBenObject pCurrObject
)
142 return static_cast<pCBenObject
>(cObjects
.GetNextOrNULL(pCurrObject
));
146 LtcBenContainer::FindNextObjectWithProperty(pCBenObject pCurrObject
,
147 BenObjectID PropertyID
)
149 while ((pCurrObject
= GetNextObject(pCurrObject
)) != NULL
)
150 if (pCurrObject
->UseProperty(PropertyID
) != NULL
)
158 * @param Bento file stream pointer
161 LtcBenContainer::LtcBenContainer(LwpSvStream
* pStream
)
162 : cNextAvailObjectID(0)
165 pStream
->Seek(STREAM_SEEK_TO_END
);
166 m_ulLength
= pStream
->Tell();
167 pStream
->Seek(STREAM_SEEK_TO_BEGIN
);
171 * Read buffer fro bento file with specified buffer
173 * @param buffer pointer
175 * @param number of bytes read
178 BenError
LtcBenContainer::Read(BenDataPtr pBuffer
, unsigned long MaxSize
,
179 unsigned long * pAmtRead
)
181 *pAmtRead
= cpStream
->Read(pBuffer
, MaxSize
);
185 * Read buffer from bento file with specified size
187 * @param buffer pointer
188 * @param number of bytes to be read
191 BenError
LtcBenContainer::ReadKnownSize(BenDataPtr pBuffer
, unsigned long Amt
)
194 ulLength
= cpStream
->Read(pBuffer
, Amt
);
199 return BenErr_ReadPastEndOfContainer
;
202 * Seek to position from the beginning of the bento file
204 * @param position in container file from beginning
207 BenError
LtcBenContainer::SeekToPosition(BenContainerPos Pos
)
213 * Seek to position compare to end of bento file
215 * @param position in container file from end
218 BenError
LtcBenContainer::SeekFromEnd(long Offset
)
220 cpStream
->Seek(STREAM_SEEK_TO_END
);
221 cpStream
->SeekRel(Offset
);
226 * Find the next value stream with property name
228 * @param string of property name
229 * @param current value stream pointer with the property name
230 * @return next value stream pointer with the property names
232 LtcUtBenValueStream
* LtcBenContainer::FindNextValueStreamWithPropertyName(const char * sPropertyName
, LtcUtBenValueStream
* pCurrentValueStream
)
234 CBenPropertyName
* pPropertyName
;
235 RegisterPropertyName(sPropertyName
, &pPropertyName
); // Get property name object
237 if (NULL
== pPropertyName
)
238 return NULL
; // Property not exist
240 // Get current object
241 CBenObject
* pObj
= NULL
;
242 if (pCurrentValueStream
!= NULL
)
244 pObj
= pCurrentValueStream
->GetValue()->GetProperty()->GetBenObject();
247 pObj
=FindNextObjectWithProperty(pObj
, pPropertyName
->GetID()); // Get next object with same property name
252 LtcUtBenValueStream
* pValueStream
;
254 pValue
= pObj
->UseValue(pPropertyName
->GetID());
256 pValueStream
= new LtcUtBenValueStream(pValue
);
262 * Find the unique value stream with property name
264 * @param string of property name
265 * @return the only value stream pointer with the property names
267 LtcUtBenValueStream
* LtcBenContainer::FindValueStreamWithPropertyName(const char * sPropertyName
)
269 return FindNextValueStreamWithPropertyName(sPropertyName
, NULL
);
274 * @param pointer to length of bento file
277 BenError
LtcBenContainer::GetSize(sal_uLong
* pLength
)
279 *pLength
= m_ulLength
;
283 sal_uInt32
GetSvStreamSize(SvStream
* pStream
)
285 sal_uInt32 nCurPos
= pStream
->Tell();
286 pStream
->Seek(STREAM_SEEK_TO_END
);
287 sal_uInt32 ulLength
= pStream
->Tell();
288 pStream
->Seek(nCurPos
);
294 * Find hazily according to object ID
296 * @param pObjectname - format as "GrXX,XXXXXXXX" wherein XX is high part of object ID, and XXXXXXXX is low part
297 * @return the value stream pointers with the property names
299 BenError
LtcBenContainer::CreateGraphicStream(SvStream
* &pStream
, const char *pObjectName
)
304 return BenErr_NamedObjectError
;
306 // construct the string of property name
310 sprintf(sSName
, "%s-S", pObjectName
);
311 sprintf(sDName
, "%s-D", pObjectName
);
313 /* traverse the found properties and construct the stream vectors */
314 SvMemoryStream
* pMemStream
= NULL
;
315 // get S&D's stream and merge them together
316 SvStream
*pD
= NULL
, *pS
= NULL
;
318 pS
= FindValueStreamWithPropertyName(sSName
);
319 pD
= FindValueStreamWithPropertyName(sDName
);
321 sal_uInt32 nDLen
= 0;
324 nDLen
= GetSvStreamSize(pD
);
326 sal_uInt32 nLen
= nDLen
;
329 nLen
+= GetSvStreamSize(pS
) ;
332 OSL_ENSURE(nLen
> 0, "expected a non-0 length");
333 // the 'D' stream is NULL or it has invalid length
337 return BenErr_NamedObjectError
;
340 char * pBuf
= new char[nLen
];
341 assert(pBuf
!= NULL
);
342 char * pPointer
= pBuf
;
345 pD
->Read(pPointer
, nDLen
);
351 pS
->Read(pPointer
, nLen
- nDLen
);
355 pMemStream
= new SvMemoryStream(pBuf
, nLen
, StreamMode::READ
);
356 assert(pMemStream
!= NULL
);
358 pStream
= pMemStream
;
362 }// end namespace OpenStormBento
364 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */