Hello! 

  I'm chensuchun.I'm a newbie in devloping filter.I implement a filter for 
exporting and importing my own format file,whose format is based on odt.But I 
get some problems about filter.

the code of  function filter( const Sequence< PropertyValue >& rDescriptor ) is 
following:

xDoc = uno::Reference< document::XStorageBasedDocument >( mxSrcDoc, 
uno::UNO_QUERY );  ///mxSrcDoc is set by setSourceDocument()

////save to a tmp storage use filter writer8
  xSourceStorage = uno::Reference< embed::XStorage >(   
                                            xStorageFactory->createInstance(),
                                            uno::UNO_QUERY );
  uno::Sequence< beans::PropertyValue > afArgs( 1 );
  afArgs[0].Name = ::rtl::OUString::createFromAscii( "FilterName" );
  afArgs[0].Value <<= ::rtl::OUString::createFromAscii( "writer8" );
  xDoc->storeToStorage( xSourceStorage, afArgs );

////add a sub storage to the  xSourceStorage 

const ::rtl::OUString aSubStorageName ( RTL_CONSTASCII_USTRINGPARAM ( 
"SubStorage" ) );
   uno::Reference< embed::XStorage > xSubStorage = 
            xSourceStorage->openStorageElement( aSubStorageName, 
embed::ElementModes::WRITE );

uno::Reference< beans::XPropertySet > xSubStoagePro( xSubStorage, 
uno::UNO_QUERY );
   xSubStoagePro->setPropertyValue( OUString::createFromAscii("MediaType"), 
makeAny(OUString::createFromAscii("SubMediaType")) );

......

///create the target storage

uno::Sequence< uno::Any > aArgs( 2 );
 aArgs[0] <<= aURL; ////get from rDescriptor 
 aArgs[1] <<= embed::ElementModes::READWRITE;
 uno::Reference< embed::XStorage > xTargetStorage( 
      xStorageFactory->createInstanceWithArguments( aArgs ),
                        uno::UNO_QUERY );


////copy to target storage and commit

xSourceStorage->copyToStorage( xTargetStorage );
   bRet = sal_True;
   uno::Reference< XTransactedObject > xTransaction = 
    uno::Reference< XTransactedObject >( xTargetStorage, UNO_QUERY );
   if( xTransaction.is() )
    xTransaction->commit();

/////dispose them

uno::Reference< lang::XComponent > xComponent1( xSourceStorage, uno::UNO_QUERY 
);
   OSL_ENSURE( !xSourceStorage.is() || xComponent1.is(), "Wrong storage 
implementation!" );
   if ( xComponent1.is() )
    xComponent1->dispose();

   uno::Reference< lang::XComponent > xComponent2( xTargetStorage, 
uno::UNO_QUERY );
   OSL_ENSURE( !xTargetStorage.is() || xComponent2.is(), "Wrong storage 
implementation!" );
   if ( xComponent2.is() )
    xComponent2->dispose();

////End

After the execution of filter( const Sequence< PropertyValue >& rDescriptor ),

the target file is created and the size of the file is about 7KB.

But after  executing the following code in sal_Bool SfxObjectShell::SaveTo_Impl:


  // transfer data to its destinated location
  // the medium commits the storage or the stream it is based on
        RegisterTransfer( rMedium );
        bOk = rMedium.Commit();

the size of target file becomes 0 KB.

Why? 

Is some thing wrong in my filter( const Sequence< PropertyValue >& rDescriptor 
) function?

what should I do with the XStorage ? 

Any help and sugestion in identifying the missing pieces is appreciated.

Thanks   


-------------------------------------------------------------------
MOTO新摄会 狂拍无极限 超多好礼等你来赢( 
http://d1.sina.com.cn/sina/limeng3/mail_zhuiyu/2007/mail_zhuiyu_20070625.html )

===================================================================
注册新浪2G免费邮箱( http://mail.sina.com.cn/chooseMode.html

Reply via email to