list.jsp revision 1389
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.
1384N/APortions Copyright 2011, 2012 Jens Elkner.
1186N/A
1384N/A--%><%@page session="false" errorPage="error.jsp" import="
1186N/Ajava.io.BufferedInputStream,
1355N/Ajava.io.File,
1355N/Ajava.io.IOException,
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,
1384N/Aorg.opensolaris.opengrok.analysis.XrefInputStream,
1384N/Aorg.opensolaris.opengrok.analysis.XrefWriter,
1186N/Aorg.opensolaris.opengrok.history.Annotation,
1355N/Aorg.opensolaris.opengrok.history.HistoryGuru,
1325N/Aorg.opensolaris.opengrok.index.IgnoredNames,
1355N/Aorg.opensolaris.opengrok.index.IndexDatabase,
1384N/Aorg.opensolaris.opengrok.util.IOUtils,
1355N/Aorg.opensolaris.opengrok.web.EftarFileReader"
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
1364N/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()) {
1384N/A // directory listing
1384N/A
1384N/A // valid resource is requested: mast.jsp assures, that resourceFile is
1384N/A // valid and not the source root "/"
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
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) {
1384N/A%> <th>Description</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>
1389N/A <td><p class="u"/></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 }
1368N/A // entries
1368N/A for (String file : files) {
1368N/A if (ignoredNames.ignore(file)) {
1368N/A continue;
1368N/A }
1368N/A File child = new File(resourceFile, file);
1368N/A if ((file.startsWith("README") || file.endsWith("README")
1368N/A || file.startsWith("readme")) && child.isFile())
1368N/A {
1368N/A readMes.add(file);
1368N/A }
1368N/A boolean isDir = child.isDirectory();
1325N/A long lastm = child.lastModified();
1325N/A%>
1325N/A<tr>
1389N/A <td><p class="<%= isDir ? 'v' : 'w' %>"/></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>
1368N/A<div id="src"><%
1368N/A if (readMes.size() != 0) {
1368N/A ArrayList<String> readMesImg = null;
1368N/A File[] xrefs = cfg.findDataFiles(readMes);
1368N/A for (int i=0; i < xrefs.length; i++) {
1368N/A File readme = xrefs[i];
1370N/A boolean pre = false;
1368N/A if (readme == null) { // no xref avail or outdated or img
1368N/A readme = new File(resourceFile, readMes.get(i));
1368N/A Genre g = AnalyzerGuru.getGenre(readme.getName());
1368N/A if (g == null) {
1368N/A BufferedInputStream in = null;
1368N/A try {
1368N/A in = new BufferedInputStream(new FileInputStream(readme));
1368N/A g = AnalyzerGuru.getGenre(in);
1368N/A } catch (Exception e) {
1368N/A // ignore
1368N/A } finally {
1368N/A IOUtils.close(in);
1368N/A }
1368N/A }
1368N/A if (g == Genre.IMAGE) {
1368N/A if (readMesImg == null) {
1368N/A readMesImg = new ArrayList<String>(3);
1368N/A }
1368N/A readMesImg.add(readme.getName());
1368N/A continue;
1368N/A } else if (g != Genre.HTML && g != Genre.PLAIN) {
1368N/A continue;
1368N/A }
1370N/A pre = true;
1368N/A // else dump
1368N/A }
1368N/A%>
1370N/A<h3><%= readMes.get(i) %></h3><%
1370N/A if (pre) {
1370N/A out.write("<pre>");
1370N/A }
1384N/A if (xrefs[i] != null) {
1384N/A XrefInputStream.dump(xrefs[i], out, false);
1384N/A } else {
1384N/A Util.dump(out,readme, readme.getName().endsWith(".gz"));
1384N/A }
1370N/A if (pre) {
1370N/A out.write("</pre>");
1370N/A }
1368N/A }
1368N/A if (readMesImg != null) {
1368N/A for (String image : readMesImg) {
1368N/A%>
1368N/A<h3><%= image %></h3>
1368N/A<img src="<%= Util.URIEncodePath(rawPath + '/' + image) %>"/><%
1368N/A }
1368N/A }
1369N/A }
1368N/A%>
1186N/A</div><%
1368N/A }
1368N/A // end of directory listing
1281N/A } else if (rev.length() != 0) {
1384N/A // list a previous revision of a file
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) {
1384N/A XrefWriter xout = 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">
1368N/A Binary file [Click <a href="<%= Util.URIEncodePath(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 <%=
1370N/A rev.substring(2) %></span><%
1281N/A if (g == Genre.PLAIN) {
1384N/A%>
1384N/A<div id='linenums'></div><div id='annos'></div><%
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 r = new InputStreamReader(in);
1384N/A xout = new XrefWriter(out);
1384N/A AnalyzerGuru.writeXref(a, r, xout , defs,
1281N/A annotation, Project.getProject(resourceFile));
1281N/A } else if (g == Genre.IMAGE) {
1370N/A %>
1370N/A <img src="<%= Util.URIEncodePath(rawPath) %>?<%= rev %>"/><%
1281N/A } else if (g == Genre.HTML) {
1281N/A r = new InputStreamReader(in);
1281N/A Util.dump(out, r);
1281N/A } else {
1368N/A %> Click <a href="<%= Util.URIEncodePath(rawPath) %>?<%=
1368N/A 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 }
1384N/A IOUtils.close(in);
1384N/A IOUtils.close(xout);
1281N/A }
1370N/A%>
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">
1368N/A <img src="<%= Util.URIEncodePath(rawPath) %>?<%= rev %>"/>
1186N/A</div><%
1281N/A } else {
1186N/A%>
1186N/A<div id="src">
1368N/A Binary file [Click <a href="<%= Util.URIEncodePath(rawPath) %>?<%= rev
1281N/A %>">here</a> to download]
1186N/A</div><%
1281N/A }
1384N/A // end list a previous revision of a file
1281N/A } else {
1384N/A // list current version of a file
1281N/A File xrefFile = null;
1281N/A if (!cfg.annotate()) {
1281N/A xrefFile = cfg.findDataFile();
1281N/A }
1281N/A if (xrefFile != null) {
1384N/A // dump cross file
1186N/A%>
1384N/A<div id="src"><div id='linenums'></div><div id='annos'></div><%
1384N/A XrefInputStream.dump(xrefFile, out, true);
1370N/A%>
1186N/A</div><%
1384N/A // end dump cross file
1281N/A } else {
1384N/A // dump [annotated] source file
1281N/A BufferedInputStream bin =
1281N/A new BufferedInputStream(new FileInputStream(resourceFile));
1384N/A XrefWriter xout = null;
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">
1368N/A <img src="<%= Util.URIEncodePath(rawPath) %>"/>
1186N/A</div><%
1384N/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%>
1384N/A<div id="src"><div id='linenums'></div><div id='annos'></div><%
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);
1384N/A xout = new XrefWriter(out);
1384N/A AnalyzerGuru.writeXref(a, r, xout, defs, annotation,
1281N/A Project.getProject(resourceFile));
1370N/A%>
1186N/A</div><%
1281N/A } else {
1186N/A%>
1368N/AClick <a href="<%= Util.URIEncodePath(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 }
1384N/A IOUtils.close(bin);
1384N/A IOUtils.close(xout);
1281N/A }
1384N/A // end dump [annotated] source file
1281N/A }
1384N/A // end list current version of a file
1281N/A }
1186N/A}
1186N/A/* ---------------------- list.jsp end --------------------- */
1186N/A%><%@
477N/A
1186N/Ainclude file="foot.jspf"
335N/A
1186N/A%>