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 = "AbstractPaginator";
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 String strFilesPath = ( isKotlin( ) ) ? PATH_KOTLIN : PATH_JAVA;
95 String strSuffix = SUFFIX_JSPBEAN_CLASS + ( ( isKotlin( ) ) ? SUFFIX_KOTLIN_EXTENSION : SUFFIX_JAVA_EXTENSION );
96
97 for ( Feature feature : pm.getFeatures( ) )
98 {
99 Collection<BusinessClass> listBusinessClasses = ModelService.getBusinessClassesByFeature( pm, feature.getId( ) );
100
101 if ( listBusinessClasses.isEmpty( ) )
102 {
103 for ( AdminJspBeanFileConfig file : _listFiles )
104 {
105 String strSuffixConfig = SUFFIX_JSPBEAN_CLASS + file.getSuffix( ) + ( ( isKotlin( ) ) ? SUFFIX_KOTLIN_EXTENSION : SUFFIX_JAVA_EXTENSION );
106 String strFilename = feature.getFeatureName( ) + strSuffixConfig;
107 String strPath = getFilePath( pm, file.getSourcePath( ) + ( isKotlin( ) ? PATH_KOTLIN : PATH_JAVA ), strFilename );
108 String strSourceCode = getJspBeanCode( pm, feature.getFeatureName( ), feature.getFeatureRight( ), file.getTemplate( ),
109 pm.getPluginNameAsRadicalPackage( ), pm.getPluginName( ) );
110 map.put( strPath, strSourceCode );
111 }
112 }
113 else
114 {
115 for ( BusinessClass business : listBusinessClasses )
116 {
117 for ( AdminJspBeanFileConfig file : _listFiles )
118 {
119 String strSuffixConfig = SUFFIX_JSPBEAN_CLASS + file.getSuffix( )
120 + ( ( isKotlin( ) ) ? SUFFIX_KOTLIN_EXTENSION : SUFFIX_JAVA_EXTENSION );
121 String strFilename = business.getBusinessClassCapsFirst( ) + strSuffixConfig;
122 String strPath = getFilePath( pm, file.getSourcePath( ) + ( isKotlin( ) ? PATH_KOTLIN : PATH_JAVA ), strFilename );
123 String strSourceCode = getJspBeanCode( pm, feature.getFeatureName( ), feature.getFeatureRight( ), business, file.getTemplate( ),
124 pm.getPluginNameAsRadicalPackage( ), pm.getPluginName( ) );
125 map.put( strPath, strSourceCode );
126 }
127 }
128 }
129 }
130 String strPath = getFilePath( pm, PREFIX_JSPBEAN_PATH + strFilesPath, PREFIX_JSPBEAN + strSuffix );
131 String strSourceCode = getAbstractJspBeanCode( pm, pm.getPluginNameAsRadicalPackage( ),
132 pm.getPluginName( ) );
133 map.put( strPath, strSourceCode );
134
135 return map;
136 }
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151 private String getJspBeanCode( PluginModel pm, String strFeatureName, String strFeatureRight, BusinessClass business, String strTemplate,
152 String strRadicalPackage, String strBeanName )
153 {
154 Map<String, Object> model = getModel( pm );
155
156 model.put( Markers.MARK_BUSINESS_CLASS, business );
157 model.put( Markers.MARK_FEATURE_NAME, strFeatureName );
158 model.put( Markers.MARK_FEATURE_RIGHT, strFeatureRight );
159
160 model.put( Markers.MARK_RADICAL_PACKAGE, strRadicalPackage );
161 model.put( Markers.MARK_BEAN_NAME, strBeanName );
162
163 return build( strTemplate, model );
164 }
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179 private String getJspBeanCode( PluginModel pm, String strFeatureName, String strFeatureRight, String strTemplate, String strRadicalPackage,
180 String strBeanName )
181 {
182 Map<String, Object> model = getModel( pm );
183
184 model.put( Markers.MARK_FEATURE_NAME, strFeatureName );
185 model.put( Markers.MARK_FEATURE_RIGHT, strFeatureRight );
186
187 model.put( Markers.MARK_RADICAL_PACKAGE, strRadicalPackage );
188 model.put( Markers.MARK_BEAN_NAME, strBeanName );
189
190 return build( strTemplate, model );
191 }
192
193
194
195
196
197
198
199
200
201
202
203
204 private String getAbstractJspBeanCode( PluginModel pm, String strRadicalPackage, String strBeanName )
205 {
206 Map<String, Object> model = getModel( pm );
207
208 model.put( Markers.MARK_RADICAL_PACKAGE, strRadicalPackage );
209 model.put( Markers.MARK_BEAN_NAME, strBeanName );
210
211 return build( _strAbstractParentBeanTemplate, model );
212 }
213 }