summaryrefslogtreecommitdiff
path: root/package/source/xstor
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2017-09-21 15:42:49 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2017-09-22 08:30:10 +0200
commitb63609ba5478ed9b020c113f5704f7ea8447dec8 (patch)
treee40896646675d8b462cec7a90ca1e94e902b3746 /package/source/xstor
parent4af6c0948be47d7816eb1b6f2137b70aba639f0d (diff)
loplugin:flatten in framework..package
Change-Id: Ide8a97eae6e2fdc7d2dcccba1480ac55a9b555bc Reviewed-on: https://gerrit.libreoffice.org/42593 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'package/source/xstor')
-rw-r--r--package/source/xstor/owriteablestream.cxx134
-rw-r--r--package/source/xstor/xstorage.cxx137
2 files changed, 124 insertions, 147 deletions
diff --git a/package/source/xstor/owriteablestream.cxx b/package/source/xstor/owriteablestream.cxx
index af0dc07fbb29..9c4c19cb9e91 100644
--- a/package/source/xstor/owriteablestream.cxx
+++ b/package/source/xstor/owriteablestream.cxx
@@ -506,15 +506,12 @@ OUString const & OWriteStream_Impl::GetFilledTempFileIfNo( const uno::Reference<
uno::Reference < ucb::XSimpleFileAccess3 > xTempAccess( ucb::SimpleFileAccess::create( ::comphelper::getProcessComponentContext() ) );
uno::Reference< io::XOutputStream > xTempOutStream = xTempAccess->openFileWrite( aTempURL );
- if ( xTempOutStream.is() )
- {
- // the current position of the original stream should be still OK, copy further
- ::comphelper::OStorageHelper::CopyInputToOutput( xStream, xTempOutStream );
- xTempOutStream->closeOutput();
- xTempOutStream.clear();
- }
- else
+ if ( !xTempOutStream.is() )
throw io::IOException(); // TODO:
+ // the current position of the original stream should be still OK, copy further
+ ::comphelper::OStorageHelper::CopyInputToOutput( xStream, xTempOutStream );
+ xTempOutStream->closeOutput();
+ xTempOutStream.clear();
}
}
catch( const packages::WrongPasswordException& rWrongPasswordException )
@@ -585,18 +582,16 @@ OUString const & OWriteStream_Impl::FillTempGetFileName()
uno::Reference < ucb::XSimpleFileAccess3 > xTempAccess( ucb::SimpleFileAccess::create( ::comphelper::getProcessComponentContext() ) );
uno::Reference< io::XOutputStream > xTempOutStream = xTempAccess->openFileWrite( m_aTempURL );
- if ( xTempOutStream.is() )
- {
- // copy stream contents to the file
- xTempOutStream->writeBytes( aData );
-
- // the current position of the original stream should be still OK, copy further
- ::comphelper::OStorageHelper::CopyInputToOutput( xOrigStream, xTempOutStream );
- xTempOutStream->closeOutput();
- xTempOutStream.clear();
- }
- else
+ if ( !xTempOutStream.is() )
throw io::IOException(); // TODO:
+
+ // copy stream contents to the file
+ xTempOutStream->writeBytes( aData );
+
+ // the current position of the original stream should be still OK, copy further
+ ::comphelper::OStorageHelper::CopyInputToOutput( xOrigStream, xTempOutStream );
+ xTempOutStream->closeOutput();
+ xTempOutStream.clear();
}
}
catch( const packages::WrongPasswordException& )
@@ -2679,31 +2674,29 @@ void SAL_CALL OWriteStream::insertRelationshipByID( const OUString& sID, const
break;
}
- if ( nIDInd == -1 || bReplace )
- {
- if ( nIDInd == -1 )
- {
- nIDInd = aSeq.getLength();
- aSeq.realloc( nIDInd + 1 );
- }
+ if ( nIDInd != -1 && !bReplace )
+ throw container::ElementExistException(); // TODO
- aSeq[nIDInd].realloc( aEntry.getLength() + 1 );
+ if ( nIDInd == -1 )
+ {
+ nIDInd = aSeq.getLength();
+ aSeq.realloc( nIDInd + 1 );
+ }
- aSeq[nIDInd][0].First = aIDTag;
- aSeq[nIDInd][0].Second = sID;
- sal_Int32 nIndTarget = 1;
- for ( sal_Int32 nIndOrig = 0;
- nIndOrig < aEntry.getLength();
- nIndOrig++ )
- {
- if ( aEntry[nIndOrig].First != aIDTag )
- aSeq[nIDInd][nIndTarget++] = aEntry[nIndOrig];
- }
+ aSeq[nIDInd].realloc( aEntry.getLength() + 1 );
- aSeq[nIDInd].realloc( nIndTarget );
+ aSeq[nIDInd][0].First = aIDTag;
+ aSeq[nIDInd][0].Second = sID;
+ sal_Int32 nIndTarget = 1;
+ for ( sal_Int32 nIndOrig = 0;
+ nIndOrig < aEntry.getLength();
+ nIndOrig++ )
+ {
+ if ( aEntry[nIndOrig].First != aIDTag )
+ aSeq[nIDInd][nIndTarget++] = aEntry[nIndOrig];
}
- else
- throw container::ElementExistException(); // TODO
+
+ aSeq[nIDInd].realloc( nIndTarget );
m_pImpl->m_aNewRelInfo = aSeq;
m_pImpl->m_xNewRelInfoStream.clear();
@@ -2901,26 +2894,24 @@ void SAL_CALL OWriteStream::setPropertyValue( const OUString& aPropertyName, con
&& aPropertyName == "UseCommonStoragePasswordEncryption" )
{
bool bUseCommonEncryption = false;
- if ( aValue >>= bUseCommonEncryption )
+ if ( !(aValue >>= bUseCommonEncryption) )
+ throw lang::IllegalArgumentException(); //TODO
+
+ if ( m_bInitOnDemand && m_pImpl->m_bHasInsertedStreamOptimization )
+ {
+ // the data stream is provided to the packagestream directly
+ m_pImpl->m_bUseCommonEncryption = bUseCommonEncryption;
+ }
+ else if ( bUseCommonEncryption )
{
- if ( m_bInitOnDemand && m_pImpl->m_bHasInsertedStreamOptimization )
+ if ( !m_pImpl->m_bUseCommonEncryption )
{
- // the data stream is provided to the packagestream directly
- m_pImpl->m_bUseCommonEncryption = bUseCommonEncryption;
+ m_pImpl->SetDecrypted();
+ m_pImpl->m_bUseCommonEncryption = true;
}
- else if ( bUseCommonEncryption )
- {
- if ( !m_pImpl->m_bUseCommonEncryption )
- {
- m_pImpl->SetDecrypted();
- m_pImpl->m_bUseCommonEncryption = true;
- }
- }
- else
- m_pImpl->m_bUseCommonEncryption = false;
}
else
- throw lang::IllegalArgumentException(); //TODO
+ m_pImpl->m_bUseCommonEncryption = false;
}
else if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML && aPropertyName == aMediaTypeString )
{
@@ -2933,30 +2924,25 @@ void SAL_CALL OWriteStream::setPropertyValue( const OUString& aPropertyName, con
else if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML && aPropertyName == "RelationsInfoStream" )
{
uno::Reference< io::XInputStream > xInRelStream;
- if ( ( aValue >>= xInRelStream ) && xInRelStream.is() )
- {
- uno::Reference< io::XSeekable > xSeek( xInRelStream, uno::UNO_QUERY );
- if ( !xSeek.is() )
- {
- // currently this is an internal property that is used for optimization
- // and the stream must support XSeekable interface
- // TODO/LATER: in future it can be changed if property is used from outside
- throw lang::IllegalArgumentException(); // TODO
- }
+ if ( !( aValue >>= xInRelStream ) || !xInRelStream.is() )
+ throw lang::IllegalArgumentException(); // TODO
- m_pImpl->m_xNewRelInfoStream = xInRelStream;
- m_pImpl->m_aNewRelInfo = uno::Sequence< uno::Sequence< beans::StringPair > >();
- m_pImpl->m_nRelInfoStatus = RELINFO_CHANGED_STREAM;
- }
- else
+ uno::Reference< io::XSeekable > xSeek( xInRelStream, uno::UNO_QUERY );
+ if ( !xSeek.is() )
+ {
+ // currently this is an internal property that is used for optimization
+ // and the stream must support XSeekable interface
+ // TODO/LATER: in future it can be changed if property is used from outside
throw lang::IllegalArgumentException(); // TODO
+ }
+
+ m_pImpl->m_xNewRelInfoStream = xInRelStream;
+ m_pImpl->m_aNewRelInfo = uno::Sequence< uno::Sequence< beans::StringPair > >();
+ m_pImpl->m_nRelInfoStatus = RELINFO_CHANGED_STREAM;
}
else if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML && aPropertyName == "RelationsInfo" )
{
- if ( aValue >>= m_pImpl->m_aNewRelInfo )
- {
- }
- else
+ if ( !(aValue >>= m_pImpl->m_aNewRelInfo) )
throw lang::IllegalArgumentException(); // TODO
}
else if ( aPropertyName == "Size" )
diff --git a/package/source/xstor/xstorage.cxx b/package/source/xstor/xstorage.cxx
index 06c5ec31ae4e..9d1f77d5223a 100644
--- a/package/source/xstor/xstorage.cxx
+++ b/package/source/xstor/xstorage.cxx
@@ -927,11 +927,12 @@ uno::Sequence< uno::Sequence< beans::StringPair > > OStorage_Impl::GetAllRelatio
ReadRelInfoIfNecessary();
- if ( m_nRelInfoStatus == RELINFO_READ
- || m_nRelInfoStatus == RELINFO_CHANGED_STREAM_READ || m_nRelInfoStatus == RELINFO_CHANGED )
- return m_aRelInfo;
- else // m_nRelInfoStatus == RELINFO_CHANGED_BROKEN || m_nRelInfoStatus == RELINFO_BROKEN
+ if ( m_nRelInfoStatus != RELINFO_READ
+ && m_nRelInfoStatus != RELINFO_CHANGED_STREAM_READ
+ && m_nRelInfoStatus != RELINFO_CHANGED )
throw io::IOException( THROW_WHERE "Wrong relinfo stream!" );
+ // m_nRelInfoStatus == RELINFO_CHANGED_BROKEN || m_nRelInfoStatus == RELINFO_BROKEN
+ return m_aRelInfo;
}
void OStorage_Impl::CopyLastCommitTo( const uno::Reference< embed::XStorage >& xNewStor )
@@ -1555,24 +1556,22 @@ void OStorage_Impl::CloneStreamElement( const OUString& aStreamName,
if (!pElement->m_xStream)
OpenSubStream( pElement );
- if (pElement->m_xStream && pElement->m_xStream->m_xPackageStream.is())
- {
- // the existence of m_pAntiImpl of the child is not interesting,
- // the copy will be created internally
+ if (!pElement->m_xStream || !pElement->m_xStream->m_xPackageStream.is())
+ throw io::IOException( THROW_WHERE ); // TODO: general_error
- // usual copying is not applicable here, only last flushed version of the
- // child stream should be used for copiing. Probably the children m_xPackageStream
- // can be used as a base of a new stream, that would be copied to result
- // storage. The only problem is that some package streams can be accessed from outside
- // at the same time (now solved by wrappers that remember own position).
+ // the existence of m_pAntiImpl of the child is not interesting,
+ // the copy will be created internally
- if (bEncryptionDataProvided)
- pElement->m_xStream->GetCopyOfLastCommit(xTargetStream, aEncryptionData);
- else
- pElement->m_xStream->GetCopyOfLastCommit(xTargetStream);
- }
+ // usual copying is not applicable here, only last flushed version of the
+ // child stream should be used for copiing. Probably the children m_xPackageStream
+ // can be used as a base of a new stream, that would be copied to result
+ // storage. The only problem is that some package streams can be accessed from outside
+ // at the same time (now solved by wrappers that remember own position).
+
+ if (bEncryptionDataProvided)
+ pElement->m_xStream->GetCopyOfLastCommit(xTargetStream, aEncryptionData);
else
- throw io::IOException( THROW_WHERE ); // TODO: general_error
+ pElement->m_xStream->GetCopyOfLastCommit(xTargetStream);
}
void OStorage_Impl::RemoveStreamRelInfo( const OUString& aOriginalName )
@@ -2628,15 +2627,13 @@ void SAL_CALL OStorage::copyStorageElementLastCommitTo(
if (!pElement->m_xStorage)
m_pImpl->OpenSubStorage( pElement, embed::ElementModes::READ );
- if (pElement->m_xStorage)
- {
- // the existence of m_pAntiImpl of the child is not interesting,
- // the copy will be created internally
-
- pElement->m_xStorage->CopyLastCommitTo(xTargetStorage);
- }
- else
+ if (!pElement->m_xStorage)
throw io::IOException( THROW_WHERE ); // TODO: general_error
+
+ // the existence of m_pAntiImpl of the child is not interesting,
+ // the copy will be created internally
+
+ pElement->m_xStorage->CopyLastCommitTo(xTargetStorage);
}
catch( const embed::InvalidStorageException& rInvalidStorageException )
{
@@ -4341,37 +4338,33 @@ void SAL_CALL OStorage::setPropertyValue( const OUString& aPropertyName, const u
if ( aPropertyName == "RelationsInfoStream" )
{
uno::Reference< io::XInputStream > xInRelStream;
- if ( ( aValue >>= xInRelStream ) && xInRelStream.is() )
- {
- uno::Reference< io::XSeekable > xSeek( xInRelStream, uno::UNO_QUERY );
- if ( !xSeek.is() )
- {
- // currently this is an internal property that is used for optimization
- // and the stream must support XSeekable interface
- // TODO/LATER: in future it can be changed if property is used from outside
- throw lang::IllegalArgumentException( THROW_WHERE, uno::Reference< uno::XInterface >(), 0 );
- }
+ if ( !( aValue >>= xInRelStream ) || !xInRelStream.is() )
+ throw lang::IllegalArgumentException( THROW_WHERE, uno::Reference< uno::XInterface >(), 0 );
- m_pImpl->m_xNewRelInfoStream = xInRelStream;
- m_pImpl->m_aRelInfo = uno::Sequence< uno::Sequence< beans::StringPair > >();
- m_pImpl->m_nRelInfoStatus = RELINFO_CHANGED_STREAM;
- m_pImpl->m_bBroadcastModified = true;
- m_pImpl->m_bIsModified = true;
- }
- else
+ uno::Reference< io::XSeekable > xSeek( xInRelStream, uno::UNO_QUERY );
+ if ( !xSeek.is() )
+ {
+ // currently this is an internal property that is used for optimization
+ // and the stream must support XSeekable interface
+ // TODO/LATER: in future it can be changed if property is used from outside
throw lang::IllegalArgumentException( THROW_WHERE, uno::Reference< uno::XInterface >(), 0 );
+ }
+
+ m_pImpl->m_xNewRelInfoStream = xInRelStream;
+ m_pImpl->m_aRelInfo = uno::Sequence< uno::Sequence< beans::StringPair > >();
+ m_pImpl->m_nRelInfoStatus = RELINFO_CHANGED_STREAM;
+ m_pImpl->m_bBroadcastModified = true;
+ m_pImpl->m_bIsModified = true;
}
else if ( aPropertyName == "RelationsInfo" )
{
- if ( aValue >>= m_pImpl->m_aRelInfo )
- {
- m_pImpl->m_xNewRelInfoStream.clear();
- m_pImpl->m_nRelInfoStatus = RELINFO_CHANGED;
- m_pImpl->m_bBroadcastModified = true;
- m_pImpl->m_bIsModified = true;
- }
- else
+ if ( !(aValue >>= m_pImpl->m_aRelInfo) )
throw lang::IllegalArgumentException( THROW_WHERE, uno::Reference< uno::XInterface >(), 0 );
+
+ m_pImpl->m_xNewRelInfoStream.clear();
+ m_pImpl->m_nRelInfoStatus = RELINFO_CHANGED;
+ m_pImpl->m_bBroadcastModified = true;
+ m_pImpl->m_bIsModified = true;
}
else if ( ( m_pData->m_bIsRoot && ( aPropertyName == "URL" || aPropertyName == "RepairPackage") )
|| aPropertyName == "IsRoot" )
@@ -4738,31 +4731,29 @@ void SAL_CALL OStorage::insertRelationshipByID( const OUString& sID, const uno:
break;
}
- if ( nIDInd == -1 || bReplace )
- {
- if ( nIDInd == -1 )
- {
- nIDInd = aSeq.getLength();
- aSeq.realloc( nIDInd + 1 );
- }
+ if ( nIDInd != -1 && !bReplace )
+ throw container::ElementExistException( THROW_WHERE );
- aSeq[nIDInd].realloc( aEntry.getLength() + 1 );
+ if ( nIDInd == -1 )
+ {
+ nIDInd = aSeq.getLength();
+ aSeq.realloc( nIDInd + 1 );
+ }
- aSeq[nIDInd][0].First = aIDTag;
- aSeq[nIDInd][0].Second = sID;
- sal_Int32 nIndTarget = 1;
- for ( sal_Int32 nIndOrig = 0;
- nIndOrig < aEntry.getLength();
- nIndOrig++ )
- {
- if ( aEntry[nIndOrig].First != aIDTag )
- aSeq[nIDInd][nIndTarget++] = aEntry[nIndOrig];
- }
+ aSeq[nIDInd].realloc( aEntry.getLength() + 1 );
- aSeq[nIDInd].realloc( nIndTarget );
+ aSeq[nIDInd][0].First = aIDTag;
+ aSeq[nIDInd][0].Second = sID;
+ sal_Int32 nIndTarget = 1;
+ for ( sal_Int32 nIndOrig = 0;
+ nIndOrig < aEntry.getLength();
+ nIndOrig++ )
+ {
+ if ( aEntry[nIndOrig].First != aIDTag )
+ aSeq[nIDInd][nIndTarget++] = aEntry[nIndOrig];
}
- else
- throw container::ElementExistException( THROW_WHERE );
+
+ aSeq[nIDInd].realloc( nIndTarget );
m_pImpl->m_aRelInfo = aSeq;
m_pImpl->m_xNewRelInfoStream.clear();