list.jsp revision 470
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
878N/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/Aorg.opensolaris.opengrok.analysis.*,
477N/Aorg.opensolaris.opengrok.configuration.Project,
0N/Aorg.opensolaris.opengrok.index.*,
123N/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;
1108N/Aif(!isDir && ef != null) {
1108N/A try {
1108N/A ef.close();
1108N/A } catch (IOException e) {
1108N/A }
1108N/A ef = null;
1108N/A}
1108N/A
1108N/Aif (valid) {
1108N/A if (isDir) {
1108N/A
1108N/A // verify that the current path is part of the selected project
1108N/A Project activeProject = Project.getProject(resourceFile);
1108N/A
1108N/A if (activeProject != null) {
1108N/A String project = null;
1108N/A
1108N/A Cookie[] cookies = request.getCookies();
1108N/A if (cookies != null) {
1108N/A for (Cookie cookie : cookies) {
1108N/A if (cookie.getName().equals("OpenGrok/project")) {
1108N/A project = cookie.getValue();
1108N/A break;
1108N/A }
1108N/A }
1108N/A }
1108N/A
850N/A boolean set = false;
962N/A if (project != null) {
962N/A boolean found = false;
962N/A for (String aproj : project.split(" ")) {
962N/A if (activeProject.getPath().equalsIgnoreCase(aproj)) {
962N/A found = true;
850N/A break;
962N/A }
962N/A }
962N/A if (!found) {
850N/A set = true;
962N/A }
962N/A } else {
850N/A set = true;
1108N/A }
1108N/A
1108N/A if (set) {
1108N/A Cookie cookie = new Cookie("OpenGrok/project", activeProject.getPath());
1108N/A cookie.setPath(context + "/");
1108N/A response.addCookie(cookie);
1108N/A }
1108N/A }
1108N/A
1108N/A // If requesting a Directory listing -------------
1108N/A DirectoryListing dl = new DirectoryListing(ef);
1108N/A String[] files = resourceFile.list();
1108N/A if (files != null) {
1108N/A Arrays.sort(files, String.CASE_INSENSITIVE_ORDER);
1108N/A List<String> readMes = dl.listTo(resourceFile, out, path, files);
1108N/A if(readMes != null && readMes.size() > 0) {
1108N/A File xdir = new File(environment.getDataRootPath() + "/xref" + path);
1108N/A if(xdir.exists() && xdir.isDirectory()) {
1108N/A char[] buf = new char[8192];
1108N/A for (String readme : readMes) {
1108N/A try {
1108N/A Reader br = new FileReader(new File(xdir, readme));
1108N/A int len = 0;
1108N/A %><h3><%=readme%></h3><div id="src"><pre><%
1108N/A while((len = br.read(buf)) > 0) {
1108N/A out.write(buf, 0, len);
1108N/A }
1108N/A %></pre></div><%
1108N/A br.close();
1108N/A } catch(IOException e) {
1108N/A }
1108N/A }
1108N/A }
1108N/A }
1108N/A }
1108N/A } else if ((rev = request.getParameter("r")) != null && !rev.equals("")) {
1108N/A // Else if requesting a previous revision -------------
1108N/A if (noHistory) {
1108N/A response.sendError(404, "Revision not found");
1108N/A } else {
1108N/A FileAnalyzerFactory a = AnalyzerGuru.find(basename);
1108N/A Genre g = AnalyzerGuru.getGenre(a);
1108N/A if (g == Genre.PLAIN|| g == Genre.HTML || g == null) {
1108N/A InputStream in = null;
1108N/A try {
1108N/A in = HistoryGuru.getInstance().getRevision(resourceFile.getParent(), basename, rev);
1108N/A } catch (Exception e) {
1108N/A response.sendError(404, "Revision not found");
1108N/A return;
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 || g == null) {
1108N/A %><div id="src">Binary file [Click <a href="<%=context%>/raw<%=path%>?r=<%=rev%>">here</a> to download] </div><%
1108N/A } else {
1108N/A %><div id="src"><span class="pagetitle"><%=basename%> revision <%=rev%> </span><pre><%
1108N/A if (g == Genre.PLAIN) {
1108N/A Annotation annotation = annotate ? HistoryGuru.getInstance().annotate(resourceFile, rev) : null;
1108N/A AnalyzerGuru.writeXref(a, in, out, annotation, Project.getProject(resourceFile));
1108N/A } else if (g == Genre.IMAGE) {
1108N/A %><img src="<%=context%>/raw<%=path%>?r=<%=rev%>"/><%
1108N/A } else if (g == Genre.HTML) {
1108N/A char[] buf = new char[8192];
1108N/A Reader br = new InputStreamReader(in);
1108N/A int len = 0;
1108N/A while((len = br.read(buf)) > 0) {
1108N/A out.write(buf, 0, len);
1108N/A }
1108N/A } else {
1108N/A %> Click <a href="<%=context%>/raw<%=path%>?r=<%=rev%>">download <%=basename%></a><%
1108N/A }
1108N/A }
1108N/A } catch (IOException e) {
1108N/A %> <h3 class="error">IO Error</h3> <p> <%=e.getMessage() %> </p> <%
1108N/A }
1108N/A %></pre></div><%
1108N/A in.close();
1108N/A } else {
1108N/A %> <h3 class="error">Error reading file</h3> <%
1108N/A }
1108N/A } else if(g == Genre.IMAGE) {
1108N/A %><div id="src"><img src="<%=context%>/raw<%=path%>?r=<%=rev%>"/></div><%
1108N/A } else {
1108N/A %><div id="src"> Binary file [Click <a href="<%=context%>/raw<%=path%>?r=<%=rev%>">here</a> to download] </div><%
1108N/A }
1108N/A }
1108N/A } else {
1108N/A // requesting cross referenced file -------------
1108N/A File xrefSource = new File(environment.getDataRootFile(), "/xref");
1108N/A File xrefFile = new File(xrefSource, path + ".gz");
1108N/A Reader fileReader = null;
1108N/A
1108N/A if (environment.isCompressXref() && xrefFile.exists()) {
1108N/A fileReader = new InputStreamReader(new GZIPInputStream(new FileInputStream(xrefFile)));
1108N/A } else {
1108N/A xrefFile = new File(xrefSource, path);
1108N/A if (xrefFile.exists()) {
1108N/A fileReader = new FileReader(xrefFile);
1108N/A }
1108N/A }
1108N/A
1108N/A if (fileReader != null && !annotate) {
1108N/A char[] buf = new char[8192];
1108N/A BufferedReader br = new BufferedReader(fileReader);
1108N/A int len = 0;
1108N/A %><div id="src"><pre><%
1108N/A while((len = br.read(buf)) > 0) {
1108N/A out.write(buf, 0, len);
1108N/A }
1108N/A %></pre></div><%
1108N/A br.close();
1108N/A } else {
1108N/A BufferedInputStream bin = new BufferedInputStream(new FileInputStream(resourceFile));
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 %><div id="src"><img src="<%=context%>/raw<%=path%>"/></div><%
1108N/A } else if( g == Genre.HTML) {
1108N/A char[] buf = new char[8192];
1108N/A Reader br = new InputStreamReader(bin);
1108N/A int len = 0;
1108N/A while((len = br.read(buf)) > 0) {
1108N/A out.write(buf, 0, len);
1108N/A }
1108N/A } else if(g == Genre.PLAIN) {
1108N/A %><div id="src"><pre><%
1108N/A Annotation annotation = annotate ? HistoryGuru.getInstance().annotate(resourceFile, rev) : null;
1108N/A AnalyzerGuru.writeXref(a, bin, out, annotation, Project.getProject(resourceFile));
1108N/A %></pre></div><%
1108N/A } else {
1108N/A %> Click <a href="<%=context%>/raw<%=path%>">download <%=basename%></a><%
1108N/A }
1108N/A }
1108N/A }
1108N/A%><%@include file="foot.jspf"%><%
1108N/A}
1108N/Aif (ef != null) {
1108N/A try {
1108N/A ef.close();
1108N/A } catch (IOException e) {
1108N/A }
1108N/A}
1108N/A%>
1108N/A