Issue 119411 - [RDF] Read/write RDF support on ODS file format
Summary: [RDF] Read/write RDF support on ODS file format
Status: CLOSED FIXED
Alias: None
Product: Calc
Classification: Application
Component: code (show other issues)
Version: 3.4.0
Hardware: All All
: P3 Normal (vote)
Target Milestone: 4.0.0
Assignee: Ariel Constenla-Haile
QA Contact:
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-05-24 14:55 UTC by hanya
Modified: 2013-07-11 09:38 UTC (History)
3 users (show)

See Also:
Issue Type: ENHANCEMENT
Latest Confirmation in: ---
Developer Difficulty: ---


Attachments
Proposed patch to add rdf read/write support in ods (2.62 KB, patch)
2012-05-24 14:55 UTC, hanya
no flags Details | Diff
Document including test macro (12.02 KB, application/vnd.oasis.opendocument.spreadsheet)
2012-05-25 13:25 UTC, hanya
no flags Details
Document with macros showing how to embed RDF files (11.80 KB, application/vnd.oasis.opendocument.spreadsheet)
2012-05-27 01:56 UTC, Ariel Constenla-Haile
no flags Details
Patch with checking bStylesOnly and error for import (4.38 KB, patch)
2012-05-31 13:44 UTC, hanya
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this issue.
Description hanya 2012-05-24 14:55:01 UTC
Created attachment 77589 [details]
Proposed patch to add rdf read/write support in ods

AOO 3.4 supports RDF read/write and statement on some document element of Writer. 
But on Calc ODS document does not support RDF. If it supports read/write of RDF in odf file filter at least, extensions can be use it to store data in it. 

I wrote patch for ods filter according to filter of odt, main/sw/source/filter/xml/wrtxml.cxx and main/sw/source/filter/xml/swxml.cxx.
Comment 1 Ariel Constenla-Haile 2012-05-25 12:19:33 UTC
(In reply to comment #0)
> Created attachment 77589 [details]
> Proposed patch to add rdf read/write support in ods
> 
> AOO 3.4 supports RDF read/write and statement on some document element of
> Writer. 
> But on Calc ODS document does not support RDF. If it supports read/write of
> RDF in odf file filter at least, extensions can be use it to store data in
> it. 

Very nice feature :)
Can you please upload some macro or script to test the feature?
Comment 2 hanya 2012-05-25 13:25:54 UTC
Created attachment 77600 [details]
Document including test macro

(In reply to comment #1)
> Very nice feature :)
> Can you please upload some macro or script to test the feature?
Sorry, I forgot to attach test file. 

Open attached file, there are three buttons on the spreadsheet. 
- Push "Store" button, it stores values from Sheet1.A1 and A2 in rdf file. Store the document through File - Save.
- Push "Read" button, it reads values from RDF file, it should be shown like: 
Sheet1.A1:value:100 \n Sheet1.A1:value:ABC for initial state of the sheet. 
The order of these values are not important.
- In the ods document, user defined RDF file should be placed in the place specified by addMetadataFile method. 
In this macro, it should be stored in mytools_calc_watchingwindow/settings.rdf.
- Push "Remove" button to remove RDF file created by this macro. Store the document from File - Save. The rdf file should be gone from the ods file.

And manifest.rdf file is created by the office. It can be seen in ODT file now too. 
The attached macro can be executed on Writer document and it stores same value in rdf. RDF file should be stored in the same path in the odf file.

And also, I used this function in my WatchingWindow extension recently released: 
http://extensions.openoffice.org/en/node/5439
Comment 3 Ariel Constenla-Haile 2012-05-27 01:53:59 UTC
(In reply to comment #2)
> And also, I used this function in my WatchingWindow extension recently
> released: 
> http://extensions.openoffice.org/en/node/5439

It seems you are not making the selection persistent. As I doubt this is going to be considered to be included in AOO 3.4.1, you can use as a workaround the embed API together with the rdf API to embed an RDF file and then pass the stream to XRepository::import/exportGraph().

I'll attach a sample document, for those who want to use RDF in Calc/Impress/Draw/Math.
Comment 4 Ariel Constenla-Haile 2012-05-27 01:56:38 UTC
Created attachment 77608 [details]
Document with macros showing how to embed RDF files
Comment 5 Ariel Constenla-Haile 2012-05-29 15:21:38 UTC
(In reply to comment #0)
> Proposed patch to add rdf read/write support in ods
> 
> AOO 3.4 supports RDF read/write and statement on some document element of
> Writer. 
> But on Calc ODS document does not support RDF. If it supports read/write of
> RDF in odf file filter at least, extensions can be use it to store data in
> it. 
> 
> I wrote patch for ods filter according to filter of odt,
> main/sw/source/filter/xml/wrtxml.cxx and main/sw/source/filter/xml/swxml.cxx.

The patch works fine, it needs only to consider two points:
a) when only the styles are requested, RDF can be ignored
b) when loading/storing the metadata from/to the storage, the exceptions should be taken into account for the function final return value

