list.jsp revision 3c2aee4d6fd37062518aa6de5ad12d4967ebabc0
1247N/A<%--
1247N/ACDDL HEADER START
1247N/A
1247N/AThe contents of this file are subject to the terms of the
1247N/ACommon Development and Distribution License (the "License").
1247N/AYou may not use this file except in compliance with the License.
1247N/A
1247N/ASee LICENSE.txt included in this distribution for the specific
1247N/Alanguage governing permissions and limitations under the License.
1247N/A
1247N/AWhen distributing Covered Code, include this CDDL HEADER in each
1247N/Afile and include the License file at LICENSE.txt.
1247N/AIf applicable, add the following below this CDDL HEADER, with the
1247N/Afields enclosed by brackets "[]" replaced with your own identifying
1247N/Ainformation: Portions Copyright [yyyy] [name of copyright owner]
1247N/A
1247N/ACDDL HEADER END
1247N/A
1247N/ACopyright 2005 Sun Microsystems, Inc. All rights reserved.
1247N/AUse is subject to license terms.
1247N/A
1247N/Aident "%Z%%M% %I% %E% SMI"
1247N/A
1247N/A--%><%@ page import = "javax.servlet.*,
1247N/Ajava.lang.*,
1247N/Ajavax.servlet.http.*,
1247N/Ajava.util.*,
1247N/Ajava.io.*,
1247N/Ajava.text.*,
1247N/Aorg.opensolaris.opengrok.analysis.*,
1247N/Aorg.opensolaris.opengrok.index.*,
1247N/Aorg.opensolaris.opengrok.analysis.FileAnalyzer.Genre,
1247N/Aorg.opensolaris.opengrok.web.*,
1247N/Aorg.opensolaris.opengrok.history.*
1247N/A"
1247N/A%><%@include file="mast.jsp"%><%
1247N/AString rev = null;
1247N/Aif(!isDir && ef != null) {
1247N/A try {
1247N/A ef.close();
1247N/A } catch (IOException e) {
1247N/A }
1247N/A ef = null;
1247N/A}
1247N/A
1247N/Aif (valid) {
1247N/A if (isDir) {
1247N/A// If requesting a Directory listing -------------
1247N/A DirectoryListing dl = new DirectoryListing(ef);
1247N/A String[] files = resourceFile.list();
1247N/A if (files != null) {
1247N/A Arrays.sort(files, String.CASE_INSENSITIVE_ORDER);
1247N/A ArrayList readMes = dl.listTo(resourceFile, out, path, files);
1247N/A if(readMes != null && readMes.size() > 0) {
1247N/A File xdir = new File(getServletContext().getInitParameter("DATA_ROOT") + "/xref" + path);
1247N/A if(xdir.exists() && xdir.isDirectory()) {
1247N/A char[] buf = new char[8192];
1247N/A for(int i = 0; i< readMes.size(); i++) {
1247N/A try {
1247N/A BufferedReader br = new BufferedReader(new FileReader(new File(xdir, (String)readMes.get(i))));
1247N/A int len = 0;
1247N/A %><h3><%=(String)readMes.get(i)%></h3><div id="src"><pre><%
1247N/A while((len = br.read(buf)) > 0) {
1247N/A out.write(buf, 0, len);
1247N/A }
1247N/A %></pre></div><%
1247N/A br.close();
1247N/A } catch(IOException e) {
1247N/A }
1247N/A }
1247N/A }
1247N/A }
1247N/A }
1247N/A } else if ((rev = request.getParameter("r")) != null && !rev.equals("")) {
1247N/A// Else if requesting a previous revision -------------
1247N/A if(noHistory) {
1247N/A response.sendError(404, "Revision not found");
1247N/A } else if (rev.matches("^[0-9]+(\\.[0-9]+)*$")) {
1247N/A Class a = AnalyzerGuru.find(basename);
1247N/A Genre g = AnalyzerGuru.getGenre(a);
1247N/A if (g == Genre.PLAIN|| g == Genre.HTML || g == null) {
1247N/A InputStream in = null;
1247N/A try{
1247N/A in = HistoryGuru.getInstance().getRevision(resourceFile.getParent(), basename, rev);
1247N/A } catch (Exception e) {
1247N/A response.sendError(404, "Revision not found");
1247N/A return;
1247N/A }
1247N/A if(in != null) {
1247N/A try {
1247N/A if (g == null) {
1247N/A a = AnalyzerGuru.find(in);
1247N/A g = AnalyzerGuru.getGenre(a);
1247N/A }
1247N/A if (g == Genre.DATA || g == Genre.XREFABLE || g == null) {
1247N/A %> <div id="src">Binary file [Click <a href="<%=context%>/raw<%=path%>?r=<%=rev%>">here</a> to download] </div><%
1247N/A } else {
1247N/A %><div id="src"><span class="pagetitle"><%=basename%> revision <%=rev%> </span><pre>
1247N/A<%
1247N/Aif (g == Genre.PLAIN) {
1247N/A System.setProperty("urlPrefix", context+"/s?");
1247N/A AnalyzerGuru.writeXref(a, in, out);
1247N/A} else if (g == Genre.IMAGE) {
1247N/A %><img src="<%=context%>/raw<%=path%>?r=<%=rev%>"/><%
1247N/A} else if (g == Genre.HTML) {
1247N/A char[] buf = new char[8192];
1247N/A Reader br = new InputStreamReader(in);
1247N/A int len = 0;
1247N/A while((len = br.read(buf)) > 0) {
1247N/A out.write(buf, 0, len);
1247N/A }
1247N/A} else {
1247N/A %> Click <a href="<%=context%>/raw<%=path%>?r=<%=rev%>">download <%=basename%></a><%
1247N/A}
1247N/A }
1247N/A } catch (IOException e) {
1247N/A %> <h3 class="error">IO Error</h3> <p> <%=e.getMessage() %> </p> <%
1247N/A
1247N/A }
1247N/A %></pre></div><%
1247N/A in.close();
1247N/A } else {
1247N/A %> <h3 class="error">Error reading file</h3> <%
1247N/A }
1247N/A
1247N/A } else if(g == Genre.IMAGE) {
1247N/A %><div id="src"><img src="<%=context%>/raw<%=path%>?r=<%=rev%>"/></div><%
1247N/A } else {
1247N/A %><div id="src"> Binary file [Click <a href="<%=context%>/raw<%=path%>?r=<%=rev%>">here</a> to download] </div><%
1247N/A }
1247N/A
1247N/A } else {
1247N/A %><h3 class="error">Error: Invalid Revision Number!</h3><%
1247N/A }
1247N/A } else {
1247N/A// requesting cross referenced file -------------
1247N/A
1247N/A String xrefSource = getServletContext().getInitParameter("DATA_ROOT") + "/xref";
1247N/A String resourceXFile = xrefSource + path;
1247N/A File xrefFile = new File(resourceXFile);
1247N/A if(xrefFile.exists()) {
1247N/A char[] buf = new char[8192];
1247N/A BufferedReader br = new BufferedReader(new FileReader(resourceXFile));
1247N/A int len = 0;
1247N/A %><div id="src"><pre><%
1247N/A while((len = br.read(buf)) > 0) {
1247N/A out.write(buf, 0, len);
1247N/A }
1247N/A %></pre></div><%
br.close();
} else {
BufferedInputStream bin = new BufferedInputStream(new FileInputStream(resourceFile));
Class 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><%
System.setProperty("urlPrefix", context+"/s?");
AnalyzerGuru.writeXref(a, bin, out);
%></pre></div><%
} else {
%> Click <a href="<%=context%>/raw<%=path%>">download <%=basename%></a><%
}
}
}
%><%@include file="foot.jsp"%><%
}
if(ef != null) {
try {
ef.close();
} catch (IOException e) {
}
}
%>