raw.jsp revision 138a7fea383af1a9084b7ec66d309d1cbc43d5f6
ef604281b397eceb0d9f67b87378b7c0b751967dTrond NorbyeCDDL HEADER START
ef604281b397eceb0d9f67b87378b7c0b751967dTrond NorbyeThe contents of this file are subject to the terms of the
ef604281b397eceb0d9f67b87378b7c0b751967dTrond NorbyeCommon Development and Distribution License (the "License").
ef604281b397eceb0d9f67b87378b7c0b751967dTrond NorbyeYou may not use this file except in compliance with the License.
ef604281b397eceb0d9f67b87378b7c0b751967dTrond NorbyeSee LICENSE.txt included in this distribution for the specific
ef604281b397eceb0d9f67b87378b7c0b751967dTrond Norbyelanguage governing permissions and limitations under the License.
ef604281b397eceb0d9f67b87378b7c0b751967dTrond NorbyeWhen distributing Covered Code, include this CDDL HEADER in each
ef604281b397eceb0d9f67b87378b7c0b751967dTrond Norbyefile and include the License file at LICENSE.txt.
ef604281b397eceb0d9f67b87378b7c0b751967dTrond NorbyeIf applicable, add the following below this CDDL HEADER, with the
ef604281b397eceb0d9f67b87378b7c0b751967dTrond Norbyefields enclosed by brackets "[]" replaced with your own identifying
ef604281b397eceb0d9f67b87378b7c0b751967dTrond Norbyeinformation: Portions Copyright [yyyy] [name of copyright owner]
ef604281b397eceb0d9f67b87378b7c0b751967dTrond NorbyeCDDL HEADER END
ef604281b397eceb0d9f67b87378b7c0b751967dTrond NorbyeCopyright 2008 Sun Microsystems, Inc. All rights reserved.
ef604281b397eceb0d9f67b87378b7c0b751967dTrond NorbyeUse is subject to license terms.
ef604281b397eceb0d9f67b87378b7c0b751967dTrond Norbye--%><%@page import="java.io.File,
ef604281b397eceb0d9f67b87378b7c0b751967dTrond Norbyeorg.opensolaris.opengrok.configuration.RuntimeEnvironment,
ef604281b397eceb0d9f67b87378b7c0b751967dTrond Norbyeorg.opensolaris.opengrok.history.HistoryGuru"%><%
ef604281b397eceb0d9f67b87378b7c0b751967dTrond Norbyeif (path == null) {
5e43c87216dfeda97c475a542b371b958b13fed5Patrick HigginsRuntimeEnvironment env = RuntimeEnvironment.getInstance();
5e43c87216dfeda97c475a542b371b958b13fed5Patrick HigginsFile file = new File(env.getSourceRootPath(), path);
5e43c87216dfeda97c475a542b371b958b13fed5Patrick Higgins path = env.getPathRelativeToSourceRoot(file, 0);
5e43c87216dfeda97c475a542b371b958b13fed5Patrick Higgins} catch (FileNotFoundException e) {
5e43c87216dfeda97c475a542b371b958b13fed5Patrick Higginsif (!file.exists() || !file.canRead() || RuntimeEnvironment.getInstance().getIgnoredNames().ignore(file)) {
ef604281b397eceb0d9f67b87378b7c0b751967dTrond Norbye response.sendError(response.SC_NOT_FOUND, "Can't download a directory");
ef604281b397eceb0d9f67b87378b7c0b751967dTrond NorbyeString mimeType = getServletContext().getMimeType(file.getAbsolutePath());
ef604281b397eceb0d9f67b87378b7c0b751967dTrond NorbyeString revision = request.getParameter("r");
ef604281b397eceb0d9f67b87378b7c0b751967dTrond Norbyeif (revision != null && revision.length() == 0) {
ef604281b397eceb0d9f67b87378b7c0b751967dTrond Norbye revision = null;
ef604281b397eceb0d9f67b87378b7c0b751967dTrond NorbyeInputStream in = null;
ef604281b397eceb0d9f67b87378b7c0b751967dTrond Norbyeif (revision != null) {
ef604281b397eceb0d9f67b87378b7c0b751967dTrond Norbye in = HistoryGuru.getInstance().getRevision(file.getParent(), file.getName(), revision);
ef604281b397eceb0d9f67b87378b7c0b751967dTrond Norbye } catch (Exception e) {
ef604281b397eceb0d9f67b87378b7c0b751967dTrond Norbye response.sendError(404, "Revision not found");
ef604281b397eceb0d9f67b87378b7c0b751967dTrond Norbye response.setDateHeader("Last-Modified", file.lastModified());
138a7fea383af1a9084b7ec66d309d1cbc43d5f6Chris Eldredge in = new FileInputStream(file);
138a7fea383af1a9084b7ec66d309d1cbc43d5f6Chris Eldredge response.setHeader("content-disposition", "attachment; filename=" + file.getName());
138a7fea383af1a9084b7ec66d309d1cbc43d5f6Chris Eldredge OutputStream o = response.getOutputStream();
138a7fea383af1a9084b7ec66d309d1cbc43d5f6Chris Eldredge byte[] buffer = new byte[8192];
138a7fea383af1a9084b7ec66d309d1cbc43d5f6Chris Eldredge while ((nr = in.read(buffer)) > 0) {
138a7fea383af1a9084b7ec66d309d1cbc43d5f6Chris Eldredge o.write(buffer, 0, nr);