Search in sources :

Example 26 with Product

use of com.liferay.faces.util.product.Product in project liferay-faces-bridge-ext by liferay.

the class ResourceHandlerLiferayImpl method isJQueryPluginJSResource.

private boolean isJQueryPluginJSResource(String resourceLibrary, String resourceName) {
    FacesContext startupFacesContext = FacesContext.getCurrentInstance();
    ExternalContext externalContext = startupFacesContext.getExternalContext();
    ProductFactory productFactory = (ProductFactory) FactoryExtensionFinder.getFactory(externalContext, ProductFactory.class);
    final Product BOOTSFACES = productFactory.getProductInfo(Product.Name.BOOTSFACES);
    boolean bootsFacesJQueryPluginJSResource = BOOTSFACES.isDetected() && "bsf".equals(resourceLibrary) && BOOTSFACES_JQUERY_PLUGIN_JS_RESOURCES.contains(resourceName);
    boolean butterFacesJQueryPluginJSResource = false;
    final Product BUTTERFACES = productFactory.getProductInfo(Product.Name.BUTTERFACES);
    if (BUTTERFACES.isDetected() && (resourceLibrary != null)) {
        butterFacesJQueryPluginJSResource = (resourceLibrary.equals("butterfaces-dist-bower") && BUTTERFACES_DIST_BOWER_JQUERY_PLUGIN_JS_RESOURCES.contains(resourceName)) || (resourceLibrary.equals("butterfaces-dist-bundle-js") && BUTTERFACES_DIST_BUNDLE_JS_JQUERY_PLUGIN_JS_RESOURCES.contains(resourceName)) || (resourceLibrary.equals("butterfaces-external") && BUTTERFACES_EXTERNAL_JQUERY_PLUGIN_JS_RESOURCES.contains(resourceName));
    }
    final Product PRIMEFACES = productFactory.getProductInfo(Product.Name.PRIMEFACES);
    boolean primeFacesJQueryPluginJSResource = PRIMEFACES.isDetected() && ((resourceLibrary == null) || resourceLibrary.equals("primefaces")) && PRIMEFACES_JQUERY_PLUGIN_JS_RESOURCES.contains(resourceName);
    boolean richFacesJQueryPluginJSResource = false;
    final Product RICHFACES = productFactory.getProductInfo(Product.Name.RICHFACES);
    if (RICHFACES.isDetected()) {
        boolean richfacesResourceLibrary = ("org.richfaces.resource".equals(resourceLibrary) || "org.richfaces.staticResource".equals(resourceLibrary) || "org.richfaces".equals(resourceLibrary));
        richFacesJQueryPluginJSResource = ((resourceLibrary == null) || richfacesResourceLibrary) && (resourceName.endsWith("packed.js") || resourceName.endsWith("jquery.js"));
    }
    return (bootsFacesJQueryPluginJSResource || butterFacesJQueryPluginJSResource || primeFacesJQueryPluginJSResource || richFacesJQueryPluginJSResource);
}
Also used : FacesContext(javax.faces.context.FacesContext) ProductFactory(com.liferay.faces.util.product.ProductFactory) ExternalContext(javax.faces.context.ExternalContext) Product(com.liferay.faces.util.product.Product)

Example 27 with Product

use of com.liferay.faces.util.product.Product in project liferay-faces-bridge-ext by liferay.

the class LiferayURLGeneratorBaseImpl method generateURL.

