mast.jsp revision 625d7e774c3d2fc1478d7748b618a88fcf5783a9
5403N/A<%--
5403N/ACDDL HEADER START
5717N/A
5403N/AThe contents of this file are subject to the terms of the
5403N/ACommon Development and Distribution License (the "License").
5403N/AYou may not use this file except in compliance with the License.
5403N/A
5403N/ASee LICENSE.txt included in this distribution for the specific
5403N/Alanguage governing permissions and limitations under the License.
5403N/A
5403N/AWhen distributing Covered Code, include this CDDL HEADER in each
5403N/Afile and include the License file at LICENSE.txt.
5403N/AIf applicable, add the following below this CDDL HEADER, with the
5403N/Afields enclosed by brackets "[]" replaced with your own identifying
5403N/Ainformation: Portions Copyright [yyyy] [name of copyright owner]
5403N/A
5403N/ACDDL HEADER END
5403N/A
5403N/ACopyright 2009 Sun Microsystems, Inc. All rights reserved.
5403N/AUse is subject to license terms.
5403N/A--%><%@ page import = "javax.servlet.*,
5403N/A java.lang.*,
5403N/A javax.servlet.http.*,
5403N/A java.util.*,
5403N/A java.io.*,
5403N/A org.opensolaris.opengrok.index.*,
5403N/A org.opensolaris.opengrok.configuration.*,
5403N/A org.opensolaris.opengrok.web.EftarFileReader,
6853N/A org.opensolaris.opengrok.web.Util,
6853N/A org.opensolaris.opengrok.history.HistoryGuru
6853N/A "
5403N/A %><%@ page session="false" %><%@ page errorPage="error.jsp"%><%
6853N/AString context = request.getContextPath();
6853N/AString servlet = request.getServletPath();
6853N/AString reqURI = request.getRequestURI();
6853N/AString path = request.getPathInfo();
6853N/Aif (path == null) path = "";
6853N/ARuntimeEnvironment environment = RuntimeEnvironment.getInstance();
6853N/Aenvironment.setUrlPrefix(context + "/s?");
6853N/Aenvironment.register();
5403N/AString rawSource = environment.getSourceRootPath();
5403N/AString resourcePath = rawSource + path;
5717N/AFile resourceFile = new File(resourcePath);
6853N/AresourcePath = resourceFile.getAbsolutePath();
6853N/Aboolean valid = true;
6853N/Aboolean noHistory = true;
6853N/Aboolean noAnnotation = true;
6853N/Aboolean annotate = false;
6853N/AString basename = resourceFile.getName();
6853N/Aboolean isDir = false;
6853N/AEftarFileReader ef = null;
6853N/AString parent = null;
5717N/AString parentBasename = resourceFile.getParentFile().getName();
5717N/AIgnoredNames ignoredNames = environment.getIgnoredNames();
5717N/AString uriEncodedName = Util.URIEncodePath(path);
6853N/A
6853N/Aif(resourcePath.length() < rawSource.length()
6853N/A|| ignoredNames.ignore(path)
5717N/A|| ignoredNames.ignore(parentBasename)
6853N/A|| !resourcePath.startsWith(rawSource)) {
6853N/A valid = false;
5717N/A response.sendError(404);
5403N/A return;
5403N/A} else if (!resourceFile.canRead() && resourcePath.startsWith(rawSource)) {
5403N/A String newPath = rawSource + "/on/" + path; //TODO do we still use "on" ???
5403N/A File newFile = new File(newPath);
5403N/A if(newFile.canRead()) {
5403N/A if(newFile.isDirectory() && servlet.startsWith("/xref") && !path.endsWith("/")) {
5403N/A response.sendRedirect(context + servlet + "/on" + path + "/");
5403N/A } else {
5403N/A response.sendRedirect(context + servlet + "/on" + path);
5403N/A }
5403N/A }
5403N/A valid = false;
5403N/A response.sendError(404);
5403N/A return;
5403N/A} else {
5403N/A valid = true;
5403N/A path = resourcePath.substring(rawSource.length());
5403N/A if ("".equals(path)) {
5403N/A path = "/";
5403N/A }
5403N/A if (File.separatorChar == '\\') {
5403N/A path = path.replace('\\','/');
5403N/A }
5403N/A isDir = resourceFile.isDirectory();
5403N/A if (isDir && !servlet.startsWith("/xref") && !servlet.startsWith("/hist")) { //if it is an existing directory perhaps people wanted directory xref
5403N/A if(!reqURI.endsWith("/")) {
5403N/A response.sendRedirect(context + "/xref" + path + "/");
5403N/A } else {
5403N/A response.sendRedirect(context + "/xref" + path);
5403N/A }
5403N/A } if (isDir && !reqURI.endsWith("/")) {
5403N/A response.sendRedirect(context + servlet + path +"/");
5403N/A } else {
5403N/A
5403N/A long flast = resourceFile.lastModified();
5403N/A String dtag = "";
5403N/A
5403N/A if (request.getDateHeader("If-Modified-Since") >= flast ) {
5403N/A response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
5403N/A valid = false;
5403N/A } else {
5403N/A
5403N/A response.setDateHeader("Last-Modified", flast);
5403N/A int lastSlash = path.lastIndexOf('/');
5403N/A parent = (lastSlash != -1) ? path.substring(0, lastSlash) : "";
5403N/A int pLastSlash = parent.lastIndexOf('/');
5403N/A parentBasename = pLastSlash != -1 ? parent.substring(pLastSlash+1) : parent;
5403N/A noHistory = !HistoryGuru.getInstance().hasHistory(resourceFile);
5403N/A noAnnotation = isDir ||
5403N/A !HistoryGuru.getInstance().hasAnnotation(resourceFile);
annotate = !noAnnotation &&
Boolean.parseBoolean(request.getParameter("a"));
try{
ef = new EftarFileReader(environment.getDataRootPath() + "/index/dtags.eftar");
dtag = ef.get(path);
if(servlet.startsWith("/xr")) {
} else {
if(ef != null) {
try {
ef.close();
} catch (IOException e) {
} finally {
ef = null;
}
}
}
} catch (Exception e) {
dtag = "";
}
String pageTitle="Cross Reference: " + path;
%><%@ include file="httpheader.jspf" %>
<body>
<% if (annotate) { %>
<script type="text/javascript" src="<%=context%>/jquery-1.4.min.js"></script>
<script type="text/javascript" src="<%=context%>/jquery.tooltip-1.3.pack.js"></script>
<script type="text/javascript">/* <![CDATA[ */
function toggle_annotations() {
var spans = document.getElementsByTagName("span");
for (var i = 0; i < spans.length; i++) {
var span = spans[i];
if (span.className == 'blame') {
span.className = 'blame-hidden';
} else if (span.className == 'blame-hidden') {
span.className = 'blame';
}
}
}
$().ready(function() {
$('a[id=r]').tooltip({
left: 5,
showURL: false
});
} );
/* ]]> */</script>
<% } %>
<div id="page">
<form action="<%=context%>/search">
<div id="header"><%@ include file="pageheader.jspf" %>
<div id="pagetitle"><b id="filename">Cross Reference: <%=basename%></b><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><%
}
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>
<%
} // date check
} // not a directory redirect
}
%>