1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package fr.paris.lutece.plugins.pluginwizard.service.generator;
35
36 import fr.paris.lutece.plugins.pluginwizard.business.model.PluginModel;
37 import fr.paris.lutece.portal.service.template.AppTemplateService;
38 import fr.paris.lutece.util.html.HtmlTemplate;
39
40 import java.util.HashMap;
41 import java.util.Locale;
42 import java.util.Map;
43
44
45
46
47
48 public abstract class AbstractGenerator implements Generator
49 {
50 protected static final String MARK_KOTLIN = "kotlin";
51
52 private String _strTemplate;
53 private boolean _bKotlin;
54
55
56
57
58
59
60
61 public void setKotlin( boolean bKotlin )
62 {
63 _bKotlin = bKotlin;
64 }
65
66
67
68
69
70
71 protected boolean isKotlin( )
72 {
73 return _bKotlin;
74 }
75
76
77
78
79
80
81 public String getTemplate( )
82 {
83 return _strTemplate;
84 }
85
86
87
88
89
90
91
92 public void setTemplate( String strTemplate )
93 {
94 _strTemplate = strTemplate;
95 }
96
97
98
99
100
101
102
103
104
105
106
107
108 protected String getFilePath( PluginModel pm, String strPath, String strFilename )
109 {
110 String strBasePath = "plugin-{plugin_name}/" + strPath;
111
112 if ( pm.isModule( ) )
113 {
114 strBasePath = "module-" + pm.getPluginName( ) + "/"
115 + strPath.replace( "{plugin_name}", ( pm.getPluginName( ).split( "-" ) [0] + "/modules/" + pm.getPluginName( ).split( "-" ) [1] ) );
116 }
117 else if( pm.isWorkflowTask( ) )
118 {
119 strBasePath = "module-workflow-" + pm.getPluginName( ) + "/" + strPath.replace( "{plugin_name}", pm.getPluginName( ) );
120 }
121 else
122 {
123 strBasePath = strBasePath.replace( "{plugin_name}", pm.getPluginName( ) );
124 }
125
126 return strBasePath + strFilename;
127 }
128
129
130
131
132
133
134
135
136 protected String getFirstCaps( String strValue )
137 {
138 String strFirstLetter = strValue.substring( 0, 1 );
139 String strLettersLeft = strValue.substring( 1 );
140 String strValueCap = strFirstLetter.toUpperCase( ) + strLettersLeft.toLowerCase( );
141
142 return strValueCap;
143 }
144
145
146
147
148
149
150
151
152 protected Map<String, Object> getModel( PluginModel pm )
153 {
154 Map<String, Object> model = new HashMap<>( );
155 model.put( Markers.MARK_PLUGIN_MODEL, pm );
156
157 return model;
158 }
159
160
161
162
163
164
165
166
167 protected String build( PluginModel pm )
168 {
169 return build( getTemplate( ), getModel( pm ) );
170 }
171
172
173
174
175
176
177
178
179
180
181 protected String build( String strTemplate, PluginModel pm )
182 {
183 return build( strTemplate, getModel( pm ) );
184 }
185
186
187
188
189
190
191
192
193 protected String build( Map<String, Object> model )
194 {
195 return build( getTemplate( ), model );
196 }
197
198
199
200
201
202
203
204
205
206
207 protected String build( String strTemplate, Map<String, Object> model )
208 {
209 HtmlTemplate template = AppTemplateService.getTemplate( strTemplate, Locale.getDefault( ), model );
210
211 return template.getHtml( );
212 }
213
214 }