Need more info for oxy:allows-child-element

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

Need more info for oxy:allows-child-element

Post by Isabelle » Fri Jul 23, 2021 9:45 pm

Hi,

I need more information for oxy:allows-child-element.

In your documentation you said :
The oxy:allows-child-element() function allows you to check whether or not an element that matches the arguments of the function is valid as a child of the element at the current cursor position, according to the associated schema.
I was thinking that this function only check the condition on the current element, but it seems that it tests also on the children elements.

In this case :
oxy:allows-child-element("*", "rfuRefIds")

Code: Select all

<parent>
   <child rfuRefIds="id1"/>
   <child rfuRefIds="id1 id2"/>
   <child/>
</parent>
the oxy:allows-child-element should return true for child element only but it also return true for parent element.

Is it normal ?
How can I test only for current element and not his children element.

Thanks in advance,
Regards,
Isabelle

alex_jitianu
Posts: 850
Joined: Wed Nov 16, 2005 11:11 am

Re: Need more info for oxy:allows-child-element

Post by alex_jitianu » Mon Jul 26, 2021 10:57 am

Hello Isabelle,

Yes, it's correct. This function is intended as a helper for author actions. Imagine that the caret is places inside the <parent> element and you want to insert a <child> element, but you don't want to make the document invalid. This means that you must access the schema information and check if a <child> element is allowed inside the <parent> element. This is what this function does.

If you write it like this, oxy:allows-child-element("*", "rfuRefIds"), with the caret inside the <parent> element, it tests if the schema permits inserting inside the <parent> element an element with a @rfuRefIds attribute .

If you want to make tests on the current element, you can write a normal XPath, like this: *[@rfuRefIds].


Best regards,
Alex

Isabelle
Posts: 81
Joined: Fri Jan 20, 2017 1:11 pm

Re: Need more info for oxy:allows-child-element

Post by Isabelle » Tue Aug 17, 2021 9:52 pm

Hello Alex,

Thanks for the information, I better understand this helper know.
But it does not fit my need.

In fact, I need an helper which telling me if the attribute is available or not on the current element.
In the example bellow, I have to allow an action on every element which can have the rfuRefIds attribute even if the attribute is not fill yet.
Because the xsd said that the element child can have the attribute rfuRefIds, my action should be available for all the three element child.

Code: Select all

<parent>
   <child rfuRefIds="id1"/>
   <child rfuRefIds="id1 id2"/>
   <child/>
</parent>

If in my framework, in the xpathCondition of my action I put self::*[@reasonForUpdateRefIds], my action only appears when the attribute is already filled but not if the attribute does not exist, and it is not ok for me.
And if I put oxy:allows-child-element("*", "rfuRefIds"), then the action is available for the parent element despite that the xsd does not allow the rfuRefIds attribute on it.

Have you an helper for that case ?

Best Regards,
Isabelle

alex_jitianu
Posts: 850
Joined: Wed Nov 16, 2005 11:11 am

Re: Need more info for oxy:allows-child-element

Post by alex_jitianu » Wed Aug 18, 2021 1:34 pm

Hello Isabelle,

Unfortunately, we don't have such an extension function. I understand the flexibility such a method would bring, but can't you just use the element names in the XPath?

Code: Select all

self::*:child
Are there so many elements with @rfuRefIds attributes that creating an XPath based on their names is not feasible?
Where do you want to make this test, in the activation XPath or in one of the operation parameter? What operation do you use, what should happen when the user clicks the action. Perhaps I can offer a workaround.

Best regards,
Alex

Isabelle
Posts: 81
Joined: Fri Jan 20, 2017 1:11 pm

Re: Need more info for oxy:allows-child-element

Post by Isabelle » Wed Aug 18, 2021 7:03 pm

Hi Alex,

We use really complex xsd, and just for the S1000D norme, there are over 1500 elements which have this attribute.
So use an xpath like self::*:child is really not possible for us.

We need this test in the activation Xpath.
The operation is implemented by us but implements AuthorOperation.

For exemple when the caret is on an element, user makes a right click and then the action must be available in the contextual menu only if the attribute is allowed regarding the xsd.
When the user click the action a new dialog open.
When user finish actions in this dialog and close it, it updates the attribute value of the element according to user wishes.
If the value is empty, it removes the attribute and if the attribute does not exist yet, it creates it with the new value.

