Subversion Repositories general

Rev

Rev 1249 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
936 dev 1
package ak.photoalbum.webapp;
2
 
3
import java.util.List;
1242 dev 4
import java.util.ArrayList;
936 dev 5
import javax.servlet.http.HttpServletRequest;
6
import javax.servlet.http.HttpServletResponse;
7
import org.apache.struts.action.ActionMapping;
8
import org.apache.struts.action.ActionForm;
9
import org.apache.struts.action.ActionForward;
10
import org.apache.log4j.Logger;
11
import ak.photoalbum.util.FileUtils;
1249 dev 12
import ak.photoalbum.logic.Logic;
13
import ak.photoalbum.logic.IndexEntry;
936 dev 14
 
15
public final class IndexAction
16
  extends BaseAction
17
{
18
  private static final Logger logger = Logger.getLogger(IndexAction.class);
19
 
20
  public ActionForward executeAction(ActionMapping mapping, ActionForm form,
21
     HttpServletRequest request, HttpServletResponse response)
22
    throws Exception
23
  {
1242 dev 24
    IndexForm  theForm = (IndexForm)form;
1249 dev 25
    String     branch  = theForm.getBranch();
936 dev 26
    String     dir     = theForm.getPath();
1242 dev 27
    int        page    = theForm.getPageInt();
936 dev 28
    IndexEntry entry   = new IndexEntry();
29
    IndexEntry top     = new IndexEntry();
30
    IndexEntry prev    = new IndexEntry();
31
    IndexEntry current = new IndexEntry();
32
    IndexEntry next    = new IndexEntry();
1242 dev 33
    List       index   = new ArrayList();
34
    List       pages   = new ArrayList();
936 dev 35
 
36
    if(dir == null) dir = "";  // the images root
37
 
38
    logger.info("get index for " + dir);
1249 dev 39
    Logic.getLogic().getEntry(branch, dir, entry, top, prev, current, next);
40
    if(!Logic.getLogic().listDirectory(branch, dir, page, index, pages))
1242 dev 41
      return mapping.findForward("error");
936 dev 42
 
1245 dev 43
    request.setAttribute("dir",          FileUtils.replaceFileSeparator(dir, " - "));
44
    request.setAttribute("index",        index);
45
    request.setAttribute("top",          top);
46
    request.setAttribute("prevEntry",    prev);
47
    request.setAttribute("current",      current);
48
    request.setAttribute("nextEntry",    next);
49
    request.setAttribute("pages",        pages);
1274 dev 50
    request.setAttribute("severalPages", Boolean.valueOf(pages.size() > 1));
1245 dev 51
    request.setAttribute("firstPage",    pages.get(0));
52
    request.setAttribute("lastPage",     pages.get(pages.size() - 1));
53
    request.setAttribute("prevPage",     (page == 0)                ? null : pages.get(page-1));
54
    request.setAttribute("nextPage",     (page == pages.size() - 1) ? null : pages.get(page+1));
936 dev 55
 
56
    return mapping.findForward("success");
57
  }
58
}