raw.jsp revision 9a79808fa9bf76ecdc7acb04783c978ee81cccd2
9b5bf10ab04b9be5564d70a57980cfb68b6372e7Mark HaywoodCDDL HEADER START
9b5bf10ab04b9be5564d70a57980cfb68b6372e7Mark HaywoodThe contents of this file are subject to the terms of the
9b5bf10ab04b9be5564d70a57980cfb68b6372e7Mark HaywoodCommon Development and Distribution License (the "License").
9b5bf10ab04b9be5564d70a57980cfb68b6372e7Mark HaywoodYou may not use this file except in compliance with the License.
9b5bf10ab04b9be5564d70a57980cfb68b6372e7Mark HaywoodSee LICENSE.txt included in this distribution for the specific
9b5bf10ab04b9be5564d70a57980cfb68b6372e7Mark Haywoodlanguage governing permissions and limitations under the License.
9b5bf10ab04b9be5564d70a57980cfb68b6372e7Mark HaywoodWhen distributing Covered Code, include this CDDL HEADER in each
9b5bf10ab04b9be5564d70a57980cfb68b6372e7Mark Haywoodfile and include the License file at LICENSE.txt.
9b5bf10ab04b9be5564d70a57980cfb68b6372e7Mark HaywoodIf applicable, add the following below this CDDL HEADER, with the
9b5bf10ab04b9be5564d70a57980cfb68b6372e7Mark Haywoodfields enclosed by brackets "[]" replaced with your own identifying
9b5bf10ab04b9be5564d70a57980cfb68b6372e7Mark Haywoodinformation: Portions Copyright [yyyy] [name of copyright owner]
9b5bf10ab04b9be5564d70a57980cfb68b6372e7Mark HaywoodCDDL HEADER END
9b5bf10ab04b9be5564d70a57980cfb68b6372e7Mark HaywoodCopyright 2008 Sun Microsystems, Inc. All rights reserved.
9b5bf10ab04b9be5564d70a57980cfb68b6372e7Mark HaywoodUse is subject to license terms.
9b5bf10ab04b9be5564d70a57980cfb68b6372e7Mark Haywood--%><%@page import="java.io.File,
9b5bf10ab04b9be5564d70a57980cfb68b6372e7Mark Haywoodorg.opensolaris.opengrok.configuration.RuntimeEnvironment,
9b5bf10ab04b9be5564d70a57980cfb68b6372e7Mark Haywoodorg.opensolaris.opengrok.history.HistoryGuru"%><%
9b5bf10ab04b9be5564d70a57980cfb68b6372e7Mark Haywoodif (path == null) {
9b5bf10ab04b9be5564d70a57980cfb68b6372e7Mark HaywoodRuntimeEnvironment env = RuntimeEnvironment.getInstance();
9b5bf10ab04b9be5564d70a57980cfb68b6372e7Mark HaywoodFile file = new File(env.getSourceRootPath(), path);
9b5bf10ab04b9be5564d70a57980cfb68b6372e7Mark Haywood path = env.getPathRelativeToSourceRoot(file, 0);
9b5bf10ab04b9be5564d70a57980cfb68b6372e7Mark Haywood} catch (FileNotFoundException e) {
9b5bf10ab04b9be5564d70a57980cfb68b6372e7Mark Haywoodif (!file.exists() || !file.canRead() || RuntimeEnvironment.getInstance().getIgnoredNames().ignore(file)) {
9b5bf10ab04b9be5564d70a57980cfb68b6372e7Mark Haywood response.sendError(response.SC_NOT_FOUND, "Can't download a directory");
9b5bf10ab04b9be5564d70a57980cfb68b6372e7Mark HaywoodString mimeType = getServletContext().getMimeType(file.getAbsolutePath());
9b5bf10ab04b9be5564d70a57980cfb68b6372e7Mark HaywoodString revision = request.getParameter("r");
9b5bf10ab04b9be5564d70a57980cfb68b6372e7Mark Haywoodif (revision != null && revision.length() == 0) {
9b5bf10ab04b9be5564d70a57980cfb68b6372e7Mark Haywood revision = null;
9b5bf10ab04b9be5564d70a57980cfb68b6372e7Mark HaywoodInputStream in = null;
9b5bf10ab04b9be5564d70a57980cfb68b6372e7Mark Haywoodif (revision != null) {
9b5bf10ab04b9be5564d70a57980cfb68b6372e7Mark Haywood in = HistoryGuru.getInstance().getRevision(file.getParent(), file.getName(), revision);
9b5bf10ab04b9be5564d70a57980cfb68b6372e7Mark Haywood } catch (Exception e) {
9b5bf10ab04b9be5564d70a57980cfb68b6372e7Mark Haywood response.sendError(404, "Revision not found");
9b5bf10ab04b9be5564d70a57980cfb68b6372e7Mark Haywood response.setDateHeader("Last-Modified", file.lastModified());
9b5bf10ab04b9be5564d70a57980cfb68b6372e7Mark Haywood in = new FileInputStream(file);
9b5bf10ab04b9be5564d70a57980cfb68b6372e7Mark Haywood response.setHeader("content-disposition", "attachment; filename=" + file.getName());
9b5bf10ab04b9be5564d70a57980cfb68b6372e7Mark Haywood OutputStream o = response.getOutputStream();
9b5bf10ab04b9be5564d70a57980cfb68b6372e7Mark Haywood byte[] buffer = new byte[8192];
9b5bf10ab04b9be5564d70a57980cfb68b6372e7Mark Haywood while ((nr = in.read(buffer)) > 0) {
9b5bf10ab04b9be5564d70a57980cfb68b6372e7Mark Haywood o.write(buffer, 0, nr);