Auto-generate ${uuid} with same value in 2 places

Post here questions and problems related to oXygen frameworks/document types.
vishwavaranasi
Posts: 144
Joined: Fri Feb 28, 2020 4:02 pm

Auto-generate ${uuid} with same value in 2 places

Post by vishwavaranasi »

Hello Team ,

We have our custom doc templates where set a custom id to new topics , I do that using addCustomEditorVariablesResolver function based on this
code :https://github.com/digicademy/CustomUUI ... nsion.java.

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE topic PUBLIC "-//COMPANY//DTD myCustom DITA Topic//EN" "myCustomTopic.dtd">
<topic id="${customUUID}" format="dita" type="topic">
    <title></title>
    <body></body>
</topic>
this works fine where every time when we creat new topic the new UUID generated and assigned as id.

here we have another requirement , we wanted the same UUID to placed for title
and the title is something should always starts with TITLE_${customUUID}

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE topic PUBLIC "-//COMPANY//DTD myCustom DITA Topic//EN" "myCustomTopic.dtd">
<topic id="${customUUID}" format="dita" type="topic">
    <title id="TITLE_${customUUID}"></title>
    <body></body>
</topic>
so here topic id is F503DC44-9A8F-4043-92D1-6B95CD92D003

then title id we need TITLE_F503DC44-9A8F-4043-92D1-6B95CD92D003 (same UUID)

would you please help us here.
Thanks,
vishwa
Radu
Posts: 9059
Joined: Fri Jul 09, 2004 5:18 pm

Re: Auto-generate ${uuid} with same value in 2 places

Post by Radu »

Hi,

You control how the UUID is generated in the Java code, there is nothing stopping you to do this for example:

Code: Select all

	public String resolveEditorVariables(String contentWithEditorVariables, String currentEditedFileURL){		
	      //Generate the uuid value only once, and then use it in all places in the content string.
		String value =  createCustomUUID().toString();
		return contentWithEditorVariables.replaceAll("\\$\\{stableCustomUUID\\}", value);
	  }
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
Post Reply