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.PluginModel;
37 import fr.paris.lutece.plugins.pluginwizard.business.model.Portlet;
38 import fr.paris.lutece.portal.service.util.AppLogService;
39
40 import java.util.ArrayList;
41 import java.util.HashMap;
42 import java.util.List;
43 import java.util.Map;
44
45
46
47
48 public class PortletGenerator extends AbstractGenerator
49 {
50 private static final String PATH = "src/java/fr/paris/lutece/plugins/{plugin_name}/business/portlet/";
51 private static final String EXT_JAVA = ".java";
52 private List<BusinessFileConfig> _listFiles;
53
54
55
56
57
58
59
60 public void setFiles( List<BusinessFileConfig> listFiles )
61 {
62 if ( listFiles != null )
63 {
64 _listFiles = (List<BusinessFileConfig>) ( ( (ArrayList<BusinessFileConfig>) listFiles ).clone( ) );
65 }
66 else
67 {
68 _listFiles = null;
69 }
70 }
71
72
73
74
75 @Override
76 public Map generate( PluginModel pm, String generationSchemeName )
77 {
78 HashMap map = new HashMap( );
79 String strRadicalPackage = pm.getPluginNameAsRadicalPackage( );
80
81 for ( Portlet portlet : pm.getPortlets( ) )
82 {
83 for ( BusinessFileConfig file : _listFiles )
84 {
85 String strPortletFile = file.getPrefix( ) + portlet.getPortletClass( ) + file.getSuffix( ) + EXT_JAVA;
86
87 String strPath = getFilePath( pm, PATH, strPortletFile );
88
89 String strSourceCode = getPortletFile( portlet, pm.getPluginName( ), file.getTemplate( ), strRadicalPackage );
90 strSourceCode = strSourceCode.replace( "<", "<" );
91 strSourceCode = strSourceCode.replace( ">", ">" );
92 map.put( strPath, strSourceCode );
93 }
94 }
95
96 return map;
97 }
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112 private String getPortletFile( Portlet portlet, String strPluginName, String strTemplate, String strRadicalPackage )
113 {
114 Map<String, Object> model = new HashMap<>( );
115
116 model.put( Markers.MARK_PORTLET, portlet );
117 model.put( Markers.MARK_PLUGIN_NAME, strPluginName );
118 model.put( Markers.MARK_RADICAL_PACKAGE, strRadicalPackage );
119
120 AppLogService.info( portlet );
121
122 return build( strTemplate, model );
123 }
124 }