raw.jsp revision 1281
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,
1063N/Ajava.io.FileNotFoundException,
1186N/Ajava.io.InputStream,
1186N/Ajava.io.OutputStream,
422N/A
1186N/Aorg.opensolaris.opengrok.configuration.RuntimeEnvironment,
1186N/Aorg.opensolaris.opengrok.history.HistoryGuru,
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
1281N/A File f = cfg.getResourceFile();
1281N/A String revision = cfg.getRequestedRevision();
1281N/A if (revision.length() == 0) {
1281N/A revision = null;
1281N/A }
1281N/A InputStream in = null;
1281N/A try {
1281N/A if (revision != null) {
1281N/A in = HistoryGuru.getInstance().getRevision(f.getParent(),
1281N/A f.getName(), revision.substring(2));
1281N/A } else {
1281N/A long flast = cfg.getLastModified();
1281N/A if (request.getDateHeader("If-Modified-Since") >= flast) {
1281N/A response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
1281N/A return;
1281N/A }
1281N/A in = new FileInputStream(f);
1281N/A response.setContentLength((int) f.length());
1281N/A response.setDateHeader("Last-Modified", f.lastModified());
1281N/A }
1281N/A } catch (Exception e) {
1281N/A response.sendError(HttpServletResponse.SC_NOT_FOUND);
1281N/A return ;
1281N/A }
1281N/A String mimeType = getServletContext().getMimeType(f.getAbsolutePath());
1281N/A response.setContentType(mimeType);
1281N/A
1281N/A try {
1281N/A response.setHeader("content-disposition", "attachment; filename="
1281N/A + f.getName());
1281N/A OutputStream o = response.getOutputStream();
1281N/A byte[] buffer = new byte[8192];
1281N/A int nr;
1281N/A while ((nr = in.read(buffer)) > 0) {
1281N/A o.write(buffer, 0, nr);
1281N/A }
1281N/A o.flush();
1281N/A o.close();
1281N/A } finally {
1281N/A in.close();
1281N/A }
422N/A}
1186N/A/* ---------------------- raw.jsp end-------------------- */
1186N/A%>