Clover coverage report -
Coverage timestamp: Sun Nov 1 2009 23:08:24 UTC
file stats: LOC: 131   Methods: 2
NCLOC: 89   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
DeleteCollectionViewer.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: DeleteCollectionViewer.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.DBException;
 30    import org.apache.xindice.core.Collection;
 31    import org.apache.xindice.webadmin.viewer.*;
 32    import org.apache.xindice.webadmin.viewer.HtmlViewerComponent;
 33    import org.apache.commons.logging.Log;
 34    import org.apache.commons.logging.LogFactory;
 35   
 36    /**
 37    * Xindice Html Viewer for deleting a collection.
 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 DeleteCollectionViewer extends HtmlViewerComponent implements HtmlCollectionViewer {
 43    private static final Log log = LogFactory.getLog(DeleteCollectionViewer.class);
 44   
 45  0 public void execute(HttpServletRequest req, HttpServletResponse res, Collection col) throws ServletException, IOException {
 46   
 47  0 String colName = col.getName();
 48  0 String path = col.getCanonicalName();
 49   
 50  0 String title = "Delete Collection " + colName;
 51   
 52  0 String action = req.getParameter("action");
 53  0 String redirect = req.getParameter("redirect");
 54  0 if (redirect == null) {
 55  0 redirect = "";
 56    }
 57  0 if (!"yes".equals(action)) {
 58  0 Writer output = startViewer(title, path, res);
 59  0 printStartTable(title, output);
 60  0 printStartSingleTableBox(output);
 61  0 output.write("Do you really want to delete the collection ");
 62  0 output.write(colName);
 63  0 output.write("? <a href=\"javascript:history.back()\">no</a> ");
 64  0 output.write(" <a href=\"?viewer=delete&action=yes&redirect=");
 65  0 output.write(redirect);
 66  0 output.write("\">yes</a>");
 67  0 printEndSingleTableBox(output);
 68  0 printEndTable(output);
 69  0 finishViewer(output);
 70    } else {
 71  0 try {
 72    // check if it is a database
 73  0 if (col.getParentCollection() == null) {
 74  0 Writer output = startViewer(title, path, res);
 75  0 title = "Error while deleting Collection!";
 76  0 printStartTable(title, output);
 77  0 printStartSingleTableBox(output);
 78  0 output.write("<b>Database cannot be deleted. Please manually change configuration files to delete or add a database.");
 79  0 output.write("</b><br />");
 80  0 printEndSingleTableBox(output);
 81  0 printEndTable(output);
 82  0 finishViewer(output);
 83  0 return;
 84    }
 85   
 86    // delete collection
 87  0 col.getParentCollection().dropCollection(col);
 88   
 89    // display output or redirect
 90  0 if (redirect.length() > 0) {
 91  0 res.sendRedirect(redirect);
 92    } else {
 93  0 Writer output = startViewer(title, path, res);
 94  0 printStartTable(title, output);
 95  0 printStartSingleTableBox(output);
 96  0 output.write("<a href=\"../?viewer=default\">up to parent collection</a>");
 97  0 printEndSingleTableBox(output);
 98  0 printStartSingleTableBox(output);
 99  0 output.write("<b>Collection ");
 100  0 output.write(colName);
 101  0 output.write(" deleted!</b>");
 102  0 printEndSingleTableBox(output);
 103  0 printEndTable(output);
 104  0 finishViewer(output);
 105    }
 106    } catch (DBException e) {
 107  0 log.error(e);
 108   
 109  0 Writer output = startViewer(title, path, res);
 110  0 printStartTable(title, output);
 111  0 printStartSingleTableBox(output);
 112  0 output.write("<a href=\"../../?viewer=default\">up to parent collection</a>");
 113  0 printEndSingleTableBox(output);
 114  0 printStartSingleTableBox(output);
 115  0 output.write("Cannot delete Collection");
 116  0 output.write(colName);
 117  0 output.write("! <br />");
 118  0 output.write(e.getMessage());
 119  0 printEndSingleTableBox(output);
 120  0 printEndTable(output);
 121  0 finishViewer(output);
 122    }
 123    }
 124   
 125    }
 126   
 127  0 protected String getName() {
 128  0 return "delete";
 129    }
 130   
 131    }