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