You can see both points in 
main/sw/source/filter/xml/wrtxml.cxx 
main/sw/source/filter/xml/swxml.cxx

For (a), take into account the "OrganizerMode", and surround the code with an if-statement ( if (!bStylesOnly) ). You can debug this "OrganizerMode":
- save a spreadsheet document as template
- go to the menu "File" - "Templates" - "Organize..."
- set a break point on ScXMLImportWrapper::Import
- double click on your template
This will try to import only the styles from the file, and will list them in the  "Template Management" dialog. With the current patch, you'll see that bStylesOnly is true, but the RDF metadata is read. See in main/sw/source/filter/xml/swxml.cxx the 
if (!(IsOrganizerMode() || ...), this is there to save us from importing the RDF metdata in this case where it isn't relevant.

For (b), we shouldn't ignore the exceptions thrown by loadMetadataFromStorage/storeMetadataToStorage . Here too look at the code in main/sw/source/filter/xml/ 
While the css::lang::WrappedTargetException can be marked as an ERROR with SCERR_IMPORT_UNKNOWN, I'm not sure there is a flag  in sc/inc/scerrors.hxx to mark a WARNING when losing the RDF metadata (I mean, to flag a data/feature lost that is a WARNING, but not an ERROR). If you find that you need to add new defines in that file, flag them with the proper WARNING flag (ERRCODE_WARNING_MASK).
Comment 6 hanya 2012-05-31 13:44:55 UTC
Created attachment 77867 [details]
Patch with checking bStylesOnly and error for import

(In reply to comment #5)
> The patch works fine, it needs only to consider two points:
> a) when only the styles are requested, RDF can be ignored
Added.
> b) when loading/storing the metadata from/to the storage, the exceptions
> should be taken into account for the function final return value
I introduced SCWARN_IMPORT_FEATURES_LOST and its string resource for import. 
But ScXMLImportWrapper::Export(sal_Bool bStylesOnly) method does not have 
the way to return back error/warning code. 
I need to change the method to it. When I return sal_True from the method, 
I makes error to faled to store the file contents, not warning. 
The attached patch do not have making warning for Export method. 
I need more time to introduce the way of warning for the Export method.
Comment 7 Ariel Constenla-Haile 2012-06-10 14:41:06 UTC
@hanya: sorry for the delay, I updated my system from Fedora 16 to Fedora 17 and my build environment got completely broken (rev. 1348593, 1348595, 1348596).

Committed as Revision 1348605

@hanya: Thanks for your contribution.
Comment 8 Ariel Constenla-Haile 2012-06-10 14:56:26 UTC
(In reply to comment #6)
> Created attachment 77867 [details]
> Patch with checking bStylesOnly and error for import
> 
> (In reply to comment #5)
> > The patch works fine, it needs only to consider two points:
> > a) when only the styles are requested, RDF can be ignored
> Added.
> > b) when loading/storing the metadata from/to the storage, the exceptions
> > should be taken into account for the function final return value
> I introduced SCWARN_IMPORT_FEATURES_LOST and its string resource for import. 
> But ScXMLImportWrapper::Export(sal_Bool bStylesOnly) method does not have 
> the way to return back error/warning code. 
> I need to change the method to it. When I return sal_True from the method, 
> I makes error to faled to store the file contents, not warning. 
> The attached patch do not have making warning for Export method. 
> I need more time to introduce the way of warning for the Export method.

There are different ways of doing this, though I find more consistent how it's done in sw than in sc (you could change the return value from boolean to error code and then check it, see inline FASTBOOL IsError( sal_uLong nErr ) in sw/inc/swerror.h and its uses.

Any way the patch is very good with the changes you made, so I committed it. If you find time to do this enhancement, reopen the issue when the patch is ready.
Comment 9 hanya 2012-06-11 09:22:06 UTC
(In reply to comment #8)
> Any way the patch is very good with the changes you made, so I committed it.
> If you find time to do this enhancement, reopen the issue when the patch is
> ready.
Sure, thanks to commit.
Comment 10 Terry Yang 2012-06-20 05:46:32 UTC
Verify fixed on trunk rev.1351249 with the sample file in this bug.
Suggest close this bug.
Comment 11 binguo 2012-11-13 07:55:25 UTC
Close it.