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

📄 portletspersistancemanager.java

📁 java 写的一个新闻发布系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
////                                   ____.//                       __/\ ______|    |__/\.     _______//            __   .____|    |       \   |    +----+       \//    _______|  /--|    |    |    -   \  _    |    :    -   \_________//   \\______: :---|    :    :           |    :    |         \________>//           |__\---\_____________:______:    :____|____:_____\//                                      /_____|////                 . . . i n   j a h i a   w e   t r u s t . . .//package org.jahia.layout;import java.io.*;import java.util.*;import org.jahia.utils.*;               			// JahiaConsoleimport org.jahia.exceptions.JahiaException;         // Jahia Exceptionsimport org.jahia.data.containers.JahiaContainer;import org.jahia.data.containers.JahiaContainerDefinition;import org.jahia.services.containers.JahiaContainersService;import org.jahia.data.fields.JahiaField;import org.jahia.services.fields.JahiaFieldService;import org.jahia.services.acl.JahiaBaseACL;import org.jahia.services.acl.JahiaACLEntry;import org.jahia.services.usermanager.JahiaGroup;import org.jahia.services.usermanager.JahiaUser;import org.jahia.services.usermanager.JahiaGroupManagerService;import org.jahia.registries.ServicesRegistry;import org.jahia.params.ParamBean;import org.jahia.data.JahiaData;/** * This class offers operations available on portlet's storage. It is used as a * facade to regroup operations on two different serializer, one XML, and one * in JahiaContent (containers to be precise) * It is able to store the portlets metadata either in Jahia Containers or in * XML files, depending on the degree of personalization desired (shared vs * personal portlets). This is why the getInstance method takes a parameters, in * order to retrieve two different singleton objects that offer a purely shared * or personalized portlet manager instance. * * @author Serge Huber */public class PortletsPersistanceManager {    private static PortletsPersistanceManager sharingManager = null;    private static PortletsPersistanceManager personalizationManager = null;    private static String theDefaultUser = "guest";    private DesktopBean  theDesktop;    private PortletBean  thePortlet;    private SkinBean     theSkin;    private Enumeration thePortletList;    private int         theColumnCount;    private boolean personalizationActivated = false; // the personalization mode    // represents a mode where each user can have a different set of portlets    // on a single page. This is achieved through the use of container entries,    // whose reference is retrieved from the XML serializer, allowing us to    // store this data for each user (one XML file per user)    /**     * Constructor, private because of singleton pattern     * @param personalizationActivated this boolean allows us to build seperate     * manager instance depending on whether we want the personalization features     * to be active or not     */    private PortletsPersistanceManager(boolean personalizationActivated)    {        this.personalizationActivated = personalizationActivated;        JahiaConsole.println( "PortletsPersistanceManager", "***** Starting the Portlets Persistance Manager *****" );    }    /**     * Retrieves an instance of the PortletsPersistanceManager according to the personalization     * mode setting.     *     * @param personalizationActivated specifies whether we want to retrieve     * the singleton that uses the personalization features or not.     *     * @returns the singleton PortletsPersistanceManager object according to the setting     * of the boolean specifying the personalization mode     */    public static synchronized PortletsPersistanceManager getInstance(boolean personalizationActivatedMode)    {        if (personalizationActivatedMode) {            if (personalizationManager == null) {                personalizationManager =                    new PortletsPersistanceManager(personalizationActivatedMode);            }            return personalizationManager;        } else {            if (sharingManager == null) {                sharingManager = new PortletsPersistanceManager(personalizationActivatedMode);            }            return sharingManager;        }    } // end getInstance    /**     * Retrieves a list of portlets for the specified page and the specified     * portlet group name on the page     *     * @param jParams ParamBean used to access jahia content data that store     * the portlet parameters in containers     * @param pageID the current JahiaPageID, ie the page on which the portlet     * layout system is present     * @param portletGroupName the name of the portlet group, as they may be     * multiple portlet groups per page     * @param theUserName the name of the currently logged in user     * @param uRLtoTemplatesDir the directory in which the personalized XML files     * are stored     *     * @returns an Enumeration containing objects of type PortletBean     */    public Enumeration getPortlets(ParamBean jParams,                                   JahiaData jData,                                   int pageID,                                   String portletGroupName,                                   String theUserName,                                   String uRLtoTemplatesDir) {        Enumeration personalPortletList = null;        Enumeration sharedPortletList = null;        try {            String theFile = theUserName + ".xml";            String theDefaultFile = theDefaultUser + ".xml";            if (jData == null) {               jData = new JahiaData(jParams); /** @todo find a lighter way to do this */            }            PortletsJahiaContentSerializer contentPortletSerializer =                new PortletsJahiaContentSerializer(jData, portletGroupName);            sharedPortletList = contentPortletSerializer.getPortlets(theUserName);            if (personalizationActivated) {                PortletsXMLSerializer XMLFile = new PortletsXMLSerializer(uRLtoTemplatesDir,                                                                          theFile,                                                                          theDefaultFile,                                                                          pageID,                                                                          portletGroupName);                personalPortletList = XMLFile.getPortlets();            }        } catch (JahiaException e) {            StringWriter strWriter = new StringWriter();            PrintWriter ptrWriter = new PrintWriter(strWriter);            e.printStackTrace(ptrWriter);            JahiaConsole.println( "PortletsPersistanceManager.getPortlets", strWriter.toString() );        }        try {            thePortletList = mergePortletLists(sharedPortletList, personalPortletList);        } catch (Throwable t) {            StringWriter strWriter = new StringWriter();            PrintWriter ptrWriter = new PrintWriter(strWriter);            t.printStackTrace(ptrWriter);            JahiaConsole.println("PortletsPersistanceManager",                                 "Exception generated -> " + strWriter.toString());        }        return thePortletList;    } // end getPortlets    /**     * Retrieves a list of portlets for the specified page and column     *     * @param jParams ParamBean object used to create JahiaData object to     * access page containers and access to portlet metadata stored in there     * @param theColumn the column number for which to retrieve the portlet     * list     * @param portletGroupName the name of the portlet group which we are accessing.     * This is usefuly in the case of multiple portlet sets on a single page.     * @param theUserName the current user name     * @param uRLtoTemplatesDir the explicit URL to the templates directory, where     * the XML files are stored.     *     * @returns an Enumeration of PortletBean objects     */    public Enumeration getPortletsFromColumn(ParamBean jParams,                                             JahiaData jData,                                             int theColumn,                                             String portletGroupName,                                             String theUserName,                                             String uRLtoTemplatesDir) {        try {            if (jData == null) {               jData = new JahiaData(jParams); /** @todo find a lighter way to do this */            }            PortletsJahiaContentSerializer jPortletSerializer=                new PortletsJahiaContentSerializer(jData, portletGroupName);            /** @todo JahiaContent version missing here !! */            if (personalizationActivated) {                String theFile = theUserName + ".xml";                String theDefaultFile = theDefaultUser + ".xml";                PortletsXMLSerializer XMLFile = new PortletsXMLSerializer(uRLtoTemplatesDir,                                                                          theFile,                                                                          theDefaultFile,                                                                          jParams.getPageID(),                                                                          portletGroupName);                thePortletList = XMLFile.getPortletsFromColumn(theColumn);            }        } catch (JahiaException e) {            StringWriter strWriter = new StringWriter();            PrintWriter ptrWriter = new PrintWriter(strWriter);            e.printStackTrace(ptrWriter);            JahiaConsole.println( "PortletsPersistanceManager.getPortletsFromColumn", strWriter.toString() );        }        return thePortletList;    } // end getPortletsFromColumn    /**     * Retrieves a portlet for the specified page and portletid     */    public PortletBean getPortlet(ParamBean jParams,                                  int thePortletID,                                  int thePageID,                                  String theUserName,                                  String uRLtoTemplatesDir) {        try {            if (personalizationActivated) {                String theFile = theUserName + ".xml";                String theDefaultFile = theDefaultUser + ".xml";                PortletsXMLSerializer XMLFile = new PortletsXMLSerializer(uRLtoTemplatesDir,                                                                          theFile,                                                                          theDefaultFile,                                                                          thePageID);                thePortlet = XMLFile.getPortlet(thePortletID);            }        } catch (JahiaException e) {            StringWriter strWriter = new StringWriter();            PrintWriter ptrWriter = new PrintWriter(strWriter);            e.printStackTrace(ptrWriter);            JahiaConsole.println( "PortletsPersistanceManager.getPortlet", strWriter.toString() );        }        return thePortlet;    } // end getPortletByID    /**     * Add new portlet in the specified page     *     * @author J閞鬽e B閐at     *     */    public void addPortlet(ParamBean jParams,                           JahiaData jData,                           JahiaContainer container,                           int theJahiaEventPageID, String theJahiaEventUserName,                           String uRLtoTemplatesDir)    throws JahiaException {        /**         * @todo still some problems here because all the portlets are created         * with a position of (0,0), therefore overlapping at rendering.         */        if (personalizationActivated) {            // this a personal portlet, let's store it in the XML serializer            String theFile = theJahiaEventUserName + ".xml";            String theDefaultFile = theDefaultUser + ".xml";            PortletsXMLSerializer XMLFile = new PortletsXMLSerializer(uRLtoTemplatesDir,                                                                      theFile,                                                                      theDefaultFile,                                                                      theJahiaEventPageID);            XMLFile.storePortlet(new PortletBean(container.getID()), theJahiaEventUserName);        } else {            if (jData == null) {                jData = new JahiaData(jParams); /** @todo find a lighter way to do this ! */            }            JahiaContainerDefinition containerDef = container.getDefinition();            String portletGroupName = containerDef.getName();            PortletsJahiaContentSerializer jPortletSerializer =                new PortletsJahiaContentSerializer(jData, portletGroupName);            jPortletSerializer.storePortlet(new PortletBean(container.getID()),                                            theJahiaEventUserName);        }    } // end addPortlet    /**     * Update portlet settings for the specified portletid     *     * @author J閞鬽e B閐at     *     */    public void setPortlet(ParamBean jParams,                           JahiaData jData,                           PortletBean thePortlet, String portletGroupName, int thePageID,                           String theUserName, String uRLtoTemplatesDir) throws JahiaException {        if (personalizationActivated) {            String theFile = theUserName + ".xml";            String theDefaultFile = theDefaultUser + ".xml";            PortletsXMLSerializer XMLFile = new PortletsXMLSerializer(uRLtoTemplatesDir,                                                                      theFile,                                                                      theDefaultFile,                                                                      thePageID);            XMLFile.storePortlet(thePortlet, theUserName);        } else {

⌨️ 快捷键说明

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