list.jsp revision 202
0N/A<%--
0N/ACDDL HEADER START
0N/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
0N/ACDDL HEADER END
0N/A
0N/ACopyright 2005 Sun Microsystems, Inc. All rights reserved.
0N/AUse is subject to license terms.
0N/A
0N/Aident "%Z%%M% %I% %E% SMI"
0N/A
0N/A--%><%@ page import = "javax.servlet.*,
0N/Ajava.lang.*,
0N/Ajavax.servlet.http.*,
0N/Ajava.util.*,
0N/Ajava.io.*,
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) {
0N/A try {
0N/A ef.close();
0N/A } catch (IOException e) {
0N/A }
0N/A ef = null;
0N/A}
0N/A
0N/Aif (valid) {
0N/A if (isDir) {
123N/A
123N/A // verify that the current path is part of the selected project
123N/A Project activeProject = Project.getProject(resourceFile);
123N/A
123N/A if (activeProject != null) {
123N/A String project = null;
123N/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
123N/A boolean add = 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) {
123N/A add = true;
123N/A }
123N/A } else {
123N/A add = true;
123N/A }
123N/A
123N/A if (add) {
123N/A if (project == null || project.length() == 0) {
123N/A project = activeProject.getPath();
123N/A } else {
123N/A project = project + " " + activeProject.getPath();
123N/A }
123N/A // update the cookie
123N/A Cookie cookie = new Cookie("OpenGrok/project", project);
123N/A cookie.setPath(context + "/");
123N/A response.addCookie(cookie);
123N/A }
123N/A }
123N/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);
0N/A ArrayList 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);
0N/A if(xdir.exists() && xdir.isDirectory()) {
0N/A char[] buf = new char[8192];
0N/A for(int i = 0; i< readMes.size(); i++) {
0N/A try {
0N/A BufferedReader br = new BufferedReader(new FileReader(new File(xdir, (String)readMes.get(i))));
0N/A int len = 0;
0N/A %><h3><%=(String)readMes.get(i)%></h3><div id="src"><pre><%
0N/A while((len = br.read(buf)) > 0) {
0N/A out.write(buf, 0, len);
0N/A }
0N/A %></pre></div><%
0N/A br.close();
0N/A } catch(IOException e) {
0N/A }
0N/A }
0N/A }
0N/A }
0N/A }
0N/A } else if ((rev = request.getParameter("r")) != null && !rev.equals("")) {
0N/A// Else if requesting a previous revision -------------
0N/A if(noHistory) {
0N/A response.sendError(404, "Revision not found");
0N/A } else if (rev.matches("^[0-9]+(\\.[0-9]+)*$")) {
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;
0N/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 }
0N/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) {
151N/A %> <div id="src">Binary file [Click <a href="<%=context%>/raw<%=uriEncodedName%>?r=<%=rev%>">here</a> to download] </div><%
0N/A } else {
0N/A %><div id="src"><span class="pagetitle"><%=basename%> revision <%=rev%> </span><pre>
0N/A<%
0N/Aif (g == Genre.PLAIN) {
89N/A Annotation annotation = annotate ?
89N/A HistoryGuru.getInstance().annotate(resourceFile, rev) : null;
89N/A AnalyzerGuru.writeXref(a, in, out, annotation);
0N/A} else if (g == Genre.IMAGE) {
0N/A %><img src="<%=context%>/raw<%=path%>?r=<%=rev%>"/><%
0N/A} else if (g == Genre.HTML) {
0N/A char[] buf = new char[8192];
0N/A Reader br = new InputStreamReader(in);
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 {
0N/A %> Click <a href="<%=context%>/raw<%=path%>?r=<%=rev%>">download <%=basename%></a><%
0N/A}
0N/A }
0N/A } catch (IOException e) {
9N/A %> <h3 class="error">IO Error</h3> <p> <%=e.getMessage() %> </p> <%
9N/A
0N/A }
0N/A %></pre></div><%
0N/A in.close();
0N/A } else {
0N/A %> <h3 class="error">Error reading file</h3> <%
0N/A }
0N/A
0N/A } else if(g == Genre.IMAGE) {
0N/A %><div id="src"><img src="<%=context%>/raw<%=path%>?r=<%=rev%>"/></div><%
0N/A } else {
0N/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 {
0N/A %><h3 class="error">Error: Invalid Revision Number!</h3><%
0N/A }
0N/A } else {
0N/A// requesting cross referenced file -------------
0N/A
81N/A String xrefSource = environment.getDataRootPath() + "/xref";
0N/A String resourceXFile = xrefSource + path;
0N/A File xrefFile = new File(resourceXFile);
89N/A if(xrefFile.exists() && !annotate) {
0N/A char[] buf = new char[8192];
0N/A BufferedReader br = new BufferedReader(new FileReader(resourceXFile));
0N/A int len = 0;
0N/A %><div id="src"><pre><%
0N/A while((len = br.read(buf)) > 0) {
0N/A out.write(buf, 0, len);
0N/A }
0N/A %></pre></div><%
0N/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) {
0N/A %><div id="src"><pre><%
89N/A Annotation annotation = annotate ?
89N/A HistoryGuru.getInstance().annotate(resourceFile, rev) : null;
89N/A AnalyzerGuru.writeXref(a, bin, out, annotation);
0N/A %></pre></div><%
0N/A } else {
151N/A %> Click <a href="<%=context%>/raw<%=uriEncodedName%>">download <%=basename%></a><%
0N/A }
0N/A }
0N/A }
66N/A%><%@include file="foot.jspf"%><%
0N/A}
0N/Aif(ef != null) {
0N/A try {
0N/A ef.close();
0N/A } catch (IOException e) {
0N/A }
0N/A}
0N/A%>