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