raw.jsp revision ef604281b397eceb0d9f67b87378b7c0b751967d
0N/A<%--
2362N/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.
2362N/A
0N/ASee LICENSE.txt included in this distribution for the specific
2362N/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
0N/ACopyright 2008 Sun Microsystems, Inc. All rights reserved.
0N/AUse is subject to license terms.
2362N/A--%><%@page import="java.io.File,
2362N/Ajava.io.InputStream,
2362N/Ajava.io.OutputStream,
0N/Ajava.io.FileInputStream,
0N/Aorg.opensolaris.opengrok.configuration.RuntimeEnvironment,
0N/Aorg.opensolaris.opengrok.history.HistoryGuru"%><%
0N/AString path = request.getPathInfo();
0N/AString root = RuntimeEnvironment.getInstance().getSourceRootPath();
0N/Aif (path == null) {
0N/A path = "";
0N/A}
0N/AFile file = new File(root, path);
0N/Apath = file.getCanonicalPath();
0N/A
0N/Aif (!path.startsWith(root) || !file.exists() || !file.canRead() || RuntimeEnvironment.getInstance().getIgnoredNames().ignore(file)) {
0N/A response.sendError(response.SC_NOT_FOUND);
0N/A return;
0N/A} else if (file.isDirectory()) {
0N/A response.sendError(response.SC_NOT_FOUND, "Can't download a directory");
0N/A return;
0N/A}
0N/A
0N/AString mimeType = getServletContext().getMimeType(file.getAbsolutePath());
0N/Aresponse.setContentType(mimeType);
0N/A
0N/AString revision = request.getParameter("r");
0N/Aif (revision != null && revision.length() == 0) {
0N/A revision = null;
0N/A}
0N/A
0N/AInputStream in = null;
0N/A
0N/Aif (revision != null) {
0N/A try{
0N/A in = HistoryGuru.getInstance().getRevision(file.getParent(), file.getName(), revision);
0N/A } catch (Exception e) {
0N/A response.sendError(404, "Revision not found");
0N/A return ;
0N/A }
0N/A} else {
0N/A in = new FileInputStream(file);
0N/A response.setContentLength((int)file.length());
0N/A response.setDateHeader("Last-Modified", file.lastModified());
0N/A}
0N/Aresponse.setHeader("content-disposition", "attachment; filename=" + file.getName());
0N/A
0N/AOutputStream o = response.getOutputStream();
0N/Abyte[] buffer = new byte[8192];
0N/Aint nr;
0N/Awhile ((nr = in.read(buffer)) > 0) {
0N/A o.write(buffer, 0, nr);
0N/A}
0N/Ao.flush();
0N/Ao.close();
0N/A%>
0N/A