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
41 import java.util.ArrayList;
42 import java.util.Collection;
43 import java.util.HashMap;
44 import java.util.List;
45 import java.util.Map;
46
47
48
49
50
51
52 public class XPageGenerator extends AbstractGenerator
53 {
54 private static final String PATH_JAVA = "java/fr/paris/lutece/plugins/{plugin_name}/web/";
55 private static final String PATH_KOTLIN = "kotlin/fr/paris/lutece/plugins/{plugin_name}/web/";
56
57 private static final String SUFFIX_JAVA_EXTENSION = ".java";
58 private static final String SUFFIX_KOTLIN_EXTENSION = ".kt";
59
60 private static final String SUFFIX_XPAGE_CLASS = "XPage";
61 private static final String SUFFIX_XPAGE = "";
62
63 private List<XPageFileConfig> _listFiles;
64
65
66
67
68
69
70
71 public void setFiles( List<XPageFileConfig> listFiles )
72 {
73 if ( listFiles != null )
74 {
75 _listFiles = (List<XPageFileConfig>) ( ( (ArrayList<XPageFileConfig>) listFiles ).clone( ) );
76 }
77 else
78 {
79 _listFiles = null;
80 }
81 }
82
83
84
85
86
87
88 @Override
89 public Map<String, String> generate( PluginModel pm, String generationSchemeName )
90 {
91 HashMap<String, String> map = new HashMap<>( );
92 String strFilesPath = ( isKotlin( ) ) ? PATH_KOTLIN : PATH_JAVA;
93
94 for ( Application application : pm.getApplications( ) )
95 {
96 Collection<BusinessClass> listBusinessClasses = ModelService.getBusinessClassesByApplication( pm, application.getId( ) );
97
98 if ( listBusinessClasses.isEmpty( ) )
99 {
100 for ( XPageFileConfig file : _listFiles )
101 {
102 String strSuffix = SUFFIX_XPAGE + file.getSuffix( ) + ( isKotlin( ) ? SUFFIX_KOTLIN_EXTENSION : SUFFIX_JAVA_EXTENSION );
103 String strFilename = application.getApplicationClass( ) + strSuffix;
104 String strPath = getFilePath( pm, file.getSourcePath( ) + ( isKotlin( ) ? PATH_KOTLIN : PATH_JAVA ), strFilename );
105 String strSourceCode = getXPageCode( pm, application.getApplicationName( ), application.getId( ), application,
106 pm.getPluginNameAsRadicalPackage( ), file.getTemplate( ) );
107 map.put( strPath, strSourceCode );
108 }
109 }
110 else
111 {
112 for ( BusinessClass businessClass : listBusinessClasses )
113 {
114 for ( XPageFileConfig file : _listFiles )
115 {
116 String strSuffix = SUFFIX_XPAGE_CLASS + file.getSuffix( ) + ( isKotlin( ) ? SUFFIX_KOTLIN_EXTENSION : SUFFIX_JAVA_EXTENSION );
117 String strFilename = businessClass.getBusinessClassCapsFirst( ) + strSuffix;
118 String strPath = getFilePath( pm, file.getSourcePath( ) + ( isKotlin( ) ? PATH_KOTLIN : PATH_JAVA ), strFilename );
119 String strSourceCode = getXPageCode( pm, application.getApplicationName( ), application.getId( ), application, businessClass,
120 pm.getPluginNameAsRadicalPackage( ), file.getTemplate( ) );
121 map.put( strPath, strSourceCode );
122 }
123 }
124 }
125 }
126
127 return map;
128 }
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145 private String getXPageCode( PluginModel pm, String strApplicationName, int nApplicationId, Application application, BusinessClass businessClass,
146 String strRadicalPackage, String strTemplate )
147 {
148 Map<String, Object> model = getModel( pm );
149 model.put( Markers.MARK_PLUGIN, pm );
150 model.put( Markers.MARK_PLUGIN_APPLICATION, ModelService.getApplication( pm, nApplicationId ) );
151 model.put( Markers.MARK_APPLICATION, application );
152 model.put( Markers.MARK_APPLICATION_NAME, strApplicationName );
153 model.put( Markers.MARK_BUSINESS_CLASS, businessClass );
154 model.put( Markers.MARK_RADICAL_PACKAGE, strRadicalPackage );
155
156 return build( strTemplate, model );
157 }
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172 private String getXPageCode( PluginModel pm, String strApplicationName, int nApplicationId, Application application, String strRadicalPackage,
173 String strTemplate )
174 {
175 Map<String, Object> model = getModel( pm );
176 model.put( Markers.MARK_PLUGIN, pm );
177 model.put( Markers.MARK_PLUGIN_APPLICATION, ModelService.getApplication( pm, nApplicationId ) );
178 model.put( Markers.MARK_APPLICATION, application );
179 model.put( Markers.MARK_APPLICATION_NAME, strApplicationName );
180 model.put( Markers.MARK_RADICAL_PACKAGE, strRadicalPackage );
181
182 return build( strTemplate, model );
183 }
184 }