10
10
import com .docusign .webforms .model .WebFormInstance ;
11
11
import com .docusign .webforms .model .WebFormSummaryList ;
12
12
import com .docusign .webforms .model .WebFormValues ;
13
- import org .apache .commons .lang3 .StringUtils ;
14
13
15
14
import java .io .IOException ;
16
15
import java .net .URISyntaxException ;
@@ -37,18 +36,17 @@ public static void addTemplateIdToForm(String fileName, String templateId) {
37
36
String targetString = "template-id" ;
38
37
39
38
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 ());
45
41
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 ));
49
43
String modifiedContent = fileContent .replace (targetString , templateId );
50
44
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 ());
52
50
} catch (IOException | URISyntaxException ex ) {
53
51
System .out .println ("An error occurred: " + ex .getMessage ());
54
52
}
0 commit comments