Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
5 : : * This Source Code Form is subject to the terms of the Mozilla Public
6 : : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
11 : : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : : * contributor license agreements. See the NOTICE file distributed
13 : : * with this work for additional information regarding copyright
14 : : * ownership. The ASF licenses this file to you under the Apache
15 : : * License, Version 2.0 (the "License"); you may not use this file
16 : : * except in compliance with the License. You may obtain a copy of
17 : : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : : */
19 : :
20 : : #include <com/sun/star/uno/Sequence.hxx>
21 : : #include <com/sun/star/lang/XSingleServiceFactory.hpp>
22 : : #include <com/sun/star/embed/XStorage.hpp>
23 : : #include <com/sun/star/embed/ElementModes.hpp>
24 : : #include <com/sun/star/beans/XPropertySet.hpp>
25 : :
26 : : #include <rtl/digest.h>
27 : : #include <osl/file.hxx>
28 : : #include <sot/stg.hxx>
29 : : #include <sot/storinfo.hxx>
30 : : #include <sot/storage.hxx>
31 : : #include <sot/formats.hxx>
32 : : #include <sot/exchange.hxx>
33 : : #include <unotools/ucbstreamhelper.hxx>
34 : : #include <tools/fsys.hxx>
35 : : #include <tools/cachestr.hxx>
36 : : #include <tools/debug.hxx>
37 : : #include <tools/urlobj.hxx>
38 : : #include <unotools/localfilehelper.hxx>
39 : : #include <unotools/ucbhelper.hxx>
40 : : #include <comphelper/processfactory.hxx>
41 : :
42 : : using namespace ::com::sun::star;
43 : :
44 : : /************** class SotStorageStream ***********************************/
45 [ # # ]: 0 : class SotStorageStreamFactory : public SotFactory
46 : : {
47 : : public:
48 : : TYPEINFO();
49 : 0 : SotStorageStreamFactory( const SvGlobalName & rName,
50 : : const String & rClassName,
51 : : CreateInstanceType pCreateFuncP )
52 : 0 : : SotFactory( rName, rClassName, pCreateFuncP )
53 : 0 : {}
54 : : };
55 [ # # ][ # # ]: 0 : TYPEINIT1(SotStorageStreamFactory,SotFactory);
56 : :
57 : :
58 [ # # ][ # # ]: 0 : SO2_IMPL_BASIC_CLASS1_DLL(SotStorageStream,SotStorageStreamFactory,SotObject,
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
59 : : SvGlobalName( 0xd7deb420, 0xf902, 0x11d0,
60 : : 0xaa, 0xa1, 0x0, 0xa0, 0x24, 0x9d, 0x55, 0x90 ) )
61 : :
62 : : /************************************************************************
63 : : |* SotStorageStream::SotStorageStream()
64 : : |*
65 : : |* Beschreibung
66 : : *************************************************************************/
67 : 0 : SvLockBytesRef MakeLockBytes_Impl( const String & rName, StreamMode nMode )
68 : : {
69 : 0 : SvLockBytesRef xLB;
70 [ # # ]: 0 : if( rName.Len() )
71 : : {
72 [ # # ][ # # ]: 0 : SvStream * pFileStm = new SvFileStream( rName, nMode );
73 [ # # ][ # # ]: 0 : xLB = new SvLockBytes( pFileStm, sal_True );
[ # # ]
74 : : }
75 : : else
76 : : {
77 [ # # ][ # # ]: 0 : SvStream * pCacheStm = new SvCacheStream();
78 [ # # ][ # # ]: 0 : xLB = new SvLockBytes( pCacheStm, sal_True );
[ # # ]
79 : : }
80 : 0 : return xLB;
81 : : }
82 : :
83 : 0 : SotStorageStream::SotStorageStream( const String & rName, StreamMode nMode,
84 : : StorageMode
85 : : #ifdef DBG_UTIL
86 : : nStorageMode
87 : : #endif
88 : : )
89 : : : SvStream( MakeLockBytes_Impl( rName, nMode ) )
90 [ # # ][ # # ]: 0 : , pOwnStm( NULL )
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
91 : : {
92 [ # # ][ # # ]: 0 : if( nMode & STREAM_WRITE )
93 : 0 : bIsWritable = sal_True;
94 : : else
95 : 0 : bIsWritable = sal_False;
96 : :
97 : : DBG_ASSERT( !nStorageMode,"StorageModes ignored" );
98 : 0 : }
99 : :
100 [ + - ][ + - ]: 1206 : SotStorageStream::SotStorageStream( BaseStorageStream * pStm )
[ # # ]
101 : : {
102 [ + - ][ # # ]: 1206 : if( pStm )
103 : : {
104 [ + + ][ # # ]: 1206 : if( STREAM_WRITE & pStm->GetMode() )
105 : 381 : bIsWritable = sal_True;
106 : : else
107 : 825 : bIsWritable = sal_False;
108 : :
109 : 1206 : pOwnStm = pStm;
110 [ + - ][ + - ]: 1206 : SetError( pStm->GetError() );
[ # # ][ # # ]
111 [ + - ][ # # ]: 1206 : pStm->ResetError();
112 : : }
113 : : else
114 : : {
115 : 0 : pOwnStm = NULL;
116 : 0 : bIsWritable = sal_True;
117 [ # # ][ # # ]: 0 : SetError( SVSTREAM_INVALID_PARAMETER );
118 : : }
119 : 1206 : }
120 : :
121 : 0 : SotStorageStream::SotStorageStream()
122 [ # # ][ # # ]: 0 : : pOwnStm( NULL )
[ # # ]
123 : : {
124 : : // ??? wenn Init virtuell ist, entsprechen setzen
125 : 0 : bIsWritable = sal_True;
126 : 0 : }
127 : :
128 : : /************************************************************************
129 : : |* SotStorageStream::~SotStorageStream()
130 : : |*
131 : : |* Beschreibung
132 : : *************************************************************************/
133 [ + - ][ + - ]: 3618 : SotStorageStream::~SotStorageStream()
[ # # ][ # # ]
134 : : {
135 [ + - ][ # # ]: 1206 : Flush(); //SetBufferSize(0);
136 [ + - ][ + - ]: 1206 : delete pOwnStm;
[ # # ][ # # ]
137 [ + - ][ + - ]: 4824 : }
[ - + ]
[ # # # # ]
[ # # ][ # # ]
[ # # ]
[ # # # # ]
138 : :
139 : : /*************************************************************************
140 : : |* SotStorageStream::ResetError()
141 : : |*
142 : : |* Beschreibung
143 : : *************************************************************************/
144 : 0 : void SotStorageStream::ResetError()
145 : : {
146 : 0 : SvStream::ResetError();
147 [ # # ]: 0 : if( pOwnStm )
148 : 0 : pOwnStm->ResetError();
149 : 0 : }
150 : :
151 : : /*************************************************************************
152 : : |* SotStorageStream::GetData()
153 : : |*
154 : : |* Beschreibung
155 : : *************************************************************************/
156 : 2242727 : sal_uLong SotStorageStream::GetData( void* pData, sal_uLong nSize )
157 : : {
158 : 2242727 : sal_uLong nRet = 0;
159 : :
160 [ + - ]: 2242727 : if( pOwnStm )
161 : : {
162 : 2242727 : nRet = pOwnStm->Read( pData, nSize );
163 : 2242727 : SetError( pOwnStm->GetError() );
164 : : }
165 : : else
166 : 0 : nRet = SvStream::GetData( (sal_Char *)pData, nSize );
167 : 2242727 : return nRet;
168 : : }
169 : :
170 : : /*************************************************************************
171 : : |* SotStorageStream::PutData()
172 : : |*
173 : : |* Beschreibung
174 : : *************************************************************************/
175 : 1053 : sal_uLong SotStorageStream::PutData( const void* pData, sal_uLong nSize )
176 : : {
177 : 1053 : sal_uLong nRet = 0;
178 : :
179 [ + - ]: 1053 : if( pOwnStm )
180 : : {
181 : 1053 : nRet = pOwnStm->Write( pData, nSize );
182 : 1053 : SetError( pOwnStm->GetError() );
183 : : }
184 : : else
185 : 0 : nRet = SvStream::PutData( (sal_Char *)pData, nSize );
186 : 1053 : return nRet;
187 : : }
188 : :
189 : : /*************************************************************************
190 : : |* SotStorageStream::SeekPos()
191 : : |*
192 : : |* Beschreibung
193 : : *************************************************************************/
194 : 1984558 : sal_uLong SotStorageStream::SeekPos( sal_uLong nPos )
195 : : {
196 : 1984558 : sal_uLong nRet = 0;
197 : :
198 [ + - ]: 1984558 : if( pOwnStm )
199 : : {
200 : 1984558 : nRet = pOwnStm->Seek( nPos );
201 : 1984558 : SetError( pOwnStm->GetError() );
202 : : }
203 : : else
204 : 0 : nRet = SvStream::SeekPos( nPos );
205 : 1984558 : return nRet;
206 : : }
207 : :
208 : : /*************************************************************************
209 : : |* SotStorageStream::Flush()
210 : : |*
211 : : |* Beschreibung
212 : : *************************************************************************/
213 : 408 : void SotStorageStream::FlushData()
214 : : {
215 [ + - ]: 408 : if( pOwnStm )
216 : : {
217 : 408 : pOwnStm->Flush();
218 : 408 : SetError( pOwnStm->GetError() );
219 : : }
220 : : else
221 : 0 : SvStream::FlushData();
222 : 408 : }
223 : :
224 : : /*************************************************************************
225 : : |* SotStorageStream::SetSize()
226 : : |*
227 : : |* Beschreibung
228 : : *************************************************************************/
229 : 18 : void SotStorageStream::SetSize( sal_uLong nNewSize )
230 : : {
231 : 18 : sal_uLong nPos = Tell();
232 [ + - ]: 18 : if( pOwnStm )
233 : : {
234 : 18 : pOwnStm->SetSize( nNewSize );
235 : 18 : SetError( pOwnStm->GetError() );
236 : : }
237 : : else
238 : 0 : SvStream::SetSize( nNewSize );
239 : :
240 [ - + ]: 18 : if( nNewSize < nPos )
241 : : // ans Ende setzen
242 : 0 : Seek( nNewSize );
243 : :
244 : : //return GetError() == SVSTREAM_OK;
245 : 18 : }
246 : :
247 : : /*************************************************************************
248 : : |*
249 : : |* SotStorageStream::GetSize()
250 : : |*
251 : : |* Beschreibung
252 : : |*
253 : : *************************************************************************/
254 : 150 : sal_uInt32 SotStorageStream::GetSize() const
255 : : {
256 : 150 : sal_uLong nPos = Tell();
257 : 150 : ((SotStorageStream *)this)->Seek( STREAM_SEEK_TO_END );
258 : 150 : sal_uLong nSize = Tell();
259 : 150 : ((SotStorageStream *)this)->Seek( nPos );
260 : 150 : return nSize;
261 : : }
262 : :
263 : 15273 : sal_Size SotStorageStream::remainingSize()
264 : : {
265 [ + - ]: 15273 : if (pOwnStm)
266 : 15273 : return pOwnStm->GetSize() - Tell();
267 : 15273 : return SvStream::remainingSize();
268 : : }
269 : :
270 : : /*************************************************************************
271 : : |* SotStorageStream::CopyTo()
272 : : |*
273 : : |* Beschreibung
274 : : *************************************************************************/
275 : 0 : sal_Bool SotStorageStream::CopyTo( SotStorageStream * pDestStm )
276 : : {
277 : 0 : Flush(); // alle Daten schreiben
278 : 0 : pDestStm->ClearBuffer();
279 [ # # ][ # # ]: 0 : if( !pOwnStm || !pDestStm->pOwnStm )
280 : : { // Wenn Ole2 oder nicht nur eigene StorageStreams
281 : :
282 : 0 : sal_uLong nPos = Tell(); // Position merken
283 : 0 : Seek( 0L );
284 : 0 : pDestStm->SetSize( 0 ); // Ziel-Stream leeren
285 : :
286 : 0 : void * pMem = new sal_uInt8[ 8192 ];
287 : : sal_uLong nRead;
288 [ # # ]: 0 : while( 0 != (nRead = Read( pMem, 8192 )) )
289 : : {
290 [ # # ]: 0 : if( nRead != pDestStm->Write( pMem, nRead ) )
291 : : {
292 : 0 : SetError( SVSTREAM_GENERALERROR );
293 : 0 : break;
294 : : }
295 : : }
296 [ # # ]: 0 : delete [] static_cast<sal_uInt8*>(pMem);
297 : : // Position setzen
298 : 0 : pDestStm->Seek( nPos );
299 : 0 : Seek( nPos );
300 : : }
301 : : else
302 : : {
303 : : /*
304 : : // Kopieren
305 : : nErr = pObjI->CopyTo( pDestStm->pObjI, uSize, NULL, &uWrite );
306 : : if( SUCCEEDED( nErr ) )
307 : : {
308 : : // Ziel-Streamzeiger steht hinter den Daten
309 : : // SvSeek abgleichen
310 : : pDestStm->Seek( uWrite.LowPart );
311 : : }
312 : : else if( GetScode( nErr ) == E_NOTIMPL )
313 : : { // Eines Tages werden alle MS... ?!#
314 : : */
315 : 0 : pOwnStm->CopyTo( pDestStm->pOwnStm );
316 : 0 : SetError( pOwnStm->GetError() );
317 : : }
318 : 0 : return GetError() == SVSTREAM_OK;
319 : : }
320 : :
321 : : /*************************************************************************
322 : : |* SotStorageStream::Commit()
323 : : |* SotStorageStream::Revert()
324 : : |*
325 : : |* Beschreibung
326 : : *************************************************************************/
327 : 0 : sal_Bool SotStorageStream::Commit()
328 : : {
329 [ # # ]: 0 : if( pOwnStm )
330 : : {
331 : 0 : pOwnStm->Flush();
332 [ # # ]: 0 : if( pOwnStm->GetError() == SVSTREAM_OK )
333 : 0 : pOwnStm->Commit();
334 : 0 : SetError( pOwnStm->GetError() );
335 : : }
336 : 0 : return GetError() == SVSTREAM_OK;
337 : : }
338 : :
339 : 0 : sal_Bool SotStorageStream::Revert()
340 : : {
341 [ # # ]: 0 : if( !pOwnStm )
342 : : {
343 : 0 : pOwnStm->Revert();
344 : 0 : SetError( pOwnStm->GetError() );
345 : : }
346 : 0 : return GetError() == SVSTREAM_OK;
347 : : }
348 : :
349 : 0 : sal_Bool SotStorageStream::SetProperty( const String& rName, const ::com::sun::star::uno::Any& rValue )
350 : : {
351 [ # # ][ # # ]: 0 : UCBStorageStream* pStg = PTR_CAST( UCBStorageStream, pOwnStm );
352 [ # # ]: 0 : if ( pStg )
353 : : {
354 : 0 : return pStg->SetProperty( rName, rValue );
355 : : }
356 : : else
357 : : {
358 : : OSL_FAIL("Not implemented!");
359 : 0 : return sal_False;
360 : : }
361 : : }
362 : :
363 : 0 : sal_Bool SotStorageStream::GetProperty( const String& rName, ::com::sun::star::uno::Any& rValue )
364 : : {
365 [ # # ][ # # ]: 0 : UCBStorageStream* pStg = PTR_CAST( UCBStorageStream, pOwnStm );
366 [ # # ]: 0 : if ( pStg )
367 : : {
368 : 0 : return pStg->GetProperty( rName, rValue );
369 : : }
370 : : else
371 : : {
372 : : OSL_FAIL("Not implemented!");
373 : 0 : return sal_False;
374 : : }
375 : : }
376 : :
377 : 0 : ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SotStorageStream::GetXInputStream() const
378 : : {
379 [ # # ][ # # ]: 0 : UCBStorageStream* pStg = PTR_CAST( UCBStorageStream, pOwnStm );
380 [ # # ]: 0 : if ( pStg )
381 : : {
382 : 0 : return pStg->GetXInputStream();
383 : : }
384 : : else
385 : : {
386 : : OSL_FAIL("Not implemented!");
387 : 0 : return ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >();
388 : : }
389 : : }
390 : :
391 : :
392 : :
393 : : /************** class SotStorage ******************************************
394 : : *************************************************************************/
395 [ # # ]: 0 : class SotStorageFactory : public SotFactory
396 : : {
397 : : public:
398 : : TYPEINFO();
399 : 0 : SotStorageFactory( const SvGlobalName & rName,
400 : : const String & rClassName,
401 : : CreateInstanceType pCreateFuncP )
402 : 0 : : SotFactory( rName, rClassName, pCreateFuncP )
403 : 0 : {}
404 : : };
405 [ # # ][ # # ]: 0 : TYPEINIT1(SotStorageFactory,SotFactory);
406 : :
407 : :
408 [ # # ][ # # ]: 0 : SO2_IMPL_BASIC_CLASS1_DLL(SotStorage,SotStorageFactory,SotObject,
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
409 : : SvGlobalName( 0x980ce7e0, 0xf905, 0x11d0,
410 : : 0xaa, 0xa1, 0x0, 0xa0, 0x24, 0x9d, 0x55, 0x90 ) )
411 : :
412 : : /************************************************************************
413 : : |*
414 : : |* SotStorage::SotStorage()
415 : : |*
416 : : |* Beschreibung Es muss ein I... Objekt an SvObject uebergeben
417 : : |* werden, da es sonst selbst ein IUnknown anlegt und
418 : : |* festlegt, dass alle weiteren I... Objekte mit
419 : : |* delete zerstoert werden (Owner() == sal_True).
420 : : |* Es werden aber nur IStorage Objekte benutzt und nicht
421 : : |* selbst implementiert, deshalb wird so getan, als ob
422 : : |* das IStorage Objekt von aussen kam und es wird mit
423 : : |* Release() freigegeben.
424 : : |* Die CreateStorage Methoden werden benoetigt, um
425 : : |* ein IStorage Objekt vor dem Aufruf von SvObject
426 : : |* zu erzeugen (Own, !Own automatik).
427 : : |* Hat CreateStorage ein Objekt erzeugt, dann wurde
428 : : |* der RefCounter schon um 1 erhoet.
429 : : |* Die Uebergabe erfolgt in pStorageCTor. Die Variable
430 : : |* ist NULL, wenn es nicht geklappt hat.
431 : : |*
432 : : *************************************************************************/
433 : : #define INIT_SotStorage() \
434 : : : m_pOwnStg( NULL ) \
435 : : , m_pStorStm( NULL ) \
436 : : , m_nError( SVSTREAM_OK ) \
437 : : , m_bIsRoot( sal_False ) \
438 : : , m_bDelStm( sal_False ) \
439 : : , m_nVersion( SOFFICE_FILEFORMAT_CURRENT )
440 : :
441 : 0 : SotStorage::SotStorage()
442 [ # # ][ # # ]: 0 : INIT_SotStorage()
[ # # ]
443 : : {
444 : : // ??? What's this ???
445 : 0 : }
446 : :
447 : : #define ERASEMASK ( STREAM_TRUNC | STREAM_WRITE | STREAM_SHARE_DENYALL )
448 : : #include <com/sun/star/uno/Reference.h>
449 : : #include <com/sun/star/ucb/XCommandEnvironment.hpp>
450 : : #include <ucbhelper/content.hxx>
451 : :
452 : 65 : SotStorage::SotStorage( const String & rName, StreamMode nMode, StorageMode nStorageMode )
453 [ + - ][ + - ]: 65 : INIT_SotStorage()
[ # # ]
454 : : {
455 [ + - # # ]: 65 : m_aName = rName; // Namen merken
456 [ + - ][ # # ]: 65 : CreateStorage( sal_True, nMode, nStorageMode );
457 [ + - ][ - + ]: 65 : if ( IsOLEStorage() )
[ # # ][ # # ]
458 : 0 : m_nVersion = SOFFICE_FILEFORMAT_50;
459 : 65 : }
460 : :
461 : 65 : void SotStorage::CreateStorage( sal_Bool bForceUCBStorage, StreamMode nMode, StorageMode nStorageMode )
462 : : {
463 : : DBG_ASSERT( !m_pStorStm && !m_pOwnStg, "Use only in ctor!" );
464 [ - + ]: 65 : if( m_aName.Len() )
465 : : {
466 : : // named storage
467 [ # # ]: 0 : if( ( ( nMode & ERASEMASK ) == ERASEMASK ) )
468 [ # # ][ # # ]: 0 : ::utl::UCBContentHelper::Kill( m_aName );
469 : :
470 [ # # ][ # # ]: 0 : INetURLObject aObj( m_aName );
471 [ # # ]: 0 : if ( aObj.GetProtocol() == INET_PROT_NOT_VALID )
472 : : {
473 : 0 : rtl::OUString aURL;
474 [ # # ][ # # ]: 0 : ::utl::LocalFileHelper::ConvertPhysicalNameToURL( m_aName, aURL );
475 [ # # ]: 0 : aObj.SetURL( aURL );
476 [ # # ][ # # ]: 0 : m_aName = aObj.GetMainURL( INetURLObject::NO_DECODE );
477 : : }
478 : :
479 : : // a new unpacked storage should be created
480 [ # # ]: 0 : if ( nStorageMode == STORAGE_CREATE_UNPACKED )
481 : : {
482 : : // don't open stream readwrite, content provider may not support this !
483 [ # # ]: 0 : String aURL = UCBStorage::CreateLinkFile( m_aName );
484 [ # # ]: 0 : if ( aURL.Len() )
485 : : {
486 [ # # ][ # # ]: 0 : ::ucbhelper::Content aContent( aURL, ::com::sun::star::uno::Reference < ::com::sun::star::ucb::XCommandEnvironment >() );
487 [ # # ][ # # ]: 0 : m_pOwnStg = new UCBStorage( aContent, aURL, nMode, sal_False );
[ # # ]
488 : : }
489 : : else
490 : : {
491 [ # # ][ # # ]: 0 : m_pOwnStg = new Storage( m_aName, nMode, (nStorageMode & STORAGE_TRANSACTED) ? sal_False : sal_True );
492 : 0 : SetError( ERRCODE_IO_NOTSUPPORTED );
493 [ # # ]: 0 : }
494 : : }
495 : : else
496 : : {
497 : : // check the stream
498 [ # # ]: 0 : m_pStorStm = ::utl::UcbStreamHelper::CreateStream( m_aName, nMode );
499 [ # # ][ # # ]: 0 : if ( m_pStorStm && m_pStorStm->GetError() )
[ # # ]
500 [ # # ][ # # ]: 0 : DELETEZ( m_pStorStm );
501 : :
502 [ # # ]: 0 : if ( m_pStorStm )
503 : : {
504 : : // try as UCBStorage, next try as OLEStorage
505 [ # # ]: 0 : sal_Bool bIsUCBStorage = UCBStorage::IsStorageFile( m_pStorStm );
506 [ # # ][ # # ]: 0 : if ( !bIsUCBStorage && bForceUCBStorage )
507 : : // if UCBStorage has priority, it should not be used only if it is really an OLEStorage
508 [ # # ]: 0 : bIsUCBStorage = !Storage::IsStorageFile( m_pStorStm );
509 : :
510 [ # # ]: 0 : if ( bIsUCBStorage )
511 : : {
512 [ # # ][ # # ]: 0 : if ( UCBStorage::GetLinkedFile( *m_pStorStm ).Len() )
[ # # ]
513 : : {
514 : : // detect special unpacked storages
515 [ # # ][ # # ]: 0 : m_pOwnStg = new UCBStorage( *m_pStorStm, (nStorageMode & STORAGE_TRANSACTED) ? sal_False : sal_True );
516 : 0 : m_bDelStm = sal_True;
517 : : }
518 : : else
519 : : {
520 : : // detect special disk spanned storages
521 [ # # ][ # # ]: 0 : if ( UCBStorage::IsDiskSpannedFile( m_pStorStm ) )
522 : 0 : nMode |= STORAGE_DISKSPANNED_MODE;
523 : :
524 : : // UCBStorage always works directly on the UCB content, so discard the stream first
525 [ # # ][ # # ]: 0 : DELETEZ( m_pStorStm );
526 [ # # ][ # # ]: 0 : m_pOwnStg = new UCBStorage( m_aName, nMode, (nStorageMode & STORAGE_TRANSACTED) ? sal_False : sal_True );
527 : : }
528 : : }
529 : : else
530 : : {
531 : : // OLEStorage can be opened with a stream
532 [ # # ][ # # ]: 0 : m_pOwnStg = new Storage( *m_pStorStm, (nStorageMode & STORAGE_TRANSACTED) ? sal_False : sal_True );
533 : 0 : m_bDelStm = sal_True;
534 : : }
535 : : }
536 [ # # ]: 0 : else if ( bForceUCBStorage )
537 : : {
538 [ # # ][ # # ]: 0 : m_pOwnStg = new UCBStorage( m_aName, nMode, (nStorageMode & STORAGE_TRANSACTED) ? sal_False : sal_True );
539 : 0 : SetError( ERRCODE_IO_NOTSUPPORTED );
540 : : }
541 : : else
542 : : {
543 [ # # ][ # # ]: 0 : m_pOwnStg = new Storage( m_aName, nMode, (nStorageMode & STORAGE_TRANSACTED) ? sal_False : sal_True );
544 : 0 : SetError( ERRCODE_IO_NOTSUPPORTED );
545 : : }
546 [ # # ]: 0 : }
547 : : }
548 : : else
549 : : {
550 : : // temporary storage
551 [ + - ]: 65 : if ( bForceUCBStorage )
552 [ + - ]: 65 : m_pOwnStg = new UCBStorage( m_aName, nMode, (nStorageMode & STORAGE_TRANSACTED) ? sal_False : sal_True );
553 : : else
554 [ # # ]: 0 : m_pOwnStg = new Storage( m_aName, nMode, (nStorageMode & STORAGE_TRANSACTED) ? sal_False : sal_True );
555 : 65 : m_aName = m_pOwnStg->GetName();
556 : : }
557 : :
558 : 65 : SetError( m_pOwnStg->GetError() );
559 : :
560 : 65 : SignAsRoot( m_pOwnStg->IsRoot() );
561 : 65 : }
562 : :
563 : 0 : SotStorage::SotStorage( sal_Bool bUCBStorage, const String & rName, StreamMode nMode, StorageMode nStorageMode )
564 [ # # ][ # # ]: 0 : INIT_SotStorage()
[ # # ]
565 : : {
566 [ # # # # ]: 0 : m_aName = rName;
567 [ # # ][ # # ]: 0 : CreateStorage( bUCBStorage, nMode, nStorageMode );
568 [ # # ][ # # ]: 0 : if ( IsOLEStorage() )
[ # # ][ # # ]
569 : 0 : m_nVersion = SOFFICE_FILEFORMAT_50;
570 : 0 : }
571 : :
572 : 54 : SotStorage::SotStorage( BaseStorage * pStor )
573 [ + - ][ + - ]: 54 : INIT_SotStorage()
[ # # ]
574 : : {
575 [ + - # # ]: 54 : if ( pStor )
576 : : {
577 [ + - ][ + - ]: 54 : m_aName = pStor->GetName(); // Namen merken
[ # # ][ # # ]
578 [ + - ][ # # ]: 54 : SignAsRoot( pStor->IsRoot() );
579 [ # # ][ + - ]: 54 : SetError( pStor->GetError() );
580 : : }
581 : :
582 : 54 : m_pOwnStg = pStor;
583 [ + - ][ + - ]: 54 : sal_uLong nErr = m_pOwnStg ? m_pOwnStg->GetError() : SVSTREAM_CANNOT_MAKE;
[ # # ][ # # ]
584 : 54 : SetError( nErr );
585 [ + - # # ]: 54 : if ( IsOLEStorage() )
[ # # ][ + - ]
586 : 54 : m_nVersion = SOFFICE_FILEFORMAT_50;
587 : 54 : }
588 : :
589 : 0 : SotStorage::SotStorage( sal_Bool bUCBStorage, SvStream & rStm )
590 [ # # ][ # # ]: 0 : INIT_SotStorage()
[ # # ]
591 : : {
592 : 0 : SetError( rStm.GetError() );
593 : :
594 : : // try as UCBStorage, next try as OLEStorage
595 [ # # ][ # # ]: 0 : if ( UCBStorage::IsStorageFile( &rStm ) || bUCBStorage )
[ # # # # ]
[ # # ][ # # ]
[ # # ][ # # ]
596 [ # # ][ # # ]: 0 : m_pOwnStg = new UCBStorage( rStm, sal_False );
[ # # ][ # # ]
597 : : else
598 [ # # ][ # # ]: 0 : m_pOwnStg = new Storage( rStm, sal_False );
[ # # ][ # # ]
599 : :
600 [ # # ][ # # ]: 0 : SetError( m_pOwnStg->GetError() );
601 : :
602 [ # # # # ]: 0 : if ( IsOLEStorage() )
[ # # ][ # # ]
603 : 0 : m_nVersion = SOFFICE_FILEFORMAT_50;
604 : :
605 [ # # ][ # # ]: 0 : SignAsRoot( m_pOwnStg->IsRoot() );
606 : 0 : }
607 : :
608 : 123 : SotStorage::SotStorage( SvStream & rStm )
609 [ + - ][ + - ]: 123 : INIT_SotStorage()
[ # # ]
610 : : {
611 : 123 : SetError( rStm.GetError() );
612 : :
613 : : // try as UCBStorage, next try as OLEStorage
614 [ - + # # ]: 123 : if ( UCBStorage::IsStorageFile( &rStm ) )
[ # # ][ + - ]
615 [ # # ][ # # ]: 0 : m_pOwnStg = new UCBStorage( rStm, sal_False );
[ # # ][ # # ]
616 : : else
617 [ + - ][ + - ]: 123 : m_pOwnStg = new Storage( rStm, sal_False );
[ # # ][ # # ]
618 : :
619 [ + - ][ # # ]: 123 : SetError( m_pOwnStg->GetError() );
620 : :
621 [ + - # # ]: 123 : if ( IsOLEStorage() )
[ # # ][ + - ]
622 : 123 : m_nVersion = SOFFICE_FILEFORMAT_50;
623 : :
624 [ + - ][ # # ]: 123 : SignAsRoot( m_pOwnStg->IsRoot() );
625 : 123 : }
626 : :
627 : 122 : SotStorage::SotStorage( SvStream * pStm, sal_Bool bDelete )
628 [ + - ][ + - ]: 122 : INIT_SotStorage()
[ # # ]
629 : : {
630 : 122 : SetError( pStm->GetError() );
631 : :
632 : : // try as UCBStorage, next try as OLEStorage
633 [ - + # # ]: 122 : if ( UCBStorage::IsStorageFile( pStm ) )
[ # # ][ + - ]
634 [ # # ][ # # ]: 0 : m_pOwnStg = new UCBStorage( *pStm, sal_False );
[ # # ][ # # ]
635 : : else
636 [ + - ][ + - ]: 122 : m_pOwnStg = new Storage( *pStm, sal_False );
[ # # ][ # # ]
637 : :
638 [ + - ][ # # ]: 122 : SetError( m_pOwnStg->GetError() );
639 : :
640 : 122 : m_pStorStm = pStm;
641 : 122 : m_bDelStm = bDelete;
642 [ + - # # ]: 122 : if ( IsOLEStorage() )
[ # # ][ + - ]
643 : 122 : m_nVersion = SOFFICE_FILEFORMAT_50;
644 : :
645 [ + - ][ # # ]: 122 : SignAsRoot( m_pOwnStg->IsRoot() );
646 : 122 : }
647 : :
648 : : /*************************************************************************
649 : : |* SotStorage::~SotStorage()
650 : : |*
651 : : |* Beschreibung
652 : : *************************************************************************/
653 [ + - ][ + - ]: 1074 : SotStorage::~SotStorage()
[ # # ][ # # ]
654 : : {
655 [ + - ][ + - ]: 358 : delete m_pOwnStg;
[ # # ][ # # ]
656 [ + + ][ # # ]: 358 : if( m_bDelStm )
657 [ + - ][ + - ]: 9 : delete m_pStorStm;
[ # # ][ # # ]
658 [ + - ][ + - ]: 1432 : }
[ - + ]
[ # # # # ]
[ # # ][ # # ]
[ # # ]
[ # # # # ]
659 : :
660 : : /*************************************************************************
661 : : |* SotStorage::CreateMemoryStream()
662 : : |*
663 : : |* Beschreibung
664 : : *************************************************************************/
665 : 0 : SvMemoryStream * SotStorage::CreateMemoryStream()
666 : : {
667 : 0 : SvMemoryStream * pStm = NULL;
668 [ # # ][ # # ]: 0 : pStm = new SvMemoryStream( 0x8000, 0x8000 );
669 [ # # ][ # # ]: 0 : SotStorageRef aStg = new SotStorage( *pStm );
670 [ # # ][ # # ]: 0 : if( CopyTo( aStg ) )
671 [ # # ]: 0 : aStg->Commit();
672 : : else
673 : : {
674 [ # # ]: 0 : aStg.Clear(); // Storage vorher freigeben
675 [ # # ][ # # ]: 0 : delete pStm;
676 : 0 : pStm = NULL;
677 : : }
678 [ # # ]: 0 : return pStm;
679 : : }
680 : :
681 : : /*************************************************************************
682 : : |* SotStorage::GetStorage()
683 : : |*
684 : : |* Beschreibung
685 : : *************************************************************************/
686 : 14 : sal_Bool SotStorage::IsStorageFile( const String & rFileName )
687 : : {
688 [ + - ]: 14 : String aName( rFileName );
689 [ + - ][ + - ]: 14 : INetURLObject aObj( aName );
690 [ - + ]: 14 : if ( aObj.GetProtocol() == INET_PROT_NOT_VALID )
691 : : {
692 : 0 : rtl::OUString aURL;
693 [ # # ][ # # ]: 0 : ::utl::LocalFileHelper::ConvertPhysicalNameToURL( aName, aURL );
694 [ # # ]: 0 : aObj.SetURL( aURL );
695 [ # # ][ # # ]: 0 : aName = aObj.GetMainURL( INetURLObject::NO_DECODE );
696 : : }
697 : :
698 [ + - ]: 14 : SvStream * pStm = ::utl::UcbStreamHelper::CreateStream( aName, STREAM_STD_READ );
699 [ + - ]: 14 : sal_Bool bRet = SotStorage::IsStorageFile( pStm );
700 [ + - ][ + - ]: 14 : delete pStm;
701 [ + - ][ + - ]: 14 : return bRet;
702 : : }
703 : :
704 : 1415 : sal_Bool SotStorage::IsStorageFile( SvStream* pStream )
705 : : {
706 : : /** code for new storages must come first! **/
707 [ + - ]: 1415 : if ( pStream )
708 : : {
709 : 1415 : long nPos = pStream->Tell();
710 : 1415 : sal_Bool bRet = UCBStorage::IsStorageFile( pStream );
711 [ + + ]: 1415 : if ( !bRet )
712 : 1259 : bRet = Storage::IsStorageFile( pStream );
713 : 1415 : pStream->Seek( nPos );
714 : 1415 : return bRet;
715 : : }
716 : : else
717 : 1415 : return sal_False;
718 : : }
719 : : /*************************************************************************
720 : : |* SotStorage::GetStorage()
721 : : |*
722 : : |* Beschreibung
723 : : *************************************************************************/
724 : 65 : const String & SotStorage::GetName() const
725 : : {
726 [ - + ]: 65 : if( !m_aName.Len() )
727 : : {
728 : : DBG_ASSERT( Owner(), "must be owner" );
729 [ # # ]: 0 : if( m_pOwnStg )
730 : 0 : ((SotStorage *)this)->m_aName = m_pOwnStg->GetName();
731 : : }
732 : 65 : return m_aName;
733 : : }
734 : :
735 : 0 : void SotStorage::SetName( const String& rName )
736 : : {
737 : : // This method is necessary because most storages will not be opened with a FileName, but an external stream instead
738 : : // This stream is a stream opened by a UCP and so aName is only used as a transport for all client code of the SotStorage
739 : : // class that depends on the fact that a root storage has a name
740 : : DBG_ASSERT( !GetName().Len(), "SetName() must not be called when the storage already has a name!" );
741 : 0 : m_aName = rName;
742 : 0 : }
743 : :
744 : : /*************************************************************************
745 : : |* SotStorage::ResetError()
746 : : |*
747 : : |* Beschreibung
748 : : *************************************************************************/
749 : 0 : void SotStorage::ResetError()
750 : : {
751 : 0 : m_nError = SVSTREAM_OK;
752 [ # # ]: 0 : if( m_pOwnStg )
753 : 0 : m_pOwnStg->ResetError();
754 : 0 : }
755 : :
756 : : /*************************************************************************
757 : : |* SotStorage::SetClass()
758 : : |* SotStorage::SetConvertClass()
759 : : |*
760 : : |* Beschreibung
761 : : *************************************************************************/
762 : 12 : void SotStorage::SetClass( const SvGlobalName & rName,
763 : : sal_uLong nOriginalClipFormat,
764 : : const String & rUserTypeName )
765 : : {
766 : : DBG_ASSERT( Owner(), "must be owner" );
767 [ + - ]: 12 : if( m_pOwnStg )
768 : 12 : m_pOwnStg->SetClass( rName, nOriginalClipFormat, rUserTypeName );
769 : : else
770 : 0 : SetError( SVSTREAM_GENERALERROR );
771 : 12 : }
772 : :
773 : 0 : void SotStorage::SetConvertClass( const SvGlobalName & rName,
774 : : sal_uLong nOriginalClipFormat,
775 : : const String & rUserTypeName )
776 : : {
777 : : DBG_ASSERT( Owner(), "must be owner" );
778 [ # # ]: 0 : if( m_pOwnStg )
779 : 0 : m_pOwnStg->SetConvertClass( rName, nOriginalClipFormat, rUserTypeName );
780 : : else
781 : 0 : SetError( SVSTREAM_GENERALERROR );
782 : 0 : }
783 : :
784 : : /*************************************************************************
785 : : |* SotStorage::GetClassName()
786 : : |* SotStorage::GetFormat()
787 : : |* SotStorage::GetUserName()
788 : : |* SotStorage::ShouldConvert()
789 : : |*
790 : : |* Beschreibung
791 : : *************************************************************************/
792 : 18 : SvGlobalName SotStorage::GetClassName()
793 : : {
794 : 18 : SvGlobalName aGN;
795 : : DBG_ASSERT( Owner(), "must be owner" );
796 [ + - ]: 18 : if( m_pOwnStg )
797 [ + - ][ + - ]: 18 : aGN = m_pOwnStg->GetClassName();
[ + - ]
798 : : else
799 : 0 : SetError( SVSTREAM_GENERALERROR );
800 : 18 : return aGN;
801 : : }
802 : :
803 : 63 : sal_uLong SotStorage::GetFormat()
804 : : {
805 : 63 : sal_uLong nFormat = 0;
806 : : DBG_ASSERT( Owner(), "must be owner" );
807 [ + - ]: 63 : if( m_pOwnStg )
808 : 63 : nFormat = m_pOwnStg->GetFormat();
809 : : else
810 : 0 : SetError( SVSTREAM_GENERALERROR );
811 : 63 : return nFormat;
812 : : }
813 : :
814 : 0 : String SotStorage::GetUserName()
815 : : {
816 : 0 : String aName;
817 : : DBG_ASSERT( Owner(), "must be owner" );
818 [ # # ]: 0 : if( m_pOwnStg )
819 [ # # ][ # # ]: 0 : aName = m_pOwnStg->GetUserName();
[ # # ]
820 : : else
821 : 0 : SetError( SVSTREAM_GENERALERROR );
822 : 0 : return aName;
823 : : }
824 : :
825 : 0 : sal_Bool SotStorage::ShouldConvert()
826 : : {
827 : : DBG_ASSERT( Owner(), "must be owner" );
828 [ # # ]: 0 : if( m_pOwnStg )
829 : 0 : return m_pOwnStg->ShouldConvert();
830 : : else
831 : 0 : SetError( SVSTREAM_GENERALERROR );
832 : 0 : return sal_False;
833 : : }
834 : :
835 : : /*************************************************************************
836 : : |* SotStorage::FillInfoList()
837 : : |*
838 : : |* Beschreibung
839 : : *************************************************************************/
840 : 30 : void SotStorage::FillInfoList( SvStorageInfoList * pFillList ) const
841 : : {
842 : : DBG_ASSERT( Owner(), "must be owner" );
843 [ + - ]: 30 : if( m_pOwnStg )
844 : 30 : m_pOwnStg->FillInfoList( pFillList );
845 : 30 : }
846 : :
847 : : /*************************************************************************
848 : : |* SotStorage::CopyTo()
849 : : |*
850 : : |* Beschreibung
851 : : *************************************************************************/
852 : 9 : sal_Bool SotStorage::CopyTo( SotStorage * pDestStg )
853 : : {
854 : : DBG_ASSERT( Owner(), "must be owner" );
855 : : DBG_ASSERT( pDestStg->Owner(), "must be owner" );
856 [ + - ][ + - ]: 9 : if( m_pOwnStg && pDestStg->m_pOwnStg )
857 : : {
858 : 9 : m_pOwnStg->CopyTo( pDestStg->m_pOwnStg );
859 : 9 : SetError( m_pOwnStg->GetError() );
860 : 9 : pDestStg->m_aKey = m_aKey;
861 : 9 : pDestStg->m_nVersion = m_nVersion;
862 : : }
863 : : else
864 : 0 : SetError( SVSTREAM_GENERALERROR );
865 : 9 : return SVSTREAM_OK == GetError();
866 : : }
867 : :
868 : : /*************************************************************************
869 : : |* SotStorage::Commit()
870 : : |*
871 : : |* Beschreibung
872 : : *************************************************************************/
873 : 18 : sal_Bool SotStorage::Commit()
874 : : {
875 : : DBG_ASSERT( Owner(), "must be owner" );
876 [ + - ]: 18 : if( m_pOwnStg )
877 : : {
878 [ - + ]: 18 : if( !m_pOwnStg->Commit() )
879 : 0 : SetError( m_pOwnStg->GetError() );
880 : : }
881 : : else
882 : 0 : SetError( SVSTREAM_GENERALERROR );
883 : 18 : return SVSTREAM_OK == GetError();
884 : : }
885 : :
886 : : /*************************************************************************
887 : : |* SotStorage::Revert()
888 : : |*
889 : : |* Beschreibung
890 : : *************************************************************************/
891 : 0 : sal_Bool SotStorage::Revert()
892 : : {
893 : : DBG_ASSERT( Owner(), "must be owner" );
894 [ # # ]: 0 : if( m_pOwnStg )
895 : : {
896 [ # # ]: 0 : if( !m_pOwnStg->Revert() )
897 : 0 : SetError( m_pOwnStg->GetError() );
898 : : }
899 : : else
900 : 0 : SetError( SVSTREAM_GENERALERROR );
901 : 0 : return SVSTREAM_OK == GetError();
902 : : }
903 : :
904 : 1206 : SotStorageStream * SotStorage::OpenSotStream( const String & rEleName,
905 : : StreamMode nMode,
906 : : StorageMode nStorageMode )
907 : : {
908 : : DBG_ASSERT( !nStorageMode, "StorageModes ignored" );
909 : 1206 : SotStorageStream * pStm = NULL;
910 : : DBG_ASSERT( Owner(), "must be owner" );
911 [ + - ]: 1206 : if( m_pOwnStg )
912 : : {
913 : : // volle Ole-Patches einschalten
914 : : // egal was kommt, nur exclusiv gestattet
915 : 1206 : nMode |= STREAM_SHARE_DENYALL;
916 : 1206 : ErrCode nE = m_pOwnStg->GetError();
917 : : BaseStorageStream * p = m_pOwnStg->OpenStream( rEleName, nMode,
918 : 1206 : (nStorageMode & STORAGE_TRANSACTED) ? sal_False : sal_True );
919 [ + - ]: 1206 : pStm = new SotStorageStream( p );
920 : :
921 [ + - ]: 1206 : if( !nE )
922 : 1206 : m_pOwnStg->ResetError(); // kein Fehler setzen
923 [ + + ]: 1206 : if( nMode & STREAM_TRUNC )
924 : 18 : pStm->SetSize( 0 );
925 : : }
926 : : else
927 : 0 : SetError( SVSTREAM_GENERALERROR );
928 : 1206 : return pStm;
929 : : }
930 : :
931 : : /*************************************************************************
932 : : |* SotStorage::OpenStorage()
933 : : |*
934 : : |* Beschreibung
935 : : *************************************************************************/
936 : 45 : SotStorage * SotStorage::OpenSotStorage( const String & rEleName,
937 : : StreamMode nMode,
938 : : StorageMode nStorageMode )
939 : : {
940 : 45 : SotStorage * pStor = NULL;
941 : : DBG_ASSERT( Owner(), "must be owner" );
942 [ + - ]: 45 : if( m_pOwnStg )
943 : : {
944 : 45 : nMode |= STREAM_SHARE_DENYALL;
945 : 45 : ErrCode nE = m_pOwnStg->GetError();
946 : : BaseStorage * p = m_pOwnStg->OpenStorage( rEleName, nMode,
947 : 45 : (nStorageMode & STORAGE_TRANSACTED) ? sal_False : sal_True );
948 [ + - ]: 45 : if( p )
949 : : {
950 [ + - ]: 45 : pStor = new SotStorage( p );
951 [ + - ]: 45 : if( !nE )
952 : 45 : m_pOwnStg->ResetError(); // kein Fehler setzen
953 : :
954 : 45 : return pStor;
955 : : }
956 : : }
957 : :
958 : 0 : SetError( SVSTREAM_GENERALERROR );
959 : :
960 : 45 : return NULL;
961 : : }
962 : :
963 : 0 : SotStorage * SotStorage::OpenUCBStorage( const String & rEleName,
964 : : StreamMode nMode,
965 : : StorageMode nStorageMode )
966 : : {
967 : 0 : SotStorage * pStor = NULL;
968 : : DBG_ASSERT( Owner(), "must be owner" );
969 [ # # ]: 0 : if( m_pOwnStg )
970 : : {
971 : 0 : nMode |= STREAM_SHARE_DENYALL;
972 : 0 : ErrCode nE = m_pOwnStg->GetError();
973 : : BaseStorage * p = m_pOwnStg->OpenUCBStorage( rEleName, nMode,
974 : 0 : (nStorageMode & STORAGE_TRANSACTED) ? sal_False : sal_True );
975 [ # # ]: 0 : pStor = new SotStorage( p );
976 [ # # ]: 0 : if( !nE )
977 : 0 : m_pOwnStg->ResetError(); // kein Fehler setzen
978 : : }
979 : : else
980 : 0 : SetError( SVSTREAM_GENERALERROR );
981 : 0 : return pStor;
982 : : }
983 : :
984 : : /*************************************************************************
985 : : |* SotStorage::IsStream()
986 : : |* SotStorage::IsStorage()
987 : : |* SotStorage::IsContained()
988 : : |*
989 : : |* Beschreibung
990 : : *************************************************************************/
991 : 0 : sal_Bool SotStorage::IsStorage( const String & rEleName ) const
992 : : {
993 : : DBG_ASSERT( Owner(), "must be owner" );
994 : : // ein bisschen schneller
995 [ # # ]: 0 : if( m_pOwnStg )
996 : 0 : return m_pOwnStg->IsStorage( rEleName );
997 : 0 : return sal_False;
998 : : }
999 : :
1000 : 228 : sal_Bool SotStorage::IsStream( const String & rEleName ) const
1001 : : {
1002 : : DBG_ASSERT( Owner(), "must be owner" );
1003 : : // ein bisschen schneller
1004 [ + - ]: 228 : if( m_pOwnStg )
1005 : 228 : return m_pOwnStg->IsStream( rEleName );
1006 : 228 : return sal_False;
1007 : : }
1008 : :
1009 : 392 : sal_Bool SotStorage::IsContained( const String & rEleName ) const
1010 : : {
1011 : : DBG_ASSERT( Owner(), "must be owner" );
1012 : : // ein bisschen schneller
1013 [ + - ]: 392 : if( m_pOwnStg )
1014 : 392 : return m_pOwnStg->IsContained( rEleName );
1015 : 392 : return sal_False;
1016 : : }
1017 : :
1018 : : /*************************************************************************
1019 : : |* SotStorage::Remove()
1020 : : |*
1021 : : |* Beschreibung
1022 : : *************************************************************************/
1023 : 9 : sal_Bool SotStorage::Remove( const String & rEleName )
1024 : : {
1025 : : DBG_ASSERT( Owner(), "must be owner" );
1026 [ + - ]: 9 : if( m_pOwnStg )
1027 : : {
1028 : 9 : m_pOwnStg->Remove( rEleName );
1029 : 9 : SetError( m_pOwnStg->GetError() );
1030 : : }
1031 : : else
1032 : 0 : SetError( SVSTREAM_GENERALERROR );
1033 : 9 : return SVSTREAM_OK == GetError();
1034 : : }
1035 : :
1036 : : /*************************************************************************
1037 : : |* SotStorage::Rename()
1038 : : |*
1039 : : |* Beschreibung
1040 : : *************************************************************************/
1041 : 0 : sal_Bool SotStorage::Rename( const String & rEleName, const String & rNewName )
1042 : : {
1043 : : DBG_ASSERT( Owner(), "must be owner" );
1044 [ # # ]: 0 : if( m_pOwnStg )
1045 : : {
1046 : 0 : m_pOwnStg->Rename( rEleName, rNewName );
1047 : 0 : SetError( m_pOwnStg->GetError() );
1048 : : }
1049 : : else
1050 : 0 : SetError( SVSTREAM_GENERALERROR );
1051 : 0 : return SVSTREAM_OK == GetError();
1052 : : }
1053 : :
1054 : : /*************************************************************************
1055 : : |* SotStorage::CopyTo()
1056 : : |*
1057 : : |* Beschreibung
1058 : : *************************************************************************/
1059 : 0 : sal_Bool SotStorage::CopyTo( const String & rEleName,
1060 : : SotStorage * pNewSt, const String & rNewName )
1061 : : {
1062 : : DBG_ASSERT( Owner(), "must be owner" );
1063 : : DBG_ASSERT( pNewSt->Owner(), "must be owner" );
1064 [ # # ]: 0 : if( m_pOwnStg )
1065 : : {
1066 : 0 : m_pOwnStg->CopyTo( rEleName, pNewSt->m_pOwnStg, rNewName );
1067 : 0 : SetError( m_pOwnStg->GetError() );
1068 : 0 : SetError( pNewSt->GetError() );
1069 : : }
1070 : : else
1071 : 0 : SetError( SVSTREAM_GENERALERROR );
1072 : 0 : return SVSTREAM_OK == GetError();
1073 : : }
1074 : :
1075 : : /*************************************************************************
1076 : : |* SotStorage::MoveTo()
1077 : : |*
1078 : : |* Beschreibung
1079 : : *************************************************************************/
1080 : 0 : sal_Bool SotStorage::MoveTo( const String & rEleName,
1081 : : SotStorage * pNewSt, const String & rNewName )
1082 : : {
1083 : : DBG_ASSERT( Owner(), "must be owner" );
1084 : : DBG_ASSERT( pNewSt->Owner(), "must be owner" );
1085 [ # # ]: 0 : if( m_pOwnStg )
1086 : : {
1087 : 0 : m_pOwnStg->MoveTo( rEleName, pNewSt->m_pOwnStg, rNewName );
1088 : 0 : SetError( m_pOwnStg->GetError() );
1089 : 0 : SetError( pNewSt->GetError() );
1090 : : }
1091 : : else
1092 : 0 : SetError( SVSTREAM_GENERALERROR );
1093 : 0 : return SVSTREAM_OK == GetError();
1094 : : }
1095 : :
1096 : 0 : const SvStream* SotStorage::GetSvStream()
1097 : : {
1098 : 0 : const SvStream* pResult = 0;
1099 : : DBG_ASSERT( Owner(), "must be owner" );
1100 [ # # ]: 0 : if( m_pOwnStg )
1101 : 0 : pResult = m_pOwnStg->GetSvStream();
1102 : 0 : return pResult;
1103 : : }
1104 : :
1105 : 6 : sal_Bool SotStorage::Validate()
1106 : : {
1107 : : DBG_ASSERT( m_bIsRoot, "Validate nur an Rootstorage" );
1108 [ + - ]: 6 : if( m_pOwnStg )
1109 : 6 : return m_pOwnStg->ValidateFAT();
1110 : : else
1111 : 6 : return sal_True;
1112 : : }
1113 : :
1114 : 0 : sal_Bool SotStorage::SetProperty( const String& rName, const ::com::sun::star::uno::Any& rValue )
1115 : : {
1116 [ # # ][ # # ]: 0 : UCBStorage* pStg = PTR_CAST( UCBStorage, m_pOwnStg );
1117 [ # # ]: 0 : if ( pStg )
1118 : : {
1119 : 0 : return pStg->SetProperty( rName, rValue );
1120 : : }
1121 : : else
1122 : : {
1123 : : DBG_WARNING("W1:Not implemented!");
1124 : 0 : return sal_False;
1125 : : }
1126 : : }
1127 : :
1128 : 0 : sal_Bool SotStorage::GetProperty( const String& rName, ::com::sun::star::uno::Any& rValue )
1129 : : {
1130 [ # # ][ # # ]: 0 : UCBStorage* pStg = PTR_CAST( UCBStorage, m_pOwnStg );
1131 [ # # ]: 0 : if ( pStg )
1132 : : {
1133 : 0 : return pStg->GetProperty( rName, rValue );
1134 : : }
1135 [ # # ]: 0 : else if ( rName.CompareToAscii("MediaType") == COMPARE_EQUAL )
1136 : : {
1137 [ # # ][ # # ]: 0 : String aStr = SotExchange::GetFormatMimeType( GetFormat() );
1138 [ # # ]: 0 : sal_uInt16 nPos = aStr.Search(';');
1139 [ # # ]: 0 : if ( nPos != STRING_NOTFOUND )
1140 [ # # ][ # # ]: 0 : aStr = aStr.Copy( 0, nPos );
[ # # ]
1141 [ # # ][ # # ]: 0 : rValue <<= (::rtl::OUString) aStr;
1142 [ # # ]: 0 : return sal_True;
1143 : : }
1144 : : else
1145 : : {
1146 : : DBG_WARNING("W1:Not implemented!");
1147 : 0 : return sal_False;
1148 : : }
1149 : : }
1150 : :
1151 : 364 : sal_Bool SotStorage::IsOLEStorage() const
1152 : : {
1153 [ + - ][ + + ]: 364 : UCBStorage* pStg = PTR_CAST( UCBStorage, m_pOwnStg );
1154 : 364 : return !pStg;
1155 : : }
1156 : :
1157 : 9 : sal_Bool SotStorage::IsOLEStorage( const String & rFileName )
1158 : : {
1159 : 9 : return Storage::IsStorageFile( rFileName );
1160 : : }
1161 : :
1162 : 364 : sal_Bool SotStorage::IsOLEStorage( SvStream* pStream )
1163 : : {
1164 : 364 : return Storage::IsStorageFile( pStream );
1165 : : }
1166 : :
1167 : 0 : void SotStorage::SetKey( const rtl::OString& rKey )
1168 : : {
1169 : 0 : m_aKey = rKey;
1170 [ # # ]: 0 : if ( !IsOLEStorage() )
1171 : : {
1172 : : sal_uInt8 aBuffer[RTL_DIGEST_LENGTH_SHA1];
1173 : 0 : rtlDigestError nError = rtl_digest_SHA1( m_aKey.getStr(), m_aKey.getLength(), aBuffer, RTL_DIGEST_LENGTH_SHA1 );
1174 [ # # ]: 0 : if ( nError == rtl_Digest_E_None )
1175 : : {
1176 : 0 : sal_uInt8* pBuffer = aBuffer;
1177 [ # # ]: 0 : ::com::sun::star::uno::Sequence < sal_Int8 > aSequ( (sal_Int8*) pBuffer, RTL_DIGEST_LENGTH_SHA1 );
1178 : 0 : ::com::sun::star::uno::Any aAny;
1179 [ # # ]: 0 : aAny <<= aSequ;
1180 [ # # ][ # # ]: 0 : SetProperty( ::rtl::OUString("EncryptionKey"), aAny );
[ # # ][ # # ]
1181 : : }
1182 : : }
1183 : 0 : }
1184 : :
1185 : 9 : SotStorage* SotStorage::OpenOLEStorage( const com::sun::star::uno::Reference < com::sun::star::embed::XStorage >& xStorage,
1186 : : const String& rEleName, StreamMode nMode )
1187 : : {
1188 : 9 : sal_Int32 nEleMode = embed::ElementModes::SEEKABLEREAD;
1189 [ + - ]: 9 : if ( nMode & STREAM_WRITE )
1190 : 9 : nEleMode |= embed::ElementModes::WRITE;
1191 [ - + ]: 9 : if ( nMode & STREAM_TRUNC )
1192 : 0 : nEleMode |= embed::ElementModes::TRUNCATE;
1193 [ - + ]: 9 : if ( nMode & STREAM_NOCREATE )
1194 : 0 : nEleMode |= embed::ElementModes::NOCREATE;
1195 : :
1196 : 9 : SvStream* pStream = NULL;
1197 : : try
1198 : : {
1199 [ + - ][ + - ]: 9 : uno::Reference < io::XStream > xStream = xStorage->openStreamElement( rEleName, nEleMode );
[ + - ]
1200 : :
1201 : : // TODO/LATER: should it be done this way?
1202 [ + - ]: 9 : if ( nMode & STREAM_WRITE )
1203 : : {
1204 [ + - ]: 9 : uno::Reference < beans::XPropertySet > xStreamProps( xStream, uno::UNO_QUERY_THROW );
1205 [ + - ]: 9 : xStreamProps->setPropertyValue(
1206 : : ::rtl::OUString( "MediaType" ),
1207 [ + - ][ + - ]: 9 : uno::makeAny( ::rtl::OUString( "application/vnd.sun.star.oleobject" ) ) );
1208 : : }
1209 : :
1210 [ + - ]: 9 : pStream = utl::UcbStreamHelper::CreateStream( xStream );
1211 : : }
1212 [ # # ]: 0 : catch ( uno::Exception& )
1213 : : {
1214 : : //TODO/LATER: ErrorHandling
1215 [ # # # # ]: 0 : pStream = new SvMemoryStream;
1216 [ # # ]: 0 : pStream->SetError( ERRCODE_IO_GENERAL );
1217 : : }
1218 : :
1219 [ + - ]: 9 : return new SotStorage( pStream, sal_True );
1220 : : }
1221 : :
1222 : 1601 : sal_Int32 SotStorage::GetFormatID( const com::sun::star::uno::Reference < com::sun::star::embed::XStorage >& xStorage )
1223 : : {
1224 [ + - ]: 1601 : uno::Reference< beans::XPropertySet > xProps( xStorage, uno::UNO_QUERY );
1225 [ - + ]: 1601 : if ( !xProps.is() )
1226 : 0 : return 0;
1227 : :
1228 : 1601 : ::rtl::OUString aMediaType;
1229 [ + - ][ + - ]: 1601 : xProps->getPropertyValue( ::rtl::OUString("MediaType") ) >>= aMediaType;
1230 [ + + ]: 1601 : if ( !aMediaType.isEmpty() )
1231 : : {
1232 : 1597 : ::com::sun::star::datatransfer::DataFlavor aDataFlavor;
1233 : 1597 : aDataFlavor.MimeType = aMediaType;
1234 [ + - ]: 1597 : return SotExchange::GetFormat( aDataFlavor );
1235 : : }
1236 : :
1237 : 1601 : return 0;
1238 : : }
1239 : :
1240 : 1601 : sal_Int32 SotStorage::GetVersion( const com::sun::star::uno::Reference < com::sun::star::embed::XStorage >& xStorage )
1241 : : {
1242 : 1601 : sal_Int32 nSotFormatID = SotStorage::GetFormatID( xStorage );
1243 [ + + + ]: 1601 : switch( nSotFormatID )
1244 : : {
1245 : : case SOT_FORMATSTR_ID_STARWRITER_8:
1246 : : case SOT_FORMATSTR_ID_STARWRITER_8_TEMPLATE:
1247 : : case SOT_FORMATSTR_ID_STARWRITERWEB_8:
1248 : : case SOT_FORMATSTR_ID_STARWRITERGLOB_8:
1249 : : case SOT_FORMATSTR_ID_STARDRAW_8:
1250 : : case SOT_FORMATSTR_ID_STARDRAW_8_TEMPLATE:
1251 : : case SOT_FORMATSTR_ID_STARIMPRESS_8:
1252 : : case SOT_FORMATSTR_ID_STARIMPRESS_8_TEMPLATE:
1253 : : case SOT_FORMATSTR_ID_STARCALC_8:
1254 : : case SOT_FORMATSTR_ID_STARCALC_8_TEMPLATE:
1255 : : case SOT_FORMATSTR_ID_STARCHART_8:
1256 : : case SOT_FORMATSTR_ID_STARCHART_8_TEMPLATE:
1257 : : case SOT_FORMATSTR_ID_STARMATH_8:
1258 : : case SOT_FORMATSTR_ID_STARMATH_8_TEMPLATE:
1259 : 1549 : return SOFFICE_FILEFORMAT_8;
1260 : : case SOT_FORMATSTR_ID_STARWRITER_60:
1261 : : case SOT_FORMATSTR_ID_STARWRITERWEB_60:
1262 : : case SOT_FORMATSTR_ID_STARWRITERGLOB_60:
1263 : : case SOT_FORMATSTR_ID_STARDRAW_60:
1264 : : case SOT_FORMATSTR_ID_STARIMPRESS_60:
1265 : : case SOT_FORMATSTR_ID_STARCALC_60:
1266 : : case SOT_FORMATSTR_ID_STARCHART_60:
1267 : : case SOT_FORMATSTR_ID_STARMATH_60:
1268 : 48 : return SOFFICE_FILEFORMAT_60;
1269 : : }
1270 : :
1271 : 1601 : return 0;
1272 : : }
1273 : :
1274 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|