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;
35
36 import fr.paris.lutece.plugins.dbpage.business.section.DbPageSection;
37 import fr.paris.lutece.portal.business.page.Page;
38 import fr.paris.lutece.portal.service.resource.Resource;
39 import fr.paris.lutece.portal.service.security.SecurityService;
40 import fr.paris.lutece.portal.service.workgroup.AdminWorkgroupResource;
41 import fr.paris.lutece.portal.service.workgroup.WorkgroupRemovalListenerService;
42
43 import java.util.List;
44
45 import javax.servlet.http.HttpServletRequest;
46
47
48
49
50
51 public class DbPage implements Resource, AdminWorkgroupResource
52 {
53 public static final String RESOURCE_TYPE = "DBPAGE";
54 private static final String EMPTY_STRING = "";
55 private static DbPageWorkgroupRemovalListener _listenerWorkgroup;
56
57
58
59 private int _nNbSection;
60 private String _strName;
61 private String _strTitle;
62 private String _strWorkgroup;
63 private List<DbPageSection> _listSections;
64
65
66
67
68 public static void init( )
69 {
70
71 if ( _listenerWorkgroup == null )
72 {
73 _listenerWorkgroup = new DbPageWorkgroupRemovalListener( );
74 WorkgroupRemovalListenerService.getService( ).registerListener( _listenerWorkgroup );
75 }
76 }
77
78
79
80
81
82
83 public int getNbSection( )
84 {
85 return _nNbSection;
86 }
87
88
89
90
91
92
93 public void setNbSection( int nNbSection )
94 {
95 _nNbSection = nNbSection;
96 }
97
98
99
100
101
102
103 public String getName( )
104 {
105 return _strName;
106 }
107
108
109
110
111
112
113 public void setName( String strName )
114 {
115 _strName = ( strName == null ) ? EMPTY_STRING : strName;
116 }
117
118
119
120
121
122
123 public String getTitle( )
124 {
125 return _strTitle;
126 }
127
128
129
130
131
132
133 public void setTitle( String strTitle )
134 {
135 _strTitle = ( strTitle == null ) ? EMPTY_STRING : strTitle;
136 }
137
138
139
140
141
142
143 public List<DbPageSection> getListSection( )
144 {
145 return _listSections;
146 }
147
148
149
150
151
152 public void setListSection( List<DbPageSection> listSections )
153 {
154 _listSections = listSections;
155 }
156
157
158
159
160
161 public String getWorkgroup( )
162 {
163 return _strWorkgroup;
164 }
165
166
167
168
169
170 public void setWorkgroup( String strWorkgroup )
171 {
172 _strWorkgroup = ( strWorkgroup == null ) ? EMPTY_STRING : strWorkgroup;
173 }
174
175
176
177
178
179
180
181 public String getContent( List<String> listValues, HttpServletRequest request )
182 {
183 StringBuffer sbSections = new StringBuffer( );
184
185 for ( DbPageSection section : _listSections )
186 {
187 if ( isVisible( request, section.getRole( ) ) )
188 {
189 sbSections.append( section.getHtmlSection( listValues, request ) );
190 }
191 }
192
193 return sbSections.toString( );
194 }
195
196
197
198
199
200
201
202
203 private boolean isVisible( HttpServletRequest request, String strRole )
204 {
205 if ( ( strRole == null ) || strRole.trim( ).equals( EMPTY_STRING ) )
206 {
207 return true;
208 }
209
210 if ( !strRole.equals( Page.ROLE_NONE ) && SecurityService.isAuthenticationEnable( ) )
211 {
212 return SecurityService.getInstance( ).isUserInRole( request, strRole );
213 }
214
215 return true;
216 }
217
218
219
220
221
222
223
224 public boolean isVisible( HttpServletRequest request )
225 {
226 return isVisible( request, getWorkgroup( ) );
227 }
228 }