Search in sources :

Example 16 with ViewConfigResolver

use of org.apache.deltaspike.core.api.config.view.metadata.ViewConfigResolver in project deltaspike by apache.

the class ViewConfigTest method testViewConfigCustomViewConfigPreProcessor.

@Test
public void testViewConfigCustomViewConfigPreProcessor() {
    this.viewConfigExtension.addPageDefinition(Pages.Public.Index.class);
    ViewConfigResolver viewConfigResolver = this.viewConfigResolverProducer.createViewConfigResolver();
    ViewConfigDescriptor viewConfigDescriptor = viewConfigResolver.getViewConfigDescriptor(Pages.Public.Index.class);
    // changed by TestConfigPreProcessor
    Assert.assertEquals("/test/view.custom", viewConfigDescriptor.getViewId());
    Assert.assertEquals(View.ViewParameterMode.DEFAULT, viewConfigDescriptor.getMetaData(View.class).iterator().next().viewParams());
}
Also used : ViewConfigDescriptor(org.apache.deltaspike.core.api.config.view.metadata.ViewConfigDescriptor) ViewConfigResolver(org.apache.deltaspike.core.api.config.view.metadata.ViewConfigResolver)

Example 17 with ViewConfigResolver

use of org.apache.deltaspike.core.api.config.view.metadata.ViewConfigResolver in project deltaspike by apache.

the class DeltaSpikeFacesContextWrapper method init.

private synchronized void init() {
    // switch into paranoia mode
    if (this.initialized == null) {
        this.beanManager = BeanManagerProvider.getInstance().getBeanManager();
        this.jsfModuleConfig = BeanProvider.getContextualReference(this.beanManager, JsfModuleConfig.class, false);
        if (ClassDeactivationUtils.isActivated(JsfRequestBroadcaster.class)) {
            this.jsfRequestBroadcaster = BeanProvider.getContextualReference(JsfRequestBroadcaster.class, true);
        }
        ViewConfigResolver viewConfigResolver = BeanProvider.getContextualReference(ViewConfigResolver.class);
        // deactivate it, if there is no default-error-view available
        this.defaultErrorViewExceptionHandlerActivated = viewConfigResolver.getDefaultErrorViewConfigDescriptor() != null && ClassDeactivationUtils.isActivated(DefaultErrorViewAwareExceptionHandlerWrapper.class);
        this.bridgeExceptionHandlerActivated = ClassDeactivationUtils.isActivated(BridgeExceptionHandlerWrapper.class);
        this.bridgeExceptionQualifier = AnnotationInstanceProvider.of(jsfModuleConfig.getExceptionQualifier());
        this.preDestroyViewMapEventFilterMode = ClassDeactivationUtils.isActivated(SecurityAwareViewHandler.class);
        this.isNavigationAwareApplicationWrapperActivated = ClassDeactivationUtils.isActivated(NavigationHandlerAwareApplication.class);
        org.apache.deltaspike.core.api.projectstage.ProjectStage dsProjectStage = ProjectStageProducer.getInstance().getProjectStage();
        for (ProjectStage ps : ProjectStage.values()) {
            if (ps.name().equals(dsProjectStage.getClass().getSimpleName())) {
                this.projectStage = ps;
                break;
            }
        }
        if (this.projectStage == null && dsProjectStage instanceof TestStage) {
            this.projectStage = ProjectStage.Development;
        }
        if (this.projectStage == ProjectStage.Production) {
            // reset it to force the delegation to the default handling
            this.projectStage = null;
        }
        this.initialized = true;
    }
}
Also used : NavigationHandlerAwareApplication(org.apache.deltaspike.jsf.impl.navigation.NavigationHandlerAwareApplication) JsfModuleConfig(org.apache.deltaspike.jsf.api.config.JsfModuleConfig) BridgeExceptionHandlerWrapper(org.apache.deltaspike.jsf.impl.exception.control.BridgeExceptionHandlerWrapper) ProjectStage(javax.faces.application.ProjectStage) SecurityAwareViewHandler(org.apache.deltaspike.jsf.impl.security.SecurityAwareViewHandler) TestStage(org.apache.deltaspike.core.api.projectstage.TestStage) ViewConfigResolver(org.apache.deltaspike.core.api.config.view.metadata.ViewConfigResolver)

