list.jsp revision 02508b90a0eace220eabd5ec85ff37e9009c6b16
d3b29d4b61f1549244a7509b798be6f806cf7d4eTimo Sirainen<%--
2a90d8a14b0e7cc1508814bc87d3dfa598ef46a8Timo SirainenCDDL HEADER START
5355df8b66da35698449a10c2c83633a64995298Timo Sirainen
d99107ddf4d9bccb710994482daf65276a9d6321Timo SirainenThe contents of this file are subject to the terms of the
d99107ddf4d9bccb710994482daf65276a9d6321Timo SirainenCommon Development and Distribution License (the "License").
2a90d8a14b0e7cc1508814bc87d3dfa598ef46a8Timo SirainenYou may not use this file except in compliance with the License.
d3b29d4b61f1549244a7509b798be6f806cf7d4eTimo Sirainen
2a90d8a14b0e7cc1508814bc87d3dfa598ef46a8Timo SirainenSee LICENSE.txt included in this distribution for the specific
9137c55411aa39d41c1e705ddc34d5bd26c65021Timo Sirainenlanguage governing permissions and limitations under the License.
fc71e94957d0c2959a609450a2f303640d681858Sascha Wilde
9137c55411aa39d41c1e705ddc34d5bd26c65021Timo SirainenWhen distributing Covered Code, include this CDDL HEADER in each
2a90d8a14b0e7cc1508814bc87d3dfa598ef46a8Timo Sirainenfile and include the License file at LICENSE.txt.
bbe42963032af89fac1318844da08c742525cc87Timo SirainenIf applicable, add the following below this CDDL HEADER, with the
72b9d8039b714ea57c4e3b31bce32ef41cb414d4Timo Sirainenfields enclosed by brackets "[]" replaced with your own identifying
1299f2c3723ca9ccf8f9e563ec23ee1a1721fe4cTimo Siraineninformation: Portions Copyright [yyyy] [name of copyright owner]
9137c55411aa39d41c1e705ddc34d5bd26c65021Timo Sirainen
9137c55411aa39d41c1e705ddc34d5bd26c65021Timo SirainenCDDL HEADER END
fc71e94957d0c2959a609450a2f303640d681858Sascha Wilde
9137c55411aa39d41c1e705ddc34d5bd26c65021Timo SirainenCopyright 2009 Sun Microsystems, Inc. All rights reserved.
bbe42963032af89fac1318844da08c742525cc87Timo SirainenUse is subject to license terms.
53f37d41e1abb068131320f39f870fc92e81f560Timo Sirainen--%><%@ page import = "javax.servlet.*,
53f37d41e1abb068131320f39f870fc92e81f560Timo Sirainenjava.lang.*,
javax.servlet.http.*,
java.util.*,
java.io.*,
java.util.zip.GZIPInputStream,
java.util.logging.Level,
org.opensolaris.opengrok.OpenGrokLogger,
org.opensolaris.opengrok.analysis.*,
org.opensolaris.opengrok.configuration.Project,
org.opensolaris.opengrok.index.*,
org.opensolaris.opengrok.analysis.FileAnalyzer.Genre,
org.opensolaris.opengrok.web.*,
org.opensolaris.opengrok.history.*
"
%><%@include file="mast.jsp"%><script type="text/javascript">/* <![CDATA[ */
function lntoggle() {
$("a").each(function() {
if (this.className == 'l' || this.className == 'hl') {
this.className=this.className+'-hide';
this.setAttribute("tmp", this.innerHTML);
this.innerHTML='';
}
else if (this.className == 'l-hide' || this.className == 'hl-hide') {
this.innerHTML=this.getAttribute("tmp");
this.className=this.className.substr(0,this.className.indexOf('-'));
}
}
);
}
/* ]]> */</script><%
String rev = null;
if(!isDir && ef != null) {
try {
ef.close();
} catch (IOException e) {
}
ef = null;
}
if (valid) {
if (isDir) {
// verify that the current path is part of the selected project
Project activeProject = Project.getProject(resourceFile);
//TODO: somehow integrate below with projects.jspf
if (activeProject != null) {
List<String> project = new ArrayList<String>();
Cookie[] cookies = request.getCookies();
if (cookies != null) {
for (Cookie cookie : cookies) {
if (cookie.getName().equals("OpenGrok/project")) {
for (String proj : cookie.getValue().split(",")) {
if (proj != "") {
if (Project.getByDescription(proj) != null) {
project.add(proj);
}
}
}
}
}
}
boolean set = false;
if (project != null) {
boolean found = false;
for (Iterator it = project.iterator(); it.hasNext();) {
if (activeProject.getDescription().equalsIgnoreCase( (String)it.next() ) ) {
found = true;
break;
}
}
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) {
}
}
%>