Example usage for com.liferay.portal.kernel.util JavaConstants JAVAX_PORTLET_PORTLET

List of usage examples for com.liferay.portal.kernel.util JavaConstants JAVAX_PORTLET_PORTLET

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.util JavaConstants JAVAX_PORTLET_PORTLET.

Prototype

String JAVAX_PORTLET_PORTLET

To view the source code for com.liferay.portal.kernel.util JavaConstants JAVAX_PORTLET_PORTLET.

Click Source Link

Usage

From source file:com.liferay.alloy.mvc.BaseAlloyControllerImpl.java

License:Open Source License

protected void initPortletVariables() {
    liferayPortletConfig = (LiferayPortletConfig) request.getAttribute(JavaConstants.JAVAX_PORTLET_CONFIG);

    portletContext = liferayPortletConfig.getPortletContext();

    portlet = liferayPortletConfig.getPortlet();

    alloyPortlet = (AlloyPortlet) request.getAttribute(JavaConstants.JAVAX_PORTLET_PORTLET);

    portletRequest = (PortletRequest) request.getAttribute(JavaConstants.JAVAX_PORTLET_REQUEST);
    portletResponse = (PortletResponse) request.getAttribute(JavaConstants.JAVAX_PORTLET_RESPONSE);

    liferayPortletResponse = (LiferayPortletResponse) portletResponse;

    lifecycle = GetterUtil.getString((String) request.getAttribute(PortletRequest.LIFECYCLE_PHASE));

    if (log.isDebugEnabled()) {
        log.debug("Lifecycle " + lifecycle);
    }//from  w  w w . j a v a2s .  c  o  m

    if (lifecycle.equals(PortletRequest.ACTION_PHASE)) {
        actionRequest = (ActionRequest) portletRequest;
        actionResponse = (ActionResponse) portletResponse;
    } else if (lifecycle.equals(PortletRequest.EVENT_PHASE)) {
        eventRequest = (EventRequest) portletRequest;
        eventResponse = (EventResponse) portletResponse;
    } else if (lifecycle.equals(PortletRequest.RENDER_PHASE)) {
        mimeResponse = (MimeResponse) portletResponse;
        renderRequest = (RenderRequest) portletRequest;
        renderResponse = (RenderResponse) portletResponse;
    } else if (lifecycle.equals(PortletRequest.RESOURCE_PHASE)) {
        mimeResponse = (MimeResponse) portletResponse;
        resourceRequest = (ResourceRequest) portletRequest;
        resourceResponse = (ResourceResponse) portletResponse;
    }
}

From source file:com.liferay.alloy.mvc.jsonwebservice.BaseAlloyControllerInvokerImpl.java

License:Open Source License