Example 18 with ViewConfigResolver

use of org.apache.deltaspike.core.api.config.view.metadata.ViewConfigResolver in project deltaspike by apache.

the class DeltaSpikeNavigationHandler method getNavigationCase.

@Override
public NavigationCase getNavigationCase(FacesContext context, String action, String outcome) {
    if (this.wrapped instanceof ConfigurableNavigationHandler) {
        if (!this.activated) {
            return ((ConfigurableNavigationHandler) this.wrapped).getNavigationCase(context, action, outcome);
        }
        if (action == null && outcome != null && outcome.contains(".") && outcome.startsWith("class ") && !otherOutcomes.contains(outcome)) {
            String originalOutcome = outcome;
            NavigationCase navigationCase = this.viewConfigBasedNavigationCaseCache.get(originalOutcome);
            if (navigationCase != null) {
                return navigationCase;
            }
            outcome = outcome.substring(6);
            ViewConfigDescriptor entry = null;
            if (DefaultErrorView.class.getName().equals(originalOutcome)) {
                ViewConfigResolver viewConfigResolver = JsfUtils.getViewConfigResolver();
                entry = viewConfigResolver.getDefaultErrorViewConfigDescriptor();
            }
            if (entry == null) {
                Object loadedClass = ClassUtils.tryToLoadClassForName(outcome);
                if (loadedClass == null) {
                    this.otherOutcomes.add(originalOutcome);
                } else if (ViewConfig.class.isAssignableFrom((Class) loadedClass)) {
                    entry = JsfUtils.getViewConfigResolver().getViewConfigDescriptor((Class<? extends ViewConfig>) loadedClass);
                }
            }
            if (entry != null) {
                View.NavigationMode navigationMode = entry.getMetaData(View.class).iterator().next().navigation();
                navigationCase = new NavigationCase("*", null, null, null, entry.getViewId(), null, View.NavigationMode.REDIRECT.equals(navigationMode), false);
                this.viewConfigBasedNavigationCaseCache.put(originalOutcome, navigationCase);
                return navigationCase;
            }
        }
        return ((ConfigurableNavigationHandler) this.wrapped).getNavigationCase(context, action, outcome);
    }
    return null;
}
Also used : DefaultErrorView(org.apache.deltaspike.core.api.config.view.DefaultErrorView) NavigationCase(javax.faces.application.NavigationCase) ViewConfig(org.apache.deltaspike.core.api.config.view.ViewConfig) ViewConfigDescriptor(org.apache.deltaspike.core.api.config.view.metadata.ViewConfigDescriptor) View(org.apache.deltaspike.jsf.api.config.view.View) DefaultErrorView(org.apache.deltaspike.core.api.config.view.DefaultErrorView) ConfigurableNavigationHandler(javax.faces.application.ConfigurableNavigationHandler) ViewConfigResolver(org.apache.deltaspike.core.api.config.view.metadata.ViewConfigResolver)

Example 19 with ViewConfigResolver

use of org.apache.deltaspike.core.api.config.view.metadata.ViewConfigResolver in project deltaspike by apache.

the class ViewConfigTest method testMetaDataInheritanceInViewConfig.

