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.Application;
37 import fr.paris.lutece.plugins.pluginwizard.business.model.Attribute;
38 import fr.paris.lutece.plugins.pluginwizard.business.model.BusinessClass;
39 import fr.paris.lutece.plugins.pluginwizard.business.model.Feature;
40 import fr.paris.lutece.plugins.pluginwizard.business.model.PluginModel;
41 import fr.paris.lutece.plugins.pluginwizard.business.model.Portlet;
42 import fr.paris.lutece.plugins.pluginwizard.util.Utils;
43 import fr.paris.lutece.portal.service.util.AppPropertiesService;
44
45 import java.text.MessageFormat;
46
47 import java.util.HashMap;
48 import java.util.Map;
49
50
51
52
53
54
55 public class ResourcesGenerator extends AbstractGenerator
56 {
57 private static final String PATH_JAVA = "src/java/fr/paris/lutece/plugins/{plugin_name}/resources/";
58 private static final String PATH_KOTLIN = "src/kotlin/fr/paris/lutece/plugins/{plugin_name}/resources/";
59 private static String [ ] _languages = {
60 "", "fr"
61 };
62 private static String [ ] _prefix = {
63 "create", "modify"
64 };
65 private static String [ ] _suffix = {
66 "created", "updated", "removed"
67 };
68
69
70
71
72 @Override
73 public Map generate( PluginModel pm, String generationSchemeName )
74 {
75 HashMap map = new HashMap( );
76
77 String prefixFileName = pm.getPluginNameForRessource( );
78
79 for ( String strLanguage : _languages )
80 {
81 String strFilesPath = ( isKotlin( ) ) ? PATH_KOTLIN : PATH_JAVA;
82 String strPath = getFilePath( pm, strFilesPath,
83 prefixFileName + "_messages" + ( strLanguage.length( ) > 0 ? "_" : "" ) + strLanguage + ".properties" );
84
85 String strSourceCode = getCode( pm, strLanguage );
86 map.put( strPath, strSourceCode );
87 }
88
89 return map;
90 }
91
92
93
94
95
96
97
98
99
100
101 private String getCode( PluginModel pm, String strLanguage )
102 {
103 StringBuilder sb = new StringBuilder( );
104 generatePluginKeys( sb, pm );
105 generateFeaturesKeys( sb, pm );
106 generateXPagesKeys( sb, pm );
107 generateBusinessClassKeys( sb, pm, strLanguage );
108 generatePortletsKeys( sb, pm );
109 generateInfosKeys( sb, pm, strLanguage );
110
111 return sb.toString( );
112 }
113
114
115
116
117
118
119
120
121
122 private void generatePluginKeys( StringBuilder sb, PluginModel pm )
123 {
124 sb.append( "# Plugin's keys\n" );
125 if ( pm.isModule( ) )
126 {
127 sb.append( "module.provider=" ).append( pm.getPluginProvider( ) ).append( "\n" );
128 sb.append( "module.description=" ).append( pm.getPluginDescription( ) ).append( "\n" );
129 }
130 else
131 {
132 sb.append( "plugin.provider=" ).append( pm.getPluginProvider( ) ).append( "\n" );
133 sb.append( "plugin.description=" ).append( pm.getPluginDescription( ) ).append( "\n" );
134 }
135
136 sb.append( "\n" );
137 }
138
139
140
141
142
143
144
145
146
147 private void generateFeaturesKeys( StringBuilder sb, PluginModel pm )
148 {
149 if ( !pm.getFeatures( ).isEmpty( ) )
150 {
151 sb.append( "\n# Admin features keys\n\n" );
152
153 for ( Feature feature : pm.getFeatures( ) )
154 {
155 sb.append( "adminFeature." ).append( feature.getFeatureName( ) ).append( ".name=" ).append( feature.getFeatureName( ) ).append( "\n" );
156 sb.append( "adminFeature." ).append( feature.getFeatureName( ) ).append( ".description=" ).append( feature.getFeatureDescription( ) )
157 .append( "\n" );
158 }
159
160 sb.append( "\n" );
161 }
162 }
163
164 private void generateXPagesKeys( StringBuilder sb, PluginModel pm )
165 {
166 if ( !pm.getApplications( ).isEmpty( ) )
167 {
168 sb.append( "\n# XPages keys\n\n" );
169 }
170
171 for ( Application application : pm.getApplications( ) )
172 {
173 if ( application.getIdBusinessClasses( ).isEmpty( ) )
174 {
175 sb.append( "xpage." ).append( application.getApplicationName( ) ).append( ".pageTitle=" ).append( application.getApplicationName( ) )
176 .append( "\n" );
177 sb.append( "xpage." ).append( application.getApplicationName( ) ).append( ".pagePathLabel=" ).append( application.getApplicationName( ) )
178 .append( "\n" );
179 }
180 else
181 {
182 for ( int id : application.getIdBusinessClasses( ) )
183 {
184 for ( BusinessClass bc : pm.getBusinessClasses( ) )
185 {
186 if ( bc.getId( ) == id )
187 {
188 sb.append( "xpage." ).append( bc.getBusinessClass( ).toLowerCase( ) ).append( ".pageTitle=" )
189 .append( bc.getBusinessClass( ).toLowerCase( ) ).append( "\n" );
190 sb.append( "xpage." ).append( bc.getBusinessClass( ).toLowerCase( ) ).append( ".pagePathLabel=" )
191 .append( bc.getBusinessClass( ).toLowerCase( ) ).append( "\n" );
192 }
193 }
194 }
195 }
196 }
197 }
198
199
200
201
202
203
204
205
206
207
208
209 private void generateBusinessClassKeys( StringBuilder sb, PluginModel pm, String strLanguage )
210 {
211 if ( !pm.getBusinessClasses( ).isEmpty( ) )
212 {
213 sb.append( "\n# Business classes keys\n\n" );
214 }
215
216 for ( BusinessClass bc : pm.getBusinessClasses( ) )
217 {
218 sb.append( "\n# keys for business classes keys : " ).append( bc.getBusinessClass( ) ).append( "\n" );
219
220 String strPrefix = "manage_" + bc.getBusinessClass( ).toLowerCase( ) + "s.";
221 sb.append( strPrefix ).append( "pageTitle=" ).append( bc.getBusinessClass( ) ).append( "\n" );
222 sb.append( strPrefix ).append( "title=" ).append( getLabel( "title.manage", strLanguage, bc.getBusinessClass( ) ) ).append( "\n" );
223 sb.append( strPrefix ).append( "buttonAdd=" ).append( getLabel( "buttonAdd", strLanguage, bc.getBusinessClass( ) ) ).append( "\n" );
224
225 for ( Attribute attribute : bc.getAttributes( ) )
226 {
227 sb.append( strPrefix ).append( "column" ).append( attribute.getName( ) ).append( "=" ).append( attribute.getLabelName( ) ).append( "\n" );
228 }
229
230 for ( String strBasePrefix : _prefix )
231 {
232 strPrefix = strBasePrefix + "_" + bc.getBusinessClass( ).toLowerCase( ) + ".";
233 sb.append( strPrefix ).append( "pageTitle=" ).append( bc.getBusinessClass( ) ).append( "\n" );
234 sb.append( strPrefix ).append( "title=" ).append( getLabel( "title." + strBasePrefix, strLanguage, bc.getBusinessClass( ) ) ).append( "\n" );
235
236 for ( Attribute attribute : bc.getAttributes( ) )
237 {
238 sb.append( strPrefix ).append( "label" ).append( attribute.getName( ) ).append( "=" ).append( attribute.getLabelName( ) ).append( "\n" );
239 sb.append( strPrefix ).append( "label" ).append( attribute.getName( ) ).append( ".help=" ).append( attribute.getLabelName( ) )
240 .append( " (" ).append( getLabel( "helpText", strLanguage ) ).append( ")\n" );
241 }
242 }
243
244 sb.append( "\nmessage.confirmRemove" ).append( bc.getBusinessClass( ) ).append( "=" )
245 .append( getLabel( "confirmRemove", strLanguage, bc.getBusinessClass( ) ) ).append( "\n" );
246
247
248 sb.append( "\n# JSR 303 constraint validator messages\n" );
249
250 strPrefix = "validation." + bc.getBusinessClass( ).toLowerCase( ) + ".";
251
252 for ( Attribute attribute : bc.getAttributes( ) )
253 {
254 if ( !attribute.getType( ).equals( "int" ) )
255 {
256 if ( attribute.getNotNull( ) )
257 {
258 sb.append( strPrefix ).append( attribute.getName( ) ).append( ".notEmpty=" )
259 .append( getLabel( "validation.notEmpty", strLanguage, attribute.getLabelName( ) ) ).append( "\n" );
260 }
261
262 if ( attribute.getMaxLength( ) > 0 )
263 {
264 sb.append( strPrefix ).append( attribute.getName( ) ).append( ".size=" )
265 .append( getLabel( "validation.size", strLanguage, attribute.getLabelName( ), "" + attribute.getMaxLength( ) ) ).append( "\n" );
266 }
267 }
268 }
269
270 sb.append( "\n# model attributes for validation messages\n" );
271 strPrefix = "model.entity." + bc.getBusinessClass( ).toLowerCase( ) + ".attribute.";
272
273 for ( Attribute attribute : bc.getAttributes( ) )
274 {
275 sb.append( strPrefix ).append( Utils.firstLowerCase( attribute.getName( ) ) ).append( "=" ).append( attribute.getLabelName( ) ).append( "\n" );
276 }
277 }
278 }
279
280
281
282
283
284
285
286
287
288 private void generatePortletsKeys( StringBuilder sb, PluginModel pm )
289 {
290 if ( !pm.getPortlets( ).isEmpty( ) )
291 {
292 sb.append( "\n# Portlets keys\n\n" );
293
294 for ( Portlet portlet : pm.getPortlets( ) )
295 {
296 sb.append( "portlet." ).append( pm.getPluginName( ).toLowerCase( ) ).append( portlet.getPortletClass( ) ).append( ".name=" )
297 .append( portlet.getJspBaseName( ) ).append( "\n" );
298 }
299
300 sb.append( "\n" );
301 }
302 }
303
304
305
306
307
308
309
310
311
312 private void generateInfosKeys( StringBuilder sb, PluginModel pm, String strLanguage )
313 {
314 if ( !pm.getBusinessClasses( ).isEmpty( ) )
315 {
316 sb.append( "\n# Infos keys\n\n" );
317
318 for ( BusinessClass bc : pm.getBusinessClasses( ) )
319 {
320 for ( String strSuffix : _suffix )
321 {
322 sb.append( "info." ).append( bc.getBusinessClass( ).toLowerCase( ) ).append( "." ).append( strSuffix ).append( "=" )
323 .append( bc.getBusinessClass( ) ).append( " " ).append( getLabel( "infoKey." + strSuffix, strLanguage ) ).append( "\n" );
324 }
325 }
326
327 sb.append( "\n" );
328 }
329 }
330
331
332
333
334
335
336
337
338
339
340
341
342 private String getLabel( String strKey, String strLanguage, String... arguments )
343 {
344 String strFullKey = "pluginwizard.label." + strKey + "." + strLanguage;
345 String strLabel = AppPropertiesService.getProperty( strFullKey, "Label not found for key " + strFullKey );
346
347 return MessageFormat.format( strLabel, (Object [ ]) arguments );
348 }
349 }