mast.jsp revision 1143
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
1105N/ACopyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
1105N/A
1129N/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,
1129N/A org.opensolaris.opengrok.web.Constants,
1111N/A org.opensolaris.opengrok.history.HistoryGuru"
850N/A %><%@ page session="false" %><%@ page errorPage="error.jsp"%><%
1143N/A
1143N/A// Use UTF-8 if no encoding is specified in the request
1143N/Aif (request.getCharacterEncoding() == null) {
1143N/A request.setCharacterEncoding("UTF-8");
1143N/A}
1143N/A
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();
1111N/Aenvironment.setUrlPrefix(context + Constants.searchR + "?");
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()) {
1111N/A if(newFile.isDirectory() && servlet.startsWith(Constants.xrefP) && !path.endsWith("/")) {
1126N/A response.sendRedirect(context + servlet + "/on" + uriEncodedName + "/");
0N/A } else {
1126N/A response.sendRedirect(context + servlet + "/on" + uriEncodedName);
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 }
1126N/A uriEncodedName = Util.URIEncodePath(path);
0N/A isDir = resourceFile.isDirectory();
1111N/A if (isDir && !servlet.startsWith(Constants.xrefP) && !servlet.startsWith(Constants.histP)) { //if it is an existing directory perhaps people wanted directory xref
0N/A if(!reqURI.endsWith("/")) {
1126N/A response.sendRedirect(context + Constants.xrefP + uriEncodedName + "/");
0N/A } else {
1126N/A response.sendRedirect(context + Constants.xrefP + uriEncodedName);
0N/A }
0N/A } if (isDir && !reqURI.endsWith("/")) {
1126N/A response.sendRedirect(context + servlet + uriEncodedName +"/");
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);
1111N/A if(servlet.startsWith(Constants.xrefS)) {
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;
1130N/A String rev = request.getParameter("r");
1130N/A if (rev == null) {
1130N/A rev = "";
1130N/A } else if (rev.length() > 0) {
1130N/A rev = "&r=" + rev;
1130N/A }
1130N/A String h = request.getParameter("h");
976N/A%><%@ include file="httpheader.jspf" %><%//below style is for the fancy always on top search bar%>
1014N/A<body style="overflow:hidden;">
976N/A<script type="text/javascript" src="<%=context%>/jquery-1.4.2.min.js"></script>
983N/A<script type="text/javascript">/* <![CDATA[ */
1130N/Afunction get_annotations() {
1130N/A link="<%=context+Constants.xrefP+uriEncodedName%>?a=true<%=rev%>";
1130N/A hash="&h="+window.location.hash.substring(1,window.location.hash.length);
1130N/A window.location=link+hash;
1130N/A}
983N/A $().ready(function() {
1130N/A h="<%=h%>";
1130N/A if (!window.location.hash) {
1130N/A if (h!=null && h!="null") { window.location.hash=h; }
1130N/A else { $('#content').focus(); }
1130N/A }
983N/A} );
983N/A/* ]]> */</script>
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() {
1129N/A $('a[name=r]').tooltip({
878N/A left: 5,
933N/A showURL: false
983N/A });
962N/A} );
878N/A/* ]]> */</script>
878N/A<% } %>
878N/A<div id="page">
954N/A<div id="whole_header" >
1111N/A<form action="<%=context+Constants.searchP%>">
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>
1111N/A <div id="Masthead"><tt><a href="<%=context+Constants.xrefP%>/">xref</a>: <%=org.opensolaris.opengrok.web.Util.breadcrumbPath(context + Constants.xrefP, path)%></tt></div>
1105N/A <div id="bar"><a href="<%=context%>/" id="home">Home</a> |
581N/A <%
581N/A
1111N/A if (noHistory || servlet.startsWith(Constants.histS)) {
581N/A %> <span class="c" id="history">History</span><%
581N/A } else {
1126N/A %><a id="history" href="<%=context+Constants.histL+uriEncodedName%>">History</a><%
581N/A }
581N/A if (noAnnotation) {
581N/A %> | <span class="c" id="annotate">Annotate</span><%
1130N/A } else {
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">
1126N/A <a href="<%=context+Constants.xrefP+uriEncodedName%><%
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 {
1130N/A %> | <a href="#" onclick="javascript:get_annotations(); return false;">Annotate</a><%
840N/A }
847N/A }
581N/A if (!isDir) {
1111N/A if ( servlet.startsWith(Constants.xrefS) ) {
1129N/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> | <a href="#" onclick="javascript:lsttoggle();return false;" title="Show or hide symbol list.">Navigate</a><%
878N/A }
1130N/A String lrev = request.getParameter("r");
1130N/A if (lrev == null || lrev.equals("")) {
1126N/A %> | <a id="download" href="<%=context+Constants.rawP+uriEncodedName%>">Download</a><%
581N/A } else {
1130N/A %> | <a id="download" href="<%=context+Constants.rawP+uriEncodedName%>?r=<%=lrev%>">Download</a><%
581N/A }
581N/A }
181N/A
581N/A Project proj = Project.getProject(resourceFile);
1108N/A //if (proj != null || !environment.hasProjects())
1108N/A {
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%>