1010import com .docusign .webforms .model .WebFormInstance ;
1111import com .docusign .webforms .model .WebFormSummaryList ;
1212import com .docusign .webforms .model .WebFormValues ;
13- import org .apache .commons .lang3 .StringUtils ;
1413
1514import java .io .IOException ;
1615import java .net .URISyntaxException ;
@@ -37,18 +36,17 @@ public static void addTemplateIdToForm(String fileName, String templateId) {
3736 String targetString = "template-id" ;
3837
3938 try {
40- ClassLoader rawPath = Thread .currentThread ().getContextClassLoader ();
41- String rootDir = Paths .get (Objects .requireNonNull (rawPath .getResource ("" )).toURI ()).toString ();
42- rootDir = StringUtils .remove (rootDir , "target\\ classes" );
43- rootDir = StringUtils .remove (rootDir , "file:/" );
44- rootDir = StringUtils .replace (rootDir , "\\ " , "/" );
39+ var templateFilePath = CreateAndEmbedFormService .class .getClassLoader ().getResource (fileName );
40+ var templateFile = Paths .get (Objects .requireNonNull (templateFilePath ).toURI ());
4541
46- String saveFilePath = rootDir + "src/main/resources/" + fileName ;
47-
48- String fileContent = new String (Files .readAllBytes (Paths .get (saveFilePath )));
42+ String fileContent = new String (Files .readAllBytes (templateFile ));
4943 String modifiedContent = fileContent .replace (targetString , templateId );
5044
51- Files .write (Paths .get (saveFilePath ), modifiedContent .getBytes ());
45+ var basePath = System .getProperty ("user.dir" );
46+ var configFile = Paths .get (basePath , "demo_documents" , fileName );
47+
48+ Files .createDirectories (Paths .get (basePath , "demo_documents" ));
49+ Files .write (configFile , modifiedContent .getBytes ());
5250 } catch (IOException | URISyntaxException ex ) {
5351 System .out .println ("An error occurred: " + ex .getMessage ());
5452 }
0 commit comments