public String generateURL(Map<String, String[]> additionalParameterMap, String cacheability, PortletMode portletMode, String resourceId, WindowState windowState) {
    String toStringValue;
    if (baseURL.contains(Portal.FRIENDLY_URL_SEPARATOR)) {
        toStringValue = baseURL;
    } else {
        StringBuilder url = new StringBuilder();
        // Build up a new URL string based on the one returned by Liferay, but discard everything after the
        // question mark because it's filled with all kinds of unnecessary stuff.
        url.append(prefix);
        // Possibly add the p_auth parameter.
        boolean firstParameter = true;
        String portalAuthToken = StringHelper.toString(additionalParameterMap.get(P_AUTH), parameterMap.get(P_AUTH));
        if (portalAuthToken != null) {
            appendParameterToURL(firstParameter, P_AUTH, portalAuthToken, url);
            firstParameter = false;
        }
        // Possibly add the p_l_id parameter.
        String plid = StringHelper.toString(additionalParameterMap.get(P_L_ID), parameterMap.get(P_L_ID));
        if (plid != null) {
            appendParameterToURL(firstParameter, P_L_ID, plid, url);
            firstParameter = false;
        }
        // Possibly add the p_p_auth parameter.
        String portletAuthToken = StringHelper.toString(additionalParameterMap.get(P_P_AUTH), parameterMap.get(P_P_AUTH));
        FacesContext facesContext = FacesContext.getCurrentInstance();
        ExternalContext externalContext = facesContext.getExternalContext();
        if (portletAuthToken != null) {
            boolean addPortletAuthToken = true;
            final Product LIFERAY_PORTAL = ProductFactory.getProductInstance(externalContext, Product.Name.LIFERAY_PORTAL);
            final int LIFERAY_BUILD_NUMBER = LIFERAY_PORTAL.getBuildId();
            if ((LIFERAY_BUILD_NUMBER < 6102) || ((LIFERAY_BUILD_NUMBER > 6102) && (LIFERAY_BUILD_NUMBER < 6130))) {
                // Versions of Liferay Portal prior to 6.1.2-CE/6.1.30-EE suffered from LPS-36481 which caused
                // PortletURLImpl.addPortletAuthToken(StringBundle, Key) method to add the p_p_auth parameter to
                // URLs for portlets when add-default-resource=false. It is therefore necessary to check that
                // add-default-resource=true before adding the p_p_auth parameter to the URL.
                PortletRequest portletRequest = (PortletRequest) externalContext.getRequest();
                String portletId = (String) portletRequest.getAttribute(WebKeys.PORTLET_ID);
                ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY);
                try {
                    Portlet portlet = PortletLocalServiceUtil.getPortletById(themeDisplay.getCompanyId(), portletId);
                    addPortletAuthToken = portlet.isAddDefaultResource();
                } catch (SystemException e) {
                    logger.error(e);
                }
            }
            if (addPortletAuthToken) {
                appendParameterToURL(firstParameter, P_P_AUTH, portletAuthToken, url);
                firstParameter = false;
            }
        }
        // Always add the p_p_id parameter
        String parameterValue = StringHelper.toString(additionalParameterMap.get(P_P_ID), responseNamespace);
        if (parameterValue.startsWith("_")) {
            parameterValue = parameterValue.substring(1);
        }
        if (parameterValue.endsWith("_")) {
            parameterValue = parameterValue.substring(0, parameterValue.length() - 1);
        }
        appendParameterToURL(firstParameter, P_P_ID, parameterValue, url);
        firstParameter = false;
        // Always add the p_p_lifecycle parameter.
        String portletLifecycleId = getPortletLifecycleId();
        appendParameterToURL(P_P_LIFECYCLE, portletLifecycleId, url);
        // Add the p_p_state parameter.
        Map<String, Object> applicationMap = externalContext.getApplicationMap();
        WindowState urlWindowState = initialWindowState;
        if (additionalParameterMap.get(P_P_STATE) != null) {
            urlWindowState = new WindowState(additionalParameterMap.get(P_P_STATE)[0]);
        }
        if (windowState != null) {
            urlWindowState = windowState;
        }
        if (urlWindowState == null) {
            parameterValue = (String) applicationMap.get(responseNamespace + P_P_STATE);
        } else {
            parameterValue = urlWindowState.toString();
        }
        appendParameterToURL(P_P_STATE, parameterValue, url);
        // Possibly add the p_p_state_rcv parameter.
        String stateRestoreCurrentView = StringHelper.toString(additionalParameterMap.get(P_P_STATE_RCV), parameterMap.get(P_P_STATE_RCV));
        if (stateRestoreCurrentView != null) {
            appendParameterToURL(P_P_STATE_RCV, stateRestoreCurrentView, url);
        }
        // Add the p_p_mode parameter.
        PortletMode urlPortletMode = initialPortletMode;
        if (additionalParameterMap.get(P_P_MODE) != null) {
            urlPortletMode = new PortletMode(additionalParameterMap.get(P_P_MODE)[0]);
        }
        if (portletMode != null) {
            urlPortletMode = portletMode;
        }
        if (urlPortletMode == null) {
            parameterValue = (String) applicationMap.get(responseNamespace + P_P_MODE);
        } else {
            parameterValue = urlPortletMode.toString();
        }
        appendParameterToURL(P_P_MODE, parameterValue, url);
        // Possibly add the p_p_cacheability parameter
        if (LIFECYCLE_RESOURCE_PHASE_ID.equals(portletLifecycleId)) {
            String urlCacheability = null;
            if (cacheability != null) {
                urlCacheability = cacheability;
            }
            if (urlCacheability == null) {
                urlCacheability = StringHelper.toString(additionalParameterMap.get(P_P_CACHEABILITY), parameterMap.get(P_P_CACHEABILITY));
            }
            if (urlCacheability != null) {
                appendParameterToURL(P_P_CACHEABILITY, urlCacheability, url);
            }
        }
        // Always add the p_p_col_id parameter
        parameterValue = (String) applicationMap.get(responseNamespace + P_P_COL_ID);
        appendParameterToURL(P_P_COL_ID, parameterValue, url);
        // Possibly add the p_p_col_count parameter.
        parameterValue = (String) applicationMap.get(responseNamespace + P_P_COL_COUNT);
        appendParameterToURL(P_P_COL_COUNT, parameterValue, url);
        // Add the p_p_col_pos parameter if it is greater than zero (same logic as Liferay's
        // PortletURLImpl.toString())
        parameterValue = (String) applicationMap.get(responseNamespace + P_P_COL_POS);
        if ((parameterValue != null) && (parameterValue.length() > 0)) {
            try {
                int colPos = Integer.parseInt(parameterValue);
                if (colPos > 0) {
                    appendParameterToURL(P_P_COL_POS, parameterValue, url);
                }
            } catch (NumberFormatException e) {
            // ignore
            }
        }
        // Possibly add the p_o_p_id parameter.
        String outerPortletId = StringHelper.toString(additionalParameterMap.get(P_O_P_ID), parameterMap.get(P_O_P_ID));
        if (outerPortletId != null) {
            appendParameterToURL(P_O_P_ID, outerPortletId, url);
        }
        // Possibly add the doAsUserId parameter.
        String doAsUserId = StringHelper.toString(additionalParameterMap.get(DO_AS_USER_ID), parameterMap.get(DO_AS_USER_ID));
        if (doAsUserId != null) {
            appendParameterToURL(DO_AS_USER_ID, doAsUserId, url);
        }
        // Possibly add the doAsUserLanguageId parameter.
        String doAsUserLanguageId = StringHelper.toString(additionalParameterMap.get(DO_AS_USER_LANGUAGE_ID), parameterMap.get(DO_AS_USER_LANGUAGE_ID));
        if (doAsUserLanguageId != null) {
            appendParameterToURL(DO_AS_USER_LANGUAGE_ID, doAsUserLanguageId, url);
        }
        // Possibly add the doAsGroupId parameter.
        String doAsGroupId = StringHelper.toString(additionalParameterMap.get(DO_AS_GROUP_ID), parameterMap.get(DO_AS_GROUP_ID));
        if (doAsGroupId != null) {
            appendParameterToURL(DO_AS_GROUP_ID, doAsGroupId, url);
        }
        // Possibly add the refererGroupId parameter.
        String refererGroupId = StringHelper.toString(additionalParameterMap.get(REFERER_GROUP_ID), parameterMap.get(REFERER_GROUP_ID));
        if (refererGroupId != null) {
            appendParameterToURL(REFERER_GROUP_ID, refererGroupId, url);
        }
        // Possibly add the refererPlid parameter.
        String refererPlid = StringHelper.toString(additionalParameterMap.get(REFERER_PLID), parameterMap.get(REFERER_PLID));
        if (refererPlid != null) {
            appendParameterToURL(REFERER_PLID, refererPlid, url);
        }
        // Possibly add the controlPanelCategory parameter.
        String controlPanelCategory = StringHelper.toString(additionalParameterMap.get(CONTROL_PANEL_CATEGORY), parameterMap.get(CONTROL_PANEL_CATEGORY));
        if (controlPanelCategory != null) {
            appendParameterToURL(CONTROL_PANEL_CATEGORY, controlPanelCategory, url);
        }
        // Add request parameters from the request parameter map.
        boolean namespaced = !responseNamespace.startsWith("wsrp");
        Set<Map.Entry<String, String[]>> mapEntries = additionalParameterMap.entrySet();
        if (mapEntries != null) {
            for (Map.Entry<String, String[]> mapEntry : mapEntries) {
                String[] parameterValues = mapEntry.getValue();
                if (parameterValues != null) {
                    String parameterName = mapEntry.getKey();
                    if (!LIFERAY_NON_NAMESPACED_PARAMS.contains(parameterName)) {
                        for (String curParameterValue : parameterValues) {
                            if (curParameterValue != null) {
                                appendParameterToURL(firstParameter, namespaced, parameterName, curParameterValue, url);
                            }
                        }
                    }
                }
            }
        }
        // Add WSRP URL parameters
        for (LiferayURLParameter wsrpParameter : wsrpParameters) {
            appendParameterToURL(wsrpParameter.getName(), wsrpParameter.getValue(), url);
        }
        // Possibly add the p_p_resource_id parameter.
        String urlResourceId = parameterMap.get(P_O_P_ID);
        if (resourceId != null) {
            urlResourceId = resourceId;
        }
        if (urlResourceId == null) {
            if (prefix.startsWith("wsrp")) {
                appendParameterToURL(P_P_RESOURCE_ID, "wsrp", url);
            }
        } else {
            appendParameterToURL(P_P_RESOURCE_ID, urlResourceId, url);
        }
        // Possibly add a Portlet URL Anchor
        if (portletURLAnchor != null) {
            url.append(portletURLAnchor);
        }
        toStringValue = url.toString();
    }
    return toStringValue;
}
Also used : WindowState(javax.portlet.WindowState) FacesContext(javax.faces.context.FacesContext) Portlet(com.liferay.portal.kernel.model.Portlet) Product(com.liferay.faces.util.product.Product) PortletMode(javax.portlet.PortletMode) PortletRequest(javax.portlet.PortletRequest) SystemException(com.liferay.portal.kernel.exception.SystemException) ExternalContext(javax.faces.context.ExternalContext) ThemeDisplay(com.liferay.portal.kernel.theme.ThemeDisplay) HashMap(java.util.HashMap) Map(java.util.Map)

