1 33 34 package edu.rice.cs.drjava.ui; 35 36 import javax.swing.event.HyperlinkListener ; 37 import javax.swing.event.HyperlinkEvent ; 38 import java.net.URL ; 39 import java.net.MalformedURLException ; 40 import java.io.File ; 41 import java.io.FileReader ; 42 import java.io.BufferedReader ; 43 import java.io.IOException ; 44 45 import edu.rice.cs.util.UnexpectedException; 46 47 51 public class JavadocFrame extends HTMLFrame { 52 53 private static final int MAX_READ_PACKAGES_LINES = 100; 54 private static final int MAX_READ_FOR_LINK_LINES = 100; 55 private static final String [] INTRO_PAGE= { 56 "overview-summary.html", 57 "packages.html" 58 }; 59 private static final String INDEX_PAGE= "allclasses-frame.html"; 60 61 private static String introPagePath(File destDir, String curClass) { 62 File test = new File (destDir, curClass + ".html"); 64 for (int i = 0; !test.exists() && (i < INTRO_PAGE.length); i++) { 65 test = new File (destDir, INTRO_PAGE[i]); 66 } 67 68 if (test.exists()) { 70 if (test.getName().equals("packages.html")) { 71 test = _parsePackagesFile(test, destDir); 72 } 73 } 74 else { 75 throw new IllegalStateException ("No Javadoc HTML output files found!"); 76 } 77 return test.getAbsolutePath(); 78 } 79 80 87 private static File _parsePackagesFile(File packages, File destDir) { 88 try { 89 FileReader fr = new FileReader (packages); 90 BufferedReader br = new BufferedReader (fr); 91 try { String line = br.readLine(); 93 int numLinesRead = 1; 94 boolean found = false; 95 while ((!found) && 96 (numLinesRead < MAX_READ_PACKAGES_LINES) && 97 (line != null)) { 98 found = (line.indexOf("The front page has been relocated") != -1); 99 if (!found) { 100 line = br.readLine(); 101 numLinesRead++; 102 } 103 } 104 105 if (found) { 107 boolean foundLink = false; 108 while ((!foundLink) && 109 (numLinesRead < MAX_READ_FOR_LINK_LINES) && 110 (line != null)) { 111 foundLink = (line.indexOf("Non-frame version") != -1); 112 if (!foundLink) { 113 line = br.readLine(); 114 numLinesRead++; 115 } 116 } 117 118 if (foundLink) { 119 String start = "HREF=\""; 120 int startIndex = line.indexOf(start) + start.length(); 121 int endIndex = line.indexOf("\">"); 122 if ((startIndex != -1) && (endIndex != -1)) { 123 String fileName = line.substring(startIndex, endIndex); 124 return new File (destDir, fileName); 125 } 126 } 127 } 128 } 129 finally { br.close(); } 130 } 131 catch (IOException ioe) { throw new UnexpectedException(ioe); } 132 return packages; 133 } 134 135 141 public JavadocFrame(File destDir, String curClass, boolean allDocs) 142 throws MalformedURLException 143 { 144 super("Javadoc Viewer", 146 new URL ("file", "", introPagePath(destDir, curClass)), 147 new URL ("file", "", (new File (destDir, INDEX_PAGE)).getAbsolutePath()), 148 "DrJavadoc.png", destDir); 149 150 addHyperlinkListener(new HyperlinkListener () { 151 public void hyperlinkUpdate(HyperlinkEvent event) { 152 if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { 153 URL url = event.getURL(); 154 jumpTo(url); 155 } 156 } 157 }); 158 159 if (!allDocs) { 160 _hideNavigationPane(); 161 } 162 } 163 } 164 | Popular Tags |