package org.jerrymouse.chineseCalendar.controller;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;
import org.jerrymouse.chineseCalendar.model.birthday.Birthday;
import org.jerrymouse.chineseCalendar.service.BirthdayService;
import org.jerrymouse.chineseCalendar.service.SiteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.opensymphony.xwork2.ActionSupport;

@Component("greetingAction")
public class GreetingAction extends ActionSupport {
	private String greeting;
	@Autowired
	BirthdayService birthdayService;
	@Autowired
	SiteService siteService;
	Log logger = LogFactory.getLog(GreetingAction.class);
	String data;

	public String getData() {
		return data;
	}

	public void setData(String data) {
		this.data = data;
	}

	@Override
	@Action(value = "/greeting", results = { @Result(name = ActionSupport.SUCCESS, type = "freemarker", location = "/WEB-INF/freemarker/greeting.ftl") })
	public String execute() throws Exception {
		List<Birthday> birthdaySource = birthdayService.decode(data);
		greeting = siteService.encodeFeedURL(birthdaySource);
		return super.execute();
	}

	public String getGreeting() {
		return greeting;
	}

	public void setGreeting(String greeting) {
		this.greeting = greeting;
	}

}