Matthias B. wrote:

> We have a custom OOo component and we'd like to store additional data
> inside a document that this component can access. So far we've encoded
> the data as text and then stored it in notes, but this is quite
> hackish. What we would like to do is to put an extra binary file into
> the ODT file (which after all is just a ZIP archive) and to read this
> file in our custom component. Does UNO have interfaces for accessing
> arbitrary data stored in the document's ODT file?

Yes. You must put your stream into a folder that you assign a MediaType to.
Here's some (untested) C++ code that illustrates this:

using namespace com::sun::star;
void StoreMyData( sal_Int8* pData, sal_Int32 nDataLen )
{
  Reference <document::XStorageBasedDocument> xDoc( xTextDocument,
    uno::UNO_QUERY );

  if (!xStore.is())
    return;

  Reference <embed::XStorage > xStg( xDoc->getDocumentStorage() );
  Reference <embed::XStorage > xSubStg = xStg->
    openStorageElement( sStorName, embed::ElementModes::READWRITE );
  ::rtl::OUString MyMediaType(...); // whatever you like
  ::rtl::OUString MyStgName(...); // whatever you like
  xSubStg->setPropertyValue(myStgName, makeAny(myMediaType));
  Reference <io::XStream > xStream = xSubStg->openStreamElement(
    myStreamName, embed::ElementModes::READWRITE );
  Reference <io::XOutputStream > xOut = xStream->getOutputStream();

  uno::Sequence < sal_Int8 > aData( pData, nDataLen );
  xOut->writeBytes( aData, nDataLen );
  xOut->closeOutput();
  xSubStg->commit();
}

I recommend to use a MediaType that points to your own "name space".

As an example, I would use "vnd.sun.star.MyComponent.MyData" (as I am
working for Sun/StarOffice).

So if you are a working on the component "Blob" for the company
"BlobFactory" perhaps "vnd.BlobFactory.Blob.BlobData" would be a good
idea. The name for your storage should probably also use this namespace
while the name of the stream is not important as only your own component
will access your sub storage.

Ciao,
Mathias


-- 
Mathias Bauer (mba) - Project Lead OpenOffice.org Writer
OpenOffice.org Engineering at Sun: http://blogs.sun.com/GullFOSS
Please don't reply to "[EMAIL PROTECTED]".
I use it for the OOo lists and only rarely read other mails sent to it.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to