Example 28 with Product

use of com.liferay.faces.util.product.Product in project liferay-faces-bridge-ext by liferay.

the class PortletRequestDispatcherBridgeLiferayImpl method include.

@Override
public void include(PortletRequest portletRequest, PortletResponse portletResponse) throws PortletException, IOException {
    boolean unwrapRequest = false;
    PortletSession portletSession = portletRequest.getPortletSession();
    PortletContext portletContext = portletSession.getPortletContext();
    ProductFactory productFactory = (ProductFactory) BridgeFactoryFinder.getFactory(portletContext, ProductFactory.class);
    final Product LIFERAY_PORTAL = productFactory.getProductInfo(Product.Name.LIFERAY_PORTAL);
    final int LIFERAY_PORTAL_MAJOR_VERSION = LIFERAY_PORTAL.getMajorVersion();
    // For more info, see https://issues.liferay.com/browse/LPS-3311
    if (LIFERAY_PORTAL_MAJOR_VERSION < 6) {
        unwrapRequest = true;
    } else // https://github.com/liferay/liferay-portal/commit/093dabbb252e2bba5404cddbcb600d787ef0b010
    if (LIFERAY_PORTAL_MAJOR_VERSION == 6) {
        final int LIFERAY_PORTAL_MINOR_VERSION = LIFERAY_PORTAL.getMinorVersion();
        if (LIFERAY_PORTAL_MINOR_VERSION == 0) {
            unwrapRequest = true;
        } else if (LIFERAY_PORTAL_MINOR_VERSION == 1) {
            final int LIFERAY_PORTAL_PATCH_VERSION = LIFERAY_PORTAL.getPatchVersion();
            // CE
            if (LIFERAY_PORTAL_PATCH_VERSION < 10) {
                unwrapRequest = (LIFERAY_PORTAL_PATCH_VERSION < 2);
            } else // EE
            if (LIFERAY_PORTAL_PATCH_VERSION < 30) {
                unwrapRequest = true;
            }
        }
    }
    if (unwrapRequest) {
        portletRequest = unwrapPortletRequest(portletRequest);
    }
    // PortletResponseWrapper.
    if ((portletResponse instanceof HttpServletResponseWrapper) || (portletResponse instanceof PortletResponseWrapper)) {
        portletResponse = unwrapPortletResponse(portletResponse);
    }
    super.include(portletRequest, portletResponse);
}
Also used : ProductFactory(com.liferay.faces.util.product.ProductFactory) PortletSession(javax.portlet.PortletSession) HttpServletResponseWrapper(javax.servlet.http.HttpServletResponseWrapper) Product(com.liferay.faces.util.product.Product) PortletContext(javax.portlet.PortletContext) PortletResponseWrapper(javax.portlet.filter.PortletResponseWrapper)

