LibreOffice 24.2.4.2 on Windows, using the Java SDK.
I am trying to find a way to associate custom metadata with individual text paragraphs in a LibreOffice document, which I can construct or manipulate using the SDK. So when adding each paragraph I want the ability to add a custom ID, e.g. 101, 102 or whatever, which I can cross-reference with content in a database, and which is preserved if the document is edited and the paragraphs reordered.
I have found the class com.sun.star.text.InContentMetadata which sounds like it might do what I want, and is documented here:
https://api.libreoffice.org/docs/idl/re ... adata.html
However I cannot seem to find this in the SDK from my Java environment. My Java IDE is picking up "libreoffice.jar" from C:\Program Files\LibreOffice\program\classes, and if I open that Jar it does not contain this class (nor a number of other documented classes).
Does that class exist, if so do you know why I am not picking that up in the SDK - are there additional Jars I need to import to access the full set of classes? And if it does exist, are there any code examples or documentation of how to use this?
Thanks.
Add custom metadata using InContentMetadata
Add custom metadata using InContentMetadata
LibreOffice 24.2 on Windows
Re: Add Custom Metadata using InContentMetadata
Hi, the easiest way to get support is to prepare a minimum sample in OO Basic and then ask for help with translating to Java
Re: Add Custom Metadata using InContentMetadata
What kind of LibreOffice document? Writer?
Each paragraph already has a metadata reference which uniquely identifies it though I don't know how persistent that reference is.
Edit:
to make it your own reference number you'd just need a lookup table somewhere with your number stored beside it.
Edits can easily remove a paragraph though.
Each paragraph already has a metadata reference which uniquely identifies it though I don't know how persistent that reference is.
Edit:
to make it your own reference number you'd just need a lookup table somewhere with your number stored beside it.
Edits can easily remove a paragraph though.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Re: Add Custom Metadata using InContentMetadata
Thanks, yes, Writer.
If I open the saved document content in content.xml within the .odt, I don't see a unique reference, I see things like this:
Code: Select all
<text:p text:style-name="Text_20_body">It was the best of times, it was the worst of times ...</text:p>
LibreOffice 24.2 on Windows
Re: Add Custom Metadata using InContentMetadata
You're right, its lost on saving so that's no use.
You could try ParaUserDefinedAttributes but my past experience suggests this may be prone to problems. Other methods would be bookmarks, or hidden text perhaps.
ParaUserDefinedAttributes, based on Zizi64's code from
viewtopic.php?t=111531
Saved in content.xml
You could try ParaUserDefinedAttributes but my past experience suggests this may be prone to problems. Other methods would be bookmarks, or hidden text perhaps.
ParaUserDefinedAttributes, based on Zizi64's code from
viewtopic.php?t=111531
Code: Select all
sub TestParaUserDefinedAttributes
p= thiscomponent.text.createenumeration.nextelement
Dim oUserData 'A copy of the UserDefinedAttributes
Dim oMyAttribute As New com.sun.star.xml.AttributeData
Dim oAttribute
Dim oDoc
'oDoc = createNewCalcDoc() REM-ed by Zizi64
oDoc = Thiscomponent 'Inserted by Zizi64
oMyAttribute.Type = "CDATA"
oMyAttribute.Value = "Andrew Pitonyak"
REM Here is where things usually go wrong with a statement like
REM oCell.UserDefinedAttributes.insertByName("Andy", oMyAttribute)
REM This fails every time. Instead, first make a copy and then
REM operate on the copy.
oUserData = p.ParaUserDefinedAttributes
If NOT oUserData.hasByName("Andy") Then
oUserData.insertByName("Andy", oMyAttribute)
p.ParaUserDefinedAttributes = oUserData
End If
oAttribute = p.ParaUserDefinedAttributes.getByName("Andy")
'Xray oCell
Print oAttribute.Value
End Sub
<style:style style:name="P1" style:family="paragraph" style:parent-style-name="Heading_20_3">
<style:paragraph-properties Andy="Andrew Pitonyak"/>
</style:style>
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)