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.system;
35
36 import fr.paris.lutece.portal.service.cache.CacheService;
37 import fr.paris.lutece.portal.service.cache.CacheableService;
38 import fr.paris.lutece.portal.service.i18n.I18nService;
39 import fr.paris.lutece.portal.service.template.AppTemplateService;
40 import fr.paris.lutece.portal.service.util.AppPropertiesService;
41 import fr.paris.lutece.portal.web.admin.AdminFeaturesPageJspBean;
42 import fr.paris.lutece.util.html.HtmlTemplate;
43
44 import java.util.ArrayList;
45 import java.util.Collection;
46 import java.util.HashMap;
47 import java.util.List;
48
49 import javax.servlet.http.HttpServletRequest;
50
51
52
53
54
55 public class CacheJspBean extends AdminFeaturesPageJspBean
56 {
57
58 public static final String RIGHT_CACHE_MANAGEMENT = "CORE_CACHE_MANAGEMENT";
59
60
61 public static final String JSP_MANAGE_CACHES = "ManageCaches.jsp";
62 private static final long serialVersionUID = 7010476999488231065L;
63
64
65 private static final String MARK_SERVICES_LIST = "services_list";
66
67
68 private static final String TEMPLATE_MANAGE_CACHES = "admin/system/manage_caches.html";
69 private static final String TEMPLATE_CACHE_INFOS = "admin/system/cache_infos.html";
70 private static final String PARAMETER_ID_CACHE = "id_cache";
71
72
73
74
75
76
77 public String getManageCaches( HttpServletRequest request )
78 {
79 HashMap<String, Collection<CacheableService>> model = new HashMap<String, Collection<CacheableService>>( );
80 model.put( MARK_SERVICES_LIST, CacheService.getCacheableServicesList( ) );
81
82 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_MANAGE_CACHES, getLocale( ), model );
83
84 return getAdminPage( template.getHtml( ) );
85 }
86
87
88
89
90
91
92
93 public static String doResetCaches( HttpServletRequest request )
94 {
95 String strCacheIndex = request.getParameter( PARAMETER_ID_CACHE );
96
97 if ( strCacheIndex != null )
98 {
99 int nCacheIndex = Integer.parseInt( strCacheIndex );
100 CacheableService cs = CacheService.getCacheableServicesList( ).get( nCacheIndex );
101 cs.resetCache( );
102 }
103 else
104 {
105 CacheService.resetCaches( );
106 AppTemplateService.resetCache( );
107 I18nService.resetCache( );
108 }
109
110 return JSP_MANAGE_CACHES;
111 }
112
113
114
115
116
117
118 public String doReloadProperties( )
119 {
120 AppPropertiesService.reloadAll( );
121
122 return JSP_MANAGE_CACHES;
123 }
124
125
126
127
128
129
130 public String getCacheInfos( HttpServletRequest request )
131 {
132 List<CacheableService> list;
133 String strCacheIndex = request.getParameter( PARAMETER_ID_CACHE );
134
135 if ( strCacheIndex != null )
136 {
137 int nCacheIndex = Integer.parseInt( strCacheIndex );
138 CacheableService cs = CacheService.getCacheableServicesList( ).get( nCacheIndex );
139 list = new ArrayList<CacheableService>( );
140 list.add( cs );
141 }
142 else
143 {
144 list = CacheService.getCacheableServicesList( );
145 }
146
147 HashMap<String, Collection<CacheableService>> model = new HashMap<String, Collection<CacheableService>>( );
148 model.put( MARK_SERVICES_LIST, list );
149
150 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_CACHE_INFOS, getLocale( ), model );
151
152 return getAdminPage( template.getHtml( ) );
153 }
154
155
156
157
158
159
160
161 public static String doToggleCache( HttpServletRequest request )
162 {
163 String strCacheIndex = request.getParameter( PARAMETER_ID_CACHE );
164
165 if ( strCacheIndex != null )
166 {
167 int nCacheIndex = Integer.parseInt( strCacheIndex );
168 CacheableService cs = CacheService.getCacheableServicesList( ).get( nCacheIndex );
169 cs.enableCache( !cs.isCacheEnable( ) );
170 }
171
172 return JSP_MANAGE_CACHES;
173 }
174 }