summaryrefslogtreecommitdiff
path: root/filter/source/placeware/exporter.cxx
diff options
context:
space:
mode:
authorChristian Lippka <cl@openoffice.org>2002-10-02 14:43:44 +0000
committerChristian Lippka <cl@openoffice.org>2002-10-02 14:43:44 +0000
commitde2e57bf174ad1904e77f0d9a0298989644ba159 (patch)
treed8d47c31722db3dcc708645de304f3cc227cac03 /filter/source/placeware/exporter.cxx
parent6e5dbdad1debcae606939bc61ec1adb04ce648af (diff)
#103668# use placewar zip instead of our own
Diffstat (limited to 'filter/source/placeware/exporter.cxx')
-rw-r--r--filter/source/placeware/exporter.cxx338
1 files changed, 178 insertions, 160 deletions
diff --git a/filter/source/placeware/exporter.cxx b/filter/source/placeware/exporter.cxx
index c86215f5b9e5..26df47a041e3 100644
--- a/filter/source/placeware/exporter.cxx
+++ b/filter/source/placeware/exporter.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: exporter.cxx,v $
*
- * $Revision: 1.3 $
+ * $Revision: 1.4 $
*
- * last change: $Author: cl $ $Date: 2002-09-26 07:34:29 $
+ * last change: $Author: cl $ $Date: 2002-10-02 15:43:44 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -136,6 +136,7 @@
#endif
#include "exporter.hxx"
#include "Base64Codec.hxx"
+#include "zip.hxx"
using rtl::OUString;
using namespace ::com::sun::star::uno;
@@ -198,214 +199,232 @@ PageEntry::PageEntry()
}
-static void addFile( Reference< XInterface > xRootFolder, Reference< XSingleServiceFactory > xFactory, Reference< XInputStream > xInput, OUString aName )
+static void encodeFile( SvStream* pSourceStream, Reference< XOutputStream >& xOutputStream ) throw( ::com::sun::star::uno::Exception )
{
- Reference< XActiveDataSink > xSink( xFactory->createInstance(), UNO_QUERY );
- Reference< XNamed > xNamed( xSink, UNO_QUERY );
- Reference< XChild > xChild( xSink, UNO_QUERY );
-
- if( xSink.is() && xNamed.is() && xChild.is() )
+ if( pSourceStream && xOutputStream.is() )
{
- xChild->setParent( xRootFolder );
- xNamed->setName( aName );
- xSink->setInputStream( xInput );
- }
-}
+ pSourceStream->Seek(STREAM_SEEK_TO_END);
+ sal_Int32 nLen = pSourceStream->Tell();
+ pSourceStream->Seek(STREAM_SEEK_TO_BEGIN);
-sal_Bool PlaceWareExporter::doExport( Reference< XComponent > xDoc, Reference < XOutputStream > xOutputStream, const rtl::OUString& rURL, Reference < XInterface > xHandler )
-{
- mxGraphicExporter = Reference< XExporter >::query( mxMSF->createInstance( OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.drawing.GraphicExportFilter") ) ) );
+ if( 0 != pSourceStream->GetError() )
+ throw IOException();
- Reference< XDrawPagesSupplier > xDrawPagesSupplier(xDoc, UNO_QUERY);
- if(!xDrawPagesSupplier.is())
- return sal_False;
+ sal_Int32 nBufferSize = 3*1024; // !!! buffer size must be a factor of 3 for base64 to work
+ Sequence< sal_Int8 > aInBuffer( nBufferSize < nLen ? nBufferSize : nLen );
+ void* pInBuffer = aInBuffer.getArray();
- Reference< XIndexAccess > xDrawPages( xDrawPagesSupplier->getDrawPages(), UNO_QUERY );
- if(!xDrawPages.is())
- return sal_False;
+ Sequence< sal_Int8 > aOutBuffer;
- Reference< XDrawPage > xDrawPage;
+ while( nLen )
+ {
+ sal_Int32 nRead = pSourceStream->Read( pInBuffer, aInBuffer.getLength() );
- utl::TempFile aFile;
- aFile.EnableKillingFile();
+ if( (0 != pSourceStream->GetError()) || (0 == nRead) )
+ throw IOException();
-// SvFileStream aFile( OUString( RTL_CONSTASCII_USTRINGPARAM("file:///e:/test.zip") ), STREAM_TRUNC|STREAM_WRITE|STREAM_READ );
+ if( nRead < aInBuffer.getLength() )
+ {
+ aInBuffer.realloc( nRead );
+ pInBuffer = aInBuffer.getArray();
+ }
- vector< PageEntry* > aPageEntries;
+ nLen -= nRead;
- // Create new package...
- try
- {
- Reference< XInputStream > xInput;
+ rtl::OUStringBuffer aStrBuffer;
+ Base64Codec::encodeBase64( aStrBuffer, aInBuffer );
- OUString aURL( aFile.GetURL() );
-// OUString aURL( RTL_CONSTASCII_USTRINGPARAM("file:///e:/test.zip") );
- Sequence< Any > aArguments( 1 );
- aArguments[ 0 ] <<= aURL;
+ sal_Int32 nCount = aStrBuffer.getLength();
- Reference< XHierarchicalNameAccess > xIfc(
- mxMSF->createInstanceWithArguments(
- rtl::OUString::createFromAscii(
- "com.sun.star.packages.comp.ZipPackage" ),
- aArguments ), UNO_QUERY );
+ if( aOutBuffer.getLength() != nCount )
+ aOutBuffer.realloc( nCount );
- Reference< XSingleServiceFactory > xFactory( xIfc, UNO_QUERY );
- Reference< XPropertySet > xZipProperties( xFactory, UNO_QUERY );
+ sal_Int8* pBytes = aOutBuffer.getArray();
+ const sal_Unicode* pUnicode = aStrBuffer.getStr();
- if ( xZipProperties.is() )
+ while( nCount-- )
+ {
+ // since base64 is always ascii, we can cast safely
+ *pBytes++ = static_cast<sal_Int8>(*pUnicode++);
+ }
+
+ xOutputStream->writeBytes( aOutBuffer );
+ }
+ }
+}
+
+static ByteString convertString( OUString aInput )
+{
+ ByteString aRet( aInput.getStr() , RTL_TEXTENCODING_UTF8 );
+ aRet.SearchAndReplaceAll( '\r', ' ' );
+ aRet.SearchAndReplaceAll( '\n', ' ' );
+
+ return aRet;
+}
+
+static void createSlideFile( Reference< XComponent > xDoc, ZipFile& rZipFile, const rtl::OUString& rURL, vector< PageEntry* >& rPageEntries ) throw( ::com::sun::star::uno::Exception )
+{
+ ByteString aInfo;
+
+ const sal_Char* pNewLine = "\r\n";
+ OUString aTemp;
+
+ Reference< XDocumentInfoSupplier > xInfoSup( xDoc, UNO_QUERY );
+ Reference< XPropertySet > xDocInfo( xInfoSup->getDocumentInfo(), UNO_QUERY );
+
+ xDocInfo->getPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("Title"))) >>= aTemp;
+ if( 0 == aTemp.getLength() )
+ {
+ sal_Int32 nPos1 = rURL.lastIndexOf( (sal_Unicode)'/' );
+ if( -1 != nPos1 )
{
- try
+ sal_Int32 nPos2 = rURL.lastIndexOf( (sal_Unicode)'.' );
+ if( nPos2 > nPos1 )
{
- xZipProperties->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("UseManifest") ), makeAny( (sal_Bool)sal_False ) );
+ aTemp = rURL.copy( nPos1 + 1, nPos2 - nPos1 - 1 );
}
- catch( Exception& )
+ else
{
+ aTemp = rURL.copy( nPos1 + 1 );
}
+ }
+ else
+ {
+ aTemp = rURL;
+ }
+ }
- // get root zip folder
- Reference< XInterface > xRootFolder;
- OUString szRootFolder( RTL_CONSTASCII_USTRINGPARAM("/") );
- xIfc->getByHierarchicalName( szRootFolder ) >>= xRootFolder;
+ aInfo.Append( "SlideSetName: " );
+ aInfo.Append( convertString( aTemp ) );
+ aInfo.Append( pNewLine );
- // export pages
- const sal_Int32 nPageCount = xDrawPages->getCount();
- sal_Int32 nPage;
- for( nPage = 0; nPage < nPageCount; nPage++)
- {
- xDrawPages->getByIndex(nPage) >>= xDrawPage;
+ xDocInfo->getPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("Author"))) >>= aTemp;
- if( !xDrawPage.is() )
- continue;
+ aInfo.Append( "PresenterName: " );
+ aInfo.Append( convertString( aTemp ) );
+ aInfo.Append( pNewLine );
- PageEntry* pEntry = exportPage( xDrawPage );
- aPageEntries.push_back( pEntry );
+ vector< PageEntry* >::iterator aIter( rPageEntries.begin() );
+ vector< PageEntry* >::iterator aEnd( rPageEntries.end() );
+ while( aIter != aEnd )
+ {
+ PageEntry* pEntry = (*aIter++);
- OUString aName( RTL_CONSTASCII_USTRINGPARAM("i") );
- aName += OUString::valueOf( nPage );
- aName += OUString( RTL_CONSTASCII_USTRINGPARAM(".gif") );
- pEntry->setURL( aName );
- xInput = new utl::OSeekableInputStreamWrapper( new SvFileStream(pEntry->getTempURL(), STREAM_READ ), true );
+ aInfo.Append( "slide: " );
+ aInfo.Append( convertString( pEntry->getName() ) );
+ aInfo.Append( pNewLine );
- addFile( xRootFolder, xFactory, xInput, aName );
- }
+ aInfo.Append( "type: gif");
+ aInfo.Append( pNewLine );
- ByteString aInfo;
+ aInfo.Append( "url: " );
+ aInfo.Append( convertString( pEntry->getURL() ) );
+ aInfo.Append( pNewLine );
- const sal_Char* pNewLine = "\r\n";
- OUString aTemp;
+ if( pEntry->getTitle().getLength() )
+ {
+ aInfo.Append( "text: " );
+ aInfo.Append( convertString( pEntry->getTitle() ) );
+ aInfo.Append( pNewLine );
+ }
-//
- Reference< XDocumentInfoSupplier > xInfoSup( xDoc, UNO_QUERY );
- Reference< XPropertySet > xDocInfo( xInfoSup->getDocumentInfo(), UNO_QUERY );
+ if( pEntry->getNotes().getLength() )
+ {
+ aInfo.Append( "notes: " );
+ aInfo.Append( convertString( pEntry->getNotes() ) );
+ aInfo.Append( pNewLine );
+ }
+ }
- xDocInfo->getPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("Title"))) >>= aTemp;
- if( 0 == aTemp.getLength() )
- {
- sal_Int32 nPos1 = rURL.lastIndexOf( (sal_Unicode)'/' );
- if( -1 != nPos1 )
- {
- sal_Int32 nPos2 = rURL.lastIndexOf( (sal_Unicode)'.' );
- if( nPos2 > nPos1 )
- {
- aTemp = rURL.copy( nPos1 + 1, nPos2 - nPos1 - 1 );
- }
- else
- {
- aTemp = rURL.copy( nPos1 + 1 );
- }
- }
- else
- {
- aTemp = rURL;
- }
- }
+ utl::TempFile aInfoFile;
+ aInfoFile.EnableKillingFile();
- aInfo.Append( "SlideSetName: " );
- aInfo.Append( ByteString( aTemp.getStr() , RTL_TEXTENCODING_UTF8 ) );
- aInfo.Append( pNewLine );
+ SvStream* pInfoFileStream = aInfoFile.GetStream( STREAM_WRITE );
- xDocInfo->getPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("Author"))) >>= aTemp;
+ pInfoFileStream->Write( aInfo.GetBuffer(), aInfo.Len() );
+ pInfoFileStream->Seek( 0 );
- aInfo.Append( "PresenterName: " );
- aInfo.Append( ByteString( aTemp.getStr() , RTL_TEXTENCODING_UTF8 ) );
- aInfo.Append( pNewLine );
+ if(!rZipFile.addFile( *pInfoFileStream, ByteString( RTL_CONSTASCII_STRINGPARAM("slides.txt") ) ))
+ throw IOException();
+}
- vector< PageEntry* >::iterator aIter = aPageEntries.begin();
- vector< PageEntry* >::iterator aEnd = aPageEntries.end();
- while( aIter != aEnd )
- {
- PageEntry* pEntry = (*aIter++);
+#define PLACEWARE_DEBUG 1
- aInfo.Append( "slide: " );
+sal_Bool PlaceWareExporter::doExport( Reference< XComponent > xDoc, Reference < XOutputStream > xOutputStream, const rtl::OUString& rURL, Reference < XInterface > xHandler )
+{
+ mxGraphicExporter = Reference< XExporter >::query( mxMSF->createInstance( OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.drawing.GraphicExportFilter") ) ) );
- {
- UniString aTemp( pEntry->getName() );
- aInfo.Append( ByteString( aTemp , RTL_TEXTENCODING_UTF8 ) );
- aInfo.Append( pNewLine );
- }
+ Reference< XDrawPagesSupplier > xDrawPagesSupplier(xDoc, UNO_QUERY);
+ if(!xDrawPagesSupplier.is())
+ return sal_False;
- aInfo.Append( "type: gif");
- aInfo.Append( pNewLine );
+ Reference< XIndexAccess > xDrawPages( xDrawPagesSupplier->getDrawPages(), UNO_QUERY );
+ if(!xDrawPages.is())
+ return sal_False;
- {
- UniString aTemp( pEntry->getURL() );
- aInfo.Append( "url: " );
- aInfo.Append( ByteString( aTemp, RTL_TEXTENCODING_UTF8 ) );
- aInfo.Append( pNewLine );
- }
- if( pEntry->getTitle().getLength() )
- {
- aInfo.Append( "text: " );
- aInfo.Append( ByteString( UniString( pEntry->getTitle() ), RTL_TEXTENCODING_UTF8 ) );
- aInfo.Append( pNewLine );
- }
+ Reference< XDrawPage > xDrawPage;
- if( pEntry->getNotes().getLength() )
- {
- aInfo.Append( "notes: " );
- aInfo.Append( ByteString( UniString( pEntry->getNotes() ), RTL_TEXTENCODING_UTF8 ) );
- aInfo.Append( pNewLine );
- }
- }
+#ifndef PLACEWARE_DEBUG
+ utl::TempFile aFile;
+ aFile.EnableKillingFile();
+ SvStream* pZipFileStream = aFile.GetStream( STREAM_WRITE|STREAM_READ );
+ OUString aURL( aFile.GetURL() );
+#else
+ SvFileStream aFile( OUString( RTL_CONSTASCII_USTRINGPARAM("file:///e:/test.zip") ), STREAM_TRUNC|STREAM_WRITE|STREAM_READ );
+ SvStream* pZipFileStream = &aFile;
+ OUString aURL( RTL_CONSTASCII_USTRINGPARAM("file:///e:/test.zip") );
+#endif
- utl::TempFile aInfoFile;
- aInfoFile.EnableKillingFile();
+ vector< PageEntry* > aPageEntries;
- SvStream* pInfoFileStream = aInfoFile.GetStream( STREAM_WRITE );
+ // Create new package...
+ try
+ {
+ ZipFile aZipFile(*pZipFileStream);
- pInfoFileStream->Write( aInfo.GetBuffer(), aInfo.Len() );
+ // export slides as gifs and collect information for slides
- xInput = new utl::OSeekableInputStreamWrapper( pInfoFileStream );
+ const sal_Int32 nPageCount = xDrawPages->getCount();
+ sal_Int32 nPage;
+ for( nPage = 0; nPage < nPageCount; nPage++)
+ {
+ xDrawPages->getByIndex(nPage) >>= xDrawPage;
- OUString aName( RTL_CONSTASCII_USTRINGPARAM("slides.txt") );
- addFile( xRootFolder, xFactory, xInput, aName );
+ if( !xDrawPage.is() )
+ continue;
- Reference< XChangesBatch > xBatch( xIfc, UNO_QUERY );
- if( xBatch.is() )
- xBatch->commitChanges();
+ PageEntry* pEntry = exportPage( xDrawPage );
+ aPageEntries.push_back( pEntry );
- xInput = new utl::OSeekableInputStreamWrapper( aFile.GetStream( STREAM_READ ) );
-// xInput = new utl::OSeekableInputStreamWrapper( aFile );
+ OUString aName( RTL_CONSTASCII_USTRINGPARAM("i") );
+ aName += OUString::valueOf( nPage );
+ aName += OUString( RTL_CONSTASCII_USTRINGPARAM(".gif") );
+ pEntry->setURL( aName );
+ }
- const sal_Int32 nLen = xInput->available();
- Sequence< sal_Int8 > aSeq( nLen );
- xInput->readBytes( aSeq, nLen );
+ // create the slide.txt file
- rtl::OUStringBuffer aStrBuffer;
- Base64Codec::encodeBase64( aStrBuffer, aSeq );
+ createSlideFile( xDoc, aZipFile, rURL, aPageEntries );
- sal_Int32 nCount = aStrBuffer.getLength();
- aSeq.realloc( nCount );
- sal_Int8* pBytes = aSeq.getArray();
- const sal_Unicode* pUnicode = aStrBuffer.getStr();
+ // add gifs to zip
+ vector< PageEntry* >::iterator aIter( aPageEntries.begin() );
+ vector< PageEntry* >::iterator aEnd( aPageEntries.end() );
+ while( aIter != aEnd )
+ {
+ PageEntry* pEntry = (*aIter++);
- while( nCount-- )
- {
- *pBytes++ = (sal_Int8)(*pUnicode++);
- }
+ SvFileStream aStream(pEntry->getTempURL(), STREAM_READ );
+ UniString aTemp( pEntry->getURL() );
- xOutputStream->writeBytes( aSeq );
+ if( !aZipFile.addFile( aStream, ByteString( aTemp, RTL_TEXTENCODING_UTF8 ) ) )
+ throw IOException();
}
+
+ if(!aZipFile.close())
+ throw IOException();
+
+ encodeFile( pZipFileStream, xOutputStream );
+
}
catch ( RuntimeException const & )
{
@@ -416,7 +435,6 @@ sal_Bool PlaceWareExporter::doExport( Reference< XComponent > xDoc, Reference <
return sal_False;
}
-
return sal_True;
}