mast.jsp revision 85f619afce0f5860dd3265e1ac5c48efcb353921
0N/A<%--
2362N/ACDDL HEADER START
0N/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.
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
2362N/ACopyright 2005 Sun Microsystems, Inc. All rights reserved.
2362N/AUse is subject to license terms.
2362N/A
0N/Aident "%Z%%M% %I% %E% SMI"
0N/A
0N/A--%><%@ page import = "javax.servlet.*,
0N/Ajava.lang.*,
0N/Ajavax.servlet.http.*,
0N/Ajava.util.*,
0N/Ajava.io.*,
0N/Ajava.net.URLDecoder,
0N/Aorg.opensolaris.opengrok.index.*,
0N/Aorg.opensolaris.opengrok.configuration.*
0N/A"
0N/A%><%@ page session="false" %><%@ page errorPage="error.jsp"%><%
0N/AString context = request.getContextPath();
0N/AString servlet = request.getServletPath();
0N/AString reqURI = request.getRequestURI();
0N/AString path = request.getPathInfo();
0N/Aif (path == null) path = "";
0N/Aelse {
0N/A try {
0N/A path = URLDecoder.decode(path, "ISO-8859-1");
0N/A } catch (UnsupportedEncodingException e) {
0N/A }
0N/A}
0N/ARuntimeEnvironment environment = RuntimeEnvironment.getInstance();
0N/Aenvironment.setUrlPrefix(context + "/s?");
0N/Aenvironment.register();
0N/AString rawSource = environment.getSourceRootPath();
0N/AString resourcePath = rawSource + path;
0N/AFile resourceFile = new File(resourcePath);
0N/AresourcePath = resourceFile.getAbsolutePath();
0N/Aboolean valid = true;
0N/Aboolean noHistory = true;
0N/Aboolean noAnnotation = true;
0N/Aboolean annotate = false;
0N/AString basename = resourceFile.getName();
0N/Aboolean isDir = false;
0N/AEftarFileReader ef = null;
0N/AString parent = null;
0N/AString parentBasename = resourceFile.getParentFile().getName();
0N/AIgnoredNames ignoredNames = environment.getIgnoredNames();
0N/AString uriEncodedName = Util.URIEncodePath(path);
0N/A
0N/Aif(resourcePath.length() < rawSource.length()
0N/A|| ignoredNames.ignore(path)
0N/A|| ignoredNames.ignore(parentBasename)
0N/A|| !resourcePath.startsWith(rawSource)) {
0N/A valid = false;
0N/A response.sendError(404);
0N/A return;
0N/A} else if (!resourceFile.canRead() && resourcePath.startsWith(rawSource)) {
0N/A String newPath = rawSource + "/on/" + path;
0N/A File newFile = new File(newPath);
0N/A if(newFile.canRead()) {
0N/A if(newFile.isDirectory() && servlet.startsWith("/xref") && !path.endsWith("/")) {
response.sendRedirect(context + servlet + "/on" + path + "/");
} else {
response.sendRedirect(context + servlet + "/on" + path);
}
}
valid = false;
response.sendError(404);
return;
} else {
valid = true;
path = resourcePath.substring(rawSource.length());
if ("".equals(path)) {
path = "/";
}
if (File.separatorChar == '\\') {
path = path.replace('\\','/');
}
isDir = resourceFile.isDirectory();
if (isDir && !servlet.startsWith("/xref") && !servlet.startsWith("/hist")) { //if it is an existing directory perhaps people wanted directory xref
if(!reqURI.endsWith("/")) {
response.sendRedirect(context + "/xref" + path + "/");
} else {
response.sendRedirect(context + "/xref" + path);
}
} if (isDir && !reqURI.endsWith("/")) {
response.sendRedirect(context + servlet + path +"/");
} else {
long flast = resourceFile.lastModified();
String dtag = "";
if (request.getDateHeader("If-Modified-Since") >= flast ) {
response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
valid = false;
} else {
response.setDateHeader("Last-Modified", flast);
int lastSlash = path.lastIndexOf('/');
parent = (lastSlash != -1) ? path.substring(0, lastSlash) : "";
int pLastSlash = parent.lastIndexOf('/');
parentBasename = pLastSlash != -1 ? parent.substring(pLastSlash+1) : parent;
noHistory = !(isDir || HistoryGuru.getInstance().hasHistory(rawSource + "/" + parent));
noAnnotation = isDir ||
!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><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 ((!isDir && 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;">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) {
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> | <%
}
}
%> <input id="search" name="q" class="q"/>
<input type="submit" value="Search" class="submit"/><%
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
}
%>