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