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 import fr.paris.lutece.plugins.pluginwizard.util.Utils;
41
42 import java.util.HashMap;
43 import java.util.List;
44 import java.util.Map;
45
46
47
48
49 public class AdminJspControllerGenerator extends AbstractGenerator
50 {
51 private static final String PATH = "webapp/jsp/admin/plugins/{plugin_name}/";
52 private String _strBusinessTemplate;
53 private String _strFeatureTemplate;
54
55
56
57
58
59
60
61 public void setBusinessTemplate( String strTemplate )
62 {
63 _strBusinessTemplate = strTemplate;
64 }
65
66
67
68
69
70
71
72 public void setFeatureTemplate( String strTemplate )
73 {
74 _strFeatureTemplate = strTemplate;
75 }
76
77
78
79
80 @Override
81 public Map generate( PluginModel pm, String generationSchemeName )
82 {
83 HashMap map = new HashMap( );
84
85 String strPluginName = pm.getPluginNameAsRadicalPackage( );
86
87 for ( Feature feature : pm.getFeatures( ) )
88 {
89 List<BusinessClass> listBusinessClasses = ModelService.getBusinessClassesByFeature( pm, feature.getId( ) );
90
91 for ( BusinessClass businessClass : listBusinessClasses )
92 {
93 String strJspFileName = "Manage" + businessClass.getBusinessClass( ) + "s.jsp";
94
95 String strPath = getFilePath( pm, PATH, strJspFileName );
96
97 String strSourceCode = getJspBusinessFile( businessClass, feature.getFeatureName( ), strPluginName, pm.isModule( ) );
98 strSourceCode = strSourceCode.replace( "<", "<" );
99 strSourceCode = strSourceCode.replace( ">", ">" );
100 map.put( strPath, strSourceCode );
101 }
102 }
103
104 return map;
105 }
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120 private String getJspBusinessFile( BusinessClass businessClass, String strFeatureName, String strPluginName, boolean bIsModule )
121 {
122 String strBeanName = strFeatureName.toLowerCase( ) + businessClass.getBusinessClass( );
123 Map<String, Object> model = new HashMap<>( );
124 model.put( Markers.MARK_BUSINESS_CLASS, businessClass );
125 model.put( Markers.MARK_PLUGIN_NAME, strPluginName );
126 model.put( Markers.MARK_BEAN_NAME, strBeanName );
127 model.put( Markers.MARK_IS_MODULE, bIsModule );
128
129 return build( _strBusinessTemplate, model );
130 }
131
132
133
134
135
136
137
138
139
140
141 private String getFeatureJspFile( String strFeatureName, String strPluginName, boolean bIsModule )
142 {
143 Map<String, Object> model = new HashMap<>( );
144 model.put( Markers.MARK_FEATURE_NAME, strFeatureName );
145 model.put( Markers.MARK_PLUGIN_NAME, strPluginName );
146 model.put( Markers.MARK_IS_MODULE, bIsModule );
147
148 return build( _strFeatureTemplate, model );
149 }
150 }