Clover coverage report - DrJava Test Coverage (drjava-20120304-r5456)
Coverage timestamp: Sun Mar 4 2012 03:13:23 CST
file stats: LOC: 164   Methods: 4
NCLOC: 97   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
JavadocFrame.java 0% 0% 0% 0%
coverage
 1    /*BEGIN_COPYRIGHT_BLOCK
 2    *
 3    * Copyright (c) 2001-2010, JavaPLT group at Rice University (drjava@rice.edu)
 4    * All rights reserved.
 5    *
 6    * Redistribution and use in source and binary forms, with or without
 7    * modification, are permitted provided that the following conditions are met:
 8    * * Redistributions of source code must retain the above copyright
 9    * notice, this list of conditions and the following disclaimer.
 10    * * Redistributions in binary form must reproduce the above copyright
 11    * notice, this list of conditions and the following disclaimer in the
 12    * documentation and/or other materials provided with the distribution.
 13    * * Neither the names of DrJava, the JavaPLT group, Rice University, nor the
 14    * names of its contributors may be used to endorse or promote products
 15    * derived from this software without specific prior written permission.
 16    *
 17    * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 18    * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 19    * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 20    * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 21    * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 22    * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 23    * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 24    * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 25    * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 26    * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 27    * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 28    *
 29    * This software is Open Source Initiative approved Open Source Software.
 30    * Open Source Initative Approved is a trademark of the Open Source Initiative.
 31    *
 32    * This file is part of DrJava. Download the current version of this project
 33    * from http://www.drjava.org/ or http://sourceforge.net/projects/drjava/
 34    *
 35    * END_COPYRIGHT_BLOCK*/
 36   
 37    package edu.rice.cs.drjava.ui;
 38   
 39    import javax.swing.event.HyperlinkListener;
 40    import javax.swing.event.HyperlinkEvent;
 41    import java.net.URL;
 42    import java.net.MalformedURLException;
 43    import java.io.File;
 44    import java.io.FileReader;
 45    import java.io.BufferedReader;
 46    import java.io.IOException;
 47   
 48    import edu.rice.cs.util.UnexpectedException;
 49   
 50    /**
 51    * DrJava's Javadoc viewing frame
 52    * @version $Id: JavadocFrame.java 5175 2010-01-20 08:46:32Z mgricken $
 53    */
 54    public class JavadocFrame extends HTMLFrame {
 55   
 56    private static final int MAX_READ_PACKAGES_LINES = 100;
 57    private static final int MAX_READ_FOR_LINK_LINES = 100;
 58    private static final String[] INTRO_PAGE= {
 59    "overview-summary.html",
 60    "packages.html"
 61    };
 62    private static final String INDEX_PAGE= "allclasses-frame.html";
 63   
 64  0 private static String introPagePath(File destDir, String curClass) {
 65    // Iterate through possible intro pages, looking for one that exists.
 66  0 File test = new File(destDir, curClass + ".html");
 67  0 for (int i = 0; !test.exists() && (i < INTRO_PAGE.length); i++) {
 68  0 test = new File(destDir, INTRO_PAGE[i]);
 69    }
 70   
 71    // Packages.html might just be a pointer to another file
 72  0 if (test.exists()) {
 73  0 if (test.getName().equals("packages.html")) {
 74  0 test = _parsePackagesFile(test, destDir);
 75    }
 76    }
 77    else {
 78  0 throw new IllegalStateException("No Javadoc HTML output files found!");
 79    }
 80  0 return test.getAbsolutePath();
 81    }
 82   
 83    /** Reads through the beginning of the packages.html file to determine
 84    * if it is just a pointer to another file. Returns either the same
 85    * file (if it's not a pointer), or the file used for "No frames" (if
 86    * it is a pointer).
 87    * @param packages Full path to the packages.html file
 88    */
 89  0 private static File _parsePackagesFile(File packages, File destDir) {
 90  0 try {
 91  0 FileReader fr = new FileReader(packages);
 92  0 BufferedReader br = new BufferedReader(fr);
 93  0 try { // process the opened file
 94  0 String line = br.readLine();
 95  0 int numLinesRead = 1;
 96  0 boolean found = false;
 97  0 while ((!found) &&
 98    (numLinesRead < MAX_READ_PACKAGES_LINES) &&
 99    (line != null)) {
 100  0 found = (line.indexOf("The front page has been relocated") != -1);
 101  0 if (!found) {
 102  0 line = br.readLine();
 103  0 numLinesRead++;
 104    }
 105    }
 106   
 107    // Replace packages.html with the No Frames link.
 108  0 if (found) {
 109  0 boolean foundLink = false;
 110  0 while ((!foundLink) &&
 111    (numLinesRead < MAX_READ_FOR_LINK_LINES) &&
 112    (line != null)) {
 113  0 foundLink = (line.indexOf("Non-frame version") != -1);
 114  0 if (!foundLink) {
 115  0 line = br.readLine();
 116  0 numLinesRead++;
 117    }
 118    }
 119   
 120  0 if (foundLink) {
 121  0 String start = "HREF=\"";
 122  0 int startIndex = line.indexOf(start) + start.length();
 123  0 int endIndex = line.indexOf("\">");
 124  0 if ((startIndex != -1) && (endIndex != -1)) {
 125  0 String fileName = line.substring(startIndex, endIndex);
 126  0 return new File(destDir, fileName);
 127    }
 128    }
 129    }
 130    }
 131  0 finally { br.close(); }
 132    }
 133  0 catch (IOException ioe) { throw new UnexpectedException(ioe); }
 134  0 return packages;
 135    }
 136   
 137    /** Constructor.
 138    * @param destDir Directory holding the Javadoc
 139    * @param curClass Name of the class to try to show by default
 140    * @param allDocs Whether Javadoc was run for all open documents
 141    */
 142  0 public JavadocFrame(File destDir, String curClass, boolean allDocs)
 143    throws MalformedURLException
 144    {
 145    // This call has to happen first!
 146  0 super("Javadoc Viewer",
 147    new URL("file", "", introPagePath(destDir, curClass)),
 148    new URL("file", "", (new File(destDir, INDEX_PAGE)).getAbsolutePath()),
 149    "DrJavadoc.png", destDir);
 150   
 151  0 addHyperlinkListener(new HyperlinkListener() {
 152  0 public void hyperlinkUpdate(HyperlinkEvent event) {
 153  0 if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
 154  0 URL url = event.getURL();
 155  0 jumpTo(url);
 156    }
 157    }
 158    });
 159   
 160  0 if (!allDocs) {
 161  0 _hideNavigationPane();
 162    }
 163    }
 164    }