use of com.liferay.faces.util.product.Product in project liferay-faces-bridge-impl by liferay.
the class HeadRendererBridgeImpl method encodeChildren.
@Override
public void encodeChildren(FacesContext facesContext, UIComponent uiComponent) throws IOException {
// Build up a list of components that are intended for the <head> section of the portal page.
UIViewRoot uiViewRoot = facesContext.getViewRoot();
List<UIComponent> headResources = new ArrayList<UIComponent>();
// Add the list of components that are to appear first.
List<UIComponent> firstResources = getFirstResources(facesContext, uiComponent);
if (firstResources != null) {
headResources.addAll(firstResources);
}
// Sort the components that are in the view root into stylesheets, scripts, and other.
List<UIComponent> headComponentResources = uiViewRoot.getComponentResources(facesContext, "head");
ExternalContext externalContext = facesContext.getExternalContext();
final Product BOOTSFACES = ProductFactory.getProductInstance(externalContext, Product.Name.BOOTSFACES);
final boolean BOOTSFACES_DETECTED = BOOTSFACES.isDetected();
List<UIComponent> styleSheetResources = new ArrayList<UIComponent>();
List<UIComponent> scriptResources = new ArrayList<UIComponent>();
List<UIComponent> otherHeadResources = new ArrayList<UIComponent>();
for (UIComponent headComponentResource : headComponentResources) {
if (RenderKitUtil.isStyleSheetResource(headComponentResource, BOOTSFACES_DETECTED) || isInlineStyleSheet(headComponentResource)) {
styleSheetResources.add(headComponentResource);
} else if (RenderKitUtil.isScriptResource(headComponentResource, BOOTSFACES_DETECTED) || isInlineScript(headComponentResource)) {
scriptResources.add(headComponentResource);
} else {
// Other head resources include <base>, <meta>, and <noscript> elments as well as passthrough <link>,
// <style>, and <script> elements.
otherHeadResources.add(headComponentResource);
}
}
// Sort children into stylesheets, scripts, and other.
List<UIComponent> children = uiComponent.getChildren();
for (UIComponent child : children) {
if (RenderKitUtil.isStyleSheetResource(child, BOOTSFACES_DETECTED) || isInlineStyleSheet(child)) {
styleSheetResources.add(child);
} else if (RenderKitUtil.isScriptResource(child, BOOTSFACES_DETECTED) || isInlineScript(child)) {
scriptResources.add(child);
} else {
// Other head resources include <base>, <meta>, and <noscript> elments as well as passthrough <link>,
// <style>, and <script> elements.
otherHeadResources.add(child);
}
}
if (!otherHeadResources.isEmpty()) {
headResources.addAll(otherHeadResources);
}
// Add the list of stylesheet components that are in the view root.
if (!styleSheetResources.isEmpty()) {
headResources.addAll(styleSheetResources);
}
// Add the list of components that are to appear in the middle.
List<UIComponent> middleResources = getMiddleResources(facesContext, uiComponent);
if (middleResources != null) {
headResources.addAll(middleResources);
}
// Add the list of script components that are in the view root.
if (!scriptResources.isEmpty()) {
headResources.addAll(scriptResources);
}
// Add the list of components that are to appear last.
List<UIComponent> lastResources = getLastResources(facesContext, uiComponent);
if (lastResources != null) {
headResources.addAll(lastResources);
}
List<UIComponent> headResourcesToRenderInBody = new ArrayList<UIComponent>();
PortletRequest portletRequest = (PortletRequest) externalContext.getRequest();
PortalContext portalContext = portletRequest.getPortalContext();
Iterator<UIComponent> iterator = headResources.iterator();
while (iterator.hasNext()) {
UIComponent headResource = iterator.next();
// portal page, then
if (!ableToAddResourceToHead(portalContext, headResource, BOOTSFACES_DETECTED)) {
// Add it to the list of resources that are to be rendered in the body section by the body renderer.
headResourcesToRenderInBody.add(headResource);
// Remove it from the list of resources that are to be rendered in the head section by this renderer.
iterator.remove();
if (logger.isDebugEnabled()) {
Map<String, Object> componentResourceAttributes = headResource.getAttributes();
logger.debug("Relocating resource to body: name=[{0}] library=[{1}] rendererType=[{2}] value=[{3}] className=[{4}]", componentResourceAttributes.get("name"), componentResourceAttributes.get("library"), headResource.getRendererType(), ComponentUtil.getComponentValue(headResource), headResource.getClass().getName());
}
}
}
// Save the list of resources that are to be rendered in the body section so that the body renderer can find it.
Map<Object, Object> facesContextAttributes = facesContext.getAttributes();
facesContextAttributes.put(RenderKitUtil.HEAD_RESOURCES_TO_RENDER_IN_BODY, headResourcesToRenderInBody);
if (!headResources.isEmpty()) {
// Save a temporary reference to the ResponseWriter provided by the FacesContext.
ResponseWriter responseWriterBackup = facesContext.getResponseWriter();
// Replace the ResponseWriter in the FacesContext with a HeadResponseWriter that knows how to write to
// the <head>...</head> section of the rendered portal page.
ResponseWriter headResponseWriter = (ResponseWriter) portletRequest.getAttribute("com.liferay.faces.bridge.HeadResponseWriter");
if (headResponseWriter == null) {
PortletResponse portletResponse = (PortletResponse) externalContext.getResponse();
PortletContext portletContext = (PortletContext) externalContext.getContext();
headResponseWriter = HeadResponseWriterFactory.getHeadResponseWriterInstance(responseWriterBackup, portletContext, portletResponse);
}
portletRequest.setAttribute("com.liferay.faces.bridge.HeadResponseWriter", headResponseWriter);
facesContext.setResponseWriter(headResponseWriter);
Set<String> headResourceIds = RenderKitUtil.getHeadResourceIds(facesContext);
for (UIComponent headResource : headResources) {
headResource.encodeAll(facesContext);
if (RenderKitUtil.isScriptResource(headResource, BOOTSFACES_DETECTED) || RenderKitUtil.isStyleSheetResource(headResource, BOOTSFACES_DETECTED)) {
headResourceIds.add(ResourceUtil.getResourceId(headResource));
}
}
// Restore the temporary ResponseWriter reference.
facesContext.setResponseWriter(responseWriterBackup);
}
}
use of com.liferay.faces.util.product.Product in project liferay-faces-bridge-impl by liferay.
the class FacesRuntimeUtil method isNamespacedViewStateSupported.
private static boolean isNamespacedViewStateSupported(ProductFactory productFactory) {
boolean namespacedViewStateSupported = false;
final Product MOJARRA = productFactory.getProductInfo(Product.Name.MOJARRA);
final Product JSF = productFactory.getProductInfo(Product.Name.JSF);
int jsfMajorVersion = JSF.getMajorVersion();
if (MOJARRA.isDetected()) {
int mojarraMajorVersion = MOJARRA.getMajorVersion();
if (mojarraMajorVersion == 2) {
int mojarraMinorVersion = MOJARRA.getMinorVersion();
if (mojarraMinorVersion == 1) {
namespacedViewStateSupported = (MOJARRA.getPatchVersion() >= 27);
} else if (mojarraMinorVersion == 2) {
namespacedViewStateSupported = (MOJARRA.getPatchVersion() >= 4);
} else if (mojarraMinorVersion > 2) {
namespacedViewStateSupported = true;
}
} else if (mojarraMajorVersion > 2) {
namespacedViewStateSupported = true;
}
} else if ((jsfMajorVersion > 2) || ((jsfMajorVersion == 2) && (JSF.getMinorVersion() >= 3))) {
namespacedViewStateSupported = true;
}
logger.debug("JSF runtime [{0}] version [{1}].[{2}].[{3}] supports namespacing [{4}]: [{5}]", JSF.getTitle(), jsfMajorVersion, JSF.getMinorVersion(), JSF.getPatchVersion(), ResponseStateManager.VIEW_STATE_PARAM, namespacedViewStateSupported);
return namespacedViewStateSupported;
}
use of com.liferay.faces.util.product.Product in project liferay-faces-bridge-impl by liferay.
the class RenderKitBridgeImpl method getRenderer.
@Override
public Renderer getRenderer(String family, String rendererType) {
FacesContext facesContext = FacesContext.getCurrentInstance();
ExternalContext externalContext = facesContext.getExternalContext();
ProductFactory productFactory = (ProductFactory) FactoryExtensionFinder.getFactory(externalContext, ProductFactory.class);
final Product PRIMEFACES = productFactory.getProductInfo(Product.Name.PRIMEFACES);
final boolean PRIMEFACES_DETECTED = PRIMEFACES.isDetected();
Renderer renderer = super.getRenderer(family, rendererType);
if (UIOutput.COMPONENT_FAMILY.equals(family)) {
if (JAVAX_FACES_HEAD.equals(rendererType)) {
final Product ICEFACES = productFactory.getProductInfo(Product.Name.ICEFACES);
final boolean ICEFACES_DETECTED = ICEFACES.isDetected();
if (ICEFACES_DETECTED) {
renderer = new HeadRendererICEfacesImpl();
} else if (PRIMEFACES_DETECTED) {
renderer = new HeadRendererPrimeFacesImpl();
} else {
renderer = new HeadRendererBridgeImpl();
}
} else if (JAVAX_FACES_BODY.equals(rendererType)) {
renderer = new BodyRendererBridgeImpl(renderer);
} else if (RenderKitUtil.SCRIPT_RENDERER_TYPE.equals(rendererType) || RenderKitUtil.STYLESHEET_RENDERER_TYPE.equals(rendererType)) {
renderer = new ResourceRendererBridgeImpl(renderer);
}
} else if (UIForm.COMPONENT_FAMILY.equals(family) && JAVAX_FACES_FORM.equals(rendererType) && PRIMEFACES_DETECTED) {
renderer = new FormRendererPrimeFacesImpl(PRIMEFACES.getMajorVersion(), PRIMEFACES.getMinorVersion(), renderer);
} else if (PRIMEFACES_FAMILY.equals(family) && PRIMEFACES_FILE_UPLOAD_RENDERER_TYPE.equals(rendererType)) {
renderer = new FileUploadRendererPortletImpl(renderer);
} else if (RICHFACES_FILE_UPLOAD_FAMILY.equals(family) && RICHFACES_FILE_UPLOAD_RENDERER_TYPE.equals(rendererType)) {
renderer = new FileUploadRendererPortletImpl(new FileUploadRendererRichFacesImpl(renderer));
}
return renderer;
}
use of com.liferay.faces.util.product.Product in project liferay-faces-alloy by liferay.
the class HeadRenderer method processEvent.
@Override
public void processEvent(ComponentSystemEvent componentSystemEvent) throws AbortProcessingException {
FacesContext facesContext = FacesContext.getCurrentInstance();
ExternalContext externalContext = facesContext.getExternalContext();
final Product LIFERAY_PORTAL = ProductFactory.getProductInstance(externalContext, Product.Name.LIFERAY_PORTAL);
// to behave responsively.
if (!LIFERAY_PORTAL.isDetected()) {
UIViewRoot uiViewRoot = facesContext.getViewRoot();
ResponsiveMetadata responsiveMetadata = new ResponsiveMetadata();
Map<String, Object> attributes = responsiveMetadata.getAttributes();
attributes.put("name", ResponsiveMetadata.COMPONENT_FAMILY);
uiViewRoot.addComponentResource(facesContext, responsiveMetadata);
}
}
use of com.liferay.faces.util.product.Product in project liferay-faces-alloy by liferay.
the class JSFUtil method isFaces_2_2_OrNewer.
public static boolean isFaces_2_2_OrNewer(FacesContext facesContext) {
ExternalContext externalContext = facesContext.getExternalContext();
final Product JSF = ProductFactory.getProductInstance(externalContext, Product.Name.JSF);
return JSF.isDetected() && ((JSF.getMajorVersion() > 2) || ((JSF.getMajorVersion() == 2) && (JSF.getMinorVersion() >= 2)));
}
Aggregations