net.sf.ginp.commands.SelectCollection.java Source code

Java tutorial

Introduction

Here is the source code for net.sf.ginp.commands.SelectCollection.java

Source

/*
 *  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.commands;

import net.sf.ginp.CommandParameter;
import net.sf.ginp.GinpModel;
import net.sf.ginp.config.Configuration;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.util.Vector;

/**
 *  Class to action the request changing the current collection.
 *
 *@author     Doug Culnane
 *@version    $Revision$
 */
public class SelectCollection implements Command {

    /**
     *  apache Commons Logger specific to this class.
     */
    private Log log = LogFactory.getLog(SelectCollection.class);

    /**
     *  Called when a Start tag is processed.
     *
     *@param  model   Description of the Parameter
     *@param  params  Description of the Parameter
     */
    public final void action(final GinpModel model, final Vector params) {
        String id = "";

        for (int i = 0; i < params.size(); i++) {
            CommandParameter param = (CommandParameter) params.get(i);

            if (param.getName().equals("id")) {
                id = param.getValue();
            }
        }

        int idNum = 0;

        try {
            idNum = (new Integer(id)).intValue();
        } catch (Exception ex) {
            log.error(ex);
            idNum = 0;
        }

        if (model.setCurrectCollection(idNum)) {
            model.setCurrentPage(Configuration.getCollectionPageName());
            model.getCollection().setPath("/");
            model.setPageOffset(0);
            model.setPagePosition(0);
        }
    }
}