list.jsp revision 1111
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"%>
335N/A<% if (!isDir) { %>
335N/A<style type="text/css">
335N/A .sym_list_style {
335N/A position:absolute;
335N/A top:100px;
0N/A left:100px;
0N/A width:100px;
0N/A height:100px;
0N/A overflow:auto;
335N/A z-index: 10;
123N/A border:solid 1px #c0c0c0;
123N/A background-color:#ffffcc;
335N/A color:#000;
123N/A font-size:12px;
123N/A font-family:monospace;
335N/A padding:5px;
123N/A opacity:0.9;
123N/A filter:alpha(opacity=90)
123N/A }
123N/A
123N/A .sym_list_style_hide {
123N/A display: none;
123N/A }
123N/A}
123N/A</style>
123N/A<script type="text/javascript">/* <![CDATA[ */
242N/Afunction lntoggle() {
123N/A $("a").each(function() {
123N/A if (this.className == 'l' || this.className == 'hl') {
123N/A this.className=this.className+'-hide';
123N/A this.setAttribute("tmp", this.innerHTML);
123N/A this.innerHTML='';
123N/A }
123N/A else if (this.className == 'l-hide' || this.className == 'hl-hide') {
123N/A this.innerHTML=this.getAttribute("tmp");
123N/A this.className=this.className.substr(0,this.className.indexOf('-'));
242N/A }
123N/A }
123N/A );
242N/A}
123N/A
335N/Afunction get_sym_list_contents()
242N/A{
242N/A var contents = "";
123N/A
123N/A contents += "<input id=\"input_highlight\" name=\"input_highlight\" class=\"q\"/>";
123N/A contents += "&nbsp;&nbsp;";
123N/A contents += "<b><a href=\"#\" onclick=\"javascript:add_highlight();return false;\" title=\"Add highlight\">Highlight</a></b><br>";
335N/A
123N/A var class_names=[
47N/A "xm",
0N/A "xe",
0N/A "xs",
0N/A "xt",
470N/A "xv",
0N/A "xi",
58N/A "xc",
0N/A "xf",
0N/A "xmt"];
470N/A var type_names=[
0N/A "Macro",
470N/A "Enum",
335N/A "Struct",
470N/A "Typedef",
335N/A "Variable",
335N/A "Interface",
335N/A "Class",
335N/A "Function",
335N/A "Method"];
0N/A var class_contents=[
0N/A "",
0N/A "",
0N/A "",
0N/A "",
0N/A "",
0N/A "",
335N/A "",
335N/A "",
335N/A ""];
283N/A
202N/A $("a").each(
0N/A function()
0N/A {
0N/A for (var i = 0; i < class_names.length; i++)
335N/A {
0N/A if (this.className == class_names[i])
0N/A {
0N/A var fname = this.innerHTML;
27N/A if (fname != "")
0N/A {
335N/A // Use line number as accurate anchor
0N/A var line = this.getAttribute("ln");
0N/A
0N/A class_contents[i] += "<a href=\"#" +
0N/A line + "\" class=\"" + class_names[i] + "\">" +
0N/A this.innerHTML + "</a><br>";
0N/A
335N/A }
0N/A
335N/A break;
335N/A }
335N/A }
335N/A }
335N/A );
335N/A
335N/A var count = 0;
335N/A for (var i = 0; i < class_names.length; i++)
335N/A {
335N/A if (class_contents[i] != "")
335N/A {
335N/A if (count > 0)
335N/A {
335N/A contents += "<br>"
335N/A }
335N/A contents += "<b>" + type_names[i] + "</b><br>"
0N/A contents += class_contents[i];
0N/A
335N/A count++;
0N/A }
335N/A }
335N/A
0N/A return contents;
335N/A}
0N/A
0N/A// Initial value
335N/Adocument.sym_div_width = 240;
0N/Adocument.sym_div_height_max = 480;
335N/Adocument.sym_div_top = 100;
0N/Adocument.sym_div_left_margin = 40;
0N/Adocument.sym_div_height_margin = 40;
0N/A
335N/Afunction get_sym_div_left()
335N/A{
335N/A document.sym_div_left = $(window).width() - (document.sym_div_width + document.sym_div_left_margin);
335N/A return document.sym_div_left;
335N/A}
335N/A
335N/Afunction get_sym_div_height()
335N/A{
335N/A document.sym_div_height = $(window).height() - document.sym_div_top - document.sym_div_height_margin;
335N/A
335N/A if (document.sym_div_height > document.sym_div_height_max)
335N/A document.sym_div_height = document.sym_div_height_max;
335N/A
335N/A return document.sym_div_height;
335N/A}
0N/A
335N/Afunction get_sym_div_top()
0N/A{
335N/A return document.sym_div_top;
335N/A}
0N/A
335N/Afunction get_sym_div_width()
335N/A{
335N/A return document.sym_div_width;
0N/A}
0N/A
202N/Afunction lsttoggle()
0N/A{
0N/A if (document.sym_div == null)
0N/A {
0N/A document.sym_div = document.createElement("div");
0N/A document.sym_div.id = "sym_div";
0N/A
0N/A document.sym_div.className = "sym_list_style";
0N/A document.sym_div.style.margin = "0px auto";
0N/A document.sym_div.style.width = get_sym_div_width() + "px";
0N/A document.sym_div.style.height = get_sym_div_height() + "px";
0N/A document.sym_div.style.top = get_sym_div_top() + "px";
0N/A document.sym_div.style.left = get_sym_div_left() + "px";
0N/A
0N/A document.sym_div.innerHTML = get_sym_list_contents();
0N/A
335N/A document.body.appendChild(document.sym_div);
335N/A document.sym_div_shown = 1;
335N/A }
335N/A else
0N/A {
335N/A if (document.sym_div_shown == 1)
335N/A {
0N/A document.sym_div.className = "sym_list_style_hide";
0N/A document.sym_div_shown = 0;
66N/A }
0N/A else
335N/A {
0N/A document.sym_div.style.height = get_sym_div_height() + "px";
0N/A document.sym_div.style.width = get_sym_div_width() + "px";
0N/A document.sym_div.style.top = get_sym_div_top() + "px";
0N/A document.sym_div.style.left = get_sym_div_left() + "px";
0N/A document.sym_div.className = "sym_list_style";
0N/A document.sym_div_shown = 1;
}
}
}
$(window).resize(
function()
{
if (document.sym_div_shown == 1)
{
document.sym_div.style.left = get_sym_div_left() + "px";
document.sym_div.style.height = get_sym_div_height() + "px";
}
}
);
// Highlighting
/*
// This will replace link's href contents as well, be careful
function HighlightKeywordsFullText(keywords)
{
var el = $("body");
$(keywords).each(
function()
{
var pattern = new RegExp("("+this+")", ["gi"]);
var rs = "<span style='background-color:#FFFF00;font-weight: bold;'>$1</span>";
el.html(el.html().replace(pattern, rs));
}
);
}
//HighlightKeywordsFullText(["nfstcpsock"]);
*/
document.highlight_count = 0;
// This only changes matching tag's style
function HighlightKeyword(keyword)
{
var high_colors=[
"#ffff66",
"#ffcccc",
"#ccccff",
"#99ff99",
"#cc66ff"];
var pattern = "a:contains('" + keyword + "')";
$(pattern).css({
'text-decoration' : 'underline',
'background-color' : high_colors[document.highlight_count % high_colors.length],
'font-weight' : 'bold'
});
document.highlight_count++;
}
//HighlightKeyword('timeval');
function add_highlight()
{
var tbox = document.getElementById('input_highlight');
HighlightKeyword(tbox.value);
}
/* ]]> */
</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() + Constants.xrefP + 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+Constants.rawP+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+Constants.rawP+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+Constants.rawP+path%>?r=<%=rev%>"/></div><%
} else {
%><div id="src"> Binary file [Click <a href="<%=context+Constants.rawP+path%>?r=<%=rev%>">here</a> to download] </div><%
}
}
} else {
// requesting cross referenced file -------------
File xrefSource = new File(environment.getDataRootFile(), Constants.xrefP);
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+Constants.rawP+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+Constants.rawP+path%>">download <%=basename%></a><%
}
}
}
%><%@include file="foot.jspf"%><%
}
if (ef != null) {
try {
ef.close();
} catch (IOException e) {
}
}
%>