@Test
public void testMetaDataInheritanceInViewConfig() {
    this.viewConfigExtension.addPageDefinition(Pages.class);
    ViewConfigResolver viewConfigResolver = this.viewConfigResolverProducer.createViewConfigResolver();
    ConfigDescriptor<?> configDescriptor = viewConfigResolver.getConfigDescriptor(Pages.class);
    Assert.assertNotNull(configDescriptor);
    Assert.assertNotNull(configDescriptor.getConfigClass());
    Assert.assertEquals(Pages.class, configDescriptor.getConfigClass());
    Assert.assertNotNull(configDescriptor.getMetaData());
    Assert.assertEquals(1, configDescriptor.getMetaData().size());
    Assert.assertEquals(1, configDescriptor.getMetaData(Folder.class).size());
    Assert.assertEquals("/", configDescriptor.getMetaData(Folder.class).iterator().next().name());
    ViewConfigDescriptor viewConfigDescriptor = viewConfigResolver.getViewConfigDescriptor(Pages.Index.class);
    Assert.assertNotNull(viewConfigDescriptor);
    Assert.assertEquals("/index.xhtml", viewConfigDescriptor.getViewId());
    Assert.assertEquals(Pages.Index.class, viewConfigDescriptor.getConfigClass());
    Assert.assertNotNull(viewConfigDescriptor.getMetaData());
    Assert.assertEquals(1, viewConfigDescriptor.getMetaData().size());
    Assert.assertEquals(View.NavigationMode.FORWARD, viewConfigDescriptor.getMetaData(View.class).iterator().next().navigation());
    Assert.assertEquals(View.ViewParameterMode.EXCLUDE, viewConfigDescriptor.getMetaData(View.class).iterator().next().viewParams());
    Assert.assertEquals("index", viewConfigDescriptor.getMetaData(View.class).iterator().next().name());
    Assert.assertEquals("xhtml", viewConfigDescriptor.getMetaData(View.class).iterator().next().extension());
    Assert.assertEquals("/", viewConfigDescriptor.getMetaData(View.class).iterator().next().basePath());
    configDescriptor = viewConfigResolver.getConfigDescriptor(Pages.Admin.class);
    Assert.assertNotNull(configDescriptor);
    Assert.assertNotNull(configDescriptor.getConfigClass());
    Assert.assertEquals(Pages.Admin.class, configDescriptor.getConfigClass());
    Assert.assertNotNull(configDescriptor.getMetaData());
    Assert.assertEquals(1, configDescriptor.getMetaData().size());
    Assert.assertEquals(1, configDescriptor.getMetaData(Folder.class).size());
    Assert.assertEquals("/admin/", configDescriptor.getMetaData(Folder.class).iterator().next().name());
    viewConfigDescriptor = viewConfigResolver.getViewConfigDescriptor(Pages.Admin.Index.class);
    Assert.assertNotNull(viewConfigDescriptor);
    Assert.assertEquals("/admin/index.xhtml", viewConfigDescriptor.getViewId());
    Assert.assertEquals(Pages.Admin.Index.class, viewConfigDescriptor.getConfigClass());
    Assert.assertNotNull(viewConfigDescriptor.getMetaData());
    Assert.assertEquals(1, viewConfigDescriptor.getMetaData().size());
    Assert.assertEquals(View.NavigationMode.FORWARD, viewConfigDescriptor.getMetaData(View.class).iterator().next().navigation());
    Assert.assertEquals(View.ViewParameterMode.EXCLUDE, viewConfigDescriptor.getMetaData(View.class).iterator().next().viewParams());
    Assert.assertEquals("index", viewConfigDescriptor.getMetaData(View.class).iterator().next().name());
    Assert.assertEquals("xhtml", viewConfigDescriptor.getMetaData(View.class).iterator().next().extension());
    Assert.assertEquals("/admin/", viewConfigDescriptor.getMetaData(View.class).iterator().next().basePath());
    configDescriptor = viewConfigResolver.getConfigDescriptor(Pages.Public.class);
    Assert.assertNotNull(configDescriptor);
    Assert.assertNotNull(configDescriptor.getConfigClass());
    Assert.assertEquals(Pages.Public.class, configDescriptor.getConfigClass());
    Assert.assertNotNull(configDescriptor.getMetaData());
    Assert.assertEquals(1, configDescriptor.getMetaData().size());
    Assert.assertEquals(1, configDescriptor.getMetaData(Folder.class).size());
    Assert.assertEquals("/public/", configDescriptor.getMetaData(Folder.class).iterator().next().name());
    viewConfigDescriptor = viewConfigResolver.getViewConfigDescriptor(Pages.Public.Index.class);
    Assert.assertNotNull(viewConfigDescriptor);
    Assert.assertEquals("/public/index.xhtml", viewConfigDescriptor.getViewId());
    Assert.assertEquals(Pages.Public.Index.class, viewConfigDescriptor.getConfigClass());
    Assert.assertNotNull(viewConfigDescriptor.getMetaData());
    Assert.assertEquals(1, viewConfigDescriptor.getMetaData().size());
    Assert.assertEquals(View.NavigationMode.FORWARD, viewConfigDescriptor.getMetaData(View.class).iterator().next().navigation());
    Assert.assertEquals(View.ViewParameterMode.EXCLUDE, viewConfigDescriptor.getMetaData(View.class).iterator().next().viewParams());
    Assert.assertEquals("index", viewConfigDescriptor.getMetaData(View.class).iterator().next().name());
    Assert.assertEquals("xhtml", viewConfigDescriptor.getMetaData(View.class).iterator().next().extension());
    Assert.assertEquals("/public/", viewConfigDescriptor.getMetaData(View.class).iterator().next().basePath());
}
Also used : ViewConfigDescriptor(org.apache.deltaspike.core.api.config.view.metadata.ViewConfigDescriptor) ViewConfigResolver(org.apache.deltaspike.core.api.config.view.metadata.ViewConfigResolver) Test(org.junit.Test)

