Thanks, I have got this working in my Java app now too. This creates a metadata graph in a new, custom file "customMeta.xml" stored within the document .odt file, and as you said this persists if the document is opened, edited and saved. In this graph I have been able to add multiple custom metadata items linked to each paragraph, using their unique ID inserted with the "ensureMetadataReference" method.
Thanks a lot for the help!
Code:
XDocumentMetadataAccess metadataAccess = UnoRuntime.queryInterface(XDocumentMetadataAccess.class, xComp); XURI metaTypeSequence = URI.createKnown(xContext, URIs.RDF_SEQ);XURI metaTypeComment = URI.createKnown(xContext, URIs.RDFS_COMMENT);XURI metaTypeLabel = URI.createKnown(xContext, URIs.RDFS_LABEL); XURI[] metaTypes = new XURI[] {metaTypeSequence, metaTypeComment, metaTypeLabel}; XURI metaGraphName = metadataAccess.addMetadataFile("customMeta.xml", metaTypes);XNamedGraph metaGraph = xRepo.getGraph(metaGraphName);...XMetadatable metadatable = UnoRuntime.queryInterface(XMetadatable.class, xTextElement);metadatable.ensureMetadataReference();XURI paraUri = UnoRuntime.queryInterface(XURI.class, xTextElement);String paraId = Integer.toString(paraNum + 100);XLiteral literal = Literal.create(xContext, paraId);metaGraph.addStatement(paraUri, metaTypeSequence, literal);literal = Literal.create(xContext, "This is a comment on Para Id " + paraId);metaGraph.addStatement(paraUri, metaTypeComment, literal);literal = Literal.create(xContext, "davide");metaGraph.addStatement(paraUri, metaTypeLabel, literal);
Statistics: Posted by ellisdp — Thu Dec 12, 2024 4:51 pm