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.BusinessClass;
37 import fr.paris.lutece.plugins.pluginwizard.business.model.Feature;
38 import fr.paris.lutece.plugins.pluginwizard.business.model.PluginModel;
39 import fr.paris.lutece.plugins.pluginwizard.service.ModelService;
40
41 import java.util.ArrayList;
42 import java.util.Collection;
43 import java.util.HashMap;
44 import java.util.List;
45 import java.util.Map;
46
47
48
49
50 public class AdminJspBeanGenerator extends AbstractGenerator
51 {
52 private static final String PATH_JAVA = "java/fr/paris/lutece/plugins/{plugin_name}/web/";
53 private static final String PATH_KOTLIN = "kotlin/fr/paris/lutece/plugins/{plugin_name}/web/";
54 private static final String PREFIX_JSPBEAN = "Abstract";
55 private static final String PREFIX_JSPBEAN_PATH = "src/";
56
57 private static final String SUFFIX_JAVA_EXTENSION = ".java";
58 private static final String SUFFIX_KOTLIN_EXTENSION = ".kt";
59
60 private static final String SUFFIX_JSPBEAN_CLASS = "JspBean";
61
62 private String _strAbstractParentBeanTemplate = "/generators/default/jspbean/gt_jspbean_abstract.html";
63 private List<AdminJspBeanFileConfig> _listFiles;
64
65 public void setFiles( List<AdminJspBeanFileConfig> listFiles )
66 {
67 if ( listFiles != null )
68 {
69 _listFiles = (List<AdminJspBeanFileConfig>) ( ( (ArrayList<AdminJspBeanFileConfig>) listFiles ).clone( ) );
70 }
71 else
72 {
73 _listFiles = null;
74 }
75 }
76
77
78
79
80
81
82
83 public void setAbstractParentBeanTemplate( String strParent )
84 {
85 _strAbstractParentBeanTemplate = strParent;
86 }
87
88
89
90
91 public Map<String, String> generate( PluginModel pm, String generationSchemeName )
92 {
93 HashMap<String, String> map = new HashMap<>( );
94
95 for ( Feature feature : pm.getFeatures( ) )
96 {
97
98 Collection<BusinessClass> listBusinessClasses = ModelService.getBusinessClassesByFeature( pm, feature.getId( ) );
99
100 String strSuffix = SUFFIX_JSPBEAN_CLASS + ( ( isKotlin( ) ) ? SUFFIX_KOTLIN_EXTENSION : SUFFIX_JAVA_EXTENSION );
101 String strFilesPath = ( isKotlin( ) ) ? PATH_KOTLIN : PATH_JAVA;
102 if ( listBusinessClasses.isEmpty( ) )
103 {
104 for ( AdminJspBeanFileConfig file : _listFiles )
105 {
106 String strSuffixConfig = SUFFIX_JSPBEAN_CLASS + file.getSuffix( ) + ( ( isKotlin( ) ) ? SUFFIX_KOTLIN_EXTENSION : SUFFIX_JAVA_EXTENSION );
107 String strFilename = feature.getFeatureName( ) + strSuffixConfig;
108 String strPath = getFilePath( pm, file.getSourcePath( ) + ( isKotlin( ) ? PATH_KOTLIN : PATH_JAVA ), strFilename );
109 String strSourceCode = getJspBeanCode( pm, feature.getFeatureName( ), feature.getFeatureRight( ), file.getTemplate( ),
110 pm.getPluginNameAsRadicalPackage( ), pm.getPluginName( ) );
111 map.put( strPath, strSourceCode );
112 }
113 }
114 else
115 {
116 for ( BusinessClass business : listBusinessClasses )
117 {
118 for ( AdminJspBeanFileConfig file : _listFiles )
119 {
120 String strSuffixConfig = SUFFIX_JSPBEAN_CLASS + file.getSuffix( )
121 + ( ( isKotlin( ) ) ? SUFFIX_KOTLIN_EXTENSION : SUFFIX_JAVA_EXTENSION );
122 String strFilename = business.getBusinessClassCapsFirst( ) + strSuffixConfig;
123 String strPath = getFilePath( pm, file.getSourcePath( ) + ( isKotlin( ) ? PATH_KOTLIN : PATH_JAVA ), strFilename );
124 String strSourceCode = getJspBeanCode( pm, feature.getFeatureName( ), feature.getFeatureRight( ), business, file.getTemplate( ),
125 pm.getPluginNameAsRadicalPackage( ), pm.getPluginName( ) );
126 map.put( strPath, strSourceCode );
127 }
128 }
129 }
130 String strPath = getFilePath( pm, PREFIX_JSPBEAN_PATH + strFilesPath, PREFIX_JSPBEAN + feature.getFeatureName( ) + strSuffix );
131 String strSourceCode = getAbstractJspBeanCode( pm, feature.getFeatureName( ), feature.getFeatureRight( ), pm.getPluginNameAsRadicalPackage( ),
132 pm.getPluginName( ) );
133 map.put( strPath, strSourceCode );
134 }
135
136 return map;
137 }
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152 private String getJspBeanCode( PluginModel pm, String strFeatureName, String strFeatureRight, BusinessClass business, String strTemplate,
153 String strRadicalPackage, String strBeanName )
154 {
155 Map<String, Object> model = getModel( pm );
156
157 model.put( Markers.MARK_BUSINESS_CLASS, business );
158 model.put( Markers.MARK_FEATURE_NAME, strFeatureName );
159 model.put( Markers.MARK_FEATURE_RIGHT, strFeatureRight );
160
161 model.put( Markers.MARK_RADICAL_PACKAGE, strRadicalPackage );
162 model.put( Markers.MARK_BEAN_NAME, strBeanName );
163
164 return build( strTemplate, model );
165 }
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180 private String getJspBeanCode( PluginModel pm, String strFeatureName, String strFeatureRight, String strTemplate, String strRadicalPackage,
181 String strBeanName )
182 {
183 Map<String, Object> model = getModel( pm );
184
185 model.put( Markers.MARK_FEATURE_NAME, strFeatureName );
186 model.put( Markers.MARK_FEATURE_RIGHT, strFeatureRight );
187
188 model.put( Markers.MARK_RADICAL_PACKAGE, strRadicalPackage );
189 model.put( Markers.MARK_BEAN_NAME, strBeanName );
190
191 return build( strTemplate, model );
192 }
193
194
195
196
197
198
199
200
201
202
203
204
205 private String getAbstractJspBeanCode( PluginModel pm, String strFeatureName, String strFeatureRight, String strRadicalPackage, String strBeanName )
206 {
207 Map<String, Object> model = getModel( pm );
208
209 model.put( Markers.MARK_FEATURE_NAME, strFeatureName );
210 model.put( Markers.MARK_FEATURE_RIGHT, strFeatureRight );
211
212 model.put( Markers.MARK_RADICAL_PACKAGE, strRadicalPackage );
213 model.put( Markers.MARK_BEAN_NAME, strBeanName );
214
215 return build( _strAbstractParentBeanTemplate, model );
216 }
217 }