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

📄 urilookup.java

📁 jetspeed源代码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package org.apache.jetspeed.util;

/*
 * Copyright 2000-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.
 */

//jetspeed support
import org.apache.jetspeed.portal.Portlet;
import org.apache.jetspeed.portal.PortletControl;
import org.apache.jetspeed.om.registry.PortletEntry;
import org.apache.jetspeed.services.Registry;
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.rundata.JetspeedRunData;

//turbine
import org.apache.turbine.util.ParameterParser;
import org.apache.turbine.util.RunData;
import org.apache.turbine.util.template.TemplateLink;


/**
 * <p>
 * URI lookup related functions.
 * </p>
 * 
 * <p>
 *  Functions to get an URI based on a type like info, edit, save
 *  and to identify the type of an URI.
 * </p>
 * 
 * <p>
 * To overwrite the default behaviour, specify one
 * of the following parameters in the JR.p file. URILookup
 * will then return the uri specified in the properties file.
 * </p>
 * <p>
 * all possible property parameters:
 * </p>
 * 
 * <UL>
 * <LI>URILookup.home.uri</LI>
 * <LI>URILookup.home.acceptlogin.uri</LI>
 * <LI>URILookup.home.restore.uri</LI>
 * <LI>URILookup.home.logout.uri</LI>
 * </UL>
 * <UL>
 * <LI>URILookup.info.uri</LI>
 * <LI>URILookup.info.mark.uri</LI>
 * </UL>
 * <UL>
 * <LI>URILookup.login.uri</LI>
 * </UL>
 * <UL>
 * <LI>URILookup.editaccount.uri</LI>
 * <LI>URILookup.editaccount.mark.uri</LI>
 * </UL>
 * <UL>
 * <LI>URILookup.back.uri</LI>
 * </UL>
 * <UL>
 * <LI>URILookup.enrollment.uri</LI>
 * </UL>
 * <UL>
 * <LI>URILookup.customizer.uri</LI>
 * <LI>URILookup.customizer.save.uri</LI>
 * </UL>
 * 
 * @author <A HREF="shesmer@raleigh.ibm.com">Stephan Hesmer</A>
 * @author <A HREF="sgala@apache.org">Santiago Gala</A>
 * @version $Id: URILookup.java,v 1.24 2004/02/23 03:23:42 jford Exp $
 */

public class URILookup 
{
    /**
     * Static initialization of the logger for this class
     */    
    private static final JetspeedLogger logger = JetspeedLogFactoryService.getLogger(URILookup.class.getName());
    /**
     * <P>show Jetspeed Home page<BR>
     * allowed Subtypes:<BR>
     * <UL>
     * <LI>SUBTYPE_NONE</LI>
     * <LI>SUBTYPE_RESTORE</LI>
     * <LI>SUBTYPE_MAXIMIZE</LI>
     * <LI>SUBTYPE_LOGOUT</LI>
     * <LI>SUBTYPE_ACCEPT_LOGIN</LI>
     * </UL>
     */
    public static final int TYPE_HOME               = 0;
    /**
     * <P>show some additional information about the portlet</P>
     * allowed Subtypes:<BR>
     * <UL>
     * <LI>SUBTYPE_NONE</LI>
     * <LI>SUBTYPE_MARK</LI>
     * </UL>
     */
    public static final int TYPE_INFO               = 1;

    /**
     * <P>show the edit page of the account</P>
     * allowed Subtypes:<BR>
     * <UL>
     * <LI>SUBTYPE_NONE</LI>
     * <LI>SUBTYPE_MARK</LI>
     * </UL>
     */
    public static final int TYPE_EDIT_ACCOUNT       = 3;
    /**
     * <P>show portlet customization</P>
     * allowed Subtypes:<BR>
     * <UL>
     * <LI>SUBTYPE_NONE</LI>
     * <LI>SUBTYPE_SAVE</LI>
     * </UL>
     */
    public static final int TYPE_CUSTOMIZE          = 4;
    /**
     * <P>show login screen</P>
     * allowed Subtypes:<BR>
     * <UL>
     * <LI>SUBTYPE_NONE</LI>
     * </UL>
     */
    public static final int TYPE_LOGIN              = 5;
    /**
     * <P>show the marked page<BR>
     * only used in function getURI, not in getURIType</P>
     * allowed Subtypes:<BR>
     * <UL>
     * <LI>SUBTYPE_NONE</LI>
     * </UL>
     */
    public static final int TYPE_BACK               = 6;

