⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 weblogmanagerimpl.java

📁 这个weblogging 设计得比较精巧
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * Created on Feb 24, 2003 */package org.roller.business;import org.apache.commons.collections.comparators.ReverseComparator;import org.apache.commons.logging.Log;import org.apache.commons.logging.LogFactory;import org.roller.RollerException;import org.roller.model.Roller;import org.roller.model.WeblogManager;import org.roller.pojos.CommentData;import org.roller.pojos.UserData;import org.roller.pojos.WeblogCategoryAssoc;import org.roller.pojos.WeblogCategoryData;import org.roller.pojos.WeblogEntryData;import org.roller.pojos.WebsiteData;import org.roller.util.DateUtil;import org.roller.util.Utilities;import java.text.SimpleDateFormat;import java.util.ArrayList;import java.util.Calendar;import java.util.Comparator;import java.util.Date;import java.util.Iterator;import java.util.List;import java.util.Map;import java.util.TreeMap;import org.roller.model.RollerFactory;/** * Abstract base implementation using PersistenceStrategy. * @author Dave Johnson * @author Lance Lavandowska */public abstract class WeblogManagerImpl implements WeblogManager{    private static Log mLogger =        LogFactory.getFactory().getInstance(WeblogManagerImpl.class);    protected PersistenceStrategy mStrategy;        /* inline creation of reverse comparator, anonymous inner class */    private Comparator reverseComparator = new ReverseComparator();    /*    new Comparator()    {        public int compare(Object o1, Object o2)        {            return -1 * ((Date) o1).compareTo((Date)o2);        }    };    */        private SimpleDateFormat formatter = DateUtil.get8charDateFormat();    public abstract List getWeblogEntries(                    WebsiteData website,                     Date    startDate,                     Date    endDate,                     String  catName,                     String  status,                     Integer maxEntries,                    Boolean pinned) throws RollerException;    public abstract List getNextPrevEntries(                    WeblogEntryData current,                     String catName,                     int maxEntries,                     boolean next) throws RollerException;    public WeblogManagerImpl(PersistenceStrategy strategy)    {        mStrategy = strategy;    }    public void release()    {    }    //------------------------------------------------ WeblogCategoryData CRUD    /**     * @see org.roller.model.WeblogManager#createWeblogCategory()     */    public WeblogCategoryData createWeblogCategory()    {        return new WeblogCategoryData();    }    /**     * @see org.roller.model.WeblogManager#createWeblogCategory(     * org.roller.pojos.WebsiteData, org.roller.pojos.WeblogCategoryData,     * java.lang.String, java.lang.String, java.lang.String)     */    public WeblogCategoryData createWeblogCategory(        WebsiteData website,        WeblogCategoryData parent,        String name,        String description,        String image) throws RollerException    {        return new WeblogCategoryData(            null, website, parent, name, description, image);    }    public WeblogCategoryData retrieveWeblogCategory(String id)        throws RollerException    {        return (WeblogCategoryData) mStrategy.load(            id,            WeblogCategoryData.class);    }    //--------------------------------------------- WeblogCategoryData Queries    public WeblogCategoryData getWeblogCategoryByPath(        WebsiteData website, String categoryPath) throws RollerException    {        return getWeblogCategoryByPath(website, null, categoryPath);    }    public String getPath(WeblogCategoryData category) throws RollerException    {        if (null == category.getParent())        {            return "/";        }        else        {            String parentPath = getPath(category.getParent());            parentPath = "/".equals(parentPath) ? "" : parentPath;            return parentPath + "/" + category.getName();        }    }    public WeblogCategoryData getWeblogCategoryByPath(        WebsiteData website, WeblogCategoryData category, String path)        throws RollerException    {        final Iterator cats;        final String[] pathArray = Utilities.stringToStringArray(path, "/");        if (category == null && (null == path || "".equals(path.trim())))        {            throw new RollerException("Bad arguments.");        }        if (path.trim().equals("/"))        {            return getRootWeblogCategory(website);        }        else if (category == null || path.trim().startsWith("/"))        {            cats = getRootWeblogCategory(website).getWeblogCategories().iterator();        }        else        {            cats = category.getWeblogCategories().iterator();        }        while (cats.hasNext())        {            WeblogCategoryData possibleMatch = (WeblogCategoryData)cats.next();            if (possibleMatch.getName().equals(pathArray[0]))            {                if (pathArray.length == 1)                {                    return possibleMatch;                }                else                {                    String[] subpath = new String[pathArray.length - 1];                    System.arraycopy(pathArray, 1, subpath, 0, subpath.length);                    String pathString= Utilities.stringArrayToString(subpath,"/");                    return getWeblogCategoryByPath(website, possibleMatch, pathString);                }            }        }        // The category did not match and neither did any sub-categories        return null;    }    //----------------------------------------------- WeblogCategoryAssoc CRUD    public WeblogCategoryAssoc createWeblogCategoryAssoc()    {        return new WeblogCategoryAssoc();    }    public WeblogCategoryAssoc createWeblogCategoryAssoc(        WeblogCategoryData category,        WeblogCategoryData ancestor,        String relation) throws RollerException    {        return new WeblogCategoryAssoc(null, category, ancestor, relation);    }    public WeblogCategoryAssoc retrieveWeblogCategoryAssoc(String id) throws RollerException    {        return (WeblogCategoryAssoc)mStrategy.load(id, WeblogCategoryAssoc.class);    }    //------------------------------------------------------- CommentData CRUD    public void removeComment(String id) throws RollerException    {        mStrategy.remove(id, CommentData.class);    }    public void removeComments(String[] ids) throws RollerException    {        for (int i = 0; i < ids.length; i++)        {            removeComment(ids[i]);        }    }    public void removeCommentsForEntry(String entryId) throws RollerException    {		List comments = getComments(entryId, false); // get all Comments		Iterator it = comments.iterator();		while (it.hasNext())		{			removeComment( ((CommentData)it.next()).getId() );		}	}    //---------------------------------------------------- CommentData Queries        public CommentData retrieveComment(String id) throws RollerException    {        return (CommentData) mStrategy.load(id, CommentData.class);            }    public List getComments(String entryId) throws RollerException    {        return getComments(entryId, true);    }    //--------------------------------------------------- WeblogEntryData CRUD    public WeblogEntryData retrieveWeblogEntry(String id)        throws RollerException    {        return (WeblogEntryData) mStrategy.load(            id, WeblogEntryData.class);    }    public void removeWeblogEntry(String id) throws RollerException    {        Roller mRoller = RollerFactory.getRoller();		mRoller.getRefererManager().removeReferersForEntry(id);		removeCommentsForEntry( id );

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -