Content completion issue

Post here questions and problems related to oXygen frameworks/document types.
Isabelle
Posts: 142
Joined: Fri Jan 20, 2017 1:11 pm

Content completion issue

Post by Isabelle »

Hello,

We used the version 25.0.0.0 of oxygen sdk.

We have this xsd :

Code: Select all

    <xs:attribute name="model" type="xs:string"/>
    <xs:element name="model" type="modelType"/>
    <xs:complexType name="modelType">
        <xs:sequence>
            <xs:element maxOccurs="unbounded" minOccurs="0" ref="version"/>           
            <xs:element minOccurs="0" ref="batchno"/>
            <xs:element minOccurs="0" ref="maintlevel"/>
        </xs:sequence>
        <xs:attribute ref="model" use="required"/>
    </xs:complexType>
    <xs:attribute name="version" type="xs:string"/>
    <xs:element name="version" type="versionType"/>
    <xs:complexType name="versionType">
        <xs:sequence>
            <xs:element maxOccurs="unbounded" minOccurs="0" ref="versrank"/>
        </xs:sequence>
        <xs:attribute ref="version" use="required"/>
        <xs:attribute ref="id"/>
    </xs:complexType>
    <xs:element name="versrank" type="versrankType"/>
    <xs:complexType name="versrankType">
        <xs:choice maxOccurs="unbounded">
            <xs:element ref="single"/>
            <xs:element ref="range"/>
        </xs:choice>
        <xs:attribute ref="verstatus"/>
    </xs:complexType>
    <xs:element name="single" type="xs:string"/>
    <xs:element name="range" type="xs:string"/>
In content completion, we have this :

Code: Select all

  <elementProposals path="model">
    <insertAttribute name="model" value="TBD"/>
  </elementProposals>

  <elementProposals path="version">
    <insertAttribute name="version" value="TBD"/>
  </elementProposals>
If I insert model element alone, the model attribute is well defined with TBD value.

Code: Select all

<model model="TBD"/>
If I insert version element in an existing model element, the version attribute is well defined with TBD value.

Code: Select all

<model model="TBD">
   <version version="TBD"/>
</model>
But if I force the insertion of version element without the model parent existing, the schemaAware insertion will add something like this :

Code: Select all

<model model="model_gwf_gfs_2yb">
   <version version="TBD"/>
</model>
And if I force the insertion of versrank element without the version and model parent existing, the schemaAware insertion will add something like this :

Code: Select all

 <model model="model_xpm_hfs_2yb">
   <version version="version_jqm_hfs_2yb">
      <versrank/>
   </version>
</model>
Why content completion rules are lost when insertion is build thanks to shemaAware ?

I tried to set those attributes manually thanks to AuthorDocumentFilter, but it does not work.
The method insertNode is used to insert parents node (model and/or version), before the insertion I set the attribute values.

Code: Select all

    @Override
    public boolean insertNode(AuthorDocumentFilterBypass authorDocumentFilterBypass, int i, AuthorNode authorNode) 
    {
        setRequiredAttributes(authorNode);
        return super.insertNode(authorDocumentFilterBypass, i, authorNode);
    }
    
    private void setRequiredAttributes(AuthorNode authorNode) {
        AuthorElement elementNote = (AuthorElement) authorNode;

        if(StringUtils.equals(authorNode.getName(), "model")){
            elementNote.setAttribute("model", new AttrValue("TBD"));

        } else if(StringUtils.equals(authorNode.getName(), "version")){
            elementNote.setAttribute("version", new AttrValue("TBD"));
        }
    }
It seems to insert node correctly with good values, but when it comes to insertFragment method, attributes values have been replaced.

How can I fix this ?

Regards,
Isabelle
Radu
Posts: 9059
Joined: Fri Jul 09, 2004 5:18 pm

Re: Content completion issue

Post by Radu »

Hi Isabelle,

Could you prepare for me a full valid sample project containing a valid XML Schema, valid XML sample document and cc_config.xml file with which I can reproduce the problem on my side? I could try to start an investigation into this. I think I have a hunch were the problem is.
About your planned workaround, indeed looking at our code the "insertNode" callback from the documentFilter is used to create ancestor elements when someone wants to insert an element which would be invalid at caret position. But after we insert the element in the document we make changes to it later in our code and add the attributes to it. So in your case maybe this callback "AuthorDocumentFilter.setAttribute(AuthorDocumentFilterBypass, String, AttrValue, AuthorElement)" would be more interesting to intercept.


Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
johnwood
Posts: 5
Joined: Sat Apr 29, 2023 8:05 am

Re: Content completion issue

