Override/Replace <Image> tag with <Object> tag

Having trouble accessing the Oxygen Content Fusion platform or installing the server solution? Got a bug to report? Post it all here.
rohan_12
Posts: 5
Joined: Wed May 08, 2024 7:19 am

Override/Replace <Image> tag with <Object> tag

Post by rohan_12 »

Hi,

Is there a feasibility that when we click on "Insert Image" from toolbar and select the image, it gets inserted inside <Object> tag instead of <Image> .

I know the usual tag is <Image>, but for application we use <Object> tag in Author and use "datakeyref" instead of "href". Our application requirement is looking for same in Oxygen Content Fusion.

I have gone through online resources and documentation, but couldn't find any Class/Implementation/Framework/Plugin which can replace and/or override one element tag with another.

Any guidance on this will be highly appreciated.
mihaela
Posts: 494
Joined: Wed May 20, 2009 2:40 pm

Re: Override/Replace <Image> tag with <Object> tag

Post by mihaela »

Hello,

You can override the built-in action that inserts images with a custom action defined in a JavaScript plugin.

See here how to implement a custom action: https://www.oxygenxml.com/maven/com/oxy ... ction.html
From the custom action you can even show a dialog: https://www.oxygenxml.com/maven/com/oxy ... ialog.html

You can retrieve data from the server by invoking a custom AuthorOperationWithResult that returns something to the client.
If you need information about the keys you can use the ro.sync.servlet.operation.reusablekeys.RetrieveReusableComponents.doOperation(AuthorDocumentModel, ArgumentsMap).keyManager Java API like this:
editorAccess.getEditingContext().getContextKeyManager().getKeys(editorAccess.getEditorLocation());

Best Regards,
Mihaela
Mihaela Calotescu
http://www.oxygenxml.com
rohan_12
Posts: 5
Joined: Wed May 08, 2024 7:19 am

Re: Override/Replace <Image> tag with <Object> tag

Post by rohan_12 »

Hi,
I have created my custom icon in toolbar, along with the icons and class invoke based on operation, but I am facing some issues.

I am unable to override the DITA jar provided classes.

Here's my code:
package ro.sync.ecss.extensions.dita.topic;

import ro.sync.annotations.api.API;
import ro.sync.annotations.api.APIType;
import ro.sync.annotations.api.SourceType;
import ro.sync.ecss.dita.DITAAccess;
import ro.sync.ecss.dita.ImageInfo;
import ro.sync.ecss.extensions.api.ArgumentDescriptor;
import ro.sync.ecss.extensions.api.ArgumentsMap;
import ro.sync.ecss.extensions.api.AuthorAccess;
import ro.sync.ecss.extensions.api.AuthorOperation;
import ro.sync.ecss.extensions.api.AuthorOperationException;
import ro.sync.ecss.extensions.api.WebappCompatible;
import ro.sync.ecss.extensions.api.webapp.WebappRestSafe;
import ro.sync.ecss.extensions.commons.ImageFileChooser;

public class InsertObjectOperation extends InsertImageOperation {

@Override
public void doOperation(AuthorAccess authorAccess, ArgumentsMap args) throws IllegalArgumentException, AuthorOperationException {
Object imageUrl = args.getArgumentValue("imageUrl");
ImageInfo ref = null;
if (imageUrl instanceof String) {
ref = new ImageInfo("datakeyref", ImageFileChooser.makeUrlRelative(authorAccess, (String)imageUrl));
} else {
ref = DITAAccess.chooseImageReference(authorAccess);
}

if (ref != null) {
DITAAccess.insertImage(authorAccess, ref);
}

}
}
I have two issues:
  • I am unable to figure out the scope of the "InsertImageOperation" class or any other similar for me to extend and override them.
  • I cannot find any other class, but this "InsertImageOperation" does not perfectly fit my requirement as I want the Image inside <Object> tag with "datakeyref" attribute, not href.
Can you guide me on this?
mihaela
Posts: 494
Joined: Wed May 20, 2009 2:40 pm

Re: Override/Replace <Image> tag with <Object> tag

Post by mihaela »

Hello,

There is no need to extend the InsertImageOperation, or any other existing DITA operation.

So, from what I understand you first have to display a dialog to the user that presents all the image keys and then invoke an operation that inserts the fragment (object with datakeyref) into the document.

For the operation, there is no need to extend the InsertImageOperation (or any other existing DITA operation).
There is already an ro.sync.ecss.extensions.commons.operations.InsertFragmentOperation that you can use to insert a fragment into the document or you can create your own operation class (if you want to do more than insert the fragment), that extends AuthorOperationWithResult. Do not forget to mark the custom operation as compatible with Oxygen XML Web Author.

Please let us know if you need more information.

Best Regards,
Mihaela
Mihaela Calotescu
http://www.oxygenxml.com
rohan_12
Posts: 5
Joined: Wed May 08, 2024 7:19 am

Re: Override/Replace <Image> tag with <Object> tag

Post by rohan_12 »

Hi,

In my framework I have used "InsertFragmentOperation" class for my Operation and in the "Activation XPath" I have put "oxy:allows-child-element("*", "class", " topic/object ")".

However, still when I do insert image action, it gets created inside <Image> tag with "href" attribute .

Is there any specific API which I can use for my custom operation to insert Image in <Object> tag with the image value in datakeyref.
cristi_talau
Posts: 501
Joined: Thu Sep 04, 2014 4:22 pm

Re: Override/Replace <Image> tag with <Object> tag

Post by cristi_talau »

Hello,

In Web Author, in the default DITA framework, the "insert.image" action that you configure using the Document Type Configuration dialog box is overwritten by a JS implementation.
So, in your DITA framework extension, you need to implement a custom action in JS and register it in the ActionsManager with the "insert.image" ID to overwrite the one included in the base DITA framework.

Best,
Cristian
Post Reply