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

📄 portlethref.java

📁 一个比较不错的java分页标签,有源代码,开发者 可以学习学习
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/**
 * Licensed under the Artistic License; you may not use this file
 * except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://displaytag.sourceforge.net/license.html
 *
 * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 */
package org.displaytag.portlet;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import javax.portlet.PortletMode;
import javax.portlet.PortletModeException;
import javax.portlet.PortletRequest;
import javax.portlet.PortletSecurityException;
import javax.portlet.PortletURL;
import javax.portlet.RenderResponse;
import javax.portlet.WindowState;
import javax.portlet.WindowStateException;

import org.apache.commons.collections.Predicate;
import org.apache.commons.collections.functors.AnyPredicate;
import org.apache.commons.collections.functors.InstanceofPredicate;
import org.apache.commons.collections.functors.NullPredicate;
import org.apache.commons.collections.map.PredicatedMap;
import org.apache.commons.lang.ObjectUtils;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.displaytag.util.Href;


/**
 * Implementation of the Href interface that generates URLs using the javax.portlet APIs. As the portlet API supports
 * the concept of WindowStates, PorletModes, secure URLs and actions versus render the implementation supports these
 * concepts as well through the standard {@link Href} APIs. <br>
 * <br>
 * The features are manipulated using special parameter names and values: <table>
 * <tr>
 * <th>Feature</th>
 * <th>Parameter Name</th>
 * <th>Parameter Value</th>
 * </tr>
 * <tr>
 * <td>Render vs Action URL</td>
 * <td>{@link #PARAM_TYPE} (portlet:type)</td>
 * <td>"render" for RenderURLs, "action" for ActionURLs</td>
 * </tr>
 * <tr>
 * <td>WindowState</td>
 * <td>{@link #PARAM_STATE} (portlet:state)</td>
 * <td>The value is used directly for the WindowState name</td>
 * </tr>
 * <tr>
 * <td>PorltetMode</td>
 * <td>{@link #PARAM_MODE} (portlet:mode)</td>
 * <td>The value is used directly for the PortletMode name</td>
 * </tr>
 * <tr>
 * <td>Secure URL</td>
 * <td>{@link #PARAM_SECURE} (portlet:secure)</td>
 * <td>"true" requests a secure URL, anything else requests a standard URL</td>
 * </tr>
 * </table>
 * @author Eric Dalquist <a href="mailto:dalquist@gmail.com">dalquist@gmail.com</a>
 * @version $Id: PortletHref.java 999 2006-01-22 20:01:46Z fgiust $
 */
public class PortletHref implements Href
{

    // Constants for working with the special parameters
    private static final String PARAM_PREFIX = "portlet:";

    public static final String PARAM_MODE = PARAM_PREFIX + "mode";

    public static final String PARAM_STATE = PARAM_PREFIX + "state";

    public static final String PARAM_SECURE = PARAM_PREFIX + "secure";

    public static final String PARAM_TYPE = PARAM_PREFIX + "type";

    public static final String TYPE_RENDER = "render";

    public static final String TYPE_ACTION = "action";

    /**
     * D1597A17A6.
     */
    private static final long serialVersionUID = 899149338534L;

    // Predicated for type checking the parameter map
    private static final Predicate PRED_TYPE_OF_STRING = new InstanceofPredicate(String.class);

    private static final Predicate PRED_TYPE_OF_STRING_ARRY = new InstanceofPredicate(String[].class);

    private static final Predicate PRED_OR_STR_STRARR = new AnyPredicate(new Predicate[]{
        PRED_TYPE_OF_STRING,
        PRED_TYPE_OF_STRING_ARRY,
        NullPredicate.INSTANCE});

    // Portlet request and response are needed for feature checking and generating the URLs
    private final PortletRequest portletRequest;

    private final RenderResponse renderResponse;

    private Map parameters = this.createParameterMap();

    private boolean isAction;

    private PortletMode requestedMode;

    private WindowState requestedState;

    private boolean requestedSecure;

    private String anchor;

    /**
     * Creates a new PortletHref. The actual PortletURL object is not generated until the toString method is called.
     * @param portletRequest request to to feature checking with, may not be null.
     * @param renderResponse response to generate the URLs from, may not be null.
     */
    public PortletHref(PortletRequest portletRequest, RenderResponse renderResponse)
    {
        if (portletRequest == null)
        {
            throw new IllegalArgumentException("portletRequest may not be null");
        }
        if (renderResponse == null)
        {
            throw new IllegalArgumentException("renderResponse may not be null");
        }

        this.portletRequest = portletRequest;
        this.renderResponse = renderResponse;
    }

    /**
     * @see org.displaytag.util.Href#setFullUrl(java.lang.String)
     */
    public void setFullUrl(String baseUrl)
    {
        // do nothing
    }

    /**
     * @return Returns the isAction.
     */
    public boolean isAction()
    {
        return this.isAction;
    }

    /**
     * @param isAction The isAction to set.
     */
    public void setAction(boolean isAction)
    {
        this.isAction = isAction;
    }

    /**
     * @return Returns the requestedMode.
     */
    public PortletMode getRequestedMode()
    {
        return this.requestedMode;
    }

    /**
     * @param requestedMode The requestedMode to set.
     */
    public void setRequestedMode(PortletMode requestedMode)
    {
        this.requestedMode = requestedMode;
    }

    /**
     * @return Returns the requestedSecure.
     */
    public boolean isRequestedSecure()
    {
        return this.requestedSecure;
    }

    /**
     * @param requestedSecure The requestedSecure to set.
     */
    public void setRequestedSecure(boolean requestedSecure)
    {
        this.requestedSecure = requestedSecure;
    }

    /**
     * @return Returns the requestedState.
     */
    public WindowState getRequestedState()
    {
        return this.requestedState;
    }

    /**
     * @param requestedState The requestedState to set.
     */
    public void setRequestedState(WindowState requestedState)
    {
        this.requestedState = requestedState;
    }

    /**
     * @see org.displaytag.util.Href#addParameter(java.lang.String, int)
     */
    public Href addParameter(String name, int value)
    {
        return this.addParameter(name, Integer.toString(value));
    }

    /**
     * @see org.displaytag.util.Href#addParameter(String, Object)
     */
    public Href addParameter(String name, Object objValue)
    {
        String value = ObjectUtils.toString(objValue, null);

        if (name != null && name.startsWith(PARAM_PREFIX))
        {
            if (PARAM_TYPE.equals(name))
            {
                if (TYPE_RENDER.equals(value))
                {
                    this.setAction(false);
                }
                else if (TYPE_ACTION.equals(value))
                {
                    this.setAction(true);
                }
                else
                {
                    throw new IllegalArgumentException("Value of parameter '"
                        + name
                        + "' must be equal to '"
                        + TYPE_RENDER
                        + "' or '"
                        + TYPE_ACTION
                        + "'. '"
                        + value
                        + "' is not allowed.");
                }
            }
            else if (PARAM_SECURE.equals(name))
            {
                if (new Boolean(value).booleanValue())
                {
                    this.setRequestedSecure(true);
                }
                else
                {
                    this.setRequestedSecure(false);
                }
            }
            else if (PARAM_MODE.equals(name))
            {
                if (value == null)
                {
                    this.setRequestedMode(null);
                }
                else
                {
                    final PortletMode mode = new PortletMode(value);

                    if (!this.portletRequest.isPortletModeAllowed(mode))
                    {
                        throw new IllegalArgumentException("PortletMode '"
                            + mode
                            + "' is not allowed for this request.");
                    }

                    this.setRequestedMode(mode);

⌨️ 快捷键说明

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