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

📄 jetspeedtool.java

📁 jetspeed源代码
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/*
 * Copyright 2000-2001,2004 The Apache Software Foundation.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.apache.jetspeed.util.template;

import org.apache.ecs.ConcreteElement;
import org.apache.ecs.StringElement;

import org.apache.turbine.util.RunData;
import org.apache.turbine.services.pull.ApplicationTool;
import org.apache.turbine.services.localization.Localization;

import org.apache.jetspeed.portal.Portlet;
import org.apache.jetspeed.portal.PortletSet;
import org.apache.jetspeed.portal.PortletControl;
import org.apache.jetspeed.services.PortalToolkit;
import org.apache.jetspeed.services.PortletFactory;
import org.apache.jetspeed.services.logging.JetspeedLogFactoryService;
import org.apache.jetspeed.services.logging.JetspeedLogger;
import org.apache.jetspeed.services.resources.JetspeedResources;
import org.apache.jetspeed.services.Profiler;
import org.apache.jetspeed.services.rundata.JetspeedRunData;
import org.apache.jetspeed.om.SecurityReference;
import org.apache.jetspeed.om.profile.PSMLDocument;
import org.apache.jetspeed.om.profile.Profile;
import org.apache.jetspeed.om.profile.ProfileException;
import org.apache.jetspeed.om.profile.Entry;
import org.apache.jetspeed.modules.ParameterLoader;
import org.apache.jetspeed.services.security.PortalResource;
import org.apache.jetspeed.om.registry.Parameter;
import org.apache.jetspeed.om.registry.PortletEntry;
import org.apache.jetspeed.om.security.JetspeedUser;
import org.apache.jetspeed.services.Registry;
import org.apache.jetspeed.services.JetspeedSecurity;
import org.apache.jetspeed.portal.security.portlets.PortletWrapper;
import org.apache.jetspeed.util.JetspeedClearElement;

import java.util.Enumeration;
import java.util.Stack;
import java.util.Map;
import java.util.Hashtable;
import java.util.StringTokenizer;

/**
 * Utility class for accessing Jetspeed in a "pull" mode
 *
 * <strong>Since the tool stores a RunData object, it may not be
 * shared between threads and/or requests</strong>
 *
 * @author <a href="mailto:raphael@apache.org">Rapha雔 Luta</a>
 * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
 * @author <a href="mark_orciuch@ngsltd.com">Mark Orciuch</a>
 * @author <a href="mailto:weaver@apache.org">Scott T. Weaver</a>
 *
 * @version $Id: JetspeedTool.java,v 1.38 2004/03/29 21:38:43 taylor Exp $
 */
public class JetspeedTool implements ApplicationTool
{
    /**
     * Static initialization of the logger for this class
     */    
    private static final JetspeedLogger logger = JetspeedLogFactoryService.getLogger(JetspeedTool.class.getName());
    
    /** RunData object for this request */
    protected JetspeedRunData rundata = null;
    
    /** Empty constructor used by introspection
     */
    public JetspeedTool()
    {
    }

    /** The Tool constructor
     *
     * @param data the RunData object for the current request
     */
    public JetspeedTool(RunData data)
    {
        this.rundata = (JetspeedRunData)data;
    }
    
    /**
     * This will initialise a JetspeedTool object that was
     * constructed with the default constructor (ApplicationTool
     * method).
     *
     * @param data assumed to be a RunData object
     */
    public void init(Object data)
    {
        this.rundata = (JetspeedRunData)data;
    }

    /**
     * Refresh method - does nothing
     */
    public void refresh()
    {
        // empty
    }

    /** 
     * Returns the portlet content customized for the current user.
     * Currently, the layout engine does not handle panes, so the 
     * panes are mapped to real PSML files.
     * If the pane name is null or "default", the profiler will automatically
     * chose the PSML content, else the tool will try to load the PSML
     * file with the specified name
     *
     * @param name the name of the pane to render
     * @return the rendered content of the pane
     */
    public ConcreteElement getPane(String name)
    {
        ConcreteElement result = null;
        String msg = "";
        
        if (null != rundata)
        {
            Profile profile = rundata.getProfile();
            try
            {
                if (null == profile)
                {
                    profile = Profiler.getProfile(rundata);
                    if (profile == null)
                    {
                        throw new ProfileException("Profile not found.");
                    }
                    rundata.setProfile(profile);
                }
            
                if ((name == null) ||  Profiler.DEFAULT_PROFILE.equals(name) || "".equals(name))
                    ;
                else
                    profile.setName(name);
     
                PSMLDocument doc = profile.getDocument();
                if (null != doc)
                {
                    result = PortalToolkit.getSet(doc.getPortlets()).getContent(rundata);
                }
            }
            catch (Exception e)
            {
                logger.warn("JetspeedTool.getPane: problem getting: "
                            + name + " from current request's profile: " + e.toString());
                msg = e.getMessage();
            }

        }
        
        if (result == null)
        {
            result = new StringElement("Error retrieving Portal Page: " + msg);
        }

        return result;
    }

    /**
     * Return the content of a named portlet. 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.
     *
     * Note:  This will return the FIRST portlet with a name = name.  Use getPortletById().
     *
     * @param name the name of the portlet to render
     * @return the rendered content of the portlet
     *
     * @deprecated Use getPortletById()
     */
    public ConcreteElement getPortlet(String name)
    {
        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.getName().equals(name))
            {
                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.getName().equals(name))
                    {                        
                        found = p;
                    }
                }
            }
        }
        
        if (found!=null)
        {
            result = found.getContent(rundata);
        }
        
        if (result==null)
        {
            //the customizer already streamed its content, return a stub
            result = new ConcreteElement();
        }

        return result;
    }

    /** This method retrieves the appropriate customizer portlet for the 
     *  current portlet
     *
     *  @param p the portlet to customize
     *  @param data the RunData for this request
     *  @return the portlet object of the appropriate customizer
     */
    public static Portlet getCustomizer(Portlet p)
    {
        Portlet customizer = p;

        while (p instanceof PortletControl)
        {
            p = ((PortletControl)p).getPortlet();
        }
        
        // if the portlet cannot customize itself...
        if ( !p.providesCustomization() )
        {

            //look for the customizer name in the portlet
            //config (from Registry definition)
        
            String name = p.getPortletConfig().getInitParameter("_customizer");
            
            if (name == null)
            {
                String key = (p instanceof PortletSet)?"PortletSet":"Portlet";            

                name = JetspeedResources.getString("customizer."+key,key+"Customizer");
            }
        
            try
            {
                customizer = PortletFactory.getPortlet(name, p.getID()+"customize");
                customizer.getPortletConfig()
                          .setPortletSkin(p.getPortletConfig().getPortletSkin());
                PortletControl control = PortalToolkit.getControl((String)null);
                if (control!=null)
                {
                    control.setPortlet(customizer);
                    control.init();
                    return control;
                }
            }
            catch (Exception e)

⌨️ 快捷键说明

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