use of com.vaadin.flow.server.webcomponent.WebComponentConfigurationRegistry in project flow by vaadin.
the class WebComponentConfigurationRegistryInitializer method initialize.
@Override
@SuppressWarnings("rawtypes")
public void initialize(Set<Class<?>> classSet, VaadinContext context) throws VaadinInitializerException {
WebComponentConfigurationRegistry instance = WebComponentConfigurationRegistry.getInstance(context);
if (classSet == null || classSet.isEmpty()) {
instance.setConfigurations(Collections.emptySet());
return;
}
try {
Set<WebComponentExporterFactory> factories = WebComponentExporterUtils.getFactories(classSet);
Set<WebComponentConfiguration<? extends Component>> configurations = constructConfigurations(factories);
validateTagNames(configurations);
validateDistinctTagNames(configurations);
instance.setConfigurations(configurations);
} catch (Exception e) {
throw new VaadinInitializerException(String.format("%s failed to collect %s implementations!", WebComponentConfigurationRegistryInitializer.class.getSimpleName(), WebComponentExporter.class.getSimpleName()), e);
}
}
use of com.vaadin.flow.server.webcomponent.WebComponentConfigurationRegistry in project flow by vaadin.
the class WebComponentProviderTest method setExporters_exportersHasOnePush_pushIsSet.
@Test
public void setExporters_exportersHasOnePush_pushIsSet() {
WebComponentConfigurationRegistry registry = setupConfigurations(ThemedComponentExporter.class, MyComponentExporter.class);
Assert.assertTrue(registry.getEmbeddedApplicationAnnotation(Push.class).isPresent());
}
use of com.vaadin.flow.server.webcomponent.WebComponentConfigurationRegistry in project flow by vaadin.
the class WebComponentBootstrapHandler method createAndInitUI.
@Override
protected BootstrapContext createAndInitUI(Class<? extends UI> uiClass, VaadinRequest request, VaadinResponse response, VaadinSession session) {
if (!canHandleRequest(request)) {
throw new IllegalStateException("Unexpected request URL '" + getRequestUrl(request) + "' in the bootstrap handler for web " + "component UI which should handle path " + PATH_PATTERN.toString());
}
final String serviceUrl = getServiceUrl(request, response);
BootstrapContext context = super.createAndInitUI(WebComponentUI.class, request, response, session);
JsonObject config = context.getApplicationParameters();
String pushURL = context.getSession().getConfiguration().getPushURL();
if (pushURL == null) {
pushURL = serviceUrl;
} else {
try {
URI uri = new URI(serviceUrl);
pushURL = uri.resolve(new URI(pushURL)).toASCIIString();
} catch (URISyntaxException exception) {
throw new IllegalStateException(String.format("Can't resolve pushURL '%s' based on the service URL '%s'", pushURL, serviceUrl), exception);
}
}
PushConfiguration pushConfiguration = context.getUI().getPushConfiguration();
pushConfiguration.setPushUrl(pushURL);
assert serviceUrl.endsWith("/");
config.put(ApplicationConstants.SERVICE_URL, serviceUrl);
config.put(ApplicationConstants.APP_WC_MODE, true);
WebComponentConfigurationRegistry registry = WebComponentConfigurationRegistry.getInstance(request.getService().getContext());
JsonArray tags = registry.getConfigurations().stream().map(conf -> Json.create(conf.getTag())).collect(JsonUtils.asArray());
config.put("webcomponents", tags);
config.put(ApplicationConstants.DEVMODE_GIZMO_ENABLED, false);
return context;
}
use of com.vaadin.flow.server.webcomponent.WebComponentConfigurationRegistry in project flow by vaadin.
the class WebComponentBootstrapHandlerTest method mockRequest.
private VaadinRequest mockRequest(boolean hasConfig) {
VaadinContext context = Mockito.mock(VaadinContext.class);
VaadinService service = Mockito.mock(VaadinService.class);
VaadinRequest request = Mockito.mock(VaadinRequest.class);
Mockito.when(request.getService()).thenReturn(service);
Mockito.when(service.getContext()).thenReturn(context);
WebComponentConfigurationRegistry registry = Mockito.mock(WebComponentConfigurationRegistry.class);
Mockito.when(context.getAttribute(Mockito.eq(WebComponentConfigurationRegistry.class), Mockito.any())).thenReturn(registry);
Mockito.when(registry.hasConfigurations()).thenReturn(hasConfig);
Mockito.when(request.getPathInfo()).thenReturn("/web-component/web-component-ui.js");
return request;
}
use of com.vaadin.flow.server.webcomponent.WebComponentConfigurationRegistry in project flow by vaadin.
the class WebComponentUI method assignThemeVariant.
private void assignThemeVariant() {
WebComponentConfigurationRegistry registry = getConfigurationRegistry();
Optional<Theme> theme = registry.getEmbeddedApplicationAnnotation(Theme.class);
if (!theme.isPresent() || theme.get().themeClass().equals(AbstractTheme.class)) {
return;
}
AbstractTheme themeInstance = Instantiator.get(this).getOrCreate(theme.get().themeClass());
ThemeDefinition definition = new ThemeDefinition(theme.get());
Map<String, String> attributes = themeInstance.getHtmlAttributes(definition.getVariant());
registry.getConfigurations().forEach(config -> addAttributes(config.getTag(), attributes));
}
Aggregations