#80556# Initial revision of manifest support + ignores leading slash in zip package folders

This commit is contained in:
Martin Gallwey
2000-11-27 15:55:07 +00:00
parent 8fbbfbb709
commit 49f70b05d8
4 changed files with 92 additions and 27 deletions

View File

@@ -2,9 +2,9 @@
* *
* $RCSfile: ZipPackage.cxx,v $ * $RCSfile: ZipPackage.cxx,v $
* *
* $Revision: 1.10 $ * $Revision: 1.11 $
* *
* last change: $Author: mtg $ $Date: 2000-11-27 16:10:30 $ * last change: $Author: mtg $ $Date: 2000-11-27 16:55:07 $
* *
* The Contents of this file are made available subject to the terms of * The Contents of this file are made available subject to the terms of
* either of the following licenses * either of the following licenses
@@ -301,6 +301,8 @@ void SAL_CALL ZipPackage::initialize( const Sequence< Any >& aArguments )
pPkgStream->setParent( Reference < XInterface > (xCurrent, UNO_QUERY)); pPkgStream->setParent( Reference < XInterface > (xCurrent, UNO_QUERY));
pPkgStream->setZipEntry( aEntry ); pPkgStream->setZipEntry( aEntry );
pPkgStream->setName( sStreamName ); pPkgStream->setName( sStreamName );
aAny <<= OUString::createFromAscii("text/plain");
pPkgStream->setPropertyValue(OUString::createFromAscii("MediaType"), aAny);
aAny <<= Reference < XUnoTunnel > (pPkgStream); aAny <<= Reference < XUnoTunnel > (pPkgStream);
xCurrent->insertByName(sStreamName, aAny); xCurrent->insertByName(sStreamName, aAny);
} }
@@ -368,7 +370,15 @@ sal_Bool SAL_CALL ZipPackage::hasByHierarchicalName( const OUString& aName )
sal_Int32 nOldIndex =0,nIndex = 0; sal_Int32 nOldIndex =0,nIndex = 0;
Any aAny; Any aAny;
Reference < XNameContainer > xCurrent = Reference < XNameContainer > (pRootFolder); Reference < XNameContainer > xCurrent = Reference < XNameContainer > (pRootFolder);
if (aName.lastIndexOf('/') == aName.getLength()-1)
if (aName[nOldIndex] == '/')
nOldIndex++;
if (aName == OUString::createFromAscii("/"))
{
return sal_True;
}
else if (aName.lastIndexOf('/') == aName.getLength()-1)
{ {
while ((nIndex = aName.indexOf('/', nOldIndex)) != -1) while ((nIndex = aName.indexOf('/', nOldIndex)) != -1)
{ {
@@ -433,12 +443,31 @@ void SAL_CALL ZipPackage::commitChanges( )
{ {
#ifdef _DEBUG_RECURSION_ #ifdef _DEBUG_RECURSION_
TestZip *pFoo = new TestZip(L"e:/clean/foo.txt", sal_False); TestZip *pFoo = new TestZip(L"e:/clean/foo.txt", sal_False);
pRootFolder->saveContents(OUString::createFromAscii(""), *pFoo); pRootFolder->saveContents(OUString::createFromAscii(""), *pFoo);
pFoo->closeInput(); pFoo->closeInput();
#else #else
pRootFolder->saveContents(OUString::createFromAscii("")); std::vector < ManifestEntry * > aManList;
pRootFolder->saveContents(OUString::createFromAscii(""), aManList);
#endif #endif
ZipEntry aEntry;
ZipPackageBuffer *pBuffer = new ZipPackageBuffer(65535);
Reference < XOutputStream > xOutStream = pBuffer;
aEntry.nVersion = -1;
aEntry.nFlag = -1;
aEntry.nMethod = STORED;
aEntry.nTime = -1;
aEntry.nCrc = -1;
aEntry.nCompressedSize = -1;
aEntry.nSize = -1;
aEntry.nOffset = -1;
aEntry.sName = OUString::createFromAscii("META-INF/manifest.xml");
pZipOut->putNextEntry(aEntry);
ManifestWriter aWriter ( xOutStream, aManList);
aWriter.Write();
pBuffer->aBuffer.realloc(pBuffer->getPosition());
pZipOut->write(pBuffer->aBuffer, 0, pBuffer->getPosition());
pZipOut->closeEntry();
pZipOut->finish(); pZipOut->finish();
} }
sal_Bool SAL_CALL ZipPackage::hasPendingChanges( ) sal_Bool SAL_CALL ZipPackage::hasPendingChanges( )

View File

@@ -2,9 +2,9 @@
* *
* $RCSfile: ZipPackageBuffer.cxx,v $ * $RCSfile: ZipPackageBuffer.cxx,v $
* *
* $Revision: 1.3 $ * $Revision: 1.4 $
* *
* last change: $Author: mtg $ $Date: 2000-11-23 14:15:52 $ * last change: $Author: mtg $ $Date: 2000-11-27 16:55:07 $
* *
* The Contents of this file are made available subject to the terms of * The Contents of this file are made available subject to the terms of
* either of the following licenses * either of the following licenses
@@ -166,9 +166,6 @@ void SAL_CALL ZipPackageBuffer::seek( sal_Int64 location )
sal_Int64 SAL_CALL ZipPackageBuffer::getPosition( ) sal_Int64 SAL_CALL ZipPackageBuffer::getPosition( )
throw(IOException, RuntimeException) throw(IOException, RuntimeException)
{ {
sal_Int8 nP = aBuffer[nCurrent];
sal_Int8 nR = aBuffer[nEnd];
int i =0;
return nCurrent; return nCurrent;
} }
sal_Int64 SAL_CALL ZipPackageBuffer::getLength( ) sal_Int64 SAL_CALL ZipPackageBuffer::getLength( )

View File

@@ -2,9 +2,9 @@
* *
* $RCSfile: ZipPackageFolder.cxx,v $ * $RCSfile: ZipPackageFolder.cxx,v $
* *
* $Revision: 1.7 $ * $Revision: 1.8 $
* *
* last change: $Author: mtg $ $Date: 2000-11-24 10:34:27 $ * last change: $Author: mtg $ $Date: 2000-11-27 16:55:07 $
* *
* The Contents of this file are made available subject to the terms of * The Contents of this file are made available subject to the terms of
* either of the following licenses * either of the following licenses
@@ -121,19 +121,30 @@ void SAL_CALL ZipPackageFolder::release( )
void SAL_CALL ZipPackageFolder::insertByName( const ::rtl::OUString& aName, const uno::Any& aElement ) void SAL_CALL ZipPackageFolder::insertByName( const ::rtl::OUString& aName, const uno::Any& aElement )
throw(lang::IllegalArgumentException, container::ElementExistException, lang::WrappedTargetException, uno::RuntimeException) throw(lang::IllegalArgumentException, container::ElementExistException, lang::WrappedTargetException, uno::RuntimeException)
{ {
if (hasByName(aName)) OUString sName;
if (aName.indexOf('/', 0 ) == 0)
sName = aName.copy(1, aName.getLength());
else
sName = aName;
if (hasByName(sName))
throw container::ElementExistException(); throw container::ElementExistException();
else else
{ {
uno::Reference < lang::XUnoTunnel > xRef; uno::Reference < lang::XUnoTunnel > xRef;
aElement >>= xRef; aElement >>= xRef;
aContents[aName] = xRef; aContents[sName] = xRef;
} }
} }
void SAL_CALL ZipPackageFolder::removeByName( const ::rtl::OUString& Name ) void SAL_CALL ZipPackageFolder::removeByName( const ::rtl::OUString& Name )
throw(container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException) throw(container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
{ {
aContents.erase(Name); OUString sName;
if (Name.indexOf('/', 0 ) == 0)
sName = Name.copy(1, Name.getLength());
else
sName = Name;
aContents.erase(sName);
} }
// XEnumerationAccess // XEnumerationAccess
uno::Reference< container::XEnumeration > SAL_CALL ZipPackageFolder::createEnumeration( ) uno::Reference< container::XEnumeration > SAL_CALL ZipPackageFolder::createEnumeration( )
@@ -157,7 +168,12 @@ uno::Any SAL_CALL ZipPackageFolder::getByName( const ::rtl::OUString& aName )
throw(container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException) throw(container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
{ {
uno::Any aAny; uno::Any aAny;
TunnelHash::const_iterator aCI = aContents.find(aName); OUString sName;
if (aName.indexOf('/', 0 ) == 0)
sName = aName.copy(1, aName.getLength());
else
sName = aName;
TunnelHash::const_iterator aCI = aContents.find(sName);
if (aCI == aContents.end()) if (aCI == aContents.end())
throw container::NoSuchElementException(); throw container::NoSuchElementException();
// rtl::OUString sTemp = aCI->first; // rtl::OUString sTemp = aCI->first;
@@ -177,13 +193,24 @@ uno::Sequence< ::rtl::OUString > SAL_CALL ZipPackageFolder::getElementNames( )
sal_Bool SAL_CALL ZipPackageFolder::hasByName( const ::rtl::OUString& aName ) sal_Bool SAL_CALL ZipPackageFolder::hasByName( const ::rtl::OUString& aName )
throw(uno::RuntimeException) throw(uno::RuntimeException)
{ {
return aContents.find(aName) != aContents.end(); OUString sName;
if (aName.indexOf('/', 0 ) == 0)
sName = aName.copy(1, aName.getLength());
else
sName = aName;
return aContents.find(sName) != aContents.end();
} }
// XNameReplace // XNameReplace
void SAL_CALL ZipPackageFolder::replaceByName( const ::rtl::OUString& aName, const uno::Any& aElement ) void SAL_CALL ZipPackageFolder::replaceByName( const ::rtl::OUString& aName, const uno::Any& aElement )
throw(lang::IllegalArgumentException, container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException) throw(lang::IllegalArgumentException, container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
{ {
removeByName(aName); OUString sName;
if (aName.indexOf('/', 0 ) == 0)
sName = aName.copy(1, aName.getLength());
else
sName = aName;
if (hasByName(aName))
removeByName(aName);
insertByName(aName, aElement); insertByName(aName, aElement);
} }
//XPropertySet //XPropertySet
@@ -239,7 +266,7 @@ void SAL_CALL ZipPackageFolder::removeVetoableChangeListener( const ::rtl::OUStr
#ifdef _DEBUG_RECURSION_ #ifdef _DEBUG_RECURSION_
void ZipPackageFolder::saveContents(rtl::OUString &rPath, TestZip &rFoo) void ZipPackageFolder::saveContents(rtl::OUString &rPath, TestZip &rFoo)
#else #else
void ZipPackageFolder::saveContents(rtl::OUString &rPath) void ZipPackageFolder::saveContents(rtl::OUString &rPath, std::vector < ManifestEntry *> &rManList)
#endif #endif
{ {
uno::Reference < lang::XUnoTunnel > xTunnel; uno::Reference < lang::XUnoTunnel > xTunnel;
@@ -282,10 +309,14 @@ void ZipPackageFolder::saveContents(rtl::OUString &rPath)
pFolder->aEntry.nTime = ZipOutputStream::tmDateToDosDate ( *localtime(&nTime)); pFolder->aEntry.nTime = ZipOutputStream::tmDateToDosDate ( *localtime(&nTime));
rZipOut.putNextEntry(pFolder->aEntry); rZipOut.putNextEntry(pFolder->aEntry);
rZipOut.closeEntry(); rZipOut.closeEntry();
ManifestEntry *pMan = new ManifestEntry;
pMan->sMediaType = OUString::createFromAscii("");
pMan->sFullPath = pFolder->aEntry.sName;
rManList.push_back (pMan);
#ifdef _DEBUG_RECURSION_ #ifdef _DEBUG_RECURSION_
pFolder->saveContents(pFolder->aEntry.sName, rFoo); pFolder->saveContents(pFolder->aEntry.sName, rFoo);
#else #else
pFolder->saveContents(pFolder->aEntry.sName); pFolder->saveContents(pFolder->aEntry.sName, rManList);
#endif #endif
} }
else else
@@ -315,6 +346,11 @@ void ZipPackageFolder::saveContents(rtl::OUString &rPath)
break; break;
} }
rZipOut.closeEntry(); rZipOut.closeEntry();
ManifestEntry *pMan = new ManifestEntry;
uno::Any aAny = pStream->getPropertyValue(OUString::createFromAscii("MediaType"));
aAny >>= pMan->sMediaType;
pMan->sFullPath = pStream->aEntry.sName;
rManList.push_back (pMan);
} }
} }
} }

View File

@@ -2,9 +2,9 @@
# #
# $RCSfile: makefile.mk,v $ # $RCSfile: makefile.mk,v $
# #
# $Revision: 1.7 $ # $Revision: 1.8 $
# #
# last change: $Author: mtg $ $Date: 2000-11-24 11:16:13 $ # last change: $Author: mtg $ $Date: 2000-11-27 16:55:07 $
# #
# The Contents of this file are made available subject to the terms of # The Contents of this file are made available subject to the terms of
# either of the following licenses # either of the following licenses
@@ -76,12 +76,15 @@ ENABLE_EXCEPTIONS=TRUE
# --- Files -------------------------------------------------------- # --- Files --------------------------------------------------------
SLOFILES= \ SLOFILES= \
$(SLO)$/ZipPackage.obj \ $(SLO)$/ZipPackage.obj \
$(SLO)$/ZipPackageBuffer.obj \ $(SLO)$/ZipPackageBuffer.obj \
$(SLO)$/ZipPackageEntry.obj \ $(SLO)$/ZipPackageEntry.obj \
$(SLO)$/ZipPackageFolder.obj \ $(SLO)$/ZipPackageFolder.obj \
$(SLO)$/ManifestExport.obj \
$(SLO)$/ManifestWriter.obj \
$(SLO)$/AttributeList.obj \
$(SLO)$/ZipPackageFolderEnumeration.obj \ $(SLO)$/ZipPackageFolderEnumeration.obj \
$(SLO)$/ZipPackageSink.obj \ $(SLO)$/ZipPackageSink.obj \
$(SLO)$/ZipPackageStream.obj $(SLO)$/ZipPackageStream.obj
# --- UNO stuff --------------------------------------------------- # --- UNO stuff ---------------------------------------------------