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.ArrayList;
45 import java.util.HashMap;
46 import java.util.List;
47 import java.util.Map;
48
49 import javax.servlet.http.HttpServletRequest;
50
51
52
53
54
55 public class DbPageSectionTable extends DbPageSection
56 {
57 private static final long serialVersionUID = 3589380186475889829L;
58 private static final String MARK_RESULT_DATASET = "result_dataset";
59 private static final String MARK_SECTION_TITLE = "section_title";
60 private static final String MARK_COLUMN_NAMES = "column_names";
61 private static final String PROPERTY_FILES_PATH = "dbpage.files.path";
62 private static final String TEMPLATE_DEFAULT_TABLE = "skin/plugins/dbpage/default_table.html";
63 private static final String TEMPLATE_CREATION_TABLE = "admin/plugins/dbpage/create_section_table.html";
64 private static final String TEMPLATE_MODIFICATION_TABLE = "admin/plugins/dbpage/modify_section_table.html";
65
66
67
68
69
70 public DbPageSectionTable( String strDescType )
71 {
72 this.setIdTypeSignature( serialVersionUID );
73 this.setDescType( strDescType );
74 }
75
76
77
78
79
80
81
82 public String getHtmlSection( List listValues, HttpServletRequest request )
83 {
84 HashMap rootModel = new HashMap( );
85
86 rootModel.put( MARK_SECTION_TITLE, getTitle( ) );
87 rootModel.put( MARK_COLUMN_NAMES, getTableHeader( ) );
88 rootModel.put( MARK_RESULT_DATASET, getTableDataset( getValuatedQuery( listValues ) ) );
89
90 if ( getTemplatePath( ).equals( "" ) )
91 {
92 HtmlTemplate tTable = AppTemplateService.getTemplate( TEMPLATE_DEFAULT_TABLE, request.getLocale( ),
93 rootModel );
94
95 return tTable.getHtml( );
96 }
97 else
98 {
99 String strFilePath = AppPropertiesService.getProperty( PROPERTY_FILES_PATH );
100 HtmlTemplate tSelect = AppTemplateService.getTemplate( getTemplatePath( ), strFilePath,
101 ( request == null ) ? null : request.getLocale( ), rootModel );
102
103 return tSelect.getHtml( );
104 }
105 }
106
107
108
109
110
111 private List<String> getTableHeader( )
112 {
113 List<String> listColumnNames = new ArrayList<String>( );
114
115 for ( String strColumnName : getColumnNames( ) )
116 {
117 listColumnNames.add( strColumnName );
118 }
119
120 return listColumnNames;
121 }
122
123
124
125
126
127
128 private List<List<String>> getTableDataset( String strRequest )
129 {
130 List<List<String>> listDataset = null;
131
132 try
133 {
134 listDataset = DbPageHome.selectRows( strRequest, getConnectionService( getDbPool( ) ) );
135 }
136 catch ( SQLException e )
137 {
138 AppLogService.error( e );
139 }
140
141 return listDataset;
142 }
143
144
145
146
147
148 public long getIdType( )
149 {
150 return getIdTypeSignature( );
151 }
152
153
154
155
156
157 public String getTypeDescription( )
158 {
159 return getDescType( );
160 }
161
162
163
164
165
166 public String getCreationTemplate( )
167 {
168 return TEMPLATE_CREATION_TABLE;
169 }
170
171
172
173
174
175 public String getModificationTemplate( )
176 {
177 return TEMPLATE_MODIFICATION_TABLE;
178 }
179
180
181
182
183 public Map<String, Object> getMarkMap( )
184 {
185 Map map = new HashMap( );
186
187 return map;
188 }
189 }