Page 1 of 1

Trigger Author Action on save?

Posted: Mon Sep 21, 2015 12:17 pm
by Frank Ralf
Hi,

I've created an DITA Author Action which adds an ID to a topic based on the topic's file name. Currently, I trigger this action with a button but it would be more elegant to trigger this action automatically with every file save.

I've already read Set prolog revised date on save? and it looks as if this would require some Java programming?

Kind regards,
Frank

Re: Trigger Author Action on save?

Posted: Mon Sep 21, 2015 3:40 pm
by alex_jitianu
Hello Frank,

Yes, right now it will require Java programming. But this requirement is one that I've encountered before quite often. So I've create a plugin that reads some author action IDs from a configuration file and executes them before save. You can give it a try:
- download ExecuteAuthorActionsOnSaveHook
- unzip it inside {OxygenInstallDir}/plugins . Please make sure not to create any additional folders.
- edit {OxygenInstallDir}/plugins/saveHook-0.0.1-SNAPSHOT/etc/actions.config . This file must contain author action IDs, each ID on a new line
- start Oxygen and verify that your action(s) is being invoked on save

Best regards,
Alex

Re: Trigger Author Action on save?

Posted: Mon Sep 21, 2015 3:51 pm
by Frank Ralf
Hi Alex,

Many thanks for your quick reply and this pointer. I will give your plugin a try and report back.

Kind regards,
Frank

Re: Trigger Author Action on save?

Posted: Mon Sep 21, 2015 4:37 pm
by Frank Ralf
Hi Alex,

Your plugin works like a charm! Many thanks.

Is there a way to deploy the plugin together with our custom DITA framework so the user doesn't have to have write access to [OXYGEN_DIR]\plugins?

Best regards,
Frank

Re: Trigger Author Action on save?

Posted: Tue Sep 22, 2015 9:58 am
by alex_jitianu
Hi Frank,

I'm glad to hear that! I don't know how you deploy the framework to the users but for the plugin you could use the add-ons mechanism. I've uploaded an add-on packaeg on GIT so here is what you must do:
1. from the git project ExecuteAuthorActionsOnSaveHook download the content of directory builds/addon. There are two resources here:
1.1 saveHook.xml is the add-on descriptor file
1.2 saveHook-0.0.1-SNAPSHOT-plugin.zip is the plugin archive. Before proceeding any further, you should edit the file actions.config from it and give the correct actions IDs.
2. You have to put these two resources on an HTTP server that is accessible to your users
3. Each user will install the plugin through the add-ons support in Oxygen. basically they will go into the Help menu, select Install new add-ons... and paste the saveHook.xml URL (the one from the HTTP server) into the dialog.

Best regards,
Alex

Re: Trigger Author Action on save?

Posted: Wed Sep 23, 2015 10:25 am
by Frank Ralf
Hi Alex,

Thanks for these instructions. I will give the add-ons mechanism a try and report back.

Kind regards,
Frank

Re: Trigger Author Action on save?

Posted: Sun Apr 03, 2016 6:55 pm
by lief.erickson
Hi Frank--

I'm looking to do the same as you -- automatically add <revised> to my <critdates>. What does your actions.config file look like?

-Lief

Re: Trigger Author Action on save?

Posted: Mon Apr 04, 2016 1:26 pm
by Frank Ralf
Hi Lief,

Thanks for your interest. Here's the Author Action in short:

File name as topic ID
  • - XPath condition: ancestor-or-self::*[contains(@class, "topic/topic ")]
    - Operation: ro.sync.ecss.extensions.commons.operations.ChangeAttributeOperation
    - elementLocation: ancestor-or-self::*[contains(@class, "topic/topic ")]
    - name: id
    - value: ${cfn}
For setting a date you could combine this with a date related editor variable like in the following example taken from one of our DITA templates.

Automatic timestamp

Code: Select all


<critdates>
<created date="${date(yyyy-MM-dd)}"/>
<revised modified=""/>
</critdates>
For further instructions see:
- Editor Variables
- Author Mode Default Operations

hth
Frank

Re: Trigger Author Action on save?

