mast.jsp revision 6fd168587048fe0e2cb37acdcc9ae9764c83b2d2
18c2aff776a775d34a4c9893a4c72e0434d68e36artem<%--
18c2aff776a775d34a4c9893a4c72e0434d68e36artemCDDL HEADER START
18c2aff776a775d34a4c9893a4c72e0434d68e36artem
18c2aff776a775d34a4c9893a4c72e0434d68e36artemThe contents of this file are subject to the terms of the
18c2aff776a775d34a4c9893a4c72e0434d68e36artemCommon Development and Distribution License (the "License").
18c2aff776a775d34a4c9893a4c72e0434d68e36artemYou may not use this file except in compliance with the License.
18c2aff776a775d34a4c9893a4c72e0434d68e36artem
18c2aff776a775d34a4c9893a4c72e0434d68e36artemSee LICENSE.txt included in this distribution for the specific
18c2aff776a775d34a4c9893a4c72e0434d68e36artemlanguage governing permissions and limitations under the License.
18c2aff776a775d34a4c9893a4c72e0434d68e36artem
18c2aff776a775d34a4c9893a4c72e0434d68e36artemWhen distributing Covered Code, include this CDDL HEADER in each
18c2aff776a775d34a4c9893a4c72e0434d68e36artemfile and include the License file at LICENSE.txt.
18c2aff776a775d34a4c9893a4c72e0434d68e36artemIf applicable, add the following below this CDDL HEADER, with the
18c2aff776a775d34a4c9893a4c72e0434d68e36artemfields enclosed by brackets "[]" replaced with your own identifying
18c2aff776a775d34a4c9893a4c72e0434d68e36arteminformation: Portions Copyright [yyyy] [name of copyright owner]
18c2aff776a775d34a4c9893a4c72e0434d68e36artem
18c2aff776a775d34a4c9893a4c72e0434d68e36artemCDDL HEADER END
18c2aff776a775d34a4c9893a4c72e0434d68e36artem
18c2aff776a775d34a4c9893a4c72e0434d68e36artemCopyright 2005 Sun Microsystems, Inc. All rights reserved.
18c2aff776a775d34a4c9893a4c72e0434d68e36artemUse is subject to license terms.
18c2aff776a775d34a4c9893a4c72e0434d68e36artem--%><%@ page import = "javax.servlet.*,
24fe0b3bf671e123467ce1df0b67cadd3614c8e4jmcpjava.lang.*,
18c2aff776a775d34a4c9893a4c72e0434d68e36artemjavax.servlet.http.*,
18c2aff776a775d34a4c9893a4c72e0434d68e36artemjava.util.*,
18c2aff776a775d34a4c9893a4c72e0434d68e36artemjava.io.*,
18c2aff776a775d34a4c9893a4c72e0434d68e36artemjava.net.URLDecoder,
18c2aff776a775d34a4c9893a4c72e0434d68e36artemorg.opensolaris.opengrok.index.*,
18c2aff776a775d34a4c9893a4c72e0434d68e36artemorg.opensolaris.opengrok.configuration.*
18c2aff776a775d34a4c9893a4c72e0434d68e36artem"
18c2aff776a775d34a4c9893a4c72e0434d68e36artem%><%@ page session="false" %><%@ page errorPage="error.jsp"%><%
18c2aff776a775d34a4c9893a4c72e0434d68e36artemString context = request.getContextPath();
18c2aff776a775d34a4c9893a4c72e0434d68e36artemString servlet = request.getServletPath();
18c2aff776a775d34a4c9893a4c72e0434d68e36artemString reqURI = request.getRequestURI();
18c2aff776a775d34a4c9893a4c72e0434d68e36artemString path = request.getPathInfo();
18c2aff776a775d34a4c9893a4c72e0434d68e36artemif (path == null) path = "";
18c2aff776a775d34a4c9893a4c72e0434d68e36artemelse {
18c2aff776a775d34a4c9893a4c72e0434d68e36artem try {
18c2aff776a775d34a4c9893a4c72e0434d68e36artem path = URLDecoder.decode(path, "ISO-8859-1");
18c2aff776a775d34a4c9893a4c72e0434d68e36artem } catch (UnsupportedEncodingException e) {
18c2aff776a775d34a4c9893a4c72e0434d68e36artem }
18c2aff776a775d34a4c9893a4c72e0434d68e36artem}
18c2aff776a775d34a4c9893a4c72e0434d68e36artemRuntimeEnvironment environment = RuntimeEnvironment.getInstance();
4e9cfc9a015e8ca7d41f7d018c74dc8a692305b3jacobsenvironment.setUrlPrefix(context + "/s?");
18c2aff776a775d34a4c9893a4c72e0434d68e36artemenvironment.register();
a9da3307db733eb1739ba859952610bba3d894abnpString rawSource = environment.getSourceRootPath();
18c2aff776a775d34a4c9893a4c72e0434d68e36artemString resourcePath = rawSource + path;
18c2aff776a775d34a4c9893a4c72e0434d68e36artemFile resourceFile = new File(resourcePath);
18c2aff776a775d34a4c9893a4c72e0434d68e36artemresourcePath = resourceFile.getAbsolutePath();
18c2aff776a775d34a4c9893a4c72e0434d68e36artemboolean valid = true;
18c2aff776a775d34a4c9893a4c72e0434d68e36artemboolean noHistory = true;
4e9cfc9a015e8ca7d41f7d018c74dc8a692305b3jacobsboolean noAnnotation = true;
4e9cfc9a015e8ca7d41f7d018c74dc8a692305b3jacobsboolean annotate = false;
18c2aff776a775d34a4c9893a4c72e0434d68e36artemString basename = resourceFile.getName();
18c2aff776a775d34a4c9893a4c72e0434d68e36artemboolean isDir = false;
18c2aff776a775d34a4c9893a4c72e0434d68e36artemEftarFileReader ef = null;
18c2aff776a775d34a4c9893a4c72e0434d68e36artemString parent = null;
18c2aff776a775d34a4c9893a4c72e0434d68e36artemString parentBasename = resourceFile.getParentFile().getName();
18c2aff776a775d34a4c9893a4c72e0434d68e36artemIgnoredNames ignoredNames = environment.getIgnoredNames();
18c2aff776a775d34a4c9893a4c72e0434d68e36artemString uriEncodedName = Util.URIEncodePath(path);
18c2aff776a775d34a4c9893a4c72e0434d68e36artem
18c2aff776a775d34a4c9893a4c72e0434d68e36artemif(resourcePath.length() < rawSource.length()
18c2aff776a775d34a4c9893a4c72e0434d68e36artem|| ignoredNames.ignore(path)
18c2aff776a775d34a4c9893a4c72e0434d68e36artem|| ignoredNames.ignore(parentBasename)
18c2aff776a775d34a4c9893a4c72e0434d68e36artem|| !resourcePath.startsWith(rawSource)) {
18c2aff776a775d34a4c9893a4c72e0434d68e36artem valid = false;
18c2aff776a775d34a4c9893a4c72e0434d68e36artem response.sendError(404);
18c2aff776a775d34a4c9893a4c72e0434d68e36artem return;
18c2aff776a775d34a4c9893a4c72e0434d68e36artem} else if (!resourceFile.canRead() && resourcePath.startsWith(rawSource)) {
18c2aff776a775d34a4c9893a4c72e0434d68e36artem String newPath = rawSource + "/on/" + path;
18c2aff776a775d34a4c9893a4c72e0434d68e36artem File newFile = new File(newPath);
18c2aff776a775d34a4c9893a4c72e0434d68e36artem if(newFile.canRead()) {
if(newFile.isDirectory() && servlet.startsWith("/xref") && !path.endsWith("/")) {
response.sendRedirect(context + servlet + "/on" + path + "/");
} else {
response.sendRedirect(context + servlet + "/on" + path);
}
}
valid = false;
response.sendError(404);
return;
} else {
valid = true;
path = resourcePath.substring(rawSource.length());
if ("".equals(path)) {
path = "/";
}
if (File.separatorChar == '\\') {
path = path.replace('\\','/');
}
isDir = resourceFile.isDirectory();
if (isDir && !servlet.startsWith("/xref") && !servlet.startsWith("/hist")) { //if it is an existing directory perhaps people wanted directory xref
if(!reqURI.endsWith("/")) {
response.sendRedirect(context + "/xref" + path + "/");
} else {
response.sendRedirect(context + "/xref" + path);
}
} if (isDir && !reqURI.endsWith("/")) {
response.sendRedirect(context + servlet + path +"/");
} else {
long flast = resourceFile.lastModified();
String dtag = "";
if (request.getDateHeader("If-Modified-Since") >= flast ) {
response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
valid = false;
} else {
response.setDateHeader("Last-Modified", flast);
int lastSlash = path.lastIndexOf('/');
parent = (lastSlash != -1) ? path.substring(0, lastSlash) : "";
int pLastSlash = parent.lastIndexOf('/');
parentBasename = pLastSlash != -1 ? parent.substring(pLastSlash+1) : parent;
noHistory = !HistoryGuru.getInstance().hasHistory(resourceFile);
noAnnotation = isDir ||
!HistoryGuru.getInstance().hasAnnotation(resourceFile);
annotate = !noAnnotation &&
Boolean.parseBoolean(request.getParameter("a"));
try{
ef = new EftarFileReader(environment.getDataRootPath() + "/index/dtags.eftar");
dtag = ef.get(path);
if(servlet.startsWith("/xr")) {
} else {
if(ef != null) {
try {
ef.close();
} catch (IOException e) {
} finally {
ef = null;
}
}
}
} catch (Exception e) {
dtag = "";
}
String pageTitle="Cross Reference: " + path;
%><%@ include file="httpheader.jspf" %>
<body><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;">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) {
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.getId()%>"/><%
}
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
}
%>