Skip to content

Commit 9544bee

Browse files
author
Vladimir Kotal
authored
refactor annotate code once again (#2172)
fixes #2170
1 parent f2a0080 commit 9544bee

File tree

1 file changed

+54
-50
lines changed

1 file changed

+54
-50
lines changed

web/list.jsp

Lines changed: 54 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -174,72 +174,75 @@ document.pageReady.push(function() { pageReadyList();});
174174
175175
}
176176
}
177-
} else if (cfg.annotate()) {
178-
// annotate
179-
BufferedInputStream bin =
180-
new BufferedInputStream(new FileInputStream(resourceFile));
181-
try {
182-
FileAnalyzerFactory a = AnalyzerGuru.find(basename);
183-
Genre g = AnalyzerGuru.getGenre(a);
184-
if (g == null) {
185-
a = AnalyzerGuru.find(bin);
186-
g = AnalyzerGuru.getGenre(a);
187-
}
188-
if (g == Genre.IMAGE) {
177+
} else if (rev.length() != 0) {
178+
// requesting a revision
179+
if (cfg.isLatestRevision(rev)) {
180+
if (cfg.annotate()) {
181+
// annotate
182+
BufferedInputStream bin =
183+
new BufferedInputStream(new FileInputStream(resourceFile));
184+
try {
185+
FileAnalyzerFactory a = AnalyzerGuru.find(basename);
186+
Genre g = AnalyzerGuru.getGenre(a);
187+
if (g == null) {
188+
a = AnalyzerGuru.find(bin);
189+
g = AnalyzerGuru.getGenre(a);
190+
}
191+
if (g == Genre.IMAGE) {
189192
%>
190193
<div id="src">
191194
<img src="<%= rawPath %>"/>
192195
</div><%
193-
} else if ( g == Genre.HTML) {
194-
/**
195-
* For backward compatibility, read the OpenGrok-produced
196-
* document using the system default charset.
197-
*/
198-
r = new InputStreamReader(bin);
199-
// dumpXref() is also useful here for translating links.
200-
Util.dumpXref(out, r, request.getContextPath());
201-
} else if (g == Genre.PLAIN) {
196+
} else if ( g == Genre.HTML) {
197+
/**
198+
* For backward compatibility, read the OpenGrok-produced
199+
* document using the system default charset.
200+
*/
201+
r = new InputStreamReader(bin);
202+
// dumpXref() is also useful here for translating links.
203+
Util.dumpXref(out, r, request.getContextPath());
204+
} else if (g == Genre.PLAIN) {
202205
%>
203206
<div id="src" data-navigate-window-enabled="<%= navigateWindowEnabled %>">
204207
<pre><%
205-
// We're generating xref for the latest revision, so we can
206-
// find the definitions in the index.
207-
Definitions defs = IndexDatabase.getDefinitions(resourceFile);
208-
Annotation annotation = cfg.getAnnotation();
209-
// SRCROOT is read with UTF-8 as a default.
210-
r = IOUtils.createBOMStrippedReader(bin,
211-
StandardCharsets.UTF_8.name());
212-
AnalyzerGuru.writeDumpedXref(request.getContextPath(), a,
213-
r, out, defs, annotation, project);
208+
// We're generating xref for the latest revision, so we can
209+
// find the definitions in the index.
210+
Definitions defs = IndexDatabase.getDefinitions(resourceFile);
211+
Annotation annotation = cfg.getAnnotation();
212+
// SRCROOT is read with UTF-8 as a default.
213+
r = IOUtils.createBOMStrippedReader(bin,
214+
StandardCharsets.UTF_8.name());
215+
AnalyzerGuru.writeDumpedXref(request.getContextPath(), a,
216+
r, out, defs, annotation, project);
214217
%></pre>
215218
</div><%
216-
} else {
219+
} else {
217220
%>
218221
Click <a href="<%= rawPath %>">download <%= basename %></a><%
222+
}
223+
} finally {
224+
if (r != null) {
225+
try { r.close(); bin = null; }
226+
catch (Exception e) { /* ignore */ }
227+
}
228+
if (bin != null) {
229+
try { bin.close(); }
230+
catch (Exception e) { /* ignore */ }
231+
}
219232
}
220-
} finally {
221-
if (r != null) {
222-
try { r.close(); bin = null; }
223-
catch (Exception e) { /* ignore */ }
224-
}
225-
if (bin != null) {
226-
try { bin.close(); }
227-
catch (Exception e) { /* ignore */ }
228-
}
229-
}
230-
} else if (rev.length() != 0) {
231-
// requesting a revision
232-
if (cfg.isLatestRevision(rev)) {
233-
File xrefFile = cfg.findDataFile();
234-
if (xrefFile != null) {
233+
234+
} else {
235+
File xrefFile = cfg.findDataFile();
236+
if (xrefFile != null) {
235237
%>
236238
<div id="src" data-navigate-window-enabled="<%= navigateWindowEnabled %>">
237239
<pre><%
238-
boolean compressed = xrefFile.getName().endsWith(".gz");
239-
Util.dumpXref(out, xrefFile, compressed,
240-
request.getContextPath());
240+
boolean compressed = xrefFile.getName().endsWith(".gz");
241+
Util.dumpXref(out, xrefFile, compressed,
242+
request.getContextPath());
241243
%></pre>
242244
</div><%
245+
}
243246
}
244247
} else {
245248
// requesting a previous revision
@@ -283,7 +286,8 @@ Click <a href="<%= rawPath %>">download <%= basename %></a><%
283286
r = IOUtils.createBOMStrippedReader(in,
284287
StandardCharsets.UTF_8.name());
285288
AnalyzerGuru.writeDumpedXref(
286-
request.getContextPath(), a, r, out,
289+
request.getContextPath(),
290+
a, r, out,
287291
defs, annotation, project);
288292
} else if (g == Genre.IMAGE) {
289293
%></pre>

0 commit comments

Comments
 (0)