Hi everybody,

 

I'm implementing an extension that writes a file into an odt archive just after 
the document 

gets stored in OOo Writer. For write access of an odt file I use the code 
below. With

Linux all works fine and I have no problems. When I use the extension on 
Windows XP

the store procedure fails with these error messages:

 

error: This package may be read only!

error: general error during transfer

 

But I've found out that the code below does work on Win as well. If I set the 
filepath to

another odt file which isn't currently opened by OOo the store operation 
succeeds.

 

So I assume this has to be some kind of file locking problem. Do you have any 
ideas how

I can get this running on Windows?

 

Thanks in advance!

 

 

void Foo::StoreXmlFile(OUString sFilename, xmlChar* pData, int nDataLen) {

            printf("sFilename: %s\n", utf8(sFilename));

  Reference <XStorable> xStore (xTextDocument, UNO_QUERY);

  if (!xStore.is()) return;

  OUString aFilepath = xStore->getLocation();

  // aFilepath = C2U("file:///C:/test.odt"); // uncomment this an it works

 

  Sequence< Any > aArguments( 2 );

  aArguments[ 0 ] <<= aFilepath;

                                                            

  NamedValue aNamedValue;

  aNamedValue.Name = C2U("PackageFormat");

  aNamedValue.Value = makeAny(sal_False);

  aArguments[1] <<= aNamedValue;

  Reference< XHierarchicalNameAccess > 
xIfc(xServiceManager->createInstanceWithArguments(C2U("com.sun.star.packages.comp.ZipPackage"),

                                                                                
                                                  aArguments ), UNO_QUERY );

  Reference <XInterface> xRoot;

  xIfc->getByHierarchicalName(C2U("/")) >>= xRoot;

  Reference< XNameContainer > xNameContainer(xRoot, UNO_QUERY );

 

  Reference< XSingleServiceFactory > xFactory( xIfc, UNO_QUERY );

  Reference< XActiveDataSink > xSink( xFactory->createInstance(), UNO_QUERY );

  Reference< XUnoTunnel > xTunnel( xSink, UNO_QUERY );

 

  if( xSink.is() && xTunnel.is()) {    

    MyByteSequence aData(nDataLen);

    for (int i=0; i<nDataLen; i++)

      aData[i] = (sal_Int8) pData[i];

    SequenceInputStream aInputStream(aData);

    

    Reference <XInputStream> xInput = static_cast< XInputStream * >( new 
SequenceInputStream(aData) );

    xNameContainer->insertByName(sFilename, makeAny(xTunnel));

    

    xSink->setInputStream( xInput );

    

    // Commit changes

    Reference<XChangesBatch> xBatch ( xIfc, UNO_QUERY);

    if (xBatch.is()) {

      try {

        xBatch->commitChanges();

      }

      catch (WrappedTargetException ex) {

            printf("error: %s\n", utf8(ex.Message));

            Exception e;

            ex.TargetException >>= e;

            printf("error: %s\n", utf8(e.Message));

      }     

    }

  }

}

 

 

Jakob Lechner

Research & Development

Fabalabs Software GmbH

Honauerstraße 4

A-4020 Linz

Tel.: [+43] (70) 60 61 62

Fax: [+43] (70) 60 61 62-609

E-Mail: [EMAIL PROTECTED]

Web: http://www.fabalabs.org <http://www.fabalabs.org/> 

 

Reply via email to