Example 29 with Product

use of com.liferay.faces.util.product.Product in project liferay-faces-bridge-ext by liferay.

the class BridgeExtDependencyVerifier method verify.

public static void verify(ExternalContext externalContext) {
    ProductFactory productFactory = (ProductFactory) FactoryExtensionFinder.getFactory(externalContext, ProductFactory.class);
    final Product LIFERAY_PORTAL = productFactory.getProductInfo(Product.Name.LIFERAY_PORTAL);
    Package bridgeExtPackage = BridgeExtDependencyVerifier.class.getPackage();
    String implementationTitle = bridgeExtPackage.getImplementationTitle();
    String implementationVersion = bridgeExtPackage.getImplementationVersion();
    final int LIFERAY_PORTAL_MAJOR_VERSION = LIFERAY_PORTAL.getMajorVersion();
    final int LIFERAY_PORTAL_MINOR_VERSION = LIFERAY_PORTAL.getMinorVersion();
    if (!((LIFERAY_PORTAL_MAJOR_VERSION == 7) && (LIFERAY_PORTAL_MINOR_VERSION >= 2))) {
        logger.error("{0} {1} is designed to be used with Liferay Portal 7.2+ but detected {2}.{3}", implementationTitle, implementationVersion, LIFERAY_PORTAL_MAJOR_VERSION, LIFERAY_PORTAL_MINOR_VERSION);
    }
    final Product JSF = productFactory.getProductInfo(Product.Name.JSF);
    final int JSF_MAJOR_VERSION = JSF.getMajorVersion();
    final int JSF_MINOR_VERSION = JSF.getMinorVersion();
    if (!((JSF_MAJOR_VERSION == 2) && (JSF_MINOR_VERSION == 3))) {
        logger.error("{0} {1} is designed to be used with JSF 2.3 but detected {2}.{3}", implementationTitle, implementationVersion, JSF_MAJOR_VERSION, JSF_MINOR_VERSION);
    }
}
Also used : ProductFactory(com.liferay.faces.util.product.ProductFactory) Product(com.liferay.faces.util.product.Product)

Aggregations

Product (com.liferay.faces.util.product.Product)29 ExternalContext (javax.faces.context.ExternalContext)19 ProductFactory (com.liferay.faces.util.product.ProductFactory)12 FacesContext (javax.faces.context.FacesContext)7 PortletContext (javax.portlet.PortletContext)5 List (java.util.List)4 MultiPartFormData (com.liferay.faces.util.context.map.MultiPartFormData)3 ArrayList (java.util.ArrayList)3 ResponseWriter (javax.faces.context.ResponseWriter)3 PortletRequest (javax.portlet.PortletRequest)3 ConfiguredServletMapping (com.liferay.faces.util.config.ConfiguredServletMapping)2 FacesRequestParameterMap (com.liferay.faces.util.context.map.FacesRequestParameterMap)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 UIComponent (javax.faces.component.UIComponent)2 UIViewRoot (javax.faces.component.UIViewRoot)2 PortalContext (javax.portlet.PortalContext)2 PortletResponse (javax.portlet.PortletResponse)2 PortletSession (javax.portlet.PortletSession)2 BridgePortalContext (com.liferay.faces.bridge.context.BridgePortalContext)1