list.jsp revision ca13a2073cb9936daab594cd277550783ac2e6b6
70N/A<%--
70N/ACDDL HEADER START
286N/A
70N/AThe contents of this file are subject to the terms of the
70N/ACommon Development and Distribution License (the "License").
70N/AYou may not use this file except in compliance with the License.
70N/A
70N/ASee LICENSE.txt included in this distribution for the specific
70N/Alanguage governing permissions and limitations under the License.
70N/A
70N/AWhen distributing Covered Code, include this CDDL HEADER in each
70N/Afile and include the License file at LICENSE.txt.
70N/AIf applicable, add the following below this CDDL HEADER, with the
70N/Afields enclosed by brackets "[]" replaced with your own identifying
70N/Ainformation: Portions Copyright [yyyy] [name of copyright owner]
70N/A
70N/ACDDL HEADER END
70N/A
70N/ACopyright 2005 Sun Microsystems, Inc. All rights reserved.
70N/AUse is subject to license terms.
70N/A
70N/Aident "%Z%%M% %I% %E% SMI"
70N/A
70N/A--%><%@ page import = "javax.servlet.*,
70N/Ajava.lang.*,
70N/Ajavax.servlet.http.*,
70N/Ajava.util.*,
70N/Ajava.io.*,
70N/Aorg.opensolaris.opengrok.analysis.*,
70N/Aorg.opensolaris.opengrok.configuration.Project,
424N/Aorg.opensolaris.opengrok.index.*,
70N/Aorg.opensolaris.opengrok.analysis.FileAnalyzer.Genre,
70N/Aorg.opensolaris.opengrok.web.*,
70N/Aorg.opensolaris.opengrok.history.*
359N/A"
359N/A%><%@include file="mast.jsp"%><%
359N/AString rev = null;
98N/Aif(!isDir && ef != null) {
321N/A try {
321N/A ef.close();
213N/A } catch (IOException e) {
304N/A }
325N/A ef = null;
320N/A}
332N/A
231N/Aif (valid) {
98N/A if (isDir) {
347N/A
346N/A // verify that the current path is part of the selected project
324N/A Project activeProject = Project.getProject(resourceFile);
347N/A
310N/A if (activeProject != null) {
316N/A String project = null;
290N/A
332N/A Cookie[] cookies = request.getCookies();
332N/A if (cookies != null) {
332N/A for (Cookie cookie : cookies) {
210N/A if (cookie.getName().equals("OpenGrok/project")) {
128N/A project = cookie.getValue();
414N/A break;
326N/A }
335N/A }
370N/A }
70N/A
400N/A boolean add = false;
294N/A if (project != null) {
98N/A boolean found = false;
277N/A for (String aproj : project.split(" ")) {
356N/A if (activeProject.getPath().equalsIgnoreCase(aproj)) {
289N/A found = true;
326N/A break;
290N/A }
424N/A }
286N/A if (!found) {
90N/A add = true;
295N/A }
70N/A } else {
299N/A add = true;
262N/A }
277N/A
332N/A if (add) {
332N/A if (project == null || project.length() == 0) {
70N/A project = activeProject.getPath();
70N/A } else {
319N/A project = project + " " + activeProject.getPath();
280N/A }
319N/A // update the cookie
359N/A Cookie cookie = new Cookie("OpenGrok/project", project);
418N/A cookie.setPath(context + "/");
418N/A response.addCookie(cookie);
70N/A }
98N/A }
98N/A
414N/A // If requesting a Directory listing -------------
98N/A DirectoryListing dl = new DirectoryListing(ef);
156N/A String[] files = resourceFile.list();
156N/A if (files != null) {
98N/A Arrays.sort(files, String.CASE_INSENSITIVE_ORDER);
70N/A ArrayList readMes = dl.listTo(resourceFile, out, path, files);
70N/A if(readMes != null && readMes.size() > 0) {
70N/A File xdir = new File(environment.getDataRootPath() + "/xref" + path);
70N/A if(xdir.exists() && xdir.isDirectory()) {
70N/A char[] buf = new char[8192];
70N/A for(int i = 0; i< readMes.size(); i++) {
70N/A try {
70N/A BufferedReader br = new BufferedReader(new FileReader(new File(xdir, (String)readMes.get(i))));
70N/A int len = 0;
70N/A %><h3><%=(String)readMes.get(i)%></h3><div id="src"><pre><%
70N/A while((len = br.read(buf)) > 0) {
70N/A out.write(buf, 0, len);
70N/A }
70N/A %></pre></div><%
380N/A br.close();
380N/A } catch(IOException e) {
380N/A }
70N/A }
70N/A }
70N/A }
70N/A }
253N/A } else if ((rev = request.getParameter("r")) != null && !rev.equals("")) {
70N/A// Else if requesting a previous revision -------------
70N/A if(noHistory) {
response.sendError(404, "Revision not found");
} else if (rev.matches("^[0-9]+(\\.[0-9]+)*$")) {
FileAnalyzerFactory a = AnalyzerGuru.find(basename);
Genre g = AnalyzerGuru.getGenre(a);
if (g == Genre.PLAIN|| g == Genre.HTML || g == null) {
InputStream in = null;
try{
in = HistoryGuru.getInstance().getRevision(resourceFile.getParent(), basename, rev);
} catch (Exception e) {
response.sendError(404, "Revision not found");
return;
}
if(in != null) {
try {
if (g == null) {
a = AnalyzerGuru.find(in);
g = AnalyzerGuru.getGenre(a);
}
if (g == Genre.DATA || g == Genre.XREFABLE || g == null) {
%> <div id="src">Binary file [Click <a href="<%=context%>/raw<%=uriEncodedName%>?r=<%=rev%>">here</a> to download] </div><%
} else {
%><div id="src"><span class="pagetitle"><%=basename%> revision <%=rev%> </span><pre>
<%
if (g == Genre.PLAIN) {
Annotation annotation = annotate ?
HistoryGuru.getInstance().annotate(resourceFile, rev) : null;
AnalyzerGuru.writeXref(a, in, out, annotation);
} else if (g == Genre.IMAGE) {
%><img src="<%=context%>/raw<%=path%>?r=<%=rev%>"/><%
} else if (g == Genre.HTML) {
char[] buf = new char[8192];
Reader br = new InputStreamReader(in);
int len = 0;
while((len = br.read(buf)) > 0) {
out.write(buf, 0, len);
}
} else {
%> Click <a href="<%=context%>/raw<%=path%>?r=<%=rev%>">download <%=basename%></a><%
}
}
} catch (IOException e) {
%> <h3 class="error">IO Error</h3> <p> <%=e.getMessage() %> </p> <%
}
%></pre></div><%
in.close();
} else {
%> <h3 class="error">Error reading file</h3> <%
}
} else if(g == Genre.IMAGE) {
%><div id="src"><img src="<%=context%>/raw<%=path%>?r=<%=rev%>"/></div><%
} else {
%><div id="src"> Binary file [Click <a href="<%=context%>/raw<%=path%>?r=<%=rev%>">here</a> to download] </div><%
}
} else {
%><h3 class="error">Error: Invalid Revision Number!</h3><%
}
} else {
// requesting cross referenced file -------------
String xrefSource = environment.getDataRootPath() + "/xref";
String resourceXFile = xrefSource + path;
File xrefFile = new File(resourceXFile);
if(xrefFile.exists() && !annotate) {
char[] buf = new char[8192];
BufferedReader br = new BufferedReader(new FileReader(resourceXFile));
int len = 0;
%><div id="src"><pre><%
while((len = br.read(buf)) > 0) {
out.write(buf, 0, len);
}
%></pre></div><%
br.close();
} else {
BufferedInputStream bin = new BufferedInputStream(new FileInputStream(resourceFile));
FileAnalyzerFactory a = AnalyzerGuru.find(basename);
Genre g = AnalyzerGuru.getGenre(a);
if(g == null) {
a = AnalyzerGuru.find(bin);
g = AnalyzerGuru.getGenre(a);
}
if (g == Genre.IMAGE) {
%><div id="src"><img src="<%=context%>/raw<%=path%>"/></div><%
} else if( g == Genre.HTML) {
char[] buf = new char[8192];
Reader br = new InputStreamReader(bin);
int len = 0;
while((len = br.read(buf)) > 0) {
out.write(buf, 0, len);
}
} else if(g == Genre.PLAIN) {
%><div id="src"><pre><%
Annotation annotation = annotate ?
HistoryGuru.getInstance().annotate(resourceFile, rev) : null;
AnalyzerGuru.writeXref(a, bin, out, annotation);
%></pre></div><%
} else {
%> Click <a href="<%=context%>/raw<%=uriEncodedName%>">download <%=basename%></a><%
}
}
}
%><%@include file="foot.jspf"%><%
}
if(ef != null) {
try {
ef.close();
} catch (IOException e) {
}
}
%>