    /**
     * <P>creates new account<BR>
     * allowed Subtypes:<BR>
     * <UL>
     * <LI>SUBTYPE_NONE</LI>
     * </UL>
     */
    public static final int TYPE_ENROLLMENT         = 7;

    /**
     * apply no subtype to the url
     */
    public static final int SUBTYPE_NONE            = 0;
    /**
     * restore portlet to default size
     */
    public static final int SUBTYPE_RESTORE         = 1;
    /**
     * show the current portlet maximized<BR>
     * additionally, the current page is marked for restoring
     */
    public static final int SUBTYPE_MAXIMIZE        = 2;
    /**
     * mark the current page before processing portlet
     */
    public static final int SUBTYPE_MARK            = 3;
    /**
     * logs out the user
     */
    public static final int SUBTYPE_LOGOUT          = 4;
    /**
     * trues to login, after entering username and password
     */
    public static final int SUBTYPE_ACCEPT_LOGIN    = 5;
    /**
     * save user settings before processing portlet
     */
    public static final int SUBTYPE_SAVE            = 6;

    /**
     * Gets the URI for the specified type
     * 
     * @param aType    type of the URI
     * @param aSubType subtype of the URI
     * @param rundata  the RunData object
     * @return the URI
     * @exception JetspeedException
     */
    public static String getURI(int aType,
                                int aSubType,
                                RunData rundata)
        throws JetspeedException
    {
        return getURI(aType, 
                      aSubType,
                      null,
                      (String)null,
                      rundata);
    }

    /**
     * Gets the URI of the specified portlet with the specified type
     * 
     * @param aType    type of the URI
     * @param aSubType subtype of the URI
     * @param aPortlet Portlet the URI points to
     * @param rundata  the RunData object
     * @return the URI
     */
    public static String getURI(int aType, 
                                int aSubType, 
                                Portlet aPortlet, 
                                RunData rundata)
        throws JetspeedException
    {
        return getURI(aType,
                      aSubType,
                      null,
                      aPortlet, 
                      rundata);
    }

    /**
     * Gets the URI of the specified portlet with the specified type
     * 
     * @param aType    type of the URI
     * @param aSubType subtype of the URI
     * @param aPortletName Portlet the URI points to
     * @param rundata  the RunData object
     * @return the URI
     */
    public static String getURI(int aType,
                                int aSubType,
                                String aPortletName,
                                RunData rundata)
        throws JetspeedException
    {
        return getURI(aType,
                      aSubType,
                      null,
                      aPortletName,
                      rundata);
    }

    /**
     * Gets the URI of the specified portlet with the specified type and adds
     * given user data.
     * 
     * @param aType    type of the URI
     * @param aSubType subtype of the URI
     * @param userData string which should be added to the URL
     * @param aPortlet Portlet the URI points to
     * @param rundata  the RunData object
     * @return the URI
     */
    public static String getURI(int aType,
                                int aSubType,
                                String userData,
                                Portlet aPortlet,
                                RunData rundata)
        throws JetspeedException
    {
        if (aPortlet!=null) {
            aPortlet = getRealPortlet(aPortlet);
            return getURI(aType,
                          aSubType,
                          userData,
                          aPortlet.getName(),
                          rundata);
        }
        else {
            return getURI(aType,
                          aSubType,
                          userData,
                          (String)null,
                          rundata);
        }
    }

