list.jsp revision 1186
e2f91e3434ddf2d4cb85d2385057a492eb462166Fox Wilson<%--
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn$Id$
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn
198b363fff1de9afcee2f26b9aa847316f589afeSerge HallynCDDL HEADER START
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn
198b363fff1de9afcee2f26b9aa847316f589afeSerge HallynThe contents of this file are subject to the terms of the
198b363fff1de9afcee2f26b9aa847316f589afeSerge HallynCommon Development and Distribution License (the "License").
198b363fff1de9afcee2f26b9aa847316f589afeSerge HallynYou may not use this file except in compliance with the License.
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn
198b363fff1de9afcee2f26b9aa847316f589afeSerge HallynSee LICENSE.txt included in this distribution for the specific
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallynlanguage governing permissions and limitations under the License.
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn
198b363fff1de9afcee2f26b9aa847316f589afeSerge HallynWhen distributing Covered Code, include this CDDL HEADER in each
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallynfile and include the License file at LICENSE.txt.
198b363fff1de9afcee2f26b9aa847316f589afeSerge HallynIf applicable, add the following below this CDDL HEADER, with the
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallynfields enclosed by brackets "[]" replaced with your own identifying
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyninformation: Portions Copyright [yyyy] [name of copyright owner]
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn
198b363fff1de9afcee2f26b9aa847316f589afeSerge HallynCDDL HEADER END
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn
198b363fff1de9afcee2f26b9aa847316f589afeSerge HallynCopyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
198b363fff1de9afcee2f26b9aa847316f589afeSerge HallynPortions Copyright 2011 Jens Elkner.
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn--%><%@page import="
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallynjava.io.BufferedInputStream,
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallynjava.io.BufferedReader,
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallynjava.io.FileInputStream,
94a77f3fd8be2fb87f7d1465521fac3ec4b7e6b5Serge Hallynjava.io.FileReader,
94a77f3fd8be2fb87f7d1465521fac3ec4b7e6b5Serge Hallynjava.io.InputStream,
94a77f3fd8be2fb87f7d1465521fac3ec4b7e6b5Serge Hallynjava.io.InputStreamReader,
94a77f3fd8be2fb87f7d1465521fac3ec4b7e6b5Serge Hallynjava.io.Reader,
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallynjava.util.ArrayList,
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallynjava.util.Arrays,
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallynjava.util.List,
94a77f3fd8be2fb87f7d1465521fac3ec4b7e6b5Serge Hallynjava.util.Set,
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallynjava.util.logging.Level,
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallynjava.util.zip.GZIPInputStream,
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallynorg.opensolaris.opengrok.OpenGrokLogger,
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallynorg.opensolaris.opengrok.analysis.AnalyzerGuru,
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallynorg.opensolaris.opengrok.analysis.Definitions,
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallynorg.opensolaris.opengrok.analysis.FileAnalyzer.Genre,
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallynorg.opensolaris.opengrok.analysis.FileAnalyzerFactory,
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallynorg.opensolaris.opengrok.history.Annotation,
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallynorg.opensolaris.opengrok.index.IndexDatabase,
94a77f3fd8be2fb87f7d1465521fac3ec4b7e6b5Serge Hallynorg.opensolaris.opengrok.web.DirectoryListing"
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn%><%
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn{
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn // need to set it here since requesting parameters
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn if (request.getCharacterEncoding() == null) {
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn request.setCharacterEncoding("UTF-8");
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn }
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn cfg = PageConfig.get(request);
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn Annotation annotation = cfg.getAnnotation();
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn if (annotation != null) {
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn int r = annotation.getWidestRevision();
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn int a = annotation.getWidestAuthor();
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn cfg.addHeaderData("<style type=\"text/css\">"
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn + ".blame .r { width: " + (r == 0 ? 6 : r) + "ex; } "
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn + ".blame .a { width: " + (a == 0 ? 6 : a) + "ex; } "
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn + "</style>");
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn }
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn}
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn%><%@include
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallynfile="mast.jsp"
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn%><script type="text/javascript">/* <![CDATA[ */
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyndocument.pageReady.push(function() { pageReadyList();});
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn/* ]]> */</script>
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn<%
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn/* ---------------------- list.jsp start --------------------- */
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn{
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn cfg = PageConfig.get(request);
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn String rev = cfg.getRequestedRevision();
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn File resourceFile = cfg.getResourceFile();
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn String path = cfg.getPath();
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn String basename = resourceFile.getName();
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn String rawPath = request.getContextPath() + Prefix.RAW_P + path;
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn Reader r = null;
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn if (cfg.isDir()) {
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn // valid resource is requested
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn // mast.jsp assures, that resourceFile is valid and not /
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn // see cfg.resourceNotAvailable()
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn Project activeProject = Project.getProject(resourceFile);
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn String cookieValue = cfg.getRequestedProjectsAsString();
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn if (activeProject != null) {
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn Set<String> projects = cfg.getRequestedProjects();
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn if (!projects.contains(activeProject.getDescription())) {
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn projects.add(activeProject.getDescription());
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn // update cookie
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn cookieValue = cookieValue.length() == 0
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn ? activeProject.getDescription()
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn : activeProject.getDescription() + '/' + cookieValue;
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn Cookie cookie = new Cookie("OpenGrokProject", cookieValue);
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn // TODO hmmm, projects.jspf doesn't set a path
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn cookie.setPath(request.getContextPath() + '/');
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn response.addCookie(cookie);
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn }
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn }
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn // requesting a directory listing
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn DirectoryListing dl = new DirectoryListing(cfg.getEftarReader());
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn String[] files = cfg.getResourceFileList();
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn if (files.length != 0) {
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn List<String> readMes = dl.listTo(resourceFile, out, path, files);
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn File[] catfiles = cfg.findDataFiles(readMes);
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn for (int i=0; i < catfiles.length; i++) {
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn if (catfiles[i] == null) {
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn continue;
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn }
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn%><h3><%= readMes.get(i) %></h3>
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn<div id="src">
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn <pre><%
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn Util.dump(out, catfiles[i], catfiles[i].getName().endsWith(".gz"));
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn %></pre>
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn</div><%
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn }
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn }
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn } else if (rev.length() != 0) {
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn // requesting a previous revision
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn FileAnalyzerFactory a = AnalyzerGuru.find(basename);
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn Genre g = AnalyzerGuru.getGenre(a);
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn String error = null;
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn if (g == Genre.PLAIN|| g == Genre.HTML || g == null) {
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn InputStream in = null;
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn try {
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn in = HistoryGuru.getInstance()
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn .getRevision(resourceFile.getParent(), basename, rev.substring(2));
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn } catch (Exception e) {
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn // fall through to error message
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn error = e.getMessage();
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn }
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn if (in != null) {
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn try {
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn if (g == null) {
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn a = AnalyzerGuru.find(in);
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn g = AnalyzerGuru.getGenre(a);
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn }
if (g == Genre.DATA || g == Genre.XREFABLE
|| g == null)
{
%>
<div id="src">
Binary file [Click <a href="<%= rawPath %>?<%= rev
%>">here</a> to download]
</div><%
} else {
%>
<div id="src">
<span class="pagetitle"><%= basename %> revision <%=
rev.substring(2) %></span>
<pre><%
if (g == Genre.PLAIN) {
// We don't have any way to get definitions
// for old revisions currently.
Definitions defs = null;
Annotation annotation = cfg.getAnnotation();
//not needed yet
//annotation.writeTooltipMap(out);
r = new InputStreamReader(in);
AnalyzerGuru.writeXref(a, r, out, defs,
annotation, Project.getProject(resourceFile));
} else if (g == Genre.IMAGE) {
%></pre>
<img src="<%= rawPath %>?<%= rev %>"/>
<pre><%
} else if (g == Genre.HTML) {
r = new InputStreamReader(in);
Util.dump(out, r);
} else {
%> Click <a href="<%= rawPath %>?<%= rev %>">download <%= basename %></a><%
}
}
} catch (IOException e) {
error = e.getMessage();
} finally {
if (r != null) {
try { r.close(); in = null;}
catch (Exception e) { /* ignore */ }
}
if (in != null) {
try { in.close(); }
catch (Exception e) { /* ignore */ }
}
}
%></pre>
</div><%
} else {
%>
<h3 class="error">Error reading file</h3><%
if (error != null) {
%>
<p class="error"><%= error %></p><%
}
}
} else if (g == Genre.IMAGE) {
%>
<div id="src">
<img src="<%= rawPath %>?<%= rev %>"/>
</div><%
} else {
%>
<div id="src">
Binary file [Click <a href="<%= rawPath %>?<%= rev
%>">here</a> to download]
</div><%
}
} else {
// requesting cross referenced file
File xrefFile = null;
if (!cfg.annotate()) {
xrefFile = cfg.findDataFile();
}
if (xrefFile != null) {
%>
<div id="src">
<pre><%
Util.dump(out, xrefFile, xrefFile.getName().endsWith(".gz"));
%></pre>
</div><%
} else {
// annotate
BufferedInputStream bin =
new BufferedInputStream(new FileInputStream(resourceFile));
try {
FileAnalyzerFactory a = AnalyzerGuru.find(basename);
Genre g = AnalyzerGuru.getGenre(a);
if (g == null) {
a = AnalyzerGuru.find(bin);
g = AnalyzerGuru.getGenre(a);
}
if (g == Genre.IMAGE) {
%>
<div id="src">
<img src="<%= rawPath %>"/>
</div><%
} else if ( g == Genre.HTML) {
r = new InputStreamReader(bin);
Util.dump(out, r);
} else if (g == Genre.PLAIN) {
%>
<div id="src">
<pre><%
// We're generating xref for the latest revision, so we can
// find the definitions in the index.
Definitions defs = IndexDatabase.getDefinitions(resourceFile);
Annotation annotation = cfg.getAnnotation();
r = new InputStreamReader(bin);
AnalyzerGuru.writeXref(a, r, out, defs, annotation,
Project.getProject(resourceFile));
%></pre>
</div><%
} else {
%>
Click <a href="<%= rawPath %>">download <%= basename %></a><%
}
} finally {
if (r != null) {
try { r.close(); bin = null; }
catch (Exception e) { /* ignore */ }
}
if (bin != null) {
try { bin.close(); }
catch (Exception e) { /* ignore */ }
}
}
}
}
}
/* ---------------------- list.jsp end --------------------- */
%><%@
include file="foot.jspf"
%>