Package org.mapache.ui.blog

Source Code of org.mapache.ui.blog.BlogManagementBean

package org.mapache.ui.blog;

import java.util.Date;
import java.util.List;

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.blog.Blog;
import org.mapache.business.blog.BlogManager;
import org.mapache.business.category.Category;
import org.mapache.business.topic.Topic;

public class BlogManagementBean {
    private HtmlDataList _blogDataList;
    private HtmlDataList _topicDataList;
    private HtmlDataList _categoryTopicDataList;
    private HtmlDataList _categoryDataList;
    private Blog _blog;
    private List<Blog> _blogs;
    private List<Topic> _topics;
    private List<Category> _categories;
    private String _search;
       
    public BlogManagementBean() {
    }
    private BlogController getBlogController(){
        return BlogController.getInstance();
    }
    public void setBlogDataList(HtmlDataList blogDataList) {
        this._blogDataList = blogDataList;
    }

    public HtmlDataList getBlogDataList() {
        return _blogDataList;
    }

    public void setBlog(Blog blog) {
        this._blog = blog;
    }

    public Blog getBlog() {
        String id = (String)FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("blog");
        if(id !=null && id.length()>0){
            try {
                _blog = getBlogController().loadBlogByBlogName_visitor(id.replaceAll("_"," "));
            } catch (MapacheException e) {
                // TODO
                e.printStackTrace();
            }
        }
        return _blog;
    }

    public List<Blog> getBlogs() {
        try {
            _blogs = getBlogController().loadBlogs();
        } catch (MapacheException e) {
            e.printStackTrace();
        }
        return _blogs;
    }

    public String loadTopicsOfBlog() {
        _blog = (Blog)_blogDataList.getRowData();
        return "loadTopicsOfBlogClicked";
    }

    public void setTopics(List<Topic> topics) {
        this._topics = topics;
    }

    public List<Topic> getTopics() {
        try {
                //if(_search==null || _search.equalsIgnoreCase("")){
                _topics = getBlogController().loadTopics(getBlog(),getCategory());
                /*}else{
                    _topics = getBlogController().loadTopicsBySearch(_search.split(" "));
                }*/
            } catch (MapacheException e) {
                e.printStackTrace();
            }
        return _topics;
    }

    public void setTopicDataList(HtmlDataList topicDataList) {
        this._topicDataList = topicDataList;
    }

    public HtmlDataList getTopicDataList() {
        return _topicDataList;
    }

    public void setCategoryTopicDataList(HtmlDataList categoryDataList) {
        this._categoryTopicDataList = categoryDataList;
    }

    public HtmlDataList getCategoryTopicDataList() {
        return _categoryTopicDataList;
    }

    public void setCategoryDataList(HtmlDataList categoryDataList) {
        this._categoryDataList = categoryDataList;
    }

    public HtmlDataList getCategoryDataList() {
        return _categoryDataList;
    }

    public void setCategories(List<Category> categories) {
        this._categories = categories;
    }

    public List<Category> getCategories() {
        try {
            _categories = getBlogController().loadCategoriesOfBlog(getBlog());
        } catch (MapacheException e) {
            e.printStackTrace();
        }
        return _categories;
    }

    private Category getCategory() {
        String name = (String)FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("category");
        Category c = null;
        if(name !=null && name.length()>0){
            try {
                c = getBlogController().loadCategoryByCategoryName(name.replaceAll("_"," "));
            } catch (MapacheException e) {
                // TODO
                e.printStackTrace();
            }
        }
        return c;
    }


    public void setSearch(String search) {
        this._search = search;
    }

    public String getSearch() {
        return _search;
    }

    public String search() {
        String[] params = _search.split(" ");
        try {
            _topics = getBlogController().loadTopicsBySearch(params);
        } catch (MapacheException e) {
            // TODO
            e.printStackTrace();
        }
        return "searchClicked";
    }
}
TOP

Related Classes of org.mapache.ui.blog.BlogManagementBean

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.