use of org.apache.deltaspike.core.api.config.view.metadata.ConfigDescriptor in project deltaspike by apache.
the class DefaultViewConfigResolver method initCaches.
protected void initCaches() {
//folders
Map<String, ConfigDescriptor> folderPathMapping = new HashMap<String, ConfigDescriptor>();
for (ConfigDescriptor folderConfigDescriptor : this.folderDefinitionToViewDefinitionEntryMapping.values()) {
if (folderPathMapping.containsKey(folderConfigDescriptor.toString())) {
throw new IllegalStateException("Duplicated config for the same folder configured. See: " + folderPathMapping.get(folderConfigDescriptor.toString()).getConfigClass().getName() + " and " + folderConfigDescriptor.getConfigClass().getName());
}
folderPathMapping.put(folderConfigDescriptor.getPath(), folderConfigDescriptor);
}
this.folderPathToViewDefinitionEntryMapping = Collections.unmodifiableMap(folderPathMapping);
//pages
Map<String, ViewConfigDescriptor> viewPathMapping = new HashMap<String, ViewConfigDescriptor>();
for (ViewConfigDescriptor pageConfigDescriptor : this.viewDefinitionToViewDefinitionEntryMapping.values()) {
if (viewPathMapping.containsKey(pageConfigDescriptor.getViewId())) {
throw new IllegalStateException("Duplicated config for the same page configured. See: " + viewPathMapping.get(pageConfigDescriptor.getViewId()).getConfigClass().getName() + " and " + pageConfigDescriptor.getConfigClass().getName());
}
viewPathMapping.put(pageConfigDescriptor.getPath(), pageConfigDescriptor);
}
this.viewPathToViewDefinitionEntryMapping = Collections.unmodifiableMap(viewPathMapping);
}
use of org.apache.deltaspike.core.api.config.view.metadata.ConfigDescriptor in project deltaspike by apache.
the class ViewRootAccessHandler method checkAccessTo.
public void checkAccessTo(UIViewRoot uiViewRoot) {
if (uiViewRoot == null) {
return;
}
String viewId = uiViewRoot.getViewId();
if (!checkView(viewId)) {
return;
}
this.checkedViewIds.add(viewId);
ConfigDescriptor configDescriptor = this.viewConfigResolver.getViewConfigDescriptor(viewId);
//topmost nodes get checked first
Stack<ConfigDescriptor> configDescriptorStack = new Stack<ConfigDescriptor>();
if (configDescriptor != null) {
configDescriptorStack.push(configDescriptor);
}
List<String> parentPathList = new ArrayList<String>();
createPathList(viewId, parentPathList);
ConfigDescriptor pathDescriptor;
for (String path : parentPathList) {
pathDescriptor = this.viewConfigResolver.getConfigDescriptor(path);
if (pathDescriptor != null) {
configDescriptorStack.push(pathDescriptor);
}
}
EditableAccessDecisionVoterContext accessDecisionVoterContext = BeanProvider.getContextualReference(EditableAccessDecisionVoterContext.class, false);
for (ConfigDescriptor currentConfigDescriptor : configDescriptorStack) {
SecurityUtils.invokeVoters(accessDecisionVoterContext, currentConfigDescriptor);
}
}
use of org.apache.deltaspike.core.api.config.view.metadata.ConfigDescriptor in project deltaspike by apache.
the class ViewConfigPathValidator method validateViewConfigPaths.
//allows to test and re-use it in a custom listener
// (if a custom listener is needed for supporting custom extensions or
// this listener is deactivated e.g. to change the order)
protected void validateViewConfigPaths(ServletContextEvent sce, ViewConfigResolver viewConfigResolver, List<String> supportedExtensions) {
for (ConfigDescriptor configDescriptor : viewConfigResolver.getConfigDescriptors()) {
try {
if (configDescriptor instanceof ViewConfigDescriptor) {
//currently other extensions aren't supported
String viewId = ((ViewConfigDescriptor) configDescriptor).getViewId();
String extension = viewId.substring(viewId.lastIndexOf('.') + 1);
if (!supportedExtensions.contains(extension)) {
continue;
}
}
if (!isValidPath(sce, configDescriptor)) {
if (configDescriptor instanceof DefaultFolderConfigDescriptor && !configDescriptor.getConfigClass().isAnnotationPresent(Folder.class)) {
LOGGER.fine(configDescriptor.getConfigClass().getName() + " looks like a marker interface" + " only used for providing meta-data, because the path " + configDescriptor.getPath() + " doesn't exist and the config-class isn't annotated with " + Folder.class.getName());
continue;
}
throw new IllegalStateException("path '" + configDescriptor.getPath() + "' is missing, but mapped by: " + configDescriptor.getConfigClass().getName());
}
} catch (Exception e) {
printException(e);
throw ExceptionUtils.throwAsRuntimeException(e);
}
}
}
use of org.apache.deltaspike.core.api.config.view.metadata.ConfigDescriptor in project deltaspike by apache.
the class ViewConfigTest method testNestedViewConfig.
@Test
public void testNestedViewConfig() {
this.viewConfigExtension.addPageDefinition(Pages.Index.class);
this.viewConfigExtension.addPageDefinition(Pages.Home.class);
this.viewConfigExtension.addPageDefinition(Pages.Admin.Index.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("/pages/", ((Folder) configDescriptor.getMetaData().iterator().next()).name());
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("/pages/admin/", ((Folder) configDescriptor.getMetaData().iterator().next()).name());
ViewConfigDescriptor viewConfigDescriptor = viewConfigResolver.getViewConfigDescriptor(Pages.Index.class);
Assert.assertNotNull(viewConfigDescriptor);
Assert.assertEquals("/pages/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, ((View) viewConfigDescriptor.getMetaData().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(View.Extension.XHTML, (viewConfigDescriptor.getMetaData(View.class).iterator().next()).extension());
viewConfigDescriptor = viewConfigResolver.getViewConfigDescriptor(Pages.Home.class);
Assert.assertNotNull(viewConfigDescriptor);
Assert.assertEquals("/pages/home.xhtml", viewConfigDescriptor.getViewId());
Assert.assertEquals(Pages.Home.class, viewConfigDescriptor.getConfigClass());
Assert.assertNotNull(viewConfigDescriptor.getMetaData());
Assert.assertEquals(1, viewConfigDescriptor.getMetaData().size());
Assert.assertEquals(View.NavigationMode.FORWARD, ((View) viewConfigDescriptor.getMetaData().iterator().next()).navigation());
Assert.assertEquals(View.ViewParameterMode.EXCLUDE, (viewConfigDescriptor.getMetaData(View.class).iterator().next()).viewParams());
Assert.assertEquals("home", (viewConfigDescriptor.getMetaData(View.class).iterator().next()).name());
Assert.assertEquals(View.Extension.XHTML, (viewConfigDescriptor.getMetaData(View.class).iterator().next()).extension());
ConfigDescriptor folderDescriptor = viewConfigResolver.getConfigDescriptor(Pages.Admin.class);
Assert.assertNotNull(folderDescriptor);
Assert.assertEquals("/pages/admin/", folderDescriptor.getPath());
Assert.assertEquals(Pages.Admin.class, folderDescriptor.getConfigClass());
Assert.assertNotNull(folderDescriptor.getMetaData());
Assert.assertEquals(1, folderDescriptor.getMetaData().size());
Assert.assertEquals("/pages/admin/", ((Folder) folderDescriptor.getMetaData().iterator().next()).name());
viewConfigDescriptor = viewConfigResolver.getViewConfigDescriptor(Pages.Admin.Index.class);
Assert.assertNotNull(viewConfigDescriptor);
Assert.assertEquals("/pages/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, ((View) viewConfigDescriptor.getMetaData().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(View.Extension.XHTML, (viewConfigDescriptor.getMetaData(View.class).iterator().next()).extension());
}
Aggregations