use of javax.portlet.faces.BridgeConfig in project liferay-faces-bridge-impl by liferay.
the class BridgeRequestAttributeListener method attributeAdded.
/**
* This method is called after an attribute is added to the ServletRequest. Note that this should only get called
* for remote WSRP portlets. For more info, see: http://issues.liferay.com/browse/FACES-146
*/
@Override
public void attributeAdded(ServletRequestAttributeEvent servletRequestAttributeEvent) {
// NOTE: We only care about phases prior to the HEADER_PHASE because we're concerned here about managed beans
// that get added to the request scope when the BridgeRequestScope begins. We're trying to provide those managed
// beans with an opportunity to prepare for an unexpected invocation of their methods annotated with
// @PreDestroy.
ServletRequest servletRequest = servletRequestAttributeEvent.getServletRequest();
PortletPhase phase = (PortletPhase) servletRequest.getAttribute(Bridge.PORTLET_LIFECYCLE_PHASE);
// HEADER_PHASE, then
if ((phase != null) && (phase != PortletPhase.HEADER_PHASE)) {
// If the attribute being added is not excluded, then invoke all methods on the attribute value (class
// instance) that are annotated with the BridgeRequestScopeAttributeAdded annotation.
String attributeName = servletRequestAttributeEvent.getName();
FacesContext facesContext = FacesContext.getCurrentInstance();
BridgeConfig bridgeConfig = RequestMapUtil.getBridgeConfig(facesContext);
Set<String> excludedRequestScopeAttributes = bridgeConfig.getExcludedRequestAttributes();
if (!excludedRequestScopeAttributes.contains(attributeName)) {
Object attributeValue = servletRequestAttributeEvent.getValue();
logger.trace("Attribute added name=[{0}] value=[{1}]", attributeName, attributeValue);
if (attributeValue != null) {
Method[] methods = attributeValue.getClass().getMethods();
if (methods != null) {
for (Method method : methods) {
if (method != null) {
if (method.isAnnotationPresent(BridgeRequestScopeAttributeAdded.class)) {
try {
method.invoke(attributeValue);
} catch (Exception e) {
logger.error(e);
}
}
}
}
}
}
}
}
}
use of javax.portlet.faces.BridgeConfig in project liferay-faces-bridge-impl by liferay.
the class ApplicationImpl method createComponent.
/**
* This method provides the ability to supply an instance of the bridge API's {@link
* PortletNamingContainerUIViewRoot} class which properly handles namespacing of "id" attributes for portlets.
*
* @see Application#createComponent(String)
*/
@Override
@SuppressWarnings("unchecked")
public UIComponent createComponent(String componentType) throws FacesException {
FacesContext facesContext = FacesContext.getCurrentInstance();
if (componentType.equals(UIViewRoot.COMPONENT_TYPE) && BridgeUtil.isPortletRequest(facesContext)) {
// to cleanup @ViewScoped managed-beans.
if (subscribeToEventsAtRuntime) {
// order to ensure that it only happens once.
synchronized (subscribeToEventsAtRuntime) {
// Need to check again within the synchronization block, just in case.
if (subscribeToEventsAtRuntime) {
BridgeConfig bridgeConfig = RequestMapUtil.getBridgeConfig(facesContext);
List<ConfiguredSystemEventListener> configuredSystemEventListeners = (List<ConfiguredSystemEventListener>) bridgeConfig.getAttributes().get(BridgeConfigAttributeMap.CONFIGURED_SYSTEM_EVENT_LISTENERS);
if (configuredSystemEventListeners != null) {
for (ConfiguredSystemEventListener configuredSystemEventListener : configuredSystemEventListeners) {
if (UIVIEWROOT_FQCN.equals(configuredSystemEventListener.getSourceClass())) {
subscribeToJSF2SystemEvent(configuredSystemEventListener);
}
}
}
}
subscribeToEventsAtRuntime = false;
}
}
return new UIViewRootBridgeImpl();
} else {
return getWrapped().createComponent(componentType);
}
}
use of javax.portlet.faces.BridgeConfig in project liferay-faces-bridge-impl by liferay.
the class ResourceInnerImpl method getRequestPath.
@Override
public String getRequestPath() {
// Get the requestPath value from the wrapped resource.
String wrappedRequestPath = wrappedResource.getRequestPath();
FacesContext facesContext = FacesContext.getCurrentInstance();
// append extension-mapped suffixes which have no meaning in a portlet environment.
if (wrappedRequestPath != null) {
if (wrappedRequestPath.contains(ResourceHandler.RESOURCE_IDENTIFIER)) {
// If this resource request was initiated from a ResourceURL (not via the FacesServlet), then
if (facesContext != null) {
BridgeConfig bridgeConfig = RequestMapUtil.getBridgeConfig(facesContext);
List<ConfiguredServletMapping> configuredFacesServletMappings = (List<ConfiguredServletMapping>) bridgeConfig.getAttributes().get(BridgeConfigAttributeMap.CONFIGURED_FACES_SERVLET_MAPPINGS);
if (configuredFacesServletMappings != null) {
for (ConfiguredServletMapping configuredServletMapping : configuredFacesServletMappings) {
if (configuredServletMapping.isExtensionMapped()) {
String extension = configuredServletMapping.getExtension();
// Note: Both Mojarra and MyFaces construct a requestPath that looks something like
// "/javax.faces.resource/jsf.js.faces?ln=javax.faces" and so we look for the
// ".faces?" as an indicator that ".faces" needs to be removed from the requestPath.
String token = extension + "?";
int pos = wrappedRequestPath.indexOf(token);
// meaning in a portlet environment.
if (pos > 0) {
wrappedRequestPath = wrappedRequestPath.substring(0, pos) + wrappedRequestPath.substring(pos + extension.length());
logger.debug("Removed extension=[{0}] from requestPath=[{1}]", extension, wrappedRequestPath);
break;
} else // path, then
if (wrappedRequestPath.endsWith(extension)) {
if (extension.equals(EXTENSION_FACES) && wrappedRequestPath.endsWith(LIBRARY_NAME_JAVAX_FACES)) {
// Special case: Don't remove ".faces" if request path ends with "javax.faces"
// http://issues.liferay.com/browse/FACES-1202
} else {
// Sometimes resources like the ICEfaces bridge.js file don't have a library
// name (ln=) parameter and simply look like this:
// /my-portlet/javax.faces.resource/bridge.js.faces
wrappedRequestPath = wrappedRequestPath.substring(0, wrappedRequestPath.lastIndexOf(extension));
logger.debug("Removed extension=[{0}] from requestPath=[{1}]", extension, wrappedRequestPath);
break;
}
}
}
}
}
}
}
// If the wrapped request path ends with "org.richfaces" then
if (wrappedRequestPath.endsWith(ResourceRichFacesImpl.ORG_RICHFACES)) {
// Check to see if the resource physically exists in the META-INF/resources/org.richfaces folder of the
// RichFaces JAR. If it does, then this qualifies as a special case in which the
// ResourceHandlerImpl#fixRichFacesImageURLs(FacesContext, String) method is unable to handle resources
// such as "node_icon.gif" and the library name must be "org.richfaces.images" instead of
// "org.richfaces".
String resourcePath = "META-INF/resources/org.richfaces/" + getResourceName();
URL resourceURL = getClass().getClassLoader().getResource(resourcePath);
if (resourceURL != null) {
wrappedRequestPath = wrappedRequestPath + ".images";
}
}
}
return wrappedRequestPath;
}
use of javax.portlet.faces.BridgeConfig in project liferay-faces-bridge-impl by liferay.
the class BridgeImpl method doFacesRequest.
@Override
public void doFacesRequest(RenderRequest renderRequest, RenderResponse renderResponse) throws BridgeDefaultViewNotSpecifiedException, BridgeUninitializedException, BridgeException {
checkNull(renderRequest, renderResponse);
if (initialized) {
String nonFacesTargetPath = renderRequest.getParameter(Bridge.NONFACES_TARGET_PATH_PARAMETER);
if (nonFacesTargetPath != null) {
throw new BridgeNotAFacesRequestException(nonFacesTargetPath);
}
PortletConfig wrappedPortletConfig = BridgePortletConfigFactory.getPortletConfigInstance(portletConfig);
BridgeConfig bridgeConfig = BridgeConfigFactory.getBridgeConfigInstance(wrappedPortletConfig);
BridgePhase bridgePhase = new BridgePhaseRenderImpl(renderRequest, renderResponse, wrappedPortletConfig, bridgeConfig);
bridgePhase.execute();
} else {
throw new BridgeUninitializedException();
}
}
use of javax.portlet.faces.BridgeConfig in project liferay-faces-bridge-impl by liferay.
the class BridgeImpl method doFacesRequest.
@Override
public void doFacesRequest(EventRequest eventRequest, EventResponse eventResponse) throws BridgeUninitializedException, BridgeException {
checkNull(eventRequest, eventResponse);
if (initialized) {
String nonFacesTargetPath = eventRequest.getParameter(Bridge.NONFACES_TARGET_PATH_PARAMETER);
if (nonFacesTargetPath != null) {
throw new BridgeNotAFacesRequestException(nonFacesTargetPath);
}
PortletConfig wrappedPortletConfig = BridgePortletConfigFactory.getPortletConfigInstance(portletConfig);
BridgeConfig bridgeConfig = BridgeConfigFactory.getBridgeConfigInstance(wrappedPortletConfig);
BridgePhase bridgePhase = new BridgePhaseEventImpl(eventRequest, eventResponse, wrappedPortletConfig, bridgeConfig);
bridgePhase.execute();
} else {
throw new BridgeUninitializedException();
}
}
Aggregations