protected DynamicServletRequest createRequest(String lifecycle, Object... parameters) throws Exception {

    if ((parameters.length % 2) != 0) {
        throw new IllegalArgumentException("Parameters length is not an even number");
    }/* w ww .  j  a  v  a2  s . c o m*/

    HttpServletRequestWrapper requestWrapper = new HttpServletRequestWrapper(
            new AlloyMockUtil.MockHttpServletRequest());

    DynamicServletRequest request = new DynamicServletRequest(requestWrapper, false);

    for (int i = 0; i < parameters.length; i += 2) {
        request.appendParameter(String.valueOf(parameters[i]), String.valueOf(parameters[i + 1]));
    }

    request.appendParameter("controller", _controller);
    request.appendParameter("format", "json");

    ThemeDisplay themeDisplay = (ThemeDisplay) _themeDisplay.clone();

    PermissionChecker permissionChecker = PermissionThreadLocal.getPermissionChecker();

    User user = UserLocalServiceUtil.getUser(permissionChecker.getUserId());

    themeDisplay.setUser(user);

    request.setAttribute(WebKeys.THEME_DISPLAY, themeDisplay);

    request.setAttribute(WebKeys.LAYOUT, themeDisplay.getLayout());

    LiferayPortletConfig liferayPortletConfig = (LiferayPortletConfig) PortletConfigFactoryUtil.create(_portlet,
            null);

    request.setAttribute(JavaConstants.JAVAX_PORTLET_CONFIG, liferayPortletConfig);

    request.setAttribute(JavaConstants.JAVAX_PORTLET_PORTLET, _alloyPortlet);

    PortletRequest portletRequest = null;
    PortletResponse portletResponse = null;

    if (lifecycle.equals(PortletRequest.ACTION_PHASE)) {
        portletRequest = createActionRequest();
        portletResponse = createActionResponse();
    } else {
        portletRequest = createRenderRequest();
        portletResponse = createRenderResponse(request, _portlet.getRootPortletId(), themeDisplay.getPlid(),
                lifecycle);
    }

    request.setAttribute(JavaConstants.JAVAX_PORTLET_REQUEST, portletRequest);
    request.setAttribute(JavaConstants.JAVAX_PORTLET_RESPONSE, portletResponse);

    request.setAttribute(PortletRequest.LIFECYCLE_PHASE, lifecycle);

    request.setAttribute(BaseAlloyControllerImpl.VIEW_PATH, StringPool.BLANK);

    return request;
}

From source file:com.liferay.faces.bridge.ext.scope.internal.RequestAttributeInspectorLiferayImpl.java

License:Open Source License

/**
 * This is a method-override that provides specific behavior for Liferay Portal. Specifically, since Liferay Portal
 * does not implement the POST-REDIRECT-GET design pattern, not all instance types listed in Section 5.1.2 of the
 * Spec can be candidates for exclusion.
 *///from   w w w .j  av  a2s. c o  m
@Override
public boolean isExcludedByType(String name, Object value) {

    boolean excluded = false;

    if (value != null) {

        if ((value instanceof ExternalContext) || (value instanceof FacesContext)) {

            // Always safe to exclude when running under Liferay Portal.
            excluded = true;
        } else if (value instanceof PortletConfig) {

            // Liferay Portal includes request attribute named "javax.portlet.config" that must not be excluded. It
            // also includes an attribute named "javax.portlet.portlet" that is the current GenericFacesPortlet
            // (which extends GenericPortlet). But since GenericPortlet implements the PortletConfig interface, need
            // to prevent it from being excluded as well.
            if (!JavaConstants.JAVAX_PORTLET_CONFIG.equals(name)
                    && !JavaConstants.JAVAX_PORTLET_PORTLET.equals(name)) {
                excluded = true;
            }
        } else if (value instanceof PortletRequest) {

            // Liferay Portal includes request attribute named "javax.portlet.request" that must not be excluded.
            if (!JavaConstants.JAVAX_PORTLET_REQUEST.equals(name)) {
                excluded = true;
            }
        } else if (value instanceof PortletResponse) {

            // Liferay Portal includes request attribute named "javax.portlet.response" that must not be excluded.
            if (!JavaConstants.JAVAX_PORTLET_RESPONSE.equals(name)) {
                excluded = true;
            }
        } else if ((value instanceof PortalContext) || (value instanceof PortletContext)
                || (value instanceof PortletPreferences) || (value instanceof PortletSession)) {

            excluded = true;
        } else if ((value instanceof HttpSession) || (value instanceof ServletConfig)
                || (value instanceof ServletContext) || (value instanceof ServletRequest)
                || (value instanceof ServletResponse)) {

            // Can only exclude attributes that are not Liferay objects. For example, Liferay Portal includes
            // a request attribute named "com.liferay.portal.kernel.servlet.PortletServletRequest" that must not be
            // excluded.
            if (!value.getClass().getName().startsWith("com.liferay")) {
                excluded = true;
            }
        }
    }

    return excluded;
}

From source file:com.liferay.faces.bridge.scope.BridgeRequestScopeLiferayImpl.java

License:Open Source License