Example 20 with ViewConfigResolver

use of org.apache.deltaspike.core.api.config.view.metadata.ViewConfigResolver in project deltaspike by apache.

the class ViewConfigPathValidatorTest method testMissingPathButUnsupportedExtension.

@Test
public void testMissingPathButUnsupportedExtension() {
    this.viewConfigExtension.addPageDefinition(Pages.Index.class);
    ViewConfigResolver viewConfigResolver = this.viewConfigResolverProducer.createViewConfigResolver();
    List<String> supportedExtensions = new ArrayList<String>();
    supportedExtensions.add(View.Extension.JSF);
    try {
        new MockedViewConfigPathValidator(false).validateViewConfigPaths(null, viewConfigResolver, supportedExtensions);
    } catch (Exception e) {
        Assert.fail("unsupported extension wasn't ignored");
    }
}
Also used : ArrayList(java.util.ArrayList) ViewConfigResolver(org.apache.deltaspike.core.api.config.view.metadata.ViewConfigResolver) Test(org.junit.Test)

Aggregations

ViewConfigResolver (org.apache.deltaspike.core.api.config.view.metadata.ViewConfigResolver)44 Test (org.junit.Test)37 ViewConfigDescriptor (org.apache.deltaspike.core.api.config.view.metadata.ViewConfigDescriptor)36 ArrayList (java.util.ArrayList)5 Method (java.lang.reflect.Method)3 ViewControllerRef (org.apache.deltaspike.core.api.config.view.controller.ViewControllerRef)3 View (org.apache.deltaspike.jsf.api.config.view.View)3 DefaultErrorView (org.apache.deltaspike.core.api.config.view.DefaultErrorView)2 ViewConfig (org.apache.deltaspike.core.api.config.view.ViewConfig)2 PreRenderView (org.apache.deltaspike.core.api.config.view.controller.PreRenderView)2 JsfModuleConfig (org.apache.deltaspike.jsf.api.config.JsfModuleConfig)2 ErrorViewAwareAccessDeniedException (org.apache.deltaspike.security.api.authorization.ErrorViewAwareAccessDeniedException)2 MalformedURLException (java.net.MalformedURLException)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 ApplicationScoped (javax.enterprise.context.ApplicationScoped)1 Produces (javax.enterprise.inject.Produces)1 ConfigurableNavigationHandler (javax.faces.application.ConfigurableNavigationHandler)1 NavigationCase (javax.faces.application.NavigationCase)1 ProjectStage (javax.faces.application.ProjectStage)1