mast.jsp revision 256
0N/A<%--
0N/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
0N/ACopyright 2005 Sun Microsystems, Inc. All rights reserved.
0N/AUse is subject to license terms.
0N/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.*,
58N/Ajava.net.URLDecoder,
58N/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();
58N/Aif (path == null) path = "";
128N/Aelse {
58N/A try {
58N/A path = URLDecoder.decode(path, "ISO-8859-1");
0N/A } catch (UnsupportedEncodingException e) {
0N/A }
0N/A}
50N/ARuntimeEnvironment environment = RuntimeEnvironment.getInstance();
0N/Aenvironment.setUrlPrefix(context + "/s?");
93N/Aenvironment.register();
93N/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;
112N/Aboolean noAnnotation = true;
158N/Aboolean annotate = false;
80N/AString basename = resourceFile.getName();
0N/Aboolean isDir = false;
112N/AEftarFileReader ef = null;
112N/AString parent = null;
0N/AString parentBasename = resourceFile.getParentFile().getName();
0N/AIgnoredNames ignoredNames = environment.getIgnoredNames();
0N/AString uriEncodedName = Util.URIEncodePath(path);
27N/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("/")) {
27N/A response.sendRedirect(context + servlet + "/on" + path + "/");
0N/A } else {
0N/A response.sendRedirect(context + servlet + "/on" + path);
0N/A }
50N/A }
50N/A valid = false;
50N/A response.sendError(404);
0N/A return;
0N/A} else {
0N/A valid = true;
0N/A path = resourcePath.substring(rawSource.length());
0N/A if ("".equals(path)) {
0N/A path = "/";
0N/A }
0N/A if (File.separatorChar == '\\') {
0N/A path = path.replace('\\','/');
0N/A }
0N/A isDir = resourceFile.isDirectory();
0N/A if (isDir && !servlet.startsWith("/xref") && !servlet.startsWith("/hist")) { //if it is an existing directory perhaps people wanted directory xref
0N/A if(!reqURI.endsWith("/")) {
0N/A response.sendRedirect(context + "/xref" + path + "/");
0N/A } else {
0N/A response.sendRedirect(context + "/xref" + path);
0N/A }
0N/A } if (isDir && !reqURI.endsWith("/")) {
0N/A response.sendRedirect(context + servlet + path +"/");
0N/A } else {
0N/A
0N/A long flast = resourceFile.lastModified();
0N/A String dtag = "";
0N/A
0N/A if (request.getDateHeader("If-Modified-Since") >= flast ) {
0N/A response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
0N/A valid = false;
0N/A } else {
93N/A
93N/A response.setDateHeader("Last-Modified", flast);
93N/A int lastSlash = path.lastIndexOf('/');
93N/A parent = (lastSlash != -1) ? path.substring(0, lastSlash) : "";
0N/A int pLastSlash = parent.lastIndexOf('/');
58N/A parentBasename = pLastSlash != -1 ? parent.substring(pLastSlash+1) : parent;
0N/A noHistory = !HistoryGuru.getInstance().hasHistory(resourceFile);
0N/A noAnnotation = isDir ||
0N/A !HistoryGuru.getInstance().hasAnnotation(resourceFile);
0N/A annotate = !noAnnotation &&
0N/A Boolean.parseBoolean(request.getParameter("a"));
0N/A try{
0N/A ef = new EftarFileReader(environment.getDataRootPath() + "/index/dtags.eftar");
0N/A dtag = ef.get(path);
0N/A if(servlet.startsWith("/xr")) {
0N/A } else {
0N/A if(ef != null) {
0N/A try {
0N/A ef.close();
0N/A } catch (IOException e) {
0N/A } finally {
144N/A ef = null;
144N/A }
144N/A }
0N/A }
0N/A } catch (Exception e) {
144N/A dtag = "";
142N/A }
0N/A String pageTitle="Cross Reference: " + path;
50N/A
0N/A%><%@ include file="httpheader.jspf" %>
0N/A<body><div id="page">
0N/A<form action="<%=context%>/search">
0N/A <div id="header"><%@ include file="pageheader.jspf" %>
0N/A <div id="pagetitle"><b id="filename">Cross Reference: <%=basename%></b><br/><%=dtag%></div>
0N/A </div>
0N/A<div id="Masthead"><tt><a href="<%=context%>/xref/">xref</a>: <%=org.opensolaris.opengrok.web.Util.breadcrumbPath(context + "/xref", path)%></tt></div>
0N/A<div id="bar"><a href="<%=context%>" id="home">Home</a> |
181N/A<%
93N/A
93N/Aif (noHistory || servlet.startsWith("/hi")) {
181N/A %> <span class="c" id="history">History</span> |<%
93N/A} else {
93N/A %><a id="history" href="<%=context%>/history<%=path%>">History</a> |<%
105N/A}
93N/Aif (noAnnotation) {
93N/A%> <span class="c" id="annotate">Annotate</span> |<%
181N/A} else {
181N/A String rev = request.getParameter("r");
181N/A if (rev == null) {
181N/A rev = "";
181N/A } else if (rev.length() > 0) {
181N/A rev = "&r=" + rev;
181N/A }
181N/A
181N/A if (Boolean.parseBoolean(request.getParameter("a"))) {
181N/A %> <span id="toggle-annotate-by-javascript" style="display: none">
181N/A<a href="#" onClick="javascript:toggle_annotations(); return false;">Annotate</a>
181N/A</span>
181N/A<span id="toggle-annotate">
181N/A<a href="<%=context%>/xref<%=path%><%
181N/Aif (rev.length() > 0) {
181N/A %>?<%=rev%><%
181N/A} %>">Annotate</a></span>
181N/A<script type="text/javascript">
181N/A<!--
181N/Avar toggle_js = document.getElementById('toggle-annotate-by-javascript');
181N/Avar toggle_ss = document.getElementById('toggle-annotate');
181N/A
181N/Atoggle_js.style.display = 'inline';
93N/Atoggle_ss.style.display = 'none';
0N/A// -->
80N/A</script> <%
80N/A } else {
151N/A %> <a href="<%=context%>/xref<%=path%>?a=true<%=rev%>">Annotate</a><%
80N/A }
151N/A %> | <%
80N/A}
0N/A if (!isDir) {
0N/A String rev = request.getParameter("r");
0N/A if (rev == null || rev.equals("")) {
0N/A%> <a id="download" href="<%=context%>/raw<%=path%>">Download</a> | <%
0N/A } else {
0N/A%> <a id="download" href="<%=context%>/raw<%=path%>?r=<%=rev%>">Download</a> | <%
0N/A }
50N/A }
0N/A
0N/A%> <input id="search" name="q" class="q"/>
0N/A<input type="submit" value="Search" class="submit"/><%
0N/A
0N/Aif(isDir) {
0N/A if(path.length() > 0) {
0N/A %><input type="checkbox" name="path" value="<%=path%>"/> only in <b><%=path%></b><%
0N/A }
0N/A} else {
0N/A %><input type="checkbox" name="path" value="<%=parent%>"/> only in <b><%=parentBasename%></b><%
0N/A}
%></div></form><%
} // date check
} // not a directory redirect
}
%>