/**
 * This is a method-override that provides specific behavior for Liferay Portal. Specifically, since Liferay Portal
 * does not implement the POST-REDIRECT-GET design pattern, not all instance types listed in Section 5.1.2 of the
 * Spec can be candidates for exclusion.
 *//*from ww  w .j  a v a 2s  .c om*/
@Override
protected boolean isExcludedRequestAttributeByInstance(String attributeName, Object attributeValue) {

    boolean excluded = false;

    if (attributeValue != null) {

        if ((attributeValue instanceof ExternalContext) || (attributeValue instanceof FacesContext)) {

            // Always safe to exclude when running under Liferay Portal.
            excluded = true;
        } else if (attributeValue instanceof PortletConfig) {

            // Liferay Portal includes request attribute named "javax.portlet.config" that must not be excluded. It
            // also includes an attribute named "javax.portlet.portlet" that is the current GenericFacesPortlet
            // (which extends GenericPortlet). But since GenericPortlet implements the PortletConfig interface, need
            // to prevent it from being excluded as well.
            if (!JavaConstants.JAVAX_PORTLET_CONFIG.equals(attributeName)
                    && !JavaConstants.JAVAX_PORTLET_PORTLET.equals(attributeName)) {
                excluded = true;
            }
        } else if (attributeValue instanceof PortletRequest) {

            // Liferay Portal includes request attribute named "javax.portlet.request" that must not be excluded.
            if (!JavaConstants.JAVAX_PORTLET_REQUEST.equals(attributeName)) {
                excluded = true;
            }
        } else if (attributeValue instanceof PortletResponse) {

            // Liferay Portal includes request attribute named "javax.portlet.response" that must not be excluded.
            if (!JavaConstants.JAVAX_PORTLET_RESPONSE.equals(attributeName)) {
                excluded = true;
            }
        } else if ((attributeValue instanceof PortalContext) || (attributeValue instanceof PortletContext)
                || (attributeValue instanceof PortletPreferences)
                || (attributeValue instanceof PortletSession)) {

            excluded = true;
        } else if ((attributeValue instanceof HttpSession) || (attributeValue instanceof ServletConfig)
                || (attributeValue instanceof ServletContext) || (attributeValue instanceof ServletRequest)
                || (attributeValue instanceof ServletResponse)) {

            // Can only exclude attributes that are not Liferay objects. For example, Liferay Portal includes
            // a request attribute named "com.liferay.portal.kernel.servlet.PortletServletRequest" that must not be
            // excluded.
            if (!attributeValue.getClass().getName().startsWith(LiferayConstants.PACKAGE_NAMESPACE)) {
                excluded = true;
            }
        }
    }

    return excluded;
}

From source file:com.liferay.faces.bridge.scope.internal.BridgeRequestScopeLiferayImpl.java

License:Open Source License

/**
 * This is a method-override that provides specific behavior for Liferay Portal. Specifically, since Liferay Portal
 * does not implement the POST-REDIRECT-GET design pattern, not all instance types listed in Section 5.1.2 of the
 * Spec can be candidates for exclusion.
 *//*  w w w. j a  va  2  s  .c o m*/
