summaryrefslogtreecommitdiff
path: root/package/source
diff options
context:
space:
mode:
Diffstat (limited to 'package/source')
-rw-r--r--package/source/zipapi/EntryInputStream.cxx11
-rw-r--r--package/source/zipapi/ZipFile.cxx200
-rw-r--r--package/source/zipapi/ZipOutputStream.cxx8
-rw-r--r--package/source/zippackage/ZipPackage.cxx222
-rw-r--r--package/source/zippackage/ZipPackageFolder.cxx118
-rw-r--r--package/source/zippackage/ZipPackageStream.cxx20
6 files changed, 318 insertions, 261 deletions
diff --git a/package/source/zipapi/EntryInputStream.cxx b/package/source/zipapi/EntryInputStream.cxx
index 9b2db8274454..ed198aac5882 100644
--- a/package/source/zipapi/EntryInputStream.cxx
+++ b/package/source/zipapi/EntryInputStream.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: EntryInputStream.cxx,v $
*
- * $Revision: 1.5 $
+ * $Revision: 1.6 $
*
- * last change: $Author: mtg $ $Date: 2000-12-01 10:49:47 $
+ * last change: $Author: mtg $ $Date: 2000-12-04 11:30:08 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -76,7 +76,7 @@ using namespace com::sun::star;
* seek to it before performing any reads.
*/
-EntryInputStream::EntryInputStream( uno::Reference < io::XInputStream > xNewInput, sal_Int64 nNewBegin, sal_Int64 nNewEnd, sal_Int32 nNewBufferSize, sal_Int64 nUncompressedSize)
+EntryInputStream::EntryInputStream( uno::Reference < io::XInputStream > xNewInput, sal_Int64 nNewBegin, sal_Int64 nNewEnd, sal_Int32 nNewBufferSize, sal_Int64 nUncompressedSize, sal_Bool bIsDeflated)
: xStream( xNewInput )
, xSeek( xNewInput, uno::UNO_QUERY )
, nCompBegin( nNewBegin )
@@ -89,11 +89,8 @@ EntryInputStream::EntryInputStream( uno::Reference < io::XInputStream > xNewInpu
, bReachEOF ( sal_False )
, aInflater( sal_True )
, aBuffer( static_cast < sal_Int32 > (nUncompressedSize) )
+, bDeflated ( bIsDeflated )
{
- if (nCompEnd - nCompBegin < nUncompressedSize)
- bDeflated = sal_True;
- else
- bDeflated = sal_False;
if (bDeflated)
{
xSeek->seek(nNewBegin);
diff --git a/package/source/zipapi/ZipFile.cxx b/package/source/zipapi/ZipFile.cxx
index 23741016d3fb..b1f034698ff3 100644
--- a/package/source/zipapi/ZipFile.cxx
+++ b/package/source/zipapi/ZipFile.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: ZipFile.cxx,v $
*
- * $Revision: 1.10 $
+ * $Revision: 1.11 $
*
- * last change: $Author: mtg $ $Date: 2000-12-01 11:39:30 $
+ * last change: $Author: mtg $ $Date: 2000-12-04 11:30:08 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -70,16 +70,20 @@ using namespace com::sun::star::package::ZipConstants;
/** This class is used to read entries from a zip file
*/
ZipFile::ZipFile (uno::Reference < io::XInputStream > &xInput)
+ throw(io::IOException, package::ZipException, uno::RuntimeException)
: xStream(xInput)
, aGrabber(xInput)
-/*, pTable(NULL)
-, nTotal(0)
-, nTableLen(0)
-*/
{
readCEN();
}
-
+ZipFile::ZipFile( com::sun::star::uno::Reference < com::sun::star::io::XInputStream > &xInput, sal_Bool bInitialise)
+ throw(io::IOException, package::ZipException, uno::RuntimeException)
+: xStream(xInput)
+, aGrabber(xInput)
+{
+ if (bInitialise)
+ readCEN();
+}
void ZipFile::updateFromManList(std::vector < ManifestEntry * > &rManList)
{
@@ -107,24 +111,8 @@ void ZipFile::updateFromManList(std::vector < ManifestEntry * > &rManList)
ZipFile::~ZipFile()
{
- /*
- if (pEntries != NULL)
- delete []pEntries;
- if (pTable != NULL)
- {
- ZipEntryImpl* pTmp = NULL;
- for (int i =0; i < nTableLen; i++)
- {
- while ((pTmp = pTable[i]) != NULL)
- {
- pTable[i] = pTmp->pNext;
- delete pTmp;
- }
- }
- delete []pTable;
- }
- */
}
+
void SAL_CALL ZipFile::close( )
throw(io::IOException, uno::RuntimeException)
{
@@ -133,17 +121,16 @@ void SAL_CALL ZipFile::close( )
uno::Reference< container::XEnumeration > SAL_CALL ZipFile::entries( )
throw(uno::RuntimeException)
{
- uno::Reference< container::XEnumeration> xEnumRef;
- xEnumRef= new ZipEnumeration( aEntries );
- //xEnumRef = uno::Reference < container::XEnumeration>( (OWeakObject*) pEnum, uno::UNO_QUERY );
-// xEnumRef = uno::Reference < container::XEnumeration>( static_cast < container::XEnumeration *> (pEnum), uno::UNO_QUERY );
+ uno::Reference< container::XEnumeration> xEnumRef = new ZipEnumeration( aEntries );
return xEnumRef;
}
+
::rtl::OUString SAL_CALL ZipFile::getName( )
throw(uno::RuntimeException)
{
return sName;
}
+
sal_Int32 SAL_CALL ZipFile::getSize( )
throw(uno::RuntimeException)
{
@@ -155,6 +142,7 @@ uno::Type SAL_CALL ZipFile::getElementType( )
{
return ::getCppuType((package::ZipEntry *) 0);
}
+
sal_Bool SAL_CALL ZipFile::hasElements( )
throw(uno::RuntimeException)
{
@@ -171,6 +159,7 @@ uno::Any SAL_CALL ZipFile::getByName( const ::rtl::OUString& aName )
aAny <<= (*aCI).second;
return aAny;
}
+
uno::Sequence< ::rtl::OUString > SAL_CALL ZipFile::getElementNames( )
throw(uno::RuntimeException)
{
@@ -180,11 +169,13 @@ uno::Sequence< ::rtl::OUString > SAL_CALL ZipFile::getElementNames( )
pNames[i] = (*aIterator).first;
return uno::Sequence<OUString> (pNames, nSize);
}
+
sal_Bool SAL_CALL ZipFile::hasByName( const ::rtl::OUString& aName )
throw(uno::RuntimeException)
{
return aEntries.count(aName);
}
+
uno::Reference< io::XInputStream > SAL_CALL ZipFile::getInputStream( const package::ZipEntry& rEntry )
throw(io::IOException, package::ZipException, uno::RuntimeException)
{
@@ -194,10 +185,12 @@ uno::Reference< io::XInputStream > SAL_CALL ZipFile::getInputStream( const packa
sal_Int64 nBegin = rEntry.nOffset;
nEnd +=nBegin;
- uno::Reference< io::XInputStream > xStreamRef = new EntryInputStream(xStream, nBegin, nEnd, 1024, rEntry.nSize);
+ uno::Reference< io::XInputStream > xStreamRef = new EntryInputStream(xStream, nBegin, nEnd, 1024, rEntry.nSize, rEntry.nMethod == DEFLATED );
return xStreamRef;
}
+
sal_Bool ZipFile::readLOC(const package::ZipEntry &rEntry)
+ throw(io::IOException, package::ZipException, uno::RuntimeException)
{
sal_uInt32 nTestSig, nTime, nCRC, nSize, nCompressedSize;
sal_uInt16 nVersion, nFlag, nHow, nNameLen, nExtraLen;
@@ -207,10 +200,7 @@ sal_Bool ZipFile::readLOC(const package::ZipEntry &rEntry)
aGrabber >> nTestSig;
if (nTestSig != LOCSIG)
- {
- VOS_DEBUG_ONLY ("Invalid LOC header (bad signature)");
- return sal_False;
- }
+ throw (package::ZipException( OUString::createFromAscii("Invalid LOC header (bad signature"), uno::Reference < uno::XInterface > () ));
aGrabber >> nVersion;
aGrabber >> nFlag;
aGrabber >> nHow;
@@ -223,39 +213,19 @@ sal_Bool ZipFile::readLOC(const package::ZipEntry &rEntry)
package::ZipEntry *pNonConstEntry = const_cast < package::ZipEntry* > (&rEntry);
pNonConstEntry->nOffset = static_cast < sal_Int32 > (aGrabber.getPosition()) + nNameLen + nExtraLen;
return sal_True;
-
-/*
- ZipEntryImpl *pEntry = new ZipEntryImpl();
-
- sal_Char * pTmpName = new sal_Char[nNameLen];
- xStream.Read(pTmpName, nNameLen);
- pEntry->sName = ByteSequence( pTmpName, nNameLen, RTL_TEXTENCODING_ASCII_US);
- delete [] pTmpName;
-
- sal_Char * pTmpExtra = new sal_Char[nExtraLen];
- xStream.Read(pTmpExtra, nExtraLen);
- pEntry->sExtra = ByteSequence(pTmpExtra, nExtraLen);
- delete [] pTmpExtra;
-
- pEntry->sComment = pComments[pCell->nIndex];
- pEntry->nSize = pCell->nSize;
- pEntry->nCompressedSize = pCell->nCompressedSize;
- pEntry->nCRC = pCell->nCRC;
- pEntry->nTime = nTime;
- pEntry->nMethod = nHow;
- pEntry->nPos = pCell->nPos + LOCHDR + nNameLen + nExtraLen;
- return pEntry;
-*/
}
-
sal_Int32 ZipFile::findEND( )
+ throw(io::IOException, package::ZipException, uno::RuntimeException)
{
sal_Int32 nLength=0, nPos=0;
uno::Sequence < sal_Int8 > aByteSeq;
nLength = nPos = static_cast <sal_Int32 > (aGrabber.getLength());
+
if (nLength == 0)
return -1;
+ //throw (package::ZipException( OUString::createFromAscii("Trying to find Zip END signature in a zero length file!"), uno::Reference < uno::XInterface> () ));
+
aGrabber.seek( nLength );
while (nLength - nPos < 0xFFFF)
@@ -291,33 +261,11 @@ sal_Int32 ZipFile::findEND( )
}
}
}
- return -1;
-}
-
-#if 0
-sal_Bool ZipFile::isMetaName( ByteSequence &rName)
-{
- ByteSequence sTemp = rName.toUpperCase();
- if (sTemp.compareToAscii( "META_INF/", 9) == 0)
- return sal_True;
- return sal_False;
-
-}
-void ZipFile::addMetaName( ByteSequence &rName )
-{
- aMetaNames.Insert (new String(rName));
+ throw (package::ZipException( OUString::createFromAscii("Zip END signature not found!"), uno::Reference < uno::XInterface> () ));
}
-
-void ZipFile::addEntryComment( int nIndex, ByteSequence &rComment)
-{
- if (pComments == NULL)
- pComments = new ByteSequence[nTotal];
- pComments[nIndex]=rComment;
-}
-#endif
-
sal_Int32 ZipFile::readCEN()
+ throw(io::IOException, package::ZipException, uno::RuntimeException)
{
sal_Int32 nEndPos, nLocPos;
sal_Int16 nCount, nTotal;
@@ -332,71 +280,46 @@ sal_Int32 ZipFile::readCEN()
aGrabber >> nCenOff;
if (nTotal<0 || nTotal * CENHDR > nCenLen)
- {
- VOS_DEBUG_ONLY("invalid END header (bad entry count)");
- return -1;
- }
- if (nTotal > ZIP_MAXENTRIES)
- {
- VOS_DEBUG_ONLY("too many entries in ZIP File");
- return -1;
- }
-
- //aGrabber.seek(nEndPos+ENDSIZ);
+ throw (package::ZipException(OUString::createFromAscii("invalid END header (bad entry count)"), uno::Reference < uno::XInterface > ()));
+ if (nTotal > ZIP_MAXENTRIES)
+ throw (package::ZipException(OUString::createFromAscii("too many entries in ZIP File"), uno::Reference < uno::XInterface > ()));
if (nCenLen < 0 || nCenLen > nEndPos)
- {
- VOS_DEBUG_ONLY ("invalid END header (bad central directory size)");
- return -1;
- }
+ throw (package::ZipException(OUString::createFromAscii("Invalid END header (bad central directory size)"), uno::Reference < uno::XInterface > ()));
+
nCenPos = nEndPos - nCenLen;
if (nCenOff < 0 || nCenOff > nCenPos)
- {
- VOS_DEBUG_ONLY("invalid END header (bad central directory size)");
- return -1;
- }
- nLocPos = nCenPos - nCenOff;
+ throw (package::ZipException(OUString::createFromAscii("Invalid END header (bad central directory size)"), uno::Reference < uno::XInterface > ()));
+ nLocPos = nCenPos - nCenOff;
aGrabber.seek(nCenPos);
-/*
- pEntries = new package::ZipEntry[nTotal];
- nTableLen = nTotal * 2;
- pTable = new ZipEntryImpl*[nTableLen];
- memset(pTable, 0, sizeof (ZipEntryImpl*) * nTableLen);
-*/
+
for (nCount = 0 ; nCount < nTotal; nCount++)
{
package::ZipEntry *pEntry = new package::ZipEntry;
sal_Int32 nTestSig, nCRC, nCompressedSize, nTime, nSize, nExtAttr, nOffset;
sal_Int16 nVerMade, nVersion, nFlag, nHow, nNameLen, nExtraLen, nCommentLen;
sal_Int16 nDisk, nIntAttr;
+
if (aGrabber.getPosition() - nCenPos + CENHDR > nCenLen)
- {
- VOS_DEBUG_ONLY("invalid CEN header (bad header size check 1");
- break;
- }
+ throw (package::ZipException(OUString::createFromAscii("Invalid CEN header (bad header size check 1)"), uno::Reference < uno::XInterface > ()));
+
aGrabber >> nTestSig;
if (nTestSig != CENSIG)
- {
- VOS_DEBUG_ONLY ("invalid CEN header (bad signature)");
- break;
- }
+ throw (package::ZipException(OUString::createFromAscii("Invalid CEN header (bad signature)"), uno::Reference < uno::XInterface > ()));
+
aGrabber >> nVerMade;
aGrabber >> nVersion;
if ((nVersion & 1) == 1)
- {
- VOS_DEBUG_ONLY ( "invalid CEN header (encrypted entry)");
- break;
- }
+ throw (package::ZipException(OUString::createFromAscii("Invalid CEN header (encrypted entry)"), uno::Reference < uno::XInterface > ()));
+
aGrabber >> nFlag;
aGrabber >> nHow;
if (nHow != STORED && nHow != DEFLATED)
- {
- VOS_DEBUG_ONLY ( "invalid CEN header (bad compression method)");
- break;
- }
+ throw (package::ZipException(OUString::createFromAscii("Invalid CEN header (bad compression method)"), uno::Reference < uno::XInterface > ()));
+
aGrabber >> nTime;
aGrabber >> nCRC;
aGrabber >> nCompressedSize;
@@ -410,20 +333,13 @@ sal_Int32 ZipFile::readCEN()
aGrabber >> nOffset;
if (aGrabber.getPosition() - nCenPos + nNameLen + nExtraLen + nCommentLen > nCenLen)
- {
- VOS_DEBUG_ONLY ( "invalid CEN header (bad header size check 2)");
- break;
- }
+ throw (package::ZipException(OUString::createFromAscii("Invalid CEN header (bad header siez check 2)"), uno::Reference < uno::XInterface > ()));
+
if (nNameLen > ZIP_MAXNAMELEN)
- {
- VOS_DEBUG_ONLY ( "name length exceeds 512 bytes");
- break;
- }
+ throw (package::ZipException(OUString::createFromAscii("name length exceeds 512 bytes"), uno::Reference < uno::XInterface > ()));
+
if (nExtraLen > ZIP_MAXEXTRA)
- {
- VOS_DEBUG_ONLY ( "extra header info exceeds 256 bytes");
- break;
- }
+ throw (package::ZipException(OUString::createFromAscii("extra header info exceeds 256 bytes"), uno::Reference < uno::XInterface > ()));
pEntry->nTime = nTime;
pEntry->nCrc = nCRC;
@@ -450,21 +366,11 @@ sal_Int32 ZipFile::readCEN()
aGrabber.readBytes(aCommentSeq, nCommentLen);
pEntry->sComment = OUString((sal_Char*)aCommentSeq.getConstArray(), nNameLen, RTL_TEXTENCODING_ASCII_US);
}
- /*
- sal_Int32 nHash = abs(pEntry->sName.hashCode() % nTableLen);
- ZipEntryImpl* pTmp = new ZipEntryImpl();
- pTmp->pEntry = pEntry;
- pTmp->pNext = pTable[nHash];
- pTable[nHash] = pTmp;
- pEntry->pNext = pTable[nHash];
- pTable[nHash] = pEntry;*/
aEntries[pEntry->sName] = *pEntry;
}
if (nCount != nTotal)
- {
- VOS_DEBUG_ONLY("Count != total!");
- return -1;
- }
+ throw (package::ZipException(OUString::createFromAscii("Count != Total"), uno::Reference < uno::XInterface > ()));
+
return nCenPos;
}
diff --git a/package/source/zipapi/ZipOutputStream.cxx b/package/source/zipapi/ZipOutputStream.cxx
index cea7fd7914eb..3bbbc88364e7 100644
--- a/package/source/zipapi/ZipOutputStream.cxx
+++ b/package/source/zipapi/ZipOutputStream.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: ZipOutputStream.cxx,v $
*
- * $Revision: 1.11 $
+ * $Revision: 1.12 $
*
- * last change: $Author: mtg $ $Date: 2000-12-01 10:49:47 $
+ * last change: $Author: mtg $ $Date: 2000-12-04 11:30:08 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -249,6 +249,7 @@ void ZipOutputStream::doDeflate()
}
}
void ZipOutputStream::writeEND(sal_uInt32 nOffset, sal_uInt32 nLength)
+ throw(io::IOException, uno::RuntimeException)
{
sal_Int16 i=0, nCommentLength = static_cast < sal_Int16 > (sComment.getLength());
const sal_Unicode *pChar = sComment.getStr();
@@ -270,6 +271,7 @@ void ZipOutputStream::writeEND(sal_uInt32 nOffset, sal_uInt32 nLength)
aChucker.writeBytes(aSequence);
}
void ZipOutputStream::writeCEN( const package::ZipEntry &rEntry )
+ throw(io::IOException, uno::RuntimeException)
{
sal_Int16 nNameLength = static_cast < sal_Int16 > ( rEntry.sName.getLength() ) ,
nCommentLength = static_cast < sal_Int16 > ( rEntry.sComment.getLength() ) ,
@@ -323,6 +325,7 @@ void ZipOutputStream::writeCEN( const package::ZipEntry &rEntry )
}
}
void ZipOutputStream::writeEXT( const package::ZipEntry &rEntry )
+ throw(io::IOException, uno::RuntimeException)
{
aChucker << EXTSIG;
aChucker << rEntry.nCrc;
@@ -331,6 +334,7 @@ void ZipOutputStream::writeEXT( const package::ZipEntry &rEntry )
}
void ZipOutputStream::writeLOC( const package::ZipEntry &rEntry )
+ throw(io::IOException, uno::RuntimeException)
{
sal_Int16 nNameLength = static_cast < sal_Int16 > (rEntry.sName.getLength());
sal_Int16 i=0;
diff --git a/package/source/zippackage/ZipPackage.cxx b/package/source/zippackage/ZipPackage.cxx
index 23d0b7678368..35df1213b1ae 100644
--- a/package/source/zippackage/ZipPackage.cxx
+++ b/package/source/zippackage/ZipPackage.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: ZipPackage.cxx,v $
*
- * $Revision: 1.20 $
+ * $Revision: 1.21 $
*
- * last change: $Author: mtg $ $Date: 2000-12-01 10:50:49 $
+ * last change: $Author: mtg $ $Date: 2000-12-04 11:30:09 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -83,7 +83,15 @@ ZipPackage::ZipPackage (Reference < XInputStream > &xNewInput,
, xContentSeek (xNewInput, UNO_QUERY)
, xFactory(xNewFactory)
{
- pZipFile = new ZipFile(xContentStream);
+ try
+ {
+ pZipFile = new ZipFile(xContentStream, sal_True);
+ }
+ catch (ZipException& rException)
+ {
+ VOS_DEBUG_ONLY(rException.Message);
+ }
+
xZipFile = Reference < XZipFile > ( pZipFile );
pRootFolder = new ZipPackageFolder( );
xRootFolder = Reference < XUnoTunnel > ( pRootFolder );
@@ -141,7 +149,7 @@ void ZipPackage::destroyFolderTree( Reference < XUnoTunnel > xFolder )
pFolder = reinterpret_cast < ZipPackageFolder* > (xTunnel->getSomething(ZipPackageFolder::getUnoTunnelImplementationId()));
bIsFolder = sal_True;
}
- catch (RuntimeException)
+ catch (RuntimeException&)
{
pStream = reinterpret_cast < ZipPackageStream* > (xTunnel->getSomething(ZipPackageStream::getUnoTunnelImplementationId()));
bIsFolder = sal_False;
@@ -185,7 +193,14 @@ void ZipPackage::getZipFileContents()
{
pPkgFolder = new ZipPackageFolder();//*this);
pPkgFolder->setName(sTemp);
- pPkgFolder->setParent( Reference < XInterface >(xCurrent, UNO_QUERY));
+ try
+ {
+ pPkgFolder->setParent( Reference < XInterface > (xCurrent, UNO_QUERY) );
+ }
+ catch ( NoSupportException& )
+ {
+ VOS_DEBUG_ONLY("setParent threw an exception: attempted to set Parent to non-existing interface!");
+ }
aAny <<= Reference < XUnoTunnel > (pPkgFolder);
//xCurrent->insertByName(sTemp, aAny);
xCurrent = Reference < XNameContainer > (pPkgFolder);
@@ -212,7 +227,14 @@ void ZipPackage::getZipFileContents()
{
pPkgFolder = new ZipPackageFolder();//*this);
pPkgFolder->setName(sTemp);
- pPkgFolder->setParent( Reference < XInterface >(xCurrent, UNO_QUERY));
+ try
+ {
+ pPkgFolder->setParent( Reference < XInterface >(xCurrent, UNO_QUERY));
+ }
+ catch ( NoSupportException& )
+ {
+ VOS_DEBUG_ONLY("setParent threw an exception: attempted to set Parent to non-existing interface!");
+ }
aAny <<= Reference < XUnoTunnel > (pPkgFolder);
//xCurrent->insertByName(sTemp, aAny);
xCurrent = Reference < XNameContainer > (pPkgFolder);
@@ -234,7 +256,14 @@ void ZipPackage::getZipFileContents()
aContainedZips.push_back (Reference < XSingleServiceFactory > (pInZip));
pPkgFolder = pInZip->getRootFolder();
pPkgFolder->setName(sStreamName);
- pPkgFolder->setParent( Reference < XInterface >(xCurrent, UNO_QUERY));
+ try
+ {
+ pPkgFolder->setParent( Reference < XInterface >(xCurrent, UNO_QUERY));
+ }
+ catch ( NoSupportException& )
+ {
+ VOS_DEBUG_ONLY("setParent threw an exception: attempted to set Parent to non-existing interface!");
+ }
aAny <<= Reference < XUnoTunnel > (pPkgFolder);
//xCurrent->insertByName(sStreamName, aAny);
}
@@ -244,7 +273,14 @@ void ZipPackage::getZipFileContents()
pPkgStream->bPackageMember = sal_True;
pPkgStream->setZipEntry( aEntry );
pPkgStream->setName( sStreamName );
- pPkgStream->setParent( Reference < XInterface > (xCurrent, UNO_QUERY));
+ try
+ {
+ pPkgStream->setParent( Reference < XInterface > (xCurrent, UNO_QUERY));
+ }
+ catch ( NoSupportException& )
+ {
+ VOS_DEBUG_ONLY("setParent threw an exception: attempted to set Parent to non-existing interface!");
+ }
aAny <<= Reference < XUnoTunnel > (pPkgStream);
//xCurrent->insertByName(sStreamName, aAny);
}
@@ -256,8 +292,18 @@ void ZipPackage::getZipFileContents()
Reference < XUnoTunnel > xTunnel;
aAny >>= xTunnel;
Reference < XActiveDataSink > xSink (xTunnel, UNO_QUERY);
- ManifestReader aReader(*this, xSink->getInputStream(), xFactory);
- aReader.Read();
+ if (xSink.is())
+ {
+ try
+ {
+ ManifestReader aReader(*this, xSink->getInputStream(), xFactory);
+ aReader.Read();
+ }
+ catch ( com::sun::star::xml::sax::SAXException & )
+ {
+ VOS_DEBUG_ONLY( "SAX threw an exception when reading XML Manifest!");
+ }
+ }
}
}
// XInitialization
@@ -268,13 +314,26 @@ void SAL_CALL ZipPackage::initialize( const Sequence< Any >& aArguments )
aArguments[0] >>= sURL;
pContent = new ::ucb::Content(sURL, Reference < com::sun::star::ucb::XCommandEnvironment >() );
Reference < XActiveDataSink > xSink = new ZipPackageSink;
- if (pContent->openStream ( xSink) )
- xContentStream = xSink->getInputStream();
-
- xContentSeek = Reference < XSeekable > (xContentStream, UNO_QUERY);
- pZipFile = new ZipFile(xContentStream);
- xZipFile = Reference < XZipFile > ( pZipFile );
- getZipFileContents();
+ try
+ {
+ if (pContent->openStream ( xSink) )
+ xContentStream = xSink->getInputStream();
+ xContentSeek = Reference < XSeekable > (xContentStream, UNO_QUERY);
+ try
+ {
+ pZipFile = new ZipFile(xContentStream, sal_True);
+ xZipFile = Reference < XZipFile > ( pZipFile );
+ }
+ catch (ZipException& rException)
+ {
+ VOS_DEBUG_ONLY(rException.Message);
+ }
+ getZipFileContents();
+ }
+ catch (::com::sun::star::ucb::CommandAbortedException&)
+ {
+ // File doesn't exist, we'll create it at commitChanges time
+ }
}
// XHierarchicalNameAccess
Any SAL_CALL ZipPackage::getByHierarchicalName( const OUString& aName )
@@ -339,7 +398,7 @@ Any SAL_CALL ZipPackage::getByHierarchicalName( const OUString& aName )
sal_Bool SAL_CALL ZipPackage::hasByHierarchicalName( const OUString& aName )
throw(RuntimeException)
{
- sal_Int32 nOldIndex =0,nIndex = 0;
+ sal_Int32 nOldIndex = 0, nIndex = 0;
Any aAny;
Reference < XNameContainer > xCurrent = Reference < XNameContainer > (pRootFolder);
@@ -355,7 +414,7 @@ sal_Bool SAL_CALL ZipPackage::hasByHierarchicalName( const OUString& aName )
while ((nIndex = aName.indexOf('/', nOldIndex)) != -1)
{
OUString sTemp = aName.copy (nOldIndex, nIndex - nOldIndex);
- if (nIndex == nOldIndex) //sTemp.getLength() == 1)
+ if (nIndex == nOldIndex)
break;
if (xCurrent->hasByName(sTemp))
{
@@ -375,7 +434,7 @@ sal_Bool SAL_CALL ZipPackage::hasByHierarchicalName( const OUString& aName )
while ((nIndex = aName.indexOf('/', nOldIndex)) != -1)
{
OUString sTemp = aName.copy (nOldIndex, nIndex - nOldIndex);
- if (nIndex == nOldIndex) //sTemp.getLength() == 1)
+ if (nIndex == nOldIndex)
break;
if (xCurrent->hasByName(sTemp))
{
@@ -416,10 +475,13 @@ Reference< XInterface > SAL_CALL ZipPackage::createInstanceWithArguments( const
void SAL_CALL ZipPackage::commitChanges( )
throw(WrappedTargetException, RuntimeException)
{
- Reference < XNameContainer > xMetaFolder;
- Reference < XUnoTunnel > xMetaTunnel;
std::vector < ManifestEntry * > aManList;
Any aAny;
+
+ // Set up output buffer. ZipPackageBuffer implements both
+ // XInputStream and XOutputStream as the UCB requires an XInputStream
+ // and the ZipOutputStream writes to an XOutputStream
+
ZipPackageBuffer *pZipBuffer = new ZipPackageBuffer( 65535 );
Reference < XOutputStream > xOutStream (pZipBuffer);
ZipOutputStream *pZipOut = new ZipOutputStream( xOutStream, 65535 );
@@ -427,71 +489,101 @@ void SAL_CALL ZipPackage::commitChanges( )
pZipOut->setMethod(DEFLATED);
pZipOut->setLevel(DEFAULT_COMPRESSION);
+ Reference < XNameContainer > xZipRoot = Reference < XNameContainer > (xRootFolder, UNO_QUERY);
+
sal_Bool bAddMetaFolder = sal_False;
- if (hasByHierarchicalName(OUString::createFromAscii("META-INF/")))
- {
- aAny = getByHierarchicalName(OUString::createFromAscii("META-INF/"));
- aAny >>= xMetaTunnel;
- xMetaFolder = Reference < XNameContainer > (xMetaTunnel, UNO_QUERY);
- if (xMetaFolder->hasByName(OUString::createFromAscii("manifest.xml")))
- xMetaFolder->removeByName(OUString::createFromAscii("manifest.xml"));
- }
- else
- bAddMetaFolder = sal_True;
+
+ // Remove the old META-INF directory as this will be re-generated below.
+ // Pass save-contents a vector which will be used to store the entries which
+ // are placed inside the Manifest et al. Note: saveContents is called
+ // recursively.
+
+ if (xZipRoot->hasByName(OUString::createFromAscii("META-INF")))
+ xZipRoot->removeByName(OUString::createFromAscii("META-INF"));
pRootFolder->saveContents(OUString::createFromAscii(""), aManList, *pZipOut);
- if (bAddMetaFolder)
- {
- sal_Bool bFolder = sal_True;
- aAny <<= bFolder;
- xMetaFolder = Reference < XNameContainer> (createInstanceWithArguments( Sequence < Any > (&aAny, 1)), UNO_QUERY);
- Reference < XNameContainer > xZipRoot = Reference < XNameContainer > (xRootFolder, UNO_QUERY);
- xMetaTunnel = Reference < XUnoTunnel > (xMetaFolder, UNO_QUERY);
- aAny <<= xMetaTunnel;
- xZipRoot->insertByName(OUString::createFromAscii("META-INF"), aAny);
- }
+ ZipPackageFolder *pMetaInfFolder = new ZipPackageFolder();
+ ZipPackageStream *pManifestStream = new ZipPackageStream( pZipFile );
+ aAny <<= Reference < XUnoTunnel > (pMetaInfFolder);
+ xZipRoot->insertByName(OUString::createFromAscii("META-INF"), aAny);
- Reference < XUnoTunnel > xManifestStream = Reference < XUnoTunnel > (createInstance(), UNO_QUERY);
- ZipPackageStream * pManifestStream = reinterpret_cast < ZipPackageStream * > (xManifestStream->getSomething(ZipPackageStream::getUnoTunnelImplementationId()));
ZipPackageBuffer *pBuffer = new ZipPackageBuffer(65535);
-
Reference < XOutputStream > xManOutStream (pBuffer);
+
pManifestStream->aEntry.sName = OUString::createFromAscii("META-INF/manifest.xml");
- pManifestStream->aEntry.nVersion = -1;
- pManifestStream->aEntry.nFlag = 0;
pManifestStream->aEntry.nMethod = STORED;
- pManifestStream->aEntry.nTime = -1;
- pManifestStream->aEntry.nCrc = 0;
- pManifestStream->aEntry.nOffset = -1;
pManifestStream->bPackageMember = sal_True;
- ManifestWriter aWriter ( xManOutStream, xFactory, aManList);
- aWriter.Write();
+ try
+ {
+ ManifestWriter aWriter ( xManOutStream, xFactory, aManList);
+ aWriter.Write();
+ }
+ catch ( com::sun::star::xml::sax::SAXException & )
+ {
+ VOS_DEBUG_ONLY( "SAX threw an exception when writing XML Manifest!");
+ }
+ pManifestStream->setInputStream(Reference < XInputStream > (xManOutStream, UNO_QUERY));
+
pManifestStream->aEntry.nSize = pManifestStream->aEntry.nCompressedSize = static_cast < sal_Int32 > (pBuffer->getPosition());
- pBuffer->aBuffer.realloc(static_cast < sal_Int32 > (pBuffer->getPosition()));
+ pBuffer->aBuffer.realloc(pManifestStream->aEntry.nSize);
CRC32 aCRC;
aCRC.update(pBuffer->aBuffer);
pManifestStream->aEntry.nCrc = aCRC.getValue();
- pZipOut->putNextEntry(pManifestStream->aEntry);
- pZipOut->write(pBuffer->aBuffer, 0, static_cast < sal_Int32 > (pBuffer->getPosition()));
- pZipOut->closeEntry();
+ try
+ {
+ pZipOut->putNextEntry(pManifestStream->aEntry);
+ pZipOut->write(pBuffer->aBuffer, 0, pManifestStream->aEntry.nSize);
+ pZipOut->closeEntry();
+ pZipOut->finish();
+ }
+ catch (::com::sun::star::io::IOException & )
+ {
+ VOS_DEBUG_ONLY ( "Error writing ZipOutputStream" );
+ }
- pZipOut->finish();
pZipBuffer->seek(0);
- aAny <<= xManifestStream;
- xMetaFolder->insertByName(OUString::createFromAscii("manifest.xml"), aAny);
+ aAny <<= Reference < XUnoTunnel > (pManifestStream);
+ pMetaInfFolder->insertByName(OUString::createFromAscii("manifest.xml"), aAny);
+
- pZipFile->updateFromManList( aManList );
for (sal_uInt32 i=0 ; i < aManList.size(); i++)
{
ZipEntry * pEntry = aManList[i]->pEntry;
pEntry->sName = aManList[i]->sShortName;
}
- pContent->writeStream(Reference < XInputStream > (pZipBuffer), sal_True);
+ try
+ {
+ pContent->writeStream(Reference < XInputStream > (pZipBuffer), sal_True);
+ }
+ catch (::com::sun::star::ucb::CommandAbortedException&)
+ {
+ VOS_DEBUG_ONLY( "Unable to write Zip File to disk!");
+ }
+ if (!pZipFile)
+ {
+ // If we have a valid pZipFile pointer, then we opened a stream
+ // earlier and read from it
+ // Otherwise we are writing a new ZipFile
+ xContentStream = Reference < XInputStream > (pZipBuffer);
+ xContentSeek = Reference < XSeekable > (pZipBuffer);
+ try
+ {
+ pZipFile = new ZipFile(xContentStream, sal_False);
+ xZipFile = Reference < XZipFile > ( pZipFile );
+ pRootFolder->updateReferences ( pZipFile );
+ }
+ catch (ZipException& rException)
+ {
+ VOS_DEBUG_ONLY(rException.Message);
+ }
+ }
+ pZipFile->updateFromManList( aManList );
}
+
sal_Bool SAL_CALL ZipPackage::hasPendingChanges( )
throw(RuntimeException)
{
@@ -505,14 +597,18 @@ Sequence< ElementChange > SAL_CALL ZipPackage::getPendingChanges( )
sal_Bool ZipPackage::isZipFile(com::sun::star::package::ZipEntry &rEntry)
{
- Reference < XInputStream > xContentStream = pZipFile->getInputStream(rEntry);
+ Reference < XInputStream > xEntryStream = pZipFile->getInputStream(rEntry);
Sequence < sal_Int8 > aSequence (4);
- xContentStream->readBytes(aSequence, 4);
+
+ if (xEntryStream->readBytes(aSequence, 4) < 4)
+ return sal_False;
+
sal_uInt32 nTestSig = static_cast < sal_uInt32 >
(static_cast < sal_uInt8> (aSequence[0]& 0xFF)
| static_cast < sal_uInt8> (aSequence[1]& 0xFF) << 8
| static_cast < sal_uInt8> (aSequence[2]& 0xFF) << 16
| static_cast < sal_uInt8> (aSequence[3]& 0xFF) << 24);
+
if (nTestSig == LOCSIG)
return sal_True;
else
diff --git a/package/source/zippackage/ZipPackageFolder.cxx b/package/source/zippackage/ZipPackageFolder.cxx
index 7b144699e367..4f46a974abf3 100644
--- a/package/source/zippackage/ZipPackageFolder.cxx
+++ b/package/source/zippackage/ZipPackageFolder.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: ZipPackageFolder.cxx,v $
*
- * $Revision: 1.16 $
+ * $Revision: 1.17 $
*
- * last change: $Author: mtg $ $Date: 2000-12-01 10:50:49 $
+ * last change: $Author: mtg $ $Date: 2000-12-04 11:30:09 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -66,8 +66,7 @@ using namespace com::sun::star::package::ZipConstants;
using namespace com::sun::star;
using namespace rtl;
-ZipPackageFolder::ZipPackageFolder (void) //ZipOutputStream &rStream)//ZipPackage &rInPackage)
-//: rZipOut(rStream)
+ZipPackageFolder::ZipPackageFolder (void)
{
aEntry.nVersion = -1;
aEntry.nFlag = 0;
@@ -138,7 +137,14 @@ void SAL_CALL ZipPackageFolder::insertByName( const ::rtl::OUString& aName, cons
uno::Reference < uno::XInterface > xInterface (*this);
xNamed->setName (sName);
aContents[sName] = xRef;
- xChild->setParent (xInterface);
+ try
+ {
+ xChild->setParent (xInterface);
+ }
+ catch ( lang::NoSupportException& )
+ {
+ VOS_DEBUG_ONLY("setParent threw an exception: attempted to set Parent to non-existing interface!");
+ }
}
}
void SAL_CALL ZipPackageFolder::removeByName( const ::rtl::OUString& Name )
@@ -272,12 +278,13 @@ void SAL_CALL ZipPackageFolder::removeVetoableChangeListener( const ::rtl::OUStr
{
}
void ZipPackageFolder::saveContents(rtl::OUString &rPath, std::vector < ManifestEntry *> &rManList, ZipOutputStream & rZipOut)
+ throw(uno::RuntimeException)
{
uno::Reference < lang::XUnoTunnel > xTunnel;
package::ZipEntry *aEntry = NULL;
ZipPackageFolder *pFolder = NULL;
ZipPackageStream *pStream = NULL;
- sal_Bool bIsFolder;
+ sal_Bool bIsFolder = sal_False;
TunnelHash::const_iterator aCI = aContents.begin();
//rPath = rPath + getName();
@@ -285,14 +292,23 @@ void ZipPackageFolder::saveContents(rtl::OUString &rPath, std::vector < Manifest
for (;aCI!=aContents.end();aCI++)
{
xTunnel = uno::Reference < lang::XUnoTunnel> ((*aCI).second, uno::UNO_QUERY);
- try
+ sal_Int64 nTest=0;
+ if ((nTest = xTunnel->getSomething(ZipPackageFolder::getUnoTunnelImplementationId())) != 0)
{
- pFolder = reinterpret_cast < ZipPackageFolder* > (xTunnel->getSomething(ZipPackageFolder::getUnoTunnelImplementationId()));
+ pFolder = reinterpret_cast < ZipPackageFolder* > ( nTest );
bIsFolder = sal_True;
}
- catch (uno::RuntimeException)
+ else
{
- pStream = reinterpret_cast < ZipPackageStream* > (xTunnel->getSomething(ZipPackageStream::getUnoTunnelImplementationId()));
+ // If this getSomething call returns 0, it means that
+ // something evil has crept into the contents hash_map, which
+ // should mean that something has gone very wrong somewhere, and someone
+ // else should deal with it
+
+ nTest = xTunnel->getSomething(ZipPackageFolder::getUnoTunnelImplementationId());
+ if (nTest == 0)
+ throw (uno::RuntimeException());
+ pStream = reinterpret_cast < ZipPackageStream* > ( nTest );
bIsFolder = sal_False;
}
@@ -306,12 +322,18 @@ void ZipPackageFolder::saveContents(rtl::OUString &rPath, std::vector < Manifest
pFolder->aEntry.nCrc = 0;
pFolder->aEntry.nSize = 0;
pFolder->aEntry.nCompressedSize = 0;
- rZipOut.putNextEntry(pFolder->aEntry);
- rZipOut.closeEntry();
+ try
+ {
+ rZipOut.putNextEntry(pFolder->aEntry);
+ rZipOut.closeEntry();
+ }
+ catch (::com::sun::star::io::IOException & )
+ {
+ VOS_DEBUG_ONLY ( "Error writing ZipOutputStream" );
+ }
pMan->sMediaType = OUString::createFromAscii("");
pMan->pEntry = &(pFolder->aEntry);
pFolder->saveContents(pFolder->aEntry.sName, rManList, rZipOut);
- //setEntry(pMan->aEntry, pFolder->aEntry);
rManList.push_back (pMan);
}
else
@@ -337,28 +359,41 @@ void ZipPackageFolder::saveContents(rtl::OUString &rPath, std::vector < Manifest
}
}
- rZipOut.putNextEntry(pStream->aEntry);
- while (1)
+ try
{
- uno::Sequence < sal_Int8 > aSeq (65535);
- sal_Int32 nLength;
- nLength = xStream->readBytes(aSeq, 65535);
- if (nLength < 65535)
- aSeq.realloc(nLength);
- rZipOut.write(aSeq, 0, nLength);
- if (bTrackLength)
- pStream->aEntry.nSize+=nLength;
- if (nLength < 65535) // EOF
+ rZipOut.putNextEntry(pStream->aEntry);
+ while (1)
+ {
+ uno::Sequence < sal_Int8 > aSeq (65535);
+ sal_Int32 nLength;
+ nLength = xStream->readBytes(aSeq, 65535);
+ if (nLength < 65535)
+ aSeq.realloc(nLength);
+ rZipOut.write(aSeq, 0, nLength);
+ if (bTrackLength)
+ pStream->aEntry.nSize+=nLength;
+ if (nLength < 65535) // EOF
break;
+ }
+ if (bTrackLength)
+ pStream->aEntry.nCompressedSize = pStream->aEntry.nSize;
+ pStream->bPackageMember = sal_True;
+ rZipOut.closeEntry();
+ }
+ catch (::com::sun::star::io::IOException & )
+ {
+ VOS_DEBUG_ONLY ( "Error writing ZipOutputStream" );
+ }
+ try
+ {
+ uno::Any aAny = pStream->getPropertyValue(OUString::createFromAscii("MediaType"));
+ aAny >>= pMan->sMediaType;
+ }
+ catch (::com::sun::star::beans::UnknownPropertyException & )
+ {
+ VOS_DEBUG_ONLY ( "MediaType is an unknown property!!" );
}
- if (bTrackLength)
- pStream->aEntry.nCompressedSize = pStream->aEntry.nSize;
- pStream->bPackageMember = sal_True;
- rZipOut.closeEntry();
- uno::Any aAny = pStream->getPropertyValue(OUString::createFromAscii("MediaType"));
- aAny >>= pMan->sMediaType;
pMan->pEntry = &(pStream->aEntry);
- //setEntry(pMan->aEntry, pStream->aEntry);
rManList.push_back (pMan);
}
}
@@ -388,14 +423,23 @@ void ZipPackageFolder::updateReferences( ZipFile * pNewZipFile)
for (;aCI!=aContents.end();aCI++)
{
xTunnel = uno::Reference < lang::XUnoTunnel> ((*aCI).second, uno::UNO_QUERY);
- try
+ sal_Int64 nTest=0;
+ if ((nTest = xTunnel->getSomething(ZipPackageFolder::getUnoTunnelImplementationId())) != 0)
{
- pFolder = reinterpret_cast < ZipPackageFolder* > (xTunnel->getSomething(ZipPackageFolder::getUnoTunnelImplementationId()));
+ pFolder = reinterpret_cast < ZipPackageFolder* > ( nTest );
bIsFolder = sal_True;
}
- catch (uno::RuntimeException)
+ else
{
- pStream = reinterpret_cast < ZipPackageStream* > (xTunnel->getSomething(ZipPackageStream::getUnoTunnelImplementationId()));
+ // If this getSomething call returns 0, it means that
+ // something evil has crept into the contents hash_map, which
+ // should mean that something has gone very wrong somewhere, and someone
+ // else should deal with it
+
+ nTest = xTunnel->getSomething(ZipPackageFolder::getUnoTunnelImplementationId());
+ if (nTest == 0)
+ throw (uno::RuntimeException());
+ pStream = reinterpret_cast < ZipPackageStream* > ( nTest );
bIsFolder = sal_False;
}
@@ -426,7 +470,7 @@ sal_Int64 SAL_CALL ZipPackageFolder::getSomething( const uno::Sequence< sal_Int8
throw(uno::RuntimeException)
{
if (aIdentifier.getLength() == 16 && 0 == rtl_compareMemory(getUnoTunnelImplementationId().getConstArray(), aIdentifier.getConstArray(), 16 ) )
- return reinterpret_cast<sal_Int64>(this);
+ return reinterpret_cast < sal_Int64 > ( this );
- throw uno::RuntimeException();
+ return 0;
}
diff --git a/package/source/zippackage/ZipPackageStream.cxx b/package/source/zippackage/ZipPackageStream.cxx
index eb8475520f4b..4a425771fbad 100644
--- a/package/source/zippackage/ZipPackageStream.cxx
+++ b/package/source/zippackage/ZipPackageStream.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: ZipPackageStream.cxx,v $
*
- * $Revision: 1.9 $
+ * $Revision: 1.10 $
*
- * last change: $Author: mtg $ $Date: 2000-11-29 03:21:56 $
+ * last change: $Author: mtg $ $Date: 2000-12-04 11:30:09 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -143,7 +143,17 @@ uno::Reference< io::XInputStream > SAL_CALL ZipPackageStream::getInputStream( )
throw(uno::RuntimeException)
{
if (bPackageMember)
- return pZipFile->getInputStream(aEntry);
+ {
+ try
+ {
+ return pZipFile->getInputStream(aEntry);
+ }
+ catch (package::ZipException &rException)
+ {
+ VOS_DEBUG_ONLY(rException.Message);
+ return uno::Reference < io::XInputStream > ();
+ }
+ }
else
return xStream;
}
@@ -217,7 +227,7 @@ sal_Int64 SAL_CALL ZipPackageStream::getSomething( const uno::Sequence< sal_Int8
throw(uno::RuntimeException)
{
if (aIdentifier.getLength() == 16 && 0 == rtl_compareMemory(getUnoTunnelImplementationId().getConstArray(), aIdentifier.getConstArray(), 16 ) )
- return reinterpret_cast<sal_Int64>(this);
+ return reinterpret_cast < sal_Int64 > ( this );
- throw uno::RuntimeException();
+ return 0;
}