raw.jsp revision 1281
1422N/A<%--
1422N/A$Id$
1422N/A
1422N/ACDDL HEADER START
1422N/A
1422N/AThe contents of this file are subject to the terms of the
1422N/ACommon Development and Distribution License (the "License").
1422N/AYou may not use this file except in compliance with the License.
1422N/A
1422N/ASee LICENSE.txt included in this distribution for the specific
1422N/Alanguage governing permissions and limitations under the License.
1422N/A
1422N/AWhen distributing Covered Code, include this CDDL HEADER in each
1422N/Afile and include the License file at LICENSE.txt.
1422N/AIf applicable, add the following below this CDDL HEADER, with the
1422N/Afields enclosed by brackets "[]" replaced with your own identifying
1422N/Ainformation: Portions Copyright [yyyy] [name of copyright owner]
1422N/A
1422N/ACDDL HEADER END
1422N/A
1422N/ACopyright 2008 Sun Microsystems, Inc. All rights reserved.
1422N/AUse is subject to license terms.
1422N/A
1422N/APortions Copyright 2011 Jens Elkner.
1422N/A
1422N/A--%><%@page import="
java.io.File,
java.io.FileInputStream,
java.io.FileNotFoundException,
java.io.InputStream,
java.io.OutputStream,
org.opensolaris.opengrok.configuration.RuntimeEnvironment,
org.opensolaris.opengrok.history.HistoryGuru,
org.opensolaris.opengrok.web.PageConfig"
%><%@
include file="pageconfig.jspf"
%><%
/* ---------------------- raw.jsp start --------------------- */
{
cfg = PageConfig.get(request);
String redir = cfg.canProcess();
if (redir == null || redir.length() > 0) {
if (redir != null) {
response.sendRedirect(redir);
} else {
response.sendError(HttpServletResponse.SC_NOT_FOUND);
}
return;
}
File f = cfg.getResourceFile();
String revision = cfg.getRequestedRevision();
if (revision.length() == 0) {
revision = null;
}
InputStream in = null;
try {
if (revision != null) {
in = HistoryGuru.getInstance().getRevision(f.getParent(),
f.getName(), revision.substring(2));
} else {
long flast = cfg.getLastModified();
if (request.getDateHeader("If-Modified-Since") >= flast) {
response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
return;
}
in = new FileInputStream(f);
response.setContentLength((int) f.length());
response.setDateHeader("Last-Modified", f.lastModified());
}
} catch (Exception e) {
response.sendError(HttpServletResponse.SC_NOT_FOUND);
return ;
}
String mimeType = getServletContext().getMimeType(f.getAbsolutePath());
response.setContentType(mimeType);
try {
response.setHeader("content-disposition", "attachment; filename="
+ f.getName());
OutputStream o = response.getOutputStream();
byte[] buffer = new byte[8192];
int nr;
while ((nr = in.read(buffer)) > 0) {
o.write(buffer, 0, nr);
}
o.flush();
o.close();
} finally {
in.close();
}
}
/* ---------------------- raw.jsp end-------------------- */
%>