read-only attributes

Post here questions and problems related to oXygen frameworks/document types.
odovao
Posts: 12
Joined: Tue Oct 04, 2016 12:18 pm

read-only attributes

Post by odovao »

Hi

Is is possible to mark a element's attributes read-only in CSS, but still be able to modify the element itself?

Version: Web author 18.0.0

Thanks
cristi_talau
Posts: 517
Joined: Thu Sep 04, 2014 4:22 pm

Re: read-only attributes

Post by cristi_talau »

Hello,

In Web Author an attribute can be edited either inline using a form-control or by using the "Attributes" side-view.

If you want an attribute to be read-only, you can remove from CSS any form-control that edits that attribute. Regarding the "Attributes" view, we have Java API [1] that allows one to completely hide the attribute from the UI. To use this Java API, you should create a plugin [2].

Best,
Cristian

[1] https://www.oxygenxml.com/InstData/Edit ... playFilter
[2] https://www.oxygenxml.com/doc/versions/ ... ugins.html
odovao
Posts: 12
Joined: Tue Oct 04, 2016 12:18 pm

Re: read-only attributes

Post by odovao »

Hi,

I have implemented a CustomProtocolPlugin (this is working fine) and also an AuthorAttributesDisplayFilter, however how do I activate the filter?

Looking at other threads in the forum, it seems that I need to do this via WSAuthorEditorPageBase. Where/how do I get an instance of WSAuthorEditorPageBase so that I can add the filter to it?

Thanks,
Oscar
Gabriel Titerlea
Site Admin
Posts: 95
Joined: Thu Jun 09, 2016 2:01 pm

Re: read-only attributes

Post by Gabriel Titerlea »

Hello,

To add your filter you can implement a ro.sync.exml.plugin.workspace.WorkspaceAccessPluginExtension and override the applicationStarted method:

Code: Select all

  @Override
public void applicationStarted(StandalonePluginWorkspace pluginWorkspaceAccess) {
WebappPluginWorkspace workspaceAccess = (WebappPluginWorkspace) pluginWorkspaceAccess;

workspaceAccess.addEditingSessionLifecycleListener(new WebappEditingSessionLifecycleListener() {
@Override
public void editingSessionStarted(String sessionId, AuthorDocumentModel documentModel) {
documentModel.getAuthorAccess().getEditorAccess().addAuthorAttributesDisplayFilter(YOUR_FILTER_HERE);
}
});
}
To register the WorkspaceAccessPluginExtension you need to add it in the plugin.xml file of your plugin as follows:

Code: Select all

<extension type="WorkspaceAccess" class="com.example.YourWorkspaceAccessPluginExtension"/>
Best,
Gabriel
Stevee
Posts: 16
Joined: Wed Jan 12, 2022 6:17 pm

Re: read-only attributes

Post by Stevee »

Hi :)

I seem to have the same/ similar Use-Case.

I want to make some Attributes of XML-Tags to be not editable via the Attributes-Side View and the In-place Attributes Editor in Author Mode.

Instead of Web Author, i am using OxygenXMLAuthor Eclipse Plugin v24.0

Greetings,
Steffen
Radu
Posts: 9556
Joined: Fri Jul 09, 2004 5:18 pm

Re: read-only attributes

Post by Radu »

Hi Steffen,
Here are some possibilities:

1) Remove the attribute completely from being displayed in the Attributes view, using the API Gabriel mentioned above which works also in the Eclipse plugin:
https://www.oxygenxml.com/InstData/Edit ... layFilter-
2) Use the API to set a document filter:
ro.sync.ecss.extensions.api.AuthorDocumentController.setDocumentFilter(AuthorDocumentFilter)
and avoid changing the value for that specific attribute, but the end user might still get confused as the value will remain editable in the Attributes view but when it gets committed it will not be inserted in the document.
3) If you edit your DITA framework customization in the Oxygen Preferences->"Document Type Associations" page, in the "Extensions" tab there is an extension named "Author Custom Attribute Value Editor" which can be set by you to your own Java class:
https://www.oxygenxml.com/doc/versions/ ... ditor.html

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
Dinesh
Posts: 15
Joined: Mon Feb 24, 2025 12:19 pm

Re: read-only attributes

Post by Dinesh »

Radu wrote: Fri Mar 11, 2022 7:55 am
3) If you edit your DITA framework customization in the Oxygen Preferences->"Document Type Associations" page, in the "Extensions" tab there is an extension named "Author Custom Attribute Value Editor" which can be set by you to your own Java class:
https://www.oxygenxml.com/doc/versions/ ... ditor.html
Hi Radu,

I have a similar use case in Oxygen XML Author. We have our own framework for DocBook, and I created a CustomAttributeEditor. However, I would like to know if there is a way to enable Oxygen's default attribute editing feature for all attributes except for a specific read-only attribute.

For example,

