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
1478N/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,
1478N/Ajava.util.Collections,
1463N/Ajava.util.Date,
1478N/Ajava.util.EnumSet,
1478N/Ajava.util.LinkedHashMap,
1186N/Ajava.util.List,
1463N/Ajava.util.Map,
1186N/Ajava.util.Set,
1186N/A
1478N/Aorg.opensolaris.opengrok.Info,
1478N/Aorg.opensolaris.opengrok.configuration.Project,
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,
1478N/Aorg.opensolaris.opengrok.web.EftarFileReader,
1478N/Aorg.opensolaris.opengrok.web.PageConfig,
1478N/Aorg.opensolaris.opengrok.web.Prefix,
1478N/Aorg.opensolaris.opengrok.web.Util,
1478N/Aorg.opensolaris.opengrok.web.WebappListener"
1281N/A%><%
1108N/A{
1473N/A // need to set it here since requesting parameters
1473N/A if (request.getCharacterEncoding() == null) {
1473N/A request.setCharacterEncoding("UTF-8");
1473N/A }
1473N/A cfg = PageConfig.get(request);
1473N/A Annotation annotation = cfg.getAnnotation();
1473N/A if (annotation != null) {
1473N/A float r = annotation.getWidestRevision() * 1.15f;
1473N/A float a = annotation.getWidestAuthor() * 1.15f;
1473N/A cfg.addHeaderData("<style type=\"text/css\">"
1473N/A + ".r { width: " + (r == 0 ? 6 : r) + "ex; } "
1473N/A + ".a { width: " + (a == 0 ? 6 : a) + "ex; } "
1473N/A + "</style>");
1473N/A }
1145N/A}
1281N/A%><%@include
1108N/A
1478N/Afile="mast.jspf"
335N/A
1364N/A%><%
1186N/A/* ---------------------- list.jsp start --------------------- */
1186N/A{
1473N/A cfg = PageConfig.get(request);
1473N/A String rev = cfg.getRequestedRevision();
1281N/A
1473N/A File resourceFile = cfg.getResourceFile();
1473N/A String path = cfg.getPath();
1473N/A String basename = resourceFile.getName();
1473N/A String rawPath = request.getContextPath() + Prefix.RAW_P + path;
1473N/A Reader r = null;
1473N/A if (cfg.isDir()) {
1473N/A // directory listing
1474N/A boolean virtual =
1474N/A basename.isEmpty() || request.getParameter("all") != null;
1384N/A
1474N/A Project activeProject = Project.getProject(path);
1473N/A if (activeProject != null) {
1473N/A Set<String> projects = cfg.getRequestedProjects();
1473N/A if (!projects.contains(activeProject.getDescription())) {
1475N/A String cookieValue = cfg.getRequestedProjectsAsString();
1473N/A projects.add(activeProject.getDescription());
1473N/A // update cookie
1473N/A cookieValue = cookieValue.length() == 0
1473N/A ? activeProject.getDescription()
1473N/A : activeProject.getDescription() + '/' + cookieValue;
1473N/A Cookie cookie = new Cookie("OpenGrokProject", cookieValue);
1473N/A // TODO hmmm, projects.jspf doesn't set a path
1473N/A cookie.setPath(request.getContextPath() + '/');
1473N/A response.addCookie(cookie);
1473N/A }
1473N/A }
1325N/A
1474N/A LinkedHashMap<String,String> path2rev =
1474N/A virtual ? new LinkedHashMap<String,String>() : null;
1474N/A Map<String, Date> modTimes = HistoryGuru.getInstance()
1474N/A .getLastModifiedTimes(new File(cfg.getSourceRootPath() + path), path2rev);
1474N/A List<String> files = virtual
1474N/A ? new ArrayList<String>(modTimes.keySet())
1474N/A : cfg.getResourceFileList();
1474N/A if (virtual) {
1474N/A // to be consistent with resource file listing
1474N/A Collections.sort(files, String.CASE_INSENSITIVE_ORDER);
1474N/A }
1474N/A
1474N/A long now = System.currentTimeMillis();
1474N/A ArrayList<String> readMes = new ArrayList<String>();
1474N/A int offset = -1;
1474N/A EftarFileReader.FNode parentFNode = null;
1474N/A EftarFileReader desc = cfg.getEftarReader();
1474N/A if (desc != null) {
1474N/A parentFNode = desc.getNode(path);
1474N/A if (parentFNode != null) {
1474N/A offset = parentFNode.childOffset;
1463N/A }
1474N/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>
1474N/A <th><%= virtual ? "Revision" : "Size" %></th><%
1474N/A if (offset > 0) {
1384N/A%> <th>Description</th><%
1474N/A }
1325N/A%>
1325N/A</tr>
1325N/A</thead>
1325N/A<tbody><%
1474N/A IgnoredNames ignoredNames = cfg.getIgnoredNames();
1474N/A Format dateFormatter =
1474N/A new SimpleDateFormat(cfg.getConfig().getDirlistDatePattern());
1474N/A boolean useToday = cfg.getConfig().isDirlistUseToday();
1474N/A // upper directory
1474N/A if (path.length() != 0) {
1474N/A long lastm = 0;
1474N/A if (!modTimes.isEmpty()) {
1474N/A for (Date d : modTimes.values()) {
1474N/A long l = d.getTime();
1474N/A if (l > lastm) {
1474N/A lastm = l;
1463N/A }
1463N/A }
1474N/A } else if (!virtual) {
1474N/A lastm = resourceFile.getParentFile().lastModified();
1474N/A } else {
1474N/A lastm = now;
1474N/A }
1474N/A String css = now - lastm < 86400000 ? " class='x'" : "";
1325N/A%>
1325N/A<tr>
1389N/A <td><p class="u"/></td>
1325N/A <td><b><a href="..">..</a></b></td>
1474N/A <td<%= css%>><%= useToday && now - lastm < 86400000
1469N/A ? "Today" : dateFormatter.format(lastm) %></td>
1474N/A <td><%= virtual
1474N/A ? path2rev.size() + " entries"
1474N/A : resourceFile.getParentFile().length() + ""
1474N/A %></td><%
1474N/A if (offset > 0) { %>
1325N/A <td/><%
1474N/A } %>
1325N/A</tr><%
1474N/A }
1474N/A // entries
1474N/A boolean isDir;
1474N/A long lastm;
1474N/A String size;
1474N/A String link;
1474N/A for (String file : files) {
1474N/A if (ignoredNames.match(file)) {
1474N/A continue;
1463N/A }
1474N/A if (virtual) {
1474N/A isDir = file.endsWith("/");
1474N/A lastm = modTimes.get(file).getTime();
1474N/A size = path2rev.get(file);
1474N/A // we do not display any readmes for virtual dirs
1474N/A link = Util.uriEncodePath(file);
1474N/A if (!isDir) {
1474N/A link += "?r=" + size;
1368N/A }
1474N/A } else {
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 }
1474N/A isDir = child.isDirectory();
1475N/A Date lmd = modTimes.get(isDir ? file + '/' : file);
1474N/A lastm = lmd == null ? child.lastModified() : lmd.getTime();
1474N/A size = Util.readableSize(child.length());
1474N/A link = Util.uriEncodePath(file);
1474N/A }
1474N/A String css = now - lastm < 86400000 ? " class='x'" : "";
1325N/A%>
1325N/A<tr>
1389N/A <td><p class="<%= isDir ? 'v' : 'w' %>"/></td>
1474N/A <td><a href="<%= link %>"><%= isDir ? "<b>"
1469N/A + Util.htmlize(file) + "</b>" : Util.htmlize(file) %></a></td>
1469N/A <td<%= css%>><%= useToday && now-lastm < 86400000
1469N/A ? "Today" : dateFormatter.format(lastm) %></td>
1474N/A <td><%= size %></td><%
1474N/A if (offset > 0) {
1474N/A String briefDesc = desc.getChildTag(parentFNode, file); %>
1469N/A <td><%= briefDesc == null ? "" : Util.htmlize(briefDesc) %></td><%
1463N/A } %>
1325N/A</tr><%
1463N/A }
1325N/A%>
1325N/A</tbody>
1325N/A</table>
1368N/A<div id="src"><%
1474N/A if (readMes.size() != 0) {
1474N/A ArrayList<String> readMesImg = null;
1474N/A File[] xrefs = cfg.findDataFiles(readMes);
1474N/A for (int i=0; i < xrefs.length; i++) {
1474N/A File readme = xrefs[i];
1474N/A boolean pre = false;
1474N/A if (readme == null) { // no xref avail or outdated or img
1474N/A readme = new File(resourceFile, readMes.get(i));
1474N/A Genre g = AnalyzerGuru.getGenre(readme.getName());
1474N/A if (g == null) {
1474N/A BufferedInputStream in = null;
1474N/A try {
1474N/A in = new BufferedInputStream(new FileInputStream(readme));
1474N/A g = AnalyzerGuru.getGenre(in);
1474N/A } catch (Exception e) {
1474N/A // ignore
1474N/A } finally {
1474N/A IOUtils.close(in);
1368N/A }
1474N/A }
1474N/A if (g == Genre.IMAGE) {
1474N/A if (readMesImg == null) {
1474N/A readMesImg = new ArrayList<String>(3);
1368N/A }
1474N/A readMesImg.add(readme.getName());
1474N/A continue;
1474N/A } else if (g != Genre.HTML && g != Genre.PLAIN) {
1474N/A continue;
1368N/A }
1474N/A pre = true;
1474N/A // else dump
1474N/A }
1368N/A%>
1370N/A<h3><%= readMes.get(i) %></h3><%
1474N/A if (pre) {
1474N/A out.write("<pre>");
1368N/A }
1474N/A if (xrefs[i] != null) {
1474N/A XrefInputStream.dump(xrefs[i], out, false);
1474N/A } else {
1474N/A // not clean, but usually works
1474N/A Util.dump(out,readme, readme.getName().endsWith(".gz"));
1474N/A }
1474N/A if (pre) {
1474N/A out.write("</pre>");
1474N/A }
1474N/A }
1474N/A if (readMesImg != null) {
1474N/A for (String image : readMesImg) {
1368N/A%>
1368N/A<h3><%= image %></h3>
1469N/A<img src="<%= Util.uriEncodePath(rawPath + '/' + image) %>"/><%
1368N/A }
1369N/A }
1474N/A }
1368N/A%>
1186N/A</div><%
1368N/A // end of directory listing
1473N/A } else if (rev.length() != 0) {
1473N/A // list a previous revision of a file
1473N/A String parent = resourceFile.getParent();
1473N/A if (basename.isEmpty()) {
1473N/A // virtual file
1473N/A int idx = path.lastIndexOf('/');
1473N/A if (idx != -1) {
1473N/A basename = path.substring(idx+1);
1473N/A parent = cfg.getSourceRootPath() + '/' + path.substring(0, idx);
1473N/A }
1473N/A }
1473N/A FileAnalyzerFactory a = AnalyzerGuru.find(basename);
1473N/A Genre g = AnalyzerGuru.getGenre(a);
1473N/A String error = null;
1473N/A if (g == Genre.PLAIN|| g == Genre.HTML || g == null) {
1473N/A InputStream in = null;
1473N/A try {
1473N/A in = HistoryGuru.getInstance()
1473N/A .getRevision(parent, basename, rev.substring(2));
1473N/A } catch (Exception e) {
1473N/A // fall through to error message
1473N/A error = e.getMessage();
1473N/A }
1473N/A if (in != null) {
1473N/A XrefWriter xout = null;
1473N/A try {
1473N/A // we don't get enough info from history guru, that's why
1473N/A // this little hack to emp. detect deleted/moved files
1473N/A in.mark(2);
1473N/A int b = in.read();
1473N/A in.reset();
1473N/A if (b == -1) {
1473N/A%>
1473N/A<div id="src"></div>
1473N/A<p><%= basename %> for revision <%= rev.substring(2) %> is empty. It was
1473N/Aprobably moved to a different location or deleted. A click on the <b>History</b>
1473N/Abutton may reveal more details.</p>
1473N/A<%
1473N/A } else {
1473N/A if (g == null) {
1473N/A a = AnalyzerGuru.find(in);
1473N/A g = AnalyzerGuru.getGenre(a);
1473N/A }
1473N/A if (g == Genre.DATA || g == Genre.XREFABLE || g == null) {
1473N/A%>
1473N/A<div id="src"></div>
1473N/A<p>Binary file [Click <a href="<%= Util.uriEncodePath(rawPath) %>?<%= rev
1473N/A %>">here</a> to download]</p><%
1473N/A } else {
1186N/A%>
1186N/A<div id="src">
1473N/A <span class="pagetitle"><%= Util.htmlize(basename) %> revision <%=
1473N/A rev.substring(2) %></span><%
1473N/A if (g == Genre.PLAIN) {
1384N/A%>
1384N/A<div id='linenums'></div><div id='annos'></div><%
1473N/A // We don't have any way to get definitions
1473N/A // for old revisions currently.
1473N/A Definitions defs = null;
1473N/A Annotation annotation = cfg.getAnnotation();
1473N/A r = new InputStreamReader(in);
1473N/A xout = new XrefWriter(out);
1473N/A AnalyzerGuru.writeXref(a, r, xout , defs,
1473N/A annotation, Project.getProject(resourceFile));
1473N/A } else if (g == Genre.IMAGE) {
1473N/A %>
1473N/A <img src="<%= Util.uriEncodePath(rawPath) %>?<%= rev %>"/><%
1473N/A } else if (g == Genre.HTML) {
1473N/A r = new InputStreamReader(in);
1473N/A Util.dump(out, r);
1473N/A } else {
1473N/A %> Click <a href="<%= Util.uriEncodePath(rawPath) %>?<%=
1473N/A rev %>">download <%= Util.htmlize(basename) %></a><%
1473N/A }
1473N/A %>
1186N/A</div><%
1473N/A }
1473N/A }
1473N/A } catch (IOException e) {
1473N/A error = e.getMessage();
1473N/A } finally {
1473N/A if (r != null) {
1473N/A try { r.close(); in = null;}
1473N/A catch (Exception e) { /* ignore */ }
1473N/A }
1473N/A IOUtils.close(in);
1473N/A IOUtils.close(xout);
1473N/A }
1473N/A } else {
1186N/A%>
1186N/A<h3 class="error">Error reading file</h3><%
1473N/A if (error != null) {
1186N/A%>
1186N/A<p class="error"><%= error %></p><%
1473N/A }
1473N/A }
1473N/A } else if (g == Genre.IMAGE) {
1186N/A%>
1186N/A<div id="src">
1473N/A <img src="<%= Util.uriEncodePath(rawPath) %>?<%= rev %>"/>
1186N/A</div><%
1473N/A } else {
1473N/A%>
1473N/A<div id="src"></div>
1473N/A <p>Binary file [Click <a href="<%= Util.uriEncodePath(rawPath) %>?<%= rev
1473N/A %>">here</a> to download]</p><%
1473N/A }
1473N/A // end list a previous revision of a file
1473N/A } else {
1473N/A // list current version of a file
1473N/A File xrefFile = null;
1473N/A if (!cfg.annotate()) {
1473N/A xrefFile = cfg.findDataFile();
1473N/A }
1473N/A if (xrefFile != null) {
1473N/A // dump cross file
1186N/A%>
1384N/A<div id="src"><div id='linenums'></div><div id='annos'></div><%
1473N/A XrefInputStream.dump(xrefFile, out, true);
1370N/A%>
1186N/A</div><%
1384N/A // end dump cross file
1473N/A } else {
1473N/A // dump [annotated] source file
1473N/A BufferedInputStream bin =
1473N/A new BufferedInputStream(new FileInputStream(resourceFile));
1473N/A XrefWriter xout = null;
1473N/A try {
1473N/A FileAnalyzerFactory a = AnalyzerGuru.find(basename);
1473N/A Genre g = AnalyzerGuru.getGenre(a);
1473N/A if (g == null) {
1473N/A a = AnalyzerGuru.find(bin);
1473N/A g = AnalyzerGuru.getGenre(a);
1473N/A }
1473N/A if (g == Genre.IMAGE) {
1186N/A%>
1186N/A<div id="src">
1473N/A <img src="<%= Util.uriEncodePath(rawPath) %>"/>
1186N/A</div><%
1473N/A } else if (g == Genre.HTML) {
1473N/A r = new InputStreamReader(bin);
1473N/A Util.dump(out, r);
1473N/A } else if (g == Genre.PLAIN) {
1186N/A%>
1384N/A<div id="src"><div id='linenums'></div><div id='annos'></div><%
1473N/A // We're generating xref for the latest revision, so we can
1473N/A // find the definitions in the index.
1473N/A Definitions defs = IndexDatabase.getDefinitions(resourceFile);
1473N/A Annotation annotation = cfg.getAnnotation();
1473N/A r = new InputStreamReader(bin);
1473N/A xout = new XrefWriter(out);
1473N/A AnalyzerGuru.writeXref(a, r, xout, defs, annotation,
1473N/A Project.getProject(resourceFile));
1370N/A%>
1186N/A</div><%
1473N/A } else {
1186N/A%>
1469N/AClick <a href="<%= Util.uriEncodePath(rawPath) %>">download <%=
1469N/A Util.htmlize(basename) %></a><%
1473N/A }
1473N/A } finally {
1473N/A if (r != null) {
1473N/A try { r.close(); bin = null; }
1473N/A catch (Exception e) { /* ignore */ }
1473N/A }
1473N/A IOUtils.close(bin);
1473N/A IOUtils.close(xout);
1473N/A }
1473N/A // end dump [annotated] source file
1473N/A }
1473N/A // end list current version of a file
1473N/A }
1186N/A}
1186N/A/* ---------------------- list.jsp end --------------------- */
1186N/A%><%@
477N/A
1186N/Ainclude file="foot.jspf"
335N/A
1186N/A%>