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

📄 macros.java

📁 这个weblogging 设计得比较精巧
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
package org.roller.presentation.velocity;import org.apache.commons.logging.Log;import org.apache.commons.logging.LogFactory;import org.apache.velocity.Template;import org.apache.velocity.VelocityContext;import org.apache.velocity.runtime.RuntimeSingleton;import org.roller.model.RefererManager;import org.roller.model.UserManager;import org.roller.pojos.PageData;import org.roller.pojos.RefererData;import org.roller.pojos.UserData;import org.roller.pojos.WeblogCategoryData;import org.roller.pojos.WebsiteData;import org.roller.presentation.RollerContext;import org.roller.presentation.RollerRequest;import org.roller.presentation.bookmarks.tags.ViewBookmarksTag;import org.roller.presentation.tags.menu.EditorNavigationBarTag;import org.roller.presentation.tags.menu.NavigationBarTag;import org.roller.presentation.weblog.tags.RssBadgeTag;import org.roller.presentation.weblog.tags.ViewWeblogEntriesTag;import org.roller.presentation.weblog.tags.WeblogCategoryChooserTag;import org.roller.util.Utilities;import java.io.PrintWriter;import java.io.StringWriter;import java.text.SimpleDateFormat;import java.util.ArrayList;import java.util.Date;import java.util.Iterator;import java.util.List;import javax.servlet.ServletContext;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import javax.servlet.jsp.PageContext;import org.roller.config.RollerRuntimeConfig;import org.roller.model.RollerFactory;/** * Provides the macros object that is available to Roller templates and  * weblog entries. */public class Macros{    private static Log mLogger =         LogFactory.getFactory().getInstance(Macros.class);    protected PageContext mPageContext = null;        protected PageHelper mPageHelper = null;    /** Maximum depth of recursion for includePage and showWeblogEntry calls */    public static final int MAX_RECURSION_DEPTH = 6;        /** Keep track of each thread's recursive depth in includePage(). */    protected static final ThreadLocal mIncludePageTLS = new ThreadLocal();        /** Keep track of each thread's recursive depth in showWeblogEntries(s */    protected static final ThreadLocal mEntriesTLS = new ThreadLocal();        /** Keep track of each thread's recursive depth in showWeblogEntries(s */    protected static final ThreadLocal mEntriesDayTLS = new ThreadLocal();    //------------------------------------------------------------------------    /** Construts a macros object for a JSP page context. */    public Macros( PageContext ctx, PageHelper helper )    {        mPageContext = ctx;        mPageHelper = helper;    }    //------------------------------------------------------------------------    /** Get the Roller request object associated with this instance */    protected RollerRequest getRollerRequest()    {        return RollerRequest.getRollerRequest(mPageContext);    }    //------------------------------------------------------------------------    /**     * Returns the current date formatted according to the specified pattern.     * @param pattern Date pattern, @see java.text.SimpleDateFormat     * @return Current date formatted according to specified pattern.     */    public String formatCurrentDate( String pattern )    {        String date = null;        try        {            SimpleDateFormat format = new SimpleDateFormat( pattern );            date = format.format( new Date() );        }        catch (RuntimeException e)        {            date = "ERROR: formatting date";        }        return date;    }    //------------------------------------------------------------------------    /**     * Returns most recent update time of collection of weblog entries using     * the specified pattern.     * @param weblogEntries Collection of weblog entries.     * @param Date format pattern, @see java.text.SimpleDateFormat.     * @return Most recent update time formatted by pattern.     */    public String formatUpdateTime( ArrayList weblogEntries, String pattern )    {        String date = null;        Date updateTime = getUpdateTime(weblogEntries);        try        {            SimpleDateFormat format = new SimpleDateFormat( pattern );            date = format.format( updateTime );        }        catch (RuntimeException e)        {            date = "ERROR: formatting date";        }        return date;    }       //------------------------------------------------------------------------    /**     * Returns most recent update time of collection of weblog entries.     * @param weblogEntries Collection of weblog entries.     * @return Most recent update time.     */    public Date getUpdateTime( ArrayList weblogEntries )    {        return PageModel.getUpdateTime( weblogEntries );    }       //------------------------------------------------------------------------    /**     * Version number of Roller.     * @return Version number of Roller.     */    public String showVersion()    {        ServletContext ctx = mPageContext.getServletContext();        return ctx.getInitParameter( RollerContext.VERSION_KEY );    }    //------------------------------------------------------------------------    /**     * Title of your website.     * @return Title of your website.     */    public String showWebsiteTitle()    {        WebsiteData wd = null;        RollerRequest rreq = getRollerRequest();        try {            wd = rreq.getWebsite();        }        catch (Exception e) {            return "ERROR finding website in request: " + e.toString();        }        return wd.getName();    }    //------------------------------------------------------------------------    /**     * Website description.     * @return Website description.     */    public String showWebsiteDescription()    {        WebsiteData wd = null;        RollerRequest rreq = getRollerRequest();        try {            wd = rreq.getWebsite();        }        catch (Exception e) {            return "ERROR finding website in request: " + e.toString();        }        return wd.getDescription();    }    //------------------------------------------------------------------------    /**     * Show navigation links for pages that are not hidden.     * @param vertical Display links in a vertical column, separated by BR tags.     * @return HTML for navigation bar.     */    public String showNavBar( boolean vertical )    {        NavigationBarTag navTag = new NavigationBarTag();        navTag.setPageContext(mPageContext);        navTag.setVertical(vertical);        return navTag.emit();    }    //------------------------------------------------------------------------    /**     * Show navigation links for pages that are not hidden, separated by a     * specified delimeter.     * @param vertical Display links in a vertical column.     * @param delimeter Delimeter to separate links.     * @return HTML for navigation bar.     */    public String showNavBar( boolean vertical, String delimiter )    {        NavigationBarTag navTag = new NavigationBarTag();        navTag.setPageContext(mPageContext);        navTag.setVertical(vertical);        navTag.setDelimiter(delimiter);        return navTag.emit();    }    //------------------------------------------------------------------------    /**     * Show the Roller Editor menu as a navigation bar.     * specified delimeter.     * @param vertical Displaylinks in a vertical column.     * @return HTML for navigation bar.     * */    public String showEditorNavBar( boolean vertical )    {        EditorNavigationBarTag editorTag = new EditorNavigationBarTag();        editorTag.setPageContext(mPageContext);        if ( vertical )        {            editorTag.setView("/navbar-vertical.vm");        }        else        {            editorTag.setView("/navbar-horizontal.vm");        }        editorTag.setModel("editor-menu.xml");        return editorTag.emit();    }    //------------------------------------------------------------------------    /**     * Display bookmarks in specified folder using specified title.     * @param folderName Folder to be dislayed.     * @param title Title to be displayed.     * @return HTML for bookmarks display.     */    public String showBookmarks( String folderName, String title )    {        ViewBookmarksTag booksTag = new ViewBookmarksTag();        booksTag.setPageContext(mPageContext);        return booksTag.view( folderName, title );    }    /**     * Display bookmarks in specified folder using specified title.     * @param folderName Folder to be dislayed.     * @param showFolderName Display folder name as title.     * @return HTML for bookmarks display.     */    public String showBookmarks( String folderName, boolean showFolderName )    {        ViewBookmarksTag booksTag = new ViewBookmarksTag();        booksTag.setPageContext(mPageContext);        return booksTag.view( folderName, showFolderName );    }    /**     * Display bookmarks in specified folder as an expandable link.     * @param folderName Folder to be dislayed.     * @param showFolderName Display folder name as title.     * @param expandingFolder Show bookmarks in expanding folder.     * @return HTML and JavaScript for bookmarks display.     */    public String showBookmarks(        String folderName, boolean showFolderName, boolean expandingFolder )    {        ViewBookmarksTag booksTag = new ViewBookmarksTag();        booksTag.setPageContext(mPageContext);        return booksTag.view( folderName, showFolderName, expandingFolder );    }    //------------------------------------------------------------------------    /**     * Get {@link org.roller.pojos.UserData UserData} object.     * @see org.roller.pojos.UserData     * @return User object.     */    public UserData getUser()    {        try        {            return getRollerRequest().getUser();        }        catch (Exception e)        {            mLogger.error("Getting user",e);         }        return null;    }    //------------------------------------------------------------------------    /**     * Get       * {@link org.roller.presentation.users.WebsiteDataEx WebsiteDataEx}      * object.     * @see org.roller.pojos.WebsiteData     * @return Website object.     */    public WebsiteData getWebsite()    {        try        {            return getRollerRequest().getWebsite();        }        catch (Exception e)        {            mLogger.error("Getting website",e);         }        return null;    }    //------------------------------------------------------------------------    /**     * Show weblog enties using the day template specified in your site      * settings.     * @return HTML for weblog entries.     */        public String showWeblogEntries()    {        return showWeblogEntries(15);    }    //------------------------------------------------------------------------    /**     * Show up to 100 weblog enties using the day template specified in your site      * settings.     * @param maxEntries Maximum number of entries to display.     * @return HTML for weblog entries.     */        public String showWeblogEntries(int maxEntries)    {        String ret = null;        try        {            // protection from recursion            if ( mEntriesTLS.get() == null )            {                mEntriesTLS.set( new Integer(0) );            }            else            {                Integer countObj = (Integer)mEntriesTLS.get();                int count = countObj.intValue();                if ( count++ > MAX_RECURSION_DEPTH )                {                    return "ERROR: recursion level too deep";                }                mEntriesTLS.set( new Integer(count) );            }            ViewWeblogEntriesTag entriesTag = new ViewWeblogEntriesTag();            entriesTag.setPageContext(mPageContext);            entriesTag.setMaxEntries(maxEntries);            ret = entriesTag.emit();        }        finally        {            mEntriesTLS.set( null );        }        return ret;

⌨️ 快捷键说明

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