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