summaryrefslogtreecommitdiff
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
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>
-rw-r--r--compilerplugins/clang/flatten.cxx31
-rw-r--r--io/source/acceptor/acc_pipe.cxx37
-rw-r--r--io/source/connector/ctr_pipe.cxx25
-rw-r--r--io/source/stm/odata.cxx89
-rw-r--r--io/source/stm/omark.cxx216
-rw-r--r--io/source/stm/opump.cxx13
-rw-r--r--lingucomponent/source/languageguessing/guesslang.cxx15
-rw-r--r--oox/source/ppt/comments.cxx7
-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
15 files changed, 417 insertions, 515 deletions
diff --git a/compilerplugins/clang/flatten.cxx b/compilerplugins/clang/flatten.cxx
index adcc4972fd8f..ceff258179dd 100644
--- a/compilerplugins/clang/flatten.cxx
+++ b/compilerplugins/clang/flatten.cxx
@@ -153,7 +153,7 @@ bool Flatten::rewrite(const IfStmt* ifStmt)
if (!replaceText(elseRange, thenString)) {
return false;
}
- if (!removeText(elseKeywordRange, RewriteOptions(RemoveLineIfEmpty))) {
+ if (!removeText(elseKeywordRange)) {
return false;
}
if (!replaceText(thenRange, elseString)) {
@@ -169,22 +169,24 @@ bool Flatten::rewrite(const IfStmt* ifStmt)
std::string stripOpenAndCloseBrace(std::string s)
{
size_t i = s.find("{");
- if (i != std::string::npos) {
+ if (i == std::string::npos)
+ throw "did not find {";
+
+ ++i;
+ // strip to line end
+ while (s[i] == ' ')
++i;
- // strip to line end
- while (s[i] == ' ')
- ++i;
- if (s[i] == '\n')
- ++i;
- s = s.substr(i);
- }
+ if (s[i] == '\n')
+ ++i;
+ s = s.substr(i);
+
i = s.rfind("}");
- if (i != std::string::npos) {
+ if (i == std::string::npos)
+ throw "did not find }";
+ --i;
+ while (s[i] == ' ')
--i;
- while (s[i] == ' ')
- --i;
- s = s.substr(0,i);
- }
+ s = s.substr(0,i);
return s;
}
@@ -272,7 +274,6 @@ SourceRange Flatten::extendOverComments(SourceRange range)
--p1;
startLoc = startLoc.getLocWithOffset(p1 - SM.getCharacterData( startLoc ));
- p2 += Lexer::MeasureTokenLength( endLoc, SM, compiler.getLangOpts());
// look for trailing ";"
while (*p2 == ';')
++p2;
diff --git a/io/source/acceptor/acc_pipe.cxx b/io/source/acceptor/acc_pipe.cxx
index b1395946d936..06570022aebc 100644
--- a/io/source/acceptor/acc_pipe.cxx
+++ b/io/source/acceptor/acc_pipe.cxx
@@ -70,35 +70,32 @@ namespace io_acceptor
sal_Int32 PipeConnection::read( Sequence < sal_Int8 > & aReadBytes , sal_Int32 nBytesToRead )
{
- if( ! m_nStatus )
+ if( m_nStatus )
{
- if( aReadBytes.getLength() < nBytesToRead )
- {
- aReadBytes.realloc( nBytesToRead );
- }
- sal_Int32 n = m_pipe.read( aReadBytes.getArray(), nBytesToRead );
- OSL_ASSERT( n >= 0 && n <= aReadBytes.getLength() );
- if( n < aReadBytes.getLength() )
- {
- aReadBytes.realloc( n );
- }
- return n;
- }
- else {
throw IOException();
}
+ if( aReadBytes.getLength() < nBytesToRead )
+ {
+ aReadBytes.realloc( nBytesToRead );
+ }
+ sal_Int32 n = m_pipe.read( aReadBytes.getArray(), nBytesToRead );
+ OSL_ASSERT( n >= 0 && n <= aReadBytes.getLength() );
+ if( n < aReadBytes.getLength() )
+ {
+ aReadBytes.realloc( n );
+ }
+ return n;
+
}
void PipeConnection::write( const Sequence < sal_Int8 > &seq )
{
- if( ! m_nStatus )
+ if( m_nStatus )
{
- if( m_pipe.write( seq.getConstArray() , seq.getLength() ) != seq.getLength() )
- {
- throw IOException();
- }
+ throw IOException();
}
- else {
+ if( m_pipe.write( seq.getConstArray() , seq.getLength() ) != seq.getLength() )
+ {
throw IOException();
}
}
diff --git a/io/source/connector/ctr_pipe.cxx b/io/source/connector/ctr_pipe.cxx
index aacfa48aa6e5..993836236d90 100644
--- a/io/source/connector/ctr_pipe.cxx
+++ b/io/source/connector/ctr_pipe.cxx
@@ -48,29 +48,26 @@ namespace stoc_connector {
sal_Int32 PipeConnection::read( Sequence < sal_Int8 > & aReadBytes , sal_Int32 nBytesToRead )
{
- if( ! m_nStatus )
+ if( m_nStatus )
{
- if( aReadBytes.getLength() != nBytesToRead )
- {
- aReadBytes.realloc( nBytesToRead );
- }
- return m_pipe.read( aReadBytes.getArray() , aReadBytes.getLength() );
- }
- else {
throw IOException();
}
+ if( aReadBytes.getLength() != nBytesToRead )
+ {
+ aReadBytes.realloc( nBytesToRead );
+ }
+ return m_pipe.read( aReadBytes.getArray() , aReadBytes.getLength() );
+
}
void PipeConnection::write( const Sequence < sal_Int8 > &seq )
{
- if( ! m_nStatus )
+ if( m_nStatus )
{
- if( m_pipe.write( seq.getConstArray() , seq.getLength() ) != seq.getLength() )
- {
- throw IOException();
- }
+ throw IOException();
}
- else {
+ if( m_pipe.write( seq.getConstArray() , seq.getLength() ) != seq.getLength() )
+ {
throw IOException();
}
}
diff --git a/io/source/stm/odata.cxx b/io/source/stm/odata.cxx
index 618d52ffa3f7..47a3694407ae 100644
--- a/io/source/stm/odata.cxx
+++ b/io/source/stm/odata.cxx
@@ -109,72 +109,46 @@ protected:
// XInputStream
sal_Int32 ODataInputStream::readBytes(Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead)
{
- sal_Int32 nRead;
-
- if( m_bValidStream )
- {
- nRead = m_input->readBytes( aData , nBytesToRead );
- }
- else
- {
+ if( !m_bValidStream )
+ {
throw NotConnectedException( );
}
-
+ sal_Int32 nRead = m_input->readBytes( aData , nBytesToRead );
return nRead;
}
sal_Int32 ODataInputStream::readSomeBytes(Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead)
{
- sal_Int32 nRead;
- if( m_bValidStream ) {
- nRead = m_input->readSomeBytes( aData , nMaxBytesToRead );
- }
- else {
+ if( !m_bValidStream )
throw NotConnectedException( );
- }
-
+ sal_Int32 nRead = m_input->readSomeBytes( aData , nMaxBytesToRead );
return nRead;
}
void ODataInputStream::skipBytes(sal_Int32 nBytesToSkip)
{
- if( m_bValidStream ) {
- m_input->skipBytes( nBytesToSkip );
- }
- else
- {
+ if( !m_bValidStream )
throw NotConnectedException( );
- }
+ m_input->skipBytes( nBytesToSkip );
}
sal_Int32 ODataInputStream::available()
{
- sal_Int32 nAvail;
-
- if( m_bValidStream )
- {
- nAvail = m_input->available( );
- }
- else
- {
+ if( !m_bValidStream )
throw NotConnectedException( );
- }
+ sal_Int32 nAvail = m_input->available( );
return nAvail;
}
void ODataInputStream::closeInput()
{
- if( m_bValidStream ) {
- m_input->closeInput( );
- setInputStream( Reference< XInputStream > () );
- setPredecessor( Reference < XConnectable >() );
- setSuccessor( Reference < XConnectable >() );
- m_bValidStream = false;
- }
- else
- {
+ if( !m_bValidStream )
throw NotConnectedException( );
- }
+ m_input->closeInput( );
+ setInputStream( Reference< XInputStream > () );
+ setPredecessor( Reference < XConnectable >() );
+ setSuccessor( Reference < XConnectable >() );
+ m_bValidStream = false;
}
@@ -509,42 +483,27 @@ protected:
// XOutputStream
void ODataOutputStream::writeBytes(const Sequence< sal_Int8 >& aData)
{
- if( m_bValidStream )
- {
- m_output->writeBytes( aData );
- }
- else {
+ if( !m_bValidStream )
throw NotConnectedException( );
- }
+ m_output->writeBytes( aData );
}
void ODataOutputStream::flush()
{
- if( m_bValidStream )
- {
- m_output->flush();
- }
- else
- {
+ if( !m_bValidStream )
throw NotConnectedException();
- }
-
+ m_output->flush();
}
void ODataOutputStream::closeOutput()
{
- if( m_bValidStream )
- {
- m_output->closeOutput();
- setOutputStream( Reference< XOutputStream > () );
- setPredecessor( Reference < XConnectable >() );
- setSuccessor( Reference < XConnectable >() );
- }
- else
- {
+ if( !m_bValidStream )
throw NotConnectedException();
- }
+ m_output->closeOutput();
+ setOutputStream( Reference< XOutputStream > () );
+ setPredecessor( Reference < XConnectable >() );
+ setSuccessor( Reference < XConnectable >() );
}
// XDataOutputStream
diff --git a/io/source/stm/omark.cxx b/io/source/stm/omark.cxx
index 4dff49e4c0de..33cc84bfdf8d 100644
--- a/io/source/stm/omark.cxx
+++ b/io/source/stm/omark.cxx
@@ -137,22 +137,21 @@ OMarkableOutputStream::OMarkableOutputStream( )
// XOutputStream
void OMarkableOutputStream::writeBytes(const Sequence< sal_Int8 >& aData)
{
- if( m_bValidStream ) {
- if( m_mapMarks.empty() && ( m_pBuffer->getSize() == 0 ) ) {
- // no mark and buffer active, simple write through
- m_output->writeBytes( aData );
- }
- else {
- MutexGuard guard( m_mutex );
- // new data must be buffered
- m_pBuffer->writeAt( m_nCurrentPos , aData );
- m_nCurrentPos += aData.getLength();
- checkMarksAndFlush();
- }
+ if( !m_bValidStream ) {
+ throw NotConnectedException();
+ }
+ if( m_mapMarks.empty() && ( m_pBuffer->getSize() == 0 ) ) {
+ // no mark and buffer active, simple write through
+ m_output->writeBytes( aData );
}
else {
- throw NotConnectedException();
+ MutexGuard guard( m_mutex );
+ // new data must be buffered
+ m_pBuffer->writeAt( m_nCurrentPos , aData );
+ m_nCurrentPos += aData.getLength();
+ checkMarksAndFlush();
}
+
}
void OMarkableOutputStream::flush()
@@ -174,26 +173,25 @@ void OMarkableOutputStream::flush()
void OMarkableOutputStream::closeOutput()
{
- if( m_bValidStream ) {
- MutexGuard guard( m_mutex );
- // all marks must be cleared and all
+ if( !m_bValidStream ) {
+ throw NotConnectedException();
+ }
+ MutexGuard guard( m_mutex );
+ // all marks must be cleared and all
- if( ! m_mapMarks.empty() )
- {
- m_mapMarks.clear();
- }
- m_nCurrentPos = m_pBuffer->getSize();
- checkMarksAndFlush();
+ if( ! m_mapMarks.empty() )
+ {
+ m_mapMarks.clear();
+ }
+ m_nCurrentPos = m_pBuffer->getSize();
+ checkMarksAndFlush();
- m_output->closeOutput();
+ m_output->closeOutput();
+
+ setOutputStream( Reference< XOutputStream > () );
+ setPredecessor( Reference < XConnectable >() );
+ setSuccessor( Reference< XConnectable > () );
- setOutputStream( Reference< XOutputStream > () );
- setPredecessor( Reference < XConnectable >() );
- setSuccessor( Reference< XConnectable > () );
- }
- else {
- throw NotConnectedException();
- }
}
@@ -474,43 +472,42 @@ sal_Int32 OMarkableInputStream::readBytes(Sequence< sal_Int8 >& aData, sal_Int32
{
sal_Int32 nBytesRead;
- if( m_bValidStream ) {
- MutexGuard guard( m_mutex );
- if( m_mapMarks.empty() && ! m_pBuffer->getSize() ) {
- // normal read !
- nBytesRead = m_input->readBytes( aData, nBytesToRead );
- }
- else {
- // read from buffer
- sal_Int32 nRead;
+ if( !m_bValidStream ) {
+ throw NotConnectedException(
+ "MarkableInputStream::readBytes NotConnectedException",
+ *this );
+ }
+ MutexGuard guard( m_mutex );
+ if( m_mapMarks.empty() && ! m_pBuffer->getSize() ) {
+ // normal read !
+ nBytesRead = m_input->readBytes( aData, nBytesToRead );
+ }
+ else {
+ // read from buffer
+ sal_Int32 nRead;
- // read enough bytes into buffer
- if( m_pBuffer->getSize() - m_nCurrentPos < nBytesToRead ) {
- sal_Int32 nToRead = nBytesToRead - ( m_pBuffer->getSize() - m_nCurrentPos );
- nRead = m_input->readBytes( aData , nToRead );
+ // read enough bytes into buffer
+ if( m_pBuffer->getSize() - m_nCurrentPos < nBytesToRead ) {
+ sal_Int32 nToRead = nBytesToRead - ( m_pBuffer->getSize() - m_nCurrentPos );
+ nRead = m_input->readBytes( aData , nToRead );
- OSL_ASSERT( aData.getLength() == nRead );
+ OSL_ASSERT( aData.getLength() == nRead );
- m_pBuffer->writeAt( m_pBuffer->getSize() , aData );
+ m_pBuffer->writeAt( m_pBuffer->getSize() , aData );
- if( nRead < nToRead ) {
- nBytesToRead = nBytesToRead - (nToRead-nRead);
- }
+ if( nRead < nToRead ) {
+ nBytesToRead = nBytesToRead - (nToRead-nRead);
}
+ }
- OSL_ASSERT( m_pBuffer->getSize() - m_nCurrentPos >= nBytesToRead );
+ OSL_ASSERT( m_pBuffer->getSize() - m_nCurrentPos >= nBytesToRead );
- m_pBuffer->readAt( m_nCurrentPos , aData , nBytesToRead );
+ m_pBuffer->readAt( m_nCurrentPos , aData , nBytesToRead );
- m_nCurrentPos += nBytesToRead;
- nBytesRead = nBytesToRead;
- }
- }
- else {
- throw NotConnectedException(
- "MarkableInputStream::readBytes NotConnectedException",
- *this );
+ m_nCurrentPos += nBytesToRead;
+ nBytesRead = nBytesToRead;
}
+
return nBytesRead;
}
@@ -519,46 +516,45 @@ sal_Int32 OMarkableInputStream::readSomeBytes(Sequence< sal_Int8 >& aData, sal_I
{
sal_Int32 nBytesRead;
- if( m_bValidStream ) {
- MutexGuard guard( m_mutex );
- if( m_mapMarks.empty() && ! m_pBuffer->getSize() ) {
- // normal read !
- nBytesRead = m_input->readSomeBytes( aData, nMaxBytesToRead );
+ if( !m_bValidStream ) {
+ throw NotConnectedException(
+ "MarkableInputStream::readSomeBytes NotConnectedException",
+ *this );
+ }
+
+ MutexGuard guard( m_mutex );
+ if( m_mapMarks.empty() && ! m_pBuffer->getSize() ) {
+ // normal read !
+ nBytesRead = m_input->readSomeBytes( aData, nMaxBytesToRead );
+ }
+ else {
+ // read from buffer
+ sal_Int32 nRead = 0;
+ sal_Int32 nInBuffer = m_pBuffer->getSize() - m_nCurrentPos;
+ sal_Int32 nAdditionalBytesToRead = Min(nMaxBytesToRead-nInBuffer,m_input->available());
+ nAdditionalBytesToRead = Max(0 , nAdditionalBytesToRead );
+
+ // read enough bytes into buffer
+ if( 0 == nInBuffer ) {
+ nRead = m_input->readSomeBytes( aData , nMaxBytesToRead );
+ }
+ else if( nAdditionalBytesToRead ) {
+ nRead = m_input->readBytes( aData , nAdditionalBytesToRead );
}
- else {
- // read from buffer
- sal_Int32 nRead = 0;
- sal_Int32 nInBuffer = m_pBuffer->getSize() - m_nCurrentPos;
- sal_Int32 nAdditionalBytesToRead = Min(nMaxBytesToRead-nInBuffer,m_input->available());
- nAdditionalBytesToRead = Max(0 , nAdditionalBytesToRead );
-
- // read enough bytes into buffer
- if( 0 == nInBuffer ) {
- nRead = m_input->readSomeBytes( aData , nMaxBytesToRead );
- }
- else if( nAdditionalBytesToRead ) {
- nRead = m_input->readBytes( aData , nAdditionalBytesToRead );
- }
- if( nRead ) {
- aData.realloc( nRead );
- m_pBuffer->writeAt( m_pBuffer->getSize() , aData );
- }
+ if( nRead ) {
+ aData.realloc( nRead );
+ m_pBuffer->writeAt( m_pBuffer->getSize() , aData );
+ }
- nBytesRead = Min( nMaxBytesToRead , nInBuffer + nRead );
+ nBytesRead = Min( nMaxBytesToRead , nInBuffer + nRead );
- // now take everything from buffer !
- m_pBuffer->readAt( m_nCurrentPos , aData , nBytesRead );
+ // now take everything from buffer !
+ m_pBuffer->readAt( m_nCurrentPos , aData , nBytesRead );
- m_nCurrentPos += nBytesRead;
- }
- }
- else
- {
- throw NotConnectedException(
- "MarkableInputStream::readSomeBytes NotConnectedException",
- *this );
+ m_nCurrentPos += nBytesRead;
}
+
return nBytesRead;
@@ -580,42 +576,36 @@ void OMarkableInputStream::skipBytes(sal_Int32 nBytesToSkip)
sal_Int32 OMarkableInputStream::available()
{
- sal_Int32 nAvail;
- if( m_bValidStream ) {
- MutexGuard guard( m_mutex );
- nAvail = m_input->available() + ( m_pBuffer->getSize() - m_nCurrentPos );
- }
- else
- {
+ if( !m_bValidStream ) {
throw NotConnectedException(
"MarkableInputStream::available NotConnectedException",
*this );
}
+ MutexGuard guard( m_mutex );
+ sal_Int32 nAvail = m_input->available() + ( m_pBuffer->getSize() - m_nCurrentPos );
return nAvail;
}
void OMarkableInputStream::closeInput()
{
- if( m_bValidStream ) {
- MutexGuard guard( m_mutex );
-
- m_input->closeInput();
-
- setInputStream( Reference< XInputStream > () );
- setPredecessor( Reference< XConnectable > () );
- setSuccessor( Reference< XConnectable >() );
-
- m_pBuffer.reset();
- m_nCurrentPos = 0;
- m_nCurrentMark = 0;
- }
- else {
+ if( !m_bValidStream ) {
throw NotConnectedException(
"MarkableInputStream::closeInput NotConnectedException",
*this );
}
+ MutexGuard guard( m_mutex );
+
+ m_input->closeInput();
+
+ setInputStream( Reference< XInputStream > () );
+ setPredecessor( Reference< XConnectable > () );
+ setSuccessor( Reference< XConnectable >() );
+
+ m_pBuffer.reset();
+ m_nCurrentPos = 0;
+ m_nCurrentMark = 0;
}
// XMarkable
diff --git a/io/source/stm/opump.cxx b/io/source/stm/opump.cxx
index b00ccf3319d9..cf8a356901e8 100644
--- a/io/source/stm/opump.cxx
+++ b/io/source/stm/opump.cxx
@@ -354,18 +354,17 @@ void Pump::start()
{
Guard< Mutex > aGuard( m_aMutex );
m_aThread = osl_createSuspendedThread(Pump::static_run,this);
- if( m_aThread )
- {
- // will be released by OPump::static_run
- acquire();
- osl_resumeThread( m_aThread );
- }
- else
+ if( !m_aThread )
{
throw RuntimeException(
"Pump::start Couldn't create worker thread",
*this);
}
+
+ // will be released by OPump::static_run
+ acquire();
+ osl_resumeThread( m_aThread );
+
}
diff --git a/lingucomponent/source/languageguessing/guesslang.cxx b/lingucomponent/source/languageguessing/guesslang.cxx
index 85e041813205..a6469ec4063a 100644
--- a/lingucomponent/source/languageguessing/guesslang.cxx
+++ b/lingucomponent/source/languageguessing/guesslang.cxx
@@ -173,17 +173,14 @@ Locale SAL_CALL LangGuess_Impl::guessPrimaryLanguage(
EnsureInitialized();
- lang::Locale aRes;
- if (nStartPos >=0 && nLen >= 0 && nStartPos + nLen <= rText.getLength())
- {
- OString o( OUStringToOString( rText.copy(nStartPos, nLen), RTL_TEXTENCODING_UTF8 ) );
- Guess g = m_aGuesser.GuessPrimaryLanguage(o.getStr());
- aRes.Language = OUString::createFromAscii( g.GetLanguage().c_str() );
- aRes.Country = OUString::createFromAscii( g.GetCountry().c_str() );
- }
- else
+ if (nStartPos < 0 || nLen < 0 || nStartPos + nLen > rText.getLength())
throw lang::IllegalArgumentException();
+ OString o( OUStringToOString( rText.copy(nStartPos, nLen), RTL_TEXTENCODING_UTF8 ) );
+ Guess g = m_aGuesser.GuessPrimaryLanguage(o.getStr());
+ lang::Locale aRes;
+ aRes.Language = OUString::createFromAscii( g.GetLanguage().c_str() );
+ aRes.Country = OUString::createFromAscii( g.GetCountry().c_str() );
return aRes;
}
diff --git a/oox/source/ppt/comments.cxx b/oox/source/ppt/comments.cxx
index 965a7ef658b0..9f9a8fe7977c 100644
--- a/oox/source/ppt/comments.cxx
+++ b/oox/source/ppt/comments.cxx
@@ -76,10 +76,11 @@ OUString Comment::getAuthor ( const CommentAuthorList& list )
const Comment& CommentList::getCommentAtIndex (int index)
{
- if(index < (int)cmLst.size() && index >= 0)
- return cmLst.at(index);
- else
+ if(index >= (int)cmLst.size() || index < 0)
throw css::lang::IllegalArgumentException();
+
+ return cmLst.at(index)
+;
}
} }
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 );