1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package nl.hippo.client.webapp.matchers;
17
18 import nl.hippo.client.api.ClientException;
19 import nl.hippo.client.webapp.RepositoryAdapter;
20 import nl.hippo.client.webapp.Request;
21 import nl.hippo.client.webapp.ServiceWrapper;
22 import nl.hippo.client.webapp.WebAppLogger;
23 import nl.hippo.client.webdav.WebdavResponse;
24
25
26 public class DeleteQueryMatcher extends Matcher {
27
28 public DeleteQueryMatcher() {
29 super("/deletequery/((.*$))");
30 }
31
32 public WebdavResponse execute(final Request request) throws ClientException {
33 return wrapExec(new MatcherCallback() {
34 public WebdavResponse doExec() throws ClientException {
35 WebAppLogger.log.debug("Executing GetQueryMatcher with parameters " + request.toString(regexp));
36 String[] parameters = request.getParameters(regexp);
37 ServiceWrapper service = (ServiceWrapper)request.getContext().getAttribute((RepositoryAdapter.QUERIES_WEBDAV));
38 WebdavResponse response = service.deleteQuery(parameters[1]);
39
40 StringBuffer result = new StringBuffer().append("<html><body>");
41 if (!response.isValid()) {
42 String msg = "Delete failed with status code " + response.getResponseCode();
43 WebAppLogger.log.error(msg);
44 result = result.append("<b>").append(msg).append("</b>");
45 } else {
46 result = result.append("Delete successful");
47 }
48 result = result.append("<br/><a href=\"").append(request.getContextPath()).append(
49 "/admin/\">Back to the admin page</a></body></html>");
50
51 return new WebdavResponse(result.toString().getBytes());
52 }
53 });
54 }
55
56 }