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

📄 jahiacontainersbaseservice.java

📁 java 写的一个新闻发布系统
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
////                                   ____.//                       __/\ ______|    |__/\.     _______//            __   .____|    |       \   |    +----+       \//    _______|  /--|    |    |    -   \  _    |    :    -   \_________//   \\______: :---|    :    :           |    :    |         \________>//           |__\---\_____________:______:    :____|____:_____\//                                      /_____|////                 . . . i n   j a h i a   w e   t r u s t . . .////  EV  07.01.01package org.jahia.services.containers;import org.jahia.bin.*;           	// Jahiaimport org.jahia.data.*;            // JahiaDataimport org.jahia.data.search.*;import org.jahia.data.cache.*;      // JahiaCacheimport org.jahia.data.containers.*; // JahiaContainersimport org.jahia.data.fields.*;     // JahiaFieldimport org.jahia.exceptions.*;import org.jahia.params.*;          // ParamBeanimport org.jahia.registries.*;      // ServicesRegistryimport org.jahia.services.acl.*;import org.jahia.services.cache.*;  // JahiaCacheFactoryimport org.jahia.services.pages.*;import org.jahia.services.search.*;  // JahiaUserimport org.jahia.services.usermanager.*;import org.jahia.settings.*;        // SettingsBeanimport org.jahia.utils.*;           // JahiaConsoleimport org.jahia.utils.properties.*;            // PropertiesManagerimport java.io.*;                     	// Fileimport java.sql.*;import java.util.*;                     // Vectorpublic class JahiaContainersBaseService extends JahiaContainersService {    private static JahiaContainersBaseService   theObject = null;    private static SettingsBean             jSettings;    private JahiaContainerUtilsDB       c_utils;    private JahiaContainersDB           c_containers;    private JahiaContainerListsDB       c_lists;    private JahiaContainerListPropDB    c_lists_props;    private JahiaContainerDefinitionsDB c_defs;    private JahiaContainerDefPropDB     c_defs_props;    private JahiaContainersLogic        c_logic;    private JahiaContainerStructuresDB  c_struct;    private static JahiaSimpleCache         cacheContainers;    private static int                      MAX_CACHED_OBJECTS = 2000;    /***        * constructor        * EV    26.12.2000        *        */    protected JahiaContainersBaseService()    {        JahiaConsole.println( "JahiaContainersBaseService",                              "***** Starting up Containers Services *****" );    } // end constructor   /***        * inits the service cache and settings        *        * @param        jSettings           Settings to let the sevice where to save files, i.e.        *        */    public void init( JahiaPrivateSettings jSettings )    {        this.jSettings = new SettingsBean( jSettings );        c_utils         = new JahiaContainerUtilsDB();        c_containers    = new JahiaContainersDB();        c_lists         = new JahiaContainerListsDB();        c_lists_props   = new JahiaContainerListPropDB();        c_defs          = new JahiaContainerDefinitionsDB();        c_defs_props    = new JahiaContainerDefPropDB();        c_logic         = new JahiaContainersLogic();        c_struct		= new JahiaContainerStructuresDB();        //patchCtnDefs();        cacheContainers = JahiaCacheFactory.getInstance().                                createJahiaSimpleCache("ContainerCache",                                                 "Caches the jahia Container entries from the DB",                                                 MAX_CACHED_OBJECTS);    } // end init    /**     * Returns a singleton object for the service instance. This method is     * synchronized.     *     * @author EV    26.12.2000     * @returns the singleton object.     *     */    public static synchronized JahiaContainersBaseService getInstance()    {        if (theObject == null) {            theObject = new JahiaContainersBaseService();        }        return theObject;    } // end getInstance    //-------------------------------------------------------------------------------    /**     * Create a clone of the container list and all its contents (containers)     *     * @param   cListID         The containerList to clone     * @param   newPageID       The Id of the new page to which the cloned containerList must     *                          belong to.     * @param   parentEntryID   The id of the container which contains this containerList     *                          egal 0, if the containerList is in a page.     */     public synchronized void cloneContainerList(int cListID, int newPageID,                                                 int parentAclID,                                                 boolean childrenCloned)     throws JahiaException     {        JahiaContainerList clonedCList = cloneContainerList(cListID, newPageID,                                                            0, parentAclID,                                                            childrenCloned);     }    //-------------------------------------------------------------------------------    /**     * Create a clone of the container list and all its contents (containers)     *     * @param   cListID         The containerList to clone     * @param   newPageID       The Id of the new page to which the cloned containerList must     *                          belong to.     * @param   parentEntryID   The id of the container which contains this containerList     *                          egal 0, if the containerList is in a page.     */     public synchronized JahiaContainerList cloneContainerList(int cListID,                                                               int newPageID,                                                               int parentEntryID,                                                               int parentAclID,                                                               boolean childrenCloned)     throws JahiaException     {        //get list object        int loadFlag = LoadFlags.ALL;        JahiaContainerList theList = loadContainerList( cListID, loadFlag, null );        if (theList == null)        {            throw new JahiaException ("Could not clone container list.",                "Could not load the JahiaContainerList object.",                JahiaException.PAGE_ERROR, JahiaException.CRITICAL);        }        // All the ContainerList of the page are cloned        // the containerList in a container too        // set the parentEntryID of the clone to be not equal to 0        // if the containerList to clone has a parentEntryId !=0        // the parentEntryID of the clone will be set in        // cloneContainer method.        int parentEntryID2 = theList.getParentEntryID();        if (parentEntryID2 != 0 && parentEntryID == 0)        {            parentEntryID = parentEntryID2;        }        // clone acl        int aclID = theList.getAclID();        JahiaBaseACL aclObj = new JahiaBaseACL(aclID);        if (aclObj == null)        {            throw new JahiaException ("Could not clone container list.",                "Could not get JahiaBaseACL object.",                JahiaException.PAGE_ERROR, JahiaException.CRITICAL);        }        JahiaBaseACL clonedACL = (JahiaBaseACL)aclObj.clone();        if (clonedACL == null)        {            throw new JahiaException ("Could not clone container list.",                "Could not clone acl.",                JahiaException.PAGE_ERROR, JahiaException.CRITICAL);        }        clonedACL.setParentID(parentAclID);        int cListAclID = clonedACL.getID();        //clone containerList        JahiaContainerList clonedList = new JahiaContainerList(0,parentEntryID, newPageID,                                         theList.getctndefid(), clonedACL.getID());        if (clonedList == null)        {            throw new JahiaException ("Could not clone container list.",                "Could not instanciate a new JahiaContainerList object.",                JahiaException.PAGE_ERROR, JahiaException.CRITICAL);        }        // gets a new field id        int theListID = ServicesRegistry.getInstance().getJahiaIncrementorsDBService().autoIncrement( "jahia_ctn_lists" );        if (theListID != 0)        {            clonedList.setID( theListID );        }        // save containerList in database        c_lists.db_create_container_list2(clonedList);        // clone containers into the containerList        JahiaContainer clonedContainer = null;        for (Enumeration e = theList.getContainers(); e.hasMoreElements();)        {            clonedContainer = cloneContainer((JahiaContainer)e.nextElement(), clonedList.getID(), newPageID, cListAclID, childrenCloned);            if (clonedContainer != null)            {                clonedList.addContainer(clonedContainer);            }        }        return clonedList;     }     //-------------------------------------------------------------------------------    /**     * Create a clone of the container and all its contents (fields and containerList)     *     * @param   theContainer    The container to clone     * @param   newPageID       The Id of the new page to which the cloned containerList must     *                          belong to.     * @param   newCListID      The id of the container list which contains this container.     *     */     public synchronized JahiaContainer cloneContainer(JahiaContainer theContainer, int newCListID, int newPageID, int parentAclID, boolean childrenCloned)     throws JahiaException     {        // get the container object        int loadFlag = LoadFlags.ALL;        theContainer = loadContainer( theContainer.getID(), loadFlag, null );        if (theContainer == null)        {            throw new JahiaException ("Could not clone container.",                "Could not load the JahiaContainer object.",                JahiaException.PAGE_ERROR, JahiaException.CRITICAL);        }        //cloneACl        int aclID = theContainer.getAclID();        JahiaBaseACL aclObj = new JahiaBaseACL(aclID);        if (aclObj == null)        {            throw new JahiaException ("Could not clone container.",                "Could not get JahiaBaseACL object.",                JahiaException.PAGE_ERROR, JahiaException.CRITICAL);        }        JahiaBaseACL clonedACL = (JahiaBaseACL)aclObj.clone();        if (clonedACL == null)        {            throw new JahiaException ("Could not clone container.",                "Could not clone acl.",                JahiaException.PAGE_ERROR, JahiaException.CRITICAL);        }        clonedACL.setParentID(parentAclID);        int containerAclID = clonedACL.getID();        //clone container        JahiaContainer clonedContainer = new JahiaContainer (0, theContainer.getJahiaID(),                                         newPageID, newCListID, theContainer.getRank(),                                         clonedACL.getID(), theContainer.getctndefid());        if (clonedContainer == null)        {            throw new JahiaException ("Could not clone container.",                "Could not instanciate a new JahiaContainer object.",                JahiaException.PAGE_ERROR, JahiaException.CRITICAL);        }        // gets the new container id        int newctnid = ServicesRegistry.getInstance().getJahiaIncrementorsDBService().autoIncrement( "jahia_ctn_entries" );        if (newctnid != 0)        {            clonedContainer.setID(newctnid);        }        //clone fields into container        JahiaField clonedField = null;        for (Enumeration e = theContainer.getFields(); e.hasMoreElements();)        {            clonedField = ServicesRegistry.getInstance().getJahiaFieldService().cloneField(                        (JahiaField)e.nextElement(), clonedContainer.getID(), newPageID, containerAclID, childrenCloned);            if (clonedField == null)            {                throw new JahiaException ("Could not clone container.",                    "Could not clone a field.",                   JahiaException.PAGE_ERROR, JahiaException.CRITICAL);            }            clonedContainer.addField(clonedField);        }        // clone container lists into container        // Already done, because all the container list of the page are cloned !        // set the parentEntryID of the containerList        int pageID = theContainer.getPageID();        JahiaPage page = ServicesRegistry.getInstance().getJahiaPageService().lookupPage(pageID);        if (page != null)        {            Vector cListIDs = getContainerListIDsInPage( page );            int cListID;            for (int i=0; i < cListIDs.size(); i++) {               cListID = ((Integer)cListIDs.elementAt(i)).intValue();               JahiaContainerList cList = loadContainerListInfo(cListID);               if (cList != null)               {                // The cloned containerList is already associated with the clonedPage                // the cloned containerList has the same parentEntryID as the containerList to clone                // then set the parentEntryID.                if ( cList.getParentEntryID() == theContainer.getID() && cList.getPageID() == newPageID)                {                    cList.setParentEntryID(newctnid);                    c_lists.db_update_container_list( cList );                }               }           }        }        //save container in DB        c_containers.db_create_container(clonedContainer);        return clonedContainer;     }    /***        * builds the complete container structure for a specific page        * builds the complete container structure        * (containerlists->containers->fields/containerlists)        * for a specific page        *        * DO NOT CACHE THIS METHOD (it depends on other caches values) !!        *        * @param        pageID          the page id        * @param        jData           JahiaData        * @return       a Vector of containerlist IDs        *        */    public JahiaContainerSet buildContainerStructureForPage( JahiaData jData )    throws JahiaException    {        // cache all Containers at the load of each page... it takes a little        // time when the containers are already cached, but it's worth it        // when they're not into cache!        Vector allContainers = c_containers.db_load_all_containers_info_from_page(jData.params().getPageID());        for (int i=0; i<allContainers.size(); i++)        {            JahiaContainer cachedContainer = (JahiaContainer)allContainers.elementAt(i);            cacheContainers.setValue (cachedContainer.clone(), new Integer(cachedContainer.getID()));

⌨️ 快捷键说明

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