Clover coverage report -
Coverage timestamp: Sun Nov 1 2009 23:08:24 UTC
file stats: LOC: 119   Methods: 2
NCLOC: 80   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
DeleteResourceViewer.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: DeleteResourceViewer.java 711958 2008-11-06 20:12:54Z natalia $
 18    */
 19   
 20    package org.apache.xindice.webadmin.viewer.components;
 21   
 22    import java.io.IOException;
 23    import java.io.Writer;
 24   
 25    import javax.servlet.ServletException;
 26    import javax.servlet.http.HttpServletRequest;
 27    import javax.servlet.http.HttpServletResponse;
 28   
 29    import org.apache.xindice.core.Collection;
 30    import org.apache.xindice.core.DBException;
 31    import org.apache.xindice.webadmin.viewer.HtmlViewerComponent;
 32    import org.apache.xindice.webadmin.viewer.HtmlResourceViewer;
 33    import org.apache.commons.logging.LogFactory;
 34    import org.apache.commons.logging.Log;
 35   
 36    /**
 37    * Xindice Html Viewer for deleting resources.
 38    *
 39    * @author <a href="mailto:jmetzner@apache.org">Jan Metzner</a>
 40    * @version $Revision: 711958 $, $Date: 2008-11-06 20:12:54 +0000 (Thu, 06 Nov 2008) $
 41    */
 42    public class DeleteResourceViewer extends HtmlViewerComponent implements HtmlResourceViewer {
 43    private static final Log log = LogFactory.getLog(DeleteResourceViewer.class);
 44   
 45  0 public void execute(HttpServletRequest req, HttpServletResponse res, Collection col, String resourceName)
 46    throws ServletException, IOException {
 47   
 48  0 String path = col.getCanonicalName() + "/" + resourceName;
 49  0 String title = "Delete Document " + path;
 50   
 51  0 String action = req.getParameter("action");
 52  0 String redirect = req.getParameter("redirect");
 53  0 if (redirect == null) {
 54  0 redirect = "";
 55    }
 56   
 57  0 if (!"yes".equals(action)) { // ask confirmation
 58  0 Writer output = startViewer(title, path, res);
 59  0 printStartTable(title, output);
 60  0 printStartSingleTableBox(output);
 61  0 output.write("<a href=\"./?viewer=default\">up to parent collection</a>");
 62  0 printEndSingleTableBox(output);
 63  0 printStartSingleTableBox(output);
 64  0 output.write("Do you really want to delete ");
 65  0 output.write(resourceName);
 66  0 output.write("? <a href=\"javascript:history.back()\">no</a> ");
 67  0 output.write("<a href=\"?viewer=delete&action=yes&redirect=");
 68  0 output.write(redirect);
 69  0 output.write("\">yes</a>");
 70  0 printEndSingleTableBox(output);
 71  0 printEndTable(output);
 72  0 finishViewer(output);
 73    } else {
 74  0 try {
 75    // delete resource
 76  0 col.remove(resourceName);
 77   
 78    // display output or redirect
 79  0 if (redirect.length() > 0) {
 80  0 res.sendRedirect(redirect);
 81    } else {
 82  0 Writer output = startViewer(title, path, res);
 83  0 printStartTable(title, output);
 84  0 printStartSingleTableBox(output);
 85  0 output.write("<a href=\"./?viewer=default\">up to parent collection</a>");
 86  0 printEndSingleTableBox(output);
 87  0 printStartSingleTableBox(output);
 88  0 output.write("<b>Document ");
 89  0 output.write(resourceName);
 90  0 output.write(" deleted! </b>");
 91  0 printEndSingleTableBox(output);
 92  0 printEndTable(output);
 93  0 finishViewer(output);
 94    }
 95    } catch (DBException e) {
 96  0 log.error(e);
 97  0 Writer output = startViewer(title, path, res);
 98  0 printStartTable(title, output);
 99  0 printStartSingleTableBox(output);
 100  0 output.write("<a href=\"./?viewer=default\">up to parent collection</a>");
 101  0 printEndSingleTableBox(output);
 102  0 printStartSingleTableBox(output);
 103  0 output.write("<b>Cannot delete ");
 104  0 output.write(resourceName);
 105  0 output.write(": ");
 106  0 output.write(e.getMessage());
 107  0 printEndSingleTableBox(output);
 108  0 printEndTable(output);
 109  0 finishViewer(output);
 110    }
 111    }
 112   
 113    }
 114   
 115  0 protected String getName() {
 116  0 return "delete";
 117    }
 118   
 119    }