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

📄 jahiatreeviewservice.java

📁 java 写的一个新闻发布系统
💻 JAVA
字号:
// $Id: JahiaTreeViewService.java,v 1.4 2002/11/27 16:54:19 shuber Exp $//////                                   ____.//                       __/\ ______|    |__/\.     _______//            __   .____|    |       \   |    +----+       \//    _______|  /--|    |    |    -   \  _    |    :    -   \_________//   \\______: :---|    :    :           |    :    |         \________>//           |__\---\_____________:______:    :____|____:_____\//                                      /_____|////                 . . . i n   j a h i a   w e   t r u s t . . .//package org.jahia.services.pages;import java.util.Vector;import java.util.Enumeration;import org.jahia.registries.ServicesRegistry;import org.jahia.params.ParamBean;import org.jahia.exceptions.JahiaException;import org.jahia.services.JahiaService;import org.jahia.utils.JahiaConsole;import org.jahia.tools.tree.*;               // GenericTree, Node/** * This class provides basic functionnality for generating and expanding * <code>com.mycomponents.tools.tree.GenericTree</code> objects controlling a display * structure of JahiaPage objects. * * Copyright:    Copyright (c) 2002 * Company:      Jahia Ltd * * @author  Mikha雔 Janson * @version 1.0 */public class JahiaTreeViewService extends JahiaService{    private static JahiaTreeViewService mObject = null;    private JahiaPageService mPageService = null;    private GenericTree      mTopTree     = null;    //-------------------------------------------------------------------------    /**     * constructor     */    protected JahiaTreeViewService ()        throws JahiaException    {        JahiaConsole.println ("JahiaTreeViewService", "***** Starting up the Jahia Tree View Service *****");        setServiceName ("JahiaTreeViewService");        mPageService = ServicesRegistry.getInstance().getJahiaPageService();        if (mPageService == null) {            throw new JahiaException ("Page error",                                      "Could not get the page templates service instance.",                                      JahiaException.PAGE_ERROR,                                      JahiaException.CRITICAL);        }    }    /***        * Returns the single instance of this object        *        * @return   an instance of the TreeView service        */    public static synchronized JahiaTreeViewService getInstance()        throws JahiaException    {        if (mObject == null) {            mObject = new JahiaTreeViewService();        }        return mObject;    } // end getInstance    /***        * This method should be called to build an initial GenericTree        * suitable for JSP processing into a tree view.        * The tree will contain references to the page identified by        * <code>originPageID</code> and to all its direct subpages up to        * the specified number of levels        * Each page is embedded in a wrapper defining how to display        * the branch it controls (expanded / collapsed / terminal)        *        * @param        originPageID        the ID of the page which will be at the origin        *                                   of the tree        * @param        levels              the number of sublevels to feed to the tree        * @params       jParams             the ParamBean object        * @return                           a GenericTree object controlling a display structure        *                                   of JahiaPage objects        * @see #buildTree(int, int, int, ParamBean)        *        */    public GenericTree buildTree( int originPageID, int levels, ParamBean jParams )    throws JahiaException    {            return extendTree(originPageID, null, PageLoadFlags.DIRECT, levels, jParams);    } // end buildGenericTree (int, int, ParamBean)    /***        * This method should be called to build an initial GenericTree.        * suitable for JSP processing into a tree view.        * The tree will contain references to the page identified by        * <code>originPageID</code> and to all its subpages up to the        * specified number of levels        * Pages are filtered by types (direct reference / internal link        * / external link) according to the <code>loadFlags</code>        * Each page is embedded in a wrapper defining how to display        * the branch it controls (expanded / collapsed / terminal)        *        * @param        originPageID        the ID of the page which will be at the origin        *                                   of the tree        * @param        loadFlags           which page types to load        *                                   (see {@link org.jahia.services.pages.PageLoadFlags})        * @param        levels              the number of sublevels to feed to the tree        * @params       jParams             the ParamBean object        * @return                           a GenericTree object controlling a display structure        *                                   of JahiaPage objects        */    public GenericTree buildTree( int originPageID, int loadFlags, int levels, ParamBean jParams )    throws JahiaException    {            return extendTree(originPageID, null, loadFlags, levels, jParams);    } // end buildGenericTree (int, int, int, ParamBean)    /***        * This method should be called to extend an existing GenericTree.        *        *        * @param        originPageID        the ID of the page in the tree to extend with its subpages        * @param        tree                A partially built output GenericTree; each loop appends a new set of children.        * @param        loadFlags           which page types to load        *                                   (see {@link org.jahia.services.pages.PageLoadFlags})        * @param        levels              the number of sublevels to feed to the tree        * @params       jParams             the ParamBean object        * @return                           the extended GenericTree object        */    public GenericTree extendTree( int originPageID, GenericTree tree, int loadFlags, int levels, ParamBean jParams )    throws JahiaException    {            // finds origin page            JahiaPage originPage = mPageService.lookupPage(originPageID,jParams);            if (originPage != null) {                JahiaTreeViewPageWrapper originPageWrapper = new JahiaTreeViewPageWrapper(originPage);                if (tree == null) {                    Node     originPageNode = new Node(originPageWrapper, originPageWrapper.getID());                    mTopTree                = new GenericTree(originPageNode);                } else {                    mTopTree = tree;                }                extendTree(originPageWrapper, mTopTree, jParams, loadFlags, levels);            }            return mTopTree;    } // end extendTree (int, GenericTree, int, int, ParamBean)    /***        * recursive utility method to construct a GenericTree suitable for JSP processing into a tree view,        *        * @see          com.mycomponents.tools.tree.GenericTree        * @param        originPageWrapper   a <code>JahiaTreeViewPageWrapper</code> around the page where to start recursion from.        * @param        tree                A partially built output GenericTree; each loop appends a new set of children.        * @params       jParams             the ParamBean object        * @param        loadFlags           which page types to load        *                                   (see {@link org.jahia.services.pages.PageLoadFlags})        * @param        levels              the number of sublevels to feed to the tree        *        */    private void extendTree( JahiaTreeViewPageWrapper originPageWrapper, GenericTree tree, ParamBean jParams, int loadFlags, int levels )    throws JahiaException    {        // get list of subpages        Vector subPages = mPageService.getPageChilds (originPageWrapper.getID(), loadFlags, jParams);        if ((subPages != null) && (subPages.size() > 0)) {            if (levels == 1) {                originPageWrapper.collapse();            } else {                originPageWrapper.expand();                for(int i=0; i<subPages.size(); i++) {                    JahiaPage subPage = (JahiaPage) subPages.elementAt(i);                    if(subPage != null) {                        JahiaTreeViewPageWrapper pageWrapper = new JahiaTreeViewPageWrapper(subPage);                        tree.addNode(new Node(pageWrapper, pageWrapper.getID()),                                     originPageWrapper.getID(),                                     "org.jahia.services.pages.JahiaTreeViewPageWrapper");                        if (levels >= 0) {                            int nextLevels = levels - 1;                            extendTree(pageWrapper, tree, jParams, loadFlags, nextLevels);                        }                    }                }            }        }    } // end extendTree (JahiaTreeViewPageWrapper, GenericTree, ParamBean, int, int)}

⌨️ 快捷键说明

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