Resolve conkeyref

Post here questions and problems related to oXygen frameworks/document types.
Lordy
Posts: 8
Joined: Thu Aug 01, 2024 5:22 pm

Resolve conkeyref

Post by Lordy »

Hi team.
I'm new working with the Oxygen's API and currently I'm trying to resolve some <ph> tags with a conkeyref attribute, for example:

Code: Select all

<title id="GUID-XXXX-XXXX-XXXX">
	How Oxygen Works with <ph conkeyref="GUID-YYYY-YYYY-YYYY/AA-0000-BB-2222"/>
</title>
The main idea is to get the text from the <ph> reference and return the entire string (for example: "How Oxygen Works with XMLs Files").
Someone has any idea how to do it?
Thanks a lot.
Radu
Posts: 9217
Joined: Fri Jul 09, 2004 5:18 pm

Re: Resolve conkeyref

Post by Radu »

Hi,
I'm not sure I understand, could you elaborate?
Oxygen should already resolved conrefs and conkeyrefs in the Author visual editing mode so that the referenced content becomes visible.
Are you working with the API for the Oxygen desktop or Oxygen in-browser WebAuthor?
Are you building a plugin or a framework configuration?
Why isn't Oxygen's default behavior of resolving content references enough for you?
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
Lordy
Posts: 8
Joined: Thu Aug 01, 2024 5:22 pm

Re: Resolve conkeyref

Post by Lordy »

Hi Radu, my bad.

I'm developing a plugin for Oxygen Desktop version 24.1.
I was trying to access to the <title> tag through the XML Document Class, but I hadn't noticed that I can use the AuthorDocumentController Class to bring the AuthorNode for the selected tag, which returns the tag with the resolved references.

Right now, my problem is solved. I apologize for any inconvenience.
Thanks.
Radu wrote: Fri Aug 02, 2024 6:56 am Hi,
I'm not sure I understand, could you elaborate?
Oxygen should already resolved conrefs and conkeyrefs in the Author visual editing mode so that the referenced content becomes visible.
Are you working with the API for the Oxygen desktop or Oxygen in-browser WebAuthor?
Are you building a plugin or a framework configuration?
Why isn't Oxygen's default behavior of resolving content references enough for you?
Regards,
Radu
Radu
Posts: 9217
Joined: Fri Jul 09, 2004 5:18 pm

Re: Resolve conkeyref

Post by Radu »

Hi,
Right, once a conref/conkeyref is expanded in the Author visual editing mode, the "AuthorNode's" for that expanded content should be in the structure of nodes of the current document and can be accessed.
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
Lordy
Posts: 8
Joined: Thu Aug 01, 2024 5:22 pm

Re: Resolve conkeyref

Post by Lordy »

Thanks, Radu.

Just another question, there's a way to check if the conref/conkeyref is resolved correctly?

I mean, we have some cases where the reference can't be resolved, in those cases Oxygen display the conref/conkeyref value directly, and when I get the text for that node through the AuthorNode.getTextContent() method, it retrieves the reference and the text, for example:

Code: Select all

<title id="GUID-XXXX-XXXX-XXXX">
	How Oxygen Works with <ph conkeyref="GUID-YYYY-YYYY-YYYY/AA-0000-BB-2222"/>
</title>
If Oxygen can't find the reference, the returned text is: "How Oxygen Works with GUID-YYYY-YYYY-YYYY/AA-0000-BB-2222". In this case we're expecting to replace that reference value by a whitespace or any other string.

You have any idea how I can check it? Again, I'm developing a plugin for Oxygen Desktop in its version 24.1.
Thanks a lot!
Radu
Posts: 9217
Joined: Fri Jul 09, 2004 5:18 pm

Re: Resolve conkeyref

Post by Radu »

Hi,
So let's say you have this particular conkeyref in the DITA XML topic:

Code: Select all

<ph conkeyref="GUID-YYYY-YYYY-YYYY/AA-0000-BB-2222"/>
The internal structure of nodes when a conref is properly resolved looks like this:

Code: Select all

  <ph (conref/conkeyref)>
    <referenceNode>
       <ph (the target reused element)>
so the Java code to look if the <ph> has a proper resolved conref/conkeyref would look like this:

Code: Select all

    AuthorNode[] nodes = authorAccess.getDocumentController().findNodesByXPath("//ph[@conkeyref='GUID-YYYY-YYYY-YYYY/AA-0000-BB-2222']", false, false, false);
    AuthorElement ph = (AuthorElement) nodes[0];
    List<AuthorNode> contentNodes = ph.getContentNodes();
    if(!contentNodes.isEmpty()) {
      //The first child node of the ph should be a reference node.
      AuthorNode node = contentNodes.get(0);
      if(node.getType() == AuthorNode.NODE_TYPE_REFERENCE) {
        AuthorReferenceNode refNode = (AuthorReferenceNode) node;
        //And the first child of the reference node
        //should be the target referenced <ph> from the target document.
        List<AuthorNode> refContentNodes = refNode.getContentNodes();
        if(! refContentNodes.isEmpty()) {
          AuthorNode targetPh = refContentNodes.get(0);
          if("ph".equals(targetPh.getName())) {
            //The reference is properly resolved.
            AuthorElement targetPhElement = (AuthorElement) targetPh;
            String text = targetPhElement.getTextContent();
          }
        }
      }
    }
  
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
Lordy
Posts: 8
Joined: Thu Aug 01, 2024 5:22 pm

Re: Resolve conkeyref

Post by Lordy »

Hi Radu, I didn't know that Oxygen behavior.
Thanks a lot, your solution worked for me.
cosminef
Site Admin
Posts: 163
Joined: Wed Aug 30, 2023 2:33 pm

Re: Resolve conkeyref

Post by cosminef »

Hello,
I'm working with the in-browser WebAuthor. Any tips for better conref
handling in this environment?
Thank you for contacting us.
In order to provide you with the most suitable solution for your situation, can you please elaborate in detail on your use case?

Best.
Cosmin
Cosmin Eftenie
www.oxygenxml.com
Post Reply