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
118 {
119 strBasePath = strBasePath.replace( "{plugin_name}", pm.getPluginName( ) );
120 }
121
122 return strBasePath + strFilename;
123 }
124
125
126
127
128
129
130
131
132 protected String getFirstCaps( String strValue )
133 {
134 String strFirstLetter = strValue.substring( 0, 1 );
135 String strLettersLeft = strValue.substring( 1 );
136 String strValueCap = strFirstLetter.toUpperCase( ) + strLettersLeft.toLowerCase( );
137
138 return strValueCap;
139 }
140
141
142
143
144
145
146
147
148 protected Map<String, Object> getModel( PluginModel pm )
149 {
150 Map<String, Object> model = new HashMap<>( );
151 model.put( Markers.MARK_PLUGIN_MODEL, pm );
152
153 return model;
154 }
155
156
157
158
159
160
161
162
163 protected String build( PluginModel pm )
164 {
165 return build( getTemplate( ), getModel( pm ) );
166 }
167
168
169
170
171
172
173
174
175
176
177 protected String build( String strTemplate, PluginModel pm )
178 {
179 return build( strTemplate, getModel( pm ) );
180 }
181
182
183
184
185
186
187
188
189 protected String build( Map<String, Object> model )
190 {
191 return build( getTemplate( ), model );
192 }
193
194
195
196
197
198
199
200
201
202
203 protected String build( String strTemplate, Map<String, Object> model )
204 {
205 HtmlTemplate template = AppTemplateService.getTemplate( strTemplate, Locale.getDefault( ), model );
206
207 return template.getHtml( );
208 }
209
210 }