01: /*
02: * Copyright Aduna (http://www.aduna-software.com/) (c) 1997-2007.
03: *
04: * Licensed under the Aduna BSD-style license.
05: */
06: package org.openrdf.http.webclient;
07:
08: import javax.servlet.http.HttpServletRequest;
09: import javax.servlet.http.HttpServletResponse;
10: import javax.servlet.http.HttpSession;
11:
12: import org.springframework.web.servlet.HandlerInterceptor;
13: import org.springframework.web.servlet.ModelAndView;
14:
15: import info.aduna.webapp.navigation.NavigationModel;
16:
17: import org.openrdf.http.webclient.server.Server;
18: import org.openrdf.repository.manager.RepositoryInfo;
19:
20: /**
21: * @author Herko ter Horst
22: */
23: public class NavigationRulesHandlerInterceptor implements
24: HandlerInterceptor {
25:
26: public void afterCompletion(HttpServletRequest arg0,
27: HttpServletResponse arg1, Object arg2, Exception arg3)
28: throws Exception {
29: // nop
30: }
31:
32: public void postHandle(HttpServletRequest arg0,
33: HttpServletResponse arg1, Object arg2, ModelAndView arg3)
34: throws Exception {
35: // nop
36: }
37:
38: public boolean preHandle(HttpServletRequest request,
39: HttpServletResponse response, Object arg2) throws Exception {
40: HttpSession session = request.getSession(true);
41: NavigationModel navigationModel = (NavigationModel) session
42: .getAttribute(NavigationModel.NAVIGATION_MODEL_KEY);
43: Server server = (Server) session
44: .getAttribute(SessionKeys.SERVER_KEY);
45: RepositoryInfo repoInfo = (RepositoryInfo) session
46: .getAttribute(SessionKeys.REPOSITORY_INFO_KEY);
47:
48: navigationModel.getGroup("server").getView("overview")
49: .setEnabled(server != null);
50: navigationModel.getGroup("repository").setEnabled(
51: server != null && repoInfo != null);
52: navigationModel.getGroup("repository").getGroup("modify")
53: .setEnabled(repoInfo != null && repoInfo.isWritable());
54: navigationModel.getGroup("repository").getGroup("query")
55: .setEnabled(repoInfo != null && repoInfo.isReadable());
56: navigationModel.getGroup("repository").getGroup("explore")
57: .setEnabled(repoInfo != null && repoInfo.isReadable());
58: navigationModel.getGroup("repository").getGroup("extract")
59: .setEnabled(repoInfo != null && repoInfo.isReadable());
60:
61: return true;
62: }
63:
64: }
|