mast.jsp revision 68903e4ab30e59de41fcf7293ec11b1ac96788b1
363N/A<%--
363N/ACDDL HEADER START
363N/A
363N/AThe contents of this file are subject to the terms of the
363N/ACommon Development and Distribution License (the "License").
363N/AYou may not use this file except in compliance with the License.
363N/A
363N/ASee LICENSE.txt included in this distribution for the specific
363N/Alanguage governing permissions and limitations under the License.
363N/A
363N/AWhen distributing Covered Code, include this CDDL HEADER in each
363N/Afile and include the License file at LICENSE.txt.
363N/AIf applicable, add the following below this CDDL HEADER, with the
363N/Afields enclosed by brackets "[]" replaced with your own identifying
363N/Ainformation: Portions Copyright [yyyy] [name of copyright owner]
363N/A
363N/ACDDL HEADER END
363N/A
363N/ACopyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
363N/A
3817N/A--%><%@ page import = "javax.servlet.*,
363N/A java.lang.*,
363N/A javax.servlet.http.*,
363N/A java.util.*,
2221N/A java.io.*,
2221N/A org.opensolaris.opengrok.index.*,
363N/A org.opensolaris.opengrok.configuration.*,
363N/A org.opensolaris.opengrok.web.EftarFileReader,
364N/A org.opensolaris.opengrok.web.Util,
363N/A org.opensolaris.opengrok.history.HistoryGuru
363N/A "
3062N/A %><%@ page session="false" %><%@ page errorPage="error.jsp"%><%
2221N/AString context = request.getContextPath();
363N/AString servlet = request.getServletPath();
844N/AString reqURI = request.getRequestURI();
3062N/AString path = request.getPathInfo();
363N/Aif (path == null) path = "";
2931N/ARuntimeEnvironment environment = RuntimeEnvironment.getInstance();
363N/Aenvironment.setUrlPrefix(context + "/s?");
3817N/Aenvironment.register();
3817N/AString rawSource = environment.getSourceRootPath();
363N/AString resourcePath = rawSource + path;
695N/AFile resourceFile = new File(resourcePath);
365N/AresourcePath = resourceFile.getAbsolutePath();
363N/Aboolean valid = true;
363N/Aboolean noHistory = true;
363N/Aboolean noAnnotation = true;
363N/Aboolean annotate = false;
363N/AString basename = resourceFile.getName();
2221N/Aboolean isDir = false;
363N/AEftarFileReader ef = null;
363N/AString parent = null;
363N/AString parentBasename = resourceFile.getParentFile().getName();
695N/AIgnoredNames ignoredNames = environment.getIgnoredNames();
363N/AString uriEncodedName = Util.URIEncodePath(path);
363N/A
363N/Aif(resourcePath.length() < rawSource.length()
4250N/A|| ignoredNames.ignore(path)
814N/A|| ignoredNames.ignore(parentBasename)
363N/A|| !resourcePath.startsWith(rawSource)) {
2221N/A valid = false;
791N/A response.sendError(404);
791N/A return;
791N/A} else if (!resourceFile.canRead() && resourcePath.startsWith(rawSource)) {
791N/A String newPath = rawSource + "/on/" + path; //TODO do we still use "on" ???
363N/A File newFile = new File(newPath);
3062N/A if(newFile.canRead()) {
3062N/A if(newFile.isDirectory() && servlet.startsWith("/xref") && !path.endsWith("/")) {
3062N/A response.sendRedirect(context + servlet + "/on" + path + "/");
3062N/A } else {
363N/A response.sendRedirect(context + servlet + "/on" + path);
3062N/A }
363N/A }
363N/A valid = false;
363N/A response.sendError(404);
363N/A return;
363N/A} else {
363N/A valid = true;
363N/A path = resourcePath.substring(rawSource.length());
363N/A if ("".equals(path)) {
363N/A path = "/";
363N/A }
363N/A if (File.separatorChar == '\\') {
2221N/A path = path.replace('\\','/');
2221N/A }
2221N/A isDir = resourceFile.isDirectory();
2221N/A if (isDir && !servlet.startsWith("/xref") && !servlet.startsWith("/hist")) { //if it is an existing directory perhaps people wanted directory xref
2221N/A if(!reqURI.endsWith("/")) {
2221N/A response.sendRedirect(context + "/xref" + path + "/");
2221N/A } else {
363N/A response.sendRedirect(context + "/xref" + path);
2221N/A }
2221N/A } if (isDir && !reqURI.endsWith("/")) {
363N/A response.sendRedirect(context + servlet + path +"/");
2221N/A } else {
363N/A
363N/A long flast = resourceFile.lastModified();
363N/A String dtag = "";
363N/A
363N/A if (request.getDateHeader("If-Modified-Since") >= flast ) {
695N/A response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
695N/A valid = false;
363N/A } else {
363N/A
363N/A response.setDateHeader("Last-Modified", flast);
363N/A int lastSlash = path.lastIndexOf('/');
363N/A parent = (lastSlash != -1) ? path.substring(0, lastSlash) : "";
363N/A int pLastSlash = parent.lastIndexOf('/');
3477N/A parentBasename = pLastSlash != -1 ? parent.substring(pLastSlash+1) : parent;
3477N/A noHistory = !HistoryGuru.getInstance().hasHistory(resourceFile);
363N/A noAnnotation = isDir ||
363N/A !HistoryGuru.getInstance().hasAnnotation(resourceFile);
363N/A annotate = !noAnnotation &&
363N/A Boolean.parseBoolean(request.getParameter("a"));
695N/A try{
363N/A ef = new EftarFileReader(environment.getDataRootPath() + "/index/dtags.eftar");
363N/A dtag = ef.get(path);
363N/A if(servlet.startsWith("/xr")) {
363N/A } else {
363N/A if(ef != null) {
363N/A try {
4514N/A ef.close();
2877N/A } catch (IOException e) {
363N/A } finally {
363N/A ef = null;
363N/A }
363N/A }
363N/A }
363N/A } catch (Exception e) {
363N/A dtag = "";
4337N/A }
4337N/A String pageTitle="Cross Reference: " + path;
%><%@ include file="httpheader.jspf" %><%//below style is for the fancy always on top search bar%>
<body style="overflow:hidden;">
<script type="text/javascript" src="<%=context%>/jquery-1.4.2.min.js"></script>
<script type="text/javascript">/* <![CDATA[ */
$().ready(function() {
if (!window.location.hash) {$('#content').focus();}
} );
/* ]]> */</script>
<% if (annotate) { %>
<script type="text/javascript" src="<%=context%>/jquery.tooltip-1.3.pack.js"></script>
<script type="text/javascript">/* <![CDATA[ */
function toggle_annotations() {
$("span").each(function() {
if (this.className == 'blame') {
this.className = 'blame-hidden';
} else if (this.className == 'blame-hidden') {
this.className = 'blame';
}
}
);
}
$().ready(function() {
$('a[id=r]').tooltip({
left: 5,
showURL: false
});
} );
/* ]]> */</script>
<% } %>
<div id="page">
<div id="whole_header" >
<form action="<%=context%>/search">
<div id="header"><%@ include file="pageheader.jspf" %>
<div id="pagetitle"><b id="filename">Cross Reference: <%=basename%></b><% if (dtag!=null & dtag!="") { %><br/><%=dtag%><% } %></div>
</div>
<div id="Masthead"><tt><a href="<%=context%>/xref/">xref</a>: <%=org.opensolaris.opengrok.web.Util.breadcrumbPath(context + "/xref", path)%></tt></div>
<div id="bar"><a href="<%=context%>/" id="home">Home</a> |
<%
if (noHistory || servlet.startsWith("/hi")) {
%> <span class="c" id="history">History</span><%
} else {
%><a id="history" href="<%=context%>/history<%=path%>">History</a><%
}
if (noAnnotation) {
%> | <span class="c" id="annotate">Annotate</span><%
} else {
String rev = request.getParameter("r");
if (rev == null) {
rev = "";
} else if (rev.length() > 0) {
rev = "&r=" + rev;
}
if (Boolean.parseBoolean(request.getParameter("a"))) {
%> | <span id="toggle-annotate-by-javascript" style="display: none">
<a href="#" onclick="javascript:toggle_annotations(); return false;" title="Show or hide line annotation(commit revisions,authors)." >Annotate</a>
</span>
<span id="toggle-annotate">
<a href="<%=context%>/xref<%=path%><%
if (rev.length() > 0) {
%>?<%=rev%><%
} %>">Annotate</a></span>
<script type="text/javascript">
<!--
var toggle_js = document.getElementById('toggle-annotate-by-javascript');
var toggle_ss = document.getElementById('toggle-annotate');
toggle_js.style.display = 'inline';
toggle_ss.style.display = 'none';
// -->
</script> <%
} else {
%> | <a href="<%=context%>/xref<%=path%>?a=true<%=rev%>">Annotate</a><%
}
}
if (!isDir) {
if ( servlet.startsWith("/xr") ) {
%> | <a href="#" onclick="javascript:lntoggle();return false;" title="Show or hide line numbers (might be slower if file has more than 10 000 lines).">Line #</a> | <a href="#" onclick="javascript:lsttoggle();return false;" title="Show or hide symbol list.">List</a><%
}
String rev = request.getParameter("r");
if (rev == null || rev.equals("")) {
%> | <a id="download" href="<%=context%>/raw<%=path%>">Download</a><%
} else {
%> | <a id="download" href="<%=context%>/raw<%=path%>?r=<%=rev%>">Download</a><%
}
}
Project proj = Project.getProject(resourceFile);
//if (proj != null || !environment.hasProjects())
{
%> | <input id="search" name="q" class="q"/>
<input type="submit" value="Search" class="submit"/>
<%
if (proj != null) {
%><input type="hidden" name="project" value="<%=proj.getDescription()%>"/><%
}
if(isDir) {
if(path.length() > 0) {
%><input type="checkbox" name="path" value="<%=path%>"/> only in <b><%=path%></b><%
}
} else {
%><input type="checkbox" name="path" value="<%=parent%>"/> only in <b><%=parentBasename%></b><%
}
}
%>
</div></form></div>
<div id="content"><%
} // date check
} // not a directory redirect
}
%>