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

📄 portletspersistancemanager.java

📁 java 写的一个新闻发布系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            if (jData == null) {                jData = new JahiaData(jParams); /** @todo find a better lighter way ! */            }            PortletsJahiaContentSerializer jPortletSerializer =                new PortletsJahiaContentSerializer(jData, portletGroupName);            jPortletSerializer.storePortlet(thePortlet, theUserName);        }    } // end setPortlet    /**     * Delete a Portlet from the storage area     *     */    public void delPortlet(ParamBean jParams,                           JahiaData jData,                           JahiaContainer container,                           int theJahiaEventPageID, String theJahiaEventUserName,                           String uRLtoTemplatesDir) throws JahiaException {        if (personalizationActivated) {            String theFile = theJahiaEventUserName + ".xml";            String theDefaultFile = theDefaultUser + ".xml";            PortletsXMLSerializer XMLFile = new PortletsXMLSerializer(uRLtoTemplatesDir,                                                                      theFile,                                                                      theDefaultFile,                                                                      theJahiaEventPageID);            XMLFile.deletePortlet(container.getID());        } else {            if (jData == null) {                jData = new JahiaData(jParams); /** @todo find a better lighter way ! */            }            JahiaContainerDefinition containerDef = container.getDefinition();            String portletGroupName = containerDef.getName();            PortletsJahiaContentSerializer jPortletSerializer =                new PortletsJahiaContentSerializer(jData, portletGroupName);            jPortletSerializer.removePortlet(new PortletBean(container.getID()),                                             theJahiaEventUserName);        }    } // end delPortlet    /**     * Add new portlet group (add new page)     *     * @author J閞鬽e B閐at     *     */    public void addPortletGroup(ParamBean jParams,                                int theJahiaEventObjectID,                                String theJahiaEventUserName,                                String uRLtoTemplatesDir) throws JahiaException {        if (personalizationActivated) {            String theFile = theJahiaEventUserName + ".xml";            String theDefaultFile = theDefaultUser + ".xml";            PortletsXMLSerializer XMLFile = new PortletsXMLSerializer(uRLtoTemplatesDir,                                                                      theFile,                                                                      theDefaultFile,                                                                      theJahiaEventObjectID);            XMLFile.addPortletGroup(theJahiaEventObjectID);        }    } // end addPortletGroup    /**     * Retrieves a column count for the specified page     *     * @author J閞鬽e B閐at     *     */    /*    public int getPortletsColumnCount(int thePageID, String theUserName,                                      String uRLtoTemplatesDir) throws JahiaException {        String theFile = theUserName + ".xml";        String theDefaultFile = theDefaultUser + ".xml";        PortletsXMLSerializer XMLFile = new PortletsXMLSerializer(uRLtoTemplatesDir,                                                                  theFile,                                                                  theDefaultFile,                                                                  thePageID);        theColumnCount = XMLFile.getColumnCount();        return theColumnCount;    } // end getPortletsColumnCount    */    /**     * Copy the Portlet Group from the specified user XML file to the other users files     *     * @author J閞鬽e B閐at     *     */     /*    public void copyPortletGroup(int thePageID, String theUserName,                                 String uRLtoTemplatesDir) {        try {            String theFile = theUserName + ".xml";            String theDefaultFile = theDefaultUser + ".xml";            PortletsXMLSerializer XMLFile = new PortletsXMLSerializer(uRLtoTemplatesDir, theFile, theDefaultFile, thePageID);            File   portletsAPIPathDir  = new File( uRLtoTemplatesDir + File.separator + "portlets_api" + File.separator );            File[] portletsAPIFileList = portletsAPIPathDir.listFiles();            Vector sourceIDList = XMLFile.copyXMLPortletGroup(uRLtoTemplatesDir + File.separator + "portlets_api" + File.separator + theDefaultFile);            for(int i=0; i<portletsAPIFileList.length; i++) {                if (!portletsAPIFileList[i].getAbsolutePath().equals(uRLtoTemplatesDir + File.separator + "portlets_api" + File.separator + theFile) && !portletsAPIFileList[i].getAbsolutePath().equals(uRLtoTemplatesDir + File.separator + "portlets_api" + File.separator + theDefaultFile)) {                    XMLFile.copyXMLPortletGroup(portletsAPIFileList[i].getAbsolutePath());                }            }            unassignRightsToPortlets (sourceIDList);        } catch (JahiaException e) {            JahiaConsole.println( "PortletsBean -> copyPortletGroup", e.toString() );        }    } // end copyPortletGroup*/    /**     * Load a Skin from the DataBase     *     * @author J閞鬽e B閐at     *     */    public SkinBean loadSkin(String theType, int theID) {        try {            PortletWidgetsDBSerializer DB = PortletWidgetsDBSerializer.getInstance();            if (theType.equals("portlet")) {                theSkin = DB.load_portlet_skin(theID);            } else if (theType.equals("desktop")) {                theSkin = DB.load_desktop_skin(theID);            }            if (theSkin == null) {                theSkin = new SkinBean(1,"","");            }        } catch (JahiaException e) {            theSkin = new SkinBean(1,"","");            JahiaConsole.println( "PortletsPersistanceManager.loadSkin", e.toString() );        }        return theSkin;    } // end loadSkin    //-------------------------------------------------------------------------    private void unassignRightsToPortlets (ParamBean jParams, Vector containerIDs) {        // get the administrator group name.        String adminGroupName =                JahiaGroupManagerService.ADMINISTRATORS_GROUPNAME;        // get the administrator group object.        JahiaGroup adminGroup = ServicesRegistry.getInstance().                getJahiaGroupManagerService ().                lookupGroup (JahiaGroupManagerService.ADMINISTRATORS_GROUPNAME);        // get the administrator group object.        JahiaGroup usersGroup = ServicesRegistry.getInstance().                getJahiaGroupManagerService ().                lookupGroup (JahiaGroupManagerService.USERS_GROUPNAME);        // get the administrator group object.        JahiaGroup guestGroup = ServicesRegistry.getInstance().                getJahiaGroupManagerService ().                lookupGroup (JahiaGroupManagerService.GUEST_GROUPNAME);        // if the administrators group is not available .. just leave.        // ok ok .. it's a hack, but I'll fix this later.   (Fulco)        if (adminGroup == null) {            return;        }        // process all the fields to reset the rights.        for (int index = 0; index < containerIDs.size(); index++) {            try {                // get the field ID                int containerID = ((Integer)containerIDs.get (index)).intValue();                // Get the container reference holding the field.                JahiaContainer container = ServicesRegistry.getInstance().                        getJahiaContainersService().loadContainerInfo (containerID);                if (container != null) {                    // Get the ACL of the container                    try {                        JahiaBaseACL acl = new JahiaBaseACL (container.getAclID());                        if (acl != null) {                            // remove all the user who are not an                            // administrator for administrator users, keep                            // the existing entry.                            // get all the user entries.                            Vector usernames = acl.getUsernameList (null);                            if (usernames.size() > 0) {                                for (int i=0; i<usernames.size(); i++) {                                    String username = (String)usernames.get(i);                                    JahiaUser user = ServicesRegistry.                                            getInstance().                                            getJahiaUserManagerService().                                            lookupUser (username);                                    if ((user != null) &&                                        (!user.isMemberOfGroup (jParams.getSiteID(), adminGroupName)))                                    {                                        acl.removeUserEntry (user);                                    }                                }                            }                            // disable the access to the users and guest group                            JahiaACLEntry entry = new JahiaACLEntry (0, 0);                            entry.setPermission (JahiaBaseACL.READ_RIGHTS, JahiaACLEntry.ACL_YES);                            acl.setGroupEntry (usersGroup, entry);                            acl.setGroupEntry (guestGroup, entry);                            // set the new administration group rights                            JahiaACLEntry adminEntry = new JahiaACLEntry ();                            for (int i=0; i<acl.size(); i++) {                                adminEntry.setPermission (i, JahiaACLEntry.ACL_YES);                            }                            acl.setGroupEntry (adminGroup, adminEntry);                        }                    }                    catch (Throwable t) {                        // the ACL was not found .. go to the next field.                    }                }            }            catch (JahiaException ex) {                // go to the next field.            }        }    }    /**     * This method allows us to do a merge of two portlet lists and return the     * result of the merge.     * This isn't simply a concatenation of the elements of the first list with     * the ones from the second, instead it check the element of the first list     * if they allow parameter "inheritance" from the second. In effect, this     * is the stuff that's going on :     *  iteration through the first list     *      for each element of masterList do     *          check list two for same element     *          if present in both list then     *              if element of list one is blocked     *                  do nothing with element of list two (= reject it)     *              else     *                  merge the parameters, using the list two parameters     *                  as predominant and store the portlet in the result     *                  list     *              end if     *          else     *              insert the element in the result list     *          end if     *      end for     */    private Enumeration mergePortletLists( Enumeration masterList,                                           Enumeration slaveList )    throws JahiaException {        JahiaConsole.println("PortletsPersistanceManager.mergePortletLists", "Merging portlet lists....");        Hashtable resultList = new Hashtable();        if (masterList == null) {            return slaveList;        }        if (slaveList == null) {            return masterList;        }        // first we copy the master list into the hashtable        while (masterList.hasMoreElements()) {            Object curElement = masterList.nextElement();            if (!(curElement instanceof PortletBean)) {                throw new JahiaException("PortletManager.mergePortletLists",                                         "Master portlet list contains invalid objects !",                                         JahiaException.ERROR, JahiaException.ENGINE_ERROR);            }            PortletBean pb = (PortletBean) curElement;            resultList.put(new Integer(pb.getPortletSourceID()), pb);        }        // now let's merge, resolving conflicts as they arise        while (slaveList.hasMoreElements()) {            Object curElement = slaveList.nextElement();            if (!(curElement instanceof PortletBean)) {                throw new JahiaException("PortletManager.mergePortletLists",                                         "Slave portlet list contains invalid objects !",                                         JahiaException.ERROR, JahiaException.ENGINE_ERROR);            }            PortletBean pb = (PortletBean) curElement;            if (resultList.containsKey(new Integer(pb.getPortletSourceID()))) {                // found the portlet from the master list, let's resolve the                // conflict.                PortletBean masterPB = (PortletBean) resultList.get(new Integer(pb.getPortletSourceID()));                /** @todo for the moment we just ignore the slave data, we will                 *  work on implementing this in the next version of the layout                 *  system                 */            } else {                // the portlet isn't already in the list, let's simply add it                resultList.put(new Integer(pb.getPortletSourceID()), pb);            }        }        return resultList.elements();    }}

⌨️ 快捷键说明

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