raw.jsp revision 1473
422N/A<%--
422N/A$Id$
422N/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.
422N/A
422N/APortions Copyright 2011 Jens Elkner.
422N/A
422N/A--%><%@page import="
422N/Ajava.io.File,
422N/Ajava.io.FileInputStream,
422N/Ajava.io.InputStream,
422N/Ajava.io.OutputStream,
422N/A
422N/Aorg.opensolaris.opengrok.history.HistoryGuru,
422N/Aorg.opensolaris.opengrok.util.IOUtils,
422N/Aorg.opensolaris.opengrok.web.PageConfig"
422N/A%><%@
422N/A
422N/Ainclude file="pageconfig.jspf"
422N/A
422N/A%><%
422N/A/* ---------------------- raw.jsp start --------------------- */
422N/A{
422N/A cfg = PageConfig.get(request);
422N/A String redir = cfg.canProcess();
422N/A if (redir == null || redir.length() > 0) {
422N/A if (redir != null) {
422N/A response.sendRedirect(redir);
422N/A } else {
422N/A response.sendError(HttpServletResponse.SC_NOT_FOUND);
422N/A }
422N/A return;
422N/A }
422N/A
422N/A File f = new File(cfg.getSourceRootPath() + '/' + cfg.getPath());
422N/A String revision = cfg.getRequestedRevision();
422N/A if (revision.length() == 0) {
422N/A revision = null;
422N/A }
422N/A int b = -1;
422N/A InputStream in = null;
422N/A try {
422N/A if (revision != null) {
422N/A in = HistoryGuru.getInstance().getRevision(f.getParent(),
422N/A f.getName(), revision.substring(2));
422N/A // it might be a virtual file - History guru does not provide
422N/A // sufficient info to detect in a reliable way
422N/A in.mark(2);
422N/A b = in.read();
422N/A in.reset();
422N/A } else {
422N/A long flast = f.lastModified()/1000 * 1000;
422N/A long lmdate = cfg.getConfig().getLastModified();
422N/A if (lmdate > flast) {
422N/A flast = lmdate;
422N/A }
422N/A 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", flast);
b = 0;
}
} catch (Exception e) {
IOUtils.close(in); // can't do that in finally - in still needed
}
if (b == -1) {
response.sendError(HttpServletResponse.SC_NOT_FOUND);
return;
}
String mimeType = getServletContext().getMimeType(f.getPath());
response.setContentType(mimeType);
try {
response.setHeader("content-disposition", "attachment; filename="
+ f.getName());
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 {
IOUtils.close(in);
}
}
/* ---------------------- raw.jsp end-------------------- */
%>