list.jsp revision 921
460N/A<%--
460N/ACDDL HEADER START
460N/A
460N/AThe contents of this file are subject to the terms of the
460N/ACommon Development and Distribution License (the "License").
460N/AYou may not use this file except in compliance with the License.
460N/A
460N/ASee LICENSE.txt included in this distribution for the specific
460N/Alanguage governing permissions and limitations under the License.
460N/A
460N/AWhen distributing Covered Code, include this CDDL HEADER in each
460N/Afile and include the License file at LICENSE.txt.
460N/AIf applicable, add the following below this CDDL HEADER, with the
460N/Afields enclosed by brackets "[]" replaced with your own identifying
460N/Ainformation: Portions Copyright [yyyy] [name of copyright owner]
460N/A
460N/ACDDL HEADER END
460N/A
460N/ACopyright 2009 Sun Microsystems, Inc. All rights reserved.
460N/AUse is subject to license terms.
460N/A--%><%@ page import = "javax.servlet.*,
460N/Ajava.lang.*,
460N/Ajavax.servlet.http.*,
460N/Ajava.util.*,
460N/Ajava.io.*,
460N/Ajava.util.zip.GZIPInputStream,
460N/Ajava.util.logging.Level,
460N/Aorg.opensolaris.opengrok.OpenGrokLogger,
460N/Aorg.opensolaris.opengrok.analysis.*,
460N/Aorg.opensolaris.opengrok.configuration.Project,
460N/Aorg.opensolaris.opengrok.index.*,
460N/Aorg.opensolaris.opengrok.analysis.FileAnalyzer.Genre,
460N/Aorg.opensolaris.opengrok.web.*,
460N/Aorg.opensolaris.opengrok.history.*
460N/A"
460N/A%><%@include file="mast.jsp"%><script type="text/javascript">/* <![CDATA[ */
460N/Afunction lntoggle() {
460N/A var a = document.getElementsByTagName("a");
460N/A for (var i = 0; i < a.length; i++) {
460N/A var el = a[i];
460N/A if (el.className == 'l' || el.className == 'hl') {
460N/A el.className=el.className+'-hide';
460N/A el.setAttribute("tmp", el.innerHTML);
460N/A el.innerHTML='';
460N/A }
460N/A else if (el.className == 'l-hide' || el.className == 'hl-hide') {
460N/A el.innerHTML=el.getAttribute("tmp");
460N/A el.className=el.className.substr(0,el.className.indexOf('-'));
460N/A }
460N/A }
460N/A}
460N/A/* ]]> */</script><%
460N/AString rev = null;
460N/Aif(!isDir && ef != null) {
460N/A try {
460N/A ef.close();
460N/A } catch (IOException e) {
460N/A }
460N/A ef = null;
460N/A}
460N/A
460N/Aif (valid) {
460N/A if (isDir) {
460N/A
460N/A // verify that the current path is part of the selected project
460N/A Project activeProject = Project.getProject(resourceFile);
460N/A//TODO: somehow integrate below with projects.jspf
460N/A if (activeProject != null) {
460N/A List<String> project = new ArrayList<String>();
460N/A
460N/A Cookie[] cookies = request.getCookies();
460N/A if (cookies != null) {
460N/A for (Cookie cookie : cookies) {
460N/A if (cookie.getName().equals("OpenGrok/project")) {
460N/A for (String proj : cookie.getValue().split(",")) {
460N/A if (proj != "") {
460N/A if (Project.getByDescription(proj) != null) {
460N/A project.add(proj);
460N/A }
460N/A }
460N/A }
460N/A }
460N/A }
460N/A }
460N/A
460N/A boolean set = false;
460N/A if (project != null) {
460N/A boolean found = false;
460N/A for (Iterator it = project.iterator(); it.hasNext();) {
460N/A
460N/A if (activeProject.getDescription().equalsIgnoreCase( (String)it.next() ) ) {
460N/A found = true;
460N/A break;
460N/A }
460N/A }
460N/A if (!found) {
set = true;
}
} else {
set = true;
}
// 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% :)
if (set) {
StringBuffer sproject=new StringBuffer(activeProject.getDescription()+",");
if (project!=null) {
//only save found projects into cookies
for (Iterator it = project.iterator(); it.hasNext();) {
sproject.append((String)it.next()+",");
}
}
// update the cookie
Cookie cookie = new Cookie("OpenGrok/project", sproject.toString());
cookie.setPath(context + "/");
response.addCookie(cookie);
}
}
// If requesting a Directory listing -------------
DirectoryListing dl = new DirectoryListing(ef);
String[] files = resourceFile.list();
if (files != null) {
Arrays.sort(files, String.CASE_INSENSITIVE_ORDER);
List<String> readMes = dl.listTo(resourceFile, out, path, files);
if(readMes != null && readMes.size() > 0) {
File xdir = new File(environment.getDataRootPath() + "/xref" + path);
if (xdir.exists() && xdir.isDirectory()) {
char[] buf = new char[8192];
for (String readme : readMes) {
File readmeFile = new File(xdir, readme + ".gz");
Reader br = null;
try {
if (environment.isCompressXref() && readmeFile.exists()) {
br = new InputStreamReader(new GZIPInputStream(new FileInputStream(readmeFile)));
} else {
readmeFile = new File(xdir, readme);
if (readmeFile.exists()) {
br = new FileReader(readmeFile);
}
}
if (br != null) {
int len = 0;
%><h3><%=readme%></h3><div id="src"><pre><%
while((len = br.read(buf)) > 0) {
out.write(buf, 0, len);
}
%></pre></div><%
}
} catch(IOException e) {
OpenGrokLogger.getLogger().log(Level.WARNING, "An error occured while reading/writing readme:", e);
} finally {
if (br != null) {
try {
br.close();
} catch (IOException e) {
OpenGrokLogger.getLogger().log(Level.WARNING, "An error occured while closing file:", e);
}
}
}
}
}
}
}
} else if ((rev = request.getParameter("r")) != null && !rev.equals("")) {
// Else if requesting a previous revision -------------
if (noHistory) {
response.sendError(404, "Revision not found");
} else {
FileAnalyzerFactory a = AnalyzerGuru.find(basename);
Genre g = AnalyzerGuru.getGenre(a);
if (g == Genre.PLAIN|| g == Genre.HTML || g == null) {
InputStream in = null;
try {
in = HistoryGuru.getInstance().getRevision(resourceFile.getParent(), basename, rev);
} catch (Exception e) {
response.sendError(404, "Revision not found");
return;
}
if (in != null) {
try {
if (g == null) {
a = AnalyzerGuru.find(in);
g = AnalyzerGuru.getGenre(a);
}
if (g == Genre.DATA || g == Genre.XREFABLE || g == null) {
%><div id="src">Binary file [Click <a href="<%=context%>/raw<%=path%>?r=<%=rev%>">here</a> to download] </div><%
} else {
%><div id="src"><span class="pagetitle"><%=basename%> revision <%=rev%> </span><pre><%
if (g == Genre.PLAIN) {
Annotation annotation = annotate ? HistoryGuru.getInstance().annotate(resourceFile, rev) : null;
//annotation.writeTooltipMap(out); //not needed yet
Reader r = new InputStreamReader(in);
AnalyzerGuru.writeXref(a, r, out, annotation, Project.getProject(resourceFile));
} else if (g == Genre.IMAGE) {
%><img src="<%=context%>/raw<%=path%>?r=<%=rev%>"/><%
} else if (g == Genre.HTML) {
char[] buf = new char[8192];
Reader br = new InputStreamReader(in);
int len = 0;
while((len = br.read(buf)) > 0) {
out.write(buf, 0, len);
}
} else {
%> Click <a href="<%=context%>/raw<%=path%>?r=<%=rev%>">download <%=basename%></a><%
}
}
} catch (IOException e) {
%> <h3 class="error">IO Error</h3> <p> <%=e.getMessage() %> </p> <%
}
%></pre></div><%
in.close();
} else {
%> <h3 class="error">Error reading file</h3> <%
}
} else if(g == Genre.IMAGE) {
%><div id="src"><img src="<%=context%>/raw<%=path%>?r=<%=rev%>"/></div><%
} else {
%><div id="src"> Binary file [Click <a href="<%=context%>/raw<%=path%>?r=<%=rev%>">here</a> to download] </div><%
}
}
} else {
// requesting cross referenced file -------------
File xrefSource = new File(environment.getDataRootFile(), "/xref");
File xrefFile = new File(xrefSource, path + ".gz");
Reader fileReader = null;
if (environment.isCompressXref() ) {
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;
Reader r = new InputStreamReader(bin);
AnalyzerGuru.writeXref(a, r, 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) {
}
}
%>