list.jsp revision 847
335N/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
0N/ACopyright 2005 Sun Microsystems, Inc. All rights reserved.
0N/AUse is subject to license terms.
0N/A--%><%@ page import = "javax.servlet.*,
0N/Ajava.lang.*,
0N/Ajavax.servlet.http.*,
0N/Ajava.util.*,
0N/Ajava.io.*,
335N/Ajava.util.zip.GZIPInputStream,
477N/Ajava.util.logging.Level,
477N/Aorg.opensolaris.opengrok.OpenGrokLogger,
0N/Aorg.opensolaris.opengrok.analysis.*,
123N/Aorg.opensolaris.opengrok.configuration.Project,
0N/Aorg.opensolaris.opengrok.index.*,
0N/Aorg.opensolaris.opengrok.analysis.FileAnalyzer.Genre,
0N/Aorg.opensolaris.opengrok.web.*,
0N/Aorg.opensolaris.opengrok.history.*
0N/A"
0N/A%><%@include file="mast.jsp"%><%
0N/AString rev = null;
0N/Aif(!isDir && ef != null) {
335N/A try {
335N/A ef.close();
335N/A } catch (IOException e) {
335N/A }
335N/A ef = null;
0N/A}
0N/A
0N/Aif (valid) {
0N/A if (isDir) {
335N/A
123N/A // verify that the current path is part of the selected project
123N/A Project activeProject = Project.getProject(resourceFile);
335N/A
123N/A if (activeProject != null) {
123N/A String project = null;
335N/A
123N/A Cookie[] cookies = request.getCookies();
123N/A if (cookies != null) {
123N/A for (Cookie cookie : cookies) {
123N/A if (cookie.getName().equals("OpenGrok/project")) {
123N/A project = cookie.getValue();
123N/A break;
123N/A }
123N/A }
123N/A }
123N/A
242N/A boolean set = false;
123N/A if (project != null) {
123N/A boolean found = false;
123N/A for (String aproj : project.split(" ")) {
123N/A if (activeProject.getPath().equalsIgnoreCase(aproj)) {
123N/A found = true;
123N/A break;
123N/A }
123N/A }
123N/A if (!found) {
242N/A set = true;
123N/A }
123N/A } else {
242N/A set = true;
123N/A }
335N/A
242N/A if (set) {
242N/A Cookie cookie = new Cookie("OpenGrok/project", activeProject.getPath());
123N/A cookie.setPath(context + "/");
123N/A response.addCookie(cookie);
123N/A }
123N/A }
335N/A
123N/A // If requesting a Directory listing -------------
47N/A DirectoryListing dl = new DirectoryListing(ef);
0N/A String[] files = resourceFile.list();
0N/A if (files != null) {
0N/A Arrays.sort(files, String.CASE_INSENSITIVE_ORDER);
470N/A List<String> readMes = dl.listTo(resourceFile, out, path, files);
0N/A if(readMes != null && readMes.size() > 0) {
58N/A File xdir = new File(environment.getDataRootPath() + "/xref" + path);
477N/A if (xdir.exists() && xdir.isDirectory()) {
0N/A char[] buf = new char[8192];
470N/A for (String readme : readMes) {
477N/A File readmeFile = new File(xdir, readme + ".gz");
477N/A Reader br = null;
477N/A try {
477N/A if (environment.isCompressXref() && readmeFile.exists()) {
477N/A br = new InputStreamReader(new GZIPInputStream(new FileInputStream(readmeFile)));
477N/A } else {
477N/A readmeFile = new File(xdir, readme);
477N/A if (readmeFile.exists()) {
477N/A br = new FileReader(readmeFile);
477N/A }
477N/A }
477N/A
477N/A if (br != null) {
477N/A int len = 0;
477N/A %><h3><%=readme%></h3><div id="src"><pre><%
477N/A while((len = br.read(buf)) > 0) {
477N/A out.write(buf, 0, len);
477N/A }
477N/A %></pre></div><%
477N/A }
477N/A } catch(IOException e) {
477N/A OpenGrokLogger.getLogger().log(Level.WARNING, "An error occured while reading/writing readme:", e);
477N/A } finally {
477N/A if (br != null) {
477N/A try {
335N/A br.close();
477N/A } catch (IOException e) {
477N/A OpenGrokLogger.getLogger().log(Level.WARNING, "An error occured while closing file:", e);
477N/A }
0N/A }
477N/A }
0N/A }
0N/A }
0N/A }
0N/A }
0N/A } else if ((rev = request.getParameter("r")) != null && !rev.equals("")) {
335N/A // Else if requesting a previous revision -------------
335N/A if (noHistory) {
335N/A response.sendError(404, "Revision not found");
283N/A } else {
202N/A FileAnalyzerFactory a = AnalyzerGuru.find(basename);
0N/A Genre g = AnalyzerGuru.getGenre(a);
0N/A if (g == Genre.PLAIN|| g == Genre.HTML || g == null) {
0N/A InputStream in = null;
335N/A try {
0N/A in = HistoryGuru.getInstance().getRevision(resourceFile.getParent(), basename, rev);
0N/A } catch (Exception e) {
0N/A response.sendError(404, "Revision not found");
27N/A return;
0N/A }
335N/A if (in != null) {
0N/A try {
0N/A if (g == null) {
0N/A a = AnalyzerGuru.find(in);
0N/A g = AnalyzerGuru.getGenre(a);
0N/A }
0N/A if (g == Genre.DATA || g == Genre.XREFABLE || g == null) {
335N/A %><div id="src">Binary file [Click <a href="<%=context%>/raw<%=path%>?r=<%=rev%>">here</a> to download] </div><%
0N/A } else {
335N/A %><div id="src"><span class="pagetitle"><%=basename%> revision <%=rev%> </span><pre><%
335N/A if (g == Genre.PLAIN) {
335N/A Annotation annotation = annotate ? HistoryGuru.getInstance().annotate(resourceFile, rev) : null;
335N/A AnalyzerGuru.writeXref(a, in, out, annotation, Project.getProject(resourceFile));
335N/A } else if (g == Genre.IMAGE) {
335N/A %><img src="<%=context%>/raw<%=path%>?r=<%=rev%>"/><%
335N/A } else if (g == Genre.HTML) {
335N/A char[] buf = new char[8192];
335N/A Reader br = new InputStreamReader(in);
335N/A int len = 0;
335N/A while((len = br.read(buf)) > 0) {
335N/A out.write(buf, 0, len);
335N/A }
335N/A } else {
335N/A %> Click <a href="<%=context%>/raw<%=path%>?r=<%=rev%>">download <%=basename%></a><%
335N/A }
0N/A }
0N/A } catch (IOException e) {
335N/A %> <h3 class="error">IO Error</h3> <p> <%=e.getMessage() %> </p> <%
0N/A }
335N/A %></pre></div><%
335N/A in.close();
0N/A } else {
335N/A %> <h3 class="error">Error reading file</h3> <%
0N/A }
0N/A } else if(g == Genre.IMAGE) {
335N/A %><div id="src"><img src="<%=context%>/raw<%=path%>?r=<%=rev%>"/></div><%
0N/A } else {
335N/A %><div id="src"> Binary file [Click <a href="<%=context%>/raw<%=path%>?r=<%=rev%>">here</a> to download] </div><%
0N/A }
0N/A }
0N/A } else {
335N/A // requesting cross referenced file -------------
335N/A File xrefSource = new File(environment.getDataRootFile(), "/xref");
335N/A File xrefFile = new File(xrefSource, path + ".gz");
335N/A Reader fileReader = null;
335N/A
335N/A if (environment.isCompressXref() && xrefFile.exists()) {
335N/A fileReader = new InputStreamReader(new GZIPInputStream(new FileInputStream(xrefFile)));
335N/A } else {
335N/A xrefFile = new File(xrefSource, path);
335N/A if (xrefFile.exists()) {
335N/A fileReader = new FileReader(xrefFile);
335N/A }
335N/A }
335N/A
335N/A if (fileReader != null && !annotate) {
0N/A char[] buf = new char[8192];
335N/A BufferedReader br = new BufferedReader(fileReader);
0N/A int len = 0;
335N/A %><div id="src"><pre><%
335N/A while((len = br.read(buf)) > 0) {
0N/A out.write(buf, 0, len);
335N/A }
335N/A %></pre></div><%
335N/A br.close();
0N/A } else {
0N/A BufferedInputStream bin = new BufferedInputStream(new FileInputStream(resourceFile));
202N/A FileAnalyzerFactory a = AnalyzerGuru.find(basename);
0N/A Genre g = AnalyzerGuru.getGenre(a);
0N/A if(g == null) {
0N/A a = AnalyzerGuru.find(bin);
0N/A g = AnalyzerGuru.getGenre(a);
0N/A }
0N/A if (g == Genre.IMAGE) {
0N/A %><div id="src"><img src="<%=context%>/raw<%=path%>"/></div><%
0N/A } else if( g == Genre.HTML) {
0N/A char[] buf = new char[8192];
0N/A Reader br = new InputStreamReader(bin);
0N/A int len = 0;
0N/A while((len = br.read(buf)) > 0) {
0N/A out.write(buf, 0, len);
0N/A }
0N/A } else if(g == Genre.PLAIN) {
335N/A %><div id="src"><pre><%
335N/A Annotation annotation = annotate ? HistoryGuru.getInstance().annotate(resourceFile, rev) : null;
335N/A AnalyzerGuru.writeXref(a, bin, out, annotation, Project.getProject(resourceFile));
335N/A %></pre></div><%
0N/A } else {
335N/A %> Click <a href="<%=context%>/raw<%=path%>">download <%=basename%></a><%
335N/A }
0N/A }
0N/A }
847N/A %><%@include file="foot.jspf"%><%
0N/A}
335N/Aif (ef != null) {
0N/A try {
0N/A ef.close();
0N/A } catch (IOException e) {
0N/A }
0N/A}
0N/A%>