Code: Select all

@Override
public String getAttributeValue(EditedAttribute attribute, Object parentComponent)
        throws CancelledByUserException {
    // Show an error message if the attribute is read-only
    if(attribute.getAttributeQName().equals("myattr")) {
        PluginWorkspaceProvider.getPluginWorkspace().showErrorMessage("Editing the 'myattr' attribute is not allowed.");
        throw new CancelledByUserException("Editing the 'myattr' attribute is not allowed.");
    }
    // Use Oxygen's default editor for other attributes, currently the example mentioned in the docs opens the JEditorPane, which results in loss of some features like combobox, etc, which we get for free in attribute view.
    return super.getAttributeValue(attribute, parentComponent);
}
However, this approach does not work because getAttributeValue is an abstract method. Is there a better way to achieve this, or perhaps a way to do it using CSS? My goal is to make only the specific attribute read-only.

Thanks,
Dinesh
Radu
Posts: 9556
Joined: Fri Jul 09, 2004 5:18 pm

Re: read-only attributes

Post by Radu »

Hi Dinesh,

So you have your own Java extensions bundle class which probably extends the base "ro.sync.ecss.extensions.docbook.DocBook5ExtensionsBundle" extension bundle or something similar, right?
Then you would overwrite this API which has a "shouldHandleAttribute" method:

Code: Select all

 /**
   * @see ro.sync.ecss.extensions.api.ExtensionsBundle#createCustomAttributeValueEditor(boolean)
   */
  @Override
  public CustomAttributeValueEditor createCustomAttributeValueEditor(boolean forEclipsePlugin) {
    return new CustomAttributeValueEditor() {
      @Override
      public String getDescription() {
        // TODO Auto-generated method stub
        return null;
      }
      @Override
      public boolean shouldHandleAttribute(EditedAttribute attribute) {
        // TODO Auto-generated method stub
        return false;
      }
      @Override
      public String getAttributeValue(EditedAttribute attribute, Object parentComponent)
          throws CancelledByUserException {
        // TODO Auto-generated method stub
        return null;
      }
    };
  }
As another possible approach we have an API "ro.sync.exml.workspace.api.editor.page.author.WSAuthorEditorPageBase.addAuthorAttributesDisplayFilter(AuthorAttributesDisplayFilter)" which would allow you to hide certain attributes from appearing at all in the Attributes view and other places.

https://www.oxygenxml.com/InstData/Edit ... ilter.html

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
Dinesh
Posts: 15
Joined: Mon Feb 24, 2025 12:19 pm

Re: read-only attributes

Post by Dinesh »

Radu wrote: Tue Nov 04, 2025 12:54 pm
So you have your own Java extensions bundle class which probably extends the base "ro.sync.ecss.extensions.docbook.DocBook5ExtensionsBundle" extension bundle or something similar, right?
Then you would overwrite this API which has a "shouldHandleAttribute" method:
Hi Radu,

Thank you for the prompt response. Yes, you are correct—we have our own class that extends DocBook5ExtensionsBundle. I can override the shouldHandleAttribute method and display an error dialog, returning false if the attribute is read-only. This approach fits my needs exactly.

Regarding the use of AuthorAttributesDisplayFilter, this would require us to create a plugin, correct? We are a little concerned about using plugins because, if we want to update the functionality in the future, I don't think it is possible to automatically update the plugin on the technical writers' Author installations. That’s why we are leaning toward using a framework, as we can deliver updates more swiftly and reliably compared to a plugin, but I could be wrong.

Thanks again for your quick response. I will reach out if I encounter any issues.

Best regards,
Dinesh
Dinesh
Posts: 15
Joined: Mon Feb 24, 2025 12:19 pm

Re: read-only attributes

Post by Dinesh »

Radu wrote: Tue Nov 04, 2025 12:54 pm So you have your own Java extensions bundle class which probably extends the base "ro.sync.ecss.extensions.docbook.DocBook5ExtensionsBundle" extension bundle or something similar, right?
Then you would overwrite this API which has a "shouldHandleAttribute" method:

Code: Select all

 /**
   * @see ro.sync.ecss.extensions.api.ExtensionsBundle#createCustomAttributeValueEditor(boolean)
   */
  @Override
  public CustomAttributeValueEditor createCustomAttributeValueEditor(boolean forEclipsePlugin) {
    return new CustomAttributeValueEditor() {
      @Override
      public String getDescription() {
        // TODO Auto-generated method stub
        return null;
      }
      @Override
      public boolean shouldHandleAttribute(EditedAttribute attribute) {
        // TODO Auto-generated method stub
        return false;
      }
      @Override
      public String getAttributeValue(EditedAttribute attribute, Object parentComponent)
          throws CancelledByUserException {
        // TODO Auto-generated method stub
        return null;
      }
    };
  }
Hi,

