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