raw.jsp revision 5e43c87216dfeda97c475a542b371b958b13fed5
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 in = new FileInputStream(file);
ef604281b397eceb0d9f67b87378b7c0b751967dTrond Norbye response.setDateHeader("Last-Modified", file.lastModified());
ef604281b397eceb0d9f67b87378b7c0b751967dTrond Norbyeresponse.setHeader("content-disposition", "attachment; filename=" + file.getName());
ef604281b397eceb0d9f67b87378b7c0b751967dTrond NorbyeOutputStream o = response.getOutputStream();
ef604281b397eceb0d9f67b87378b7c0b751967dTrond Norbyebyte[] buffer = new byte[8192];
ef604281b397eceb0d9f67b87378b7c0b751967dTrond Norbyewhile ((nr = in.read(buffer)) > 0) {
ef604281b397eceb0d9f67b87378b7c0b751967dTrond Norbye o.write(buffer, 0, nr);