Post by johnwood »

Based on the information provided, it seems like the issue is related to the behavior of the "insertFragment" method in the context of schema-aware content completion. When you insert a fragment using "insertFragment," it may override the attribute values that you have set manually before the insertion.

To address this issue, you can try the following approach:
  1. Override the "insertFragment" method:
    Instead of setting the attributes directly on the node before insertion, you can override the "insertFragment" method in your custom AuthorNodeInsertFragmentHandler. This way, you can intercept the insertion and modify the attributes of the inserted nodes before they are added to the document.
  2. Set the required attributes during "insertFragment":
    Inside your overridden "insertFragment" method, you can traverse the inserted fragment nodes, find the elements where you want to set the "model" and "version" attributes, and then update their attribute values accordingly.
Here's a modified version of your AuthorNodeInsertFragmentHandler that takes the above approach:

Code: Select all

public class CustomInsertFragmentHandler extends AuthorNodeInsertFragmentHandler {

    @Override
    protected void insertFragment(AuthorNode targetNode, AuthorDocumentFragment fragmentToInsert, boolean cloneIfNeeded, AuthorAccess authorAccess) throws AuthorOperationException {
        super.insertFragment(targetNode, fragmentToInsert, cloneIfNeeded, authorAccess);

        // Find the model and version elements and set their required attributes
        if (targetNode instanceof AuthorElement) {
            AuthorElement insertedElement = (AuthorElement) targetNode;
            
            if (insertedElement.getName().equals("model")) {
                // Set 'model' attribute to 'TBD' if it doesn't exist
                if (insertedElement.getAttribute("model") == null) {
                    insertedElement.setAttribute("model", new AttrValue("TBD"));
                }
            } else if (insertedElement.getName().equals("version")) {
                // Set 'version' attribute to 'TBD' if it doesn't exist
                if (insertedElement.getAttribute("version") == null) {
                    insertedElement.setAttribute("version", new AttrValue("TBD"));
                }
            }
        }
    }
}

Note: Make sure you register your custom AuthorNodeInsertFragmentHandler appropriately in your Oxygen XML plugin to ensure that it is used for content completion.AI directory

By using the above approach, you should be able to ensure that the "model" and "version" attributes are correctly set even when inserting elements through schema-aware content completion.
Radu
Posts: 9059
Joined: Fri Jul 09, 2004 5:18 pm

Re: Content completion issue

Post by Radu »

Hi John,
I do not think your advice applies in this particular case.
Oxygen has an insertion strategy which automatically creates ancestor elements when the end user attempts to insert an element which is invalid at the caret position.
And this insertion strategy uses the "insertNode" API to create the ancestor elements, but after calling the "insertNode" it also sets some attributes on the inserted elements and this generates the problem reported by Isabelle.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
Isabelle
Posts: 142
Joined: Fri Jan 20, 2017 1:11 pm

Re: Content completion issue

Post by Isabelle »

Hi Radu,

Sorry for the delay, how can I send you those files ?

Regards,
Isabelle
Radu
Posts: 9059
Joined: Fri Jul 09, 2004 5:18 pm

Re: Content completion issue

Post by Radu »

Hi isabelle,
We have a tech support form to which you can attach a zip file:
https://www.oxygenxml.com/techSupport.html
Or you can email us (support@oxygenxml.com).
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
Isabelle
Posts: 142
Joined: Fri Jan 20, 2017 1:11 pm

Re: Content completion issue

Post by Isabelle »

Radu,

I used the tech support form to send you a zip files with the 3 files requested.

In order to reproduce the issue, try to insert version or versrank element thanks to content completion, directly in applic element.

Regards,
Isabelle
Radu
Posts: 9059
Joined: Fri Jul 09, 2004 5:18 pm

Re: Content completion issue

Post by Radu »

Hi,
Based on the received samples I confirm that our next Oxygen version 26 release (October 2023) should have a fix for this reported problem.
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
Radu
Posts: 9059
Joined: Fri Jul 09, 2004 5:18 pm

Re: Content completion issue

Post by Radu »

Hi,
We released Oxygen 26 which should have a fix for this reported problem.
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
Isabelle
Posts: 142
Joined: Fri Jan 20, 2017 1:11 pm

Re: Content completion issue

Post by Isabelle »

Hello,

For information, this issue is fixed since our upgrade to oxygen 26.0.0.0.
Thanks.

Regards,
Isabelle
Radu
Posts: 9059
Joined: Fri Jul 09, 2004 5:18 pm

Re: Content completion issue

Post by Radu »

Great, thanks for confirming this Isabelle!

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
Post Reply