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 java.util.HashMap;
41 import java.util.List;
42 import java.util.Map;
43
44
45
46
47
48
49 public class AdminJspGenerator extends AbstractGenerator
50 {
51 private static final String PATH = "webapp/jsp/admin/plugins/{plugin_name}/";
52 private static final String EXT_JSP = ".jsp";
53 private static String [ ] _jsp_prefix = {
54 "Create", "DoCreate", "Remove", "DoRemove", "Manage", "Modify", "DoModify"
55 };
56 private String _strBusinessTemplate;
57 private String _strFeatureTemplate;
58
59
60
61
62
63
64
65 public void setBusinessTemplate( String strTemplate )
66 {
67 _strBusinessTemplate = strTemplate;
68 }
69
70
71
72
73
74
75
76 public void setFeatureTemplate( String strTemplate )
77 {
78 _strFeatureTemplate = strTemplate;
79 }
80
81
82
83
84 @Override
85 public Map generate( PluginModel pm, String generationSchemeName )
86 {
87 HashMap map = new HashMap( );
88 String strPluginName = pm.getPluginNameAsRadicalPackage( );
89
90 for ( Feature feature : pm.getFeatures( ) )
91 {
92 List<BusinessClass> listBusinessClasses = ModelService.getBusinessClassesByFeature( pm, feature.getId( ) );
93
94 for ( BusinessClass businessClass : listBusinessClasses )
95 {
96 for ( int i = 0; i < _jsp_prefix.length; i++ )
97 {
98
99 String strSuffix = EXT_JSP;
100 String strJspFileName = "";
101
102
103 if( i == 4 )
104 {
105 strJspFileName = _jsp_prefix [i] + businessClass.getPluralBusinessClass( ) + strSuffix;
106 }
107 else
108 {
109 strJspFileName = _jsp_prefix [i] + businessClass.getBusinessClass( ) + strSuffix;
110 }
111
112 String strPath = getFilePath( pm, PATH, strJspFileName );
113
114 String strSourceCode = getJspBusinessFile( businessClass, feature.getFeatureName( ), strPluginName, i + 1, pm.isModule( ) );
115 strSourceCode = strSourceCode.replace( "<", "<" );
116 strSourceCode = strSourceCode.replace( ">", ">" );
117 map.put( strPath, strSourceCode );
118 }
119 }
120
121 String strPath = getFilePath( pm, PATH, feature.getFeatureName( ) + EXT_JSP );
122
123 String strSourceCode = getFeatureJspFile( feature.getFeatureName( ), strPluginName, pm.isModule( ) );
124 strSourceCode = strSourceCode.replace( "<", "<" );
125 strSourceCode = strSourceCode.replace( ">", ">" );
126 map.put( strPath, strSourceCode );
127 }
128
129 return map;
130 }
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146 private String getJspBusinessFile( BusinessClass businessClass, String strFeatureName, String strPluginName, int nJspType, boolean bIsModule )
147 {
148 Map<String, Object> model = new HashMap<>( );
149 model.put( Markers.MARK_FEATURE_NAME, strFeatureName );
150 model.put( Markers.MARK_BUSINESS_CLASS, businessClass );
151 model.put( Markers.MARK_PLUGIN_NAME, strPluginName );
152 model.put( Markers.MARK_JSP_TYPE, "" + nJspType );
153 model.put( Markers.MARK_IS_MODULE, bIsModule );
154
155 String strBeanName = strFeatureName.toLowerCase( ) + businessClass.getBusinessClassCapsFirst( );
156 model.put( Markers.MARK_BEAN_NAME, strBeanName );
157
158 return build( _strBusinessTemplate, model );
159 }
160
161
162
163
164
165
166
167
168
169
170
171 private String getFeatureJspFile( String strFeatureName, String strPluginName, boolean bIsModule )
172 {
173 Map<String, Object> model = new HashMap<>( );
174 model.put( Markers.MARK_FEATURE_NAME, strFeatureName );
175 model.put( Markers.MARK_PLUGIN_NAME, strPluginName );
176 model.put( Markers.MARK_IS_MODULE, bIsModule );
177
178 return build( _strFeatureTemplate, model );
179 }
180 }