/*
 * $Id: ShowNewsForm.java,v 1.4 2005/01/05 18:49:19 marbobo Exp $
 * 
 * Copyright (c) Siemens AG 2008 
 *           (c) Universität Paderborn 2008 
 * Licensed under EUPL 1.1. 
 * 
 * $Log: ShowNewsForm.java,v $
 * Revision 1.4  2005/01/05 18:49:19  marbobo
 * + Wenn nur gültige Nachrichten angezeigt werden sollen, dann ungültige aus der Collection raus schmeisen
 *
 * Revision 1.3  2004/07/28 23:09:57  marbobo
 * + isConsiderValidNewsOnly()
 *
 * Revision 1.2  2004/07/26 13:31:16  marbobo
 * + Umgeschrieben
 *
 * Revision 1.1  2004/07/26 12:40:54  marbobo
 * + Nack vkc.news verschoben
 */
package vkc.news.form;

import java.util.Iterator;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionMapping;

import vkc.db.entities.VKCNews;
import vkc.db.serializer.VKCNewsSerializer;
import vkc.db.serializer.VKCSysParameterSerializer;
import vkc.exception.DBException;
import vkc.view.form.BasicActionForm;

public class ShowNewsForm extends BasicActionForm {
    List news = null;

    public void reset( ActionMapping mapping, HttpServletRequest request ) {
	    super.reset( mapping, request );
	    news = null;
	}

    public List getNews() throws DBException {
        if ( news == null ) {
    	    news = VKCNewsSerializer.retrieveNews();
    	    
    	    if ( isConsiderValidNewsOnly() ) {
    	        Iterator it = news.iterator();
    	        
    	        while ( it.hasNext() ) {
    	            VKCNews n = (VKCNews)it.next();
    	            
    	            if ( !n.isValid() ) {
    	                it.remove();
    	            }
    	        }
    	    }
        }
        
        return news;
    }
    
	public void setNews( List l ) {
		news = l;
	}
	
	public boolean isConsiderValidNewsOnly() throws DBException {
		if ( VKCSysParameterSerializer.retrieveIntValue( "NEWS", "ConsiderValidNewsOnly", 0 ) == 0 ) {
		    return false;
		}
		
		return true;
	}
}