<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<p>Hallo,<br>
We did some test to use RDF (also Miklos his advice) to store some information about images in a Writerdoc, before we stored the information in the ImageObject , what was not a good idea.<br>
Greetz<br>
Fernand<br>
</p>
<p>below the code who works well</p>
<p>const BASE_TYPE = <a class="moz-txt-link-rfc2396E" href="http://PMGopmaak.writer/Allgraphics">
"http://PMGopmaak.writer/Allgraphics"</a><br>
const TYPE_NAME = "GraphicURL"<br>
<br>
const FILE_NAME = "PMGopmaak.writer/Allgraphics.rdf"<br>
<br>
<br>
Sub StoreRDF<br>
  RemoveRDF()<br>
  <br>
  ' "graph" staat hier niet voor een graphic maar voor een ellement die data kan omschrijven en stockeren<br>
  ' een "litera" is een string die we stockeren en kunnen opvragen <br>
  doc = ThisComponent<br>
  repo = doc.getRDFRepository()<br>
  type_uri = GetTypeURI()<br>
  graph_name = doc.addMetadataFile(FILE_NAME, Array(type_uri))<br>
  named_graph = repo.getGraph(graph_name)<br>
  <br>
  value_uri = CreateURI(com.sun.star.rdf.URIs.RDF_VALUE)<br>
  <br>
 <br>
  <br>
  if doc.supportsService("com.sun.star.text.TextDocument") then<br>
    <br>
   oDocGraphics = doc.GraphicObjects<br>
 <br>
    vAlleFotos = oDocGraphics.getElementNames()<br>
            aantal = oDocGraphics.count<br>
             For iG = 0 to aantal - 1 <br>
            iFotNr = ig + 1<br>
             '   sFotMetNr = vAlleFotos(iG)<br>
                oGraphic1 = oDocGraphics.GetbyIndex(ig)<br>
  named_graph.addStatement(CreateURI(oGraphic1.Name &":", "URL"),value_uri,CreateLiteral(Ographic1.Title))<br>
  named_graph.addStatement(CreateURI(oGraphic1.Name &":", "ONDERSCHRIFT"),value_uri,CreateLiteral(Ographic1.Hyperlinkname))<br>
 <br>
  next IG <br>
<br>
  End If<br>
  <br>
  doc.setModified(True)<br>
End Sub<br>
<br>
Sub ReadRDF()<br>
zoek = "Image1:URL"<br>
  doc = ThisComponent<br>
  repo = doc.getRDFRepository()<br>
 <br>
  type_uri = GetTypeURI()<br>
<br>
  graph_names = doc.getMetadataGraphsWithType(type_uri)<br>
<br>
  If ubound(graph_names) = -1 then exit sub<br>
  <br>
  graph_name = graph_names(0)<br>
  <br>
  named_graph = repo.getGraph(graph_name)<br>
  value_uri = CreateURI(com.sun.star.rdf.URIs.RDF_VALUE)<br>
 <br>
 ' named_graph.clear<br>
  enume = named_graph.getStatements(Null, value_uri, Null)<br>
 ' xray named_graph.getStatements(null, value_uri, Null)<br>
  s = ""<br>
   Do while Enume.hasMoreElements <br>
    st = enume.nextElement()<br>
     name = st.Subject.StringValue<br>
       sts = st.Object.StringValue<br>
    s = s & name & ": " & sts & chr(10)<br>
    print name<br>
   ' if name = zoek  then<br>
   ' print sts<br>
  ' named_graph.removeStatements(st.Subject, value_uri,st.Object)<br>
   ' exit do<br>
  ' endif<br>
 loop<br>
<br>
  msgbox s<br>
End Sub<br>
<br>
<br>
Sub RemoveRDF<br>
  doc = ThisComponent<br>
  repo = doc.getRDFRepository()<br>
  <br>
  type_uri = GetTypeURI()<br>
  graph_names = doc.getMetadataGraphsWithType(type_uri)<br>
  if ubound(graph_names) = -1 then exit sub<br>
  graph_name = graph_names(0)<br>
  doc.removeMetadataFile(graph_name)<br>
  doc.setModified(True)<br>
End Sub<br>
<br>
<br>
Function GetTypeURI() As variant<br>
  GetTypeURI = CreateURI(BASE_TYPE & "/" & TYPE_NAME)<br>
