Re: [API] How to retrieve a document property

2014-06-26 Thread Amenel VOGLOZIN
Hi all,

Alexandro, I had spotted the XDocumentProperties interface. I had seen it's 
meant to provide document properties but I had put it aside until I could get 
event notifications sorted out.

In that interface, there are only 2 suitable methods to read (or load) 
properties: loadFromStorage and loadFromMedium. Both of these have [in] 
parameters only and both return void... So I'm wondering, how is the client 
code supposed to retrieve the value of say, the ModifiedBy attribute?

The documentation isn't clear at all. For instance, the second parameter in 
both functions is explained to be a 
MediaDescriptor:http://www.openoffice.org/api/docs/common/ref/com/sun/star/document/MediaDescriptor.html
 says So this descriptor should be used as an in/out parameter. but the 
parameter is specified in loadFromMedium as [in].


I haven't found sample code that retrieves document properties with 
XDocumentProperties. Here's what I tried:
        if (docPropsSupplier != null) {
            XDocumentProperties docProps = 
docPropsSupplier.getDocumentProperties();
            if (url != null) {
                ListPropertyValue propertiesToFetch = getPropertiesToFetch();
                PropertyValue[] propsArray = propertiesToFetch.toArray(new 
PropertyValue[0]);
                try {
                    docProps.loadFromMedium(url, propsArray);
                } catch (WrongFormatException e) {
                …

(The url was retrieved earlier in the code.)

I thought propsArray would somehow be filled with the properties (Author, 
Title, etc.) that I was interested in. That didn't happen (verified by 
debugging the extension), which isn't really surprising since the parameter is 
labeled [in]. Just for the sake of trying, I also tried the call with an 
empty propsArray, thinking that maybe the entire set of available properties 
would be retrieved. To no avail.

Therefore, as is, the call to loadFromMedium has no effect as far as my client 
code is concerned. I'm back to square one.

To sum up, I just want to sysout a property (e.g. the original author) of a 
document but I don't succeed in getting that information in a variable.

Does anyone see what I could be doing wrong here? Are the loadFromMedium calls 
supposed to have a side effect, making the properties available via some other 
mechanism?

Thank you.




Le Mercredi 25 juin 2014 18h36, Alexandro Colorado j...@oooes.org a écrit :
 


Here is some documentaion on file properties under the XDocumentProperties
https://wiki.openoffice.org/wiki/API/Samples/Java/Office/DocumentHandling

Re: [API] How to retrieve a document property

2014-06-26 Thread Ariel Constenla-Haile
On Thu, Jun 26, 2014 at 02:58:18PM +0100, Amenel VOGLOZIN wrote:
 Hi all,
 
 Alexandro, I had spotted the XDocumentProperties interface. I had seen
 it's meant to provide document properties but I had put it aside until
 I could get event notifications sorted out.

If you only want two (when a document is opened and closed), then you
should go for the css.task.Job, a global document event listener is an
overhead as it will listen to every event for every document.

 In that interface, there are only 2 suitable methods to read (or
 load) properties: loadFromStorage and loadFromMedium. Both of these
 have [in] parameters only and both return void... So I'm wondering,
 how is the client code supposed to retrieve the value of say, the
 ModifiedBy attribute?
 Therefore, as is, the call to loadFromMedium has no effect as far as
 my client code is concerned. I'm back to square one.

Don't use that, the document model implements
http://www.openoffice.org/api/docs/common/ref/com/sun/star/document/XDocumentPropertiesSupplier.html
and this gives direct access to the interface's attributes, just use the
getters to retrieve the information.

 To sum up, I just want to sysout a property (e.g. the original author)
 of a document but I don't succeed in getting that information in
 a variable.

In Basic:
author = ThisComponent.getDocumentProperties().Author
MsgBox author


Regards
-- 
Ariel Constenla-Haile
La Plata, Argentina


signature.asc
Description: Digital signature