Subversion Repositories general

Compare Revisions

Ignore whitespace Rev 1257 → Rev 1272

/PhotoAlbum/trunk/src/ak/photoalbum/webapp/ImageAction.java
8,6 → 8,7
import org.apache.struts.action.ActionForward;
import org.apache.log4j.Logger;
import ak.photoalbum.logic.Logic;
import ak.photoalbum.util.TimestampRecipient;
 
public final class ImageAction
extends BaseAction
18,30 → 19,66
HttpServletRequest request, HttpServletResponse response)
throws Exception
{
PathForm theForm = (PathForm)form;
String branch = theForm.getBranch();
String path = theForm.getPath();
Logic logic = Logic.getLogic();
PathForm theForm = (PathForm)form;
String branch = theForm.getBranch();
String path = theForm.getPath();
Logic logic = Logic.getLogic();
HttpTimestampRecipient timestampRecipient = new HttpTimestampRecipient(response);
long ifModifiedSince;
boolean fileModified = true;
 
try {
ifModifiedSince = request.getDateHeader("If-Modified-Since");
}
catch(Exception ex) {
ifModifiedSince = -1;
}
 
logger.info("get image " + mapping.getParameter() + " for " + path);
 
if("dir".equals(mapping.getParameter())) {
response.setContentType(logic.getThumbnailMime(branch));
logic.writeDir(branch, path, response.getOutputStream());
fileModified = logic.writeDir(branch, path, ifModifiedSince,
response.getOutputStream(), timestampRecipient);
}
else if("small".equals(mapping.getParameter())) {
response.setContentType(logic.getThumbnailMime(branch));
logic.writeSmall(branch, path, response.getOutputStream());
fileModified = logic.writeSmall(branch, path, ifModifiedSince,
response.getOutputStream(), timestampRecipient);
}
else if("medium".equals(mapping.getParameter())) {
response.setContentType(logic.getThumbnailMime(branch));
logic.writeMedium(branch, path, response.getOutputStream());
fileModified = logic.writeMedium(branch, path, ifModifiedSince,
response.getOutputStream(), timestampRecipient);
}
else if("origin".equals(mapping.getParameter())) {
response.setContentType(logic.getOriginMime(branch, path));
logic.writeOrigin(branch, path, response.getOutputStream());
fileModified = logic.writeOrigin(branch, path, ifModifiedSince,
response.getOutputStream(), timestampRecipient);
}
 
// if file was modified comapring to "If-Modified-Since" header, then it's already written
// into to response; otherwise send 304 code
if(!fileModified) {
response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
}
 
return null;
}
 
private class HttpTimestampRecipient
implements TimestampRecipient
{
private HttpServletResponse response;
 
public HttpTimestampRecipient(HttpServletResponse response)
{
this.response = response;
}
 
public void setTimestamp(long timestamp)
{
response.setDateHeader("Last-Modified", timestamp);
}
}
}