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 import fr.paris.lutece.portal.service.template.AppTemplateService;
42 import fr.paris.lutece.util.html.HtmlTemplate;
43
44 import java.util.Collection;
45 import java.util.HashMap;
46 import java.util.Locale;
47 import java.util.Map;
48
49
50
51
52
53
54 public class AdminTemplateGenerator extends AbstractGenerator
55 {
56 private static final String PATH = "webapp/WEB-INF/templates/admin/plugins/{plugin_name}/";
57 private static String [ ] _template_prefix = {
58 "create_", "modify_", "manage_"
59 };
60 private String _strTabsTemplate;
61
62
63
64
65
66
67 @Override
68 public Map generate( PluginModel pm, String generationSchemeName )
69 {
70 HashMap map = new HashMap( );
71
72 String strPluginName = pm.getPluginNameAsPackage( );
73 String strLink = pm.getPluginNameAsRadicalPath( );
74
75
76 Collection<Feature> listFeatures = pm.getFeatures( );
77
78 for ( Feature feature : listFeatures )
79 {
80 Collection<BusinessClass> listBusinessClasses = ModelService.getBusinessClassesByFeature( pm, feature.getId( ) );
81
82 for ( BusinessClass businessClass : listBusinessClasses )
83 {
84 Feature admin_feature = ModelService.getFeatureByBusinessClass( pm, businessClass.getId( ) );
85
86 for ( int i = 0; i < _template_prefix.length; i++ )
87 {
88 String strSuffix = ( i == 2 ) ? "s.html" : ".html";
89 String strPath = getFilePath( pm, PATH, _template_prefix [i] + businessClass.getBusinessClass( ).toLowerCase( ) + strSuffix );
90
91 String strSourceCode = getCreateHtmlCode( listBusinessClasses, admin_feature, businessClass, i, strPluginName, strLink );
92 map.put( strPath, strSourceCode );
93 }
94 }
95
96
97 String strPath = getFilePath( pm, PATH, feature.getFeatureName( ).toLowerCase( ) + "_tabs.html" );
98
99 String strSourceCode = getTabsHtmlCode( listBusinessClasses, strPluginName, feature, strLink );
100 map.put( strPath, strSourceCode );
101 }
102
103 return map;
104 }
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120 private String getCreateHtmlCode( Collection<BusinessClass> listAllBusinessClasses, Feature admin_feature, BusinessClass businessClass, int nTemplateType,
121 String strPluginName, String strLinkJsp )
122 {
123 Map<String, Object> model = new HashMap<String, Object>( );
124
125 model.put( Markers.MARK_PLUGIN_NAME, strPluginName );
126 model.put( Markers.MARK_I18N_BRACKETS_OPEN, "@@i18n{" );
127 model.put( Markers.MARK_I18N_BRACKETS_CLOSE, "}" );
128 model.put( Markers.MARK_MACRO, "@" );
129 model.put( Markers.MARK_VARIABLE, "@@" );
130 model.put( Markers.MARK_BRACKETS_OPEN, "${" );
131 model.put( Markers.MARK_BRACKETS_CLOSE, "}" );
132 model.put( Markers.MARK_BUSINESS_CLASS, businessClass );
133 model.put( Markers.MARK_LIST_BUSINESS_CLASSES, listAllBusinessClasses );
134 model.put( Markers.MARK_ADMIN_FEATURE, admin_feature );
135 model.put( Markers.MARK_INCLUDE, "@@include" );
136 model.put( Markers.MARK_PLUGIN_PATH, strLinkJsp );
137
138 model.put( Markers.MARK_TEMPLATE_TYPE, nTemplateType );
139
140 HtmlTemplate template = AppTemplateService.getTemplate( getTemplate( ), Locale.getDefault( ), model );
141
142 return template.getHtml( ).replace( "@@", "#" );
143 }
144
145
146
147
148
149
150
151
152
153
154
155
156
157 private String getTabsHtmlCode( Collection<BusinessClass> listAllBusinessClasses, String strPluginName, Feature feature, String strLinkJsp )
158 {
159 Map<String, Object> model = new HashMap<String, Object>( );
160
161 model.put( Markers.MARK_PLUGIN_NAME, strPluginName );
162 model.put( Markers.MARK_FEATURE, feature );
163 model.put( Markers.MARK_I18N_BRACKETS_OPEN, "@@i18n{" );
164 model.put( Markers.MARK_I18N_BRACKETS_CLOSE, "}" );
165 model.put( Markers.MARK_MACRO, "@" );
166 model.put( Markers.MARK_VARIABLE, "@@" );
167 model.put( Markers.MARK_BRACKETS_OPEN, "${" );
168 model.put( Markers.MARK_BRACKETS_CLOSE, "}" );
169 model.put( Markers.MARK_MACRO_DEF, "@@macro" );
170 model.put( Markers.MARK_LIST_BUSINESS_CLASSES, listAllBusinessClasses );
171 model.put( Markers.MARK_PLUGIN_PATH, strLinkJsp );
172
173 HtmlTemplate template = AppTemplateService.getTemplate( _strTabsTemplate, Locale.getDefault( ), model );
174
175 return template.getHtml( ).replace( "@@", "#" );
176 }
177
178
179
180
181
182 public void setTabsTemplate( String tabsTemplate )
183 {
184 _strTabsTemplate = tabsTemplate;
185 }
186 }