list.jsp revision 1244
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
1186N/A--%><%@page import="
1186N/Ajava.io.BufferedInputStream,
1186N/Ajava.io.BufferedReader,
1186N/Ajava.io.FileInputStream,
1186N/Ajava.io.FileReader,
1186N/Ajava.io.InputStream,
1186N/Ajava.io.InputStreamReader,
1186N/Ajava.io.Reader,
1186N/Ajava.util.ArrayList,
1186N/Ajava.util.Arrays,
1186N/Ajava.util.List,
1186N/Ajava.util.Set,
1186N/Ajava.util.logging.Level,
335N/Ajava.util.zip.GZIPInputStream,
1186N/A
477N/Aorg.opensolaris.opengrok.OpenGrokLogger,
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,
1186N/Aorg.opensolaris.opengrok.index.IndexDatabase,
1186N/Aorg.opensolaris.opengrok.web.DirectoryListing"
1186N/A%><%
1108N/A{
1186N/A // need to set it here since requesting parameters
1186N/A if (request.getCharacterEncoding() == null) {
1186N/A request.setCharacterEncoding("UTF-8");
1186N/A }
1186N/A cfg = PageConfig.get(request);
1186N/A Annotation annotation = cfg.getAnnotation();
1186N/A if (annotation != null) {
1186N/A int r = annotation.getWidestRevision();
1186N/A int a = annotation.getWidestAuthor();
1186N/A cfg.addHeaderData("<style type=\"text/css\">"
1186N/A + ".blame .r { width: " + (r == 0 ? 6 : r) + "ex; } "
1186N/A + ".blame .a { width: " + (a == 0 ? 6 : a) + "ex; } "
1186N/A + "</style>");
1186N/A }
1145N/A}
1186N/A%><%@include
1108N/A
1186N/Afile="mast.jsp"
335N/A
1186N/A%><script type="text/javascript">/* <![CDATA[ */
1186N/Adocument.pageReady.push(function() { pageReadyList();});
1186N/A/* ]]> */</script>
1186N/A<%
1186N/A/* ---------------------- list.jsp start --------------------- */
1186N/A{
1186N/A cfg = PageConfig.get(request);
1186N/A String rev = cfg.getRequestedRevision();
1186N/A
1186N/A File resourceFile = cfg.getResourceFile();
1186N/A String path = cfg.getPath();
1186N/A String basename = resourceFile.getName();
1186N/A String rawPath = request.getContextPath() + Prefix.RAW_P + path;
1186N/A Reader r = null;
1186N/A if (cfg.isDir()) {
1186N/A // valid resource is requested
1186N/A // mast.jsp assures, that resourceFile is valid and not /
1186N/A // see cfg.resourceNotAvailable()
1186N/A Project activeProject = Project.getProject(resourceFile);
1186N/A String cookieValue = cfg.getRequestedProjectsAsString();
1186N/A if (activeProject != null) {
1186N/A Set<String> projects = cfg.getRequestedProjects();
1186N/A if (!projects.contains(activeProject.getDescription())) {
1186N/A projects.add(activeProject.getDescription());
1186N/A // update cookie
1186N/A cookieValue = cookieValue.length() == 0
1186N/A ? activeProject.getDescription()
1186N/A : activeProject.getDescription() + '/' + cookieValue;
1186N/A Cookie cookie = new Cookie("OpenGrokProject", cookieValue);
1186N/A // TODO hmmm, projects.jspf doesn't set a path
1186N/A cookie.setPath(request.getContextPath() + '/');
1186N/A response.addCookie(cookie);
1186N/A }
1186N/A }
1186N/A // requesting a directory listing
1186N/A DirectoryListing dl = new DirectoryListing(cfg.getEftarReader());
1244N/A List<String> files = cfg.getResourceFileList();
1244N/A if (!files.isEmpty()) {
1186N/A List<String> readMes = dl.listTo(resourceFile, out, path, files);
1186N/A File[] catfiles = cfg.findDataFiles(readMes);
1186N/A for (int i=0; i < catfiles.length; i++) {
1186N/A if (catfiles[i] == null) {
1186N/A continue;
1186N/A }
1186N/A%><h3><%= readMes.get(i) %></h3>
1186N/A<div id="src">
1186N/A <pre><%
1186N/A Util.dump(out, catfiles[i], catfiles[i].getName().endsWith(".gz"));
1186N/A %></pre>
1186N/A</div><%
1186N/A }
1186N/A }
1186N/A } else if (rev.length() != 0) {
1186N/A // requesting a previous revision
1186N/A FileAnalyzerFactory a = AnalyzerGuru.find(basename);
1186N/A Genre g = AnalyzerGuru.getGenre(a);
1186N/A String error = null;
1186N/A if (g == Genre.PLAIN|| g == Genre.HTML || g == null) {
1186N/A InputStream in = null;
1186N/A try {
1186N/A in = HistoryGuru.getInstance()
1186N/A .getRevision(resourceFile.getParent(), basename, rev.substring(2));
1186N/A } catch (Exception e) {
1186N/A // fall through to error message
1186N/A error = e.getMessage();
1186N/A }
1186N/A if (in != null) {
1186N/A try {
1186N/A if (g == null) {
1186N/A a = AnalyzerGuru.find(in);
1186N/A g = AnalyzerGuru.getGenre(a);
1186N/A }
1186N/A if (g == Genre.DATA || g == Genre.XREFABLE
1186N/A || g == null)
1186N/A {
1186N/A%>
1186N/A<div id="src">
1186N/A Binary file [Click <a href="<%= rawPath %>?<%= rev
1186N/A %>">here</a> to download]
1186N/A</div><%
1186N/A } else {
1186N/A%>
1186N/A<div id="src">
1186N/A <span class="pagetitle"><%= basename %> revision <%=
1186N/A rev.substring(2) %></span>
1186N/A <pre><%
1186N/A if (g == Genre.PLAIN) {
1186N/A // We don't have any way to get definitions
1186N/A // for old revisions currently.
1186N/A Definitions defs = null;
1186N/A Annotation annotation = cfg.getAnnotation();
1186N/A //not needed yet
1186N/A //annotation.writeTooltipMap(out);
1186N/A r = new InputStreamReader(in);
1186N/A AnalyzerGuru.writeXref(a, r, out, defs,
1186N/A annotation, Project.getProject(resourceFile));
1186N/A } else if (g == Genre.IMAGE) {
1186N/A %></pre>
1186N/A <img src="<%= rawPath %>?<%= rev %>"/>
1186N/A <pre><%
1186N/A } else if (g == Genre.HTML) {
1186N/A r = new InputStreamReader(in);
1186N/A Util.dump(out, r);
1186N/A } else {
1186N/A %> Click <a href="<%= rawPath %>?<%= rev %>">download <%= basename %></a><%
1186N/A }
1186N/A }
1186N/A } catch (IOException e) {
1186N/A error = e.getMessage();
1186N/A } finally {
1186N/A if (r != null) {
1186N/A try { r.close(); in = null;}
1186N/A catch (Exception e) { /* ignore */ }
1186N/A }
1186N/A if (in != null) {
1186N/A try { in.close(); }
1186N/A catch (Exception e) { /* ignore */ }
1186N/A }
1186N/A }
1186N/A %></pre>
1186N/A</div><%
1186N/A } else {
1186N/A%>
1186N/A<h3 class="error">Error reading file</h3><%
1186N/A if (error != null) {
1186N/A%>
1186N/A<p class="error"><%= error %></p><%
1186N/A }
1186N/A }
1186N/A } else if (g == Genre.IMAGE) {
1186N/A%>
1186N/A<div id="src">
1186N/A <img src="<%= rawPath %>?<%= rev %>"/>
1186N/A</div><%
1186N/A } else {
1186N/A%>
1186N/A<div id="src">
1186N/A Binary file [Click <a href="<%= rawPath %>?<%= rev
1186N/A %>">here</a> to download]
1186N/A</div><%
1186N/A }
1186N/A } else {
1186N/A // requesting cross referenced file
1186N/A File xrefFile = null;
1186N/A if (!cfg.annotate()) {
1186N/A xrefFile = cfg.findDataFile();
1186N/A }
1186N/A if (xrefFile != null) {
1186N/A%>
1186N/A<div id="src">
1186N/A <pre><%
1186N/A Util.dump(out, xrefFile, xrefFile.getName().endsWith(".gz"));
1186N/A %></pre>
1186N/A</div><%
1186N/A } else {
1186N/A // annotate
1186N/A BufferedInputStream bin =
1186N/A new BufferedInputStream(new FileInputStream(resourceFile));
1186N/A try {
1186N/A FileAnalyzerFactory a = AnalyzerGuru.find(basename);
1186N/A Genre g = AnalyzerGuru.getGenre(a);
1186N/A if (g == null) {
1186N/A a = AnalyzerGuru.find(bin);
1186N/A g = AnalyzerGuru.getGenre(a);
1186N/A }
1186N/A if (g == Genre.IMAGE) {
1186N/A%>
1186N/A<div id="src">
1186N/A <img src="<%= rawPath %>"/>
1186N/A</div><%
1186N/A } else if ( g == Genre.HTML) {
1186N/A r = new InputStreamReader(bin);
1186N/A Util.dump(out, r);
1186N/A } else if (g == Genre.PLAIN) {
1186N/A%>
1186N/A<div id="src">
1186N/A <pre><%
1186N/A // We're generating xref for the latest revision, so we can
1186N/A // find the definitions in the index.
1186N/A Definitions defs = IndexDatabase.getDefinitions(resourceFile);
1186N/A Annotation annotation = cfg.getAnnotation();
1186N/A r = new InputStreamReader(bin);
1186N/A AnalyzerGuru.writeXref(a, r, out, defs, annotation,
1186N/A Project.getProject(resourceFile));
1186N/A %></pre>
1186N/A</div><%
1186N/A } else {
1186N/A%>
1186N/AClick <a href="<%= rawPath %>">download <%= basename %></a><%
1186N/A }
1186N/A } finally {
1186N/A if (r != null) {
1186N/A try { r.close(); bin = null; }
1186N/A catch (Exception e) { /* ignore */ }
1186N/A }
1186N/A if (bin != null) {
1186N/A try { bin.close(); }
1186N/A catch (Exception e) { /* ignore */ }
1186N/A }
1186N/A }
1186N/A }
1186N/A }
1186N/A}
1186N/A/* ---------------------- list.jsp end --------------------- */
1186N/A%><%@
477N/A
1186N/Ainclude file="foot.jspf"
335N/A
1186N/A%>