11package com .atsebak .ui5 .autogeneration ;
22
3- import com .atsebak .ui5 .config . UI5Library ;
3+ import com .atsebak .ui5 .AppType ;
44import org .jetbrains .annotations .NotNull ;
55
66import java .util .HashMap ;
@@ -14,110 +14,93 @@ public final class CodeGenerator {
1414 * @return
1515 */
1616 public String createControllerCode (@ NotNull final String root ) {
17- return Template .builder ().name ("templates/controller.js.ftl" ).classContext (this .getClass ())
18- .data (new HashMap <String , Object >() {{
19- put ("root" , root );
20- }})
21- .build ()
22- .toString ();
17+ return createTemplate ("templates/controller.js.ftl" , new HashMap <String , Object >() {{
18+ put ("root" , root );
19+ }});
2320 }
2421
2522 /**
2623 * Index.html code
2724 *
28- * @param ui5Library
25+ * @param appType
2926 * @param rootModuleName
3027 * @param intialViewExt
3128 * @return
3229 */
33- public String createIndexCode (@ NotNull UI5Library ui5Library , @ NotNull final String rootModuleName , @ NotNull final String intialViewExt ) {
34- String templateLocation = "" ;
35- switch (ui5Library ) {
36- case DESKTOP :
37- templateLocation = "templates/desktop/index.html.ftl" ;
38- break ;
39- case MOBILE :
40- templateLocation = "templates/mobile/index.html.ftl" ;
41- break ;
42- }
43-
44- return Template .builder ().name (templateLocation ).classContext (this .getClass ())
45- .data (new HashMap <String , Object >() {{
46- put ("rootModuleName" , rootModuleName );
47- put ("intialViewExt" , intialViewExt .toUpperCase ());
48- }})
49- .build ()
50- .toString ();
30+ public String createIndexCode (@ NotNull AppType appType , @ NotNull final String rootModuleName , @ NotNull final String intialViewExt ) {
31+ return createTemplate ("templates/" + appType .name ().toLowerCase () + "/index.html.ftl" , new HashMap <String , Object >() {{
32+ put ("rootModuleName" , rootModuleName );
33+ put ("intialViewExt" , intialViewExt .toUpperCase ());
34+ }});
5135 }
5236
5337 /**
5438 * HTML Code
5539 *
56- * @param ui5Library
40+ * @param appType
5741 * @param controllerPath
5842 * @return
5943 */
60- public String createHtmlViewCode (@ NotNull UI5Library ui5Library , @ NotNull String controllerPath ) {
61- return getGeneratedCodeForView (ui5Library , controllerPath , "html" );
44+ public String createHtmlViewCode (@ NotNull AppType appType , @ NotNull String controllerPath ) {
45+ return getGeneratedCodeForView (appType , controllerPath , "html" );
6246 }
6347
6448 /**
6549 * JS Code
6650 *
67- * @param ui5Library
51+ * @param appType
6852 * @param controllerPath
6953 * @return
7054 */
71- public String createJavascriptViewCode (@ NotNull UI5Library ui5Library , @ NotNull String controllerPath ){
72- return getGeneratedCodeForView (ui5Library , controllerPath , "js" );
55+ public String createJavascriptViewCode (@ NotNull AppType appType , @ NotNull String controllerPath ){
56+ return getGeneratedCodeForView (appType , controllerPath , "js" );
7357 }
7458
7559 /**
7660 * XML Code
7761 *
78- * @param ui5Library
62+ * @param appType
7963 * @param controllerPath
8064 * @return
8165 */
82- public String createXmlViewCode (@ NotNull UI5Library ui5Library , @ NotNull String controllerPath ) {
83- return getGeneratedCodeForView (ui5Library , controllerPath , "xml" );
66+ public String createXmlViewCode (@ NotNull AppType appType , @ NotNull String controllerPath ) {
67+ return getGeneratedCodeForView (appType , controllerPath , "xml" );
8468 }
8569
8670 /**
8771 * JSON Code
8872 *
89- * @param ui5Library
73+ * @param appType
9074 * @param controllerPath
9175 * @return
9276 */
93- public String createJsonViewCode (@ NotNull UI5Library ui5Library ,@ NotNull String controllerPath ) {
94- return getGeneratedCodeForView (ui5Library , controllerPath , "json" );
77+ public String createJsonViewCode (@ NotNull AppType appType ,@ NotNull String controllerPath ) {
78+ return getGeneratedCodeForView (appType , controllerPath , "json" );
9579 }
9680
9781 /**
9882 * Generic method to autogenerate code based on file template extension
9983 *
100- * @param ui5Library
84+ * @param appType
10185 * @param controllerPath
10286 * @param ext
10387 * @return
10488 */
105- private String getGeneratedCodeForView (@ NotNull UI5Library ui5Library , @ NotNull final String controllerPath ,@ NotNull String ext ) {
106- String templateLocation = "" ;
107- switch (ui5Library ) {
108- case DESKTOP :
109- templateLocation = "templates/desktop/view." + ext + ".ftl" ;
110- break ;
111- case MOBILE :
112- templateLocation = "templates/mobile/view." + ext + ".ftl" ;
113- break ;
114- }
89+ private String getGeneratedCodeForView (@ NotNull AppType appType , @ NotNull final String controllerPath ,@ NotNull String ext ) {
90+ return createTemplate ("templates/" + appType .name ().toLowerCase () + "/view." + ext + ".ftl" , new HashMap <String , Object >() {{
91+ put ("controllerPath" , controllerPath );
92+ }});
93+ }
11594
116- return Template .builder ().name (templateLocation ).classContext (this .getClass ())
117- .data (new HashMap <String , Object >() {{
118- put ("controllerPath" , controllerPath );
119- }})
120- .build ()
95+ /**
96+ * Template Builder class
97+ * @param templateName
98+ * @param replacements
99+ * @return
100+ */
101+ private String createTemplate (String templateName , HashMap <String , Object > replacements ) {
102+ return Template .builder ().name (templateName ).classContext (this .getClass ())
103+ .data (replacements ).build ()
121104 .toString ();
122105 }
123106}
0 commit comments