mast.jsp revision 1126
286N/A<%--
286N/ACDDL HEADER START
286N/A
286N/AThe contents of this file are subject to the terms of the
286N/ACommon Development and Distribution License (the "License").
286N/AYou may not use this file except in compliance with the License.
286N/A
286N/ASee LICENSE.txt included in this distribution for the specific
286N/Alanguage governing permissions and limitations under the License.
286N/A
286N/AWhen distributing Covered Code, include this CDDL HEADER in each
286N/Afile and include the License file at LICENSE.txt.
286N/AIf applicable, add the following below this CDDL HEADER, with the
286N/Afields enclosed by brackets "[]" replaced with your own identifying
286N/Ainformation: Portions Copyright [yyyy] [name of copyright owner]
286N/A
286N/ACDDL HEADER END
286N/A
286N/ACopyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
286N/A
286N/A--%><%@page import="org.opensolaris.opengrok.web.Constants"%>
286N/A<%@ page import = "javax.servlet.*,
286N/A java.lang.*,
286N/A javax.servlet.http.*,
286N/A java.util.*,
286N/A java.io.*,
286N/A org.opensolaris.opengrok.index.*,
286N/A org.opensolaris.opengrok.configuration.*,
286N/A org.opensolaris.opengrok.web.EftarFileReader,
286N/A org.opensolaris.opengrok.web.Util,
286N/A org.opensolaris.opengrok.history.HistoryGuru"
286N/A %><%@ page session="false" %><%@ page errorPage="error.jsp"%><%
286N/AString context = request.getContextPath();
286N/AString servlet = request.getServletPath();
286N/AString reqURI = request.getRequestURI();
286N/AString path = request.getPathInfo();
286N/Aif (path == null) path = "";
286N/ARuntimeEnvironment environment = RuntimeEnvironment.getInstance();
286N/Aenvironment.setUrlPrefix(context + Constants.searchR + "?");
286N/Aenvironment.register();
286N/AString rawSource = environment.getSourceRootPath();
286N/AString resourcePath = rawSource + path;
286N/AFile resourceFile = new File(resourcePath);
286N/AresourcePath = resourceFile.getAbsolutePath();
286N/Aboolean valid = true;
286N/Aboolean noHistory = true;
286N/Aboolean noAnnotation = true;
286N/Aboolean annotate = false;
286N/AString basename = resourceFile.getName();
286N/Aboolean isDir = false;
286N/AEftarFileReader ef = null;
286N/AString parent = null;
286N/AString parentBasename = resourceFile.getParentFile().getName();
286N/AIgnoredNames ignoredNames = environment.getIgnoredNames();
286N/AString uriEncodedName = Util.URIEncodePath(path);
286N/A
286N/Aif(resourcePath.length() < rawSource.length()
286N/A|| ignoredNames.ignore(path)
286N/A|| ignoredNames.ignore(parentBasename)
286N/A|| !resourcePath.startsWith(rawSource)) {
286N/A valid = false;
286N/A response.sendError(404);
286N/A return;
286N/A} else if (!resourceFile.canRead() && resourcePath.startsWith(rawSource)) {
286N/A String newPath = rawSource + "/on/" + path; //TODO do we still use "on" ???
286N/A File newFile = new File(newPath);
286N/A if(newFile.canRead()) {
286N/A if(newFile.isDirectory() && servlet.startsWith(Constants.xrefP) && !path.endsWith("/")) {
286N/A response.sendRedirect(context + servlet + "/on" + uriEncodedName + "/");
286N/A } else {
286N/A response.sendRedirect(context + servlet + "/on" + uriEncodedName);
286N/A }
286N/A }
286N/A valid = false;
286N/A response.sendError(404);
286N/A return;
286N/A} else {
286N/A valid = true;
286N/A path = resourcePath.substring(rawSource.length());
286N/A if ("".equals(path)) {
286N/A path = "/";
286N/A }
286N/A if (File.separatorChar == '\\') {
286N/A path = path.replace('\\','/');
286N/A }
286N/A uriEncodedName = Util.URIEncodePath(path);
286N/A isDir = resourceFile.isDirectory();
286N/A if (isDir && !servlet.startsWith(Constants.xrefP) && !servlet.startsWith(Constants.histP)) { //if it is an existing directory perhaps people wanted directory xref
286N/A if(!reqURI.endsWith("/")) {
286N/A response.sendRedirect(context + Constants.xrefP + uriEncodedName + "/");
286N/A } else {
286N/A response.sendRedirect(context + Constants.xrefP + uriEncodedName);
286N/A }
286N/A } if (isDir && !reqURI.endsWith("/")) {
286N/A response.sendRedirect(context + servlet + uriEncodedName +"/");
286N/A } else {
286N/A
286N/A long flast = resourceFile.lastModified();
286N/A String dtag = "";
286N/A
286N/A if (request.getDateHeader("If-Modified-Since") >= flast ) {
286N/A response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
286N/A valid = false;
286N/A } else {
286N/A
286N/A response.setDateHeader("Last-Modified", flast);
286N/A int lastSlash = path.lastIndexOf('/');
286N/A parent = (lastSlash != -1) ? path.substring(0, lastSlash) : "";
286N/A int pLastSlash = parent.lastIndexOf('/');
286N/A parentBasename = pLastSlash != -1 ? parent.substring(pLastSlash+1) : parent;
286N/A noHistory = !HistoryGuru.getInstance().hasHistory(resourceFile);
286N/A noAnnotation = isDir ||
286N/A !HistoryGuru.getInstance().hasAnnotation(resourceFile);
286N/A annotate = !noAnnotation &&
286N/A Boolean.parseBoolean(request.getParameter("a"));
286N/A try{
286N/A ef = new EftarFileReader(environment.getDataRootPath() + "/index/dtags.eftar");
286N/A dtag = ef.get(path);
286N/A if(servlet.startsWith(Constants.xrefS)) {
286N/A } else {
286N/A if(ef != null) {
286N/A try {
286N/A ef.close();
286N/A } catch (IOException e) {
286N/A } finally {
286N/A ef = null;
286N/A }
286N/A }
286N/A }
286N/A } catch (Exception e) {
286N/A dtag = "";
286N/A }
286N/A String pageTitle="Cross Reference: " + path;
286N/A
286N/A%><%@ include file="httpheader.jspf" %><%//below style is for the fancy always on top search bar%>
286N/A<body style="overflow:hidden;">
286N/A<script type="text/javascript" src="<%=context%>/jquery-1.4.2.min.js"></script>
286N/A<script type="text/javascript">/* <![CDATA[ */
286N/A $().ready(function() {
286N/A if (!window.location.hash) {$('#content').focus();}
286N/A} );
286N/A/* ]]> */</script>
286N/A<% if (annotate) { %>
286N/A<script type="text/javascript" src="<%=context%>/jquery.tooltip-1.3.pack.js"></script>
286N/A<script type="text/javascript">/* <![CDATA[ */
286N/Afunction toggle_annotations() {
286N/A $("span").each(function() {
286N/A if (this.className == 'blame') {
286N/A this.className = 'blame-hidden';
286N/A } else if (this.className == 'blame-hidden') {
286N/A this.className = 'blame';
286N/A }
286N/A }
286N/A );
286N/A}
286N/A$().ready(function() {
286N/A $('a[id=r]').tooltip({
286N/A left: 5,
286N/A showURL: false
286N/A });
286N/A} );
286N/A/* ]]> */</script>
<% } %>
<div id="page">
<div id="whole_header" >
<form action="<%=context+Constants.searchP%>">
<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+Constants.xrefP%>/">xref</a>: <%=org.opensolaris.opengrok.web.Util.breadcrumbPath(context + Constants.xrefP, path)%></tt></div>
<div id="bar"><a href="<%=context%>/" id="home">Home</a> |
<%
if (noHistory || servlet.startsWith(Constants.histS)) {
%> <span class="c" id="history">History</span><%
} else {
%><a id="history" href="<%=context+Constants.histL+uriEncodedName%>">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+Constants.xrefP+uriEncodedName%><%
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+Constants.xrefP+uriEncodedName%>?a=true<%=rev%>">Annotate</a><%
}
}
if (!isDir) {
if ( servlet.startsWith(Constants.xrefS) ) {
%> | <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+Constants.rawP+uriEncodedName%>">Download</a><%
} else {
%> | <a id="download" href="<%=context+Constants.rawP+uriEncodedName%>?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
}
%>