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

📄 jetspeedtool.java

📁 jetspeed源代码
💻 JAVA
📖 第 1 页 / 共 3 页
字号:

            if (canAccess)
            {
                // Always set portlet id to "preview" so each preview request gets it from the cache.
                // At least, I think that's how it works.
                p = PortletFactory.getPortlet(portletName, "preview");
                PortletControl control = controlName == null ? PortalToolkit.getControl((String) null) 
                                                             : PortalToolkit.getControl(controlName);
                if (control != null)
                {
                    JetspeedRunData jdata = (JetspeedRunData) rundata;
                    // Use the profile's skin
                    p.getPortletConfig().setPortletSkin(PortalToolkit.getSkin(jdata.getProfile().getDocument().getPortlets().getSkin()));
                    control.setPortlet(p);
                    control.init();
                    result = control.getContent(rundata);
                } 
                else if (p != null)
                {
                    result = p.getContent(rundata);
                }
            }
            else
            {
                result = new JetspeedClearElement(Localization.getString(data, "SECURITY_NO_ACCESS_TO_PORTLET"));
            }
        } 
        catch (Exception e) 
        {
            logger.error("Exception",  e);
            result = new ConcreteElement();
        }
                
        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
     * @deprecated Do not use this method because it's not secure. It will be removed after Beta 5.
     */
    public ConcreteElement getPortletFromRegistry(String portletName, String controlName)
    {

        ConcreteElement result = null;
        Portlet p = null;
        
        try 
        {
            // Always set portlet id to "preview" so each preview request gets it from the cache.
            // At least, I think that's how it works.
            p = PortletFactory.getPortlet(portletName, "preview");
            PortletControl control = controlName == null ? PortalToolkit.getControl((String) null) 
                                                         : PortalToolkit.getControl(controlName);
            if (control != null)
            {
                JetspeedRunData jdata = (JetspeedRunData) rundata;
                // Use the profile's skin
                p.getPortletConfig().setPortletSkin(PortalToolkit.getSkin(jdata.getProfile().getDocument().getPortlets().getSkin()));
                control.setPortlet(p);
                control.init();
                result = control.getContent(rundata);
            } 
            else if (p != null)
            {
                result = p.getContent(rundata);
            }
        } 
        catch (Exception e) 
        {
            logger.error("Exception",  e);
            result = new ConcreteElement();
        }
                
        if (result == null)
        {
            //the customizer already streamed its content, return a stub
            result = new ConcreteElement();
        }

        return result;
    }

    /**
     * Returns a parameter in its defined parameter style
     * 
     * @param data     for this request
     * @param portlet  portlet instance
     * @param parmName parameter name
     * @return current parameter value using specified presentation style
     */
    public static String getPortletParameter(RunData data, Portlet portlet, String parmName)
    {

        if (portlet != null && parmName != null) 
        {
            String parmValue = portlet.getPortletConfig().getInitParameter(parmName, "");
            return getPortletParameter(data, portlet, parmName, parmValue);
        }

        return "";
    }

    /**
     * Returns a parameter in its defined parameter style
     * 
     * @param data      for this request
     * @param portlet   portlet instance
     * @param parmName  parameter name
     * @param parmValue current parameter value
     * @return current parameter value using specified presentation style
     */
    public static String getPortletParameter(RunData data, Portlet portlet, String parmName, String parmValue)
    {
        String result = null;
        try 
        {
            if (portlet != null && parmName != null) 
            {
                // Retrieve registry entry and its parameter
                PortletEntry entry = (PortletEntry) Registry.getEntry(Registry.PORTLET, portlet.getName());
                Parameter param = entry.getParameter(parmName);

                // Verify security for the parameter
                boolean canAccess = JetspeedSecurity.checkPermission((JetspeedUser) data.getUser(), 
                                                                     new PortalResource(entry, param), 
                                                                     JetspeedSecurity.PERMISSION_CUSTOMIZE);
                Map portletParms = portlet.getPortletConfig().getInitParameters();
                String parmStyle = portlet.getPortletConfig().getInitParameter(parmName + ".style");

                // Add portlet reference
                portletParms.put(parmName.concat(".style.portlet"), portlet);

                if (canAccess)
                {
                    if (parmStyle != null) 
                    {
                        result = ParameterLoader.getInstance().eval(data, 
                                                                    parmStyle, 
                                                                    parmName, 
                                                                    parmValue, 
                                                                    portletParms);                
                    }
                    else
                    {
                        result = "<input type=\"text\" name=\"" + parmName + "\" value=\"" + parmValue + "\"";
                    }
                }
                else
                {
                    // If security does not allow access to specific parameter, allow to provide a fallback parameter
                    String parmNameNoAccess = portlet.getPortletConfig().getInitParameter(parmName + ".style.no-access");
                    if (parmNameNoAccess != null) 
                    {
                        if (logger.isDebugEnabled())
                        {
                            logger.debug("JetspeedTool: access to parm [" + parmName + "] disallowed, redirecting to parm [" + 
                                      parmNameNoAccess + "]");
                        }
                        String parmStyleNoAccess = portlet.getPortletConfig().getInitParameter(parmNameNoAccess + ".style");
                        result = ParameterLoader.getInstance().eval(data, 
                                                                    parmStyleNoAccess, 
                                                                    parmNameNoAccess, 
                                                                    parmValue, 
                                                                    portletParms);                
                    }
                }
            }
        } 
        catch (Exception e)
        {
            logger.error("Exception",  e);
        }

        return result;
    }
    
    /**
     * Returns a parameter rendered in specific parameter style
     * 
     * @param data      for this request
     * @param parmStyle parameter style
     * @param parmName  parameter name
     * @param parmValue current parameter value
     * @param options   optional style parameters in delimited format (option1=value1;option2=value2)
     * @return current parameter value using specified presentation style
     */
    public static String getParameter(RunData data, String parmStyle, String parmName, String parmValue, String parmOptions)
    {
        String result = null;
        try 
        {
            if (parmName != null) 
            {
                if (parmStyle != null) 
                {
                    Map options = null;
                    if (parmOptions != null && parmOptions.length() > 0)
                    {
                        options = new Hashtable();

                        StringTokenizer st = new StringTokenizer(parmOptions, ";");
                        String prefix = parmName + ".style.";
                        while (st.hasMoreTokens())
                        {
                            StringTokenizer pair = new StringTokenizer(st.nextToken(), "=");
                            if (pair.countTokens() == 2)
                            {
                                options.put(prefix + pair.nextToken().trim(), pair.nextToken().trim());
                            }
                        }

                    }
                    result = ParameterLoader.getInstance().eval(data, 
                                                                parmStyle, 
                                                                parmName, 
                                                                parmValue, 
                                                                options);                
                }
                else
                {
                    result = "<input type=\"text\" name=\"" + parmName + "\" value=\"" + parmValue + "\"";
                }                
            }
        } 
        catch (Exception e)
        {
            logger.error("Exception",  e);
            result = "<input type=\"text\" name=\"" + parmName + "\" value=\"" + parmValue + "\"";
        }

        return result;
    }

    /**
     * Retreives the correct SecurityReference for the portlet based on the current
     * profile and the request.
     */
    public SecurityReference getSecurityReference(Entry entry)
    {
        return JetspeedSecurity.getSecurityReference(entry, rundata);
    }
    
    public int getSecuritySource(Entry entry)
    {
        return JetspeedSecurity.getSecuritySource(entry, rundata);
    }
    
    /**
     * Retreives the Entry object for current portlet based on the 
     * "js_peid" parameter
     */
    public Entry getEntryFromRequest() throws Exception
    {
        String jsPeid = rundata.getParameters().getString("js_peid");
        Profile profile = Profiler.getProfile(rundata);
        PSMLDocument doc = profile.getDocument();
        return doc.getEntryById(jsPeid);
    }

}

⌨️ 快捷键说明

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