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