list.jsp revision 59b6a8c0cc6ef741a7180504b3c371e67c2aa338
eb32a77fdb57f20c042b7b79b28a4fb4060cb949Lubos Kosco<%--
eb32a77fdb57f20c042b7b79b28a4fb4060cb949Lubos Kosco$Id$
eb32a77fdb57f20c042b7b79b28a4fb4060cb949Lubos Kosco
eb32a77fdb57f20c042b7b79b28a4fb4060cb949Lubos KoscoCDDL HEADER START
eb32a77fdb57f20c042b7b79b28a4fb4060cb949Lubos Kosco
eb32a77fdb57f20c042b7b79b28a4fb4060cb949Lubos KoscoThe contents of this file are subject to the terms of the
eb32a77fdb57f20c042b7b79b28a4fb4060cb949Lubos KoscoCommon Development and Distribution License (the "License").
eb32a77fdb57f20c042b7b79b28a4fb4060cb949Lubos KoscoYou may not use this file except in compliance with the License.
eb32a77fdb57f20c042b7b79b28a4fb4060cb949Lubos Kosco
eb32a77fdb57f20c042b7b79b28a4fb4060cb949Lubos KoscoSee LICENSE.txt included in this distribution for the specific
eb32a77fdb57f20c042b7b79b28a4fb4060cb949Lubos Koscolanguage governing permissions and limitations under the License.
eb32a77fdb57f20c042b7b79b28a4fb4060cb949Lubos Kosco
eb32a77fdb57f20c042b7b79b28a4fb4060cb949Lubos KoscoWhen distributing Covered Code, include this CDDL HEADER in each
eb32a77fdb57f20c042b7b79b28a4fb4060cb949Lubos Koscofile and include the License file at LICENSE.txt.
eb32a77fdb57f20c042b7b79b28a4fb4060cb949Lubos KoscoIf applicable, add the following below this CDDL HEADER, with the
eb32a77fdb57f20c042b7b79b28a4fb4060cb949Lubos Koscofields enclosed by brackets "[]" replaced with your own identifying
eb32a77fdb57f20c042b7b79b28a4fb4060cb949Lubos Koscoinformation: Portions Copyright [yyyy] [name of copyright owner]
eb32a77fdb57f20c042b7b79b28a4fb4060cb949Lubos Kosco
eb32a77fdb57f20c042b7b79b28a4fb4060cb949Lubos KoscoCDDL HEADER END
eb32a77fdb57f20c042b7b79b28a4fb4060cb949Lubos Kosco
4750e1be4c1b2ba11705d5b73b86dd1b9dd4e1acKnut Anders HatlenCopyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
eb32a77fdb57f20c042b7b79b28a4fb4060cb949Lubos KoscoPortions Copyright 2011 Jens Elkner.
4750e1be4c1b2ba11705d5b73b86dd1b9dd4e1acKnut Anders Hatlen
eb32a77fdb57f20c042b7b79b28a4fb4060cb949Lubos Kosco--%><%@page import="
eb32a77fdb57f20c042b7b79b28a4fb4060cb949Lubos Koscojava.io.BufferedInputStream,
4750e1be4c1b2ba11705d5b73b86dd1b9dd4e1acKnut Anders Hatlenjava.io.BufferedReader,
bfc104f8240fac5b59d4347db4c27be705f6dfc2Knut Anders Hatlenjava.io.FileInputStream,
4750e1be4c1b2ba11705d5b73b86dd1b9dd4e1acKnut Anders Hatlenjava.io.FileReader,
eb32a77fdb57f20c042b7b79b28a4fb4060cb949Lubos Koscojava.io.InputStream,
b645988bdc1cf4f2f82b8c00ed041ddddd822c24Lubos Koscojava.io.InputStreamReader,
b645988bdc1cf4f2f82b8c00ed041ddddd822c24Lubos Koscojava.io.Reader,
b645988bdc1cf4f2f82b8c00ed041ddddd822c24Lubos Koscojava.util.ArrayList,
eb32a77fdb57f20c042b7b79b28a4fb4060cb949Lubos Koscojava.util.Arrays,
eb32a77fdb57f20c042b7b79b28a4fb4060cb949Lubos Koscojava.util.List,
eb32a77fdb57f20c042b7b79b28a4fb4060cb949Lubos Koscojava.util.Set,
b645988bdc1cf4f2f82b8c00ed041ddddd822c24Lubos Koscojava.util.logging.Level,
b645988bdc1cf4f2f82b8c00ed041ddddd822c24Lubos Koscojava.util.zip.GZIPInputStream,
b645988bdc1cf4f2f82b8c00ed041ddddd822c24Lubos Kosco
b645988bdc1cf4f2f82b8c00ed041ddddd822c24Lubos Koscoorg.opensolaris.opengrok.OpenGrokLogger,
eb32a77fdb57f20c042b7b79b28a4fb4060cb949Lubos Koscoorg.opensolaris.opengrok.analysis.AnalyzerGuru,
eb32a77fdb57f20c042b7b79b28a4fb4060cb949Lubos Koscoorg.opensolaris.opengrok.analysis.Definitions,
eb32a77fdb57f20c042b7b79b28a4fb4060cb949Lubos Koscoorg.opensolaris.opengrok.analysis.FileAnalyzer.Genre,
eb32a77fdb57f20c042b7b79b28a4fb4060cb949Lubos Koscoorg.opensolaris.opengrok.analysis.FileAnalyzerFactory,
eb32a77fdb57f20c042b7b79b28a4fb4060cb949Lubos Koscoorg.opensolaris.opengrok.history.Annotation,
eb32a77fdb57f20c042b7b79b28a4fb4060cb949Lubos Koscoorg.opensolaris.opengrok.index.IndexDatabase,
eb32a77fdb57f20c042b7b79b28a4fb4060cb949Lubos Koscoorg.opensolaris.opengrok.web.DirectoryListing"
b645988bdc1cf4f2f82b8c00ed041ddddd822c24Lubos Kosco%><%
bfc104f8240fac5b59d4347db4c27be705f6dfc2Knut Anders Hatlen{
4750e1be4c1b2ba11705d5b73b86dd1b9dd4e1acKnut Anders Hatlen // need to set it here since requesting parameters
bfc104f8240fac5b59d4347db4c27be705f6dfc2Knut Anders Hatlen if (request.getCharacterEncoding() == null) {
4750e1be4c1b2ba11705d5b73b86dd1b9dd4e1acKnut Anders Hatlen request.setCharacterEncoding("UTF-8");
4750e1be4c1b2ba11705d5b73b86dd1b9dd4e1acKnut Anders Hatlen }
4750e1be4c1b2ba11705d5b73b86dd1b9dd4e1acKnut Anders Hatlen cfg = PageConfig.get(request);
4750e1be4c1b2ba11705d5b73b86dd1b9dd4e1acKnut Anders Hatlen Annotation annotation = cfg.getAnnotation();
4750e1be4c1b2ba11705d5b73b86dd1b9dd4e1acKnut Anders Hatlen if (annotation != null) {
4750e1be4c1b2ba11705d5b73b86dd1b9dd4e1acKnut Anders Hatlen int r = annotation.getWidestRevision();
4750e1be4c1b2ba11705d5b73b86dd1b9dd4e1acKnut Anders Hatlen int a = annotation.getWidestAuthor();
4750e1be4c1b2ba11705d5b73b86dd1b9dd4e1acKnut Anders Hatlen cfg.addHeaderData("<style type=\"text/css\">"
4750e1be4c1b2ba11705d5b73b86dd1b9dd4e1acKnut Anders Hatlen + ".blame .r { width: " + (r == 0 ? 6 : r) + "ex; } "
4750e1be4c1b2ba11705d5b73b86dd1b9dd4e1acKnut Anders Hatlen + ".blame .a { width: " + (a == 0 ? 6 : a) + "ex; } "
4750e1be4c1b2ba11705d5b73b86dd1b9dd4e1acKnut Anders Hatlen + "</style>");
bfc104f8240fac5b59d4347db4c27be705f6dfc2Knut Anders Hatlen }
bfc104f8240fac5b59d4347db4c27be705f6dfc2Knut Anders Hatlen}
bfc104f8240fac5b59d4347db4c27be705f6dfc2Knut Anders Hatlen%><%@include
bfc104f8240fac5b59d4347db4c27be705f6dfc2Knut Anders Hatlen
bfc104f8240fac5b59d4347db4c27be705f6dfc2Knut Anders Hatlenfile="mast.jsp"
50203181d8c071cfd69cb197b5da0eda5c4d6372Jens Elkner
50203181d8c071cfd69cb197b5da0eda5c4d6372Jens Elkner%><script type="text/javascript">/* <![CDATA[ */
50203181d8c071cfd69cb197b5da0eda5c4d6372Jens Elknerdocument.pageReady.push(function() { pageReadyList();});
c6e0f8b39af7343c04ec7558a085c965159f4ea0Lubos Kosco/* ]]> */</script>
eb32a77fdb57f20c042b7b79b28a4fb4060cb949Lubos Kosco<%
b645988bdc1cf4f2f82b8c00ed041ddddd822c24Lubos Kosco/* ---------------------- list.jsp start --------------------- */
b645988bdc1cf4f2f82b8c00ed041ddddd822c24Lubos Kosco{
eb32a77fdb57f20c042b7b79b28a4fb4060cb949Lubos Kosco cfg = PageConfig.get(request);
b645988bdc1cf4f2f82b8c00ed041ddddd822c24Lubos Kosco String rev = cfg.getRequestedRevision();
eb32a77fdb57f20c042b7b79b28a4fb4060cb949Lubos Kosco
b645988bdc1cf4f2f82b8c00ed041ddddd822c24Lubos Kosco File resourceFile = cfg.getResourceFile();
b645988bdc1cf4f2f82b8c00ed041ddddd822c24Lubos Kosco String path = cfg.getPath();
b645988bdc1cf4f2f82b8c00ed041ddddd822c24Lubos Kosco String basename = resourceFile.getName();
b645988bdc1cf4f2f82b8c00ed041ddddd822c24Lubos Kosco String rawPath = request.getContextPath() + Prefix.RAW_P + path;
817883e9f0d419428e8236a09b77cdeeaa034df7Knut Anders Hatlen Reader r = null;
be5cdf850da5383468637c6937c016f26bd339cfLubos Kosco if (cfg.isDir()) {
b645988bdc1cf4f2f82b8c00ed041ddddd822c24Lubos Kosco // valid resource is requested
817883e9f0d419428e8236a09b77cdeeaa034df7Knut Anders Hatlen // mast.jsp assures, that resourceFile is valid and not /
b645988bdc1cf4f2f82b8c00ed041ddddd822c24Lubos Kosco // see cfg.resourceNotAvailable()
b645988bdc1cf4f2f82b8c00ed041ddddd822c24Lubos Kosco Project activeProject = Project.getProject(resourceFile);
eb32a77fdb57f20c042b7b79b28a4fb4060cb949Lubos Kosco String cookieValue = cfg.getRequestedProjectsAsString();
if (activeProject != null) {
Set<String> projects = cfg.getRequestedProjects();
if (!projects.contains(activeProject.getDescription())) {
projects.add(activeProject.getDescription());
// update cookie
cookieValue = cookieValue.length() == 0
? activeProject.getDescription()
: activeProject.getDescription() + '/' + cookieValue;
Cookie cookie = new Cookie("OpenGrokProject", cookieValue);
// TODO hmmm, projects.jspf doesn't set a path
cookie.setPath(request.getContextPath() + '/');
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">
<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"
%>