list.jsp revision 878
335N/A<%--
0N/ACDDL HEADER START
0N/A
0N/AThe contents of this file are subject to the terms of the
335N/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 2009 Sun Microsystems, Inc. All rights reserved.
0N/AUse is subject to license terms.
0N/A--%><%@ page import = "javax.servlet.*,
0N/Ajava.lang.*,
0N/Ajavax.servlet.http.*,
0N/Ajava.util.*,
0N/Ajava.io.*,
335N/Ajava.util.zip.GZIPInputStream,
0N/Ajava.util.logging.Level,
123N/Aorg.opensolaris.opengrok.OpenGrokLogger,
0N/Aorg.opensolaris.opengrok.analysis.*,
0N/Aorg.opensolaris.opengrok.configuration.Project,
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"%><script type="text/javascript">/* <![CDATA[ */
335N/Afunction lntoggle() {
335N/A var a = document.getElementsByTagName("a");
335N/A for (var i = 0; i < a.length; i++) {
335N/A var el = a[i];
335N/A if (el.className == 'l' || el.className == 'hl') {
0N/A el.className=el.className+'-hide';
0N/A el.setAttribute("tmp", el.innerHTML);
0N/A el.innerHTML='';
0N/A }
335N/A else if (el.className == 'l-hide' || el.className == 'hl-hide') {
123N/A el.innerHTML=el.getAttribute("tmp");
123N/A el.className=el.className.substr(0,el.className.indexOf('-'));
335N/A }
123N/A }
123N/A}
335N/A/* ]]> */</script><%
123N/AString rev = null;
123N/Aif(!isDir && ef != null) {
123N/A try {
123N/A ef.close();
123N/A } catch (IOException e) {
123N/A }
123N/A ef = null;
123N/A}
123N/A
123N/Aif (valid) {
242N/A if (isDir) {
123N/A
123N/A // verify that the current path is part of the selected project
123N/A Project activeProject = Project.getProject(resourceFile);
123N/A
123N/A if (activeProject != null) {
123N/A List<String> project = new ArrayList<String>();
123N/A
123N/A Cookie[] cookies = request.getCookies();
123N/A if (cookies != null) {
242N/A for (Cookie cookie : cookies) {
123N/A if (cookie.getName().equals("OpenGrok/project")) {
123N/A for (String proj : cookie.getValue().split(",")) {
242N/A if (proj != "") {
123N/A if (Project.getByDescription(proj) != null) {
335N/A project.add(proj);
242N/A }
242N/A }
123N/A }
123N/A }
123N/A }
123N/A }
335N/A
123N/A boolean set = false;
47N/A if (project != null) {
0N/A boolean found = false;
0N/A for (Iterator it = project.iterator(); it.hasNext();) {
0N/A
470N/A if (activeProject.getDescription().equalsIgnoreCase( (String)it.next() ) ) {
0N/A found = true;
58N/A break;
0N/A }
0N/A }
470N/A if (!found) {
0N/A set = true;
470N/A }
335N/A } else {
470N/A set = true;
335N/A }
335N/A// set this in case there is no project selected or current cookie doesn't contain current project from the link, so the rest of search works 100% :)
335N/A if (set) {
335N/A StringBuffer sproject=new StringBuffer(activeProject.getDescription()+",");
335N/A if (project!=null) {
0N/A //only save found projects into cookies
0N/A for (Iterator it = project.iterator(); it.hasNext();) {
0N/A sproject.append((String)it.next()+",");
0N/A }
0N/A }
0N/A // update the cookie
0N/A Cookie cookie = new Cookie("OpenGrok/project", sproject.toString());
335N/A cookie.setPath(context + "/");
335N/A response.addCookie(cookie);
335N/A }
283N/A }
202N/A
0N/A // If requesting a Directory listing -------------
0N/A DirectoryListing dl = new DirectoryListing(ef);
0N/A String[] files = resourceFile.list();
335N/A if (files != null) {
0N/A Arrays.sort(files, String.CASE_INSENSITIVE_ORDER);
0N/A List<String> readMes = dl.listTo(resourceFile, out, path, files);
0N/A if(readMes != null && readMes.size() > 0) {
27N/A File xdir = new File(environment.getDataRootPath() + "/xref" + path);
0N/A if (xdir.exists() && xdir.isDirectory()) {
335N/A char[] buf = new char[8192];
0N/A for (String readme : readMes) {
0N/A File readmeFile = new File(xdir, readme + ".gz");
0N/A Reader br = null;
0N/A try {
0N/A if (environment.isCompressXref() && readmeFile.exists()) {
0N/A br = new InputStreamReader(new GZIPInputStream(new FileInputStream(readmeFile)));
335N/A } else {
0N/A readmeFile = new File(xdir, readme);
335N/A if (readmeFile.exists()) {
335N/A br = new FileReader(readmeFile);
335N/A }
335N/A }
335N/A
335N/A if (br != null) {
335N/A int len = 0;
335N/A %><h3><%=readme%></h3><div id="src"><pre><%
335N/A while((len = br.read(buf)) > 0) {
335N/A out.write(buf, 0, len);
335N/A }
335N/A %></pre></div><%
335N/A }
335N/A } catch(IOException e) {
335N/A OpenGrokLogger.getLogger().log(Level.WARNING, "An error occured while reading/writing readme:", e);
335N/A } finally {
0N/A if (br != null) {
0N/A try {
335N/A br.close();
0N/A } catch (IOException e) {
335N/A OpenGrokLogger.getLogger().log(Level.WARNING, "An error occured while closing file:", e);
335N/A }
0N/A }
335N/A }
0N/A }
0N/A }
335N/A }
0N/A }
335N/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");
335N/A } else {
335N/A FileAnalyzerFactory a = AnalyzerGuru.find(basename);
335N/A Genre g = AnalyzerGuru.getGenre(a);
335N/A if (g == Genre.PLAIN|| g == Genre.HTML || g == null) {
335N/A InputStream in = null;
335N/A try {
335N/A in = HistoryGuru.getInstance().getRevision(resourceFile.getParent(), basename, rev);
335N/A } catch (Exception e) {
335N/A response.sendError(404, "Revision not found");
335N/A return;
335N/A }
335N/A if (in != null) {
335N/A try {
335N/A if (g == null) {
335N/A a = AnalyzerGuru.find(in);
0N/A g = AnalyzerGuru.getGenre(a);
335N/A }
0N/A if (g == Genre.DATA || g == Genre.XREFABLE || g == null) {
335N/A %><div id="src">Binary file [Click <a href="<%=context%>/raw<%=path%>?r=<%=rev%>">here</a> to download] </div><%
335N/A } else {
0N/A %><div id="src"><span class="pagetitle"><%=basename%> revision <%=rev%> </span><pre><%
335N/A if (g == Genre.PLAIN) {
335N/A Annotation annotation = annotate ? HistoryGuru.getInstance().annotate(resourceFile, rev) : null;
335N/A //annotation.writeTooltipMap(out); //not needed yet
0N/A AnalyzerGuru.writeXref(a, in, out, annotation, Project.getProject(resourceFile));
0N/A } else if (g == Genre.IMAGE) {
202N/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) {
0N/A %> <h3 class="error">IO Error</h3> <p> <%=e.getMessage() %> </p> <%
0N/A }
0N/A %></pre></div><%
335N/A in.close();
335N/A } else {
335N/A %> <h3 class="error">Error reading file</h3> <%
335N/A }
0N/A } else if(g == Genre.IMAGE) {
335N/A %><div id="src"><img src="<%=context%>/raw<%=path%>?r=<%=rev%>"/></div><%
335N/A } else {
0N/A %><div id="src"> Binary file [Click <a href="<%=context%>/raw<%=path%>?r=<%=rev%>">here</a> to download] </div><%
0N/A }
66N/A }
0N/A } else {
335N/A // requesting cross referenced file -------------
0N/A File xrefSource = new File(environment.getDataRootFile(), "/xref");
0N/A File xrefFile = new File(xrefSource, path + ".gz");
0N/A Reader fileReader = null;
0N/A
0N/A if (environment.isCompressXref() ) {
0N/A if (xrefFile.exists()) {
fileReader = new InputStreamReader(new GZIPInputStream(new FileInputStream(xrefFile)));
}
} else {
xrefFile = new File(xrefSource, path);
if (xrefFile.exists()) {
fileReader = new FileReader(xrefFile);
}
}
if (fileReader != null && !annotate) {
char[] buf = new char[8192];
BufferedReader br = new BufferedReader(fileReader);
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));
FileAnalyzerFactory 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><%
Annotation annotation = annotate ? HistoryGuru.getInstance().annotate(resourceFile, rev) : null;
AnalyzerGuru.writeXref(a, bin, out, annotation, Project.getProject(resourceFile));
%></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) {
}
}
%>