mast.jsp revision 976
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
878N/ACopyright 2009 Sun Microsystems, Inc. All rights reserved.
0N/AUse is subject to license terms.
850N/A--%><%@ page import = "javax.servlet.*,
581N/A java.lang.*,
581N/A javax.servlet.http.*,
581N/A java.util.*,
581N/A java.io.*,
581N/A org.opensolaris.opengrok.index.*,
819N/A org.opensolaris.opengrok.configuration.*,
819N/A org.opensolaris.opengrok.web.EftarFileReader,
819N/A org.opensolaris.opengrok.web.Util,
819N/A org.opensolaris.opengrok.history.HistoryGuru
581N/A "
850N/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 = "";
58N/ARuntimeEnvironment environment = RuntimeEnvironment.getInstance();
128N/Aenvironment.setUrlPrefix(context + "/s?");
58N/Aenvironment.register();
58N/AString rawSource = environment.getSourceRootPath();
0N/AString resourcePath = rawSource + path;
0N/AFile resourceFile = new File(resourcePath);
0N/AresourcePath = resourceFile.getAbsolutePath();
50N/Aboolean valid = true;
0N/Aboolean noHistory = true;
93N/Aboolean noAnnotation = true;
93N/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();
112N/AIgnoredNames ignoredNames = environment.getIgnoredNames();
158N/AString uriEncodedName = Util.URIEncodePath(path);
80N/A
0N/Aif(resourcePath.length() < rawSource.length()
112N/A|| ignoredNames.ignore(path)
112N/A|| ignoredNames.ignore(parentBasename)
0N/A|| !resourcePath.startsWith(rawSource)) {
0N/A valid = false;
0N/A response.sendError(404);
27N/A return;
0N/A} else if (!resourceFile.canRead() && resourcePath.startsWith(rawSource)) {
878N/A String newPath = rawSource + "/on/" + path; //TODO do we still use "on" ???
0N/A File newFile = new File(newPath);
0N/A if(newFile.canRead()) {
0N/A if(newFile.isDirectory() && servlet.startsWith("/xref") && !path.endsWith("/")) {
0N/A response.sendRedirect(context + servlet + "/on" + path + "/");
0N/A } else {
0N/A response.sendRedirect(context + servlet + "/on" + path);
0N/A }
0N/A }
0N/A valid = false;
0N/A response.sendError(404);
27N/A return;
0N/A} else {
0N/A valid = true;
0N/A path = resourcePath.substring(rawSource.length());
50N/A if ("".equals(path)) {
50N/A path = "/";
50N/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 {
0N/A
0N/A response.setDateHeader("Last-Modified", flast);
0N/A int lastSlash = path.lastIndexOf('/');
0N/A parent = (lastSlash != -1) ? path.substring(0, lastSlash) : "";
0N/A int pLastSlash = parent.lastIndexOf('/');
0N/A parentBasename = pLastSlash != -1 ? parent.substring(pLastSlash+1) : parent;
256N/A noHistory = !HistoryGuru.getInstance().hasHistory(resourceFile);
93N/A noAnnotation = isDir ||
93N/A !HistoryGuru.getInstance().hasAnnotation(resourceFile);
93N/A annotate = !noAnnotation &&
93N/A Boolean.parseBoolean(request.getParameter("a"));
0N/A try{
58N/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 {
0N/A ef = null;
0N/A }
0N/A }
0N/A }
0N/A } catch (Exception e) {
0N/A dtag = "";
0N/A }
144N/A String pageTitle="Cross Reference: " + path;
581N/A
976N/A%><%@ include file="httpheader.jspf" %><%//below style is for the fancy always on top search bar%>
976N/A<script type="text/javascript" src="<%=context%>/jquery-1.4.2.min.js"></script>
976N/A<body style="overflow: hidden;" onload="$('#search').focus();">
925N/A<% if (annotate) { %>
878N/A<script type="text/javascript" src="<%=context%>/jquery.tooltip-1.3.pack.js"></script>
878N/A<script type="text/javascript">/* <![CDATA[ */
878N/Afunction toggle_annotations() {
962N/A $("span").each(function() {
962N/A if (this.className == 'blame') {
962N/A this.className = 'blame-hidden';
962N/A } else if (this.className == 'blame-hidden') {
962N/A this.className = 'blame';
878N/A }
962N/A }
962N/A );
878N/A}
878N/A$().ready(function() {
878N/A $('a[id=r]').tooltip({
878N/A left: 5,
933N/A showURL: false
962N/A });
962N/A} );
878N/A/* ]]> */</script>
878N/A<% } %>
878N/A<div id="page">
954N/A<div id="whole_header" >
954N/A<form action="<%=context%>/search">
144N/A <div id="header"><%@ include file="pageheader.jspf" %>
954N/A <div id="pagetitle"><b id="filename">Cross Reference: <%=basename%></b><% if (dtag!=null & dtag!="") { %><br/><%=dtag%><% } %></div>
0N/A </div>
954N/A <div id="Masthead"><tt><a href="<%=context%>/xref/">xref</a>: <%=org.opensolaris.opengrok.web.Util.breadcrumbPath(context + "/xref", path)%></tt></div>
954N/A <div id="bar"><a href="<%=context%>" id="home">Home</a> |
581N/A <%
581N/A
581N/A if (noHistory || servlet.startsWith("/hi")) {
581N/A %> <span class="c" id="history">History</span><%
581N/A } else {
581N/A %><a id="history" href="<%=context%>/history<%=path%>">History</a><%
581N/A }
581N/A if (noAnnotation) {
581N/A %> | <span class="c" id="annotate">Annotate</span><%
581N/A } else {
581N/A String rev = request.getParameter("r");
581N/A if (rev == null) {
581N/A rev = "";
581N/A } else if (rev.length() > 0) {
581N/A rev = "&r=" + rev;
581N/A }
581N/A
581N/A if (Boolean.parseBoolean(request.getParameter("a"))) {
581N/A %> | <span id="toggle-annotate-by-javascript" style="display: none">
896N/A <a href="#" onclick="javascript:toggle_annotations(); return false;" title="Show or hide line annotation(commit revisions,authors)." >Annotate</a>
581N/A </span>
581N/A <span id="toggle-annotate">
581N/A <a href="<%=context%>/xref<%=path%><%
581N/A if (rev.length() > 0) {
581N/A %>?<%=rev%><%
581N/A } %>">Annotate</a></span>
581N/A <script type="text/javascript">
581N/A <!--
581N/A var toggle_js = document.getElementById('toggle-annotate-by-javascript');
581N/A var toggle_ss = document.getElementById('toggle-annotate');
181N/A
581N/A toggle_js.style.display = 'inline';
581N/A toggle_ss.style.display = 'none';
581N/A // -->
581N/A </script> <%
581N/A } else {
581N/A %> | <a href="<%=context%>/xref<%=path%>?a=true<%=rev%>">Annotate</a><%
840N/A }
847N/A }
581N/A if (!isDir) {
878N/A if ( servlet.startsWith("/xr") ) {
896N/A %> | <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><%
878N/A }
581N/A String rev = request.getParameter("r");
581N/A if (rev == null || rev.equals("")) {
581N/A %> | <a id="download" href="<%=context%>/raw<%=path%>">Download</a><%
581N/A } else {
581N/A %> | <a id="download" href="<%=context%>/raw<%=path%>?r=<%=rev%>">Download</a><%
581N/A }
581N/A }
181N/A
581N/A Project proj = Project.getProject(resourceFile);
581N/A if (proj != null || !environment.hasProjects()) {
581N/A %> | <input id="search" name="q" class="q"/>
581N/A <input type="submit" value="Search" class="submit"/>
581N/A <%
271N/A if (proj != null) {
867N/A %><input type="hidden" name="project" value="<%=proj.getDescription()%>"/><%
271N/A }
271N/A if(isDir) {
0N/A if(path.length() > 0) {
581N/A %><input type="checkbox" name="path" value="<%=path%>"/> only in <b><%=path%></b><%
581N/A }
271N/A } else {
581N/A %><input type="checkbox" name="path" value="<%=parent%>"/> only in <b><%=parentBasename%></b><%
581N/A }
271N/A }
581N/A %>
954N/A</div></form></div>
976N/A <div id="content"><%
0N/A} // date check
0N/A } // not a directory redirect
0N/A}
0N/A%>