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

📄 jahiacontainersbaseservice.java

📁 java 写的一个新闻发布系统
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
                {                    aField = (JahiaField) fList.nextElement();                    /*                    aField = ServicesRegistry.getInstance().                        getJahiaFieldService().loadField( aField.getID(), LoadFlags.ALL, jParams );                    */                    JahiaFieldDefinition theDef = aField.getDefinition();                    if ( theDef != null ){                        // create the ACL object...                        JahiaBaseACL newAcl = null;                        newAcl = new JahiaBaseACL ();                        newAcl.create(newList.getAclID());                        newList.setProperty("view_field_acl_"+theDef.getName(), String.valueOf(newAcl.getID()) );                    }                }                saveContainerListInfo(newList, parentAclID );                theContainer.setListID( newList.getID() );            }            // Start Create a new ACL object for the new container.            JahiaBaseACL acl = new JahiaBaseACL ();            if (acl != null) {                // let's load the parent ContainerList to get its ACL ID                JahiaContainerList tempList = loadContainerListInfo (theContainer.getListID());                int	clAclID = 0;                if (tempList!=null)                {                    clAclID = tempList.getAclID();                    toDebug (">Container herited ACL from the ContainerList, OK<");                }                tempList = null; // destroy the tempList.                // create a new object by specifying the parent ACL ID (a containerList)                if (!acl.create (clAclID)) {                    String message = "Could not create an ACL object for a new container.";                    JahiaConsole.println ("", message+" -> Stop container creation!");                    throw new JahiaException ("JahiaContainersBaseService", message,                            JahiaException.ACL_ERROR, JahiaException.CRITICAL);                } else {                    JahiaConsole.println ("JahiaContainersBaseService", "ACL ["+acl.getID()+"] has just been created! (Container)");                }            } else {                throw new JahiaException ("JahiaContainersBaseService", "Counld not instanciate the JahiaBaseACL class",                        JahiaException.ACL_ERROR, JahiaException.CRITICAL);            }            // End Create ACL            theContainer.setAclID(acl.getID());            // gets the new container id            int thectnid = ServicesRegistry.getInstance().getJahiaIncrementorsDBService().autoIncrement( "jahia_ctn_entries" );            theContainer.setID( thectnid );            JahiaContainer tmpContainer = (JahiaContainer)theContainer.clone();            c_containers.db_create_container( tmpContainer );            cacheContainers.setValue(tmpContainer, new Integer(theContainer.getID()));        } else {            // container already exists -> just need to update            JahiaContainer tmpContainer = (JahiaContainer)theContainer.clone();            c_containers.db_update_container( tmpContainer );            cacheContainers.setValue(tmpContainer, new Integer(theContainer.getID()));        }    } // end saveContainerInfo    /***        * saves the container info and fields        * saves the container info and fields, but not the dependant container lists        * if id=0, assigns a new id to container and creates it in datasource        * if listid=0, assigns a new listid to container and creates it in datasource        *        * @param        theContainer        a JahiaContainer object        * @see          org.jahia.data.containers.JahiaContainer        *        */    public void saveContainer(  JahiaContainer  theContainer,                                int             containerParentID,                                ParamBean       jParams )    throws JahiaException    {        // gets the parent acl ID        int parentAclID = 0;        int listID = theContainer.getListID();        // if the container is included in an existing list,        // just get the container list acl id        if (listID != 0) {            JahiaContainerList theList = this.loadContainerListInfo(listID);            if (theList != null) {                parentAclID = theList.getAclID();            }        }        // if parent acl id is still 0, then if the container is included in        // a parent container, just get the parent container acl id        if (parentAclID == 0) {            if (containerParentID != 0) {                JahiaContainer parentContainer = this.loadContainerInfo(containerParentID);                if (parentContainer != null) {                    parentAclID = parentContainer.getAclID();                }            }        }        // if parent acl id is still 0, then simply get the page acl id        if (parentAclID == 0) {            parentAclID = jParams.getPage().getAclID();        }        // end of getting parent acl id        // save the container list info        ServicesRegistry.getInstance().getJahiaContainersService().                    saveContainerInfo( theContainer, containerParentID, parentAclID, jParams );        // save fields, one by one        Enumeration fields = theContainer.getFields();        while (fields.hasMoreElements()) {            // gets the field            JahiaField containerField = (JahiaField) fields.nextElement();            // ensures that the field points to its including container            containerField.setctnid( theContainer.getID() );            // saves the field            ServicesRegistry.getInstance().getJahiaFieldService().                    saveField( containerField, theContainer.getAclID(), jParams );        }    } // end saveContainer    /***        * deletes the container info, fields and sublists        * deletes the container info, fields and sublists        *        * @param        ctnid         the container id        * @param        jParams             the request parameters        * @see          org.jahia.data.containers.JahiaContainer        *        */        // DJ 29.01.01 - added ACL check    public synchronized void deleteContainer( int ctnid, ParamBean jParams )    throws JahiaException    {        // loads container info        JahiaContainer theContainer = loadContainer( ctnid, LoadFlags.NOTHING );        // start check for correct rights.        if (jParams != null) {            JahiaUser   currentUser = jParams.getUser();            if (currentUser != null)            {                toDebug ("deleteContainer(): checking rights...");                // if the user has no write rights, exit method.                if (!theContainer.checkWriteAccess (currentUser))                {                    toDebug ("deleteContainer(): NO write rights! -> don't delete");                    return;                }                toDebug ("deleteContainer(): write rights OK");            } else {                throw new JahiaException ("No user present !",                    "No current user defined in the params in deleteContainer() method.",                    JahiaException.USER_ERROR, JahiaException.ERROR);            }        }        // end check rights.        // deletes container fields - even if no write rights in the fields        Enumeration theFields = theContainer.getFields();        while (theFields.hasMoreElements()) {            JahiaField theField = (JahiaField) theFields.nextElement();            ServicesRegistry.getInstance().getJahiaFieldService().deleteField( theField.getID(), jParams );        }        //deletes sub container lists - even if no write rights in the lists        Enumeration theLists = theContainer.getContainerLists();        while (theLists.hasMoreElements()) {            JahiaContainerList theContainerList = (JahiaContainerList) theLists.nextElement();            //System.out.println( "Deleting container list id " + theContainerList.getID() );            deleteContainerList( theContainerList.getID() );        }        // deletes ACL        try {            JahiaBaseACL theACL = new JahiaBaseACL (theContainer.getAclID());            theACL.delete ();        }        catch (ACLNotFoundException ex) {            JahiaException je = new JahiaException ("", "Could not find the ACL ["+Integer.toString (theContainer.getAclID())+                                "] while removing field ["+Integer.toString(ctnid)+"]",                                JahiaException.ACL_ERROR, JahiaException.WARNING);        }        // deletes container info        Integer containerParam = new Integer (theContainer.getID());        c_containers.db_delete_container( theContainer.getID() );        cacheContainers.removeValue(containerParam);    } // end deleteContainer    /***        * loads a container list info without its containers        * loads container list info, but not dependant fields and container lists        * no rights check.        *        * @param        containerListID     the container list id        * @see          org.jahia.data.containers.JahiaContainerList        *        */    public JahiaContainerList loadContainerListInfo( int containerListID )    throws JahiaException    {        JahiaContainerList result = c_lists.db_load_container_list( containerListID );        if (result != null) {            Properties listProps = c_lists_props.getProperties(result.getID());            result.setProperties(listProps);        }        return result;    } // end loadContainerListInfo    /***        * loads a container list        * loads container list info and containers, but not dependant container lists        * this method cannot load request-specific values (i.e. applications);        * see the loadContainerList( containerListID, loadFlag, jParams) for that.        *        * DO NOT CACHE THIS METHOD (it depends on other caches values) !!        *        * @param        containerListID     the container list id        * @param        loadFlag            the loadFlag        * @see          org.jahia.data.containers.JahiaContainerList        * @see          org.jahia.data.fields.LoadFlags        *        */    public JahiaContainerList loadContainerList( int containerListID, int loadFlag )    throws JahiaException    {        return loadContainerList( containerListID, loadFlag, null );    } // end loadContainerList    /**     * loads a container list     * loads container list info and containers, but not dependant container lists     * this method can load request-specific values (i.e. applications).     *     * DO NOT CACHE THIS METHOD (it depends on other caches values) !!     *     * @param        containerListID     the container list id     * @param        loadFlag            the loadFlag     * @param        jParams             the ParamBean object, containing request and response     * @see          org.jahia.data.containers.JahiaContainerList     * @see          org.jahia.data.fields.LoadFlags     *     */    // DJ 29.01.01 - added ACL rights    // SH 19.01.02 - added Scrollable container support    public JahiaContainerList loadContainerList( int containerListID,                                                 int loadFlag,                                                 ParamBean jParams )    throws JahiaException {        return loadContainerList(containerListID, loadFlag, jParams, new Hashtable());    }    public JahiaContainerList loadContainerList( int containerListID,                                                 int loadFlag,                                                 ParamBean jParams, Hashtable cachedFieldsInContainer )    throws JahiaException    {        JahiaConsole.println("JahiaContainersBaseService.loadContainerList : ", "Starting...[" + containerListID + "]");        Vector ctnids = getctnidsInList( containerListID );        return loadContainerList(containerListID,ctnids,loadFlag,jParams,cachedFieldsInContainer);    } // end loadContainerList    /**     * Loads a set of containers for a given container list     * Loads container list info and containers, but not dependant container lists     * this method can load request-specific values (i.e. applications).     *     * DO NOT CACHE THIS METHOD (it depends on other caches values) !!     *     * @param        containerListID     the container list id     * @param        Vector     		 ctnids, vector of container ids to load.     * @param        loadFlag            the loadFlag     * @param        jParams             the ParamBean object, containing request and response     * @see          org.jahia.data.containers.JahiaContainerList     * @see          org.jahia.data.fields.LoadFlags     * @author		 NK     *     */    public JahiaContainerList loadContainerList( int containerListID,                                                 Vector ctnids,                                                 int loadFlag,                                                 ParamBean jParams,                                                 Hashtable cachedFieldsInContainer )    throws JahiaException    {        JahiaConsole.println("JahiaContainersBaseService.loadContainerList(Vector ctnids)", "Starting for ctnlist [" + containerListID + "]");        // loads container list info        JahiaContainerList theContainerList = loadContainerListInfo( containerListID );        if (theContainerList == null) {            throw new JahiaException ("Error while loading content",                 "JahiaContainersBaseService.loadContainerList> couldn't find container list ID " +                 Integer.toString(containerListID) + " in database",                 JahiaException.USER_ERROR, JahiaException.ERROR);        }        // start check for correct rights.        if (jParams!=null) 			// no jParams, can't check for rights        {            JahiaUser   currentUser = jParams.getUser();            if (currentUser != null)            {                toDebug ("loadContainerList(): checking rights...");                // if the user has no read rights, return an empty list.                if (!theContainerList.checkReadAccess (currentUser,jParams.getSiteID()))                {                    toDebug ("loadContainerList(): NO read rights! -> returning empty list");                    theContainerList.setIsContainersLoaded(true);                    return theContainerList;                }                toDebug ("loadContainerList(): read rights OK");            } else {                throw new JahiaException ("No user present !",                     "No current user defined in the params in loadContainerList() method.",                     JahiaException.USER_ERROR, JahiaException.ERROR);            }			// Check container ACL access.			if ( ctnids.size()>0 )			{				Hashtable acls = c_utils.db_get_all_containers_aclid(containerListID);				Vector v = new Vector();				int size = ctnids.size();				Integer ctnID = null;				Integer aclID = null;				for ( int i=0 ; i<size ; i++ )				{					try {						ctnID = (Integer)ctnids.get(i);						aclID = (Integer)acls.get(ctnID);						JahiaBaseACL acl = new JahiaBaseACL(aclID.intValue());						if ( acl != null && acl.getPermission(currentUser,JahiaBaseACL.READ_RIGHTS,jParams.getSiteID()) )						{							v.add(ctnID);						}					} catch ( Throwable t ) {						t.printStackTrace();					}				}				ctnids = v;			}        }        // lets set the full size of the data for the container list.        theContainerList.setFullSize(ctnids.size());		// init the container list pagination		JahiaContainerListPagination cListPagination = new JahiaContainerListPagination(theContainerList,jParams,-1);		theContainerList.setCtnListPagination(cListPagination);        int startPos = 0;        int endPos = cListPagination.getSize();        if ( cListPagination.isValid() ){            startPos = cListPagination.getFirstItemIndex();            endPos = cListPagination.getLastItemIndex();        }		if ( endPos<cListPagination.getSize() ){			endPos +=1 ;		}        JahiaContainer thisContainer;        for (int i=startPos; i < endPos; i++) {

⌨️ 快捷键说明

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