Genereate unique ID

Having trouble installing Oxygen? Got a bug to report? Post it all here.
PetrO
Posts: 3
Joined: Wed Feb 16, 2022 12:30 pm

Genereate unique ID

Post by PetrO »

Hi all,
I have a problem with generate new unique ID. I need to change the pattern for generating new ids (behavior of magic wound). What I understand from some posts here is that the pattern can be change in my_framework/resources/idGenerationDefaultOptions.xml What I did.
image.png
image.png (23.66 KiB) Viewed 797 times
But I click on the element I still cannot generate id by the patter.
image.png
image.png (9.44 KiB) Viewed 797 times
I don't know what I do wrong? Can you help me with thist, please? I'm not java developer but I'm ok with javascript.
If there is no way out and only jar file has to be rewrite I would like to create a button to generate new id in js but then I will need to remove magic wound button, is it possible? I use the plugin for removing menu components so it won't be problem but I cannot figure it out what is the name of wound :(
Thank you very much,
Petr
Radu
Posts: 9059
Joined: Fri Jul 09, 2004 5:18 pm

Re: Genereate unique ID

Post by Radu »

Hi,

Can you give me more details about the final result you want to achieve? It would help me give you better advice.

So the default settings file for DocBook 5 ID generation is located in "OXYGEN_INSTALL_DIR/frameworks/docbook/resources/idGenerationDefaultOptionsDB5.xml" and from what I checked if I make changes to it they are taken into account when generating an ID with a DocBook file opened.
But it's a default configurations file, if the end user opens a DocBook file and then goes to the main menu DocBook->"ID Options..." and changes settings from there, the default configuration settings file will not be taken into account.

Some general ideas for Javascript devs:
1) Using only Javascript you can implement an Oxygen Javascript-based plugin:
https://www.oxygenxml.com/doc/versions/ ... in-js.html
There are a bunch of sample plugins here:
https://github.com/oxygenxml/wsaccess-j ... le-plugins
for example a sample plugin which adds a new contextual menu action to the Author visual editing mode:
https://github.com/oxygenxml/wsaccess-j ... AuthorPage
The Javascript plugin is activated when Oxygen starts and receives a "pluginWorkspaceAccess" reference which has access to call this Java API directly from Javascript:
https://www.oxygenxml.com/InstData/Edit ... space.html

With a Javascript based plugin you can also add a custom editor variables resolver, for example to take control over how the ${id} editor variable gets expanded:
https://github.com/oxygenxml/wsaccess-j ... rVariables

2) You can add a new custom Author action to the DocBook 5 framework configuration and then add it to the contextual menu, main menu, toolbar.
The Author action can invoke an operation which uses Javascript to call our Java based APIs:
https://www.oxygenxml.com/doc/versions/ ... tions.html
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
PetrO
Posts: 3
Joined: Wed Feb 16, 2022 12:30 pm

Re: Genereate unique ID

Post by PetrO »

Ok thanks for replay.
Well what I want to achieve is than if user creates new section(article, book, etc...) and double click on that he/she can generate new id by clicking on "Generate unique ID value" and here I wanna change the pattern. Not like this : article_el5_nd3_psb but something like this: Article_20220216153454 (^[A-Za-z]+_[N]*?[0-9]+$).
I thought if I change the pattern in "idGenerationDefaultOptions.xml" in my framework that would do that trick.
Exactly how you write I can create new button in Contextual Menu with JS function, but then I want to remove the "Generate unique ID value" button (magic wand), because if user clicks on that button it rewrites correct id.
image.png
image.png (10.08 KiB) Viewed 784 times
I hope now it is more clear :)
Radu
Posts: 9059
Joined: Fri Jul 09, 2004 5:18 pm

Re: Genereate unique ID

Post by Radu »

