Clover coverage report -
Coverage timestamp: Sun Nov 1 2009 23:08:24 UTC
file stats: LOC: 93   Methods: 1
NCLOC: 55   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
Head.java 0% 0% 0% 0%
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: Head.java 712249 2008-11-07 20:08:48Z vgritsenko $
 18    */
 19   
 20    package org.apache.xindice.webadmin.webdav.components;
 21   
 22    import java.io.IOException;
 23   
 24    import javax.servlet.ServletException;
 25    import javax.servlet.http.HttpServletResponse;
 26   
 27    import org.apache.xindice.core.Collection;
 28    import org.apache.xindice.core.DBException;
 29    import org.apache.xindice.core.data.Entry;
 30    import org.apache.xindice.webadmin.util.MimeTable;
 31    import org.apache.xindice.webadmin.webdav.DAVRequest;
 32    import org.apache.xindice.webadmin.webdav.DAVResponse;
 33    import org.apache.xindice.webadmin.Location;
 34    import org.apache.xindice.xml.TextWriter;
 35    import org.apache.commons.logging.LogFactory;
 36    import org.apache.commons.logging.Log;
 37    import org.w3c.dom.Document;
 38   
 39    /**
 40    * This class implements the Head HTTP command for WebDAV operations on
 41    * Xindice.
 42    *
 43    * @author <a href="mailto:jmetzner@apache.org">Jan Metzner</a>
 44    * @author <a href="mailto:gianugo@apache.org">Gianugo Rabellino</a>
 45    * @version $Revision: 712249 $, $Date: 2008-11-07 20:08:48 +0000 (Fri, 07 Nov 2008) $
 46    */
 47    public class Head implements DAVComponent {
 48    private static final Log log = LogFactory.getLog(Head.class);
 49   
 50  0 public void execute(DAVRequest req, DAVResponse res, Location target) throws ServletException, IOException {
 51  0 Collection col = target.getCollection();
 52  0 String name = target.getName();
 53   
 54  0 if (target.isRoot() || (col != null && name == null)) {
 55  0 if (log.isDebugEnabled()) {
 56  0 log.debug("Method Head not allowed on collections!");
 57    }
 58  0 res.setStatus(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
 59  0 return;
 60    }
 61   
 62  0 if (col == null) {
 63  0 res.setStatus(HttpServletResponse.SC_NOT_FOUND);
 64  0 return;
 65    }
 66   
 67  0 try {
 68  0 Entry resource = col.getEntry(name);
 69   
 70  0 if (resource != null) {
 71  0 byte[] resultBytes;
 72  0 if (resource.getEntryType() == Entry.DOCUMENT) {
 73  0 resultBytes = TextWriter.toString((Document) resource.getValue()).getBytes();
 74  0 res.setContentType(MimeTable.XML_MIME_TYPE);
 75    } else {
 76  0 resultBytes = (byte[]) resource.getValue();
 77  0 res.setContentType(MimeTable.getMimeType(name));
 78    }
 79   
 80  0 if (resource.getModificationTime() != 0) {
 81  0 res.addDateHeader("Last-Modified", resource.getModificationTime());
 82    }
 83  0 res.setContentLength(resultBytes.length);
 84   
 85    } else {
 86  0 res.setStatus(HttpServletResponse.SC_NOT_FOUND);
 87    }
 88    } catch (DBException e) {
 89  0 log.error("Could not get resource " + name + " from collection " + col.getCanonicalName(), e);
 90  0 res.setStatus(HttpServletResponse.SC_NOT_FOUND);
 91    }
 92    }
 93    }