list.jsp revision 470
2N/A<%--
2N/ACDDL HEADER START
2N/A
2N/AThe contents of this file are subject to the terms of the
2N/ACommon Development and Distribution License (the "License").
2N/AYou may not use this file except in compliance with the License.
2N/A
2N/ASee LICENSE.txt included in this distribution for the specific
2N/Alanguage governing permissions and limitations under the License.
2N/A
2N/AWhen distributing Covered Code, include this CDDL HEADER in each
2N/Afile and include the License file at LICENSE.txt.
2N/AIf applicable, add the following below this CDDL HEADER, with the
2N/Afields enclosed by brackets "[]" replaced with your own identifying
2N/Ainformation: Portions Copyright [yyyy] [name of copyright owner]
2N/A
2N/ACDDL HEADER END
2N/A
2N/ACopyright 2005 Sun Microsystems, Inc. All rights reserved.
2N/AUse is subject to license terms.
2N/A--%><%@ page import = "javax.servlet.*,
2N/Ajava.lang.*,
2N/Ajavax.servlet.http.*,
2N/Ajava.util.*,
2N/Ajava.io.*,
2N/Ajava.util.zip.GZIPInputStream,
2N/Aorg.opensolaris.opengrok.analysis.*,
2N/Aorg.opensolaris.opengrok.configuration.Project,
2N/Aorg.opensolaris.opengrok.index.*,
2N/Aorg.opensolaris.opengrok.analysis.FileAnalyzer.Genre,
2N/Aorg.opensolaris.opengrok.web.*,
2N/Aorg.opensolaris.opengrok.history.*
2N/A"
2N/A%><%@include file="mast.jsp"%><%
2N/AString rev = null;
2N/Aif(!isDir && ef != null) {
2N/A try {
2N/A ef.close();
2N/A } catch (IOException e) {
2N/A }
2N/A ef = null;
2N/A}
2N/A
2N/Aif (valid) {
2N/A if (isDir) {
2N/A
2N/A // verify that the current path is part of the selected project
2N/A Project activeProject = Project.getProject(resourceFile);
2N/A
2N/A if (activeProject != null) {
2N/A String project = null;
2N/A
2N/A Cookie[] cookies = request.getCookies();
2N/A if (cookies != null) {
2N/A for (Cookie cookie : cookies) {
2N/A if (cookie.getName().equals("OpenGrok/project")) {
2N/A project = cookie.getValue();
2N/A break;
2N/A }
2N/A }
2N/A }
2N/A
2N/A boolean set = false;
2N/A if (project != null) {
2N/A boolean found = false;
2N/A for (String aproj : project.split(" ")) {
2N/A if (activeProject.getPath().equalsIgnoreCase(aproj)) {
2N/A found = true;
2N/A break;
2N/A }
2N/A }
2N/A if (!found) {
2N/A set = true;
2N/A }
2N/A } else {
2N/A set = true;
2N/A }
2N/A
2N/A if (set) {
2N/A Cookie cookie = new Cookie("OpenGrok/project", activeProject.getPath());
2N/A cookie.setPath(context + "/");
2N/A response.addCookie(cookie);
2N/A }
2N/A }
2N/A
2N/A // If requesting a Directory listing -------------
2N/A DirectoryListing dl = new DirectoryListing(ef);
2N/A String[] files = resourceFile.list();
2N/A if (files != null) {
2N/A Arrays.sort(files, String.CASE_INSENSITIVE_ORDER);
2N/A List<String> readMes = dl.listTo(resourceFile, out, path, files);
2N/A if(readMes != null && readMes.size() > 0) {
2N/A File xdir = new File(environment.getDataRootPath() + "/xref" + path);
2N/A if(xdir.exists() && xdir.isDirectory()) {
2N/A char[] buf = new char[8192];
2N/A for (String readme : readMes) {
2N/A try {
2N/A Reader br = new FileReader(new File(xdir, readme));
2N/A int len = 0;
2N/A %><h3><%=readme%></h3><div id="src"><pre><%
2N/A while((len = br.read(buf)) > 0) {
2N/A out.write(buf, 0, len);
2N/A }
2N/A %></pre></div><%
2N/A br.close();
2N/A } catch(IOException e) {
2N/A }
2N/A }
2N/A }
2N/A }
2N/A }
2N/A } else if ((rev = request.getParameter("r")) != null && !rev.equals("")) {
2N/A // Else if requesting a previous revision -------------
2N/A if (noHistory) {
2N/A response.sendError(404, "Revision not found");
2N/A } else {
2N/A FileAnalyzerFactory a = AnalyzerGuru.find(basename);
2N/A Genre g = AnalyzerGuru.getGenre(a);
2N/A if (g == Genre.PLAIN|| g == Genre.HTML || g == null) {
2N/A InputStream in = null;
2N/A try {
2N/A in = HistoryGuru.getInstance().getRevision(resourceFile.getParent(), basename, rev);
2N/A } catch (Exception e) {
2N/A response.sendError(404, "Revision not found");
2N/A return;
2N/A }
2N/A if (in != null) {
2N/A try {
2N/A if (g == null) {
2N/A a = AnalyzerGuru.find(in);
2N/A g = AnalyzerGuru.getGenre(a);
2N/A }
2N/A if (g == Genre.DATA || g == Genre.XREFABLE || g == null) {
2N/A %><div id="src">Binary file [Click <a href="<%=context%>/raw<%=path%>?r=<%=rev%>">here</a> to download] </div><%
2N/A } else {
2N/A %><div id="src"><span class="pagetitle"><%=basename%> revision <%=rev%> </span><pre><%
2N/A if (g == Genre.PLAIN) {
2N/A Annotation annotation = annotate ? HistoryGuru.getInstance().annotate(resourceFile, rev) : null;
2N/A AnalyzerGuru.writeXref(a, in, out, annotation, Project.getProject(resourceFile));
2N/A } else if (g == Genre.IMAGE) {
2N/A %><img src="<%=context%>/raw<%=path%>?r=<%=rev%>"/><%
2N/A } else if (g == Genre.HTML) {
2N/A char[] buf = new char[8192];
2N/A Reader br = new InputStreamReader(in);
2N/A int len = 0;
2N/A while((len = br.read(buf)) > 0) {
2N/A out.write(buf, 0, len);
2N/A }
2N/A } else {
2N/A %> Click <a href="<%=context%>/raw<%=path%>?r=<%=rev%>">download <%=basename%></a><%
2N/A }
2N/A }
2N/A } catch (IOException e) {
2N/A %> <h3 class="error">IO Error</h3> <p> <%=e.getMessage() %> </p> <%
2N/A }
2N/A %></pre></div><%
2N/A in.close();
2N/A } else {
2N/A %> <h3 class="error">Error reading file</h3> <%
2N/A }
2N/A } else if(g == Genre.IMAGE) {
2N/A %><div id="src"><img src="<%=context%>/raw<%=path%>?r=<%=rev%>"/></div><%
2N/A } else {
2N/A %><div id="src"> Binary file [Click <a href="<%=context%>/raw<%=path%>?r=<%=rev%>">here</a> to download] </div><%
2N/A }
2N/A }
2N/A } else {
2N/A // requesting cross referenced file -------------
2N/A File xrefSource = new File(environment.getDataRootFile(), "/xref");
2N/A File xrefFile = new File(xrefSource, path + ".gz");
2N/A Reader fileReader = null;
2N/A
2N/A if (environment.isCompressXref() && xrefFile.exists()) {
2N/A fileReader = new InputStreamReader(new GZIPInputStream(new FileInputStream(xrefFile)));
2N/A } else {
2N/A xrefFile = new File(xrefSource, path);
2N/A if (xrefFile.exists()) {
2N/A fileReader = new FileReader(xrefFile);
2N/A }
2N/A }
2N/A
2N/A if (fileReader != null && !annotate) {
2N/A char[] buf = new char[8192];
2N/A BufferedReader br = new BufferedReader(fileReader);
2N/A int len = 0;
2N/A %><div id="src"><pre><%
2N/A while((len = br.read(buf)) > 0) {
2N/A out.write(buf, 0, len);
2N/A }
2N/A %></pre></div><%
2N/A br.close();
2N/A } else {
2N/A BufferedInputStream bin = new BufferedInputStream(new FileInputStream(resourceFile));
2N/A FileAnalyzerFactory a = AnalyzerGuru.find(basename);
2N/A Genre g = AnalyzerGuru.getGenre(a);
2N/A if(g == null) {
2N/A a = AnalyzerGuru.find(bin);
2N/A g = AnalyzerGuru.getGenre(a);
2N/A }
2N/A if (g == Genre.IMAGE) {
2N/A %><div id="src"><img src="<%=context%>/raw<%=path%>"/></div><%
2N/A } else if( g == Genre.HTML) {
2N/A char[] buf = new char[8192];
2N/A Reader br = new InputStreamReader(bin);
2N/A int len = 0;
2N/A while((len = br.read(buf)) > 0) {
2N/A out.write(buf, 0, len);
2N/A }
2N/A } else if(g == Genre.PLAIN) {
2N/A %><div id="src"><pre><%
2N/A Annotation annotation = annotate ? HistoryGuru.getInstance().annotate(resourceFile, rev) : null;
2N/A AnalyzerGuru.writeXref(a, bin, out, annotation, Project.getProject(resourceFile));
2N/A %></pre></div><%
2N/A } else {
2N/A %> Click <a href="<%=context%>/raw<%=path%>">download <%=basename%></a><%
2N/A }
2N/A }
2N/A }
2N/A%><%@include file="foot.jspf"%><%
2N/A}
2N/Aif (ef != null) {
2N/A try {
2N/A ef.close();
2N/A } catch (IOException e) {
2N/A }
2N/A}
2N/A%>
2N/A