mast.jsp revision 112
1029N/A<%--
1029N/ACDDL HEADER START
1356N/A
1029N/AThe contents of this file are subject to the terms of the
1356N/ACommon Development and Distribution License (the "License").
1029N/AYou may not use this file except in compliance with the License.
1029N/A
1075N/ASee LICENSE.txt included in this distribution for the specific
1075N/Alanguage governing permissions and limitations under the License.
1075N/A
1075N/AWhen distributing Covered Code, include this CDDL HEADER in each
1075N/Afile and include the License file at LICENSE.txt.
1075N/AIf applicable, add the following below this CDDL HEADER, with the
1075N/Afields enclosed by brackets "[]" replaced with your own identifying
1075N/Ainformation: Portions Copyright [yyyy] [name of copyright owner]
1075N/A
1075N/ACDDL HEADER END
1075N/A
1075N/ACopyright 2005 Sun Microsystems, Inc. All rights reserved.
1075N/AUse is subject to license terms.
1075N/A
1075N/Aident "%Z%%M% %I% %E% SMI"
1075N/A
1075N/A--%><%@ page import = "javax.servlet.*,
1029N/Ajava.lang.*,
1029N/Ajavax.servlet.http.*,
1029N/Ajava.util.*,
1029N/Ajava.io.*,
1029N/Aorg.opensolaris.opengrok.index.*,
1029N/Aorg.opensolaris.opengrok.configuration.*
1408N/A"
1029N/A%><%@ page session="false" %><%@ page errorPage="error.jsp"%><%
1029N/AString context = request.getContextPath();
1408N/AString servlet = request.getServletPath();
1408N/AString reqURI = request.getRequestURI();
1408N/AString path = request.getPathInfo();
1029N/Aif (path == null) path = "";
1029N/ARuntimeEnvironment environment = RuntimeEnvironment.getInstance();
1029N/Aenvironment.register();
1029N/AString rawSource = environment.getSourceRootPath();
1029N/AString resourcePath = rawSource + path;
1356N/AFile resourceFile = new File(resourcePath);
1123N/AresourcePath = resourceFile.getAbsolutePath();
1123N/Aboolean valid = true;
1029N/Aboolean noHistory = true;
1029N/Aboolean noAnnotation = true;
1276N/Aboolean annotate = false;
1374N/AString basename = resourceFile.getName();
1029N/Aboolean isDir = false;
1132N/AEftarFileReader ef = null;
1132N/AString parent = null;
1132N/AString parentBasename = resourceFile.getParentFile().getName();
1029N/AIgnoredNames ignoredNames = environment.getIgnoredNames();
1029N/A
1029N/Aif(resourcePath.length() < rawSource.length()
1029N/A|| ignoredNames.ignore(path)
1374N/A|| ignoredNames.ignore(parentBasename)
1374N/A|| !resourcePath.startsWith(rawSource)) {
1374N/A valid = false;
1029N/A response.sendError(404);
1075N/A return;
1029N/A} else if (!resourceFile.canRead() && resourcePath.startsWith(rawSource)) {
1029N/A String newPath = rawSource + "/on/" + path;
1029N/A File newFile = new File(newPath);
1029N/A if(newFile.canRead()) {
1029N/A if(newFile.isDirectory() && servlet.startsWith("/xref") && !path.endsWith("/")) {
1029N/A response.sendRedirect(context + servlet + "/on" + path + "/");
1029N/A } else {
1029N/A response.sendRedirect(context + servlet + "/on" + path);
1029N/A }
1029N/A }
1029N/A valid = false;
1029N/A response.sendError(404);
1029N/A return;
1029N/A} else {
1029N/A valid = true;
1029N/A path = resourcePath.substring(rawSource.length());
1029N/A if ("".equals(path)) {
1029N/A path = "/";
1029N/A }
1029N/A if (File.separatorChar == '\\') {
1029N/A path = path.replace('\\','/');
1029N/A }
1029N/A isDir = resourceFile.isDirectory();
1029N/A if (isDir && !servlet.startsWith("/xref") && !servlet.startsWith("/hist")) { //if it is an existing directory perhaps people wanted directory xref
1029N/A if(!reqURI.endsWith("/")) {
1029N/A response.sendRedirect(context + "/xref" + path + "/");
1029N/A } else {
1029N/A response.sendRedirect(context + "/xref" + path);
1029N/A }
1029N/A } if (isDir && !reqURI.endsWith("/")) {
1029N/A response.sendRedirect(context + servlet + path +"/");
1029N/A } else {
1029N/A
1029N/A long flast = resourceFile.lastModified();
1029N/A String dtag = "";
1029N/A
1029N/A if (request.getDateHeader("If-Modified-Since") >= flast ) {
1029N/A response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
1374N/A valid = false;
1374N/A } else {
1374N/A
1375N/A response.setDateHeader("Last-Modified", flast);
1375N/A int lastSlash = path.lastIndexOf('/');
1374N/A parent = (lastSlash != -1) ? path.substring(0, lastSlash) : "";
1374N/A int pLastSlash = parent.lastIndexOf('/');
1374N/A parentBasename = pLastSlash != -1 ? parent.substring(pLastSlash+1) : parent;
1374N/A noHistory = !(isDir || HistoryGuru.getInstance().hasHistory(rawSource + "/" + parent));
1374N/A noAnnotation = isDir ||
1374N/A !HistoryGuru.getInstance().hasAnnotation(resourceFile);
1374N/A annotate = !noAnnotation &&
1374N/A 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 = "";
}
%><?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
<head>
<meta name="robots" content="noindex,nofollow">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
<title>Cross Reference: <%=path%></title>
<link rel="icon" href="<%=context%>/img/icon.png" type="image/png"/>
<link rel="stylesheet" type="text/css" href="<%=context%>/style.css"/>
<link rel="stylesheet" type="text/css" href="<%=context%>/print.css" media="print" />
<link rel="alternate stylesheet" type="text/css" media="all" title="Paper White" href="<%=context%>/print.css"/>
</head>
<body><div id="page">
<form action="<%=context%>/search">
<div id="header">
<%= getServletContext().getInitParameter("HEADER") %>
<div id="pagetitle"><b id="filename">Cross Reference: <%=path%></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 || annotate) {
%> <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;
}
%> <a id="annotate" 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
}
%>