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.repository.modify.remove;
07:
08: import javax.servlet.http.HttpServletRequest;
09: import javax.servlet.http.HttpServletResponse;
10:
11: import org.slf4j.Logger;
12: import org.slf4j.LoggerFactory;
13: import org.springframework.validation.BindException;
14: import org.springframework.web.servlet.ModelAndView;
15: import org.springframework.web.servlet.mvc.SimpleFormController;
16:
17: import org.openrdf.http.webclient.SessionKeys;
18: import org.openrdf.repository.RepositoryConnection;
19: import org.openrdf.repository.RepositoryException;
20: import org.openrdf.repository.http.HTTPRepository;
21:
22: /**
23: * @author Herko ter Horst
24: */
25: public class ClearController extends SimpleFormController {
26:
27: final Logger logger = LoggerFactory.getLogger(this .getClass());
28:
29: @Override
30: protected ModelAndView onSubmit(HttpServletRequest request,
31: HttpServletResponse response, Object command,
32: BindException errors) {
33: logger.info("Clearing data...");
34: String actionResult = "repository.modify.remove.clear.success";
35:
36: RemovalSpecification toRemove = (RemovalSpecification) command;
37:
38: HTTPRepository repo = (HTTPRepository) request.getSession()
39: .getAttribute(SessionKeys.REPOSITORY_KEY);
40: RepositoryConnection conn = null;
41: try {
42: conn = repo.getConnection();
43: conn.clear(toRemove.getContexts());
44: conn.commit();
45: logger.info("Clear committed.");
46: } catch (RepositoryException e) {
47: logger.warn("Unable to clear repository", e);
48: actionResult = "repository.modify.remove.clear.failure";
49: } finally {
50: if (conn != null) {
51: try {
52: conn.close();
53: } catch (RepositoryException e) {
54: e.printStackTrace();
55: }
56: }
57: }
58:
59: return new ModelAndView(getSuccessView(), "actionResult",
60: actionResult);
61: }
62: }
|