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