use of org.apache.myfaces.config.element.FacesConfigData in project myfaces by apache.
the class FacesConfigurator method configureFactories.
private void configureFactories() {
FacesConfigData dispenser = getDispenser();
setFactories(FactoryFinder.APPLICATION_FACTORY, dispenser.getApplicationFactoryIterator(), DEFAULT_APPLICATION_FACTORY);
setFactories(FactoryFinder.EXCEPTION_HANDLER_FACTORY, dispenser.getExceptionHandlerFactoryIterator(), DEFAULT_EXCEPTION_HANDLER_FACTORY);
setFactories(FactoryFinder.EXTERNAL_CONTEXT_FACTORY, dispenser.getExternalContextFactoryIterator(), DEFAULT_EXTERNAL_CONTEXT_FACTORY);
setFactories(FactoryFinder.FACES_CONTEXT_FACTORY, dispenser.getFacesContextFactoryIterator(), DEFAULT_FACES_CONTEXT_FACTORY);
setFactories(FactoryFinder.LIFECYCLE_FACTORY, dispenser.getLifecycleFactoryIterator(), DEFAULT_LIFECYCLE_FACTORY);
setFactories(FactoryFinder.RENDER_KIT_FACTORY, dispenser.getRenderKitFactoryIterator(), DEFAULT_RENDER_KIT_FACTORY);
setFactories(FactoryFinder.TAG_HANDLER_DELEGATE_FACTORY, dispenser.getTagHandlerDelegateFactoryIterator(), DEFAULT_TAG_HANDLER_DELEGATE_FACTORY);
setFactories(FactoryFinder.PARTIAL_VIEW_CONTEXT_FACTORY, dispenser.getPartialViewContextFactoryIterator(), DEFAULT_PARTIAL_VIEW_CONTEXT_FACTORY);
setFactories(FactoryFinder.VISIT_CONTEXT_FACTORY, dispenser.getVisitContextFactoryIterator(), DEFAULT_VISIT_CONTEXT_FACTORY);
setFactories(FactoryFinder.VIEW_DECLARATION_LANGUAGE_FACTORY, dispenser.getViewDeclarationLanguageFactoryIterator(), DEFAULT_VIEW_DECLARATION_LANGUAGE_FACTORY);
setFactories(FactoryFinder.FACELET_CACHE_FACTORY, dispenser.getFaceletCacheFactoryIterator(), DEFAULT_FACELET_CACHE_FACTORY);
setFactories(FactoryFinder.FLASH_FACTORY, dispenser.getFlashFactoryIterator(), DEFAULT_FLASH_FACTORY);
setFactories(FactoryFinder.CLIENT_WINDOW_FACTORY, dispenser.getClientWindowFactoryIterator(), DEFAULT_CLIENT_WINDOW_FACTORY);
setFactories(FactoryFinder.FLOW_HANDLER_FACTORY, dispenser.getFlowHandlerFactoryIterator(), DEFAULT_FLOW_FACTORY);
setFactories(FactoryFinder.SEARCH_EXPRESSION_CONTEXT_FACTORY, dispenser.getSearchExpressionContextFactoryIterator(), DEFAULT_SEARCH_EXPRESSION_CONTEXT_FACTORY);
}
use of org.apache.myfaces.config.element.FacesConfigData in project myfaces by apache.
the class FacesConfigurator method configureProtectedViews.
public void configureProtectedViews() {
Application application = getApplication();
FacesConfigData dispenser = getDispenser();
// Protected Views
ViewHandler viewHandler = application.getViewHandler();
for (String urlPattern : dispenser.getProtectedViewUrlPatterns()) {
viewHandler.addProtectedView(urlPattern);
}
}
use of org.apache.myfaces.config.element.FacesConfigData in project myfaces by apache.
the class FacesConfigurator method configureRenderKits.
private void configureRenderKits() {
RenderKitFactory renderKitFactory = (RenderKitFactory) FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY);
FacesConfigData dispenser = getDispenser();
for (String renderKitId : dispenser.getRenderKitIds()) {
Collection<String> renderKitClass = dispenser.getRenderKitClasses(renderKitId);
if (renderKitClass.isEmpty()) {
renderKitClass = new ArrayList<>(1);
renderKitClass.add(DEFAULT_RENDER_KIT_CLASS);
}
RenderKit renderKit = (RenderKit) ClassUtils.buildApplicationObject(RenderKit.class, renderKitClass, null);
// If the default html RenderKit instance is wrapped, the top level object will not implement
// LazyRenderKit and all renderers will be added using the standard form.
boolean lazyRenderKit = renderKit instanceof LazyRenderKit;
for (Renderer element : dispenser.getRenderers(renderKitId)) {
jakarta.faces.render.Renderer renderer;
if (element.getRendererClass() != null) {
if (lazyRenderKit) {
// Add renderer using LazyRenderKit interface. This will have the effect of improve startup
// time avoiding load renderer classes that are not used.
((LazyRenderKit) renderKit).addRenderer(element.getComponentFamily(), element.getRendererType(), element.getRendererClass());
} else {
// Use standard form
try {
renderer = (jakarta.faces.render.Renderer) ClassUtils.newInstance(element.getRendererClass());
} catch (Throwable e) {
// ignore the failure so that the render kit is configured
log.log(Level.SEVERE, "failed to configure class " + element.getRendererClass(), e);
continue;
}
if (renderer != null) {
renderKit.addRenderer(element.getComponentFamily(), element.getRendererType(), renderer);
} else {
log.log(Level.INFO, "Renderer instance cannot be created for " + element.getRendererClass() + ", ignoring..." + element.getRendererClass());
}
}
} else {
log.log(Level.INFO, "Renderer element with no rendererClass found, ignoring..." + element.getRendererClass());
}
}
Collection<ClientBehaviorRenderer> clientBehaviorRenderers = dispenser.getClientBehaviorRenderers(renderKitId);
for (ClientBehaviorRenderer clientBehaviorRenderer : clientBehaviorRenderers) {
try {
jakarta.faces.render.ClientBehaviorRenderer behaviorRenderer = (jakarta.faces.render.ClientBehaviorRenderer) ClassUtils.newInstance(clientBehaviorRenderer.getRendererClass());
renderKit.addClientBehaviorRenderer(clientBehaviorRenderer.getRendererType(), behaviorRenderer);
} catch (Throwable e) {
if (log.isLoggable(Level.SEVERE)) {
log.log(Level.SEVERE, "failed to configure client behavior renderer class " + clientBehaviorRenderer.getRendererClass(), e);
}
}
}
renderKitFactory.addRenderKit(renderKitId, renderKit);
}
}
use of org.apache.myfaces.config.element.FacesConfigData in project myfaces by apache.
the class FacesConfigurator method configureFlowHandler.
private void configureFlowHandler() {
FacesContext facesContext = getFacesContext();
Application application = getApplication();
FacesConfigData dispenser = getDispenser();
if (!dispenser.getFacesFlowDefinitions().isEmpty()) {
// Faces Flow require client window enabled to work.
FacesConfigurator.enableDefaultWindowMode(facesContext);
}
for (FacesFlowDefinition flowDefinition : dispenser.getFacesFlowDefinitions()) {
FlowImpl flow = new FlowImpl();
// TODO: configure flow object
flow.setId(flowDefinition.getId());
flow.setDefiningDocumentId(flowDefinition.getDefiningDocumentId());
flow.setStartNodeId(flowDefinition.getStartNode());
if (StringUtils.isNotEmpty(flowDefinition.getInitializer())) {
flow.setInitializer(application.getExpressionFactory().createMethodExpression(facesContext.getELContext(), flowDefinition.getInitializer(), null, NO_PARAMETER_TYPES));
}
if (StringUtils.isNotEmpty(flowDefinition.getFinalizer())) {
flow.setFinalizer(application.getExpressionFactory().createMethodExpression(facesContext.getELContext(), flowDefinition.getFinalizer(), null, NO_PARAMETER_TYPES));
}
for (FacesFlowCall call : flowDefinition.getFlowCallList()) {
FlowCallNodeImpl node = new FlowCallNodeImpl(call.getId());
if (call.getFlowReference() != null) {
node.setCalledFlowId(call.getFlowReference().getFlowId());
node.setCalledFlowDocumentId(call.getFlowReference().getFlowDocumentId());
}
for (FacesFlowParameter parameter : call.getOutboundParameterList()) {
node.putOutboundParameter(parameter.getName(), new ParameterImpl(parameter.getName(), application.getExpressionFactory().createValueExpression(facesContext.getELContext(), parameter.getValue(), Object.class)));
}
flow.putFlowCall(node.getId(), node);
}
for (FacesFlowMethodCall methodCall : flowDefinition.getMethodCallList()) {
MethodCallNodeImpl node = new MethodCallNodeImpl(methodCall.getId());
if (StringUtils.isNotEmpty(methodCall.getMethod())) {
node.setMethodExpression(application.getExpressionFactory().createMethodExpression(facesContext.getELContext(), methodCall.getMethod(), null, NO_PARAMETER_TYPES));
}
if (StringUtils.isNotEmpty(methodCall.getDefaultOutcome())) {
node.setOutcome(application.getExpressionFactory().createValueExpression(facesContext.getELContext(), methodCall.getDefaultOutcome(), Object.class));
}
for (FacesFlowMethodParameter parameter : methodCall.getParameterList()) {
node.addParameter(new ParameterImpl(parameter.getClassName(), application.getExpressionFactory().createValueExpression(facesContext.getELContext(), parameter.getValue(), Object.class)));
}
flow.addMethodCall(node);
}
for (FacesFlowParameter parameter : flowDefinition.getInboundParameterList()) {
flow.putInboundParameter(parameter.getName(), new ParameterImpl(parameter.getName(), application.getExpressionFactory().createValueExpression(facesContext.getELContext(), parameter.getValue(), Object.class)));
}
for (NavigationRule rule : flowDefinition.getNavigationRuleList()) {
flow.addNavigationCases(rule.getFromViewId(), NavigationUtils.convertNavigationCasesToAPI(rule));
}
for (FacesFlowSwitch flowSwitch : flowDefinition.getSwitchList()) {
SwitchNodeImpl node = new SwitchNodeImpl(flowSwitch.getId());
if (flowSwitch.getDefaultOutcome() != null && StringUtils.isNotEmpty(flowSwitch.getDefaultOutcome().getFromOutcome())) {
if (ELText.isLiteral(flowSwitch.getDefaultOutcome().getFromOutcome())) {
node.setDefaultOutcome(flowSwitch.getDefaultOutcome().getFromOutcome());
} else {
node.setDefaultOutcome(application.getExpressionFactory().createValueExpression(facesContext.getELContext(), flowSwitch.getDefaultOutcome().getFromOutcome(), Object.class));
}
}
for (NavigationCase navCase : flowSwitch.getNavigationCaseList()) {
SwitchCaseImpl nodeCase = new SwitchCaseImpl();
nodeCase.setFromOutcome(navCase.getFromOutcome());
if (StringUtils.isNotEmpty(navCase.getIf())) {
nodeCase.setCondition(application.getExpressionFactory().createValueExpression(facesContext.getELContext(), navCase.getIf(), Object.class));
}
node.addCase(nodeCase);
}
flow.putSwitch(node.getId(), node);
}
for (FacesFlowView view : flowDefinition.getViewList()) {
ViewNodeImpl node = new ViewNodeImpl(view.getId(), view.getVdlDocument());
flow.addView(node);
}
for (FacesFlowReturn flowReturn : flowDefinition.getReturnList()) {
ReturnNodeImpl node = new ReturnNodeImpl(flowReturn.getId());
if (flowReturn.getNavigationCase() != null && StringUtils.isNotEmpty(flowReturn.getNavigationCase().getFromOutcome())) {
if (ELText.isLiteral(flowReturn.getNavigationCase().getFromOutcome())) {
node.setFromOutcome(flowReturn.getNavigationCase().getFromOutcome());
} else {
node.setFromOutcome(application.getExpressionFactory().createValueExpression(facesContext.getELContext(), flowReturn.getNavigationCase().getFromOutcome(), Object.class));
}
}
flow.putReturn(node.getId(), node);
}
flow.freeze();
// Add the flow, so the config can be processed by the flow system and the
// navigation system.
application.getFlowHandler().addFlow(facesContext, flow);
}
configureAnnotatedFlows(facesContext);
}
use of org.apache.myfaces.config.element.FacesConfigData in project myfaces by apache.
the class FacesConfigurator method configureRuntimeConfig.
private void configureRuntimeConfig() {
RuntimeConfig runtimeConfig = RuntimeConfig.getCurrentInstance(_externalContext);
FacesConfigData dispenser = getDispenser();
List<String> knownNamespaces = new ArrayList<>();
for (ComponentTagDeclaration declaration : dispenser.getComponentTagDeclarations()) {
runtimeConfig.addComponentTagDeclaration(declaration);
if (declaration.getNamespace() != null) {
knownNamespaces.add(declaration.getNamespace());
}
}
for (NavigationRule rule : dispenser.getNavigationRules()) {
runtimeConfig.addNavigationRule(rule);
}
for (String converterClassName : dispenser.getConverterConfigurationByClassName()) {
runtimeConfig.addConverterConfiguration(converterClassName, _dispenser.getConverterConfiguration(converterClassName));
}
for (ResourceBundle bundle : dispenser.getResourceBundles()) {
runtimeConfig.addResourceBundle(bundle);
}
for (String className : dispenser.getElResolvers()) {
ELResolver elResolver = (ELResolver) ClassUtils.newInstance(className, ELResolver.class);
_callInjectAndPostConstruct(elResolver);
runtimeConfig.addFacesConfigElResolver(elResolver);
}
for (String className : dispenser.getSearchKeywordResolvers()) {
SearchKeywordResolver searchKeywordResolver = (SearchKeywordResolver) ClassUtils.newInstance(className, SearchKeywordResolver.class);
runtimeConfig.addApplicationSearchExpressionResolver(searchKeywordResolver);
}
runtimeConfig.setFacesVersion(dispenser.getFacesVersion());
runtimeConfig.setNamedEventManager(new NamedEventManager());
for (NamedEvent event : dispenser.getNamedEvents()) {
try {
Class<? extends ComponentSystemEvent> clazz = ClassUtils.classForName(event.getEventClass());
runtimeConfig.getNamedEventManager().addNamedEvent(event.getShortName(), clazz);
} catch (ClassNotFoundException e) {
log.log(Level.SEVERE, "Named event could not be initialized, reason:", e);
}
}
String elResolverComparatorClass = _myfacesConfig.getElResolverComparator();
if (elResolverComparatorClass != null && !elResolverComparatorClass.isEmpty()) {
try {
Class<Comparator<ELResolver>> clazz = ClassUtils.classForName(elResolverComparatorClass);
Comparator<ELResolver> comparator = ClassUtils.newInstance(clazz);
runtimeConfig.setELResolverComparator(comparator);
} catch (Exception e) {
if (log.isLoggable(Level.SEVERE)) {
log.log(Level.SEVERE, "Cannot instantiate EL Resolver Comparator " + elResolverComparatorClass + " . Check " + MyfacesConfig.EL_RESOLVER_COMPARATOR + " web config param. " + "Initialization continues with no comparator used.", e);
}
}
} else {
runtimeConfig.setELResolverComparator(null);
}
String elResolverPredicateClass = _myfacesConfig.getElResolverPredicate();
if (elResolverPredicateClass != null && !elResolverPredicateClass.isEmpty()) {
try {
Class<?> clazz = ClassUtils.classForName(elResolverPredicateClass);
Object elResolverPredicate = ClassUtils.newInstance(clazz);
if (elResolverPredicate instanceof Predicate) {
runtimeConfig.setELResolverPredicate((Predicate) elResolverPredicate);
} else {
if (log.isLoggable(Level.SEVERE)) {
log.log(Level.SEVERE, "EL Resolver Predicate " + elResolverPredicateClass + " must implement " + Predicate.class.getName() + " . Check " + MyfacesConfig.EL_RESOLVER_PREDICATE + " web config param. " + "Initialization continues with no predicate used.");
}
}
} catch (Exception e) {
if (log.isLoggable(Level.SEVERE)) {
log.log(Level.SEVERE, "Cannot instantiate EL Resolver Predicate " + elResolverPredicateClass + " . Check " + MyfacesConfig.EL_RESOLVER_PREDICATE + " web config param. " + "Initialization continues with no predicate used.", e);
}
}
} else {
runtimeConfig.setELResolverPredicate(null);
}
for (FaceletsProcessing faceletsProcessing : dispenser.getFaceletsProcessing()) {
runtimeConfig.addFaceletProcessingConfiguration(faceletsProcessing.getFileExtension(), faceletsProcessing);
}
ResourceLibraryContractsProvider rlcp = ResourceLibraryContractsProviderFactory.getFacesConfigResourceProviderFactory(_externalContext).createResourceLibraryContractsProvider(_externalContext);
try {
// JSF 2.2 section 11.4.2.1 scan for available resource library contracts
// and store the result in a internal data structure, so it can be used
// later in ViewDeclarationLanguage.calculateResourceLibraryContracts(
// FacesContext context, String viewId)
runtimeConfig.setExternalContextResourceLibraryContracts(rlcp.getExternalContextResourceLibraryContracts(_externalContext));
runtimeConfig.setClassLoaderResourceLibraryContracts(rlcp.getClassloaderResourceLibraryContracts(_externalContext));
} catch (Exception e) {
if (log.isLoggable(Level.SEVERE)) {
log.log(Level.SEVERE, "An error was found when scanning for resource library contracts", e);
}
}
// JSF 2.2 section 11.4.2.1 check all contracts are loaded
if (log.isLoggable(Level.INFO)) {
for (List<String> list : runtimeConfig.getContractMappings().values()) {
for (String contract : list) {
if (!runtimeConfig.getResourceLibraryContracts().contains(contract)) {
log.log(Level.INFO, "Resource Library Contract " + contract + " was not found while scanning for " + "available contracts.");
}
}
}
}
// to all views.
if (runtimeConfig.getContractMappings().isEmpty()) {
String[] contracts = runtimeConfig.getResourceLibraryContracts().toArray(new String[runtimeConfig.getResourceLibraryContracts().size()]);
runtimeConfig.addContractMapping("*", contracts);
}
for (String resourceResolver : dispenser.getResourceResolvers()) {
runtimeConfig.addResourceResolver(resourceResolver);
}
for (FaceletTagLibrary faceletTagLibrary : dispenser.getTagLibraries()) {
runtimeConfig.addFaceletTagLibrary(faceletTagLibrary);
if (faceletTagLibrary.getNamespace() != null) {
knownNamespaces.add(faceletTagLibrary.getNamespace());
}
}
// Add default namespaces to the known namespaces
knownNamespaces.add("http://xmlns.jcp.org/jsf/core");
knownNamespaces.add("http://java.sun.com/jsf/core");
knownNamespaces.add("http://xmlns.jcp.org/jsf/html");
knownNamespaces.add("http://java.sun.com/jsf/html");
knownNamespaces.add("http://xmlns.jcp.org/jsf/facelets");
knownNamespaces.add("http://java.sun.com/jsf/facelets");
knownNamespaces.add("http://xmlns.jcp.org/jsp/jstl/core");
knownNamespaces.add("http://java.sun.com/jsp/jstl/core");
knownNamespaces.add("http://java.sun.com/jstl/core");
knownNamespaces.add("http://xmlns.jcp.org/jsp/jstl/functions");
knownNamespaces.add("http://java.sun.com/jsp/jstl/functions");
knownNamespaces.add("http://xmlns.jcp.org/jsf/composite");
knownNamespaces.add("http://java.sun.com/jsf/composite");
knownNamespaces.add("http://xmlns.jcp.org/jsf");
knownNamespaces.add("http://java.sun.com/jsf");
knownNamespaces.add("http://xmlns.jcp.org/jsf/passthrough");
knownNamespaces.add("http://java.sun.com/jsf/passthrough");
Map<Integer, String> namespaceById = new HashMap<>();
Map<String, Integer> idByNamespace = new HashMap<>();
// Sort them to ensure the same id
Collections.sort(knownNamespaces);
for (int i = 0; i < knownNamespaces.size(); i++) {
namespaceById.put(i, knownNamespaces.get(i));
idByNamespace.put(knownNamespaces.get(i), i);
}
runtimeConfig.setNamespaceById(Collections.unmodifiableMap(namespaceById));
runtimeConfig.setIdByNamespace(Collections.unmodifiableMap(idByNamespace));
for (ViewPoolMapping viewPoolMapping : dispenser.getViewPoolMappings()) {
runtimeConfig.addViewPoolMapping(viewPoolMapping);
}
for (FaceletsTemplateMapping faceletsTemplateMapping : dispenser.getFaceletsTemplateMappings()) {
runtimeConfig.addFaceletsTemplateMapping(faceletsTemplateMapping);
}
}
Aggregations