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