@Override
protected boolean isExcludedRequestAttributeByInstance(String attributeName, Object attributeValue) {

    boolean excluded = false;

    if (attributeValue != null) {

        if ((attributeValue instanceof ExternalContext) || (attributeValue instanceof FacesContext)) {

            // Always safe to exclude when running under Liferay Portal.
            excluded = true;
        } else if (attributeValue instanceof PortletConfig) {

            // Liferay Portal includes request attribute named "javax.portlet.config" that must not be excluded. It
            // also includes an attribute named "javax.portlet.portlet" that is the current GenericFacesPortlet
            // (which extends GenericPortlet). But since GenericPortlet implements the PortletConfig interface, need
            // to prevent it from being excluded as well.
            if (!JavaConstants.JAVAX_PORTLET_CONFIG.equals(attributeName)
                    && !JavaConstants.JAVAX_PORTLET_PORTLET.equals(attributeName)) {
                excluded = true;
            }
        } else if (attributeValue instanceof PortletRequest) {

            // Liferay Portal includes request attribute named "javax.portlet.request" that must not be excluded.
            if (!JavaConstants.JAVAX_PORTLET_REQUEST.equals(attributeName)) {
                excluded = true;
            }
        } else if (attributeValue instanceof PortletResponse) {

            // Liferay Portal includes request attribute named "javax.portlet.response" that must not be excluded.
            if (!JavaConstants.JAVAX_PORTLET_RESPONSE.equals(attributeName)) {
                excluded = true;
            }
        } else if ((attributeValue instanceof PortalContext) || (attributeValue instanceof PortletContext)
                || (attributeValue instanceof PortletPreferences)
                || (attributeValue instanceof PortletSession)) {

            excluded = true;
        } else if ((attributeValue instanceof HttpSession) || (attributeValue instanceof ServletConfig)
                || (attributeValue instanceof ServletContext) || (attributeValue instanceof ServletRequest)
                || (attributeValue instanceof ServletResponse)) {

            // Can only exclude attributes that are not Liferay objects. For example, Liferay Portal includes
            // a request attribute named "com.liferay.portal.kernel.servlet.PortletServletRequest" that must not be
            // excluded.
            if (!attributeValue.getClass().getName().startsWith("com.liferay")) {
                excluded = true;
            }
        }
    }

    return excluded;
}

From source file:com.liferay.portlet.InvokerPortletImpl.java

License:Open Source License

protected void invoke(LiferayPortletRequest portletRequest, LiferayPortletResponse portletResponse,
        String lifecycle, List<? extends PortletFilter> filters) throws IOException, PortletException {

    FilterChain filterChain = new FilterChainImpl(_portlet, filters);

    if (_portletConfigImpl.isWARFile()) {
        String invokerPortletName = _portletConfigImpl.getInitParameter(INIT_INVOKER_PORTLET_NAME);

        if (invokerPortletName == null) {
            invokerPortletName = _portletConfigImpl.getPortletName();
        }/*www.ja  v  a2s .c  o m*/

        String path = StringPool.SLASH + invokerPortletName + "/invoke";

        RequestDispatcher requestDispatcher = _portletContextImpl.getServletContext()
                .getRequestDispatcher(path);

        HttpServletRequest request = portletRequest.getHttpServletRequest();
        HttpServletResponse response = portletResponse.getHttpServletResponse();

        request.setAttribute(JavaConstants.JAVAX_PORTLET_PORTLET, _portlet);
        request.setAttribute(PortletRequest.LIFECYCLE_PHASE, lifecycle);
        request.setAttribute(PortletServlet.PORTLET_SERVLET_FILTER_CHAIN, filterChain);

        try {

            // Resource phase must be a forward because includes do not
            // allow you to specify the content type or headers

            if (lifecycle.equals(PortletRequest.RESOURCE_PHASE)) {
                requestDispatcher.forward(request, response);
            } else {
                requestDispatcher.include(request, response);
            }
        } catch (ServletException se) {
            Throwable cause = se.getRootCause();

            if (cause instanceof PortletException) {
                throw (PortletException) cause;
            }

            throw new PortletException(cause);
        }
    } else {
        PortletFilterUtil.doFilter(portletRequest, portletResponse, lifecycle, filterChain);
    }

    portletResponse.transferMarkupHeadElements();

    Map<String, String[]> properties = portletResponse.getProperties();

    if ((properties != null) && (properties.size() > 0)) {
        if (_expCache != null) {
            String[] expCache = properties.get(RenderResponse.EXPIRATION_CACHE);

            if ((expCache != null) && (expCache.length > 0) && (expCache[0] != null)) {

                _expCache = new Integer(GetterUtil.getInteger(expCache[0]));
            }
        }
    }
}