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