422N/A<%--
1186N/A$Id$
1186N/A
422N/ACDDL HEADER START
422N/A
422N/AThe contents of this file are subject to the terms of the
422N/ACommon Development and Distribution License (the "License").
422N/AYou may not use this file except in compliance with the License.
422N/A
422N/ASee LICENSE.txt included in this distribution for the specific
422N/Alanguage governing permissions and limitations under the License.
422N/A
422N/AWhen distributing Covered Code, include this CDDL HEADER in each
422N/Afile and include the License file at LICENSE.txt.
422N/AIf applicable, add the following below this CDDL HEADER, with the
422N/Afields enclosed by brackets "[]" replaced with your own identifying
422N/Ainformation: Portions Copyright [yyyy] [name of copyright owner]
422N/A
422N/ACDDL HEADER END
422N/A
422N/ACopyright 2008 Sun Microsystems, Inc. All rights reserved.
422N/AUse is subject to license terms.
1186N/A
1186N/APortions Copyright 2011 Jens Elkner.
1186N/A
1186N/A--%><%@page import="
1186N/Ajava.io.File,
422N/Ajava.io.FileInputStream,
1186N/Ajava.io.InputStream,
1186N/Ajava.io.OutputStream,
422N/A
1186N/Aorg.opensolaris.opengrok.history.HistoryGuru,
1473N/Aorg.opensolaris.opengrok.util.IOUtils,
1186N/Aorg.opensolaris.opengrok.web.PageConfig"
1186N/A%><%@
422N/A
1186N/Ainclude file="pageconfig.jspf"
422N/A
1186N/A%><%
1186N/A/* ---------------------- raw.jsp start --------------------- */
1186N/A{
1281N/A cfg = PageConfig.get(request);
1281N/A String redir = cfg.canProcess();
1281N/A if (redir == null || redir.length() > 0) {
1281N/A if (redir != null) {
1281N/A response.sendRedirect(redir);
1281N/A } else {
1281N/A response.sendError(HttpServletResponse.SC_NOT_FOUND);
1281N/A }
1281N/A return;
1281N/A }
1156N/A
1473N/A File f = new File(cfg.getSourceRootPath() + '/' + cfg.getPath());
1473N/A String revision = cfg.getRequestedRevision();
1473N/A if (revision.length() == 0) {
1473N/A revision = null;
1473N/A }
1473N/A int b = -1;
1473N/A InputStream in = null;
1473N/A try {
1473N/A if (revision != null) {
1473N/A in = HistoryGuru.getInstance().getRevision(f.getParent(),
1473N/A f.getName(), revision.substring(2));
1473N/A // it might be a virtual file - History guru does not provide
1473N/A // sufficient info to detect in a reliable way
1473N/A in.mark(2);
1473N/A b = in.read();
1473N/A in.reset();
1473N/A } else {
1473N/A long flast = f.lastModified()/1000 * 1000;
1473N/A long lmdate = cfg.getConfig().getLastModified();
1473N/A if (lmdate > flast) {
1473N/A flast = lmdate;
1473N/A }
1473N/A if (request.getDateHeader("If-Modified-Since") >= flast) {
1473N/A response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
1473N/A return;
1473N/A }
1473N/A in = new FileInputStream(f);
1473N/A response.setContentLength((int) f.length());
1473N/A response.setDateHeader("Last-Modified", flast);
1473N/A b = 0;
1473N/A }
1473N/A } catch (Exception e) {
1473N/A IOUtils.close(in); // can't do that in finally - in still needed
1473N/A }
1473N/A if (b == -1) {
1473N/A response.sendError(HttpServletResponse.SC_NOT_FOUND);
1473N/A return;
1473N/A }
1473N/A String mimeType = getServletContext().getMimeType(f.getPath());
1473N/A response.setContentType(mimeType);
1281N/A
1473N/A try {
1473N/A response.setHeader("content-disposition", "attachment; filename="
1473N/A + f.getName());
1473N/A OutputStream o = response.getOutputStream();
1473N/A byte[] buffer = new byte[8192];
1473N/A int nr;
1473N/A while ((nr = in.read(buffer)) > 0) {
1473N/A o.write(buffer, 0, nr);
1473N/A }
1473N/A o.flush();
1473N/A o.close();
1473N/A } finally {
1473N/A IOUtils.close(in);
1473N/A }
422N/A}
1186N/A/* ---------------------- raw.jsp end-------------------- */
1186N/A%>