list.jsp revision 477
335N/A<%--
1186N/ACDDL HEADER START
1186N/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.
335N/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.
1244N/A--%><%@ page import = "javax.servlet.*,
1186N/Ajava.lang.*,
1186N/Ajavax.servlet.http.*,
1368N/Ajava.util.*,
1368N/Ajava.io.*,
1186N/Ajava.util.zip.GZIPInputStream,
1355N/Ajava.util.logging.Level,
1355N/Aorg.opensolaris.opengrok.OpenGrokLogger,
1186N/Aorg.opensolaris.opengrok.analysis.*,
1186N/Aorg.opensolaris.opengrok.configuration.Project,
1186N/Aorg.opensolaris.opengrok.index.*,
1186N/Aorg.opensolaris.opengrok.analysis.FileAnalyzer.Genre,
1325N/Aorg.opensolaris.opengrok.web.*,
1325N/Aorg.opensolaris.opengrok.history.*
1186N/A"
1186N/A%><%@include file="mast.jsp"%><%
1186N/AString rev = null;
1186N/Aif(!isDir && ef != null) {
1186N/A try {
1127N/A ef.close();
0N/A } catch (IOException e) {
1186N/A }
1186N/A ef = null;
1355N/A}
1325N/A
1355N/Aif (valid) {
1355N/A if (isDir) {
1281N/A
1108N/A // verify that the current path is part of the selected project
1281N/A Project activeProject = Project.getProject(resourceFile);
1281N/A
1281N/A if (activeProject != null) {
1281N/A String project = null;
1281N/A
1281N/A Cookie[] cookies = request.getCookies();
1281N/A if (cookies != null) {
1354N/A for (Cookie cookie : cookies) {
1354N/A if (cookie.getName().equals("OpenGrok/project")) {
1281N/A project = cookie.getValue();
1281N/A break;
1281N/A }
1281N/A }
1281N/A }
1145N/A
1281N/A boolean set = false;
1108N/A if (project != null) {
1186N/A boolean found = false;
335N/A for (String aproj : project.split(" ")) {
1364N/A if (activeProject.getPath().equalsIgnoreCase(aproj)) {
1186N/A found = true;
1186N/A break;
1281N/A }
1281N/A }
1281N/A if (!found) {
1281N/A set = true;
1281N/A }
1281N/A } else {
1281N/A set = true;
1281N/A }
1281N/A
1281N/A if (set) {
1281N/A Cookie cookie = new Cookie("OpenGrok/project", activeProject.getPath());
1281N/A cookie.setPath(context + "/");
1281N/A response.addCookie(cookie);
1281N/A }
1281N/A }
1281N/A
1281N/A // If requesting a Directory listing -------------
1281N/A DirectoryListing dl = new DirectoryListing(ef);
1281N/A String[] files = resourceFile.list();
1281N/A if (files != null) {
1281N/A Arrays.sort(files, String.CASE_INSENSITIVE_ORDER);
1281N/A List<String> readMes = dl.listTo(resourceFile, out, path, files);
1281N/A if(readMes != null && readMes.size() > 0) {
1281N/A File xdir = new File(environment.getDataRootPath() + "/xref" + path);
1281N/A if (xdir.exists() && xdir.isDirectory()) {
1281N/A char[] buf = new char[8192];
1281N/A for (String readme : readMes) {
1281N/A File readmeFile = new File(xdir, readme + ".gz");
1325N/A Reader br = null;
1325N/A try {
1281N/A if (environment.isCompressXref() && readmeFile.exists()) {
1281N/A br = new InputStreamReader(new GZIPInputStream(new FileInputStream(readmeFile)));
1325N/A } else {
1325N/A readmeFile = new File(xdir, readme);
1325N/A if (readmeFile.exists()) {
1325N/A br = new FileReader(readmeFile);
1325N/A }
1325N/A }
1325N/A
1325N/A if (br != null) {
1325N/A int len = 0;
1325N/A %><h3><%=readme%></h3><div id="src"><pre><%
1325N/A while((len = br.read(buf)) > 0) {
1325N/A out.write(buf, 0, len);
1325N/A }
1325N/A %></pre></div><%
1325N/A }
1325N/A } catch(IOException e) {
1325N/A OpenGrokLogger.getLogger().log(Level.WARNING, "An error occured while reading/writing readme:", e);
1325N/A } finally {
1325N/A if (br != null) {
1325N/A try {
1325N/A br.close();
1325N/A } catch (IOException e) {
1325N/A OpenGrokLogger.getLogger().log(Level.WARNING, "An error occured while closing file:", e);
1325N/A }
1325N/A }
1325N/A }
1325N/A }
1325N/A }
1325N/A }
1325N/A }
1325N/A } else if ((rev = request.getParameter("r")) != null && !rev.equals("")) {
1325N/A // Else if requesting a previous revision -------------
1325N/A if (noHistory) {
1325N/A response.sendError(404, "Revision not found");
1325N/A } else {
1325N/A FileAnalyzerFactory a = AnalyzerGuru.find(basename);
1325N/A Genre g = AnalyzerGuru.getGenre(a);
1325N/A if (g == Genre.PLAIN|| g == Genre.HTML || g == null) {
1325N/A InputStream in = null;
1325N/A try {
1325N/A in = HistoryGuru.getInstance().getRevision(resourceFile.getParent(), basename, rev);
1368N/A } catch (Exception e) {
1368N/A response.sendError(404, "Revision not found");
1368N/A return;
1368N/A }
1368N/A if (in != null) {
1368N/A try {
1368N/A if (g == null) {
1368N/A a = AnalyzerGuru.find(in);
1368N/A g = AnalyzerGuru.getGenre(a);
1368N/A }
1368N/A if (g == Genre.DATA || g == Genre.XREFABLE || g == null) {
1368N/A %><div id="src">Binary file [Click <a href="<%=context%>/raw<%=path%>?r=<%=rev%>">here</a> to download] </div><%
1325N/A } else {
1325N/A %><div id="src"><span class="pagetitle"><%=basename%> revision <%=rev%> </span><pre><%
1325N/A if (g == Genre.PLAIN) {
1325N/A Annotation annotation = annotate ? HistoryGuru.getInstance().annotate(resourceFile, rev) : null;
1325N/A AnalyzerGuru.writeXref(a, in, out, annotation, Project.getProject(resourceFile));
1325N/A } else if (g == Genre.IMAGE) {
1325N/A %><img src="<%=context%>/raw<%=path%>?r=<%=rev%>"/><%
1325N/A } else if (g == Genre.HTML) {
1325N/A char[] buf = new char[8192];
1325N/A Reader br = new InputStreamReader(in);
1325N/A int len = 0;
1325N/A while((len = br.read(buf)) > 0) {
1325N/A out.write(buf, 0, len);
1325N/A }
1325N/A } else {
1325N/A %> Click <a href="<%=context%>/raw<%=path%>?r=<%=rev%>">download <%=basename%></a><%
1368N/A }
1368N/A }
1368N/A } catch (IOException e) {
1368N/A %> <h3 class="error">IO Error</h3> <p> <%=e.getMessage() %> </p> <%
1368N/A }
1368N/A %></pre></div><%
1368N/A in.close();
1368N/A } else {
1368N/A %> <h3 class="error">Error reading file</h3> <%
1368N/A }
1368N/A } else if(g == Genre.IMAGE) {
1368N/A %><div id="src"><img src="<%=context%>/raw<%=path%>?r=<%=rev%>"/></div><%
1368N/A } else {
1368N/A %><div id="src"> Binary file [Click <a href="<%=context%>/raw<%=path%>?r=<%=rev%>">here</a> to download] </div><%
1368N/A }
1368N/A }
1368N/A } else {
1368N/A // requesting cross referenced file -------------
1368N/A File xrefSource = new File(environment.getDataRootFile(), "/xref");
1368N/A File xrefFile = new File(xrefSource, path + ".gz");
1368N/A Reader fileReader = null;
1368N/A
1368N/A if (environment.isCompressXref() && xrefFile.exists()) {
1368N/A fileReader = new InputStreamReader(new GZIPInputStream(new FileInputStream(xrefFile)));
1368N/A } else {
1368N/A xrefFile = new File(xrefSource, path);
1368N/A if (xrefFile.exists()) {
1368N/A fileReader = new FileReader(xrefFile);
1368N/A }
1368N/A }
1368N/A
1368N/A if (fileReader != null && !annotate) {
1368N/A char[] buf = new char[8192];
1368N/A BufferedReader br = new BufferedReader(fileReader);
1368N/A int len = 0;
1368N/A %><div id="src"><pre><%
1368N/A while((len = br.read(buf)) > 0) {
1368N/A out.write(buf, 0, len);
1368N/A }
1368N/A %></pre></div><%
1368N/A br.close();
1368N/A } else {
1368N/A BufferedInputStream bin = new BufferedInputStream(new FileInputStream(resourceFile));
1368N/A FileAnalyzerFactory a = AnalyzerGuru.find(basename);
1368N/A Genre g = AnalyzerGuru.getGenre(a);
1368N/A if(g == null) {
1368N/A a = AnalyzerGuru.find(bin);
1186N/A g = AnalyzerGuru.getGenre(a);
1368N/A }
1368N/A if (g == Genre.IMAGE) {
1281N/A %><div id="src"><img src="<%=context%>/raw<%=path%>"/></div><%
1281N/A } else if( g == Genre.HTML) {
1281N/A char[] buf = new char[8192];
1281N/A Reader br = new InputStreamReader(bin);
1281N/A int len = 0;
1281N/A while((len = br.read(buf)) > 0) {
1281N/A out.write(buf, 0, len);
1281N/A }
1281N/A } else if(g == Genre.PLAIN) {
1281N/A %><div id="src"><pre><%
1281N/A Annotation annotation = annotate ? HistoryGuru.getInstance().annotate(resourceFile, rev) : null;
1281N/A AnalyzerGuru.writeXref(a, bin, out, annotation, Project.getProject(resourceFile));
1281N/A %></pre></div><%
1281N/A } else {
1281N/A %> Click <a href="<%=context%>/raw<%=path%>">download <%=basename%></a><%
1281N/A }
1281N/A }
1281N/A }
1281N/A%><%@include file="foot.jspf"%><%
1281N/A}
1281N/Aif (ef != null) {
1281N/A try {
1281N/A ef.close();
1186N/A } catch (IOException e) {
1186N/A }
1368N/A}
1281N/A%>
1186N/A