That is why we need to show this action only on available element, because added this attributes on other element causes xsd issues.

Hope you will find a workaround.

Best Regards,
Isabelle

alex_jitianu
Posts: 850
Joined: Wed Nov 16, 2005 11:11 am

Re: Need more info for oxy:allows-child-element

Post by alex_jitianu » Thu Aug 19, 2021 3:41 pm

Hi Isabelle,

On the XPath activation part, I don't think there is anything that you can do. We don't have an API for contributing additional actions. What you could do is to leave the author action active at all times and, when it gets invoked, the action itself checks to see if the attribute is allowed or not. The API to use is this:

Code: Select all

int caretOffset = authorAccess.getEditorAccess().getCaretOffset();
AuthorSchemaManager authorSchemaManager = authorAccess.getDocumentController().getAuthorSchemaManager();
WhatElementsCanGoHereContext wecghContext = authorSchemaManager.createWhatElementsCanGoHereContext(caretOffset);
    if (wecghContext != null) {
          whatElementsCanGoHere = authorSchemaManager.whatElementsCanGoHere(wecghContext);
              
              // Check if the default attribute.
          List<CIAttribute> attributesWithDefaultValues = authorSchemaManager.getElementDescription(wecghContext).getAttributesWithDefaultValues();
          // TODO Look iniside the list for the @rfuRefIds attribute
    }

This way the user will not accidentally set the attribute on a wrong element.
There might be a way to remove the action from the contextual menu by using the plugin API from an Oxygen Workspace Access plugin. Such a plugin can intercept the contextual menu and remove actions from it:

Code: Select all

  public void applicationStarted(final StandalonePluginWorkspace pluginWorkspaceAccess) {
    
    pluginWorkspaceAccess.addEditorChangeListener(new WSEditorChangeListener() {
      @Override
      public void editorOpened(URL editorLocation) {
        WSEditor editorAccess = pluginWorkspaceAccess.getEditorAccess(editorLocation, PluginWorkspace.MAIN_EDITING_AREA);

        if (editorAccess.getCurrentPageID() == EditorPageConstants.PAGE_AUTHOR) {
          WSAuthorEditorPage page = (WSAuthorEditorPage) editorAccess.getCurrentPage();
          page.addPopUpMenuCustomizer(new AuthorPopupMenuCustomizer() {

            @Override
            public void customizePopUpMenu(Object popUp, AuthorAccess authorAccess) {
              JPopupMenu menu = (JPopupMenu) popUp;

              // TODO Find the action and remove it from the menu if the current element doesn't have a @rfuRefIds default attribute.
            }
          });
        }
      }
    }, PluginWorkspace.MAIN_EDITING_AREA);
The code that checks for the default attribute is the same as in the first code snapshot. If you already have such a plugin, then it will be quite easy to add a block like this.

Best regards,
Alex

Isabelle
Posts: 81
Joined: Fri Jan 20, 2017 1:11 pm

Re: Need more info for oxy:allows-child-element

Post by Isabelle » Fri Aug 20, 2021 1:27 pm

Hello Alex,

Thanks for the workaround, it works fine for the right - click action (field "popupMenuDescriptor" in our framework).
We also have added this action in the contextual menu (field "contextualItems" in our framework).

How can I add a listener on contextualItems like for the popupMenuDescriptor ?
I don't find listener for that on pluginWorkspaceAccess.

Thanks.

Regards,
Isabelle

alex_jitianu
Posts: 850
Joined: Wed Nov 16, 2005 11:11 am

Re: Need more info for oxy:allows-child-element

Post by alex_jitianu » Fri Aug 20, 2021 5:33 pm

Hello Isabelle,

So you've added the action the the content completion proposals window as well. Unfortunately, we don't have such a API. How about if you don't put the action there anymore? Perhaps you can add it as a button form control. A CSS rule should have access to the default attributes so you could write a selector like this:

Code: Select all

*[rfuRefIds] {
    content: oxy_button(
         actionID, 'my.action.id',
         showIcon, true
)
}
Best regards,
Alex

Post Reply