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