<%-- $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=" java.io.BufferedInputStream, java.io.File, java.io.IOException, java.io.FileInputStream, java.io.InputStream, java.io.InputStreamReader, java.io.Reader, java.text.Format, java.text.SimpleDateFormat, java.util.ArrayList, java.util.Collections, java.util.Date, java.util.EnumSet, java.util.LinkedHashMap, java.util.List, java.util.Map, java.util.Set, org.opensolaris.opengrok.Info, org.opensolaris.opengrok.configuration.Project, 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, org.opensolaris.opengrok.web.PageConfig, org.opensolaris.opengrok.web.Prefix, org.opensolaris.opengrok.web.Util, org.opensolaris.opengrok.web.WebappListener" %><% { // 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(""); } } %><%@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 projects = cfg.getRequestedProjects(); if (!projects.contains(activeProject.getDescription())) { String cookieValue = cfg.getRequestedProjectsAsString(); 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); } } LinkedHashMap path2rev = virtual ? new LinkedHashMap() : null; Map modTimes = HistoryGuru.getInstance() .getLastModifiedTimes(new File(cfg.getSourceRootPath() + path), path2rev); List files = virtual ? new ArrayList(modTimes.keySet()) : cfg.getResourceFileList(); if (virtual) { // to be consistent with resource file listing Collections.sort(files, String.CASE_INSENSITIVE_ORDER); } long now = System.currentTimeMillis(); ArrayList readMes = new ArrayList(); int offset = -1; EftarFileReader.FNode parentFNode = null; EftarFileReader desc = cfg.getEftarReader(); if (desc != null) { parentFNode = desc.getNode(path); if (parentFNode != null) { offset = parentFNode.childOffset; } } %><% if (offset > 0) { %> <% } %> <% 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'" : ""; %> ><%= useToday && now - lastm < 86400000 ? "Today" : dateFormatter.format(lastm) %> <% if (offset > 0) { %> <% } // 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'" : ""; %> ><%= useToday && now-lastm < 86400000 ? "Today" : dateFormatter.format(lastm) %> <% if (offset > 0) { String briefDesc = desc.getChildTag(parentFNode, file); %> <% } %> <% } %>
Name Date <%= virtual ? "Revision" : "Size" %>Description

.. <%= virtual ? path2rev.size() + " entries" : resourceFile.getParentFile().length() + "" %><% } %>

<%= isDir ? "" + Util.htmlize(file) + "" : Util.htmlize(file) %> <%= size %><%= briefDesc == null ? "" : Util.htmlize(briefDesc) %>
<% if (readMes.size() != 0) { ArrayList 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(3); } readMesImg.add(readme.getName()); continue; } else if (g != Genre.HTML && g != Genre.PLAIN) { continue; } pre = true; // else dump } %>

<%= readMes.get(i) %>

<% if (pre) { out.write("
");
				}
				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("
"); } } if (readMesImg != null) { for (String image : readMesImg) { %>

<%= image %>

<% } } } %>
<% // 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) { %>

<%= basename %> for revision <%= rev.substring(2) %> is empty. It was probably moved to a different location or deleted. A click on the History button may reveal more details.

<% } else { if (g == null) { a = AnalyzerGuru.find(in); g = AnalyzerGuru.getGenre(a); } if (g == Genre.DATA || g == Genre.XREFABLE || g == null) { %>

Binary file [Click here to download]

<% } else { %>
<%= Util.htmlize(basename) %> revision <%= rev.substring(2) %><% if (g == Genre.PLAIN) { %>
<% // 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) { %> <% } else if (g == Genre.HTML) { r = new InputStreamReader(in); Util.dump(out, r); } else { %> Click download <%= Util.htmlize(basename) %><% } %>
<% } } } 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 { %>

Error reading file

<% if (error != null) { %>

<%= error %>

<% } } } else if (g == Genre.IMAGE) { %>
<% } else { %>

Binary file [Click here to download]

<% } // 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 %>
<% XrefInputStream.dump(xrefFile, out, true); %>
<% // 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) { %>
<% } else if (g == Genre.HTML) { r = new InputStreamReader(bin); Util.dump(out, r); } else if (g == Genre.PLAIN) { %>
<% // 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)); %>
<% } else { %> Click download <%= Util.htmlize(basename) %><% } } 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" %>