Clover coverage report -
Coverage timestamp: Sun Nov 1 2009 23:08:24 UTC
file stats: LOC: 100   Methods: 7
NCLOC: 57   Classes: 2
 
 Source file Conditionals Statements Methods TOTAL
ListDatabaseViewer.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: ListDatabaseViewer.java 711958 2008-11-06 20:12:54Z natalia $
 18    */
 19   
 20    package org.apache.xindice.webadmin.viewer.components;
 21   
 22    import org.apache.xindice.webadmin.viewer.HtmlViewerComponent;
 23    import org.apache.xindice.webadmin.viewer.HtmlDatabaseViewer;
 24    import org.apache.xindice.core.Database;
 25    import org.apache.xindice.util.StringUtilities;
 26   
 27    import javax.servlet.http.HttpServletRequest;
 28    import javax.servlet.http.HttpServletResponse;
 29    import javax.servlet.ServletException;
 30    import java.io.IOException;
 31    import java.io.Writer;
 32   
 33    /**
 34    * Xindice Html Viewer for database listings.
 35    *
 36    * @version $Revision: 711958 $, $Date: 2008-11-06 20:12:54 +0000 (Thu, 06 Nov 2008) $
 37    */
 38    public class ListDatabaseViewer extends HtmlViewerComponent implements HtmlDatabaseViewer {
 39   
 40  0 public void execute(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
 41   
 42  0 String[] databases = Database.listDatabases();
 43   
 44  0 String path = "/";
 45  0 String title = "List databases";
 46   
 47  0 ListDatabaseViewer.TableRow row = new ListDatabaseViewer.TableRow();
 48  0 Writer output = startViewer(title, path, res);
 49  0 printStartTable(row.getTitles(), output);
 50   
 51  0 for (int i = 0; i < databases.length; i++) {
 52  0 boolean metaEnabled = Database.getDatabase(databases[i]).isMetaEnabled();
 53  0 String dbRoot = Database.getDatabase(databases[i]).getCollectionRoot().getCanonicalPath();
 54  0 printTableRow(row.getDatabase(databases[i], metaEnabled, dbRoot), output);
 55    }
 56   
 57  0 printEndTable(output);
 58  0 finishViewer(output);
 59    }
 60   
 61  0 protected String getName() {
 62  0 return "list";
 63    }
 64   
 65    // TableRow Inner Class
 66    protected class TableRow {
 67   
 68    protected final String[] titles = {"Name", "Type", "Meta-enabled", "DB root"};
 69   
 70    protected String[] content;
 71   
 72  0 TableRow() {
 73  0 content = new String[titles.length];
 74  0 reset();
 75    }
 76   
 77  0 protected String[] getTitles() {
 78  0 return titles;
 79    }
 80   
 81  0 protected void reset() {
 82  0 for (int i = 0; i < content.length; i++) {
 83  0 content[i] = null;
 84    }
 85    }
 86   
 87  0 protected String[] getDatabase(String name, boolean metaEnabled, String dbRoot) {
 88  0 reset();
 89  0 content[0] = createLink(StringUtilities.escapePath(name) + "/?viewer=list", name);
 90  0 content[1] = "database";
 91  0 content[2] = Boolean.toString(metaEnabled);
 92  0 content[3] = dbRoot;
 93  0 return content;
 94    }
 95   
 96  0 protected String createLink(String link, String name) {
 97  0 return "<a href=\"" + link + "\">" + name + "</a>";
 98    }
 99    }
 100    }