list.jsp revision 1142
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
1127N/ACopyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
0N/A--%><%@ page import = "javax.servlet.*,
0N/Ajava.lang.*,
0N/Ajavax.servlet.http.*,
0N/Ajava.util.*,
0N/Ajava.io.*,
335N/Ajava.util.zip.GZIPInputStream,
477N/Ajava.util.logging.Level,
477N/Aorg.opensolaris.opengrok.OpenGrokLogger,
0N/Aorg.opensolaris.opengrok.analysis.*,
123N/Aorg.opensolaris.opengrok.configuration.Project,
0N/Aorg.opensolaris.opengrok.index.*,
1127N/Aorg.opensolaris.opengrok.analysis.Definitions,
0N/Aorg.opensolaris.opengrok.analysis.FileAnalyzer.Genre,
0N/Aorg.opensolaris.opengrok.web.*,
0N/Aorg.opensolaris.opengrok.history.*
0N/A"
1108N/A%><%@include file="mast.jsp"%>
1108N/A<% if (!isDir) { %>
1108N/A<style type="text/css">
1108N/A .sym_list_style {
1108N/A position:absolute;
1108N/A top:100px;
1108N/A left:100px;
1108N/A width:100px;
1108N/A height:100px;
1108N/A overflow:auto;
1108N/A z-index: 10;
1108N/A border:solid 1px #c0c0c0;
1108N/A background-color:#ffffcc;
1108N/A color:#000;
1108N/A font-size:12px;
1108N/A font-family:monospace;
1108N/A padding:5px;
1108N/A opacity:0.9;
1108N/A filter:alpha(opacity=90)
1108N/A }
1108N/A
1108N/A .sym_list_style_hide {
1108N/A display: none;
1108N/A }
1108N/A}
1108N/A</style>
1108N/A<script type="text/javascript">/* <![CDATA[ */
850N/Afunction lntoggle() {
962N/A $("a").each(function() {
962N/A if (this.className == 'l' || this.className == 'hl') {
962N/A this.className=this.className+'-hide';
962N/A this.setAttribute("tmp", this.innerHTML);
962N/A this.innerHTML='';
850N/A }
962N/A else if (this.className == 'l-hide' || this.className == 'hl-hide') {
962N/A this.innerHTML=this.getAttribute("tmp");
962N/A this.className=this.className.substr(0,this.className.indexOf('-'));
850N/A }
962N/A }
962N/A );
850N/A}
1108N/A
1108N/Afunction get_sym_list_contents()
1108N/A{
1108N/A var contents = "";
1108N/A
1129N/A //contents += "<input id=\"input_highlight\" name=\"input_highlight\" class=\"q\"/>";
1129N/A //contents += "&nbsp;&nbsp;";
1129N/A //contents += "<b><a href=\"#\" onclick=\"javascript:add_highlight();return false;\" title=\"Add highlight\">Highlight</a></b><br>";
1129N/A contents += "<a href=\"#\" onclick=\"javascript:lsttoggle();\">[Close]</a><br>"
1108N/A
1108N/A var class_names=[
1108N/A "xm",
1108N/A "xe",
1108N/A "xs",
1108N/A "xt",
1108N/A "xv",
1108N/A "xi",
1108N/A "xc",
1135N/A "xn",
1135N/A "xp",
1108N/A "xf",
1135N/A "xmt",
1135N/A "xsr"];
1108N/A var type_names=[
1108N/A "Macro",
1108N/A "Enum",
1108N/A "Struct",
1108N/A "Typedef",
1108N/A "Variable",
1108N/A "Interface",
1108N/A "Class",
1135N/A "Namespace",
1135N/A "Package",
1108N/A "Function",
1135N/A "Method",
1135N/A "Subroutine"];
1108N/A var class_contents=[
1108N/A "",
1108N/A "",
1108N/A "",
1108N/A "",
1108N/A "",
1108N/A "",
1108N/A "",
1108N/A "",
1135N/A "",
1135N/A "",
1135N/A "",
1108N/A ""];
1108N/A
1108N/A $("a").each(
1108N/A function()
1108N/A {
1108N/A for (var i = 0; i < class_names.length; i++)
1108N/A {
1108N/A if (this.className == class_names[i])
1108N/A {
1108N/A var fname = this.innerHTML;
1108N/A if (fname != "")
1108N/A {
1108N/A // Use line number as accurate anchor
1108N/A var line = this.getAttribute("ln");
1108N/A
1108N/A class_contents[i] += "<a href=\"#" +
1108N/A line + "\" class=\"" + class_names[i] + "\">" +
1108N/A this.innerHTML + "</a><br>";
1108N/A
1108N/A }
1108N/A
1108N/A break;
1108N/A }
1108N/A }
1108N/A }
1108N/A );
1108N/A
1108N/A var count = 0;
1108N/A for (var i = 0; i < class_names.length; i++)
1108N/A {
1108N/A if (class_contents[i] != "")
1108N/A {
1108N/A if (count > 0)
1108N/A {
1108N/A contents += "<br>"
1108N/A }
1108N/A contents += "<b>" + type_names[i] + "</b><br>"
1108N/A contents += class_contents[i];
1108N/A
1108N/A count++;
1108N/A }
1108N/A }
1108N/A
1108N/A return contents;
1108N/A}
1108N/A
1108N/A// Initial value
1108N/Adocument.sym_div_width = 240;
1108N/Adocument.sym_div_height_max = 480;
1108N/Adocument.sym_div_top = 100;
1108N/Adocument.sym_div_left_margin = 40;
1108N/Adocument.sym_div_height_margin = 40;
1108N/A
1108N/Afunction get_sym_div_left()
1108N/A{
1108N/A document.sym_div_left = $(window).width() - (document.sym_div_width + document.sym_div_left_margin);
1108N/A return document.sym_div_left;
1108N/A}
1108N/A
1108N/Afunction get_sym_div_height()
1108N/A{
1108N/A document.sym_div_height = $(window).height() - document.sym_div_top - document.sym_div_height_margin;
1108N/A
1108N/A if (document.sym_div_height > document.sym_div_height_max)
1108N/A document.sym_div_height = document.sym_div_height_max;
1108N/A
1108N/A return document.sym_div_height;
1108N/A}
1108N/A
1108N/Afunction get_sym_div_top()
1108N/A{
1108N/A return document.sym_div_top;
1108N/A}
1108N/A
1108N/Afunction get_sym_div_width()
1108N/A{
1108N/A return document.sym_div_width;
1108N/A}
1108N/A
1108N/Afunction lsttoggle()
1108N/A{
1108N/A if (document.sym_div == null)
1108N/A {
1108N/A document.sym_div = document.createElement("div");
1108N/A document.sym_div.id = "sym_div";
1108N/A
1108N/A document.sym_div.className = "sym_list_style";
1108N/A document.sym_div.style.margin = "0px auto";
1108N/A document.sym_div.style.width = get_sym_div_width() + "px";
1108N/A document.sym_div.style.height = get_sym_div_height() + "px";
1108N/A document.sym_div.style.top = get_sym_div_top() + "px";
1108N/A document.sym_div.style.left = get_sym_div_left() + "px";
1108N/A
1108N/A document.sym_div.innerHTML = get_sym_list_contents();
1108N/A
1108N/A document.body.appendChild(document.sym_div);
1108N/A document.sym_div_shown = 1;
1108N/A }
1108N/A else
1108N/A {
1108N/A if (document.sym_div_shown == 1)
1108N/A {
1108N/A document.sym_div.className = "sym_list_style_hide";
1108N/A document.sym_div_shown = 0;
1108N/A }
1108N/A else
1108N/A {
1108N/A document.sym_div.style.height = get_sym_div_height() + "px";
1108N/A document.sym_div.style.width = get_sym_div_width() + "px";
1108N/A document.sym_div.style.top = get_sym_div_top() + "px";
1108N/A document.sym_div.style.left = get_sym_div_left() + "px";
1108N/A document.sym_div.className = "sym_list_style";
1108N/A document.sym_div_shown = 1;
1108N/A }
1108N/A }
1108N/A}
1108N/A
1108N/A$(window).resize(
1108N/A function()
1108N/A {
1108N/A if (document.sym_div_shown == 1)
1108N/A {
1108N/A document.sym_div.style.left = get_sym_div_left() + "px";
1108N/A document.sym_div.style.height = get_sym_div_height() + "px";
1108N/A }
1108N/A }
1108N/A);
1108N/A
1108N/A// Highlighting
1108N/A/*
1108N/A// This will replace link's href contents as well, be careful
1108N/Afunction HighlightKeywordsFullText(keywords)
1108N/A{
1108N/A var el = $("body");
1108N/A
1108N/A $(keywords).each(
1108N/A function()
1108N/A {
1108N/A var pattern = new RegExp("("+this+")", ["gi"]);
1108N/A var rs = "<span style='background-color:#FFFF00;font-weight: bold;'>$1</span>";
1108N/A el.html(el.html().replace(pattern, rs));
1108N/A }
1108N/A );
1108N/A}
1108N/A//HighlightKeywordsFullText(["nfstcpsock"]);
1108N/A*/
1108N/A
1108N/Adocument.highlight_count = 0;
1108N/A// This only changes matching tag's style
1108N/Afunction HighlightKeyword(keyword)
1108N/A{
1108N/A var high_colors=[
1108N/A "#ffff66",
1108N/A "#ffcccc",
1108N/A "#ccccff",
1108N/A "#99ff99",
1108N/A "#cc66ff"];
1108N/A
1108N/A var pattern = "a:contains('" + keyword + "')";
1108N/A $(pattern).css({
1108N/A 'text-decoration' : 'underline',
1108N/A 'background-color' : high_colors[document.highlight_count % high_colors.length],
1108N/A 'font-weight' : 'bold'
1108N/A });
1108N/A
1108N/A document.highlight_count++;
1108N/A}
1108N/A
1108N/A//HighlightKeyword('timeval');
1108N/A
1108N/Afunction add_highlight()
1108N/A{
1108N/A var tbox = document.getElementById('input_highlight');
1108N/A HighlightKeyword(tbox.value);
1108N/A}
1108N/A
1108N/A/* ]]> */
1108N/A</script>
1108N/A<% } %>
1108N/A<%
0N/AString rev = null;
0N/Aif(!isDir && ef != null) {
335N/A try {
335N/A ef.close();
335N/A } catch (IOException e) {
335N/A }
335N/A ef = null;
0N/A}
0N/A
0N/Aif (valid) {
0N/A if (isDir) {
335N/A
123N/A // verify that the current path is part of the selected project
123N/A Project activeProject = Project.getProject(resourceFile);
896N/A//TODO: somehow integrate below with projects.jspf
123N/A if (activeProject != null) {
1142N/A final List<String> project = new ArrayList<String>();
335N/A
123N/A Cookie[] cookies = request.getCookies();
123N/A if (cookies != null) {
867N/A for (Cookie cookie : cookies) {
1141N/A if (cookie.getName().equals("OpenGrokProject")) {
867N/A for (String proj : cookie.getValue().split(",")) {
867N/A if (proj != "") {
867N/A if (Project.getByDescription(proj) != null) {
867N/A project.add(proj);
867N/A }
867N/A }
123N/A }
123N/A }
867N/A }
123N/A }
123N/A
1142N/A boolean found = false;
1142N/A for (String proj : project) {
1142N/A if (activeProject.getDescription().equalsIgnoreCase(proj)) {
1142N/A found = true;
1142N/A break;
1142N/A }
123N/A }
867N/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% :)
1142N/A if (!found) {
867N/A StringBuffer sproject=new StringBuffer(activeProject.getDescription()+",");
867N/A if (project!=null) {
867N/A //only save found projects into cookies
867N/A for (Iterator it = project.iterator(); it.hasNext();) {
867N/A sproject.append((String)it.next()+",");
867N/A }
867N/A }
867N/A // update the cookie
1141N/A Cookie cookie = new Cookie("OpenGrokProject", sproject.toString());
867N/A cookie.setPath(context + "/");
867N/A response.addCookie(cookie);
123N/A }
123N/A }
335N/A
123N/A // If requesting a Directory listing -------------
47N/A DirectoryListing dl = new DirectoryListing(ef);
0N/A String[] files = resourceFile.list();
0N/A if (files != null) {
0N/A Arrays.sort(files, String.CASE_INSENSITIVE_ORDER);
470N/A List<String> readMes = dl.listTo(resourceFile, out, path, files);
0N/A if(readMes != null && readMes.size() > 0) {
1111N/A File xdir = new File(environment.getDataRootPath() + Constants.xrefP + path);
477N/A if (xdir.exists() && xdir.isDirectory()) {
0N/A char[] buf = new char[8192];
470N/A for (String readme : readMes) {
477N/A File readmeFile = new File(xdir, readme + ".gz");
477N/A Reader br = null;
477N/A try {
477N/A if (environment.isCompressXref() && readmeFile.exists()) {
477N/A br = new InputStreamReader(new GZIPInputStream(new FileInputStream(readmeFile)));
477N/A } else {
477N/A readmeFile = new File(xdir, readme);
477N/A if (readmeFile.exists()) {
477N/A br = new FileReader(readmeFile);
477N/A }
477N/A }
477N/A
477N/A if (br != null) {
477N/A int len = 0;
477N/A %><h3><%=readme%></h3><div id="src"><pre><%
477N/A while((len = br.read(buf)) > 0) {
477N/A out.write(buf, 0, len);
477N/A }
477N/A %></pre></div><%
477N/A }
477N/A } catch(IOException e) {
477N/A OpenGrokLogger.getLogger().log(Level.WARNING, "An error occured while reading/writing readme:", e);
477N/A } finally {
477N/A if (br != null) {
477N/A try {
335N/A br.close();
477N/A } catch (IOException e) {
477N/A OpenGrokLogger.getLogger().log(Level.WARNING, "An error occured while closing file:", e);
477N/A }
0N/A }
477N/A }
0N/A }
0N/A }
0N/A }
0N/A }
0N/A } else if ((rev = request.getParameter("r")) != null && !rev.equals("")) {
335N/A // Else if requesting a previous revision -------------
335N/A if (noHistory) {
335N/A response.sendError(404, "Revision not found");
283N/A } else {
202N/A FileAnalyzerFactory a = AnalyzerGuru.find(basename);
0N/A Genre g = AnalyzerGuru.getGenre(a);
0N/A if (g == Genre.PLAIN|| g == Genre.HTML || g == null) {
0N/A InputStream in = null;
335N/A try {
0N/A in = HistoryGuru.getInstance().getRevision(resourceFile.getParent(), basename, rev);
0N/A } catch (Exception e) {
0N/A response.sendError(404, "Revision not found");
27N/A return;
0N/A }
335N/A if (in != null) {
0N/A try {
0N/A if (g == null) {
0N/A a = AnalyzerGuru.find(in);
0N/A g = AnalyzerGuru.getGenre(a);
0N/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><%
0N/A } else {
335N/A %><div id="src"><span class="pagetitle"><%=basename%> revision <%=rev%> </span><pre><%
335N/A if (g == Genre.PLAIN) {
1127N/A // We don't have any way to get definitions
1127N/A // for old revisions currently.
1127N/A Definitions defs = null;
335N/A Annotation annotation = annotate ? HistoryGuru.getInstance().annotate(resourceFile, rev) : null;
878N/A //annotation.writeTooltipMap(out); //not needed yet
921N/A Reader r = new InputStreamReader(in);
1127N/A AnalyzerGuru.writeXref(a, r, out, defs, annotation, Project.getProject(resourceFile));
335N/A } else if (g == Genre.IMAGE) {
1111N/A %><img src="<%=context+Constants.rawP+path%>?r=<%=rev%>"/><%
335N/A } else if (g == Genre.HTML) {
335N/A char[] buf = new char[8192];
335N/A Reader br = new InputStreamReader(in);
335N/A int len = 0;
335N/A while((len = br.read(buf)) > 0) {
335N/A out.write(buf, 0, len);
335N/A }
335N/A } else {
1111N/A %> Click <a href="<%=context+Constants.rawP+path%>?r=<%=rev%>">download <%=basename%></a><%
335N/A }
0N/A }
0N/A } catch (IOException e) {
335N/A %> <h3 class="error">IO Error</h3> <p> <%=e.getMessage() %> </p> <%
0N/A }
335N/A %></pre></div><%
335N/A in.close();
0N/A } else {
335N/A %> <h3 class="error">Error reading file</h3> <%
0N/A }
0N/A } else if(g == Genre.IMAGE) {
1111N/A %><div id="src"><img src="<%=context+Constants.rawP+path%>?r=<%=rev%>"/></div><%
0N/A } else {
1111N/A %><div id="src"> Binary file [Click <a href="<%=context+Constants.rawP+path%>?r=<%=rev%>">here</a> to download] </div><%
0N/A }
0N/A }
0N/A } else {
335N/A // requesting cross referenced file -------------
1111N/A File xrefSource = new File(environment.getDataRootFile(), Constants.xrefP);
335N/A File xrefFile = new File(xrefSource, path + ".gz");
335N/A Reader fileReader = null;
335N/A
849N/A if (environment.isCompressXref() ) {
849N/A if (xrefFile.exists()) {
335N/A fileReader = new InputStreamReader(new GZIPInputStream(new FileInputStream(xrefFile)));
849N/A }
849N/A } else {
335N/A xrefFile = new File(xrefSource, path);
335N/A if (xrefFile.exists()) {
335N/A fileReader = new FileReader(xrefFile);
335N/A }
335N/A }
335N/A
335N/A if (fileReader != null && !annotate) {
0N/A char[] buf = new char[8192];
335N/A BufferedReader br = new BufferedReader(fileReader);
0N/A int len = 0;
335N/A %><div id="src"><pre><%
335N/A while((len = br.read(buf)) > 0) {
0N/A out.write(buf, 0, len);
335N/A }
335N/A %></pre></div><%
335N/A br.close();
0N/A } else {
0N/A BufferedInputStream bin = new BufferedInputStream(new FileInputStream(resourceFile));
202N/A FileAnalyzerFactory a = AnalyzerGuru.find(basename);
0N/A Genre g = AnalyzerGuru.getGenre(a);
0N/A if(g == null) {
0N/A a = AnalyzerGuru.find(bin);
0N/A g = AnalyzerGuru.getGenre(a);
0N/A }
0N/A if (g == Genre.IMAGE) {
1111N/A %><div id="src"><img src="<%=context+Constants.rawP+path%>"/></div><%
0N/A } else if( g == Genre.HTML) {
0N/A char[] buf = new char[8192];
0N/A Reader br = new InputStreamReader(bin);
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 if(g == Genre.PLAIN) {
335N/A %><div id="src"><pre><%
1127N/A // We're generating xref for the latest revision, so we can
1127N/A // find the definitions in the index.
1127N/A Definitions defs = IndexDatabase.getDefinitions(resourceFile);
878N/A Annotation annotation = annotate ? HistoryGuru.getInstance().annotate(resourceFile, rev) : null;
921N/A Reader r = new InputStreamReader(bin);
1127N/A AnalyzerGuru.writeXref(a, r, out, defs, annotation, Project.getProject(resourceFile));
335N/A %></pre></div><%
0N/A } else {
1111N/A %> Click <a href="<%=context+Constants.rawP+path%>">download <%=basename%></a><%
335N/A }
0N/A }
0N/A }
847N/A %><%@include file="foot.jspf"%><%
0N/A}
335N/Aif (ef != null) {
0N/A try {
0N/A ef.close();
0N/A } catch (IOException e) {
0N/A }
0N/A}
0N/A%>