Clover coverage report -
Coverage timestamp: Sun Nov 1 2009 23:08:24 UTC
file stats: LOC: 162   Methods: 9
NCLOC: 107   Classes: 2
 
 Source file Conditionals Statements Methods TOTAL
ListCollectionViewer.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: ListCollectionViewer.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    import java.text.SimpleDateFormat;
 25    import java.util.Date;
 26    import java.util.Locale;
 27    import java.util.TimeZone;
 28   
 29    import javax.servlet.ServletException;
 30    import javax.servlet.http.HttpServletRequest;
 31    import javax.servlet.http.HttpServletResponse;
 32   
 33    import org.apache.xindice.core.Collection;
 34    import org.apache.xindice.core.DBException;
 35    import org.apache.xindice.webadmin.viewer.HtmlCollectionViewer;
 36    import org.apache.xindice.webadmin.viewer.HtmlViewerComponent;
 37    import org.apache.xindice.util.StringUtilities;
 38   
 39    /**
 40    * Xindice Html Viewer for collection listings.
 41    *
 42    * @author <a href="mailto:jmetzner@apache.org">Jan Metzner</a>
 43    * @version $Revision: 711958 $, $Date: 2008-11-06 20:12:54 +0000 (Thu, 06 Nov 2008) $
 44    */
 45    public class ListCollectionViewer extends HtmlViewerComponent implements HtmlCollectionViewer {
 46   
 47    /**
 48    * Simple date format for the modification date representation.
 49    */
 50    public static final String DATE_FORMAT = "EEE, dd MMM yyyy HH:mm:ss zzz";
 51   
 52  0 public void execute(HttpServletRequest req, HttpServletResponse res, Collection col)
 53    throws ServletException, IOException {
 54   
 55  0 String path = col.getCanonicalName();
 56  0 String title = "List contents for " + path;
 57   
 58  0 TableRow row = new TableRow();
 59  0 Writer output = startViewer(title, path, res);
 60  0 printStartTable(row.getTitles(), output);
 61   
 62    // write parent
 63  0 printTableRow(row.getParentCollection(), output);
 64   
 65    // write child collections
 66  0 String[] childCol;
 67  0 try {
 68  0 childCol = col.listCollections();
 69    } catch (DBException e) {
 70  0 childCol = new String[0];
 71    }
 72  0 for (int i = 0; i < childCol.length; i++) {
 73  0 printTableRow(row.getCollection(childCol[i]), output);
 74    }
 75   
 76    // write child resources
 77  0 String[] childRes;
 78  0 try { // get names
 79  0 childRes = col.listDocuments();
 80    } catch (Exception e) {
 81  0 childRes = new String[0];
 82    }
 83   
 84  0 for (int i = 0; i < childRes.length; i++) {
 85  0 String date;
 86  0 try { // get date
 87  0 long modificationDate = col.getEntryMeta(childRes[i]).getModificationTime();
 88  0 if (modificationDate != 0) {
 89  0 SimpleDateFormat formatter = new SimpleDateFormat(DATE_FORMAT, Locale.US);
 90  0 formatter.setTimeZone(TimeZone.getTimeZone("GMT"));
 91  0 date = formatter.format(new Date(modificationDate));
 92    } else {
 93  0 date = "";
 94    }
 95    } catch (DBException e) {
 96  0 date = "";
 97    }
 98  0 printTableRow(row.getResource(childRes[i], date), output);
 99    }
 100  0 printEndTable(output);
 101  0 finishViewer(output);
 102    }
 103   
 104  0 protected String getName() {
 105  0 return "list";
 106    }
 107   
 108    // TableRow Inner Class
 109    protected class TableRow {
 110   
 111    protected final String[] titles = {"Name", "Type", "Last Modification", "Source", "Delete"};
 112   
 113    protected String[] content;
 114   
 115  0 TableRow() {
 116  0 content = new String[titles.length];
 117  0 reset();
 118    }
 119   
 120  0 protected String[] getTitles() {
 121  0 return titles;
 122    }
 123   
 124  0 protected void reset() {
 125  0 for (int i = 0; i < content.length; i++) {
 126  0 content[i] = null;
 127    }
 128    }
 129   
 130  0 protected String[] getCollection(String name) {
 131  0 reset();
 132  0 String encName = StringUtilities.escapePath(name);
 133  0 content[0] = createLink(encName + "/?viewer=list", name);
 134  0 content[1] = "collection";
 135  0 content[3] = "&nbsp;";
 136  0 content[4] = createLink(encName + "/?viewer=delete&redirect=../?viewer=list", "delete");
 137  0 return content;
 138    }
 139   
 140  0 protected String[] getResource(String name, String date) {
 141  0 reset();
 142  0 String encName = StringUtilities.escapePath(name);
 143  0 content[0] = createLink(encName + "?viewer=default", name);
 144  0 content[1] = "resource";
 145  0 content[2] = date;
 146  0 content[3] = createLink(encName, "src");
 147  0 content[4] = createLink(encName + "?viewer=delete&redirect=./?viewer=list", "delete");
 148  0 return content;
 149    }
 150   
 151  0 protected String[] getParentCollection() {
 152  0 reset();
 153  0 content[0] = createLink("../?viewer=list", "up to parent collection");
 154  0 content[1] = "collection";
 155  0 return content;
 156    }
 157   
 158  0 protected String createLink(String link, String name) {
 159  0 return "<a href=\"" + link + "\">" + name + "</a>";
 160    }
 161    }
 162    }