list.jsp revision 1389
0N/A<%--
157N/A$Id$
0N/A
0N/ACDDL HEADER START
0N/A
0N/AThe contents of this file are subject to the terms of the
157N/ACommon Development and Distribution License (the "License").
0N/AYou may not use this file except in compliance with the License.
157N/A
0N/ASee LICENSE.txt included in this distribution for the specific
0N/Alanguage governing permissions and limitations under the License.
0N/A
0N/AWhen distributing Covered Code, include this CDDL HEADER in each
0N/Afile and include the License file at LICENSE.txt.
0N/AIf applicable, add the following below this CDDL HEADER, with the
0N/Afields enclosed by brackets "[]" replaced with your own identifying
0N/Ainformation: Portions Copyright [yyyy] [name of copyright owner]
0N/A
0N/ACDDL HEADER END
0N/A
157N/ACopyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
157N/APortions Copyright 2011, 2012 Jens Elkner.
157N/A
0N/A--%><%@page session="false" errorPage="error.jsp" import="
0N/Ajava.io.BufferedInputStream,
0N/Ajava.io.File,
0N/Ajava.io.IOException,
0N/Ajava.io.FileInputStream,
0N/Ajava.io.InputStream,
0N/Ajava.io.InputStreamReader,
0N/Ajava.io.Reader,
0N/Ajava.text.Format,
0N/Ajava.text.SimpleDateFormat,
0N/Ajava.util.ArrayList,
0N/Ajava.util.List,
0N/Ajava.util.Set,
0N/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.analysis.XrefInputStream,
org.opensolaris.opengrok.analysis.XrefWriter,
org.opensolaris.opengrok.history.Annotation,
org.opensolaris.opengrok.history.HistoryGuru,
org.opensolaris.opengrok.index.IgnoredNames,
org.opensolaris.opengrok.index.IndexDatabase,
org.opensolaris.opengrok.util.IOUtils,
org.opensolaris.opengrok.web.EftarFileReader"
%><%
{
// 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) {
float r = annotation.getWidestRevision() * 1.15f;
float a = annotation.getWidestAuthor() * 1.15f;
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"
%><%
/* ---------------------- 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.RAW_P + path;
Reader r = null;
if (cfg.isDir()) {
// directory listing
// valid resource is requested: mast.jsp assures, that resourceFile is
// valid and not the source root "/"
// 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("OpenGrokProject", cookieValue);
// TODO hmmm, projects.jspf doesn't set a path
cookie.setPath(request.getContextPath() + '/');
response.addCookie(cookie);
}
}
List<String> files = cfg.getResourceFileList();
if (!files.isEmpty()) {
long now = System.currentTimeMillis();
ArrayList<String> readMes = new ArrayList<String>();
int offset = -1;
EftarFileReader.FNode parentFNode = null;
EftarFileReader desc = cfg.getEftarReader();
if (desc != null) {
parentFNode = desc.getNode(path);
if (parentFNode != null) {
offset = parentFNode.childOffset;
}
}
%><table id="dirlist">
<thead>
<tr>
<th/>
<th>Name</th>
<th>Date</th>
<th>Size</th><%
if (offset > 0) {
%> <th>Description</th><%
}
%>
</tr>
</thead>
<tbody><%
IgnoredNames ignoredNames = cfg.getIgnoredNames();
Format dateFormatter = new SimpleDateFormat("dd-MMM-yyyy");
// upper directory
if (path.length() != 0) {
long lastm = resourceFile.getParentFile().lastModified();
%>
<tr>
<td><p class="u"/></td>
<td><b><a href="..">..</a></b></td>
<td><%= now-lastm < 86400000 ? "Today" : dateFormatter.format(lastm) %></td>
<td><%= Util.readableSize(resourceFile.getParentFile().length()) %></td><%
if (offset > 0) { %>
<td/><%
} %>
</tr><%
}
// entries
for (String file : files) {
if (ignoredNames.ignore(file)) {
continue;
}
File child = new File(resourceFile, file);
if ((file.startsWith("README") || file.endsWith("README")
|| file.startsWith("readme")) && child.isFile())
{
readMes.add(file);
}
boolean isDir = child.isDirectory();
long lastm = child.lastModified();
%>
<tr>
<td><p class="<%= isDir ? 'v' : 'w' %>"/></td>
<td><a href="<%= Util.URIEncodePath(file) %>"><%= isDir ? "<b>" + file + "</b>" : file %></a></td>
<td><%= now-lastm < 86400000 ? "Today" : dateFormatter.format(lastm) %></td>
<td><%= Util.readableSize(child.length()) %></td><%
if (offset > 0) {
String briefDesc = desc.getChildTag(parentFNode, file); %>
<td><%= briefDesc == null ? "" : briefDesc %></td><%
} %>
</tr><%
}
%>
</tbody>
</table>
<div id="src"><%
if (readMes.size() != 0) {
ArrayList<String> readMesImg = null;
File[] xrefs = cfg.findDataFiles(readMes);
for (int i=0; i < xrefs.length; i++) {
File readme = xrefs[i];
boolean pre = false;
if (readme == null) { // no xref avail or outdated or img
readme = new File(resourceFile, readMes.get(i));
Genre g = AnalyzerGuru.getGenre(readme.getName());
if (g == null) {
BufferedInputStream in = null;
try {
in = new BufferedInputStream(new FileInputStream(readme));
g = AnalyzerGuru.getGenre(in);
} catch (Exception e) {
// ignore
} finally {
IOUtils.close(in);
}
}
if (g == Genre.IMAGE) {
if (readMesImg == null) {
readMesImg = new ArrayList<String>(3);
}
readMesImg.add(readme.getName());
continue;
} else if (g != Genre.HTML && g != Genre.PLAIN) {
continue;
}
pre = true;
// else dump
}
%>
<h3><%= readMes.get(i) %></h3><%
if (pre) {
out.write("<pre>");
}
if (xrefs[i] != null) {
XrefInputStream.dump(xrefs[i], out, false);
} else {
Util.dump(out,readme, readme.getName().endsWith(".gz"));
}
if (pre) {
out.write("</pre>");
}
}
if (readMesImg != null) {
for (String image : readMesImg) {
%>
<h3><%= image %></h3>
<img src="<%= Util.URIEncodePath(rawPath + '/' + image) %>"/><%
}
}
}
%>
</div><%
}
// end of directory listing
} else if (rev.length() != 0) {
// list a previous revision of a file
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) {
XrefWriter xout = 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="<%= Util.URIEncodePath(rawPath) %>?<%= rev
%>">here</a> to download]
</div><%
} else {
%>
<div id="src">
<span class="pagetitle"><%= basename %> revision <%=
rev.substring(2) %></span><%
if (g == Genre.PLAIN) {
%>
<div id='linenums'></div><div id='annos'></div><%
// We don't have any way to get definitions
// for old revisions currently.
Definitions defs = null;
Annotation annotation = cfg.getAnnotation();
r = new InputStreamReader(in);
xout = new XrefWriter(out);
AnalyzerGuru.writeXref(a, r, xout , defs,
annotation, Project.getProject(resourceFile));
} else if (g == Genre.IMAGE) {
%>
<img src="<%= Util.URIEncodePath(rawPath) %>?<%= rev %>"/><%
} else if (g == Genre.HTML) {
r = new InputStreamReader(in);
Util.dump(out, r);
} else {
%> Click <a href="<%= Util.URIEncodePath(rawPath) %>?<%=
rev %>">download <%= basename %></a><%
}
}
} catch (IOException e) {
error = e.getMessage();
} finally {
if (r != null) {
try { r.close(); in = null;}
catch (Exception e) { /* ignore */ }
}
IOUtils.close(in);
IOUtils.close(xout);
}
%>
</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="<%= Util.URIEncodePath(rawPath) %>?<%= rev %>"/>
</div><%
} else {
%>
<div id="src">
Binary file [Click <a href="<%= Util.URIEncodePath(rawPath) %>?<%= rev
%>">here</a> to download]
</div><%
}
// end list a previous revision of a file
} else {
// list current version of a file
File xrefFile = null;
if (!cfg.annotate()) {
xrefFile = cfg.findDataFile();
}
if (xrefFile != null) {
// dump cross file
%>
<div id="src"><div id='linenums'></div><div id='annos'></div><%
XrefInputStream.dump(xrefFile, out, true);
%>
</div><%
// end dump cross file
} else {
// dump [annotated] source file
BufferedInputStream bin =
new BufferedInputStream(new FileInputStream(resourceFile));
XrefWriter xout = null;
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="<%= Util.URIEncodePath(rawPath) %>"/>
</div><%
} else if (g == Genre.HTML) {
r = new InputStreamReader(bin);
Util.dump(out, r);
} else if (g == Genre.PLAIN) {
%>
<div id="src"><div id='linenums'></div><div id='annos'></div><%
// 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);
xout = new XrefWriter(out);
AnalyzerGuru.writeXref(a, r, xout, defs, annotation,
Project.getProject(resourceFile));
%>
</div><%
} else {
%>
Click <a href="<%= Util.URIEncodePath(rawPath) %>">download <%= basename %></a><%
}
} finally {
if (r != null) {
try { r.close(); bin = null; }
catch (Exception e) { /* ignore */ }
}
IOUtils.close(bin);
IOUtils.close(xout);
}
// end dump [annotated] source file
}
// end list current version of a file
}
}
/* ---------------------- list.jsp end --------------------- */
%><%@
include file="foot.jspf"
%>