custom paste special -> paste as xml action for dita topics

Post here questions and problems related to oXygen frameworks/document types.
changke
Posts: 15
Joined: Tue Aug 15, 2023 10:58 pm

custom paste special -> paste as xml action for dita topics

Post by changke »

We have a requirement to copy graphic reference from another application and paste it to a dita topic which is open in Oxygen XML Editor's Editor (Author mode). While the graphics is pasted, we would need to validate if the graphics exists in Oxygen already. If it does not exist, the graphics will then be downloaded to oxygen from the other application so that the graphic image could be visible in the editor.
the content on the clipboard is like
<image href="carwash.jpg" alt="washing the car"/>

How should we implement extensions to support the use case?

Thank you very much!
alex_jitianu
Posts: 1009
Joined: Wed Nov 16, 2005 11:11 am

Re: custom paste special -> paste as xml action for dita topics

Post by alex_jitianu »

Hi,

You can use our Java-based API, more precisely an AuthorDocumentFilter, to intercept the inserted fragment and make the checks. This API is available at the framework level. After you download our SDK, you need to focus on the project oxygen-sample-framework. In this project, follow SDFDocumentFilter. The callback you'll probably need is insertFragment()

Best regards,
Alex
changke
Posts: 15
Joined: Tue Aug 15, 2023 10:58 pm

Re: custom paste special -> paste as xml action for dita topics

Post by changke »

Alex,

Thanks.
The sample framework example shows how to add AuthorDocumentFilter in Framework level API. The AuthorDocumentFilter is added in SDFAuthorExtensionStateListener.activated(final AuthorAccess authorAccess), and SDFAuthorExtensionStateListener is registered in SDFExtensionsBundle. For our case, the paste action is on oxygen existing dita framework. How should we add our custom AuthorDocumentFilter to dita framework? We would want this customization to be applied to S1000D framework as well.

In AuthorDocumentFilter API documentation, it says that AuthorDocumentFilter could be added at Workspace Access plugin as well. Since we have already added a workspace access plugin, could we go this approach?

What are the pros/cons for two different approaches?

Thanks!

Kehua
alex_jitianu
Posts: 1009
Joined: Wed Nov 16, 2005 11:11 am

Re: custom paste special -> paste as xml action for dita topics

Post by alex_jitianu »

Hi,

Yes, the filter can be added both from framework and plugin level API. If you already have a plugin and you needed for two frameworks then it makes sense to use the plugin level API, like this:

Code: Select all

	/**
	 * @see WorkspaceAccessPluginExtension#applicationStarted(StandalonePluginWorkspace)
	 */
	@Override
	public void applicationStarted(final StandalonePluginWorkspace pluginWS) {
	  pluginWS.addEditorChangeListener(new WSEditorChangeListener() {
	    @Override
	    public void editorOpened(URL editorLocation) {
	      WSEditor editorAccess = pluginWS.getEditorAccess(editorLocation, PluginWorkspace.MAIN_EDITING_AREA);
	      if (EditorPageConstants.PAGE_AUTHOR.equals(editorAccess.getCurrentPageID()) ) {
	        WSAuthorEditorPage currentPage = (WSAuthorEditorPage) editorAccess.getCurrentPage();
	        
	        currentPage.getDocumentController().setDocumentFilter(filter);
	      } else {
	        // Add a listener
	        editorAccess.addEditorListener(new WSEditorListener() {
	          @Override
	          public void editorPageChanged() {
	            // TODO On first page switch to author mode add the filter.
	          }
	        });
	      }
	    }
	  }, PluginWorkspace.MAIN_EDITING_AREA);
Best regards,
Alex
changke
Posts: 15
Joined: Tue Aug 15, 2023 10:58 pm

Re: custom paste special -> paste as xml action for dita topics

Post by changke »

Alex,

Thank you very much for quick reply.
We also have a requirement to copy graphic reference from another application and paste it to a dita topic which is open in Oxygen XML Editor's Text Editor. the content on the clipboard is
<image href="carwash.jpg" alt="washing the car"/>
While the graphics is pasted, we would need to validate if the graphics exists in Oxygen already. If it does not exist, the graphics will then be downloaded to oxygen from the other application so that the graphic image could be visible in the editor.

Should we follow the similiar approach as for paste command in Author Mode editor? Should we use the same AuthorDocumentFilter and implement a different callback function?

Thank you very much!

Kehua
alex_jitianu
Posts: 1009
Joined: Wed Nov 16, 2005 11:11 am

Re: custom paste special -> paste as xml action for dita topics

Post by alex_jitianu »

Hi Kehua,

So this other application is putting a String flavor inside the Clipboard? If that's the case, the AuthorDocumentFilter approach will work with the mention that you would need to use Paste special -> Paste as XML from the contextual menu to trigger the paste operation. We treat a String flavor as plain text so "<image href="carwash.jpg" alt="washing the car"/>" text will be inserted as plain text if you use the normal Paste action.

If this other application puts an HTML flavor in the clipboard, then Oxygen will automatically convert it to DITA, parse the DITA Fragment, insert the DITA nodes, and the AuthorDocumentFilter.insertFragment() callback is invoked. You will then be able to make that validation.

Another API that you can use is ro.sync.ecss.extensions.api.content.ClipboardFragmentProcessor. Such an instance is set using ro.sync.ecss.extensions.api.AuthorDocumentController.addClipboardFragmentProcessor(ClipboardFragmentProcessor). Inside this processor you can get the fragment using ro.sync.ecss.extensions.api.content.ClipboardFragmentInformation.getFragment(). If the fragment contains just text, but it can be parsed as a DITA fragment (ro.sync.ecss.extensions.api.AuthorDocumentController.createNewDocumentFragmentInContext(String, int)) and it represents an image, you set the new fragment (ro.sync.ecss.extensions.api.content.ClipboardFragmentInformation.setFragment(AuthorDocumentFragment)) and make the check/copy of the image. This way the standard Paste will work as well.

Best regards,
Alex
changke
Posts: 15
Joined: Tue Aug 15, 2023 10:58 pm

Re: custom paste special -> paste as xml action for dita topics

Post by changke »

Alex,

Thank you very much!

Kehua
changke
Posts: 15
Joined: Tue Aug 15, 2023 10:58 pm

Re: custom paste special -> paste as xml action for dita topics

Post by changke »

Hi Alex,

When the other application copies graphics, the data on the clipboard is not in the format of dita graphic reference, for example the information on the clipboard is like graphicName=carwash.jpg. While it is pated to Dita topic, we want it to be pasted as dita graphic reference: <image href="carwash.jpg""/>, while it is pated to S1000D data module, it will be pasted as S1000D graphic reference like <graphic infoEntityIdent="carwash.jpg"/>.

How could we achieve it? is there any prepaste callback where we could change the content on clipboard to aligned with the target document type?

Thank you very much!

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

Re: custom paste special -> paste as xml action for dita topics

Post by Radu »

Hi Kehua,
Alex proposed 3 approaches to you. He also asked you a question. Did you try any of the proposed approaches?
In general we have API to know what type of document an opened editor has:
https://www.oxygenxml.com/InstData/Edit ... ormation()
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
changke
Posts: 15
Joined: Tue Aug 15, 2023 10:58 pm

Re: custom paste special -> paste as xml action for dita topics

Post by changke »

Radu,

Yes. I am trying Alex's proposed solution to handle the change in editor page. That assumes we have string data in xml format or html format on clipboard.
But I think my latest question is different from what I asked before. On clipboard the string data is not in dita xml or html graphic reference format. My new question is about how to convert or adapt the graphic data in clipboard to the data needed by Oxygen editor based on the target object (dita, s1000d or ATA) in the oxygen xml editor. While the graphic data is copied to clipboard in our own application, it does not have the destination context about the dita, s1000d or ATA etc).
By the way, what is the html format for dita graphic reference?

