Trigger Author Action on save?
-
- Posts: 452
- Joined: Thu Jan 23, 2014 2:29 pm
- Location: Hamburg
- Contact:
Trigger Author Action on save?
Post by Frank Ralf »
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
parson AG
www.parson-europe.com
-
- Posts: 1008
- Joined: Wed Nov 16, 2005 11:11 am
Re: Trigger Author Action on save?
Post by alex_jitianu »
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
-
- Posts: 452
- Joined: Thu Jan 23, 2014 2:29 pm
- Location: Hamburg
- Contact:
Re: Trigger Author Action on save?
Post by Frank Ralf »
Many thanks for your quick reply and this pointer. I will give your plugin a try and report back.
Kind regards,
Frank
parson AG
www.parson-europe.com
-
- Posts: 452
- Joined: Thu Jan 23, 2014 2:29 pm
- Location: Hamburg
- Contact:
Re: Trigger Author Action on save?
Post by Frank Ralf »
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
parson AG
www.parson-europe.com
-
- Posts: 1008
- Joined: Wed Nov 16, 2005 11:11 am
Re: Trigger Author Action on save?
Post by alex_jitianu »
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
-
- Posts: 452
- Joined: Thu Jan 23, 2014 2:29 pm
- Location: Hamburg
- Contact:
Re: Trigger Author Action on save?
Post by Frank Ralf »
Thanks for these instructions. I will give the add-ons mechanism a try and report back.
Kind regards,
Frank
parson AG
www.parson-europe.com
-
- Posts: 17
- Joined: Sun Mar 01, 2015 8:26 am
Re: Trigger Author Action on save?
Post by lief.erickson »
I'm looking to do the same as you -- automatically add <revised> to my <critdates>. What does your actions.config file look like?
-Lief
-
- Posts: 452
- Joined: Thu Jan 23, 2014 2:29 pm
- Location: Hamburg
- Contact:
Re: Trigger Author Action on save?
Post by Frank Ralf »
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}
Automatic timestamp
Code: Select all
<critdates>
<created date="${date(yyyy-MM-dd)}"/>
<revised modified=""/>
</critdates>
- Editor Variables
- Author Mode Default Operations
hth
Frank
parson AG
www.parson-europe.com
-
- Posts: 1008
- Joined: Wed Nov 16, 2005 11:11 am
Re: Trigger Author Action on save?
Post by alex_jitianu »
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
-
- Posts: 17
- Joined: Sun Mar 01, 2015 8:26 am
Re: Trigger Author Action on save?
Post by lief.erickson »
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
-
- Posts: 1008
- Joined: Wed Nov 16, 2005 11:11 am
Re: Trigger Author Action on save?
Post by alex_jitianu »
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?
Post by Anonymous1 »
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?
-
- Posts: 1008
- Joined: Wed Nov 16, 2005 11:11 am
Re: Trigger Author Action on save?
Post by alex_jitianu »
Lief's requirement was that he didn't want multiple <revised> elements added for the same day:
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."If the last <revised> @modified contains today's date, do nothing; otherwise add a new revised element with today's date and continue."
Best regards,
Alex
-
- Posts: 17
- Joined: Sun Mar 01, 2015 8:26 am
Re: Trigger Author Action on save?
Post by lief.erickson »
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?
Post by Anonymous1 »
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?
Return to “DITA (Editing and Publishing DITA Content)”
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service