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