Thank you very much!

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

Re: custom paste special -> paste as xml action for dita topics

Post by Radu »

Hi Kehua,

Let's say that when you copy content in your application, you add to the clipboard besides the plain text flavor an HTML flavor containing the content:

Code: Select all

<html>
    <body>
        <p><a href="someImage.png" class="specialLink"></a></p>
    </body>
</html>
In each of the DITA and S1000D framework configurations which are installed in Oxygen you can have a distinct XSLT stylesheet which interprets this HTML flavor in specific ways:
https://www.oxygenxml.com/doc/versions/ ... mart-paste
So the XSLT in the DITA framework could create for example a DITA link from it and the XSLT in the S1000D framework could create an S1000D link from it.
By the way, what is the html format for dita graphic reference?
There is no such thing/standard, with the XSLT stylesheet which is customized in the DITA framework you decide for yourself how to convert the HTML flavor to DITA XML.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
changke
Posts: 15
Joined: Tue Aug 15, 2023 10:58 pm

Re: custom paste special -> paste as xml action for dita topics

Post by changke »

Hi Radu,

Thank you for your quick answer.
I will take a look of the smart paste feature.
alex_jitianu wrote: Thu Sep 07, 2023 3:02 pm If this other application puts an HTML flavor in the clipboard, then Oxygen will automatically convert it to DITA, parse the DITA Fragment, insert the DITA nodes, and the AuthorDocumentFilter.insertFragment() callback is invoked. You will then be able to make that validation.
What did Alex statement mean here? with dita graphic reference example here, what's the HTML flavor in the clipboard that Oxygen regular paste command will automatically convert it to DITA, parse the DITA Fragment, insert the DITA nodes etc?

Regards,

Kehua
changke
Posts: 15
Joined: Tue Aug 15, 2023 10:58 pm

Re: custom paste special -> paste as xml action for dita topics

Post by changke »

By the way, is smart paste new in Oxygen XML version 25?
Radu
Posts: 9059
Joined: Fri Jul 09, 2004 5:18 pm

Re: custom paste special -> paste as xml action for dita topics

Post by Radu »

Hi,

So:
What did Alex statement mean here? with dita graphic reference example here, what's the HTML flavor in the clipboard that Oxygen regular paste command will automatically convert it to DITA, parse the DITA Fragment, insert the DITA nodes etc?
The regular XSLTs used for pasting HTML flavors in DITA topics are in this folder:

Code: Select all

OXYGEN_INSTALL_DIR/frameworks/dita/resources/xhtml2ditaDriver.xsl
So this "xhtml2ditaDriver.xsl" stylesheet gets called to process the HTML content set in the clipboard and convert it to DITA XML content.
Hyperlinks processing is done for example in the "xhtml2dita.xsl" stylesheet, there is an XML comment there <!-- Hyperlinks -->.
If for example you create your own DITA framework extension folder (or already have one) you can copy the entire "OXYGEN_INSTALL_DIR/frameworks/dita/resources/" folder to your custom DITA framework folder, change the stylesheets there to fit more your use cases and then use them instead of ours.
By the way, is smart paste new in Oxygen XML version 25?
No, we have had this feature for a long time, more than 6-8 years.

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