package org.mapache.ui.blog;
import java.io.IOException;
import java.util.List;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import org.apache.myfaces.custom.datalist.HtmlDataList;
import org.mapache.business.BlogController;
import org.mapache.business.MapacheException;
import org.mapache.business.reply.Reply;
import org.mapache.business.topic.Topic;
import org.mapache.ui.common.MapacheUIUtils;
public class ReplyManagementBean {
private BlogController _bgControl;
private Topic _topic;
private HtmlDataList _repliesDataList;
private HtmlDataList _categoryTopicDataList;
private HtmlDataList _blogDataList;
private List<Reply> _replies;
private String _userName,_userEmail,_userHomePage,_content;
public ReplyManagementBean() {
}
private BlogController getBlogController(){
/*if(_bgControl==null){
_bgControl = new BlogController();
}
return _bgControl;*/
return BlogController.getInstance();
}
public void setTopic(Topic topic) {
this._topic = topic;
}
public Topic getTopic() {
String title = (String)FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("topic");
if(title!=null && title.length()>0){
try {
_topic = getBlogController().loadTopicByTopicTitle(title.replaceAll("_"," "));
} catch (MapacheException e) {
// TODO
e.printStackTrace();
}
}
else if(_topic==null){
try {
FacesContext.getCurrentInstance().getExternalContext().redirect("blog.jspx");
} catch (IOException e) {
// TODO
e.printStackTrace();
}
}
return _topic;
}
public void setRepliesDataList(HtmlDataList repliesDataList) {
this._repliesDataList = repliesDataList;
}
public HtmlDataList getRepliesDataList() {
return _repliesDataList;
}
public void setReplies(List<Reply> replies) {
this._replies = replies;
}
public void setBlogDataList(HtmlDataList blogDataList) {
this._blogDataList = blogDataList;
}
public HtmlDataList getBlogDataList() {
return _blogDataList;
}
public List<Reply> getReplies() {
try {
_replies = getBlogController().loadRepliesOfTopic(getTopic());
} catch (MapacheException e) {
// TODO
e.printStackTrace();
}
return _replies;
}
public void setCategoryTopicDataList(HtmlDataList categoryTopicDataList) {
this._categoryTopicDataList = categoryTopicDataList;
}
public HtmlDataList getCategoryTopicDataList() {
return _categoryTopicDataList;
}
public void setUserName(String userName) {
this._userName = userName;
}
public String getUserName() {
return _userName;
}
public void setUserEmail(String userEmail) {
this._userEmail = userEmail;
}
public String getUserEmail() {
return _userEmail;
}
public void setUserHomePage(String userHomePage) {
this._userHomePage = userHomePage;
}
public String getUserHomePage() {
return _userHomePage;
}
public void setContent(String content) {
this._content = content;
}
public String getContent() {
return _content;
}
public String reply() {
Reply newReply = new Reply();
newReply.setContent(_content);
newReply.setUserEmail(_userEmail);
newReply.setUserName(_userName);
newReply.setUserHomePage(_userHomePage);
try {
getBlogController().createReply(newReply,_topic.getTopicID());
_content = _userEmail = _userName = _userHomePage = null;
} catch (MapacheException e) {
e.printStackTrace();
}
return "createClicked";
}
}