list.jsp revision d8371503c60e1f6933455e25b1cc47e4858a3a43
96c1ae30d032621b47c4ac375b151ddaef5f1507Trond Norbye<%--
96c1ae30d032621b47c4ac375b151ddaef5f1507Trond Norbye$Id$
96c1ae30d032621b47c4ac375b151ddaef5f1507Trond Norbye
96c1ae30d032621b47c4ac375b151ddaef5f1507Trond NorbyeCDDL HEADER START
96c1ae30d032621b47c4ac375b151ddaef5f1507Trond Norbye
96c1ae30d032621b47c4ac375b151ddaef5f1507Trond NorbyeThe contents of this file are subject to the terms of the
96c1ae30d032621b47c4ac375b151ddaef5f1507Trond NorbyeCommon Development and Distribution License (the "License").
96c1ae30d032621b47c4ac375b151ddaef5f1507Trond NorbyeYou may not use this file except in compliance with the License.
96c1ae30d032621b47c4ac375b151ddaef5f1507Trond Norbye
96c1ae30d032621b47c4ac375b151ddaef5f1507Trond NorbyeSee LICENSE.txt included in this distribution for the specific
96c1ae30d032621b47c4ac375b151ddaef5f1507Trond Norbyelanguage governing permissions and limitations under the License.
96c1ae30d032621b47c4ac375b151ddaef5f1507Trond Norbye
96c1ae30d032621b47c4ac375b151ddaef5f1507Trond NorbyeWhen distributing Covered Code, include this CDDL HEADER in each
96c1ae30d032621b47c4ac375b151ddaef5f1507Trond Norbyefile and include the License file at LICENSE.txt.
96c1ae30d032621b47c4ac375b151ddaef5f1507Trond NorbyeIf applicable, add the following below this CDDL HEADER, with the
96c1ae30d032621b47c4ac375b151ddaef5f1507Trond Norbyefields enclosed by brackets "[]" replaced with your own identifying
96c1ae30d032621b47c4ac375b151ddaef5f1507Trond Norbyeinformation: Portions Copyright [yyyy] [name of copyright owner]
96c1ae30d032621b47c4ac375b151ddaef5f1507Trond Norbye
96c1ae30d032621b47c4ac375b151ddaef5f1507Trond NorbyeCDDL HEADER END
96c1ae30d032621b47c4ac375b151ddaef5f1507Trond Norbye
96c1ae30d032621b47c4ac375b151ddaef5f1507Trond NorbyeCopyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
96c1ae30d032621b47c4ac375b151ddaef5f1507Trond NorbyePortions Copyright 2011 Jens Elkner.
96c1ae30d032621b47c4ac375b151ddaef5f1507Trond Norbye
96c1ae30d032621b47c4ac375b151ddaef5f1507Trond Norbye--%><%@page import="
96c1ae30d032621b47c4ac375b151ddaef5f1507Trond Norbyejava.io.BufferedInputStream,
96c1ae30d032621b47c4ac375b151ddaef5f1507Trond Norbyejava.io.BufferedReader,
96c1ae30d032621b47c4ac375b151ddaef5f1507Trond Norbyejava.io.FileInputStream,
96c1ae30d032621b47c4ac375b151ddaef5f1507Trond Norbyejava.io.FileReader,
96c1ae30d032621b47c4ac375b151ddaef5f1507Trond Norbyejava.io.InputStream,
96c1ae30d032621b47c4ac375b151ddaef5f1507Trond Norbyejava.io.InputStreamReader,
96c1ae30d032621b47c4ac375b151ddaef5f1507Trond Norbyejava.io.Reader,
96c1ae30d032621b47c4ac375b151ddaef5f1507Trond Norbyejava.util.ArrayList,
96c1ae30d032621b47c4ac375b151ddaef5f1507Trond Norbyejava.util.Arrays,
96c1ae30d032621b47c4ac375b151ddaef5f1507Trond Norbyejava.util.List,
96c1ae30d032621b47c4ac375b151ddaef5f1507Trond Norbyejava.util.Set,
96c1ae30d032621b47c4ac375b151ddaef5f1507Trond Norbyejava.util.logging.Level,
96c1ae30d032621b47c4ac375b151ddaef5f1507Trond Norbyejava.util.zip.GZIPInputStream,
96c1ae30d032621b47c4ac375b151ddaef5f1507Trond Norbye
96c1ae30d032621b47c4ac375b151ddaef5f1507Trond Norbyeorg.opensolaris.opengrok.OpenGrokLogger,
96c1ae30d032621b47c4ac375b151ddaef5f1507Trond Norbyeorg.opensolaris.opengrok.analysis.AnalyzerGuru,
96c1ae30d032621b47c4ac375b151ddaef5f1507Trond Norbyeorg.opensolaris.opengrok.analysis.Definitions,
96c1ae30d032621b47c4ac375b151ddaef5f1507Trond Norbyeorg.opensolaris.opengrok.analysis.FileAnalyzer.Genre,
96c1ae30d032621b47c4ac375b151ddaef5f1507Trond Norbyeorg.opensolaris.opengrok.analysis.FileAnalyzerFactory,
96c1ae30d032621b47c4ac375b151ddaef5f1507Trond Norbyeorg.opensolaris.opengrok.history.Annotation,
96c1ae30d032621b47c4ac375b151ddaef5f1507Trond Norbyeorg.opensolaris.opengrok.index.IndexDatabase,
96c1ae30d032621b47c4ac375b151ddaef5f1507Trond Norbyeorg.opensolaris.opengrok.web.DirectoryListing"
96c1ae30d032621b47c4ac375b151ddaef5f1507Trond Norbye%><%
96c1ae30d032621b47c4ac375b151ddaef5f1507Trond Norbye{
96c1ae30d032621b47c4ac375b151ddaef5f1507Trond Norbye // need to set it here since requesting parameters
96c1ae30d032621b47c4ac375b151ddaef5f1507Trond Norbye if (request.getCharacterEncoding() == null) {
96c1ae30d032621b47c4ac375b151ddaef5f1507Trond Norbye request.setCharacterEncoding("UTF-8");
96c1ae30d032621b47c4ac375b151ddaef5f1507Trond Norbye }
96c1ae30d032621b47c4ac375b151ddaef5f1507Trond Norbye cfg = PageConfig.get(request);
96c1ae30d032621b47c4ac375b151ddaef5f1507Trond Norbye Annotation annotation = cfg.getAnnotation();
96c1ae30d032621b47c4ac375b151ddaef5f1507Trond Norbye if (annotation != null) {
96c1ae30d032621b47c4ac375b151ddaef5f1507Trond Norbye int r = annotation.getWidestRevision();
96c1ae30d032621b47c4ac375b151ddaef5f1507Trond Norbye int a = annotation.getWidestAuthor();
96c1ae30d032621b47c4ac375b151ddaef5f1507Trond Norbye cfg.addHeaderData("<style type=\"text/css\">"
96c1ae30d032621b47c4ac375b151ddaef5f1507Trond Norbye + ".blame .r { width: " + (r == 0 ? 6 : r) + "ex; } "
96c1ae30d032621b47c4ac375b151ddaef5f1507Trond Norbye + ".blame .a { width: " + (a == 0 ? 6 : a) + "ex; } "
96c1ae30d032621b47c4ac375b151ddaef5f1507Trond Norbye + "</style>");
96c1ae30d032621b47c4ac375b151ddaef5f1507Trond Norbye }
96c1ae30d032621b47c4ac375b151ddaef5f1507Trond Norbye}
96c1ae30d032621b47c4ac375b151ddaef5f1507Trond Norbye%><%@include
96c1ae30d032621b47c4ac375b151ddaef5f1507Trond Norbye
96c1ae30d032621b47c4ac375b151ddaef5f1507Trond Norbyefile="mast.jsp"
96c1ae30d032621b47c4ac375b151ddaef5f1507Trond Norbye
96c1ae30d032621b47c4ac375b151ddaef5f1507Trond Norbye%><script type="text/javascript">/* <![CDATA[ */
96c1ae30d032621b47c4ac375b151ddaef5f1507Trond Norbyedocument.pageReady.push(function() { pageReadyList();});
96c1ae30d032621b47c4ac375b151ddaef5f1507Trond Norbye/* ]]> */</script>
96c1ae30d032621b47c4ac375b151ddaef5f1507Trond Norbye<%
96c1ae30d032621b47c4ac375b151ddaef5f1507Trond Norbye/* ---------------------- list.jsp start --------------------- */
96c1ae30d032621b47c4ac375b151ddaef5f1507Trond Norbye{
96c1ae30d032621b47c4ac375b151ddaef5f1507Trond Norbye cfg = PageConfig.get(request);
96c1ae30d032621b47c4ac375b151ddaef5f1507Trond Norbye String rev = cfg.getRequestedRevision();
96c1ae30d032621b47c4ac375b151ddaef5f1507Trond Norbye
96c1ae30d032621b47c4ac375b151ddaef5f1507Trond Norbye File resourceFile = cfg.getResourceFile();
96c1ae30d032621b47c4ac375b151ddaef5f1507Trond Norbye String path = cfg.getPath();
96c1ae30d032621b47c4ac375b151ddaef5f1507Trond Norbye String basename = resourceFile.getName();
96c1ae30d032621b47c4ac375b151ddaef5f1507Trond Norbye String rawPath = request.getContextPath() + Prefix.DOWNLOAD_P + path;
96c1ae30d032621b47c4ac375b151ddaef5f1507Trond Norbye Reader r = null;
96c1ae30d032621b47c4ac375b151ddaef5f1507Trond Norbye if (cfg.isDir()) {
96c1ae30d032621b47c4ac375b151ddaef5f1507Trond Norbye // valid resource is requested
96c1ae30d032621b47c4ac375b151ddaef5f1507Trond Norbye // mast.jsp assures, that resourceFile is valid and not /
96c1ae30d032621b47c4ac375b151ddaef5f1507Trond Norbye // see cfg.resourceNotAvailable()
96c1ae30d032621b47c4ac375b151ddaef5f1507Trond Norbye Project activeProject = Project.getProject(resourceFile);
96c1ae30d032621b47c4ac375b151ddaef5f1507Trond Norbye String cookieValue = cfg.getRequestedProjectsAsString();
96c1ae30d032621b47c4ac375b151ddaef5f1507Trond Norbye if (activeProject != null) {
96c1ae30d032621b47c4ac375b151ddaef5f1507Trond Norbye Set<String> projects = cfg.getRequestedProjects();
96c1ae30d032621b47c4ac375b151ddaef5f1507Trond Norbye if (!projects.contains(activeProject.getDescription())) {
96c1ae30d032621b47c4ac375b151ddaef5f1507Trond Norbye projects.add(activeProject.getDescription());
96c1ae30d032621b47c4ac375b151ddaef5f1507Trond Norbye // update cookie
96c1ae30d032621b47c4ac375b151ddaef5f1507Trond Norbye cookieValue = cookieValue.length() == 0
96c1ae30d032621b47c4ac375b151ddaef5f1507Trond Norbye ? activeProject.getDescription()
96c1ae30d032621b47c4ac375b151ddaef5f1507Trond Norbye : activeProject.getDescription() + '/' + cookieValue;
96c1ae30d032621b47c4ac375b151ddaef5f1507Trond Norbye Cookie cookie = new Cookie("OpenGrokProject", cookieValue);
96c1ae30d032621b47c4ac375b151ddaef5f1507Trond Norbye // TODO hmmm, projects.jspf doesn't set a path
96c1ae30d032621b47c4ac375b151ddaef5f1507Trond Norbye cookie.setPath(request.getContextPath() + '/');
96c1ae30d032621b47c4ac375b151ddaef5f1507Trond Norbye response.addCookie(cookie);
}
}
// requesting a directory listing
DirectoryListing dl = new DirectoryListing(cfg.getEftarReader());
List<String> files = cfg.getResourceFileList();
if (!files.isEmpty()) {
List<String> readMes = dl.listTo(resourceFile, out, path, files);
File[] catfiles = cfg.findDataFiles(readMes);
for (int i=0; i < catfiles.length; i++) {
if (catfiles[i] == null) {
continue;
}
%><h3><%= readMes.get(i) %></h3>
<div id="src<%=i%>">
<pre><%
Util.dump(out, catfiles[i], catfiles[i].getName().endsWith(".gz"));
%></pre>
</div><%
}
}
} else if (rev.length() != 0) {
// requesting a previous revision
FileAnalyzerFactory a = AnalyzerGuru.find(basename);
Genre g = AnalyzerGuru.getGenre(a);
String error = null;
if (g == Genre.PLAIN|| g == Genre.HTML || g == null) {
InputStream in = null;
try {
in = HistoryGuru.getInstance()
.getRevision(resourceFile.getParent(), basename, rev.substring(2));
} catch (Exception e) {
// fall through to error message
error = e.getMessage();
}
if (in != null) {
try {
if (g == null) {
a = AnalyzerGuru.find(in);
g = AnalyzerGuru.getGenre(a);
}
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"
%>