[Solved] Setting Custom Properties from external application

Java, C++, C#, Delphi... - Using the UNO bridges
Post Reply
iwbnwif
Posts: 7
Joined: Tue Jan 10, 2012 2:21 pm

[Solved] Setting Custom Properties from external application

Post by iwbnwif »

I would like to be able to change some already defined Custom Properties (File -> Properties -> Custom Properties) in the currently active text document from my separate (large) application.

So far I have been able to achieve basically what I want to do by adding the following code to the SimpleBootstrap_cpp example:

Code: Select all

            Reference< XDocumentInfoSupplier > xDocumentInfoSupplier(xComponent, UNO_QUERY);
            Reference< XDocumentInfo > xDocumentInfo = xDocumentInfoSupplier->getDocumentInfo();
            
            Reference< XDocumentPropertiesSupplier > xDocumentPropertiesSupplier(xDocumentInfo, UNO_QUERY);
            Reference< XDocumentProperties > xDocumentProperties = xDocumentPropertiesSupplier->getDocumentProperties();
            
            Reference< XPropertyContainer > xPropertyContainer = xDocumentProperties->getUserDefinedProperties();
            Reference< XPropertySet > xPropertySet(xPropertyContainer, UNO_QUERY);
        
            Reference< XPropertySetInfo > xPropertySetInfo = xPropertySet->getPropertySetInfo();
            
            if (xPropertySetInfo->hasPropertyByName(OUString::createFromAscii("Info 1")))
            {
                Any newValue, sName;
                newValue <<= OUString::createFromAscii("Value has been set by API");
                xPropertySet->setPropertyValue (OUString::createFromAscii("Info 1"), newValue);
            }
Firstly I would welcome any comments on the above code - is it correct or have I just been lucky?

Secondly please could I ask for advice as to whether it is best to keep this as a standalone utility and execute (spawn) it from the main application or would it be possible to build it into my application or better create a shared library? If so are there any guides / notes that I have missed for doing this?

The reason for asking is that the SDK clearly does a lot of the hard work, such as setting the appropriate environment variables, calling the cpp helper tools etc.

My application is wxWidgets based and I am currently using MinGW (Windows) and gcc / clang (Linux).

Thanks!

p.s. I really appreciate the effort to get the code snippets from oooforum.org back online. It has been something of a struggle for me to get this far and Google has teased me with some tantalizing links to oooforum that are no longer available :( .
Last edited by iwbnwif on Wed Aug 06, 2014 11:29 am, edited 2 times in total.
LibreOffice 3.4.4 Linux Mint 12
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Setting Custom Properties from external application

Post by Villeroy »

Open some ODF document with a zip tool and have a look at meta.xml which contains all the custom properties in plain simple XML. You don't need an over sophisticated office API to write custom properties into the meta.xml of an ODF document.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
iwbnwif
Posts: 7
Joined: Tue Jan 10, 2012 2:21 pm

Re: Setting Custom Properties from external application

Post by iwbnwif »

Villeroy, thank you for the fast response and good idea.

I will investigate this straight away.

However I would still be interested in the possibilities of using the API from an external application in case I later need to do something more exotic.
LibreOffice 3.4.4 Linux Mint 12
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Setting Custom Properties from external application

Post by Villeroy »

Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
iwbnwif
Posts: 7
Joined: Tue Jan 10, 2012 2:21 pm

Re: Setting Custom Properties from external application

Post by iwbnwif »

Thanks again. Actually I used MRI to create the template code in my original post.

Sorry I wasn't clear about my (new) question. It is really more about compiling and linking, but I think I should first read:

https://wiki.openoffice.org/wiki/MakeFi ... me_example

To try to understand what the SDK does better.
LibreOffice 3.4.4 Linux Mint 12
iwbnwif
Posts: 7
Joined: Tue Jan 10, 2012 2:21 pm

Re: [Solved] Setting Custom Properties from external applica

Post by iwbnwif »

Open some ODF document with a zip tool and have a look at meta.xml which contains all the custom properties in plain simple XML. You don't need an over sophisticated office API to write custom properties into the meta.xml of an ODF document.
In fact this is excellent advice from Villeroy.

For reference I found by using the wxWidgets classes http://docs.wxwidgets.org/trunk/classwx ... ument.html and http://docs.wxwidgets.org/trunk/classwx ... tream.html make doing this a breeze :super:
LibreOffice 3.4.4 Linux Mint 12
Post Reply