mast.jsp revision 878
55a7410569737197afb302b07b488973324b0cc5Timo Sirainen<%--
55a7410569737197afb302b07b488973324b0cc5Timo SirainenCDDL HEADER START
55a7410569737197afb302b07b488973324b0cc5Timo Sirainen
def516ea503a60f20d510c14d5070b7ff5bbddf4Timo SirainenThe contents of this file are subject to the terms of the
55a7410569737197afb302b07b488973324b0cc5Timo SirainenCommon Development and Distribution License (the "License").
5ce2084ada06ade9f44fc2914c34658e9a842dc1Timo SirainenYou may not use this file except in compliance with the License.
5ce2084ada06ade9f44fc2914c34658e9a842dc1Timo Sirainen
55a7410569737197afb302b07b488973324b0cc5Timo SirainenSee LICENSE.txt included in this distribution for the specific
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainenlanguage governing permissions and limitations under the License.
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainen
55a7410569737197afb302b07b488973324b0cc5Timo SirainenWhen distributing Covered Code, include this CDDL HEADER in each
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainenfile and include the License file at LICENSE.txt.
55a7410569737197afb302b07b488973324b0cc5Timo SirainenIf applicable, add the following below this CDDL HEADER, with the
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainenfields enclosed by brackets "[]" replaced with your own identifying
55a7410569737197afb302b07b488973324b0cc5Timo Siraineninformation: Portions Copyright [yyyy] [name of copyright owner]
55a7410569737197afb302b07b488973324b0cc5Timo Sirainen
55a7410569737197afb302b07b488973324b0cc5Timo SirainenCDDL HEADER END
55a7410569737197afb302b07b488973324b0cc5Timo Sirainen
55a7410569737197afb302b07b488973324b0cc5Timo SirainenCopyright 2009 Sun Microsystems, Inc. All rights reserved.
55a7410569737197afb302b07b488973324b0cc5Timo SirainenUse is subject to license terms.
55a7410569737197afb302b07b488973324b0cc5Timo Sirainen--%><%@ page import = "javax.servlet.*,
55a7410569737197afb302b07b488973324b0cc5Timo Sirainen java.lang.*,
55a7410569737197afb302b07b488973324b0cc5Timo Sirainen javax.servlet.http.*,
55a7410569737197afb302b07b488973324b0cc5Timo Sirainen java.util.*,
55a7410569737197afb302b07b488973324b0cc5Timo Sirainen java.io.*,
55a7410569737197afb302b07b488973324b0cc5Timo Sirainen org.opensolaris.opengrok.index.*,
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainen org.opensolaris.opengrok.configuration.*,
e60a349c641bb2f4723e4a395a25f55531682d2bTimo Sirainen org.opensolaris.opengrok.web.EftarFileReader,
55a7410569737197afb302b07b488973324b0cc5Timo Sirainen org.opensolaris.opengrok.web.Util,
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainen org.opensolaris.opengrok.history.HistoryGuru
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainen "
55a7410569737197afb302b07b488973324b0cc5Timo Sirainen %><%@ page session="false" %><%@ page errorPage="error.jsp"%><%
55a7410569737197afb302b07b488973324b0cc5Timo SirainenString context = request.getContextPath();
63946971b08cfb1eec698c28569e1c4aa237852dTimo SirainenString servlet = request.getServletPath();
63946971b08cfb1eec698c28569e1c4aa237852dTimo SirainenString reqURI = request.getRequestURI();
e60a349c641bb2f4723e4a395a25f55531682d2bTimo SirainenString path = request.getPathInfo();
63946971b08cfb1eec698c28569e1c4aa237852dTimo Sirainenif (path == null) path = "";
63946971b08cfb1eec698c28569e1c4aa237852dTimo SirainenRuntimeEnvironment environment = RuntimeEnvironment.getInstance();
63946971b08cfb1eec698c28569e1c4aa237852dTimo Sirainenenvironment.setUrlPrefix(context + "/s?");
cd466fe7b84b0223735a6469c7f7bc225f65996dTimo Sirainenenvironment.register();
4b058f90f9e8a2c6b2eed275de4eb8cc5195a71dTimo SirainenString rawSource = environment.getSourceRootPath();
55a7410569737197afb302b07b488973324b0cc5Timo SirainenString resourcePath = rawSource + path;
55a7410569737197afb302b07b488973324b0cc5Timo SirainenFile resourceFile = new File(resourcePath);
4525c4a8f8d1a6365e4469c0c8f46575400a9a67Timo SirainenresourcePath = resourceFile.getAbsolutePath();
55a7410569737197afb302b07b488973324b0cc5Timo Sirainenboolean valid = true;
55a7410569737197afb302b07b488973324b0cc5Timo Sirainenboolean noHistory = true;
55a7410569737197afb302b07b488973324b0cc5Timo Sirainenboolean noAnnotation = true;
55a7410569737197afb302b07b488973324b0cc5Timo Sirainenboolean annotate = false;
55a7410569737197afb302b07b488973324b0cc5Timo SirainenString basename = resourceFile.getName();
55a7410569737197afb302b07b488973324b0cc5Timo Sirainenboolean isDir = false;
55a7410569737197afb302b07b488973324b0cc5Timo SirainenEftarFileReader ef = null;
e60a349c641bb2f4723e4a395a25f55531682d2bTimo SirainenString parent = null;
55a7410569737197afb302b07b488973324b0cc5Timo SirainenString parentBasename = resourceFile.getParentFile().getName();
55a7410569737197afb302b07b488973324b0cc5Timo SirainenIgnoredNames ignoredNames = environment.getIgnoredNames();
55a7410569737197afb302b07b488973324b0cc5Timo SirainenString uriEncodedName = Util.URIEncodePath(path);
55a7410569737197afb302b07b488973324b0cc5Timo Sirainen
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainenif(resourcePath.length() < rawSource.length()
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainen|| ignoredNames.ignore(path)
55a7410569737197afb302b07b488973324b0cc5Timo Sirainen|| ignoredNames.ignore(parentBasename)
55a7410569737197afb302b07b488973324b0cc5Timo Sirainen|| !resourcePath.startsWith(rawSource)) {
55a7410569737197afb302b07b488973324b0cc5Timo Sirainen valid = false;
def516ea503a60f20d510c14d5070b7ff5bbddf4Timo Sirainen response.sendError(404);
def516ea503a60f20d510c14d5070b7ff5bbddf4Timo Sirainen return;
55a7410569737197afb302b07b488973324b0cc5Timo Sirainen} else if (!resourceFile.canRead() && resourcePath.startsWith(rawSource)) {
55a7410569737197afb302b07b488973324b0cc5Timo Sirainen String newPath = rawSource + "/on/" + path; //TODO do we still use "on" ???
e60a349c641bb2f4723e4a395a25f55531682d2bTimo Sirainen File newFile = new File(newPath);
55a7410569737197afb302b07b488973324b0cc5Timo Sirainen if(newFile.canRead()) {
55a7410569737197afb302b07b488973324b0cc5Timo Sirainen if(newFile.isDirectory() && servlet.startsWith("/xref") && !path.endsWith("/")) {
55a7410569737197afb302b07b488973324b0cc5Timo Sirainen response.sendRedirect(context + servlet + "/on" + path + "/");
55a7410569737197afb302b07b488973324b0cc5Timo Sirainen } else {
def516ea503a60f20d510c14d5070b7ff5bbddf4Timo Sirainen response.sendRedirect(context + servlet + "/on" + path);
55a7410569737197afb302b07b488973324b0cc5Timo Sirainen }
55a7410569737197afb302b07b488973324b0cc5Timo Sirainen }
6ef7e31619edfaa17ed044b45861d106a86191efTimo Sirainen valid = false;
55a7410569737197afb302b07b488973324b0cc5Timo Sirainen response.sendError(404);
e60a349c641bb2f4723e4a395a25f55531682d2bTimo Sirainen return;
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainen} else {
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainen valid = true;
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainen path = resourcePath.substring(rawSource.length());
55a7410569737197afb302b07b488973324b0cc5Timo Sirainen if ("".equals(path)) {
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainen path = "/";
55a7410569737197afb302b07b488973324b0cc5Timo Sirainen }
55a7410569737197afb302b07b488973324b0cc5Timo Sirainen if (File.separatorChar == '\\') {
55a7410569737197afb302b07b488973324b0cc5Timo Sirainen path = path.replace('\\','/');
55a7410569737197afb302b07b488973324b0cc5Timo Sirainen }
55a7410569737197afb302b07b488973324b0cc5Timo Sirainen isDir = resourceFile.isDirectory();
55a7410569737197afb302b07b488973324b0cc5Timo Sirainen if (isDir && !servlet.startsWith("/xref") && !servlet.startsWith("/hist")) { //if it is an existing directory perhaps people wanted directory xref
55a7410569737197afb302b07b488973324b0cc5Timo Sirainen if(!reqURI.endsWith("/")) {
e60a349c641bb2f4723e4a395a25f55531682d2bTimo Sirainen response.sendRedirect(context + "/xref" + path + "/");
55a7410569737197afb302b07b488973324b0cc5Timo Sirainen } else {
55a7410569737197afb302b07b488973324b0cc5Timo Sirainen response.sendRedirect(context + "/xref" + path);
55a7410569737197afb302b07b488973324b0cc5Timo Sirainen }
55a7410569737197afb302b07b488973324b0cc5Timo Sirainen } if (isDir && !reqURI.endsWith("/")) {
e60a349c641bb2f4723e4a395a25f55531682d2bTimo Sirainen response.sendRedirect(context + servlet + path +"/");
55a7410569737197afb302b07b488973324b0cc5Timo Sirainen } else {
55a7410569737197afb302b07b488973324b0cc5Timo Sirainen
55a7410569737197afb302b07b488973324b0cc5Timo Sirainen long flast = resourceFile.lastModified();
55a7410569737197afb302b07b488973324b0cc5Timo Sirainen String dtag = "";
e60a349c641bb2f4723e4a395a25f55531682d2bTimo Sirainen
55a7410569737197afb302b07b488973324b0cc5Timo Sirainen if (request.getDateHeader("If-Modified-Since") >= flast ) {
55a7410569737197afb302b07b488973324b0cc5Timo Sirainen response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
55a7410569737197afb302b07b488973324b0cc5Timo Sirainen valid = false;
e60a349c641bb2f4723e4a395a25f55531682d2bTimo Sirainen } else {
55a7410569737197afb302b07b488973324b0cc5Timo Sirainen
55a7410569737197afb302b07b488973324b0cc5Timo Sirainen response.setDateHeader("Last-Modified", flast);
55a7410569737197afb302b07b488973324b0cc5Timo Sirainen int lastSlash = path.lastIndexOf('/');
55a7410569737197afb302b07b488973324b0cc5Timo Sirainen parent = (lastSlash != -1) ? path.substring(0, lastSlash) : "";
55a7410569737197afb302b07b488973324b0cc5Timo Sirainen int pLastSlash = parent.lastIndexOf('/');
55a7410569737197afb302b07b488973324b0cc5Timo Sirainen parentBasename = pLastSlash != -1 ? parent.substring(pLastSlash+1) : parent;
e60a349c641bb2f4723e4a395a25f55531682d2bTimo Sirainen noHistory = !HistoryGuru.getInstance().hasHistory(resourceFile);
55a7410569737197afb302b07b488973324b0cc5Timo Sirainen noAnnotation = isDir ||
fd4632d0060b2e9eef513b544ccff1e26d1fc222Timo Sirainen !HistoryGuru.getInstance().hasAnnotation(resourceFile);
55a7410569737197afb302b07b488973324b0cc5Timo Sirainen annotate = !noAnnotation &&
4525c4a8f8d1a6365e4469c0c8f46575400a9a67Timo Sirainen Boolean.parseBoolean(request.getParameter("a"));
55a7410569737197afb302b07b488973324b0cc5Timo Sirainen try{
55a7410569737197afb302b07b488973324b0cc5Timo Sirainen ef = new EftarFileReader(environment.getDataRootPath() + "/index/dtags.eftar");
fd4632d0060b2e9eef513b544ccff1e26d1fc222Timo Sirainen dtag = ef.get(path);
55a7410569737197afb302b07b488973324b0cc5Timo Sirainen if(servlet.startsWith("/xr")) {
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen } else {
55a7410569737197afb302b07b488973324b0cc5Timo Sirainen if(ef != null) {
55a7410569737197afb302b07b488973324b0cc5Timo Sirainen try {
e60a349c641bb2f4723e4a395a25f55531682d2bTimo Sirainen ef.close();
e60a349c641bb2f4723e4a395a25f55531682d2bTimo Sirainen } catch (IOException e) {
c4267cf4c40fb1f866b5958ff122ef836b8c5dfbTimo Sirainen } finally {
e60a349c641bb2f4723e4a395a25f55531682d2bTimo Sirainen ef = null;
e60a349c641bb2f4723e4a395a25f55531682d2bTimo Sirainen }
39e6fcc3e8b1ccb13087c232cb6bdea04d1a20a4Timo Sirainen }
55a7410569737197afb302b07b488973324b0cc5Timo Sirainen }
e60a349c641bb2f4723e4a395a25f55531682d2bTimo Sirainen } catch (Exception e) {
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen dtag = "";
55a7410569737197afb302b07b488973324b0cc5Timo Sirainen }
55a7410569737197afb302b07b488973324b0cc5Timo Sirainen String pageTitle="Cross Reference: " + path;
55a7410569737197afb302b07b488973324b0cc5Timo Sirainen
55a7410569737197afb302b07b488973324b0cc5Timo Sirainen%><%@ include file="httpheader.jspf" %>
55a7410569737197afb302b07b488973324b0cc5Timo Sirainen<body>
<% if (!noAnnotation) { %>
<script type="text/javascript" src="<%=context%>/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="<%=context%>/jquery.tooltip-1.3.pack.js"></script>
<script type="text/javascript">/* <![CDATA[ */
function toggle_annotations() {
var spans = document.getElementsByTagName("span");
for (var i = 0; i < spans.length; i++) {
var span = spans[i];
if (span.className == 'blame') {
span.className = 'blame-hidden';
} else if (span.className == 'blame-hidden') {
span.className = 'blame';
}
}
}
$().ready(function() {
$('a[id=r]').tooltip({
left: 5,
showURL: false,
});
} );
/* ]]> */</script>
<% } %>
<div id="page">
<form action="<%=context%>/search">
<div id="header"><%@ include file="pageheader.jspf" %>
<div id="pagetitle"><b id="filename">Cross Reference: <%=basename%></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 (noHistory || servlet.startsWith("/hi")) {
%> <span class="c" id="history">History</span><%
} else {
%><a id="history" href="<%=context%>/history<%=path%>">History</a><%
}
if (noAnnotation) {
%> | <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;
}
if (Boolean.parseBoolean(request.getParameter("a"))) {
%> | <span id="toggle-annotate-by-javascript" style="display: none">
<a href="#" onClick="javascript:toggle_annotations(); return false;" title="Show or hide line annotation(commit revisions,authors)." >Annotate</a>
</span>
<span id="toggle-annotate">
<a href="<%=context%>/xref<%=path%><%
if (rev.length() > 0) {
%>?<%=rev%><%
} %>">Annotate</a></span>
<script type="text/javascript">
<!--
var toggle_js = document.getElementById('toggle-annotate-by-javascript');
var toggle_ss = document.getElementById('toggle-annotate');
toggle_js.style.display = 'inline';
toggle_ss.style.display = 'none';
// -->
</script> <%
} else {
%> | <a href="<%=context%>/xref<%=path%>?a=true<%=rev%>">Annotate</a><%
}
}
if (!isDir) {
if ( servlet.startsWith("/xr") ) {
%> | <a href="javascript:lntoggle();" title="Show or hide line numbers (might be slower if file has more than 10 000 lines).">Line #</a><%
}
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><%
}
}
Project proj = Project.getProject(resourceFile);
if (proj != null || !environment.hasProjects()) {
%> | <input id="search" name="q" class="q"/>
<input type="submit" value="Search" class="submit"/>
<%
if (proj != null) {
%><input type="hidden" name="project" value="<%=proj.getDescription()%>"/><%
}
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
}
%>