
package jp.co.sint.beans.front;

import java.util.Collection;

import java.sql.Connection;

import jp.co.sint.basic.SINewsManager;
import jp.co.sint.config.SIConfig;
import jp.co.sint.tools.SIURLParameter;
import jp.co.sint.tools.SIUtil;

public class UIFrontNews {
  
  int index = 0;
  
  public int getIndex() {
    return index;
  }
  
  public void setIndex(int index) {
    this.index = index;
  }
  
  public UIFrontNews(){}
  
  public UIFrontNews(int index){
    this.setIndex(index);
  }
  
  public void init(SIURLParameter urlParam) {
    if(SIUtil.isNotNull((String)urlParam.getParam("inx"))) {
      this.setIndex(Integer.parseInt((String)urlParam.getParam("inx")));
      if (index>SIConfig.ctgryGroupName.length) index=0;
    }
  }
  
  public Collection getNewsCollection(Connection lConnection) {
    SINewsManager news = new SINewsManager(lConnection,this.index);
    return news.getCollection();
  }
  
  public String getCtgryGroupName(){
    if (this.index < 1) return "‘‡";
    return SIConfig.ctgryGroupName[this.index - 1];
  }
}