use of jakarta.faces.flow.FlowHandlerFactory in project myfaces by apache.
the class FacesConfigurator method configureApplication.
private void configureApplication() {
Application application = ((ApplicationFactory) FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY)).getApplication();
FacesConfigData dispenser = getDispenser();
ActionListener actionListener = ClassUtils.buildApplicationObject(ActionListener.class, dispenser.getActionListenerIterator(), null);
_callInjectAndPostConstruct(actionListener);
application.setActionListener(actionListener);
if (dispenser.getDefaultLocale() != null) {
application.setDefaultLocale(LocaleUtils.toLocale(dispenser.getDefaultLocale()));
}
if (dispenser.getDefaultRenderKitId() != null) {
application.setDefaultRenderKitId(dispenser.getDefaultRenderKitId());
}
if (dispenser.getMessageBundle() != null) {
application.setMessageBundle(dispenser.getMessageBundle());
}
// First build the object
NavigationHandler navigationHandler = ClassUtils.buildApplicationObject(NavigationHandler.class, ConfigurableNavigationHandler.class, null, dispenser.getNavigationHandlerIterator(), application.getNavigationHandler());
// Invoke inject and post construct
_callInjectAndPostConstruct(navigationHandler);
// Finally wrap the object with the BackwardsCompatibleNavigationHandlerWrapper if it is not assignable
// from ConfigurableNavigationHandler
navigationHandler = ClassUtils.wrapBackwardCompatible(NavigationHandler.class, ConfigurableNavigationHandler.class, BackwardsCompatibleNavigationHandlerWrapper.class, application.getNavigationHandler(), navigationHandler);
application.setNavigationHandler(navigationHandler);
StateManager stateManager = ClassUtils.buildApplicationObject(StateManager.class, dispenser.getStateManagerIterator(), application.getStateManager());
_callInjectAndPostConstruct(stateManager);
application.setStateManager(stateManager);
ResourceHandler resourceHandler = ClassUtils.buildApplicationObject(ResourceHandler.class, dispenser.getResourceHandlerIterator(), application.getResourceHandler());
_callInjectAndPostConstruct(resourceHandler);
application.setResourceHandler(resourceHandler);
List<Locale> locales = new ArrayList<>();
for (String locale : dispenser.getSupportedLocalesIterator()) {
locales.add(LocaleUtils.toLocale(locale));
}
application.setSupportedLocales(locales);
application.setViewHandler(ClassUtils.buildApplicationObject(ViewHandler.class, dispenser.getViewHandlerIterator(), application.getViewHandler()));
application.setSearchExpressionHandler(ClassUtils.buildApplicationObject(SearchExpressionHandler.class, dispenser.getSearchExpressionHandlerIterator(), application.getSearchExpressionHandler()));
for (SystemEventListener systemEventListener : dispenser.getSystemEventListeners()) {
try {
// note here used to be an instantiation to deal with the explicit source type in the registration,
// that cannot work because all system events need to have the source being passed in the constructor
// instead we now rely on the standard system event types and map them to their appropriate
// constructor types
Class eventClass = ClassUtils.classForName((systemEventListener.getSystemEventClass() != null) ? systemEventListener.getSystemEventClass() : SystemEvent.class.getName());
jakarta.faces.event.SystemEventListener listener = (jakarta.faces.event.SystemEventListener) ClassUtils.newInstance(systemEventListener.getSystemEventListenerClass());
_callInjectAndPostConstruct(listener);
if (systemEventListener.getSourceClass() != null && systemEventListener.getSourceClass().length() > 0) {
application.subscribeToEvent((Class<? extends SystemEvent>) eventClass, ClassUtils.classForName(systemEventListener.getSourceClass()), listener);
} else {
application.subscribeToEvent((Class<? extends SystemEvent>) eventClass, listener);
}
} catch (ClassNotFoundException e) {
log.log(Level.SEVERE, "System event listener could not be initialized, reason:", e);
}
}
for (Map.Entry<String, Component> entry : dispenser.getComponentsByType().entrySet()) {
application.addComponent(entry.getKey(), entry.getValue().getComponentClass());
}
for (Map.Entry<String, String> entry : dispenser.getConverterClassesById().entrySet()) {
application.addConverter(entry.getKey(), entry.getValue());
}
for (Map.Entry<String, String> entry : dispenser.getConverterClassesByClass().entrySet()) {
try {
application.addConverter(ClassUtils.classForName(entry.getKey()), entry.getValue());
} catch (Exception ex) {
log.log(Level.SEVERE, "Converter could not be added. Reason:", ex);
}
}
for (Map.Entry<String, String> entry : dispenser.getValidatorClassesById().entrySet()) {
application.addValidator(entry.getKey(), entry.getValue());
}
// programmatically add the BeanValidator if the following requirements are met:
// - bean validation has not been disabled
// - bean validation is available in the classpath
String beanValidatorDisabled = _externalContext.getInitParameter(BeanValidator.DISABLE_DEFAULT_BEAN_VALIDATOR_PARAM_NAME);
final boolean defaultBeanValidatorDisabled = (beanValidatorDisabled != null && beanValidatorDisabled.toLowerCase().equals("true"));
boolean beanValidatorInstalledProgrammatically = false;
if (!defaultBeanValidatorDisabled && ExternalSpecifications.isBeanValidationAvailable()) {
// add the BeanValidator as default validator
application.addDefaultValidatorId(BeanValidator.VALIDATOR_ID);
beanValidatorInstalledProgrammatically = true;
}
// add the default-validators from the config files
for (String validatorId : dispenser.getDefaultValidatorIds()) {
application.addDefaultValidatorId(validatorId);
}
// default-validator programmatically, but via a config file.
if (!beanValidatorInstalledProgrammatically && application.getDefaultValidatorInfo().containsKey(BeanValidator.VALIDATOR_ID)) {
if (!ExternalSpecifications.isBeanValidationAvailable()) {
// the BeanValidator was installed via a config file,
// but bean validation is not available
log.log(Level.WARNING, "The BeanValidator was installed as a " + "default-validator from a faces-config file, but bean " + "validation is not available on the classpath, " + "thus it will not work!");
} else if (defaultBeanValidatorDisabled) {
// the user disabled the default bean validator in web.xml,
// but a config file added it, which is ok with the spec
// (section 11.1.3: "though manual installation is still possible")
// --> inform the user about this scenario
log.log(Level.INFO, "The BeanValidator was disabled as a " + "default-validator via the config parameter " + BeanValidator.DISABLE_DEFAULT_BEAN_VALIDATOR_PARAM_NAME + " in web.xml, but a faces-config file added it, " + "thus it actually was installed as a default-validator.");
}
}
for (Behavior behavior : dispenser.getBehaviors()) {
application.addBehavior(behavior.getBehaviorId(), behavior.getBehaviorClass());
}
// JSF 2.2 set FlowHandler from factory.
FlowHandlerFactory flowHandlerFactory = (FlowHandlerFactory) FactoryFinder.getFactory(FactoryFinder.FLOW_HANDLER_FACTORY);
FlowHandler flowHandler = flowHandlerFactory.createFlowHandler(getFacesContext());
application.setFlowHandler(flowHandler);
for (ContractMapping mapping : dispenser.getResourceLibraryContractMappings()) {
List<String> urlMappingsList = mapping.getUrlPatternList();
for (String urlPattern : urlMappingsList) {
for (String contract : mapping.getContractList()) {
String[] contracts = StringUtils.trim(StringUtils.splitShortString(contract, ' '));
_runtimeConfig.addContractMapping(urlPattern, contracts);
}
}
}
this.setApplication(application);
}
use of jakarta.faces.flow.FlowHandlerFactory in project mojarra by eclipse-ee4j.
the class FacesFlowDefinitionConfigProcessor method processFacesFlowDefinitions.
private void processFacesFlowDefinitions(FacesContext context, URI definingDocumentURI, Document document) throws XPathExpressionException {
String namespace = document.getDocumentElement().getNamespaceURI();
NodeList flowDefinitions = document.getDocumentElement().getElementsByTagNameNS(namespace, FACES_FLOW_DEFINITION);
if (flowDefinitions.getLength() == 0) {
return;
}
Application application = context.getApplication();
FlowHandler flowHandler = application.getFlowHandler();
if (flowHandler == null) {
FlowHandlerFactory flowHandlerFactory = (FlowHandlerFactory) FactoryFinder.getFactory(FactoryFinder.FLOW_HANDLER_FACTORY);
application.setFlowHandler(flowHandler = flowHandlerFactory.createFlowHandler(context));
}
XPath xpath = XPathFactory.newInstance().newXPath();
xpath.setNamespaceContext(new FacesConfigNamespaceContext(namespace));
String nameStr = "";
NodeList nameList = (NodeList) xpath.evaluate("./ns1:name/text()", document.getDocumentElement(), XPathConstants.NODESET);
if (null != nameList && 1 < nameList.getLength()) {
throw new XPathExpressionException("<faces-config> must have at most one <name> element.");
}
if (null != nameList && 1 == nameList.getLength()) {
nameStr = nameList.item(0).getNodeValue().trim();
if (0 < nameStr.length()) {
ApplicationAssociate associate = ApplicationAssociate.getInstance(context.getExternalContext());
try {
associate.relateUrlToDefiningDocumentInJar(definingDocumentURI.toURL(), nameStr);
} catch (MalformedURLException ex) {
throw new XPathExpressionException(ex);
}
}
}
for (int c = 0, size = flowDefinitions.getLength(); c < size; c++) {
Node flowDefinition = flowDefinitions.item(c);
String flowId = getIdAttribute(flowDefinition);
String uriStr = definingDocumentURI.toASCIIString();
if (uriStr.endsWith(RIConstants.FLOW_DEFINITION_ID_SUFFIX)) {
nameStr = "";
}
FlowBuilderImpl flowBuilder = new FlowBuilderImpl(context);
flowBuilder.id(nameStr, flowId);
processViews(xpath, flowDefinition, flowBuilder);
processNavigationRules(xpath, flowDefinition, flowBuilder);
processReturns(xpath, flowDefinition, flowBuilder);
processInboundParameters(xpath, flowDefinition, flowBuilder);
processFlowCalls(xpath, flowDefinition, flowBuilder);
processSwitches(xpath, flowDefinition, flowBuilder);
processMethodCalls(context, xpath, flowDefinition, flowBuilder);
processInitializerFinalizer(xpath, flowDefinition, flowBuilder);
String startNodeId = processStartNode(xpath, flowDefinition, flowBuilder);
if (null != startNodeId) {
FlowImpl toAdd = flowBuilder._getFlow();
FlowNode startNode = toAdd.getNode(startNodeId);
if (null == startNode) {
throw new XPathExpressionException("Unable to find flow node with id " + startNodeId + " to mark as start node");
} else {
toAdd.setStartNodeId(startNodeId);
}
} else {
flowBuilder.viewNode(flowId, "/" + flowId + "/" + flowId + ".xhtml").markAsStartNode();
}
flowHandler.addFlow(context, flowBuilder.getFlow());
}
}
Aggregations