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.portal.web.documentation;
35
36 import fr.paris.lutece.portal.business.right.FeatureGroup;
37 import fr.paris.lutece.portal.business.right.FeatureGroupHome;
38 import fr.paris.lutece.portal.business.right.Right;
39 import fr.paris.lutece.portal.business.user.AdminUser;
40 import fr.paris.lutece.portal.service.admin.AccessDeniedException;
41 import fr.paris.lutece.portal.service.admin.AdminUserService;
42 import fr.paris.lutece.portal.service.html.XmlTransformerService;
43 import fr.paris.lutece.portal.service.message.AdminMessage;
44 import fr.paris.lutece.portal.service.message.AdminMessageService;
45 import fr.paris.lutece.portal.service.template.AppTemplateService;
46 import fr.paris.lutece.portal.service.util.AppLogService;
47 import fr.paris.lutece.portal.service.util.AppPathService;
48 import fr.paris.lutece.util.html.HtmlTemplate;
49
50 import java.io.File;
51
52 import java.util.ArrayList;
53 import java.util.Collection;
54 import java.util.HashMap;
55 import java.util.List;
56 import java.util.Locale;
57 import java.util.Map;
58
59 import javax.servlet.http.HttpServletRequest;
60
61 import javax.xml.transform.stream.StreamSource;
62
63
64
65
66
67
68
69 public class AdminDocumentationJspBean
70 {
71
72 private static final String XSL_PATH = "admin_documentation.xsl";
73
74
75 private static final String PARAMS_LOCAL = "locale";
76 private static final String PARAMS_DEFAULT_LOCAL = "default_locale";
77
78
79 private static final String PARAMETER_FEATURE_DOC = "doc";
80
81
82 private static final String JSP_CLOSE = "javascript:window.close()";
83
84
85 private static final String TEMPLATE_ADMIN_SUMMARY_DOCUMENTATION = "admin/documentation/admin_summary_documentation.html";
86
87
88 private static final String BOOKMARK_FEATURE_GROUP_LIST = "feature_group_list";
89 private static final String BOOKMARK_HELP_ICON = "help_icon";
90
91
92 private static final String IMAGE_HELP_PATH = "images/admin/skin/features/admin_help.png";
93
94
95 private static final String PROPERTY_XSL_BASE_PATH = "lutece.documentation.xsl.path";
96 private static final String ADMIN_DOCUMENTATION_XSL_UNIQUE_PREFIX = "adminDocumentation-";
97
98
99 private static final String MESSAGE_ERROR = "portal.features.documentation.message.error";
100
101
102 private static final String LOCAL_DEFAULT = "en";
103 private static final String XML_BASE_PATH = "/doc/xml/";
104 private static final String XML_USER_PATH = "/xdoc/user/";
105 private static final String FEATURES_GROUP_SYSTEM = "SYSTEM";
106
107
108
109
110
111
112
113
114 public String getDocumentation( HttpServletRequest request )
115 throws AccessDeniedException
116 {
117 String strFeature = request.getParameter( PARAMETER_FEATURE_DOC );
118
119 AdminUser user = AdminUserService.getAdminUser( request );
120 Locale locale = user.getLocale( );
121
122
123 String strXslPath = AppPathService.getPath( PROPERTY_XSL_BASE_PATH, XSL_PATH );
124 File fileXsl = new File( strXslPath );
125 StreamSource sourceStyleSheet = new StreamSource( fileXsl );
126
127
128 String strXmlPath;
129 StreamSource sourceXml;
130 String strLocal = locale.toString( );
131
132 if ( ( locale == null ) || strLocal.equals( LOCAL_DEFAULT ) )
133 {
134 strXmlPath = AppPathService.getWebAppPath( ) + XML_BASE_PATH + XML_USER_PATH + strFeature + ".xml";
135 }
136 else
137 {
138 strXmlPath = AppPathService.getWebAppPath( ) + XML_BASE_PATH + locale.toString( ) + XML_USER_PATH +
139 strFeature + ".xml";
140 }
141
142 sourceXml = new StreamSource( new File( strXmlPath ) );
143
144 String strHtmlDoc = null;
145
146 Map<String, String> params = new HashMap<String, String>( );
147 params.put( PARAMS_LOCAL, locale.toString( ) );
148 params.put( PARAMS_DEFAULT_LOCAL, LOCAL_DEFAULT );
149
150 XmlTransformerService xmlTransformerService = new XmlTransformerService( );
151 String strUniqueId = ADMIN_DOCUMENTATION_XSL_UNIQUE_PREFIX + strXmlPath;
152
153 try
154 {
155 strHtmlDoc = xmlTransformerService.transformBySourceWithXslCache( sourceXml, sourceStyleSheet, strUniqueId,
156 params, null );
157 }
158 catch ( Exception e )
159 {
160 AppLogService.error( "Can't parse XML: " + e.getMessage( ), e );
161
162 return null;
163 }
164
165 return strHtmlDoc;
166 }
167
168
169
170
171
172
173
174 public String doAdminMessage( HttpServletRequest request )
175 {
176 return AdminMessageService.getMessageUrl( request, MESSAGE_ERROR, JSP_CLOSE, AdminMessage.TYPE_ERROR );
177 }
178
179
180
181
182
183
184
185 public String getSummaryDocumentation( HttpServletRequest request )
186 {
187 AdminUser user = AdminUserService.getAdminUser( request );
188
189 List<FeatureGroup> listFeatureGroups = getFeatureGroupsList( user );
190 Map<String, Object> model = new HashMap<String, Object>( );
191
192 model.put( BOOKMARK_FEATURE_GROUP_LIST, listFeatureGroups );
193 model.put( BOOKMARK_HELP_ICON, IMAGE_HELP_PATH );
194
195 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_ADMIN_SUMMARY_DOCUMENTATION,
196 user.getLocale( ), model );
197
198 return template.getHtml( );
199 }
200
201
202
203
204
205
206
207 private List<FeatureGroup> getFeatureGroupsList( AdminUser user )
208 {
209
210 ArrayList<FeatureGroup> aOutFeatureGroupList = new ArrayList<FeatureGroup>( );
211
212
213 Map<String, Right> featuresMap = user.getRights( );
214 Collection<Right> features = featuresMap.values( );
215
216
217 for ( FeatureGroup featureGroup : FeatureGroupHome.getFeatureGroupsList( ) )
218 {
219 ArrayList<Right> aLeftFeatures = new ArrayList<Right>( );
220
221 for ( Right right : features )
222 {
223 right.setLocale( user.getLocale( ) );
224
225 String strFeatureGroup = right.getFeatureGroup( );
226 String strUrlDocumentation = right.getDocumentationUrl( );
227
228 if ( featureGroup.getId( ).equalsIgnoreCase( strFeatureGroup ) && ( strUrlDocumentation != null ) &&
229 !( strUrlDocumentation.equals( "" ) ) )
230 {
231 featureGroup.addFeature( right );
232 }
233 else if ( ( strUrlDocumentation != null ) && !( strUrlDocumentation.equals( "" ) ) )
234 {
235 aLeftFeatures.add( right );
236 }
237 }
238
239 if ( !featureGroup.isEmpty( ) )
240 {
241 featureGroup.setLocale( user.getLocale( ) );
242 aOutFeatureGroupList.add( featureGroup );
243 }
244
245 features = aLeftFeatures;
246 }
247
248 FeatureGroup featureGroupSystem = FeatureGroupHome.findByPrimaryKey( FEATURES_GROUP_SYSTEM );
249
250 if ( ( featureGroupSystem != null ) && !features.isEmpty( ) )
251 {
252 boolean bSystemFeaturesGroupExist = false;
253
254
255 for ( FeatureGroup featureGroup : aOutFeatureGroupList )
256 {
257
258 if ( featureGroup.getId( ).equalsIgnoreCase( featureGroupSystem.getId( ) ) )
259 {
260
261 for ( Right right : features )
262 {
263 featureGroup.addFeature( right );
264 }
265
266 bSystemFeaturesGroupExist = true;
267
268 break;
269 }
270 }
271
272
273 if ( !bSystemFeaturesGroupExist )
274 {
275 for ( Right right : features )
276 {
277 featureGroupSystem.addFeature( right );
278 }
279
280 featureGroupSystem.setLocale( user.getLocale( ) );
281 aOutFeatureGroupList.add( featureGroupSystem );
282 }
283 }
284 else if ( ( aOutFeatureGroupList.size( ) > 0 ) && !features.isEmpty( ) )
285 {
286 FeatureGroup lastFeatureGroup = aOutFeatureGroupList.get( aOutFeatureGroupList.size( ) - 1 );
287
288 for ( Right right : features )
289 {
290 lastFeatureGroup.addFeature( right );
291 }
292 }
293
294 return aOutFeatureGroupList;
295 }
296 }