list.jsp revision a7851548ebb1d736ee4564a71293fb8ee6ba460c
9b2bd54c98edb185a3985410367754ab33217362bnicholes<%--
9b2bd54c98edb185a3985410367754ab33217362bnicholesCDDL HEADER START
9b2bd54c98edb185a3985410367754ab33217362bnicholes
9b2bd54c98edb185a3985410367754ab33217362bnicholesThe contents of this file are subject to the terms of the
9b2bd54c98edb185a3985410367754ab33217362bnicholesCommon Development and Distribution License (the "License").
9b2bd54c98edb185a3985410367754ab33217362bnicholesYou may not use this file except in compliance with the License.
9b2bd54c98edb185a3985410367754ab33217362bnicholes
9b2bd54c98edb185a3985410367754ab33217362bnicholesSee LICENSE.txt included in this distribution for the specific
9b2bd54c98edb185a3985410367754ab33217362bnicholeslanguage governing permissions and limitations under the License.
9b2bd54c98edb185a3985410367754ab33217362bnicholes
9b2bd54c98edb185a3985410367754ab33217362bnicholesWhen distributing Covered Code, include this CDDL HEADER in each
9b2bd54c98edb185a3985410367754ab33217362bnicholesfile and include the License file at LICENSE.txt.
9b2bd54c98edb185a3985410367754ab33217362bnicholesIf applicable, add the following below this CDDL HEADER, with the
9b2bd54c98edb185a3985410367754ab33217362bnicholesfields enclosed by brackets "[]" replaced with your own identifying
9b2bd54c98edb185a3985410367754ab33217362bnicholesinformation: Portions Copyright [yyyy] [name of copyright owner]
9b2bd54c98edb185a3985410367754ab33217362bnicholes
9b2bd54c98edb185a3985410367754ab33217362bnicholesCDDL HEADER END
9b2bd54c98edb185a3985410367754ab33217362bnicholes
9b2bd54c98edb185a3985410367754ab33217362bnicholesCopyright 2005 Sun Microsystems, Inc. All rights reserved.
9b2bd54c98edb185a3985410367754ab33217362bnicholesUse is subject to license terms.
9b2bd54c98edb185a3985410367754ab33217362bnicholes--%><%@ page import = "javax.servlet.*,
9b2bd54c98edb185a3985410367754ab33217362bnicholesjava.lang.*,
70953fb44a7140fe206c3a5f011e24209c8c5c6abnicholesjavax.servlet.http.*,
70953fb44a7140fe206c3a5f011e24209c8c5c6abnicholesjava.util.*,
70953fb44a7140fe206c3a5f011e24209c8c5c6abnicholesjava.io.*,
9b2bd54c98edb185a3985410367754ab33217362bnicholesjava.util.zip.GZIPInputStream,
9b2bd54c98edb185a3985410367754ab33217362bnicholesjava.util.logging.Level,
9b2bd54c98edb185a3985410367754ab33217362bnicholesorg.opensolaris.opengrok.OpenGrokLogger,
9b2bd54c98edb185a3985410367754ab33217362bnicholesorg.opensolaris.opengrok.analysis.*,
9b2bd54c98edb185a3985410367754ab33217362bnicholesorg.opensolaris.opengrok.configuration.Project,
9b2bd54c98edb185a3985410367754ab33217362bnicholesorg.opensolaris.opengrok.index.*,
be06f010941d039a422f1bbd7e321a1a0e92e291bnicholesorg.opensolaris.opengrok.analysis.FileAnalyzer.Genre,
9b2bd54c98edb185a3985410367754ab33217362bnicholesorg.opensolaris.opengrok.web.*,
9b2bd54c98edb185a3985410367754ab33217362bnicholesorg.opensolaris.opengrok.history.*
9b2bd54c98edb185a3985410367754ab33217362bnicholes"
9b2bd54c98edb185a3985410367754ab33217362bnicholes%><%@include file="mast.jsp"%><%
9b2bd54c98edb185a3985410367754ab33217362bnicholesString rev = null;
9b2bd54c98edb185a3985410367754ab33217362bnicholesif(!isDir && ef != null) {
9b2bd54c98edb185a3985410367754ab33217362bnicholes try {
9b2bd54c98edb185a3985410367754ab33217362bnicholes ef.close();
9b2bd54c98edb185a3985410367754ab33217362bnicholes } catch (IOException e) {
9b2bd54c98edb185a3985410367754ab33217362bnicholes }
9b2bd54c98edb185a3985410367754ab33217362bnicholes ef = null;
9b2bd54c98edb185a3985410367754ab33217362bnicholes}
9b2bd54c98edb185a3985410367754ab33217362bnicholes
9b2bd54c98edb185a3985410367754ab33217362bnicholesif (valid) {
9b2bd54c98edb185a3985410367754ab33217362bnicholes if (isDir) {
9b2bd54c98edb185a3985410367754ab33217362bnicholes
9b2bd54c98edb185a3985410367754ab33217362bnicholes // verify that the current path is part of the selected project
9b2bd54c98edb185a3985410367754ab33217362bnicholes Project activeProject = Project.getProject(resourceFile);
9b2bd54c98edb185a3985410367754ab33217362bnicholes
9b2bd54c98edb185a3985410367754ab33217362bnicholes if (activeProject != null) {
9b2bd54c98edb185a3985410367754ab33217362bnicholes String project = null;
9b2bd54c98edb185a3985410367754ab33217362bnicholes
be06f010941d039a422f1bbd7e321a1a0e92e291bnicholes Cookie[] cookies = request.getCookies();
9b2bd54c98edb185a3985410367754ab33217362bnicholes if (cookies != null) {
9b2bd54c98edb185a3985410367754ab33217362bnicholes for (Cookie cookie : cookies) {
9b2bd54c98edb185a3985410367754ab33217362bnicholes if (cookie.getName().equals("OpenGrok/project")) {
9b2bd54c98edb185a3985410367754ab33217362bnicholes project = cookie.getValue();
9b2bd54c98edb185a3985410367754ab33217362bnicholes break;
9b2bd54c98edb185a3985410367754ab33217362bnicholes }
be06f010941d039a422f1bbd7e321a1a0e92e291bnicholes }
9b2bd54c98edb185a3985410367754ab33217362bnicholes }
9b2bd54c98edb185a3985410367754ab33217362bnicholes
9b2bd54c98edb185a3985410367754ab33217362bnicholes boolean set = false;
9b2bd54c98edb185a3985410367754ab33217362bnicholes if (project != null) {
9b2bd54c98edb185a3985410367754ab33217362bnicholes boolean found = false;
9b2bd54c98edb185a3985410367754ab33217362bnicholes for (String aproj : project.split(" ")) {
be06f010941d039a422f1bbd7e321a1a0e92e291bnicholes if (activeProject.getPath().equalsIgnoreCase(aproj)) {
9b2bd54c98edb185a3985410367754ab33217362bnicholes found = true;
9b2bd54c98edb185a3985410367754ab33217362bnicholes break;
9b2bd54c98edb185a3985410367754ab33217362bnicholes }
9b2bd54c98edb185a3985410367754ab33217362bnicholes }
9b2bd54c98edb185a3985410367754ab33217362bnicholes if (!found) {
9b2bd54c98edb185a3985410367754ab33217362bnicholes set = true;
be06f010941d039a422f1bbd7e321a1a0e92e291bnicholes }
9b2bd54c98edb185a3985410367754ab33217362bnicholes } else {
9b2bd54c98edb185a3985410367754ab33217362bnicholes set = true;
9b2bd54c98edb185a3985410367754ab33217362bnicholes }
9b2bd54c98edb185a3985410367754ab33217362bnicholes
9b2bd54c98edb185a3985410367754ab33217362bnicholes if (set) {
9b2bd54c98edb185a3985410367754ab33217362bnicholes Cookie cookie = new Cookie("OpenGrok/project", activeProject.getPath());
9b2bd54c98edb185a3985410367754ab33217362bnicholes cookie.setPath(context + "/");
9b2bd54c98edb185a3985410367754ab33217362bnicholes response.addCookie(cookie);
9b2bd54c98edb185a3985410367754ab33217362bnicholes }
9b2bd54c98edb185a3985410367754ab33217362bnicholes }
9b2bd54c98edb185a3985410367754ab33217362bnicholes
9b2bd54c98edb185a3985410367754ab33217362bnicholes // If requesting a Directory listing -------------
9b2bd54c98edb185a3985410367754ab33217362bnicholes DirectoryListing dl = new DirectoryListing(ef);
9b2bd54c98edb185a3985410367754ab33217362bnicholes String[] files = resourceFile.list();
9b2bd54c98edb185a3985410367754ab33217362bnicholes if (files != null) {
9b2bd54c98edb185a3985410367754ab33217362bnicholes Arrays.sort(files, String.CASE_INSENSITIVE_ORDER);
9b2bd54c98edb185a3985410367754ab33217362bnicholes List<String> readMes = dl.listTo(resourceFile, out, path, files);
9b2bd54c98edb185a3985410367754ab33217362bnicholes if(readMes != null && readMes.size() > 0) {
9b2bd54c98edb185a3985410367754ab33217362bnicholes File xdir = new File(environment.getDataRootPath() + "/xref" + path);
9b2bd54c98edb185a3985410367754ab33217362bnicholes if (xdir.exists() && xdir.isDirectory()) {
9b2bd54c98edb185a3985410367754ab33217362bnicholes char[] buf = new char[8192];
9b2bd54c98edb185a3985410367754ab33217362bnicholes for (String readme : readMes) {
9b2bd54c98edb185a3985410367754ab33217362bnicholes File readmeFile = new File(xdir, readme + ".gz");
9b2bd54c98edb185a3985410367754ab33217362bnicholes Reader br = null;
9b2bd54c98edb185a3985410367754ab33217362bnicholes try {
9b2bd54c98edb185a3985410367754ab33217362bnicholes if (environment.isCompressXref() && readmeFile.exists()) {
9b2bd54c98edb185a3985410367754ab33217362bnicholes br = new InputStreamReader(new GZIPInputStream(new FileInputStream(readmeFile)));
9b2bd54c98edb185a3985410367754ab33217362bnicholes } else {
9b2bd54c98edb185a3985410367754ab33217362bnicholes readmeFile = new File(xdir, readme);
9b2bd54c98edb185a3985410367754ab33217362bnicholes if (readmeFile.exists()) {
9b2bd54c98edb185a3985410367754ab33217362bnicholes br = new FileReader(readmeFile);
9b2bd54c98edb185a3985410367754ab33217362bnicholes }
9b2bd54c98edb185a3985410367754ab33217362bnicholes }
9b2bd54c98edb185a3985410367754ab33217362bnicholes
9b2bd54c98edb185a3985410367754ab33217362bnicholes if (br != null) {
9b2bd54c98edb185a3985410367754ab33217362bnicholes int len = 0;
9b2bd54c98edb185a3985410367754ab33217362bnicholes %><h3><%=readme%></h3><div id="src"><pre><%
9b2bd54c98edb185a3985410367754ab33217362bnicholes while((len = br.read(buf)) > 0) {
9b2bd54c98edb185a3985410367754ab33217362bnicholes out.write(buf, 0, len);
be06f010941d039a422f1bbd7e321a1a0e92e291bnicholes }
9b2bd54c98edb185a3985410367754ab33217362bnicholes %></pre></div><%
9b2bd54c98edb185a3985410367754ab33217362bnicholes }
9b2bd54c98edb185a3985410367754ab33217362bnicholes } catch(IOException e) {
9b2bd54c98edb185a3985410367754ab33217362bnicholes OpenGrokLogger.getLogger().log(Level.WARNING, "An error occured while reading/writing readme:", e);
9b2bd54c98edb185a3985410367754ab33217362bnicholes } finally {
9b2bd54c98edb185a3985410367754ab33217362bnicholes if (br != null) {
9b2bd54c98edb185a3985410367754ab33217362bnicholes try {
9b2bd54c98edb185a3985410367754ab33217362bnicholes br.close();
9b2bd54c98edb185a3985410367754ab33217362bnicholes } catch (IOException e) {
9b2bd54c98edb185a3985410367754ab33217362bnicholes OpenGrokLogger.getLogger().log(Level.WARNING, "An error occured while closing file:", e);
9b2bd54c98edb185a3985410367754ab33217362bnicholes }
9b2bd54c98edb185a3985410367754ab33217362bnicholes }
9b2bd54c98edb185a3985410367754ab33217362bnicholes }
9b2bd54c98edb185a3985410367754ab33217362bnicholes }
9b2bd54c98edb185a3985410367754ab33217362bnicholes }
9b2bd54c98edb185a3985410367754ab33217362bnicholes }
9b2bd54c98edb185a3985410367754ab33217362bnicholes }
9b2bd54c98edb185a3985410367754ab33217362bnicholes } else if ((rev = request.getParameter("r")) != null && !rev.equals("")) {
9b2bd54c98edb185a3985410367754ab33217362bnicholes // Else if requesting a previous revision -------------
9b2bd54c98edb185a3985410367754ab33217362bnicholes if (noHistory) {
9b2bd54c98edb185a3985410367754ab33217362bnicholes response.sendError(404, "Revision not found");
9b2bd54c98edb185a3985410367754ab33217362bnicholes } else {
9b2bd54c98edb185a3985410367754ab33217362bnicholes FileAnalyzerFactory a = AnalyzerGuru.find(basename);
9b2bd54c98edb185a3985410367754ab33217362bnicholes Genre g = AnalyzerGuru.getGenre(a);
9b2bd54c98edb185a3985410367754ab33217362bnicholes if (g == Genre.PLAIN|| g == Genre.HTML || g == null) {
be06f010941d039a422f1bbd7e321a1a0e92e291bnicholes InputStream in = null;
9b2bd54c98edb185a3985410367754ab33217362bnicholes try {
9b2bd54c98edb185a3985410367754ab33217362bnicholes in = HistoryGuru.getInstance().getRevision(resourceFile.getParent(), basename, rev);
9b2bd54c98edb185a3985410367754ab33217362bnicholes } catch (Exception e) {
9b2bd54c98edb185a3985410367754ab33217362bnicholes response.sendError(404, "Revision not found");
9b2bd54c98edb185a3985410367754ab33217362bnicholes return;
9b2bd54c98edb185a3985410367754ab33217362bnicholes }
be06f010941d039a422f1bbd7e321a1a0e92e291bnicholes if (in != null) {
9b2bd54c98edb185a3985410367754ab33217362bnicholes try {
9b2bd54c98edb185a3985410367754ab33217362bnicholes if (g == null) {
9b2bd54c98edb185a3985410367754ab33217362bnicholes a = AnalyzerGuru.find(in);
9b2bd54c98edb185a3985410367754ab33217362bnicholes g = AnalyzerGuru.getGenre(a);
9b2bd54c98edb185a3985410367754ab33217362bnicholes }
9b2bd54c98edb185a3985410367754ab33217362bnicholes if (g == Genre.DATA || g == Genre.XREFABLE || g == null) {
9b2bd54c98edb185a3985410367754ab33217362bnicholes %><div id="src">Binary file [Click <a href="<%=context%>/raw<%=path%>?r=<%=rev%>">here</a> to download] </div><%
9b2bd54c98edb185a3985410367754ab33217362bnicholes } else {
9b2bd54c98edb185a3985410367754ab33217362bnicholes %><div id="src"><span class="pagetitle"><%=basename%> revision <%=rev%> </span><pre><%
9b2bd54c98edb185a3985410367754ab33217362bnicholes if (g == Genre.PLAIN) {
9b2bd54c98edb185a3985410367754ab33217362bnicholes Annotation annotation = annotate ? HistoryGuru.getInstance().annotate(resourceFile, rev) : null;
9b2bd54c98edb185a3985410367754ab33217362bnicholes AnalyzerGuru.writeXref(a, in, out, annotation, Project.getProject(resourceFile));
9b2bd54c98edb185a3985410367754ab33217362bnicholes } else if (g == Genre.IMAGE) {
9b2bd54c98edb185a3985410367754ab33217362bnicholes %><img src="<%=context%>/raw<%=path%>?r=<%=rev%>"/><%
9b2bd54c98edb185a3985410367754ab33217362bnicholes } else if (g == Genre.HTML) {
9b2bd54c98edb185a3985410367754ab33217362bnicholes char[] buf = new char[8192];
9b2bd54c98edb185a3985410367754ab33217362bnicholes Reader br = new InputStreamReader(in);
9b2bd54c98edb185a3985410367754ab33217362bnicholes int len = 0;
9b2bd54c98edb185a3985410367754ab33217362bnicholes while((len = br.read(buf)) > 0) {
9b2bd54c98edb185a3985410367754ab33217362bnicholes out.write(buf, 0, len);
9b2bd54c98edb185a3985410367754ab33217362bnicholes }
f628b5980b3f4ae688b70ae449a1f50aea687384bnicholes } else {
f628b5980b3f4ae688b70ae449a1f50aea687384bnicholes %> Click <a href="<%=context%>/raw<%=path%>?r=<%=rev%>">download <%=basename%></a><%
f628b5980b3f4ae688b70ae449a1f50aea687384bnicholes }
9b2bd54c98edb185a3985410367754ab33217362bnicholes }
9b2bd54c98edb185a3985410367754ab33217362bnicholes } catch (IOException e) {
9b2bd54c98edb185a3985410367754ab33217362bnicholes %> <h3 class="error">IO Error</h3> <p> <%=e.getMessage() %> </p> <%
9b2bd54c98edb185a3985410367754ab33217362bnicholes }
9b2bd54c98edb185a3985410367754ab33217362bnicholes %></pre></div><%
9b2bd54c98edb185a3985410367754ab33217362bnicholes in.close();
9b2bd54c98edb185a3985410367754ab33217362bnicholes } else {
9b2bd54c98edb185a3985410367754ab33217362bnicholes %> <h3 class="error">Error reading file</h3> <%
be06f010941d039a422f1bbd7e321a1a0e92e291bnicholes }
9b2bd54c98edb185a3985410367754ab33217362bnicholes } else if(g == Genre.IMAGE) {
9b2bd54c98edb185a3985410367754ab33217362bnicholes %><div id="src"><img src="<%=context%>/raw<%=path%>?r=<%=rev%>"/></div><%
9b2bd54c98edb185a3985410367754ab33217362bnicholes } else {
9b2bd54c98edb185a3985410367754ab33217362bnicholes %><div id="src"> Binary file [Click <a href="<%=context%>/raw<%=path%>?r=<%=rev%>">here</a> to download] </div><%
9b2bd54c98edb185a3985410367754ab33217362bnicholes }
9b2bd54c98edb185a3985410367754ab33217362bnicholes }
9b2bd54c98edb185a3985410367754ab33217362bnicholes } else {
9b2bd54c98edb185a3985410367754ab33217362bnicholes // requesting cross referenced file -------------
9b2bd54c98edb185a3985410367754ab33217362bnicholes File xrefSource = new File(environment.getDataRootFile(), "/xref");
9b2bd54c98edb185a3985410367754ab33217362bnicholes File xrefFile = new File(xrefSource, path + ".gz");
9b2bd54c98edb185a3985410367754ab33217362bnicholes Reader fileReader = null;
9b2bd54c98edb185a3985410367754ab33217362bnicholes
9b2bd54c98edb185a3985410367754ab33217362bnicholes if (environment.isCompressXref() && xrefFile.exists()) {
9b2bd54c98edb185a3985410367754ab33217362bnicholes fileReader = new InputStreamReader(new GZIPInputStream(new FileInputStream(xrefFile)));
9b2bd54c98edb185a3985410367754ab33217362bnicholes } else {
9b2bd54c98edb185a3985410367754ab33217362bnicholes xrefFile = new File(xrefSource, path);
9b2bd54c98edb185a3985410367754ab33217362bnicholes if (xrefFile.exists()) {
9b2bd54c98edb185a3985410367754ab33217362bnicholes fileReader = new FileReader(xrefFile);
9b2bd54c98edb185a3985410367754ab33217362bnicholes }
9b2bd54c98edb185a3985410367754ab33217362bnicholes }
9b2bd54c98edb185a3985410367754ab33217362bnicholes
9b2bd54c98edb185a3985410367754ab33217362bnicholes if (fileReader != null && !annotate) {
9b2bd54c98edb185a3985410367754ab33217362bnicholes char[] buf = new char[8192];
9b2bd54c98edb185a3985410367754ab33217362bnicholes BufferedReader br = new BufferedReader(fileReader);
9b2bd54c98edb185a3985410367754ab33217362bnicholes int len = 0;
9b2bd54c98edb185a3985410367754ab33217362bnicholes %><div id="src"><pre><%
9b2bd54c98edb185a3985410367754ab33217362bnicholes while((len = br.read(buf)) > 0) {
9b2bd54c98edb185a3985410367754ab33217362bnicholes out.write(buf, 0, len);
9b2bd54c98edb185a3985410367754ab33217362bnicholes }
9b2bd54c98edb185a3985410367754ab33217362bnicholes %></pre></div><%
9b2bd54c98edb185a3985410367754ab33217362bnicholes br.close();
9b2bd54c98edb185a3985410367754ab33217362bnicholes } else {
9b2bd54c98edb185a3985410367754ab33217362bnicholes BufferedInputStream bin = new BufferedInputStream(new FileInputStream(resourceFile));
9b2bd54c98edb185a3985410367754ab33217362bnicholes FileAnalyzerFactory a = AnalyzerGuru.find(basename);
9b2bd54c98edb185a3985410367754ab33217362bnicholes Genre g = AnalyzerGuru.getGenre(a);
9b2bd54c98edb185a3985410367754ab33217362bnicholes if(g == null) {
9b2bd54c98edb185a3985410367754ab33217362bnicholes a = AnalyzerGuru.find(bin);
9b2bd54c98edb185a3985410367754ab33217362bnicholes g = AnalyzerGuru.getGenre(a);
9b2bd54c98edb185a3985410367754ab33217362bnicholes }
9b2bd54c98edb185a3985410367754ab33217362bnicholes if (g == Genre.IMAGE) {
9b2bd54c98edb185a3985410367754ab33217362bnicholes %><div id="src"><img src="<%=context%>/raw<%=path%>"/></div><%
9b2bd54c98edb185a3985410367754ab33217362bnicholes } else if( g == Genre.HTML) {
9b2bd54c98edb185a3985410367754ab33217362bnicholes char[] buf = new char[8192];
9b2bd54c98edb185a3985410367754ab33217362bnicholes Reader br = new InputStreamReader(bin);
9b2bd54c98edb185a3985410367754ab33217362bnicholes int len = 0;
9b2bd54c98edb185a3985410367754ab33217362bnicholes while((len = br.read(buf)) > 0) {
9b2bd54c98edb185a3985410367754ab33217362bnicholes out.write(buf, 0, len);
9b2bd54c98edb185a3985410367754ab33217362bnicholes }
9b2bd54c98edb185a3985410367754ab33217362bnicholes } else if(g == Genre.PLAIN) {
be06f010941d039a422f1bbd7e321a1a0e92e291bnicholes %><div id="src"><pre><%
9b2bd54c98edb185a3985410367754ab33217362bnicholes Annotation annotation = annotate ? HistoryGuru.getInstance().annotate(resourceFile, rev) : null;
9b2bd54c98edb185a3985410367754ab33217362bnicholes AnalyzerGuru.writeXref(a, bin, out, annotation, Project.getProject(resourceFile));
9b2bd54c98edb185a3985410367754ab33217362bnicholes %></pre></div><%
9b2bd54c98edb185a3985410367754ab33217362bnicholes } else {
9b2bd54c98edb185a3985410367754ab33217362bnicholes %> Click <a href="<%=context%>/raw<%=path%>">download <%=basename%></a><%
be06f010941d039a422f1bbd7e321a1a0e92e291bnicholes }
9b2bd54c98edb185a3985410367754ab33217362bnicholes }
9b2bd54c98edb185a3985410367754ab33217362bnicholes }
9b2bd54c98edb185a3985410367754ab33217362bnicholes %><%@include file="foot.jspf"%><%
9b2bd54c98edb185a3985410367754ab33217362bnicholes}
9b2bd54c98edb185a3985410367754ab33217362bnicholesif (ef != null) {
9b2bd54c98edb185a3985410367754ab33217362bnicholes try {
9b2bd54c98edb185a3985410367754ab33217362bnicholes ef.close();
9b2bd54c98edb185a3985410367754ab33217362bnicholes } catch (IOException e) {
9b2bd54c98edb185a3985410367754ab33217362bnicholes }
9b2bd54c98edb185a3985410367754ab33217362bnicholes}
9b2bd54c98edb185a3985410367754ab33217362bnicholes%>
9b2bd54c98edb185a3985410367754ab33217362bnicholes