Clover coverage report -
Coverage timestamp: Sun Nov 1 2009 23:08:24 UTC
file stats: LOC: 86   Methods: 2
NCLOC: 49   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
ContentResourceViewer.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: ContentResourceViewer.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.w3c.dom.Document;
 30   
 31    import org.apache.xindice.core.Collection;
 32    import org.apache.xindice.core.DBException;
 33    import org.apache.xindice.core.data.Entry;
 34    import org.apache.xindice.webadmin.viewer.*;
 35    import org.apache.xindice.webadmin.viewer.HtmlViewerComponent;
 36    import org.apache.xindice.xml.Xml2HtmlWriter;
 37    import org.apache.commons.logging.Log;
 38    import org.apache.commons.logging.LogFactory;
 39   
 40    /**
 41    * Xindice Html Contents Viewer for Resources
 42    *
 43    * @author <a href="mailto:jmetzner@apache.org">Jan Metzner</a>
 44    * @version $Revision: 711958 $, $Date: 2008-11-06 20:12:54 +0000 (Thu, 06 Nov 2008) $
 45    */
 46    public class ContentResourceViewer extends HtmlViewerComponent implements HtmlResourceViewer {
 47   
 48    private static final Log log = LogFactory.getLog(ContentResourceViewer.class);
 49   
 50  0 public void execute(HttpServletRequest req, HttpServletResponse res, Collection col, String name)
 51    throws ServletException, IOException {
 52   
 53  0 String path = col.getCanonicalName() + "/" + name;
 54  0 String title = "Document " + path;
 55   
 56  0 Entry resource;
 57  0 try {
 58  0 resource = col.getEntry(name);
 59    } catch (DBException e) {
 60  0 log.error(e);
 61  0 throw new ServletException(e);
 62    }
 63   
 64  0 Writer output = startViewer(title, path, res);
 65  0 printStartTable(title, output);
 66  0 printStartSingleTableBox(output);
 67  0 output.write("<a href=\"./?viewer=default\">up to parent collection</a>");
 68  0 printEndSingleTableBox(output);
 69  0 printStartSingleTableBox(output);
 70    // todo: NullPointerException resource == null
 71  0 if (resource.getEntryType() == Entry.DOCUMENT) {
 72  0 Xml2HtmlWriter.write((Document) resource.getValue(), output);
 73    } else {
 74  0 output.write("binary resource <a href=\"./");
 75  0 output.write(name);
 76  0 output.write("\">view content</a>");
 77    }
 78  0 printEndSingleTableBox(output);
 79  0 printEndTable(output);
 80  0 finishViewer(output);
 81    }
 82   
 83  0 protected String getName() {
 84  0 return "content";
 85    }
 86    }