<%--
$Id$
CDDL HEADER START
The contents of this file are subject to the terms of the
Common Development and Distribution License (the "License").
You may not use this file except in compliance with the License.
See LICENSE.txt included in this distribution for the specific
language governing permissions and limitations under the License.
When distributing Covered Code, include this CDDL HEADER in each
file and include the License file at LICENSE.txt.
If applicable, add the following below this CDDL HEADER, with the
fields enclosed by brackets "[]" replaced with your own identifying
information: Portions Copyright [yyyy] [name of copyright owner]
CDDL HEADER END
Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
Portions Copyright 2011, 2012 Jens Elkner.
--%><%@page session="false" errorPage="error.jsp" import="
%><%
{
// 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\">"
+ ".r { width: " + (r == 0 ? 6 : r) + "ex; } "
+ ".a { width: " + (a == 0 ? 6 : a) + "ex; } "
+ "</style>");
}
}
%><%@include
file="mast.jspf"
%><%
/* ---------------------- 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
boolean virtual =
basename.isEmpty() || request.getParameter("all") != null;
Project activeProject = Project.getProject(path);
if (activeProject != null) {
Set<String> projects = cfg.getRequestedProjects();
if (!projects.contains(activeProject.getDescription())) {
String cookieValue = cfg.getRequestedProjectsAsString();
// update cookie
cookieValue = cookieValue.length() == 0
: 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);
}
}
LinkedHashMap<String,String> path2rev =
virtual ? new LinkedHashMap<String,String>() : null;
Map<String, Date> modTimes = HistoryGuru.getInstance()
.getLastModifiedTimes(new File(cfg.getSourceRootPath() + path), path2rev);
List<String> files = virtual
? new ArrayList<String>(modTimes.keySet())
if (virtual) {
// to be consistent with resource file listing
}
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><%= virtual ? "Revision" : "Size" %></th><%
if (offset > 0) {
%> <th>Description</th><%
}
%>
</tr>
</thead>
<tbody><%
IgnoredNames ignoredNames = cfg.getIgnoredNames();
Format dateFormatter =
new SimpleDateFormat(cfg.getConfig().getDirlistDatePattern());
boolean useToday = cfg.getConfig().isDirlistUseToday();
// upper directory
if (path.length() != 0) {
long lastm = 0;
if (!modTimes.isEmpty()) {
for (Date d : modTimes.values()) {
long l = d.getTime();
if (l > lastm) {
lastm = l;
}
}
} else if (!virtual) {
lastm = resourceFile.getParentFile().lastModified();
} else {
lastm = now;
}
String css = now - lastm < 86400000 ? " class='x'" : "";
%>
<tr>
<td><p class="u"/></td>
<td><b><a href="..">..</a></b></td>
<td<%= css%>><%= useToday && now - lastm < 86400000
? "Today" : dateFormatter.format(lastm) %></td>
<td><%= virtual
? path2rev.size() + " entries"
: resourceFile.getParentFile().length() + ""
%></td><%
if (offset > 0) { %>
<td/><%
} %>
</tr><%
}
// entries
boolean isDir;
long lastm;
String size;
String link;
for (String file : files) {
if (ignoredNames.match(file)) {
continue;
}
if (virtual) {
isDir = file.endsWith("/");
lastm = modTimes.get(file).getTime();
size = path2rev.get(file);
// we do not display any readmes for virtual dirs
link = Util.uriEncodePath(file);
if (!isDir) {
link += "?r=" + size;
}
} else {
File child = new File(resourceFile, file);
if ((file.startsWith("README") || file.endsWith("README")
|| file.startsWith("readme")) && child.isFile())
{
readMes.add(file);
}
isDir = child.isDirectory();
Date lmd = modTimes.get(isDir ? file + '/' : file);
lastm = lmd == null ? child.lastModified() : lmd.getTime();
size = Util.readableSize(child.length());
link = Util.uriEncodePath(file);
}
String css = now - lastm < 86400000 ? " class='x'" : "";
%>
<tr>
<td><p class="<%= isDir ? 'v' : 'w' %>"/></td>
<td><a href="<%= link %>"><%= isDir ? "<b>"
+ Util.htmlize(file) + "</b>" : Util.htmlize(file) %></a></td>
<td<%= css%>><%= useToday && now-lastm < 86400000
? "Today" : dateFormatter.format(lastm) %></td>
<td><%= size %></td><%
if (offset > 0) {
String briefDesc = desc.getChildTag(parentFNode, file); %>
<td><%= briefDesc == null ? "" : Util.htmlize(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);
}
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 {
// not clean, but usually works
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
String parent = resourceFile.getParent();
if (basename.isEmpty()) {
// virtual file
int idx = path.lastIndexOf('/');
if (idx != -1) {
basename = path.substring(idx+1);
parent = cfg.getSourceRootPath() + '/' + path.substring(0, idx);
}
}
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(parent, basename, rev.substring(2));
} catch (Exception e) {
// fall through to error message
error = e.getMessage();
}
if (in != null) {
XrefWriter xout = null;
try {
// we don't get enough info from history guru, that's why
// this little hack to emp. detect deleted/moved files
in.mark(2);
int b = in.read();
in.reset();
if (b == -1) {
%>
<div id="src"></div>
<p><%= basename %> for revision <%= rev.substring(2) %> is empty. It was
probably moved to a different location or deleted. A click on the <b>History</b>
button may reveal more details.</p>
<%
} else {
if (g == null) {
a = AnalyzerGuru.find(in);
g = AnalyzerGuru.getGenre(a);
}
if (g == Genre.DATA || g == Genre.XREFABLE || g == null) {
%>
<div id="src"></div>
<p>Binary file [Click <a href="<%= Util.uriEncodePath(rawPath) %>?<%= rev
%>">here</a> to download]</p><%
} else {
%>
<div id="src">
<span class="pagetitle"><%= Util.htmlize(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 <%= Util.htmlize(basename) %></a><%
}
%>
</div><%
}
}
} 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);
}
} 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"></div>
<p>Binary file [Click <a href="<%= Util.uriEncodePath(rawPath) %>?<%= rev
%>">here</a> to download]</p><%
}
// 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 <%=
Util.htmlize(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"
%>