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

📄 portletrequestimpl.java

📁 portal越来越流行了
💻 JAVA
📖 第 1 页 / 共 3 页
字号:

    /**
     * Determines whether a user is mapped to the specified role.  As specified
     * in PLT-20-3, we must reference the <security-role-ref> mappings
     * within the deployment descriptor. If no mapping is available, then, and
     * only then, do we check use the actual role name specified against the web
     * application deployment descriptor.
     *
     * @param roleName the name of the role
     * @return true if it is determined the user has the given role.
     */
    public boolean isUserInRole(String roleName) 
    {
        PortletEntity entity = portletWindow.getPortletEntity();
        PortletDefinition def = entity.getPortletDefinition();

        SecurityRoleRef ref = null;
        Iterator refs = def.getSecurityRoleRefs().iterator();
        while (refs.hasNext()) 
        {
            SecurityRoleRef r = (SecurityRoleRef) refs.next();
            if (r.getRoleName().equals(roleName)) 
            {
                ref = r;
                break;
            }
        }

        String link;
        if (ref != null && ref.getRoleLink() != null) 
        {
            link = ref.getRoleLink();
        } else 
        {
            link = roleName;
        }
        return this.getHttpServletRequest().isUserInRole(link);
    }

    public Object getAttribute(String name) 
    {
    	ArgumentUtility.validateNotNull("attributeName", name);

        if (namedRequestDispatcher && (name.startsWith("javax.servlet.forward") || name.startsWith("javax.servlet.include")))
        {
            // PLT.19.3.1
            if (name.equals("javax.servlet.include.request_uri")||name.equals("javax.servlet.include.context_path")||
                            name.equals("javax.servlet.include.servlet_path")||name.equals("javax.servlet.include.path_info")||
                            name.equals("javax.servlet.include.query_string"))
            {
                return null;
            }
            // PLT.19.4.2, ccxlii
            if (name.equals("javax.servlet.forward.request_uri")||name.equals("javax.servlet.forward.context_path")||
                            name.equals("javax.servlet.forward.servlet_path")||name.equals("javax.servlet.forward.path_info")||
                            name.equals("javax.servlet.forward.query_string"))
            {
                return null;
            }
        }
        
        final OptionalContainerServices optionalContainerServices = container.getOptionalContainerServices();
        final RequestAttributeService requestAttributeService = optionalContainerServices.getRequestAttributeService();
        return requestAttributeService.getAttribute(this, this.getHttpServletRequest(), this.portletWindow, name);
    }

    public Enumeration<String> getAttributeNames() 
    {
        final OptionalContainerServices optionalContainerServices = container.getOptionalContainerServices();
        final RequestAttributeService requestAttributeService = optionalContainerServices.getRequestAttributeService();
        return requestAttributeService.getAttributeNames(this, this.getHttpServletRequest(), this.portletWindow);
    }
    
    public String getParameter(String name) 
    {
        ArgumentUtility.validateNotNull("parameterName", name);
        String[] values  = null;
        if (parameters != null)
        {
            values = parameters.get(name);
        }
        else
        {
        	List<String> publicRenderParameterNames = portletWindow.getPortletEntity().getPortletDefinition().getSupportedPublicRenderParameters();
        	if (publicRenderParameterNames != null)
        	{
        		if (publicRenderParameterNames.contains(name))
        			values = urlProvider.getPublicRenderParameters(name);
        		else
        			values = (String[]) baseGetParameterMap().get(name);
        	}
        	else
        	{
        	    values = (String[]) baseGetParameterMap().get(name);
        	}
        }
        if (values != null && values.length > 0) 
        {
            return values[0];
        } 
        else 
        {
        	return null;
        }
    }

    public Enumeration<String> getParameterNames() 
    {
        return Collections.enumeration(baseGetParameterMap().keySet());
    }

    public String[] getParameterValues(String name) 
    {
        ArgumentUtility.validateNotNull("parameterName", name);
        String[] values  = null;
        if (parameters != null)
        {
            values = parameters.get(name);
        }
        else
        {    
        	List<String> publicRenderParameterNames = portletWindow.getPortletEntity().getPortletDefinition().getSupportedPublicRenderParameters();        	
        	if (publicRenderParameterNames != null)
        	{
        		if (publicRenderParameterNames.contains(name))
        			values = urlProvider.getPublicRenderParameters(name);
        		else
        			values = (String[]) baseGetParameterMap().get(name);
        	}
        	else
        	{
    			values = (String[]) baseGetParameterMap().get(name);
        	}
        }
        if (values != null) 
        {
            values = StringUtils.copy(values);
        }
        return values;
    }
    
    public Map<String, String[]> getParameterMap() 
    {
        if (parameters != null)
        {
            return parameters;
        }
        else
        {        
            String[] values  = null;
            Map<String, String[]>map = StringUtils.copyParameters(baseGetParameterMap());
        	List<String> publicRenderParameterNames = portletWindow.getPortletEntity().getPortletDefinition().getSupportedPublicRenderParameters();
        	if (publicRenderParameterNames!=null)
        	{
        		for (String string : publicRenderParameterNames) 
        		{
        			values = urlProvider.getPublicRenderParameters(string);
        			if (values != null)
        			{
        				map.put(string, values);
        			}
    			}
        	}
            parameters = Collections.unmodifiableMap(map);
            return parameters;        	
        }
    }

    public boolean isSecure() 
    {
        return this.getHttpServletRequest().isSecure();
    }

    public void setAttribute(String name, Object value) 
    {
        ArgumentUtility.validateNotNull("attributeName", name);
        final OptionalContainerServices optionalContainerServices = container.getOptionalContainerServices();
        final RequestAttributeService requestAttributeService = optionalContainerServices.getRequestAttributeService();
        requestAttributeService.setAttribute(this, this.getHttpServletRequest(), this.portletWindow, name, value);
    }

    public void removeAttribute(String name) 
    {
    	ArgumentUtility.validateNotNull("attributeName", name);
    	
        final OptionalContainerServices optionalContainerServices = container.getOptionalContainerServices();
        final RequestAttributeService requestAttributeService = optionalContainerServices.getRequestAttributeService();
        requestAttributeService.removeAttribute(this, this.getHttpServletRequest(), this.portletWindow, name);
    }

    public String getRequestedSessionId() 
    {
        return this.getHttpServletRequest().getRequestedSessionId();
    }

    public boolean isRequestedSessionIdValid() 
    {
        if (LOG.isDebugEnabled()) 
        {
            LOG.debug(" ***** IsRequestedSessionIdValid? "+getHttpServletRequest().isRequestedSessionIdValid());
        }
        return getHttpServletRequest().isRequestedSessionIdValid();
    }

    public String getResponseContentType() 
    {
        Enumeration<String> enumeration = getResponseContentTypes();
        while (enumeration.hasMoreElements()) 
        {
            return (String) enumeration.nextElement();
        }
        return "text/html";
    }

    public Enumeration<String> getResponseContentTypes() 
    {
        if (contentTypes == null) 
        {
            contentTypes = new Vector<String>();
            PortletDefinition dd = portletWindow.getPortletEntity().getPortletDefinition();
            Iterator supports = dd.getSupports().iterator();
            while (supports.hasNext()) 
            {
                Supports sup = (Supports) supports.next();
                contentTypes.add(sup.getMimeType());
            }
            if (contentTypes.size() < 1) 
            {
                contentTypes.add("text/html");
            }
        }
        return contentTypes.elements();
    }

    public Locale getLocale() 
    {
        return this.getHttpServletRequest().getLocale();
    }

    @SuppressWarnings("unchecked")
    public Enumeration<Locale> getLocales() 
    {
        return this.getHttpServletRequest().getLocales();
    }

    public String getScheme() 
    {
        return this.getHttpServletRequest().getScheme();
    }

    public String getServerName() 
    {
        return this.getHttpServletRequest().getServerName();
    }

    public int getServerPort() 
    {
        return this.getHttpServletRequest().getServerPort();
    }
    
    
    // Protected Methods -------------------------------------------------------
    
    protected void setBodyAccessed() 
    {
    	bodyAccessed = true;
    }
        
    // InternalPortletRequest Impl ---------------------------------------------

    public PortletWindow getPortletWindow() 
    {
        return portletWindow;
    }

    public PortletContainer getPortletContainer() 
    {
        return container;
    }

    public HttpServletRequest getHttpServletRequest() 
    {
        return (HttpServletRequest) super.getRequest();
    }
    
    public void init(InternalPortletContext portletContext, HttpServletRequest req) 
    {
        this.portletContext = portletContext;
        setRequest(req);
        setCCPPProfile();
        setLifecyclePhase();
    }

    public PortletPreferences getPreferences() 
    {
        if (portletPreferences == null) 
        {
            portletPreferences = new PortletPreferencesImpl(
                    getPortletContainer(),
                    getPortletWindow(),
                    this,
                    this.getRequestMethod());
        }
        return portletPreferences;
    }
    
	/**
     * TODO: Implement this properly.  Not required now
     */
    public void release() 
    {
    	// FIXME: This needs to be implemented
    }
    
    
    // TODO: Additional Methods of HttpServletRequestWrapper -------------------
    
    public BufferedReader getReader()
    throws UnsupportedEncodingException, IOException 
    {
    	// the super class will ensure that a IllegalStateException is thrown
    	//   if getInputStream() was called earlier
    	BufferedReader reader = getHttpServletRequest().getReader();
    	bodyAccessed = true;
    	return reader;
    }
    
    public ServletInputStream getInputStream() throws IOException 
    {
    	ServletInputStream stream = getHttpServletRequest().getInputStream();
    	bodyAccessed = true;
    	return stream;
    }

    public RequestDispatcher getRequestDispatcher(String path) 
    {
        return new ServletRequestDispatcher(getHttpServletRequest().getRequestDispatcher(path));
    }
    
    /**
     * TODO: why check bodyAccessed?
     */
    public void setCharacterEncoding(String encoding)
    throws UnsupportedEncodingException 
    {
        if (bodyAccessed) 
        {
        	throw new IllegalStateException("Cannot set character encoding "
        			+ "after HTTP body is accessed.");
        }
        super.setCharacterEncoding(encoding);
    }
    
    // Private Methods ---------------------------------------------------------
    
    private boolean isPortletModeAllowedByPortlet(PortletMode mode) 
    {
        if (isPortletModeMandatory(mode)) 
        {
            return true;
        }

        PortletDefinition dd = portletWindow.getPortletEntity()
                .getPortletDefinition();

        Iterator mimes = dd.getSupports().iterator();
        while (mimes.hasNext()) 
        {
            Iterator modes = ((Supports) mimes.next()).getPortletModes().iterator();
            while (modes.hasNext()) 
            {
                String m = (String) modes.next();
                if (m.equalsIgnoreCase(mode.toString())) 
                {
                    return true;
                }
            }
        }
        return false;
    }

    private boolean isPortletModeAllowedByPortal(PortletMode mode) 
    {
        Enumeration supportedModes = portalContext.getSupportedPortletModes();
        while (supportedModes.hasMoreElements()) 
        {
            if (supportedModes.nextElement().toString().equalsIgnoreCase(
                    (mode.toString()))) 
            {
                return true;
            }
        }
        return false;
    }

    private boolean isPortletModeMandatory(PortletMode mode) 
    {
        return PortletMode.VIEW.equals(mode) || PortletMode.EDIT.equals(mode) || PortletMode.HELP.equals(mode);
    }


// InternalRenderRequest Impl ----------------------------------------------

    public Cookie[] getCookieProperties() 
    {
        return container.getRequiredContainerServices().getPortalCallbackService().getRequestPropertyProvider().getCookieProperty(getHttpServletRequest(), portletWindow);
    }
    
    public String getMethod()
    {
        return super.getMethod();
    }
    
    
    public boolean isForwarded()
    {
        return forwarded;
    }

    public void setForwarded(boolean forwarded)
    {
        this.forwarded = forwarded;
        if (LOG.isDebugEnabled())
        {
            LOG.debug("Portlet request's forwarded mode: " + forwarded);
        }
    }

    public void setIncluded(boolean included)
    {
        this.included = included;
//        if (!included)
//        {

⌨️ 快捷键说明

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