|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| |
|
17 |
| |
|
18 |
| |
|
19 |
| |
|
20 |
| |
|
21 |
| |
|
22 |
| |
|
23 |
| |
|
24 |
| |
|
25 |
| |
|
26 |
| |
|
27 |
| |
|
28 |
| |
|
29 |
| |
|
30 |
| |
|
31 |
| |
|
32 |
| |
|
33 |
| |
|
34 |
| |
|
35 |
| |
|
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 |
| |
|
52 |
| |
|
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 |
| |
|
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 |
| |
|
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 |
| |
|
84 |
| |
|
85 |
| |
|
86 |
| |
|
87 |
| |
|
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 {
|
|
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 |
| |
|
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 |
| |
|
138 |
| |
|
139 |
| |
|
140 |
| |
|
141 |
| |
|
142 |
0
| public JavadocFrame(File destDir, String curClass, boolean allDocs)
|
|
143 |
| throws MalformedURLException |
|
144 |
| { |
|
145 |
| |
|
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 |
| } |