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 String strSuffix = ( i == 4 ) ? ( "s" + EXT_JSP ) : EXT_JSP;
99 String strJspFileName = _jsp_prefix [i] + businessClass.getBusinessClass( ) + strSuffix;
100
101 String strPath = getFilePath( pm, PATH, strJspFileName );
102
103 String strSourceCode = getJspBusinessFile( businessClass, feature.getFeatureName( ), strPluginName, i + 1, pm.isModule( ) );
104 strSourceCode = strSourceCode.replace( "<", "<" );
105 strSourceCode = strSourceCode.replace( ">", ">" );
106 map.put( strPath, strSourceCode );
107 }
108 }
109
110 String strPath = getFilePath( pm, PATH, feature.getFeatureName( ) + EXT_JSP );
111
112 String strSourceCode = getFeatureJspFile( feature.getFeatureName( ), strPluginName, pm.isModule( ) );
113 strSourceCode = strSourceCode.replace( "<", "<" );
114 strSourceCode = strSourceCode.replace( ">", ">" );
115 map.put( strPath, strSourceCode );
116 }
117
118 return map;
119 }
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135 private String getJspBusinessFile( BusinessClass businessClass, String strFeatureName, String strPluginName, int nJspType, boolean bIsModule )
136 {
137 Map<String, Object> model = new HashMap<>( );
138 model.put( Markers.MARK_FEATURE_NAME, strFeatureName );
139 model.put( Markers.MARK_BUSINESS_CLASS, businessClass );
140 model.put( Markers.MARK_PLUGIN_NAME, strPluginName );
141 model.put( Markers.MARK_JSP_TYPE, "" + nJspType );
142 model.put( Markers.MARK_IS_MODULE, bIsModule );
143
144 String strBeanName = strFeatureName.toLowerCase( ) + businessClass.getBusinessClassCapsFirst( );
145 model.put( Markers.MARK_BEAN_NAME, strBeanName );
146
147 return build( _strBusinessTemplate, model );
148 }
149
150
151
152
153
154
155
156
157
158
159
160 private String getFeatureJspFile( String strFeatureName, String strPluginName, boolean bIsModule )
161 {
162 Map<String, Object> model = new HashMap<>( );
163 model.put( Markers.MARK_FEATURE_NAME, strFeatureName );
164 model.put( Markers.MARK_PLUGIN_NAME, strPluginName );
165 model.put( Markers.MARK_IS_MODULE, bIsModule );
166
167 return build( _strFeatureTemplate, model );
168 }
169 }