Hi,
Please see some more comments below:
Well what I want to achieve is than if user creates new section(article, book, etc...) and double click on that he/she can generate new id by clicking on "Generate unique ID value" and here I wanna change the pattern.
Once you enable default auto generation ( <autoGenerate>true</autoGenerate>) for ID attributes in the "idGenerationDefaultOptions.xml" file IDs will be automatically generated when the sections are inserted and the end user will no longer need to use the magic wand in the edit attributes dialog.
Not like this : article_el5_nd3_psb but something like this: Article_20220216153454 (^[A-Za-z]+_[N]*?[0-9]+$).
We have an Oxygen editor variable named "${date}" which when expanded can generate some timestamp-like format:
https://www.oxygenxml.com/doc/versions/ ... ables.html
Maybe you can use ${date} with a custom pattern in the "idGenerationDefaultOptions.xml" file for the <idPattern> value.
I thought if I change the pattern in "idGenerationDefaultOptions.xml" in my framework that would do that trick.
It should work, what Docbook version are you using? If you are using DocBook 4, the default ID generation file is located in:"OXYGEN_INSTALL_DIR/frameworks/docbook/resources/idGenerationDefaultOptions.xml" and for DocBook 5 it is located in "OXYGEN_INSTALL_DIR/frameworks/docbook/resources/idGenerationDefaultOptionsDB5.xml".
Also ideally you should extend the DocBook framework and make changes in your extension instead of modifying XML configuration files directly inside the Oxygen installation folder:
https://www.oxygenxml.com/doc/versions/ ... on_options
If you make changes to the ID generation default options XML file and they are not reflected when starting Oxygen you should try to use the main menu "Options->Reset Global options" action to reset your settings.
Exactly how you write I can create new button in Contextual Menu with JS function, but then I want to remove the "Generate unique ID value" button (magic wand), because if user clicks on that button it rewrites correct id.
By default the magic wand should generate the ID value exactly with the pattern defined in the "idGenerationDefaultOptions.xml" file. If you want a more flexible value, for example to take full control over the generated value you will need a Java customization, you cannot do this with Javascript.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
PetrO
Posts: 3
Joined: Wed Feb 16, 2022 12:30 pm

Re: Genereate unique ID

Post by PetrO »

Thanks Radu,
I found out that one of the problem was that I didn't use Docbook4 or 5. So I started use that and I removed almost all from that framework and I kept only id.options
image.png
image.png (73.48 KiB) Viewed 742 times
But What I don't understand is that when I create new article for example it creates id but not xml:id (don't know what format of id is that)
image.png
image.png (9.72 KiB) Viewed 742 times
Strange thing is that if I click on magic wand the format is totally different (article_bvw_vmn_psb)
I checked the

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<!-- C:\Program Files\Oxygen XML Author 23\frameworks\docbook\resources\idGenerationDefaultOptionsDB5.xml -->
<!-- ID Generation default options for Docbok 5 -->
<idGeneration>
    <autoGenerate>true</autoGenerate>
    <idAttribute>xml:id</idAttribute>
    <idPattern>${localName}_${id}_${date}</idPattern>
    <generateForElement>article</generateForElement>
    <generateForElement>chapter</generateForElement>
    <generateForElement>sect1</generateForElement>
    <generateForElement>sect2</generateForElement>
    <generateForElement>sect3</generateForElement>
    <generateForElement>sect4</generateForElement>
    <generateForElement>sect5</generateForElement>
    <generateForElement>section</generateForElement>
</idGeneration>

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<!-- C:\Program Files\Oxygen XML Author 23\frameworks\docbook\resources\idGenerationDefaultOptions.xml -->
<!-- ID Generation default options for Docbok 4 -->
<idGeneration>
    <autoGenerate>true</autoGenerate>
    <idAttribute>id</idAttribute>
    <idPattern>${localName}_${date}</idPattern>
    <generateForElement>article</generateForElement>
    <generateForElement>chapter</generateForElement>
    <generateForElement>sect1</generateForElement>
    <generateForElement>sect2</generateForElement>
    <generateForElement>sect3</generateForElement>
    <generateForElement>sect4</generateForElement>
    <generateForElement>sect5</generateForElement>
    <generateForElement>section</generateForElement>
</idGeneration>
The exactly the same content of idGenerationDefaultOptions.xml and idGenerationDefaultOptions5.xml I have it in frameworks/resource folder
I really don't know where is the problem...
Attachments
image.png
image.png (7.95 KiB) Viewed 742 times
Radu
Posts: 9059
Joined: Fri Jul 09, 2004 5:18 pm

Re: Genereate unique ID

Post by Radu »

Hi,

I thought you were editing a DocBook 5 document because it had XML elements similar to the DocBook elements and also an xml:id attribute.
I'm afraid it's not clear for me what exactly you did on your side and what the current situation is.
Maybe you can email us (support@oxygenxml.com) give me a small sample document (without any confidential data) and detailed steps to customize the DocBook framework with exactly what you did on your side.

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