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

📄 jetspeedtool.java

📁 jetspeed源代码
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
            {
                logger.error("Exception",  e);
            }
        }
            
        return customizer;
    }

    /** This method retrieves the appropriate information portlet for the 
      *  current portlet
      *
      *  @param p the portlet to display information about
      *  @param data the RunData for this request
      *  @return the portlet object of the appropriate customizer
      */
     public static Portlet getPortletInfoPortlet(RunData data)
     {
         Portlet info = null;
         
         String name = JetspeedResources.getString("PortletInfoPortlet.name", "PortletInfoPortlet");
 
         try {
 
             if (null != data)
             {
                 JetspeedRunData jdata = (JetspeedRunData)data;
                 Profile profile = jdata.getProfile();
 
                 if (null == profile)
                 {
                     logger.warn("JetspeedTool: profile is null");
                     profile = Profiler.getProfile(jdata);
                     jdata.setProfile(profile);
                 }
 
                 Portlet source = findPortlet(data);
                 if (source != null) {
                     jdata.setPortlet(source.getName());
                     info = PortletFactory.getPortlet(name, "PortletInfoPortlet");
                     info.getPortletConfig().setPortletSkin(source.getPortletConfig().getPortletSkin());
                     PortletControl control = PortalToolkit.getControl((String)null);
                     if (control != null) 
                     {
                         control.setPortlet(info);
                         control.init();
                         return control;
                     }
                 }
             }
         } catch (Exception e) {
             logger.error("Exception",  e);
         }
             
         return info;
     }
 
     /**
      * Finds portlet identified by js_peid in the current user's profile
      * 
      * @param rundata for this request
      * @return portlet identified by js_peid
      */
     private static Portlet findPortlet(RunData rundata) {
 
         Portlet found = null;
         JetspeedRunData jdata = (JetspeedRunData)rundata;
         String peid = jdata.getJs_peid();
         if (peid != null) 
         {
             Stack sets = new Stack();
             sets.push(jdata.getProfile().getRootSet());
 
             while ((found==null) && (sets.size() > 0))
             {
                 PortletSet set = (PortletSet)sets.pop();
 
                 if (set.getID().equals(peid))
                 {
                     found = set;
                 }
                 else
                 {
                     Enumeration en = set.getPortlets();
                     while((found==null) && en.hasMoreElements())
                     {
                         Portlet p = (Portlet)en.nextElement();
 
                         // unstack the controls to find the real PortletSets
                         Portlet real = p;
                         while (real instanceof PortletControl)
                         {
                             real = ((PortletControl)p).getPortlet();
                         }
 
                         if (real instanceof PortletSet)
                         {
                             if (real.getID().equals(peid))
                             {
                                 found=real;
                             }
                             else
                             {
                                 // we'll explore this set afterwards
                                 sets.push(real);
                             }
                         }
                         else if (p.getID().equals(peid))
                         {                        
                             found = p;
                         }
                     }
                 }
             }
         }
 
         return found;
     }


    /** 
     * Return the content of a portal element given the id of the element. 
     *
     * @param id The portlet id
     * @return the rendered content of the portlet
     */
    public ConcreteElement getPortalElement(String id)
    {
        ConcreteElement result = null;
        
        if (null != rundata)
        {
            Profile profile = rundata.getProfile();
            try
            {
                if (null == profile)
                {
                    System.out.println("profile is null");
                    profile = Profiler.getProfile(rundata);
                    rundata.setProfile(profile);
                }
 
                PSMLDocument doc = profile.getDocument();
                if (null != doc)
                {                
                    Entry entry = doc.getEntryById(id);
                    if (null == entry)
                    {
                        // FIXME: need to write this function
                        // Portlets ps = doc.getPortletsById(id);
                        result = new  StringElement("not implemented - PortletElement");
                    }
                    else
                    {
                        Portlet p = PortletFactory.getPortlet( entry );
                        if (p != null)
                        {
                            result = p.getContent(rundata);
                        }
                        else
                           result = new  StringElement("Error retrieving PortletElement");

                    }
                }                
            }
            catch (Exception e)
            {
                logger.error("Exception",  e);
            }
        }
        
        if (result == null)
        {
            result = new StringElement("Error fetching pane");
        }

        return result;

    }

    /**
     * Return the content of a portlet using the portlet's id (PEID). This portlet is sought in
     * the current PSML resource.
     *
     * If a control is attached to the portlet description, returns the defined
     * portlet and control, otherwise use the default control.
     *
     * @param peid the peid of the portlet to render
     * @return the rendered content of the portlet
     */
    public ConcreteElement getPortletById(String peid)
    {
        ConcreteElement result = null;
        Portlet found = null;
        Stack sets = new Stack();
        sets.push(rundata.getProfile().getRootSet());
        
        while ((sets.size() > 0) && (found==null))
        {
            PortletSet set = (PortletSet)sets.pop();
            
            if (set.getID().equals(peid))
            {
                found = set;
            }
            else
            {
                Enumeration en = set.getPortlets();
                while((found==null) && en.hasMoreElements())
                {
                    Portlet p = (Portlet)en.nextElement();
                        
                    // unstack the controls to find the real PortletSets
                    Portlet real = p;
                    while (real instanceof PortletControl)
                    {
                        real = ((PortletControl)p).getPortlet();
                    }
                        
                    if (real instanceof PortletSet)
                    {
                        // we'll explore this set afterwards
                        sets.push(real);
                    }
                    else if (p.getID().equals(peid))
                    {                        
                        found = p;
                    }
                }
            }
        }
        
        if (found!=null)
        {
            // Return portlet's content checking the security first
            result = PortletWrapper.wrap(found).getContent(rundata);
        }
        
        if (result==null)
        {
            //the customizer already streamed its content, return a stub
            result = new ConcreteElement();
        }

        return result;
    }

    /**
     * Return the content of a portlet using the portlet's name. This portlet is sought in
     * the registry. This is useful when you want to get portlet's content without
     * actually having the portlet in user's profile (for example, to preview a portlet
     * before adding it to the profile).
     * <P>
     * If a control name is specified to the portlet description, returns the defined
     * portlet and control, otherwise use the default control.
     * <P>
     * Issues to resolve:
     * <UL>
     * <LI>is new portlet instance created everytime someone previews the same portlet?</LI>
     * <LI>should use the same skin as the current pane</LI>
     * <LI>if TitlePortletControl is used, the action icons (max, min, etc) are not functional.
     * Also, customize icon should not be present.</LI>
     * <LI> interactive portlets (such as DatabaseBrowser) lose functionality (such as sorting
     * in DatabaseBrowser).</LI>
     * </UL>
     * 
     * @param portletName
     *               Name of the portlet as defined in registry
     * @param controlName
     *               Optional control name to use in displaying the portlet
     * @return the rendered content of the portlet
     */
    public ConcreteElement getPortletFromRegistry(RunData data)
    {

        ConcreteElement result = null;
        Portlet p = null;
        String portletName = data.getParameters().getString("p"); 
        String controlName = data.getParameters().getString("c");
        
        try 
        {

            // Retrieve registry entry
            PortletEntry entry = (PortletEntry) Registry.getEntry(Registry.PORTLET, portletName);

            // Verify security for the parameter
            boolean canAccess = JetspeedSecurity.checkPermission((JetspeedUser) data.getUser(), 
                                                                 new PortalResource(entry), 
                                                                 JetspeedSecurity.PERMISSION_CUSTOMIZE);

⌨️ 快捷键说明

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