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.Configuration;
38 import fr.paris.lutece.plugins.pluginwizard.business.model.PluginModel;
39
40 import java.util.ArrayList;
41 import java.util.HashMap;
42 import java.util.List;
43 import java.util.Map;
44
45 import org.apache.commons.lang3.StringUtils;
46
47
48
49
50 public class TaskFormsGenerator extends AbstractGenerator
51 {
52 private static final String PATH = "webapp/WEB-INF/templates/admin/plugins/workflow/modules/{plugin_name}/";
53 private static final String EXT_HTML = ".html";
54 private List<String> _suffix;
55
56
57
58
59
60 private void setSuffixList( PluginModel pluginModel )
61 {
62 _suffix = new ArrayList<>( );
63 _suffix.add( "_information" );
64
65 if( StringUtils.equals( pluginModel.getConfiguration( ).getWorkflowFormConfigRequired( ), "1" ) )
66 {
67 _suffix.add( "_config" );
68 }
69
70 if( StringUtils.equals( pluginModel.getConfiguration( ).getWorkflowFormTaskRequired( ), "1" ) )
71 {
72 _suffix.add( "_form" );
73 }
74 }
75
76
77
78
79
80 @Override
81 public Map<String, String> generate( PluginModel pluginModel, String generationSchemeName )
82 {
83
84 setSuffixList( pluginModel );
85
86 HashMap map = new HashMap( );
87 String strTaskName = pluginModel.getConfiguration( ).getWorkflowTaskName( ).toLowerCase( );
88 if( strTaskName.length( ) > 4 )
89 {
90 strTaskName = strTaskName.substring( 0, strTaskName.length( ) - 4 );
91 }
92
93 for ( String strSuffix : _suffix )
94 {
95 String strFormFile = "task_" + strTaskName + strSuffix + EXT_HTML;
96 String strPath = getFilePath( pluginModel, PATH, strFormFile );
97 String strTemplateType = strSuffix.startsWith("_") ? strSuffix.substring( 1 ) : strSuffix;
98
99 String strSourceCode = getFormFile( pluginModel.getConfiguration( ), pluginModel.getBusinessClasses( ).get( 0 ), strTemplateType, pluginModel.getPluginName( ), this.getTemplate( ) );
100 strSourceCode = strSourceCode.replace( "<", "<" );
101 strSourceCode = strSourceCode.replace( ">", ">" );
102
103 map.put( strPath, strSourceCode.replace( "@@", "#" ) );
104 }
105
106 return map;
107 }
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124 private String getFormFile( Configuration configuration, BusinessClass businessClass, String strTemplateType, String strPluginName, String strTemplate )
125 {
126 Map<String, Object> model = new HashMap<>( );
127
128 model.put( Markers.MARK_CONFIGURATION, configuration );
129 model.put( Markers.MARK_BUSINESS_CLASS, businessClass );
130 model.put( Markers.MARK_TASK_NAME, configuration.getWorkflowTaskName( ) );
131 model.put( Markers.MARK_TEMPLATE_TYPE, strTemplateType );
132 model.put( Markers.MARK_PLUGIN_NAME, strPluginName );
133
134 model.put( Markers.MARK_I18N_BRACKETS_OPEN, "@@i18n{" );
135 model.put( Markers.MARK_I18N_BRACKETS_CLOSE, "}" );
136 model.put( Markers.MARK_MACRO, "@" );
137 model.put( Markers.MARK_VARIABLE, "#" );
138 model.put( Markers.MARK_BRACKETS_OPEN, "${" );
139 model.put( Markers.MARK_BRACKETS_CLOSE, "}" );
140 model.put( Markers.MARK_INCLUDE, "@@include" );
141
142 return build( strTemplate, model );
143 }
144 }