Subversion Repositories general

Rev

Rev 1242 | Rev 1249 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

package ak.photoalbum.webapp;

import java.util.List;
import java.util.ArrayList;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.log4j.Logger;
import ak.photoalbum.util.FileUtils;

public final class IndexAction
  extends BaseAction
{
  private static final Logger logger = Logger.getLogger(IndexAction.class);

  public ActionForward executeAction(ActionMapping mapping, ActionForm form,
     HttpServletRequest request, HttpServletResponse response)
    throws Exception
  {
    IndexForm  theForm = (IndexForm)form;
    String     dir     = theForm.getPath();
    int        page    = theForm.getPageInt();
    IndexEntry entry   = new IndexEntry();
    IndexEntry top     = new IndexEntry();
    IndexEntry prev    = new IndexEntry();
    IndexEntry current = new IndexEntry();
    IndexEntry next    = new IndexEntry();
    List       index   = new ArrayList();
    List       pages   = new ArrayList();

    if(dir == null) dir = "";  // the images root

    logger.info("get index for " + dir);
    Logic.getLogic().getEntry(dir, entry, top, prev, current, next);
    if(!Logic.getLogic().listDirectory(dir, page, index, pages))
      return mapping.findForward("error");

    request.setAttribute("dir",          FileUtils.replaceFileSeparator(dir, " - "));
    request.setAttribute("index",        index);
    request.setAttribute("top",          top);
    request.setAttribute("prevEntry",    prev);
    request.setAttribute("current",      current);
    request.setAttribute("nextEntry",    next);
    request.setAttribute("pages",        pages);
    request.setAttribute("severalPages", new Boolean(pages.size() > 1));
    request.setAttribute("firstPage",    pages.get(0));
    request.setAttribute("lastPage",     pages.get(pages.size() - 1));
    request.setAttribute("prevPage",     (page == 0)                ? null : pages.get(page-1));
    request.setAttribute("nextPage",     (page == pages.size() - 1) ? null : pages.get(page+1));

    return mapping.findForward("success");
  }
}