list.jsp revision 1354
335N/A<%--
1186N/A$Id$
1186N/A
0N/ACDDL HEADER START
0N/A
0N/AThe contents of this file are subject to the terms of the
335N/ACommon Development and Distribution License (the "License").
0N/AYou may not use this file except in compliance with the License.
0N/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
1244N/ACopyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
1186N/APortions Copyright 2011 Jens Elkner.
1186N/A
1325N/A--%><%@ page session="false" errorPage="error.jsp" import="
1186N/Ajava.io.BufferedInputStream,
1186N/Ajava.io.FileInputStream,
1186N/Ajava.io.InputStream,
1186N/Ajava.io.InputStreamReader,
1186N/Ajava.io.Reader,
1325N/Ajava.text.Format,
1325N/Ajava.text.SimpleDateFormat,
1186N/Ajava.util.ArrayList,
1186N/Ajava.util.List,
1186N/Ajava.util.Set,
1186N/A
1186N/Aorg.opensolaris.opengrok.analysis.AnalyzerGuru,
1127N/Aorg.opensolaris.opengrok.analysis.Definitions,
0N/Aorg.opensolaris.opengrok.analysis.FileAnalyzer.Genre,
1186N/Aorg.opensolaris.opengrok.analysis.FileAnalyzerFactory,
1186N/Aorg.opensolaris.opengrok.history.Annotation,
1325N/Aorg.opensolaris.opengrok.index.IgnoredNames,
1325N/Aorg.opensolaris.opengrok.index.IndexDatabase"
1281N/A%><%
1108N/A{
1281N/A // need to set it here since requesting parameters
1281N/A if (request.getCharacterEncoding() == null) {
1281N/A request.setCharacterEncoding("UTF-8");
1281N/A }
1281N/A cfg = PageConfig.get(request);
1281N/A Annotation annotation = cfg.getAnnotation();
1281N/A if (annotation != null) {
1354N/A float r = annotation.getWidestRevision() * 1.15f;
1354N/A float a = annotation.getWidestAuthor() * 1.15f;
1281N/A cfg.addHeaderData("<style type=\"text/css\">"
1281N/A + ".blame .r { width: " + (r == 0 ? 6 : r) + "ex; } "
1281N/A + ".blame .a { width: " + (a == 0 ? 6 : a) + "ex; } "
1281N/A + "</style>");
1281N/A }
1145N/A}
1281N/A%><%@include
1108N/A
1186N/Afile="mast.jsp"
335N/A
1186N/A%><script type="text/javascript">/* <![CDATA[ */
1354N/AO.pageReady.push(O.pageReadyList);
1186N/A/* ]]> */</script>
1186N/A<%
1186N/A/* ---------------------- list.jsp start --------------------- */
1186N/A{
1281N/A cfg = PageConfig.get(request);
1281N/A String rev = cfg.getRequestedRevision();
1281N/A
1281N/A File resourceFile = cfg.getResourceFile();
1281N/A String path = cfg.getPath();
1281N/A String basename = resourceFile.getName();
1281N/A String rawPath = request.getContextPath() + Prefix.RAW_P + path;
1281N/A Reader r = null;
1281N/A if (cfg.isDir()) {
1281N/A // valid resource is requested
1281N/A // mast.jsp assures, that resourceFile is valid and not /
1281N/A // see cfg.resourceNotAvailable()
1281N/A Project activeProject = Project.getProject(resourceFile);
1281N/A String cookieValue = cfg.getRequestedProjectsAsString();
1281N/A if (activeProject != null) {
1281N/A Set<String> projects = cfg.getRequestedProjects();
1281N/A if (!projects.contains(activeProject.getDescription())) {
1281N/A projects.add(activeProject.getDescription());
1281N/A // update cookie
1281N/A cookieValue = cookieValue.length() == 0
1281N/A ? activeProject.getDescription()
1281N/A : activeProject.getDescription() + '/' + cookieValue;
1281N/A Cookie cookie = new Cookie("OpenGrokProject", cookieValue);
1281N/A // TODO hmmm, projects.jspf doesn't set a path
1281N/A cookie.setPath(request.getContextPath() + '/');
1281N/A response.addCookie(cookie);
1281N/A }
1281N/A }
1325N/A
1325N/A // directory listing
1281N/A List<String> files = cfg.getResourceFileList();
1281N/A if (!files.isEmpty()) {
1325N/A long now = System.currentTimeMillis();
1325N/A ArrayList<String> readMes = new ArrayList<String>();
1325N/A int offset = -1;
1325N/A EftarFileReader.FNode parentFNode = null;
1325N/A EftarFileReader desc = cfg.getEftarReader();
1325N/A if (desc != null) {
1325N/A parentFNode = desc.getNode(path);
1325N/A if (parentFNode != null) {
1325N/A offset = parentFNode.childOffset;
1325N/A }
1325N/A }
1325N/A%><table id="dirlist">
1325N/A<thead>
1325N/A<tr>
1325N/A <th/>
1325N/A <th>Name</th>
1325N/A <th>Date</th>
1325N/A <th>Size</th><%
1325N/A if (offset > 0) {
1325N/A%> <th><tt>Description</tt></th><%
1325N/A }
1325N/A%>
1325N/A</tr>
1325N/A</thead>
1325N/A<tbody><%
1325N/A IgnoredNames ignoredNames = cfg.getIgnoredNames();
1325N/A Format dateFormatter = new SimpleDateFormat("dd-MMM-yyyy");
1325N/A // upper directory
1325N/A if (path.length() != 0) {
1325N/A long lastm = resourceFile.getParentFile().lastModified();
1325N/A%>
1325N/A<tr>
1325N/A <td><p class="r"/></td>
1325N/A <td><b><a href="..">..</a></b></td>
1325N/A <td><%= now-lastm < 86400000 ? "Today" : dateFormatter.format(lastm) %></td>
1325N/A <td><%= Util.readableSize(resourceFile.getParentFile().length()) %></td><%
1325N/A if (offset > 0) { %>
1325N/A <td/><%
1325N/A } %>
1325N/A</tr><%
1325N/A }
1325N/A // entries
1325N/A for (String file : files) {
1325N/A if (ignoredNames.ignore(file)) {
1325N/A continue;
1325N/A }
1325N/A File child = new File(resourceFile, file);
1325N/A if (file.startsWith("README") || file.endsWith("README")
1325N/A || file.startsWith("readme"))
1325N/A {
1325N/A readMes.add(file);
1325N/A }
1325N/A boolean isDir = child.isDirectory();
1325N/A long lastm = child.lastModified();
1325N/A%>
1325N/A<tr>
1325N/A <td><p class="<%= isDir ? 'r' : 'p' %>"/></td>
1325N/A <td><a href="<%= Util.URIEncodePath(file) %>"><%= isDir ? "<b>" + file + "</b>" : file %></a></td>
1325N/A <td><%= now-lastm < 86400000 ? "Today" : dateFormatter.format(lastm) %></td>
1325N/A <td><%= Util.readableSize(child.length()) %></td><%
1325N/A if (offset > 0) {
1325N/A String briefDesc = desc.getChildTag(parentFNode, file); %>
1325N/A <td><%= briefDesc == null ? "" : briefDesc %></td><%
1325N/A } %>
1325N/A</tr><%
1325N/A }
1325N/A%>
1325N/A</tbody>
1325N/A</table>
1325N/A<%
1325N/A // finally append READMEs to the listing
1281N/A File[] catfiles = cfg.findDataFiles(readMes);
1281N/A for (int i=0; i < catfiles.length; i++) {
1281N/A if (catfiles[i] == null) {
1281N/A continue;
1281N/A }
1186N/A%><h3><%= readMes.get(i) %></h3>
1186N/A<div id="src">
1281N/A <pre><%
1281N/A Util.dump(out, catfiles[i], catfiles[i].getName().endsWith(".gz"));
1281N/A %></pre>
1186N/A</div><%
1281N/A }
1281N/A }
1281N/A } else if (rev.length() != 0) {
1281N/A // requesting a previous revision
1281N/A FileAnalyzerFactory a = AnalyzerGuru.find(basename);
1281N/A Genre g = AnalyzerGuru.getGenre(a);
1281N/A String error = null;
1281N/A if (g == Genre.PLAIN|| g == Genre.HTML || g == null) {
1281N/A InputStream in = null;
1281N/A try {
1281N/A in = HistoryGuru.getInstance()
1281N/A .getRevision(resourceFile.getParent(), basename, rev.substring(2));
1281N/A } catch (Exception e) {
1281N/A // fall through to error message
1281N/A error = e.getMessage();
1281N/A }
1281N/A if (in != null) {
1281N/A try {
1281N/A if (g == null) {
1281N/A a = AnalyzerGuru.find(in);
1281N/A g = AnalyzerGuru.getGenre(a);
1281N/A }
1281N/A if (g == Genre.DATA || g == Genre.XREFABLE
1281N/A || g == null)
1281N/A {
1186N/A%>
1186N/A<div id="src">
1281N/A Binary file [Click <a href="<%= rawPath %>?<%= rev
1281N/A %>">here</a> to download]
1186N/A</div><%
1281N/A } else {
1186N/A%>
1186N/A<div id="src">
1281N/A <span class="pagetitle"><%= basename %> revision <%=
1281N/A rev.substring(2) %></span>
1281N/A <pre><%
1281N/A if (g == Genre.PLAIN) {
1281N/A // We don't have any way to get definitions
1281N/A // for old revisions currently.
1281N/A Definitions defs = null;
1281N/A Annotation annotation = cfg.getAnnotation();
1281N/A //not needed yet
1281N/A //annotation.writeTooltipMap(out);
1281N/A r = new InputStreamReader(in);
1281N/A AnalyzerGuru.writeXref(a, r, out, defs,
1281N/A annotation, Project.getProject(resourceFile));
1281N/A } else if (g == Genre.IMAGE) {
1281N/A %></pre>
1281N/A <img src="<%= rawPath %>?<%= rev %>"/>
1281N/A <pre><%
1281N/A } else if (g == Genre.HTML) {
1281N/A r = new InputStreamReader(in);
1281N/A Util.dump(out, r);
1281N/A } else {
1281N/A %> Click <a href="<%= rawPath %>?<%= rev %>">download <%= basename %></a><%
1281N/A }
1281N/A }
1281N/A } catch (IOException e) {
1281N/A error = e.getMessage();
1281N/A } finally {
1281N/A if (r != null) {
1281N/A try { r.close(); in = null;}
1281N/A catch (Exception e) { /* ignore */ }
1281N/A }
1281N/A if (in != null) {
1281N/A try { in.close(); }
1281N/A catch (Exception e) { /* ignore */ }
1281N/A }
1281N/A }
1281N/A %></pre>
1186N/A</div><%
1281N/A } else {
1186N/A%>
1186N/A<h3 class="error">Error reading file</h3><%
1281N/A if (error != null) {
1186N/A%>
1186N/A<p class="error"><%= error %></p><%
1281N/A }
1281N/A }
1281N/A } else if (g == Genre.IMAGE) {
1186N/A%>
1186N/A<div id="src">
1281N/A <img src="<%= rawPath %>?<%= rev %>"/>
1186N/A</div><%
1281N/A } else {
1186N/A%>
1186N/A<div id="src">
1281N/A Binary file [Click <a href="<%= rawPath %>?<%= rev
1281N/A %>">here</a> to download]
1186N/A</div><%
1281N/A }
1281N/A } else {
1281N/A // requesting cross referenced file
1281N/A File xrefFile = null;
1281N/A if (!cfg.annotate()) {
1281N/A xrefFile = cfg.findDataFile();
1281N/A }
1281N/A if (xrefFile != null) {
1186N/A%>
1186N/A<div id="src">
1281N/A <pre><%
1281N/A Util.dump(out, xrefFile, xrefFile.getName().endsWith(".gz"));
1281N/A %></pre>
1186N/A</div><%
1281N/A } else {
1281N/A // annotate
1281N/A BufferedInputStream bin =
1281N/A new BufferedInputStream(new FileInputStream(resourceFile));
1281N/A try {
1281N/A FileAnalyzerFactory a = AnalyzerGuru.find(basename);
1281N/A Genre g = AnalyzerGuru.getGenre(a);
1281N/A if (g == null) {
1281N/A a = AnalyzerGuru.find(bin);
1281N/A g = AnalyzerGuru.getGenre(a);
1281N/A }
1281N/A if (g == Genre.IMAGE) {
1186N/A%>
1186N/A<div id="src">
1281N/A <img src="<%= rawPath %>"/>
1186N/A</div><%
1281N/A } else if ( g == Genre.HTML) {
1281N/A r = new InputStreamReader(bin);
1281N/A Util.dump(out, r);
1281N/A } else if (g == Genre.PLAIN) {
1186N/A%>
1186N/A<div id="src">
1281N/A <pre><%
1281N/A // We're generating xref for the latest revision, so we can
1281N/A // find the definitions in the index.
1281N/A Definitions defs = IndexDatabase.getDefinitions(resourceFile);
1281N/A Annotation annotation = cfg.getAnnotation();
1281N/A r = new InputStreamReader(bin);
1281N/A AnalyzerGuru.writeXref(a, r, out, defs, annotation,
1281N/A Project.getProject(resourceFile));
1281N/A %></pre>
1186N/A</div><%
1281N/A } else {
1186N/A%>
1186N/AClick <a href="<%= rawPath %>">download <%= basename %></a><%
1281N/A }
1281N/A } finally {
1281N/A if (r != null) {
1281N/A try { r.close(); bin = null; }
1281N/A catch (Exception e) { /* ignore */ }
1281N/A }
1281N/A if (bin != null) {
1281N/A try { bin.close(); }
1281N/A catch (Exception e) { /* ignore */ }
1281N/A }
1281N/A }
1281N/A }
1281N/A }
1186N/A}
1186N/A/* ---------------------- list.jsp end --------------------- */
1186N/A%><%@
477N/A
1186N/Ainclude file="foot.jspf"
335N/A
1186N/A%>