View Javadoc

1   /*
2    * Copyright 2008 Hippo
3    *
4    * Licensed under the Apache License, Version 2.0 (the  "License"); 
5    * you may not use this file except in compliance with the License. 
6    * You may obtain a copy of the License at
7    *
8    * http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" 
12   * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
13   * See the License for the specific language governing permissions and 
14   * limitations under the License.
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  }