Java tutorial
/* * ginp - Java Web Application for Viewing Photo Collections * Copyright (C) 2004 Douglas John Culnane <doug@culnane.net> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301 USA */ package net.sf.ginp.tags; import net.sf.ginp.GinpModel; import net.sf.ginp.config.ModelUtil; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import javax.servlet.http.HttpServletRequest; import javax.servlet.jsp.JspException; /** * Get PicCollection Titles. For each PicCollection that the user has * access to, set the link to and name of the PicCollection. * *@author Doug Culnane *@version $Revision$ */ public class GetCollectionTitles extends javax.servlet.jsp.tagext.TagSupport implements javax.servlet.jsp.tagext.IterationTag { /** * */ private static final long serialVersionUID = 7292124111275174371L; /** * current position within Collection list. */ private int count; /** * number of Collections available. */ private int end; /** * instance of a single user session. */ private GinpModel model; /** * apache Commons Logger specific to this class. */ private Log log = LogFactory.getLog(GetCollectionTitles.class); /** * Set the link and name parameters for the current iteration of the * collection. Iterate again if done otherwise finish. * @return Iterate again if done otherwise don't */ public final int doAfterBody() { while (count < end) { pageContext.setAttribute("link", "ginpservlet?cmd=selectcollection&id=" + count); pageContext.setAttribute("name", model.getCollection(count).getName()); count++; return EVAL_BODY_AGAIN; } return SKIP_BODY; } /** * Called when a Start tag is processed. * *@return Description of the Return Value *@exception JspException Description of the Exception */ public final int doStartTag() throws JspException { try { model = ModelUtil.getModel((HttpServletRequest) pageContext.getRequest()); } catch (Exception e) { log.error(e); throw new JspException(e); } count = 0; end = model.getCollections().length; pageContext.setAttribute("link", "ginpservlet?cmd=selectcollection&id=" + count); pageContext.setAttribute("name", model.getCollection(count).getName()); count = 1; return EVAL_BODY_INCLUDE; } }