raw.jsp revision 5e43c87216dfeda97c475a542b371b958b13fed5
200N/A<%--
200N/ACDDL HEADER START
200N/A
0N/AThe contents of this file are subject to the terms of the
200N/ACommon Development and Distribution License (the "License").
200N/AYou may not use this file except in compliance with the License.
200N/A
0N/ASee LICENSE.txt included in this distribution for the specific
200N/Alanguage governing permissions and limitations under the License.
200N/A
200N/AWhen distributing Covered Code, include this CDDL HEADER in each
200N/Afile and include the License file at LICENSE.txt.
0N/AIf applicable, add the following below this CDDL HEADER, with the
200N/Afields enclosed by brackets "[]" replaced with your own identifying
200N/Ainformation: Portions Copyright [yyyy] [name of copyright owner]
200N/A
200N/ACDDL HEADER END
200N/A
200N/ACopyright 2008 Sun Microsystems, Inc. All rights reserved.
0N/AUse is subject to license terms.
200N/A--%><%@page import="java.io.File,
200N/Ajava.io.InputStream,
200N/Ajava.io.OutputStream,
200N/Ajava.io.FileInputStream,
200N/Ajava.io.FileNotFoundException,
200N/Aorg.opensolaris.opengrok.configuration.RuntimeEnvironment,
200N/Aorg.opensolaris.opengrok.history.HistoryGuru"%><%
0N/AString path = request.getPathInfo();
200N/Aif (path == null) {
200N/A path = "";
200N/A}
0N/ARuntimeEnvironment env = RuntimeEnvironment.getInstance();
200N/AFile file = new File(env.getSourceRootPath(), path);
200N/Atry {
200N/A path = env.getPathRelativeToSourceRoot(file, 0);
200N/A} catch (FileNotFoundException e) {
200N/A response.sendError(response.SC_NOT_FOUND);
200N/A return;
200N/A}
if (!file.exists() || !file.canRead() || RuntimeEnvironment.getInstance().getIgnoredNames().ignore(file)) {
response.sendError(response.SC_NOT_FOUND);
return;
} else if (file.isDirectory()) {
response.sendError(response.SC_NOT_FOUND, "Can't download a directory");
return;
}
String mimeType = getServletContext().getMimeType(file.getAbsolutePath());
response.setContentType(mimeType);
String revision = request.getParameter("r");
if (revision != null && revision.length() == 0) {
revision = null;
}
InputStream in = null;
if (revision != null) {
try{
in = HistoryGuru.getInstance().getRevision(file.getParent(), file.getName(), revision);
} catch (Exception e) {
response.sendError(404, "Revision not found");
return ;
}
} else {
in = new FileInputStream(file);
response.setContentLength((int)file.length());
response.setDateHeader("Last-Modified", file.lastModified());
}
response.setHeader("content-disposition", "attachment; filename=" + file.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();
%>