list.jsp revision 81
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.
725N/AIf applicable, add the following below this CDDL HEADER, with the
131N/Afields enclosed by brackets "[]" replaced with your own identifying
758N/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.
500N/AUse is subject to license terms.
131N/A
131N/Aident "%Z%%M% %I% %E% SMI"
131N/A
131N/A--%><%@ page import = "javax.servlet.*,
131N/Ajava.lang.*,
131N/Ajavax.servlet.http.*,
131N/Ajava.util.*,
144N/Ajava.io.*,
131N/Ajava.text.*,
131N/Aorg.opensolaris.opengrok.analysis.*,
246N/Aorg.opensolaris.opengrok.index.*,
131N/Aorg.opensolaris.opengrok.analysis.FileAnalyzer.Genre,
131N/Aorg.opensolaris.opengrok.web.*,
816N/Aorg.opensolaris.opengrok.history.*
816N/A"
131N/A%><%@include file="mast.jsp"%><%
131N/AString rev = null;
131N/Aif(!isDir && ef != null) {
131N/A try {
340N/A ef.close();
340N/A } catch (IOException e) {
131N/A }
131N/A ef = null;
131N/A}
246N/A
131N/Aif (valid) {
131N/A if (isDir) {
131N/A// If requesting a Directory listing -------------
131N/A DirectoryListing dl = new DirectoryListing(ef);
816N/A String[] files = resourceFile.list();
816N/A if (files != null) {
131N/A Arrays.sort(files, String.CASE_INSENSITIVE_ORDER);
340N/A ArrayList readMes = dl.listTo(resourceFile, out, path, files);
340N/A if(readMes != null && readMes.size() > 0) {
340N/A File xdir = new File(environment.getDataRootPath() + "/xref" + path);
340N/A if(xdir.exists() && xdir.isDirectory()) {
131N/A char[] buf = new char[8192];
131N/A for(int i = 0; i< readMes.size(); i++) {
131N/A try {
920N/A BufferedReader br = new BufferedReader(new FileReader(new File(xdir, (String)readMes.get(i))));
920N/A int len = 0;
131N/A %><h3><%=(String)readMes.get(i)%></h3><div id="src"><pre><%
131N/A while((len = br.read(buf)) > 0) {
131N/A out.write(buf, 0, len);
214N/A }
214N/A %></pre></div><%
131N/A br.close();
131N/A } catch(IOException e) {
131N/A }
131N/A }
131N/A }
131N/A }
131N/A }
131N/A } else if ((rev = request.getParameter("r")) != null && !rev.equals("")) {
131N/A// Else if requesting a previous revision -------------
131N/A if(noHistory) {
131N/A response.sendError(404, "Revision not found");
131N/A } else if (rev.matches("^[0-9]+(\\.[0-9]+)*$")) {
131N/A Class a = AnalyzerGuru.find(basename);
131N/A Genre g = AnalyzerGuru.getGenre(a);
131N/A if (g == Genre.PLAIN|| g == Genre.HTML || g == null) {
131N/A InputStream in = null;
131N/A try{
131N/A in = HistoryGuru.getInstance().getRevision(resourceFile.getParent(), basename, rev);
131N/A } catch (Exception e) {
131N/A response.sendError(404, "Revision not found");
131N/A return;
131N/A }
131N/A if(in != null) {
131N/A try {
131N/A if (g == null) {
131N/A a = AnalyzerGuru.find(in);
227N/A g = AnalyzerGuru.getGenre(a);
131N/A }
131N/A if (g == Genre.DATA || g == Genre.XREFABLE || g == null) {
895N/A %> <div id="src">Binary file [Click <a href="<%=context%>/raw<%=path%>?r=<%=rev%>">here</a> to download] </div><%
895N/A } else {
131N/A %><div id="src"><span class="pagetitle"><%=basename%> revision <%=rev%> </span><pre>
131N/A<%
131N/Aif (g == Genre.PLAIN) {
131N/A AnalyzerGuru.writeXref(a, in, out);
} 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()) {
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));
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><%
AnalyzerGuru.writeXref(a, bin, out);
%></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) {
}
}
%>