package com.ntsky.bbs.web.webwork.action.link;

import org.apache.log4j.Logger;

import com.ntsky.bbs.domain.Link;
import com.ntsky.bbs.exception.ActionException;
import com.ntsky.bbs.exception.ServiceException;
import com.opensymphony.xwork.ModelDriven;
/**
 * 修改友情链接
 * <ul>
 * 	<li>select -- 根据ID检索友情链接数据</li>
 *  <li>execute -- 更新友情链接数据</li>
 * </ul>
 *  
 * @author ntsky
 * @link www.ntsky.com
 * 
 * @version $Revision: 1.4 $ $Date: 2007/03/18 08:57:53 $
 */ 

public class EditLinkAction extends LinkActionSupport implements ModelDriven{

	public static Logger logger = Logger.getLogger(EditLinkAction.class);
	
	private int linkId ;
	
	public void setLinkId(int linkId){
		this.linkId = linkId;
	}
	
	// 链接数据
	private Link link = new Link() ;
	public Link getLink() {
		return link;
	}
	public void setLink(Link link) {
		this.link = link;
	}

	/**
	 * 更新友情链接
	 */
	public String execute() throws Exception {
		if(logger.isInfoEnabled()){
			logger.info("修改链接 : " +
					"链接URL="+link.getUrl());
		}
		try{
			linkService.editLink(link);
		}
		catch(ServiceException se){
			throw new ActionException(se);
		}
		return SUCCESS;
	}
	
	/**
	 * 根据链接编号检索链接数据
	 * @return SELECT
	 * @throws Exception
	 */
	public String doSelect() throws Exception{
		
		/* ---------- 权限判断 ------------ */
		//　修改友情链接
		if(!isPermisson("6_2")){
			setWarnMessage("您没有修改友情链接的权限.");
			return NO_PERMISSION;
		}
		/* ------------------------------ */		
		
		/* ------------ 记录日志 -----------*/
		recordActLog("修改友情链接");
		/* -------------------------------*/
		
		if(logger.isDebugEnabled()){
			logger.debug("修改编号["+linkId+"]的链接信息");
		}
		try{
			setLink(linkService.getLink(linkId));
		}
		catch(ServiceException se){
			throw new ActionException(se);
		}
		return SELECT;
	}

	public Object getModel() {
		return this.link;
	}
	
}