raw.jsp revision eee3266b4179dae85826d6139b3b540838ea955a
ef604281b397eceb0d9f67b87378b7c0b751967dTrond Norbye<%--
14a41f02433890d19b2f871156271e3388cd0845Jens Elkner$Id$
14a41f02433890d19b2f871156271e3388cd0845Jens Elkner
ef604281b397eceb0d9f67b87378b7c0b751967dTrond NorbyeCDDL HEADER START
ef604281b397eceb0d9f67b87378b7c0b751967dTrond Norbye
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 Norbye
ef604281b397eceb0d9f67b87378b7c0b751967dTrond NorbyeSee LICENSE.txt included in this distribution for the specific
ef604281b397eceb0d9f67b87378b7c0b751967dTrond Norbyelanguage governing permissions and limitations under the License.
ef604281b397eceb0d9f67b87378b7c0b751967dTrond Norbye
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 Norbye
ef604281b397eceb0d9f67b87378b7c0b751967dTrond NorbyeCDDL HEADER END
ef604281b397eceb0d9f67b87378b7c0b751967dTrond Norbye
eee3266b4179dae85826d6139b3b540838ea955aKnut Anders HatlenCopyright (c) 2008, 2016, Oracle and/or its affiliates. All rights reserved.
ef604281b397eceb0d9f67b87378b7c0b751967dTrond Norbye
14a41f02433890d19b2f871156271e3388cd0845Jens ElknerPortions Copyright 2011 Jens Elkner.
ef604281b397eceb0d9f67b87378b7c0b751967dTrond Norbye
14a41f02433890d19b2f871156271e3388cd0845Jens Elkner--%><%@page import="
14a41f02433890d19b2f871156271e3388cd0845Jens Elknerjava.io.File,
14a41f02433890d19b2f871156271e3388cd0845Jens Elknerjava.io.FileInputStream,
14a41f02433890d19b2f871156271e3388cd0845Jens Elknerjava.io.FileNotFoundException,
14a41f02433890d19b2f871156271e3388cd0845Jens Elknerjava.io.InputStream,
14a41f02433890d19b2f871156271e3388cd0845Jens Elknerjava.io.OutputStream,
ef604281b397eceb0d9f67b87378b7c0b751967dTrond Norbye
14a41f02433890d19b2f871156271e3388cd0845Jens Elknerorg.opensolaris.opengrok.configuration.RuntimeEnvironment,
14a41f02433890d19b2f871156271e3388cd0845Jens Elknerorg.opensolaris.opengrok.history.HistoryGuru,
d8371503c60e1f6933455e25b1cc47e4858a3a43Vladimir Kotalorg.opensolaris.opengrok.web.PageConfig,
d8371503c60e1f6933455e25b1cc47e4858a3a43Vladimir Kotalorg.opensolaris.opengrok.web.Prefix"
14a41f02433890d19b2f871156271e3388cd0845Jens Elkner%><%@
ef604281b397eceb0d9f67b87378b7c0b751967dTrond Norbye
14a41f02433890d19b2f871156271e3388cd0845Jens Elknerinclude file="pageconfig.jspf"
ef604281b397eceb0d9f67b87378b7c0b751967dTrond Norbye
14a41f02433890d19b2f871156271e3388cd0845Jens Elkner%><%
14a41f02433890d19b2f871156271e3388cd0845Jens Elkner/* ---------------------- raw.jsp start --------------------- */
14a41f02433890d19b2f871156271e3388cd0845Jens Elkner{
59b6a8c0cc6ef741a7180504b3c371e67c2aa338Knut Anders Hatlen cfg = PageConfig.get(request);
59b6a8c0cc6ef741a7180504b3c371e67c2aa338Knut Anders Hatlen String redir = cfg.canProcess();
59b6a8c0cc6ef741a7180504b3c371e67c2aa338Knut Anders Hatlen if (redir == null || redir.length() > 0) {
59b6a8c0cc6ef741a7180504b3c371e67c2aa338Knut Anders Hatlen if (redir != null) {
59b6a8c0cc6ef741a7180504b3c371e67c2aa338Knut Anders Hatlen response.sendRedirect(redir);
59b6a8c0cc6ef741a7180504b3c371e67c2aa338Knut Anders Hatlen } else {
59b6a8c0cc6ef741a7180504b3c371e67c2aa338Knut Anders Hatlen response.sendError(HttpServletResponse.SC_NOT_FOUND);
59b6a8c0cc6ef741a7180504b3c371e67c2aa338Knut Anders Hatlen }
59b6a8c0cc6ef741a7180504b3c371e67c2aa338Knut Anders Hatlen return;
59b6a8c0cc6ef741a7180504b3c371e67c2aa338Knut Anders Hatlen }
138a7fea383af1a9084b7ec66d309d1cbc43d5f6Chris Eldredge
59b6a8c0cc6ef741a7180504b3c371e67c2aa338Knut Anders Hatlen File f = cfg.getResourceFile();
59b6a8c0cc6ef741a7180504b3c371e67c2aa338Knut Anders Hatlen String revision = cfg.getRequestedRevision();
59b6a8c0cc6ef741a7180504b3c371e67c2aa338Knut Anders Hatlen if (revision.length() == 0) {
59b6a8c0cc6ef741a7180504b3c371e67c2aa338Knut Anders Hatlen revision = null;
59b6a8c0cc6ef741a7180504b3c371e67c2aa338Knut Anders Hatlen }
59b6a8c0cc6ef741a7180504b3c371e67c2aa338Knut Anders Hatlen InputStream in = null;
59b6a8c0cc6ef741a7180504b3c371e67c2aa338Knut Anders Hatlen try {
59b6a8c0cc6ef741a7180504b3c371e67c2aa338Knut Anders Hatlen if (revision != null) {
59b6a8c0cc6ef741a7180504b3c371e67c2aa338Knut Anders Hatlen in = HistoryGuru.getInstance().getRevision(f.getParent(),
eee3266b4179dae85826d6139b3b540838ea955aKnut Anders Hatlen f.getName(), revision);
59b6a8c0cc6ef741a7180504b3c371e67c2aa338Knut Anders Hatlen } else {
59b6a8c0cc6ef741a7180504b3c371e67c2aa338Knut Anders Hatlen long flast = cfg.getLastModified();
59b6a8c0cc6ef741a7180504b3c371e67c2aa338Knut Anders Hatlen if (request.getDateHeader("If-Modified-Since") >= flast) {
59b6a8c0cc6ef741a7180504b3c371e67c2aa338Knut Anders Hatlen response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
59b6a8c0cc6ef741a7180504b3c371e67c2aa338Knut Anders Hatlen return;
59b6a8c0cc6ef741a7180504b3c371e67c2aa338Knut Anders Hatlen }
59b6a8c0cc6ef741a7180504b3c371e67c2aa338Knut Anders Hatlen in = new FileInputStream(f);
59b6a8c0cc6ef741a7180504b3c371e67c2aa338Knut Anders Hatlen response.setContentLength((int) f.length());
59b6a8c0cc6ef741a7180504b3c371e67c2aa338Knut Anders Hatlen response.setDateHeader("Last-Modified", f.lastModified());
59b6a8c0cc6ef741a7180504b3c371e67c2aa338Knut Anders Hatlen }
59b6a8c0cc6ef741a7180504b3c371e67c2aa338Knut Anders Hatlen } catch (Exception e) {
59b6a8c0cc6ef741a7180504b3c371e67c2aa338Knut Anders Hatlen response.sendError(HttpServletResponse.SC_NOT_FOUND);
59b6a8c0cc6ef741a7180504b3c371e67c2aa338Knut Anders Hatlen return ;
59b6a8c0cc6ef741a7180504b3c371e67c2aa338Knut Anders Hatlen }
59b6a8c0cc6ef741a7180504b3c371e67c2aa338Knut Anders Hatlen String mimeType = getServletContext().getMimeType(f.getAbsolutePath());
59b6a8c0cc6ef741a7180504b3c371e67c2aa338Knut Anders Hatlen response.setContentType(mimeType);
59b6a8c0cc6ef741a7180504b3c371e67c2aa338Knut Anders Hatlen
59b6a8c0cc6ef741a7180504b3c371e67c2aa338Knut Anders Hatlen try {
d8371503c60e1f6933455e25b1cc47e4858a3a43Vladimir Kotal if (cfg.getPrefix() == Prefix.DOWNLOAD_P) {
d8371503c60e1f6933455e25b1cc47e4858a3a43Vladimir Kotal response.setHeader("content-disposition", "attachment; filename="
d8371503c60e1f6933455e25b1cc47e4858a3a43Vladimir Kotal + f.getName());
d8371503c60e1f6933455e25b1cc47e4858a3a43Vladimir Kotal } else {
d8371503c60e1f6933455e25b1cc47e4858a3a43Vladimir Kotal response.setHeader("content-type", "text/plain");
d8371503c60e1f6933455e25b1cc47e4858a3a43Vladimir Kotal }
59b6a8c0cc6ef741a7180504b3c371e67c2aa338Knut Anders Hatlen OutputStream o = response.getOutputStream();
59b6a8c0cc6ef741a7180504b3c371e67c2aa338Knut Anders Hatlen byte[] buffer = new byte[8192];
59b6a8c0cc6ef741a7180504b3c371e67c2aa338Knut Anders Hatlen int nr;
59b6a8c0cc6ef741a7180504b3c371e67c2aa338Knut Anders Hatlen while ((nr = in.read(buffer)) > 0) {
59b6a8c0cc6ef741a7180504b3c371e67c2aa338Knut Anders Hatlen o.write(buffer, 0, nr);
59b6a8c0cc6ef741a7180504b3c371e67c2aa338Knut Anders Hatlen }
59b6a8c0cc6ef741a7180504b3c371e67c2aa338Knut Anders Hatlen o.flush();
59b6a8c0cc6ef741a7180504b3c371e67c2aa338Knut Anders Hatlen o.close();
59b6a8c0cc6ef741a7180504b3c371e67c2aa338Knut Anders Hatlen } finally {
59b6a8c0cc6ef741a7180504b3c371e67c2aa338Knut Anders Hatlen in.close();
59b6a8c0cc6ef741a7180504b3c371e67c2aa338Knut Anders Hatlen }
ef604281b397eceb0d9f67b87378b7c0b751967dTrond Norbye}
14a41f02433890d19b2f871156271e3388cd0845Jens Elkner/* ---------------------- raw.jsp end-------------------- */
d8371503c60e1f6933455e25b1cc47e4858a3a43Vladimir Kotal%>