Posted: Tue Apr 05, 2016 9:34 am
by alex_jitianu
Hi Lief,

If I understand it correctly, you want to automatically insert <revised> automatically when the user saves a document, right? First of all you should create your author operation (just like Frank advised). Perhaps its configuration can look like this:

- id: add.revised
- XPath condition: /*/prolog/critdates[not(revised)]
- Operation: ro.sync.ecss.extensions.commons.operations.InsertFragmentOperation
- insertLocation: /*/prolog/critdates[not(revised)]
- fragment: <revised modified="${date(yyyy-MM-dd)}"/>

After installing the ExecuteAuthorActionsOnSaveHook, edit actions.config and write in it the ID of the action: add.revised

PS: If your configuration is supposed to work on DITA specializations then it's a good idea to rewrite the XPath expressions from above to rely on the @class attribute.

Best regards,
Alex

Re: Trigger Author Action on save?

Posted: Tue Apr 05, 2016 2:55 pm
by lief.erickson
Thank you very much, Frank & Alex.

This is what I'm using:

- id: add.revised
- XPath condition: //*[contains(@class," topic/critdates ")]
- Operation: ro.sync.ecss.extensions.commons.operations.InsertFragmentOperation
- insertLocation: (//*[contains(@class," topic/critdates ")])[1]
- insertPosition: As last child
- fragment: <revised modified="${date(yyyy-MM-dd)}"/>

This working, but it's working a bit too well; it's adding a new <revised> element every time the file is saved. My XPath isn't good enough to be able to do this: "If the last <revised> @modified contains today's date, do nothing; otherwise add a new revised element with today's date and continue." How can I do that in XPath?

I can easily find the element (//revised[last()]/@modified), but the date comparison part I don't get. Any thoughts?

-Lief

Re: Trigger Author Action on save?

Posted: Tue Apr 05, 2016 5:27 pm
by alex_jitianu
Hi Lief,

I think you could compare dates likes this: //critdates[not(revised) or xs:date(revised[last()]/@modified ) != current-date()]

Best regards,
Alex

Re: Trigger Author Action on save?

Posted: Mon Apr 11, 2016 12:31 pm
by Anonymous1
Thank you for your suggestion Alex. I just tried it but it didn't work.

Still a new revised element is added if the old revised element has a date older than today's date.

Were you able to make it work, Lief?

Re: Trigger Author Action on save?

Posted: Mon Apr 11, 2016 2:17 pm
by alex_jitianu
Hi,

Lief's requirement was that he didn't want multiple <revised> elements added for the same day:
"If the last <revised> @modified contains today's date, do nothing; otherwise add a new revised element with today's date and continue."
As such, the activation XPath I suggested, activated the action only when the last revised date was different than today's date. You can juggle with the activation XPath to achieve different use cases.

Best regards,
Alex

Re: Trigger Author Action on save?

Posted: Mon Apr 11, 2016 3:15 pm
by lief.erickson
Hi--

Yes, it's working. I meant to update this case with my actions.config and Author Action info. The XPath that Alex provided gave me exactly the solution I was looking for. I am not overwriting the existing <revised> but adding a new one.

Alex, thank you! I provided this change to my coworker, and we both love how this simple change makes one tiny, tedious task completely disappear!

-Lief

Re: Trigger Author Action on save?

Posted: Mon Apr 11, 2016 3:17 pm
by Anonymous1
You are right, obviously. I guess I read what I wanted to read. My intention was to only have one revised element that is always updated on save when changes were made. I'll try to adapt the XPath expression to my use case. Thanks :)

Edit:

Here is what I did for my use case "Update the revised date to today's date".

ID: update.revised
Operation: ChangeAttributeOperation
elementLocation: //revised
name: modified
value: ${date(yyyy-MM-dd)}

Plus adding the author action ID "update.revised" to the ExecuteAuthorActionsOnSaveHook actions.config file, as Alex explained in the second post.

Re: Trigger Author Action on save?

Posted: Tue Apr 12, 2016 9:54 am
by xephon
:idea: Since DITA 1.3 you can also use the Release Management Domain to document changes.