summaryrefslogtreecommitdiff
path: root/sot/source/sdstor
diff options
context:
space:
mode:
authorMathias Bauer <mba@openoffice.org>2000-11-20 11:55:09 +0000
committerMathias Bauer <mba@openoffice.org>2000-11-20 11:55:09 +0000
commit066f06e8cab65ff100d0986565c0884474999f1e (patch)
tree2f6dc14983ba1dd00a60f50120abfdf7f390a193 /sot/source/sdstor
parente38e55fdd04345aaf0a85ad41f8a7940d99f30f8 (diff)
#80466#: new abstract base class for class Storage to support new JAR storages
Diffstat (limited to 'sot/source/sdstor')
-rw-r--r--sot/source/sdstor/stg.cxx236
-rw-r--r--sot/source/sdstor/storage.cxx92
2 files changed, 240 insertions, 88 deletions
diff --git a/sot/source/sdstor/stg.cxx b/sot/source/sdstor/stg.cxx
index ca0d18d0dcd3..ae5313f29b22 100644
--- a/sot/source/sdstor/stg.cxx
+++ b/sot/source/sdstor/stg.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: stg.cxx,v $
*
- * $Revision: 1.3 $
+ * $Revision: 1.4 $
*
- * last change: $Author: mba $ $Date: 2000-10-16 14:08:34 $
+ * last change: $Author: mba $ $Date: 2000-11-20 12:55:09 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -97,17 +97,58 @@ static long nTmpCount = 0;
///////////////////////// class StorageBase //////////////////////////////
-StorageBase::StorageBase( StgIo* p, StgDirEntry* pe )
- : bAutoCommit( FALSE ), pIo( p ), pEntry( pe )
+TYPEINIT0( StorageBase );
+TYPEINIT1( BaseStorageStream, StorageBase );
+TYPEINIT1( BaseStorage, StorageBase );
+
+StorageBase::StorageBase()
+ : bAutoCommit( FALSE )
{
nMode = STREAM_READ;
nError = SVSTREAM_OK;
+}
+
+StorageBase::~StorageBase()
+{
+}
+
+// The following three methods are declared as const, since they
+// may be called from within a const method.
+
+ULONG StorageBase::GetError() const
+{
+ ULONG n = nError;
+ ((StorageBase*) this)->nError = SVSTREAM_OK;
+ return n;
+}
+
+void StorageBase::SetError( ULONG n ) const
+{
+ if( !nError )
+ ((StorageBase*) this)->nError = n;
+}
+
+void StorageBase::ResetError() const
+{
+ ((StorageBase*) this)->nError = SVSTREAM_OK;
+}
+
+// Retrieve the underlying SvStream for info purposes
+
+const SvStream* OLEStorageBase::GetSvStream_Impl() const
+{
+ return pIo ? pIo->GetStrm() : NULL;
+}
+
+OLEStorageBase::OLEStorageBase( StgIo* p, StgDirEntry* pe, StreamMode& nMode )
+ : pIo( p ), pEntry( pe ), nStreamMode( nMode )
+{
p->IncRef();
if( pe )
pe->nRefCnt++;
}
-StorageBase::~StorageBase()
+OLEStorageBase::~OLEStorageBase()
{
if( pEntry )
{
@@ -128,19 +169,16 @@ StorageBase::~StorageBase()
// Validate the instance for I/O
-BOOL StorageBase::Validate( BOOL bWrite ) const
+BOOL OLEStorageBase::Validate_Impl( BOOL bWrite ) const
{
if( pEntry
&& !pEntry->bInvalid
- && ( !bWrite || !pEntry->bDirect || ( nMode & STREAM_WRITE ) ) )
+ && ( !bWrite || !pEntry->bDirect || ( nStreamMode & STREAM_WRITE ) ) )
return TRUE;
- SetError( SVSTREAM_ACCESS_DENIED );
return FALSE;
}
-// Check the given share flags against the current flags
-
-BOOL StorageBase::ValidateMode( StreamMode m, StgDirEntry* p ) const
+BOOL OLEStorageBase::ValidateMode_Impl( StreamMode m, StgDirEntry* p ) const
{
if( m == INTERNAL_MODE )
return TRUE;
@@ -163,42 +201,16 @@ BOOL StorageBase::ValidateMode( StreamMode m, StgDirEntry* p ) const
&& ( nCurMode & STREAM_SHARE_DENYALL ) )
return TRUE;
}
- SetError( SVSTREAM_ACCESS_DENIED );
return FALSE;
}
-// The following three methods are declared as const, since they
-// may be called from within a const method.
-
-ULONG StorageBase::GetError() const
-{
- ULONG n = nError;
- ((StorageBase*) this)->nError = SVSTREAM_OK;
- return n;
-}
-
-void StorageBase::SetError( ULONG n ) const
-{
- if( !nError )
- ((StorageBase*) this)->nError = n;
-}
-
-void StorageBase::ResetError() const
-{
- ((StorageBase*) this)->nError = SVSTREAM_OK;
-}
-
-// Retrieve the underlying SvStream for info purposes
-
-const SvStream* StorageBase::GetSvStream() const
-{
- return pIo ? pIo->GetStrm() : NULL;
-}
//////////////////////// class StorageStream /////////////////////////////
+TYPEINIT1( StorageStream, BaseStorageStream );
+
StorageStream::StorageStream( StgIo* p, StgDirEntry* q, StreamMode m )
- : StorageBase( p, q ), nPos( 0L )
+ : OLEStorageBase( p, q, nMode ), nPos( 0L )
{
// The dir entry may be 0; this means that the stream is invalid.
if( q )
@@ -223,6 +235,12 @@ StorageStream::~StorageStream()
pEntry->Commit();
}
+BOOL StorageStream::Equals( const BaseStorageStream& rStream ) const
+{
+ const StorageStream* pOther = PTR_CAST( StorageStream, &rStream );
+ return pOther && ( pOther->pEntry == pEntry );
+}
+
ULONG StorageStream::Read( void* pData, ULONG nSize )
{
if( Validate() )
@@ -301,17 +319,46 @@ BOOL StorageStream::Revert()
return Good();
}
-BOOL StorageStream::CopyTo( StorageStream* pDest )
+BOOL StorageStream::CopyTo( BaseStorageStream* pDest )
{
- if( !Validate() || !pDest->Validate( TRUE ) || pEntry == pDest->pEntry )
+ if( !Validate() || !pDest->Validate( TRUE ) || Equals( *pDest ) )
return FALSE;
- pEntry->Copy( *pDest->pEntry );
+ pEntry->Copy( *pDest );
pDest->Commit();
pIo->MoveError( *this );
SetError( pDest->GetError() );
return BOOL( Good() && pDest->Good() );
}
+const SvStream* StorageStream::GetSvStream() const
+{
+ return GetSvStream_Impl();
+}
+
+BOOL StorageStream::Validate( BOOL bValidate ) const
+{
+ BOOL bRet = Validate_Impl( bValidate );
+ if ( !bRet )
+ SetError( SVSTREAM_ACCESS_DENIED );
+ return bRet;
+}
+
+BOOL StorageStream::ValidateMode( StreamMode nMode ) const
+{
+ BOOL bRet = ValidateMode_Impl( nMode, NULL );
+ if ( !bRet )
+ SetError( SVSTREAM_ACCESS_DENIED );
+ return bRet;
+}
+
+BOOL StorageStream::ValidateMode( StreamMode nMode, StgDirEntry* p ) const
+{
+ BOOL bRet = ValidateMode_Impl( nMode, p );
+ if ( !bRet )
+ SetError( SVSTREAM_ACCESS_DENIED );
+ return bRet;
+}
+
///////////////////////// class SvStorageInfo //////////////////////////////
SvStorageInfo::SvStorageInfo( const StgDirEntry& rE )
@@ -341,8 +388,10 @@ BOOL Storage::IsStorageFile( SvStream* pStream )
// Open the storage file. If writing is permitted and the file is not
// a storage file, initialize it.
+TYPEINIT1( Storage, BaseStorage );
+
Storage::Storage( const String& rFile, StreamMode m, BOOL bDirect )
- : StorageBase( new StgIo, NULL ), aName( rFile ), bIsRoot( FALSE )
+ : OLEStorageBase( new StgIo, NULL, nMode ), aName( rFile ), bIsRoot( FALSE )
{
BOOL bTemp = FALSE;
if( !aName.Len() )
@@ -373,7 +422,7 @@ Storage::Storage( const String& rFile, StreamMode m, BOOL bDirect )
// Create a storage on a given stream.
Storage::Storage( SvStream& r, BOOL bDirect )
- : StorageBase( new StgIo, NULL ), bIsRoot( FALSE )
+ : OLEStorageBase( new StgIo, NULL, nMode ), bIsRoot( FALSE )
{
nMode = STREAM_READ;
if( r.IsWritable() )
@@ -437,13 +486,12 @@ void Storage::Init( BOOL bCreate )
// Internal ctor
Storage::Storage( StgIo* p, StgDirEntry* q, StreamMode m )
- : StorageBase( p, q ), bIsRoot( FALSE )
+ : OLEStorageBase( p, q, nMode ), bIsRoot( FALSE )
{
if( q )
q->aEntry.GetName( aName );
else
m &= ~STREAM_READWRITE;
- bIsRoot = FALSE;
nMode = m;
if( q && q->nRefCnt == 1 )
q->nMode = m;
@@ -501,9 +549,9 @@ void Storage::FillInfoList( SvStorageInfoList* pList ) const
// Open or create a substorage
-Storage* Storage::OpenStorage( const String& rName, StreamMode m, BOOL bDirect )
+BaseStorage* Storage::OpenStorage( const String& rName, StreamMode m, BOOL bDirect )
{
- if( !Validate() || !ValidateMode( m, NULL ) )
+ if( !Validate() || !ValidateMode( m ) )
return new Storage( pIo, NULL, m );
BOOL bSetAutoCommit = FALSE;
if( bDirect && !pEntry->bDirect )
@@ -558,9 +606,9 @@ Storage* Storage::OpenStorage( const String& rName, StreamMode m, BOOL bDirect )
// Open a stream
-StorageStream* Storage::OpenStream( const String& rName, StreamMode m, BOOL )
+BaseStorageStream* Storage::OpenStream( const String& rName, StreamMode m, BOOL )
{
- if( !Validate() || !ValidateMode( m, NULL ) )
+ if( !Validate() || !ValidateMode( m ) )
return new StorageStream( pIo, NULL, m );
StgDirEntry* p = pIo->pTOC->Find( *pEntry, rName );
BOOL bTemp = FALSE;
@@ -637,7 +685,7 @@ BOOL Storage::Rename( const String& rOld, const String& rNew )
// Copy one element
-BOOL Storage::CopyTo( const String& rElem, Storage* pDest, const String& rNew )
+BOOL Storage::CopyTo( const String& rElem, BaseStorage* pDest, const String& rNew )
{
if( !Validate() || !pDest || !pDest->Validate( TRUE ) )
return FALSE;
@@ -655,10 +703,9 @@ BOOL Storage::CopyTo( const String& rElem, Storage* pDest, const String& rNew )
if( pElem->aEntry.GetType() == STG_STORAGE )
{
// copy the entire storage
- Storage* p1 = OpenStorage( rElem, INTERNAL_MODE );
- Storage* p2 = pDest->OpenStorage
- ( rNew, STREAM_WRITE | STREAM_SHARE_DENYALL, pEntry->bDirect );
- p2->pEntry->aEntry.SetClassId( p1->pEntry->aEntry.GetClassId() );
+ BaseStorage* p1 = OpenStorage( rElem, INTERNAL_MODE );
+ BaseStorage* p2 = pDest->OpenStorage( rNew, STREAM_WRITE | STREAM_SHARE_DENYALL, pEntry->bDirect );
+ p2->SetClassId( p1->GetClassId() );
p1->CopyTo( p2 );
SetError( p1->GetError() );
if( p2->GetError() )
@@ -672,9 +719,8 @@ BOOL Storage::CopyTo( const String& rElem, Storage* pDest, const String& rNew )
else
{
// stream copy
- StorageStream* p1 = OpenStream( rElem, INTERNAL_MODE );
- StorageStream* p2 = pDest->OpenStream
- ( rNew, STREAM_WRITE | STREAM_SHARE_DENYALL, pEntry->bDirect );
+ BaseStorageStream* p1 = OpenStream( rElem, INTERNAL_MODE );
+ BaseStorageStream* p2 = pDest->OpenStream( rNew, STREAM_WRITE | STREAM_SHARE_DENYALL, pEntry->bDirect );
p1->CopyTo( p2 );
SetError( p1->GetError() );
if( p2->GetError() )
@@ -690,10 +736,9 @@ BOOL Storage::CopyTo( const String& rElem, Storage* pDest, const String& rNew )
return FALSE;
}
-BOOL Storage::CopyTo( Storage* pDest ) const
+BOOL Storage::CopyTo( BaseStorage* pDest ) const
{
- if( !Validate() || !pDest || !pDest->Validate( TRUE )
- || pDest->pEntry == pEntry )
+ if( !Validate() || !pDest || !pDest->Validate( TRUE ) || Equals( *pDest ) )
{
SetError( SVSTREAM_ACCESS_DENIED );
return FALSE;
@@ -706,8 +751,8 @@ BOOL Storage::CopyTo( Storage* pDest ) const
return FALSE;
}
*/
- pDest->pEntry->aEntry.SetClassId( pEntry->aEntry.GetClassId() );
- pDest->pEntry->SetDirty();
+ pDest->SetClassId( GetClassId() );
+ pDest->SetDirty();
SvStorageInfoList aList;
FillInfoList( &aList );
BOOL bRes = TRUE;
@@ -723,21 +768,25 @@ BOOL Storage::CopyTo( Storage* pDest ) const
// Move one element
-BOOL Storage::MoveTo( const String& rElem, Storage* pDest, const String& rNew )
+BOOL Storage::MoveTo( const String& rElem, BaseStorage* pDest, const String& rNew )
{
- if( !Validate() || !pDest || !pDest->Validate( TRUE )
- || pDest->pEntry == pEntry )
+ if( !Validate() || !pDest || !pDest->Validate( TRUE ) || Equals( *pDest ) )
{
SetError( SVSTREAM_ACCESS_DENIED );
return FALSE;
}
+
StgDirEntry* pElem = pIo->pTOC->Find( *pEntry, rElem );
if( pElem )
{
// Simplest case: both storages share the same file
BOOL bRes;
- if( pIo == pDest->pIo && rElem == rNew )
+ Storage *pOther = PTR_CAST( Storage, pDest );
+ if( pOther && pIo == pOther->pIo && rElem == rNew )
{
+ Storage *p = (Storage*) pDest;
+ Storage *pDest = p;
+ // both storages are conventional storages, use implementation dependent code
if( !pElem->IsContained( pDest->pEntry ) )
{
// cyclic move
@@ -928,3 +977,54 @@ BOOL Storage::ValidateFAT()
return nErr == ERRCODE_NONE;
}
+void Storage::SetDirty()
+{
+ pEntry->SetDirty();
+}
+
+void Storage::SetClassId( const ClsId& rId )
+{
+ pEntry->aEntry.SetClassId( rId );
+}
+
+const ClsId& Storage::GetClassId() const
+{
+ return pEntry->aEntry.GetClassId();
+}
+
+const SvStream* Storage::GetSvStream() const
+{
+ return GetSvStream_Impl();
+}
+
+BOOL Storage::Validate( BOOL bValidate ) const
+{
+ BOOL bRet = Validate_Impl( bValidate );
+ if ( !bRet )
+ SetError( SVSTREAM_ACCESS_DENIED );
+ return bRet;
+}
+
+BOOL Storage::ValidateMode( StreamMode nMode ) const
+{
+ BOOL bRet = ValidateMode_Impl( nMode );
+ if ( !bRet )
+ SetError( SVSTREAM_ACCESS_DENIED );
+ return bRet;
+}
+
+BOOL Storage::ValidateMode( StreamMode nMode, StgDirEntry* p ) const
+{
+ BOOL bRet = ValidateMode_Impl( nMode, p );
+ if ( !bRet )
+ SetError( SVSTREAM_ACCESS_DENIED );
+ return bRet;
+}
+
+BOOL Storage::Equals( const BaseStorage& rStorage ) const
+{
+ const Storage* pOther = PTR_CAST( Storage, &rStorage );
+ return pOther && ( pOther->pEntry == pEntry );
+}
+
+
diff --git a/sot/source/sdstor/storage.cxx b/sot/source/sdstor/storage.cxx
index 6ec7506dbf8f..18a7d2145ae2 100644
--- a/sot/source/sdstor/storage.cxx
+++ b/sot/source/sdstor/storage.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: storage.cxx,v $
*
- * $Revision: 1.4 $
+ * $Revision: 1.5 $
*
- * last change: $Author: mba $ $Date: 2000-10-20 14:12:19 $
+ * last change: $Author: mba $ $Date: 2000-11-20 12:55:09 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -64,6 +64,9 @@
#include <storinfo.hxx>
#include <storage.hxx>
+#ifndef _UNTOOLS_UCBSTREAMHELPER_HXX
+#include <unotools/ucbstreamhelper.hxx>
+#endif
#ifndef _TOOLS_FSYS_HXX
#include <tools/fsys.hxx>
#endif
@@ -71,6 +74,8 @@
#include <tools/cachestr.hxx>
#endif
#include <tools/debug.hxx>
+#include <tools/urlobj.hxx>
+#include <unotools/localfilehelper.hxx>
#pragma hdrstop
/************** class SotStorageStream ***********************************/
@@ -137,7 +142,7 @@ SotStorageStream::SotStorageStream( const String & rName, StreamMode nMode,
DBG_ASSERT( !nStorageMode,"StorageModes ignored" )
}
-SotStorageStream::SotStorageStream( StorageStream * pStm )
+SotStorageStream::SotStorageStream( BaseStorageStream * pStm )
{
if( STREAM_WRITE & pStm->GetMode() )
bIsWritable = TRUE;
@@ -455,39 +460,74 @@ void SotStorage::TestMemberInvariant( BOOL bPrint )
, bIsRoot( FALSE ) \
, bDelStm( FALSE ) \
, nVersion( SOFFICE_FILEFORMAT_NOW ) \
- , pTmpStg( NULL ) \
, pOwnStg( NULL ) \
, pStorStm( NULL )
SotStorage::SotStorage()
INIT_SotStorage()
{
+ // ??? What's this ???
}
#define ERASEMASK ( STREAM_TRUNC | STREAM_WRITE | STREAM_SHARE_DENYALL )
-SotStorage::SotStorage( const String & rName, StreamMode nMode,
- StorageMode nStorageMode )
+SotStorage::SotStorage( const String & rName, StreamMode nMode, StorageMode nStorageMode )
INIT_SotStorage()
{
aName = rName; // Namen merken
- // Sicherheitshalber wird die Storage File geloescht, wenn
- // sie neu erzeugt werden soll
- if( aName.Len() && ( ( nMode & ERASEMASK ) == ERASEMASK ) )
+ if( aName.Len() )
{
- osl::File::remove( rName );
- }
+ // named storage
+ if( ( ( nMode & ERASEMASK ) == ERASEMASK ) )
+ // ???
+ osl::File::remove( rName );
+
+ String aURL;
+ INetURLObject aObj( rName );
+ if ( aObj.GetProtocol() == INET_PROT_NOT_VALID )
+ {
+ String aURL;
+ ::utl::LocalFileHelper::ConvertPhysicalNameToURL( rName, aURL );
+ aObj.SetURL( aURL );
+ }
- pTmpStg = new Storage( aName, nMode,
- (nStorageMode & STORAGE_TRANSACTED) ? FALSE : TRUE );
- pOwnStg = pTmpStg;
- if( !aName.Len() )
+ pStorStm = ::utl::UcbStreamHelper::CreateStream( aObj.GetMainURL(), nMode );
+ if ( pStorStm )
+ {
+ // try as UCBStorage, next try as OLEStorage
+ if ( UCBStorage::IsStorageFile( pStorStm ) )
+ {
+ // UCBStorage always works directly on the UCB content, so discard the stream first
+ DELETEZ( pStorStm );
+ DBG_ASSERT( (nStorageMode & STORAGE_TRANSACTED), "No direct mode supported!" );
+ pOwnStg = new UCBStorage( rName, nMode );
+ }
+ else
+ {
+ // OLEStorage can be opened with a stream
+ pOwnStg = new Storage( *pStorStm, (nStorageMode & STORAGE_TRANSACTED) ? FALSE : TRUE );
+ bDelStm = TRUE;
+ }
+ }
+ else
+ {
+ pOwnStg = new Storage( rName, nMode, (nStorageMode & STORAGE_TRANSACTED) ? FALSE : TRUE );
+ SetError( ERRCODE_IO_NOTSUPPORTED );
+ }
+ }
+ else
+ {
+ // temporary storage
+ // try as UCBStorage, next try as OLEStorage ( how to check which one is desired ?! )
+ pOwnStg = new Storage( rName, nMode, (nStorageMode & STORAGE_TRANSACTED) ? FALSE : TRUE );
aName = pOwnStg->GetName();
+ }
+
ULONG nErr = pOwnStg->GetError();
SetError( nErr );
}
-SotStorage::SotStorage( Storage * pStor )
+SotStorage::SotStorage( BaseStorage * pStor )
INIT_SotStorage()
{
aName = pStor->GetName(); // Namen merken
@@ -502,14 +542,24 @@ SotStorage::SotStorage( SvStream & rStm )
INIT_SotStorage()
{
SetError( rStm.GetError() );
- pOwnStg = new Storage( rStm, FALSE );
+
+ // try as UCBStorage, next try as OLEStorage
+ if ( UCBStorage::IsStorageFile( pStorStm ) )
+ pOwnStg = new UCBStorage( rStm, FALSE );
+ else
+ pOwnStg = new Storage( rStm, FALSE );
}
SotStorage::SotStorage( SvStream * pStm, BOOL bDelete )
INIT_SotStorage()
{
SetError( pStm->GetError() );
- pOwnStg = new Storage( *pStm, FALSE );
+
+ // try as UCBStorage, next try as OLEStorage
+ if ( UCBStorage::IsStorageFile( pStorStm ) )
+ pOwnStg = new UCBStorage( *pStm, FALSE );
+ else
+ pOwnStg = new Storage( *pStm, FALSE );
ULONG nError = pOwnStg->GetError();
if ( nError != SVSTREAM_OK )
@@ -559,11 +609,13 @@ SvMemoryStream * SotStorage::CreateMemoryStream()
*************************************************************************/
BOOL SotStorage::IsStorageFile( const String & rFileName )
{
+ /** code for new storages must come first! **/
return Storage::IsStorageFile( rFileName );
}
BOOL SotStorage::IsStorageFile( SvStream* pStream )
{
+ /** code for new storages must come first! **/
if ( pStream )
{
long nPos = pStream->Tell();
@@ -778,7 +830,7 @@ SotStorageStream * SotStorage::OpenSotStream( const String & rEleName,
// egal was kommt, nur exclusiv gestattet
nMode |= STREAM_SHARE_DENYALL;
ErrCode nE = pOwnStg->GetError();
- StorageStream * p = pOwnStg->OpenStream( rEleName, nMode,
+ BaseStorageStream * p = pOwnStg->OpenStream( rEleName, nMode,
(nStorageMode & STORAGE_TRANSACTED) ? FALSE : TRUE );
pStm = new SotStorageStream( p );
if( !nE )
@@ -806,7 +858,7 @@ SotStorage * SotStorage::OpenSotStorage( const String & rEleName,
{
nMode |= STREAM_SHARE_DENYALL;
ErrCode nE = pOwnStg->GetError();
- Storage * p = pOwnStg->OpenStorage( rEleName, nMode,
+ BaseStorage * p = pOwnStg->OpenStorage( rEleName, nMode,
(nStorageMode & STORAGE_TRANSACTED) ? FALSE : TRUE );
pStor = new SotStorage( p );
if( !nE )