    /**
     * Gets the URI of the specified portlet with the specified type and adds
     * given user data.
     * 
     * @param aType    type of the URI
     * @param aSubType subtype of the URI
     * @param userData string which should be added to the URL
     * @param aPortletName Portlet the URI points to
     * @param rundata  the RunData object
     * @return the URI
     */
    public static String getURI(int aType,
                                int aSubType,
                                String userData,
                                String aPortletName,
                                RunData rundata)
        throws JetspeedException
    {
        String newURI = null;

        String propertiesParameter = "URILookup.";

        TemplateLink uri = new TemplateLink( rundata );

        if (aType==TYPE_HOME)
        {
            propertiesParameter += "home.";
            
            if (aSubType==SUBTYPE_RESTORE)
            {
                propertiesParameter += "restore.";

                newURI = getMarkedPage( rundata );
            }
            else if (aSubType==SUBTYPE_MAXIMIZE)
            {
                propertiesParameter += "maximize.";
                
                if (aPortletName==null)
                {
                    throw new JetspeedException( "A portlet is required to return an URI." );
                }
                uri.setAction( ACTION_MARKPAGE );
                uri.addPathInfo( "portlet", aPortletName );
            }
            else if (aSubType==SUBTYPE_LOGOUT)
            {
                propertiesParameter += "logout.";

                uri.setAction( ACTION_LOGOUT );
            }
            else if (aSubType==SUBTYPE_ACCEPT_LOGIN)
            {
                propertiesParameter += "acceptlogin.";

                uri.setAction( ACTION_ACCEPT_LOGIN );
            }
            else if (aSubType!=SUBTYPE_NONE)
            {
                throw new JetspeedException( "Incorrect Type / Subtype combination." );
            }
        }
        else if (aType==TYPE_INFO)
        {
            propertiesParameter += "info.";
            
            if (aPortletName==null)
            {
                throw new JetspeedException( "A portlet is required to return an URI." );
            }
            
            uri.setPage( SCREEN_INFO );
            uri.addPathInfo( "portlet", aPortletName );

            if (aSubType==SUBTYPE_MARK)
            {
                propertiesParameter += "mark.";

                uri.setAction( ACTION_MARKPAGE );
            }
            else if (aSubType!=SUBTYPE_NONE)
            {
                throw new JetspeedException( "Incorrect Type / Subtype combination." );
            }
        }
        else if (aType==TYPE_EDIT_ACCOUNT)
        {
            propertiesParameter += "editaccount.";
            
            uri.setPage( SCREEN_EDIT_ACCOUNT );

            if (aSubType==SUBTYPE_NONE)
            {
                uri.setAction( ACTION_PREPARE_SCREEN_EDIT_ACCOUNT );
            }
            else if (aSubType==SUBTYPE_MARK)
            {
                propertiesParameter += "mark.";
                
                if (aPortletName==null) 
                {
                    throw new JetspeedException( "A portlet is required to return an URI." );
                }

                // FIX ME: how can we add a prepare action and a mark action at the same time?
                //         But I think this branch is never used anyway. (?)
                uri.setAction( ACTION_MARKPAGE );
                uri.addPathInfo( "portlet", aPortletName );
            }
            else
            {
                throw new JetspeedException( "Incorrect Type / Subtype combination." );
            }
        }
        else if (aType==TYPE_CUSTOMIZE)
        {
            propertiesParameter += "customize.";
            
            uri.setPage( SCREEN_CUSTOMIZE );
            
            if( aPortletName != null )
            {
                uri.addPathInfo( "portlet", aPortletName );
            }
            if (aSubType==SUBTYPE_NONE)
            {
                if (ACTION_CUSTOMIZER!=null) uri.setAction( ACTION_CUSTOMIZER );
            }
            else if (aSubType==SUBTYPE_SAVE)
            {
                propertiesParameter += "save.";
                
                uri.setAction( ACTION_CUSTOMIZER_SAVE );
            }
            else
            {
                throw new JetspeedException( "Incorrect Type / Subtype combination." );
            }

⌨️ 快捷键说明

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