raw.jsp revision 422
57da8c32f85c0255efa61ee32e260068afdaa565KATOH YasufumiCDDL HEADER START
57da8c32f85c0255efa61ee32e260068afdaa565KATOH YasufumiThe contents of this file are subject to the terms of the
57da8c32f85c0255efa61ee32e260068afdaa565KATOH YasufumiCommon Development and Distribution License (the "License").
57da8c32f85c0255efa61ee32e260068afdaa565KATOH YasufumiYou may not use this file except in compliance with the License.
57da8c32f85c0255efa61ee32e260068afdaa565KATOH YasufumiSee LICENSE.txt included in this distribution for the specific
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumilanguage governing permissions and limitations under the License.
57da8c32f85c0255efa61ee32e260068afdaa565KATOH YasufumiWhen distributing Covered Code, include this CDDL HEADER in each
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumifile and include the License file at LICENSE.txt.
57da8c32f85c0255efa61ee32e260068afdaa565KATOH YasufumiIf applicable, add the following below this CDDL HEADER, with the
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumifields enclosed by brackets "[]" replaced with your own identifying
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumiinformation: Portions Copyright [yyyy] [name of copyright owner]
57da8c32f85c0255efa61ee32e260068afdaa565KATOH YasufumiCDDL HEADER END
57da8c32f85c0255efa61ee32e260068afdaa565KATOH YasufumiCopyright 2008 Sun Microsystems, Inc. All rights reserved.
57da8c32f85c0255efa61ee32e260068afdaa565KATOH YasufumiUse is subject to license terms.
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi--%><%@page import="java.io.File,
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumiorg.opensolaris.opengrok.configuration.RuntimeEnvironment,
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumiorg.opensolaris.opengrok.history.HistoryGuru"%><%
57da8c32f85c0255efa61ee32e260068afdaa565KATOH YasufumiString root = RuntimeEnvironment.getInstance().getSourceRootPath();
faefa7f8584a7d1567df2e6f1f9240a28a6466abStéphane Graberif (path == null) {
57da8c32f85c0255efa61ee32e260068afdaa565KATOH YasufumiFile file = new File(root, path);
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumiif (!path.startsWith(root) || !file.exists() || !file.canRead() || RuntimeEnvironment.getInstance().getIgnoredNames().ignore(file)) {
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi response.sendError(response.SC_NOT_FOUND, "Can't download a directory");
57da8c32f85c0255efa61ee32e260068afdaa565KATOH YasufumiString mimeType = getServletContext().getMimeType(file.getAbsolutePath());
57da8c32f85c0255efa61ee32e260068afdaa565KATOH YasufumiString revision = request.getParameter("r");
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumiif (revision != null && revision.length() == 0) {
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi revision = null;
57da8c32f85c0255efa61ee32e260068afdaa565KATOH YasufumiInputStream in = null;
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumiif (revision != null) {
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi in = HistoryGuru.getInstance().getRevision(file.getParent(), file.getName(), revision);
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi } catch (Exception e) {
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi response.sendError(404, "Revision not found");
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi in = new FileInputStream(file);
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi response.setContentLength((int)file.length());
348cb247dbb92940b5684c12b43579bccba85dabKATOH Yasufumi response.setDateHeader("Last-Modified", file.lastModified());
4724cf84f941156273d52918704c6e584455f6b4KATOH Yasufumiresponse.setHeader("content-disposition", "attachment; filename=" + file.getName());
57da8c32f85c0255efa61ee32e260068afdaa565KATOH YasufumiOutputStream o = response.getOutputStream();
a4cd509bd809fda136b49991f90d66c1a2409a1cChristian Braunerbyte[] buffer = new byte[8192];
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumiwhile ((nr = in.read(buffer)) > 0) {
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi o.write(buffer, 0, nr);