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.Application;
37 import fr.paris.lutece.plugins.pluginwizard.business.model.BusinessClass;
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 XPageTemplateGenerator extends AbstractGenerator
55 {
56 private static final String PATH = "webapp/WEB-INF/templates/skin/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 String strPluginName = pm.getPluginNameAsPackage( );
72
73
74 Collection<Application> listApplication = pm.getApplications( );
75
76 for ( Application application : listApplication )
77 {
78 Collection<BusinessClass> listBusinessClasses = ModelService.getBusinessClassesByApplication( pm, application.getId( ) );
79
80 if ( listBusinessClasses.isEmpty( ) )
81 {
82 String strPath = getFilePath( pm, PATH, application.getApplicationName( ) + ".html" );
83 String strSourceCode = getCreateHtmlCode( application, strPluginName );
84 map.put( strPath, strSourceCode );
85 }
86 else
87 {
88 for ( BusinessClass businessClass : listBusinessClasses )
89 {
90 for ( int i = 0; i < _template_prefix.length; i++ )
91 {
92 String strSuffix = ".html";
93 String strPath ="";
94
95
96 if( i == 2 )
97 {
98 strPath = getFilePath( pm, PATH, _template_prefix [i] + businessClass.getPluralBusinessClass( ).toLowerCase( ) + strSuffix );
99 }
100 else
101 {
102 strPath = getFilePath( pm, PATH, _template_prefix [i] + businessClass.getBusinessClass( ).toLowerCase( ) + strSuffix );
103 }
104
105 String strSourceCode = getCreateHtmlCode( listBusinessClasses, application, businessClass, i, strPluginName );
106 map.put( strPath, strSourceCode );
107 }
108 }
109
110
111 String strPath = getFilePath( pm, PATH, application.getApplicationName( ).toLowerCase( ) + "_tabs.html" );
112
113 String strSourceCode = getTabsHtmlCode( listBusinessClasses, strPluginName, application );
114 map.put( strPath, strSourceCode );
115 }
116 }
117
118 return map;
119 }
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136 private String getCreateHtmlCode( Collection<BusinessClass> listAllBusinessClasses, Application application, BusinessClass businessClass, int nTemplateType,
137 String strPluginName )
138 {
139 Map<String, Object> model = new HashMap<>( );
140
141 model.put( Markers.MARK_PLUGIN_NAME, strPluginName );
142 model.put( Markers.MARK_I18N_BRACKETS_OPEN, "@@i18n{" );
143 model.put( Markers.MARK_I18N_BRACKETS_CLOSE, "}" );
144 model.put( Markers.MARK_MACRO, "@" );
145 model.put( Markers.MARK_VARIABLE, "@@" );
146 model.put( Markers.MARK_BRACKETS_OPEN, "${" );
147 model.put( Markers.MARK_BRACKETS_CLOSE, "}" );
148 model.put( Markers.MARK_BUSINESS_CLASS, businessClass );
149 model.put( Markers.MARK_LIST_BUSINESS_CLASSES, listAllBusinessClasses );
150 model.put( Markers.MARK_APPLICATION, application );
151 model.put( Markers.MARK_INCLUDE, "@@include" );
152
153 model.put( Markers.MARK_TEMPLATE_TYPE, nTemplateType );
154
155 HtmlTemplate template = AppTemplateService.getTemplate( getTemplate( ), Locale.getDefault( ), model );
156
157 return template.getHtml( ).replace( "@@", "#" );
158 }
159
160
161
162
163
164
165
166
167
168
169
170
171 private String getTabsHtmlCode( Collection<BusinessClass> listAllBusinessClasses, String strPluginName, Application application )
172 {
173 Map<String, Object> model = new HashMap<>( );
174
175 model.put( Markers.MARK_PLUGIN_NAME, strPluginName );
176 model.put( Markers.MARK_APPLICATION, application );
177 model.put( Markers.MARK_I18N_BRACKETS_OPEN, "@@i18n{" );
178 model.put( Markers.MARK_I18N_BRACKETS_CLOSE, "}" );
179 model.put( Markers.MARK_MACRO, "@" );
180 model.put( Markers.MARK_VARIABLE, "@@" );
181 model.put( Markers.MARK_BRACKETS_OPEN, "${" );
182 model.put( Markers.MARK_BRACKETS_CLOSE, "}" );
183 model.put( Markers.MARK_MACRO_DEF, "@@macro" );
184 model.put( Markers.MARK_LIST_BUSINESS_CLASSES, listAllBusinessClasses );
185
186 HtmlTemplate template = AppTemplateService.getTemplate( _strTabsTemplate, Locale.getDefault( ), model );
187
188 return template.getHtml( ).replace( "@@", "#" );
189 }
190
191
192
193
194
195
196
197
198
199
200 private String getCreateHtmlCode( Application application, String strPluginName )
201 {
202 Map<String, Object> model = new HashMap<>( );
203
204 model.put( Markers.MARK_PLUGIN_NAME, strPluginName );
205 model.put( Markers.MARK_I18N_BRACKETS_OPEN, "@@i18n{" );
206 model.put( Markers.MARK_I18N_BRACKETS_CLOSE, "}" );
207 model.put( Markers.MARK_MACRO, "@" );
208 model.put( Markers.MARK_VARIABLE, "@@" );
209 model.put( Markers.MARK_BRACKETS_OPEN, "${" );
210 model.put( Markers.MARK_BRACKETS_CLOSE, "}" );
211 model.put( Markers.MARK_APPLICATION, application );
212 model.put( Markers.MARK_INCLUDE, "@@include" );
213
214 HtmlTemplate template = AppTemplateService.getTemplate( getTemplate( ), Locale.getDefault( ), model );
215
216 return template.getHtml( ).replace( "@@", "#" );
217 }
218
219
220
221
222
223 public void setTabsTemplate( String tabsTemplate )
224 {
225 _strTabsTemplate = tabsTemplate;
226 }
227 }