list.jsp revision 1108
335N/A<%--
1186N/ACDDL HEADER START
1186N/A
0N/AThe contents of this file are subject to the terms of the
0N/ACommon Development and Distribution License (the "License").
0N/AYou may not use this file except in compliance with the License.
335N/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.
1244N/A--%><%@ page import = "javax.servlet.*,
1186N/Ajava.lang.*,
1186N/Ajavax.servlet.http.*,
1186N/Ajava.util.*,
1186N/Ajava.io.*,
1186N/Ajava.util.zip.GZIPInputStream,
1186N/Ajava.util.logging.Level,
1186N/Aorg.opensolaris.opengrok.OpenGrokLogger,
1186N/Aorg.opensolaris.opengrok.analysis.*,
1186N/Aorg.opensolaris.opengrok.configuration.Project,
1186N/Aorg.opensolaris.opengrok.index.*,
1186N/Aorg.opensolaris.opengrok.analysis.FileAnalyzer.Genre,
1186N/Aorg.opensolaris.opengrok.web.*,
1186N/Aorg.opensolaris.opengrok.history.*
1186N/A"
1186N/A%><%@include file="mast.jsp"%>
335N/A<% if (!isDir) { %>
1186N/A<style type="text/css">
477N/A .sym_list_style {
1186N/A position:absolute;
1127N/A top:100px;
0N/A left:100px;
1186N/A width:100px;
1186N/A height:100px;
1186N/A overflow:auto;
1186N/A z-index: 10;
1281N/A border:solid 1px #c0c0c0;
1108N/A background-color:#ffffcc;
1281N/A color:#000;
1281N/A font-size:12px;
1281N/A font-family:monospace;
1281N/A padding:5px;
1281N/A opacity:0.9;
1281N/A filter:alpha(opacity=90)
1281N/A }
1281N/A
1281N/A .sym_list_style_hide {
1281N/A display: none;
1281N/A }
1281N/A}
1281N/A</style>
1281N/A<script type="text/javascript">/* <![CDATA[ */
1145N/Afunction lntoggle() {
1281N/A $("a").each(function() {
1108N/A if (this.className == 'l' || this.className == 'hl') {
1186N/A this.className=this.className+'-hide';
335N/A this.setAttribute("tmp", this.innerHTML);
1186N/A this.innerHTML='';
1186N/A }
1186N/A else if (this.className == 'l-hide' || this.className == 'hl-hide') {
1186N/A this.innerHTML=this.getAttribute("tmp");
1186N/A this.className=this.className.substr(0,this.className.indexOf('-'));
1186N/A }
1281N/A }
1281N/A );
1281N/A}
1281N/A
1281N/Afunction get_sym_list_contents()
1281N/A{
1281N/A var contents = "";
1281N/A
1281N/A contents += "<input id=\"input_highlight\" name=\"input_highlight\" class=\"q\"/>";
1281N/A contents += "&nbsp;&nbsp;";
1281N/A contents += "<b><a href=\"#\" onclick=\"javascript:add_highlight();return false;\" title=\"Add highlight\">Highlight</a></b><br>";
1281N/A
1281N/A var class_names=[
1281N/A "xm",
1281N/A "xe",
1281N/A "xs",
1281N/A "xt",
1281N/A "xv",
1281N/A "xi",
1281N/A "xc",
1281N/A "xf",
1281N/A "xmt"];
1281N/A var type_names=[
1281N/A "Macro",
1281N/A "Enum",
1281N/A "Struct",
1281N/A "Typedef",
1281N/A "Variable",
1281N/A "Interface",
1281N/A "Class",
1281N/A "Function",
1281N/A "Method"];
1281N/A var class_contents=[
1281N/A "",
1281N/A "",
1281N/A "",
1281N/A "",
1281N/A "",
1186N/A "",
1186N/A "",
1281N/A "",
1281N/A ""];
1281N/A
1186N/A $("a").each(
1281N/A function()
1281N/A {
1281N/A for (var i = 0; i < class_names.length; i++)
1281N/A {
1281N/A if (this.className == class_names[i])
1281N/A {
1281N/A var fname = this.innerHTML;
1281N/A if (fname != "")
1281N/A {
1281N/A // Use line number as accurate anchor
1281N/A var line = this.getAttribute("ln");
1281N/A
1281N/A class_contents[i] += "<a href=\"#" +
1281N/A line + "\" class=\"" + class_names[i] + "\">" +
1281N/A this.innerHTML + "</a><br>";
1281N/A
1281N/A }
1281N/A
1281N/A break;
1281N/A }
1281N/A }
1281N/A }
1281N/A );
1281N/A
1281N/A var count = 0;
1186N/A for (var i = 0; i < class_names.length; i++)
1186N/A {
1281N/A if (class_contents[i] != "")
1281N/A {
1186N/A if (count > 0)
1281N/A {
1186N/A contents += "<br>"
1186N/A }
1281N/A contents += "<b>" + type_names[i] + "</b><br>"
1281N/A contents += class_contents[i];
1281N/A
1281N/A count++;
1281N/A }
1281N/A }
1281N/A
1281N/A return contents;
1281N/A}
1281N/A
1281N/A// Initial value
1281N/Adocument.sym_div_width = 240;
1281N/Adocument.sym_div_height_max = 480;
1281N/Adocument.sym_div_top = 100;
1281N/Adocument.sym_div_left_margin = 40;
1281N/Adocument.sym_div_height_margin = 40;
1281N/A
1281N/Afunction get_sym_div_left()
1281N/A{
1281N/A document.sym_div_left = $(window).width() - (document.sym_div_width + document.sym_div_left_margin);
1281N/A return document.sym_div_left;
1281N/A}
1281N/A
1281N/Afunction get_sym_div_height()
1281N/A{
1281N/A document.sym_div_height = $(window).height() - document.sym_div_top - document.sym_div_height_margin;
1281N/A
1281N/A if (document.sym_div_height > document.sym_div_height_max)
1281N/A document.sym_div_height = document.sym_div_height_max;
1281N/A
1281N/A return document.sym_div_height;
1281N/A}
1281N/A
1281N/Afunction get_sym_div_top()
1281N/A{
1281N/A return document.sym_div_top;
1281N/A}
1186N/A
1281N/Afunction get_sym_div_width()
1186N/A{
1186N/A return document.sym_div_width;
1281N/A}
1186N/A
1186N/Afunction lsttoggle()
1281N/A{
1281N/A if (document.sym_div == null)
1281N/A {
1186N/A document.sym_div = document.createElement("div");
1186N/A document.sym_div.id = "sym_div";
1281N/A
1186N/A document.sym_div.className = "sym_list_style";
1281N/A document.sym_div.style.margin = "0px auto";
1186N/A document.sym_div.style.width = get_sym_div_width() + "px";
1186N/A document.sym_div.style.height = get_sym_div_height() + "px";
1281N/A document.sym_div.style.top = get_sym_div_top() + "px";
1281N/A document.sym_div.style.left = get_sym_div_left() + "px";
1186N/A
1281N/A document.sym_div.innerHTML = get_sym_list_contents();
1281N/A
1281N/A document.body.appendChild(document.sym_div);
1281N/A document.sym_div_shown = 1;
1281N/A }
1281N/A else
1281N/A {
1281N/A if (document.sym_div_shown == 1)
1186N/A {
1186N/A document.sym_div.className = "sym_list_style_hide";
1281N/A document.sym_div_shown = 0;
1281N/A }
1281N/A else
1186N/A {
1281N/A document.sym_div.style.height = get_sym_div_height() + "px";
1281N/A document.sym_div.style.width = get_sym_div_width() + "px";
1281N/A document.sym_div.style.top = get_sym_div_top() + "px";
1281N/A document.sym_div.style.left = get_sym_div_left() + "px";
1281N/A document.sym_div.className = "sym_list_style";
1281N/A document.sym_div_shown = 1;
1281N/A }
1281N/A }
1281N/A}
1281N/A
1281N/A$(window).resize(
1281N/A function()
1186N/A {
1186N/A if (document.sym_div_shown == 1)
1281N/A {
1186N/A document.sym_div.style.left = get_sym_div_left() + "px";
1281N/A document.sym_div.style.height = get_sym_div_height() + "px";
1281N/A }
1281N/A }
1281N/A);
1186N/A
1186N/A// Highlighting
1281N/A/*
1281N/A// This will replace link's href contents as well, be careful
1281N/Afunction HighlightKeywordsFullText(keywords)
1281N/A{
1281N/A var el = $("body");
1281N/A
1281N/A $(keywords).each(
1281N/A function()
1281N/A {
1186N/A var pattern = new RegExp("("+this+")", ["gi"]);
1281N/A var rs = "<span style='background-color:#FFFF00;font-weight: bold;'>$1</span>";
1186N/A el.html(el.html().replace(pattern, rs));
1186N/A }
1281N/A );
1281N/A}
1281N/A//HighlightKeywordsFullText(["nfstcpsock"]);
1281N/A*/
1281N/A
1281N/Adocument.highlight_count = 0;
1281N/A// This only changes matching tag's style
1281N/Afunction HighlightKeyword(keyword)
1281N/A{
1281N/A var high_colors=[
1281N/A "#ffff66",
1281N/A "#ffcccc",
1281N/A "#ccccff",
1186N/A "#99ff99",
1186N/A "#cc66ff"];
1186N/A
477N/A var pattern = "a:contains('" + keyword + "')";
1186N/A $(pattern).css({
335N/A 'text-decoration' : 'underline',
1186N/A '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() + "/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) {
}
}
%>