I just noticed that the getAttributeValue() method should return something, and I have to override this method since it’s abstract. I still need to get input from the user for all other editable attributes. If I return null, it won’t work, because as soon as I click on an attribute to edit in the Attributes view, it adds an empty string and stops.

Therefore, in this getAttributeValue() method, I want to get the string value using Oxygen’s input mechanism—such as input from the default text field in the Attributes view itself, etc. Is that possible?
Radu
Posts: 9556
Joined: Fri Jul 09, 2004 5:18 pm

Re: read-only attributes

Post by Radu »

Hello Dinesh,

So:
(1)
Regarding the use of AuthorAttributesDisplayFilter, this would require us to create a plugin, correct?
Not necessarily, in your DocBook5ExtensionsBundle you could do something like this:

Code: Select all

/**
   * @see ro.sync.ecss.extensions.docbook.DocBook5ExtensionsBundle#createAuthorExtensionStateListener()
   */
  @Override
  public AuthorExtensionStateListener createAuthorExtensionStateListener() {
    AuthorAttributesDisplayFilter filter = new AuthorAttributesDisplayFilter() {
      /**
       * @see ro.sync.ecss.extensions.api.attributes.AuthorAttributesDisplayFilter#shouldFilterAttribute(ro.sync.ecss.extensions.api.node.AuthorElement, java.lang.String, int)
       */
      @Override
      public boolean shouldFilterAttribute(AuthorElement parentElement, String attributeQName,
          int source) {
        return "id".equals(attributeQName);
      }
    };
    AuthorExtensionStateListener superListener = super.createAuthorExtensionStateListener();
    return new AuthorExtensionStateListener() {
      @Override
      public String getDescription() {
        return null;
      }
      
      @Override
      public void deactivated(AuthorAccess authorAccess) {
        superListener.deactivated(authorAccess);
        authorAccess.getEditorAccess().removeAuthorAttributesDisplayFilter(filter);
      }
      
      @Override
      public void activated(AuthorAccess authorAccess) {
        superListener.activated(authorAccess);
        authorAccess.getEditorAccess().addAuthorAttributesDisplayFilter(filter);
      }
    };
  }
(2)
I just noticed that the getAttributeValue() method should return something, and I have to override this method since it’s abstract. I still need to get input from the user for all other editable attributes. If I return null, it won’t work, because as soon as I click on an attribute to edit in the Attributes view, it adds an empty string and stops.

Therefore, in this getAttributeValue() method, I want to get the string value using Oxygen’s input mechanism—such as input from the default text field in the Attributes view itself, etc. Is that possible?
If you return false on the "shouldHandleAttribute" callback for all other attributes which should remain editable, then they should be handled as usual in the Attributes view.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
Dinesh
Posts: 15
Joined: Mon Feb 24, 2025 12:19 pm

Re: read-only attributes

Post by Dinesh »

Radu wrote: Tue Nov 04, 2025 3:58 pm If you return false on the "shouldHandleAttribute" callback for all other attributes which should remain editable, then they should be handled as usual in the Attributes view.
Hi Radu,

Thank you for the clear explanation. I was able to resolve this using the CustomAttributeValueEditor. After going through the documentation, I now understand what you meant.

For anyone in the future who wants to make an attribute read-only:
public boolean shouldHandleAttribute(EditedAttribute attribute,
CustomAttributeValueEditingContext editContext)
Ask the custom editor if it wants to handle editing for a certain attribute in a certain context.
By asking the custom editor if it wants to handle editing, you determine whether the getAttributeValue function you override will be called. If shouldHandleAttr function returns true, then your custom getAttributeValue will be invoked. Therefore, if you want an attribute to be read-only, you just need to throw an exception or display an error message in the getAttributeValue function.

For all other attributes that should remain editable, return false; this will tell Oxygen to use its own editor to get the input.

An example would look something like this:

Code: Select all

return new CustomAttributeValueEditor() {
            @Override
            public String getAttributeValue(EditedAttribute editedAttribute, Object o) throws CancelledByUserException {
                // This function is only called when the shouldHandleAttribute returns true.
                String attributeName = editedAttribute.getAttributeQName();
                String message;
                    message = "The '" + attributeName + "' attribute is read-only.";
                PluginWorkspaceProvider.getPluginWorkspace().showErrorMessage(message);
                throw new CancelledByUserException(message);
            }

            @Override
            public boolean shouldHandleAttribute(EditedAttribute editedAttribute) {
                return editedAttribute.getAttributeQName().equals("id");
            }
This would throw an error when someone tries to change the id attribute from the Author view. Thanks again Radu!
- Dinesh
Radu
Posts: 9556
Joined: Fri Jul 09, 2004 5:18 pm

Re: read-only attributes

Post by Radu »

Hi Dinesh,
And thanks for posting the solution details for others who might have the same need and stumble across this post!
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
Post Reply