summaryrefslogtreecommitdiff
path: root/package
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
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')
-rw-r--r--package/source/xstor/owriteablestream.cxx134
-rw-r--r--package/source/xstor/xstorage.cxx137
-rw-r--r--package/source/zipapi/ByteGrabber.cxx30
-rw-r--r--package/source/zipapi/XUnbufferedStream.cxx59
-rw-r--r--package/source/zippackage/ZipPackage.cxx10
-rw-r--r--package/source/zippackage/ZipPackageFolder.cxx42
-rw-r--r--package/source/zippackage/ZipPackageStream.cxx87
7 files changed, 230 insertions, 269 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();
diff --git a/package/source/zipapi/ByteGrabber.cxx b/package/source/zipapi/ByteGrabber.cxx
index 0818f1ecd09e..89e22c368851 100644
--- a/package/source/zipapi/ByteGrabber.cxx
+++ b/package/source/zipapi/ByteGrabber.cxx
@@ -64,35 +64,33 @@ sal_Int32 SAL_CALL ByteGrabber::readBytes( uno::Sequence< sal_Int8 >& aData,
void SAL_CALL ByteGrabber::seek( sal_Int64 location )
{
::osl::MutexGuard aGuard( m_aMutex );
- if (xSeek.is() )
- {
- sal_Int64 nLen = xSeek->getLength();
- if ( location < 0 || location > nLen )
- throw lang::IllegalArgumentException(THROW_WHERE, uno::Reference< uno::XInterface >(), 1 );
- if (location > nLen )
- location = nLen;
- xSeek->seek( location );
- }
- else
+ if (!xSeek.is() )
throw io::IOException(THROW_WHERE );
+
+ sal_Int64 nLen = xSeek->getLength();
+ if ( location < 0 || location > nLen )
+ throw lang::IllegalArgumentException(THROW_WHERE, uno::Reference< uno::XInterface >(), 1 );
+ if (location > nLen )
+ location = nLen;
+ xSeek->seek( location );
}
sal_Int64 SAL_CALL ByteGrabber::getPosition( )
{
::osl::MutexGuard aGuard( m_aMutex );
- if (xSeek.is() )
- return xSeek->getPosition();
- else
+ if (!xSeek.is() )
throw io::IOException(THROW_WHERE );
+
+ return xSeek->getPosition();
}
sal_Int64 SAL_CALL ByteGrabber::getLength( )
{
::osl::MutexGuard aGuard( m_aMutex );
- if (xSeek.is() )
- return xSeek->getLength();
- else
+ if (!xSeek.is() )
throw io::IOException(THROW_WHERE );
+
+ return xSeek->getLength();
}
sal_uInt16 ByteGrabber::ReadUInt16()
diff --git a/package/source/zipapi/XUnbufferedStream.cxx b/package/source/zipapi/XUnbufferedStream.cxx
index d300abefcd97..0292217d966f 100644
--- a/package/source/zipapi/XUnbufferedStream.cxx
+++ b/package/source/zipapi/XUnbufferedStream.cxx
@@ -233,45 +233,44 @@ sal_Int32 SAL_CALL XUnbufferedStream::readBytes( Sequence< sal_Int8 >& aData, sa
throw ZipIOException("Dictionaries are not supported!" );
sal_Int32 nDiff = static_cast< sal_Int32 >( mnZipEnd - mnZipCurrent );
- if ( nDiff > 0 )
+ if ( nDiff <= 0 )
{
- mxZipSeek->seek ( mnZipCurrent );
+ throw ZipIOException("The stream seems to be broken!" );
+ }
- sal_Int32 nToRead = std::max( nRequestedBytes, static_cast< sal_Int32 >( 8192 ) );
- if ( mnBlockSize > 1 )
- nToRead = nToRead + mnBlockSize - nToRead % mnBlockSize;
- nToRead = std::min( nDiff, nToRead );
+ mxZipSeek->seek ( mnZipCurrent );
- sal_Int32 nZipRead = mxZipStream->readBytes( maCompBuffer, nToRead );
- if ( nZipRead < nToRead )
- throw ZipIOException("No expected data!" );
+ sal_Int32 nToRead = std::max( nRequestedBytes, static_cast< sal_Int32 >( 8192 ) );
+ if ( mnBlockSize > 1 )
+ nToRead = nToRead + mnBlockSize - nToRead % mnBlockSize;
+ nToRead = std::min( nDiff, nToRead );
- mnZipCurrent += nZipRead;
- // maCompBuffer now has the data, check if we need to decrypt
- // before passing to the Inflater
- if ( m_xCipherContext.is() )
- {
- if ( mbCheckCRC )
- maCRC.update( maCompBuffer );
+ sal_Int32 nZipRead = mxZipStream->readBytes( maCompBuffer, nToRead );
+ if ( nZipRead < nToRead )
+ throw ZipIOException("No expected data!" );
- maCompBuffer = m_xCipherContext->convertWithCipherContext( maCompBuffer );
- if ( mnZipCurrent == mnZipEnd )
+ mnZipCurrent += nZipRead;
+ // maCompBuffer now has the data, check if we need to decrypt
+ // before passing to the Inflater
+ if ( m_xCipherContext.is() )
+ {
+ if ( mbCheckCRC )
+ maCRC.update( maCompBuffer );
+
+ maCompBuffer = m_xCipherContext->convertWithCipherContext( maCompBuffer );
+ if ( mnZipCurrent == mnZipEnd )
+ {
+ uno::Sequence< sal_Int8 > aSuffix = m_xCipherContext->finalizeCipherContextAndDispose();
+ if ( aSuffix.getLength() )
{
- uno::Sequence< sal_Int8 > aSuffix = m_xCipherContext->finalizeCipherContextAndDispose();
- if ( aSuffix.getLength() )
- {
- sal_Int32 nOldLen = maCompBuffer.getLength();
- maCompBuffer.realloc( nOldLen + aSuffix.getLength() );
- memcpy( maCompBuffer.getArray() + nOldLen, aSuffix.getConstArray(), aSuffix.getLength() );
- }
+ sal_Int32 nOldLen = maCompBuffer.getLength();
+ maCompBuffer.realloc( nOldLen + aSuffix.getLength() );
+ memcpy( maCompBuffer.getArray() + nOldLen, aSuffix.getConstArray(), aSuffix.getLength() );
}
}
- maInflater.setInput ( maCompBuffer );
- }
- else
- {
- throw ZipIOException("The stream seems to be broken!" );
}
+ maInflater.setInput ( maCompBuffer );
+
}
}
diff --git a/package/source/zippackage/ZipPackage.cxx b/package/source/zippackage/ZipPackage.cxx
index d91c0785304c..cfdfde131120 100644
--- a/package/source/zippackage/ZipPackage.cxx
+++ b/package/source/zippackage/ZipPackage.cxx
@@ -809,13 +809,11 @@ Any SAL_CALL ZipPackage::getByHierarchicalName( const OUString& aName )
sTemp = aName.copy ( nOldIndex, nIndex - nOldIndex );
if ( nIndex == nOldIndex )
break;
- if ( pCurrent->hasByName( sTemp ) )
- {
- pPrevious = pCurrent;
- pCurrent = pCurrent->doGetByName( sTemp ).pFolder;
- }
- else
+ if ( !pCurrent->hasByName( sTemp ) )
throw NoSuchElementException(THROW_WHERE );
+
+ pPrevious = pCurrent;
+ pCurrent = pCurrent->doGetByName( sTemp ).pFolder;
nOldIndex = nIndex+1;
}
diff --git a/package/source/zippackage/ZipPackageFolder.cxx b/package/source/zippackage/ZipPackageFolder.cxx
index 5d110278c674..5d75838cfd3c 100644
--- a/package/source/zippackage/ZipPackageFolder.cxx
+++ b/package/source/zippackage/ZipPackageFolder.cxx
@@ -173,29 +173,27 @@ void SAL_CALL ZipPackageFolder::insertByName( const OUString& aName, const uno::
{
uno::Reference < XUnoTunnel > xRef;
aElement >>= xRef;
- if ( aElement >>= xRef )
- {
- sal_Int64 nTest;
- ZipPackageEntry *pEntry;
- if ( ( nTest = xRef->getSomething ( ZipPackageFolder::static_getImplementationId() ) ) != 0 )
- {
- ZipPackageFolder *pFolder = reinterpret_cast < ZipPackageFolder * > ( nTest );
- pEntry = static_cast < ZipPackageEntry * > ( pFolder );
- }
- else if ( ( nTest = xRef->getSomething ( ZipPackageStream::static_getImplementationId() ) ) != 0 )
- {
- ZipPackageStream *pStream = reinterpret_cast < ZipPackageStream * > ( nTest );
- pEntry = static_cast < ZipPackageEntry * > ( pStream );
- }
- else
- throw IllegalArgumentException(THROW_WHERE, uno::Reference< uno::XInterface >(), 0 );
+ if ( !(aElement >>= xRef) )
+ throw IllegalArgumentException(THROW_WHERE, uno::Reference< uno::XInterface >(), 0 );
- if (pEntry->getName() != aName )
- pEntry->setName (aName);
- doInsertByName ( pEntry, true );
+ sal_Int64 nTest;
+ ZipPackageEntry *pEntry;
+ if ( ( nTest = xRef->getSomething ( ZipPackageFolder::static_getImplementationId() ) ) != 0 )
+ {
+ ZipPackageFolder *pFolder = reinterpret_cast < ZipPackageFolder * > ( nTest );
+ pEntry = static_cast < ZipPackageEntry * > ( pFolder );
+ }
+ else if ( ( nTest = xRef->getSomething ( ZipPackageStream::static_getImplementationId() ) ) != 0 )
+ {
+ ZipPackageStream *pStream = reinterpret_cast < ZipPackageStream * > ( nTest );
+ pEntry = static_cast < ZipPackageEntry * > ( pStream );
}
else
throw IllegalArgumentException(THROW_WHERE, uno::Reference< uno::XInterface >(), 0 );
+
+ if (pEntry->getName() != aName )
+ pEntry->setName (aName);
+ doInsertByName ( pEntry, true );
}
}
void SAL_CALL ZipPackageFolder::removeByName( const OUString& Name )
@@ -249,10 +247,10 @@ sal_Bool SAL_CALL ZipPackageFolder::hasByName( const OUString& aName )
// XNameReplace
void SAL_CALL ZipPackageFolder::replaceByName( const OUString& aName, const uno::Any& aElement )
{
- if ( hasByName( aName ) )
- removeByName( aName );
- else
+ if ( !hasByName( aName ) )
throw NoSuchElementException(THROW_WHERE );
+
+ removeByName( aName );
insertByName(aName, aElement);
}
diff --git a/package/source/zippackage/ZipPackageStream.cxx b/package/source/zippackage/ZipPackageStream.cxx
index 460e33f0e245..00efe9cf2610 100644
--- a/package/source/zippackage/ZipPackageStream.cxx
+++ b/package/source/zippackage/ZipPackageStream.cxx
@@ -1161,22 +1161,19 @@ void SAL_CALL ZipPackageStream::setPropertyValue( const OUString& aPropertyName,
if ( m_rZipPackage.getFormat() != embed::StorageFormats::PACKAGE && m_rZipPackage.getFormat() != embed::StorageFormats::OFOPXML )
throw beans::PropertyVetoException(THROW_WHERE );
- if ( aValue >>= msMediaType )
- {
- if ( !msMediaType.isEmpty() )
- {
- if ( msMediaType.indexOf ( "text" ) != -1
- || msMediaType == "application/vnd.sun.star.oleobject" )
- m_bToBeCompressed = true;
- else if ( !m_bCompressedIsSetFromOutside )
- m_bToBeCompressed = false;
- }
- }
- else
+ if ( !(aValue >>= msMediaType) )
throw IllegalArgumentException(THROW_WHERE "MediaType must be a string!",
uno::Reference< XInterface >(),
2 );
+ if ( !msMediaType.isEmpty() )
+ {
+ if ( msMediaType.indexOf ( "text" ) != -1
+ || msMediaType == "application/vnd.sun.star.oleobject" )
+ m_bToBeCompressed = true;
+ else if ( !m_bCompressedIsSetFromOutside )
+ m_bToBeCompressed = false;
+ }
}
else if ( aPropertyName == "Size" )
{
@@ -1191,23 +1188,21 @@ void SAL_CALL ZipPackageStream::setPropertyValue( const OUString& aPropertyName,
throw beans::PropertyVetoException(THROW_WHERE );
bool bEnc = false;
- if ( aValue >>= bEnc )
- {
- // In case of new raw stream, the stream must not be encrypted on storing
- if ( bEnc && m_nStreamMode == PACKAGE_STREAM_RAW )
- throw IllegalArgumentException(THROW_WHERE "Raw stream can not be encrypted on storing",
- uno::Reference< XInterface >(),
- 2 );
-
- m_bToBeEncrypted = bEnc;
- if ( m_bToBeEncrypted && !m_xBaseEncryptionData.is() )
- m_xBaseEncryptionData = new BaseEncryptionData;
- }
- else
+ if ( !(aValue >>= bEnc) )
throw IllegalArgumentException(THROW_WHERE "Wrong type for Encrypted property!",
uno::Reference< XInterface >(),
2 );
+ // In case of new raw stream, the stream must not be encrypted on storing
+ if ( bEnc && m_nStreamMode == PACKAGE_STREAM_RAW )
+ throw IllegalArgumentException(THROW_WHERE "Raw stream can not be encrypted on storing",
+ uno::Reference< XInterface >(),
+ 2 );
+
+ m_bToBeEncrypted = bEnc;
+ if ( m_bToBeEncrypted && !m_xBaseEncryptionData.is() )
+ m_xBaseEncryptionData = new BaseEncryptionData;
+
}
else if ( aPropertyName == ENCRYPTION_KEY_PROPERTY )
{
@@ -1219,20 +1214,18 @@ void SAL_CALL ZipPackageStream::setPropertyValue( const OUString& aPropertyName,
if ( !( aValue >>= aNewKey ) )
{
OUString sTempString;
- if ( aValue >>= sTempString )
- {
- sal_Int32 nPathLength = sTempString.getLength();
- Sequence < sal_Int8 > aSequence ( nPathLength );
- sal_Int8 *pArray = aSequence.getArray();
- const sal_Unicode *pChar = sTempString.getStr();
- for ( sal_Int32 i = 0; i < nPathLength; i++ )
- pArray[i] = static_cast < sal_Int8 > ( pChar[i] );
- aNewKey = aSequence;
- }
- else
+ if ( !(aValue >>= sTempString) )
throw IllegalArgumentException(THROW_WHERE "Wrong type for EncryptionKey property!",
uno::Reference< XInterface >(),
2 );
+
+ sal_Int32 nPathLength = sTempString.getLength();
+ Sequence < sal_Int8 > aSequence ( nPathLength );
+ sal_Int8 *pArray = aSequence.getArray();
+ const sal_Unicode *pChar = sTempString.getStr();
+ for ( sal_Int32 i = 0; i < nPathLength; i++ )
+ pArray[i] = static_cast < sal_Int8 > ( pChar[i] );
+ aNewKey = aSequence;
}
if ( aNewKey.getLength() )
@@ -1291,21 +1284,19 @@ void SAL_CALL ZipPackageStream::setPropertyValue( const OUString& aPropertyName,
{
bool bCompr = false;
- if ( aValue >>= bCompr )
- {
- // In case of new raw stream, the stream must not be encrypted on storing
- if ( bCompr && m_nStreamMode == PACKAGE_STREAM_RAW )
- throw IllegalArgumentException(THROW_WHERE "Raw stream can not be encrypted on storing",
- uno::Reference< XInterface >(),
- 2 );
-
- m_bToBeCompressed = bCompr;
- m_bCompressedIsSetFromOutside = true;
- }
- else
+ if ( !(aValue >>= bCompr) )
throw IllegalArgumentException(THROW_WHERE "Wrong type for Compressed property!",
uno::Reference< XInterface >(),
2 );
+
+ // In case of new raw stream, the stream must not be encrypted on storing
+ if ( bCompr && m_nStreamMode == PACKAGE_STREAM_RAW )
+ throw IllegalArgumentException(THROW_WHERE "Raw stream can not be encrypted on storing",
+ uno::Reference< XInterface >(),
+ 2 );
+
+ m_bToBeCompressed = bCompr;
+ m_bCompressedIsSetFromOutside = true;
}
else
throw beans::UnknownPropertyException(THROW_WHERE );