Page 1 of 1

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

Posted: Wed Dec 21, 2022 5:17 pm
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.

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

Posted: Wed Dec 21, 2022 5:54 pm
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