End Function<br>
<br>
<br>
Function CreateURI(n, Optional l) As Variant<br>
  If IsMissing(l) Then<br>
    a = Array(n)<br>
  Else<br>
    a = Array(n, l)<br>
  End If<br>
  uri = CreateUnoServiceWithArguments("com.sun.star.rdf.URI", a)<br>
  CreateURI = uri<br>
End Function<br>
<br>
Function CreateLiteral(v) As Variant<br>
  a = Array(v)<br>
  literal = CreateUnoServiceWithArguments("com.sun.star.rdf.Literal", a)<br>
  CreateLiteral = literal<br>
End Function<br>
<br>
<br>
<br>
<br>
</p>
<p><br>
</p>
<div class="moz-cite-prefix">On 1/11/2019 9:27 AM, Miklos Vajna wrote:<br>
</div>
<blockquote type="cite" cite="mid:20190111082748.GQ13848@collabora.com">
<pre class="moz-quote-pre" wrap="">Hi Vincent,

On Thu, Jan 10, 2019 at 02:13:58PM +0000, LORENZO Vincent <a class="moz-txt-link-rfc2396E" href="mailto:vincent.lorenzo@cea.fr"><vincent.lorenzo@cea.fr></a> wrote:
</pre>
<blockquote type="cite">
<pre class="moz-quote-pre" wrap="">Question 1:
Currently we are studying the possibility to use the Bookmark field's name to store these datas. We want to use the Bookmark with start and end tag, to get something like that.
<text:bookmark-start text:name="UML_element_qualified_name_and_others_useful_informations" />
              Some text
       <text:bookmark-end text:name=" UML_element_qualified_name_and_others_useful_informations " />

In reality, I would prefer to be able to use a more structured datas, extending the Bookmark object (or using another solution ? ) to get that, something like that:

       <text:bookmark-start text:name="Bookmark1" umlElementQualifiedName="Package1::Class1" umlElementKind="Class" umlElementfeature="name" id="xxx"/>
                           Some text
       <text:bookmark-end text:name="Bookmark1" />

but I have no idea if it is possible and how to do that. Please, does someone have an idea to structure my datas ?
Of course, if you have a better solution than Bookmark, fell free to propose it.
</pre>
</blockquote>
<pre class="moz-quote-pre" wrap="">
Bookmark is just a string; one hack you can do is to give it a unique
name, which refers to a per-document custom metadata, where the value
disturbs the user less. But that's still just a string, so you need to
serialize/load to/from string if you want to store key-value pairs.

An alternative is to use RDF annotations, which allows more complex
structures:

<a class="moz-txt-link-freetext" href="https://wiki.openoffice.org/wiki/Documentation/DevGuide/OfficeDev/RDF_metadata">https://wiki.openoffice.org/wiki/Documentation/DevGuide/OfficeDev/RDF_metadata</a>

(Though you need to use archive.org or something like that to access it,
seems the Apache site is currently not available.)

One shortcoming of RDF is that it's ODF-only; while the per-doc custom
metadata + bookmarks works with most other formats as well.

</pre>
<blockquote type="cite">
<pre class="moz-quote-pre" wrap="">So, in this example, I write text, I look for it, then I create a XTextRange and at the end, I can create the Bookmark. I'm not very have happy with this solution. I would prefer a solution without the search step, but I don't know how to get a valid XTextRange (I admit I don't yet well understand  the behavior of the API).
Please, do you have some pointer or code example ?
</pre>
</blockquote>
<pre class="moz-quote-pre" wrap="">
Some kind of iteration or search is necessary: if you take the user's
current selection or you iterate to the nth paragraph or you search for
text is up to you. An XTextRange is just a selection (where start and
end may point to the same document model position).

</pre>
<blockquote type="cite">
<pre class="moz-quote-pre" wrap="">I thank you to read me until here.
</pre>
</blockquote>
<pre class="moz-quote-pre" wrap="">
Hope this helps. :-)

Regards,

Miklos
</pre>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<pre class="moz-quote-pre" wrap="">_______________________________________________
LibreOffice mailing list
<a class="moz-txt-link-abbreviated" href="mailto:LibreOffice@lists.freedesktop.org">LibreOffice@lists.freedesktop.org</a>
<a class="moz-txt-link-freetext" href="https://lists.freedesktop.org/mailman/listinfo/libreoffice">https://lists.freedesktop.org/mailman/listinfo/libreoffice</a>
</pre>
</blockquote>
</body>
</html>