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.dbpage.business.section;
35
36 import fr.paris.lutece.plugins.dbpage.business.DbPageHome;
37 import fr.paris.lutece.portal.service.template.AppTemplateService;
38 import fr.paris.lutece.portal.service.util.AppLogService;
39 import fr.paris.lutece.portal.service.util.AppPropertiesService;
40 import fr.paris.lutece.util.html.HtmlTemplate;
41
42 import java.sql.SQLException;
43
44 import java.util.Collection;
45 import java.util.HashMap;
46 import java.util.Iterator;
47 import java.util.List;
48 import java.util.Map;
49
50 import javax.servlet.http.HttpServletRequest;
51
52
53
54
55
56 public class DbPageSectionForm extends DbPageSection
57 {
58 private static final long serialVersionUID = 2087550201069955806L;
59 private static final String PROPERTY_ERROR_MESSAGE = "dbpage.section.properties.message.error";
60 private static final String MARK_SECTION_TITLE = "section_title";
61 private static final String MARK_SECTION_CONTENT = "section_content";
62 private static final String PROPERTY_FILES_PATH = "dbpage.files.path";
63 private static final String TEMPLATE_DEFAULT_FORM = "skin/plugins/dbpage/default_form.html";
64 private static final String TEMPLATE_CREATION_FORM = "admin/plugins/dbpage/create_section_form.html";
65 private static final String TEMPLATE_MODIFICATION_FORM = "admin/plugins/dbpage/modify_section_form.html";
66
67
68
69
70
71 public DbPageSectionForm( String strDescType )
72 {
73 this.setIdTypeSignature( serialVersionUID );
74 this.setDescType( strDescType );
75 }
76
77
78
79
80
81
82
83 public String getHtmlSection( List listValues, HttpServletRequest request )
84 {
85 HashMap<String, Object> rootModel = new HashMap<String, Object>( );
86
87 rootModel.put( MARK_SECTION_TITLE, getTitle( ) );
88
89 if ( getTemplatePath( ).equals( "" ) )
90 {
91 HtmlTemplate tForm = AppTemplateService.getTemplate( TEMPLATE_DEFAULT_FORM, request.getLocale( ), rootModel );
92 rootModel.put( MARK_SECTION_CONTENT, buildForm( tForm, listValues ) );
93
94 return tForm.getHtml( );
95 }
96 else
97 {
98 String strFilePath = AppPropertiesService.getProperty( PROPERTY_FILES_PATH );
99 HtmlTemplate tForm = AppTemplateService.getTemplate( getTemplatePath( ), strFilePath,
100 ( request == null ) ? null : request.getLocale( ), rootModel );
101 rootModel.put( MARK_SECTION_CONTENT, buildForm( tForm, listValues ) );
102
103 return tForm.getHtml( );
104 }
105 }
106
107
108
109
110
111
112
113 public String buildForm( HtmlTemplate template, List listValues )
114 {
115 String strQuery = getValuatedQuery( listValues );
116
117 if ( ( strQuery != null ) && !strQuery.equals( "" ) )
118 {
119
120
121 try
122 {
123 List<List<String>> listRows = DbPageHome.selectRows( strQuery, getConnectionService( getDbPool( ) ) );
124
125 if ( ( listRows != null ) && !listRows.isEmpty( ) )
126 {
127
128 List<String> formRow = listRows.get( 0 );
129
130 int nIndex = 0;
131 for( String strColumnName : getColumnNames( ) )
132 {
133 if( nIndex < formRow.size() )
134 {
135 String strElement = (String) formRow.get( nIndex++ );
136 String strBookmark = "@" + strColumnName + "@";
137 template.substitute( strBookmark, strElement );
138 }
139 }
140
141 return template.getHtml( );
142 }
143 else
144 {
145 return AppPropertiesService.getProperty( PROPERTY_ERROR_MESSAGE );
146 }
147 }
148 catch ( SQLException e )
149 {
150 AppLogService.error( e );
151
152 return AppPropertiesService.getProperty( PROPERTY_ERROR_MESSAGE );
153 }
154 }
155 else
156 {
157 return template.getHtml( );
158 }
159 }
160
161
162
163
164
165 public long getIdType( )
166 {
167 return getIdTypeSignature( );
168 }
169
170
171
172
173
174 public String getTypeDescription( )
175 {
176 return getDescType( );
177 }
178
179
180
181
182
183 public String getCreationTemplate( )
184 {
185 return TEMPLATE_CREATION_FORM;
186 }
187
188
189
190
191
192 public String getModificationTemplate( )
193 {
194 return TEMPLATE_MODIFICATION_FORM;
195 }
196
197
198
199
200 public Map<String, Object> getMarkMap( )
201 {
202 Map map = new HashMap( );
203
204 return map;
205 }
206 }