Clover coverage report -
Coverage timestamp: Sun Nov 1 2009 23:08:24 UTC
file stats: LOC: 105   Methods: 1
NCLOC: 60   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
Delete.java 71.4% 69% 100% 70.5%
coverage coverage
 1    /*
 2    * Licensed to the Apache Software Foundation (ASF) under one or more
 3    * contributor license agreements. See the NOTICE file distributed with
 4    * this work for additional information regarding copyright ownership.
 5    * The ASF licenses this file to You under the Apache License, Version 2.0
 6    * (the "License"); you may not use this file except in compliance with
 7    * the License. You may obtain a copy of the License at
 8    *
 9    * http://www.apache.org/licenses/LICENSE-2.0
 10    *
 11    * Unless required by applicable law or agreed to in writing, software
 12    * distributed under the License is distributed on an "AS IS" BASIS,
 13    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14    * See the License for the specific language governing permissions and
 15    * limitations under the License.
 16    *
 17    * $Id: Delete.java 541515 2007-05-25 02:45:06Z vgritsenko $
 18    */
 19   
 20    package org.apache.xindice.webadmin.webdav.components;
 21   
 22    import java.io.IOException;
 23   
 24    import javax.servlet.ServletException;
 25   
 26    import org.apache.xindice.core.Collection;
 27    import org.apache.xindice.core.DBException;
 28    import org.apache.xindice.core.FaultCodes;
 29    import org.apache.xindice.core.Database;
 30    import org.apache.xindice.webadmin.webdav.WebdavStatus;
 31    import org.apache.xindice.webadmin.webdav.DAVResponse;
 32    import org.apache.xindice.webadmin.webdav.DAVRequest;
 33    import org.apache.xindice.webadmin.Location;
 34    import org.apache.commons.logging.Log;
 35    import org.apache.commons.logging.LogFactory;
 36   
 37    /**
 38    * This class implements the Delete command for WebDAV operations on
 39    * Xindice.<br>
 40    * <br>
 41    * DELETE command deletes target collection or resource. For collections,
 42    * it deletes the entire subtree, so Depth header in request cannot be
 43    * 0 or 1, but it can be omitted.<br>
 44    * <br>
 45    * The default success status code is 204 (No Content)
 46    *
 47    * @author <a href="mailto:jmetzner@apache.org">Jan Metzner</a>
 48    * @author <a href="mailto:gianugo@apache.org">Gianugo Rabellino</a>
 49    * @version $Revision: 541515 $, $Date: 2007-05-24 19:45:06 -0700 (Thu, 24 May 2007) $
 50    */
 51    public class Delete implements DAVComponent {
 52    private final Log log = LogFactory.getLog(Delete.class);
 53   
 54  5 public void execute(DAVRequest req, DAVResponse res, Location target) throws ServletException, IOException {
 55  5 if (target.isRoot()) {
 56  0 res.setStatus(WebdavStatus.SC_FORBIDDEN);
 57  0 return;
 58    }
 59   
 60  5 Collection col = target.getCollection();
 61  5 String name = target.getName();
 62   
 63  5 if (col == null) {
 64  1 res.setStatus(WebdavStatus.SC_NOT_FOUND);
 65  1 return;
 66    }
 67   
 68  4 if (col instanceof Database) {
 69  0 res.setStatus(WebdavStatus.SC_FORBIDDEN);
 70  0 return;
 71    }
 72   
 73  4 if (req.getDepth() != DAVRequest.DEPTH_INFINITY) {
 74  1 res.setStatus(WebdavStatus.SC_BAD_REQUEST);
 75  1 return;
 76    }
 77   
 78    // TODO: set SC_FORBIDDEN for system collections
 79  3 if (name == null) { // deleting collection
 80  1 try {
 81  1 col.getDatabase().dropCollection(col);
 82    } catch (DBException e) {
 83  0 log.error("Failed to delete collection " + col.getCanonicalName(), e);
 84  0 throw new ServletException(e);
 85    }
 86    } else { // deleting resource
 87  2 try {
 88  2 col.remove(name);
 89  1 if (log.isDebugEnabled()) {
 90  0 log.debug("entry " + name + " deleted");
 91    }
 92    } catch (DBException e) {
 93  1 if (e.faultCode == FaultCodes.COL_DOCUMENT_NOT_FOUND) {
 94  1 res.setStatus(WebdavStatus.SC_NOT_FOUND);
 95  1 return;
 96    } else {
 97  0 log.error("Failed to delete resource " + name + " from collection " + col.getCanonicalName(), e);
 98  0 throw new ServletException(e);
 99    }
 100    }
 101    }
 102   
 103  2 res.setStatus(WebdavStatus.SC_NO_CONTENT);
 104    }
 105    }