list.jsp revision 9158900bac6adc966217d308f9ddea9f5eb540c7
2N/A<%--
2N/A$Id$
2N/A
2N/ACDDL HEADER START
2N/A
2N/AThe contents of this file are subject to the terms of the
2N/ACommon Development and Distribution License (the "License").
2N/AYou may not use this file except in compliance with the License.
2N/A
2N/ASee LICENSE.txt included in this distribution for the specific
2N/Alanguage governing permissions and limitations under the License.
2N/A
2N/AWhen distributing Covered Code, include this CDDL HEADER in each
2N/Afile and include the License file at LICENSE.txt.
2N/AIf applicable, add the following below this CDDL HEADER, with the
2N/Afields enclosed by brackets "[]" replaced with your own identifying
2N/Ainformation: Portions Copyright [yyyy] [name of copyright owner]
2N/A
2N/ACDDL HEADER END
2N/A
2N/ACopyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved.
2N/APortions Copyright 2011 Jens Elkner.
2N/A
2N/A--%>
2N/A<%@page import="
2N/Ajava.io.BufferedInputStream,
2N/Ajava.io.BufferedReader,
2N/Ajava.io.FileInputStream,
2N/Ajava.io.FileReader,
2N/Ajava.io.InputStream,
2N/Ajava.io.InputStreamReader,
2N/Ajava.io.Reader,
2N/Ajava.net.URLEncoder,
2N/Ajava.util.ArrayList,
2N/Ajava.util.Arrays,
2N/Ajava.util.List,
2N/Ajava.util.Set,
2N/Ajava.util.logging.Level,
2N/Ajava.util.zip.GZIPInputStream,
2N/A
org.opensolaris.opengrok.analysis.AnalyzerGuru,
org.opensolaris.opengrok.analysis.Definitions,
org.opensolaris.opengrok.analysis.FileAnalyzer.Genre,
org.opensolaris.opengrok.analysis.FileAnalyzerFactory,
org.opensolaris.opengrok.history.Annotation,
org.opensolaris.opengrok.index.IndexDatabase,
org.opensolaris.opengrok.web.DirectoryListing"
%><%
{
// need to set it here since requesting parameters
if (request.getCharacterEncoding() == null) {
request.setCharacterEncoding("UTF-8");
}
cfg = PageConfig.get(request);
Annotation annotation = cfg.getAnnotation();
if (annotation != null) {
int r = annotation.getWidestRevision();
int a = annotation.getWidestAuthor();
cfg.addHeaderData("<style type=\"text/css\">"
+ ".blame .r { width: " + (r == 0 ? 6 : r) + "ex; } "
+ ".blame .a { width: " + (a == 0 ? 6 : a) + "ex; } "
+ "</style>");
}
}
%><%@include
file="mast.jsp"
%><script type="text/javascript">/* <![CDATA[ */
document.pageReady.push(function() { pageReadyList();});
/* ]]> */</script>
<%
/* ---------------------- list.jsp start --------------------- */
{
cfg = PageConfig.get(request);
String rev = cfg.getRequestedRevision();
File resourceFile = cfg.getResourceFile();
String path = cfg.getPath();
String basename = resourceFile.getName();
String rawPath = request.getContextPath() + Prefix.DOWNLOAD_P + path;
Reader r = null;
if (cfg.isDir()) {
// valid resource is requested
// mast.jsp assures, that resourceFile is valid and not /
// see cfg.resourceNotAvailable()
Project activeProject = Project.getProject(resourceFile);
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(PageConfig.OPEN_GROK_PROJECT, URLEncoder.encode(cookieValue, "utf-8"));
// 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(
Util.URIEncodePath(request.getContextPath()),
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);
} 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 %>?r=<%= Util.URIEncode(rev) %>">here</a> to download]
</div><%
} else {
%>
<div id="src">
<span class="pagetitle"><%= basename %> revision <%= Util.htmlize(rev) %></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 %>?r=<%= Util.URIEncode(rev) %>"/>
<pre><%
} else if (g == Genre.HTML) {
r = new InputStreamReader(in);
Util.dump(out, r);
} else {
%> Click <a href="<%= rawPath %>?r=<%= Util.URIEncode(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 %>?r=<%= Util.URIEncode(rev) %>"/>
</div><%
} else {
%>
<div id="src">
Binary file [Click <a href="<%= rawPath %>?r=<%= Util.URIEncode(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"
%>