use of com.vaadin.flow.component.webcomponent.WebComponentConfiguration 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.component.webcomponent.WebComponentConfiguration in project flow by vaadin.
the class WebComponentExporterTest method configuration_bindProxy_throwsIfExporterSharesTagWithComponent.
@Test(expected = IllegalStateException.class)
@SuppressWarnings("unchecked")
public void configuration_bindProxy_throwsIfExporterSharesTagWithComponent() {
SharedTagExporter sharedTagExporter = new SharedTagExporter();
WebComponentConfiguration<SharedTagComponent> sharedConfig = (WebComponentConfiguration<SharedTagComponent>) new WebComponentExporter.WebComponentConfigurationFactory().create(sharedTagExporter);
sharedConfig.createWebComponentBinding(new MockInstantiator(), mock(Element.class), Json.createObject());
}
use of com.vaadin.flow.component.webcomponent.WebComponentConfiguration in project flow by vaadin.
the class WebComponentProviderTest method setupConfigurations.
@SuppressWarnings({ "unchecked", "rawtypes" })
@SafeVarargs
private final WebComponentConfigurationRegistry setupConfigurations(Class<? extends WebComponentExporter<? extends Component>>... exporters) {
WebComponentConfigurationRegistry registry = setUpRegistry();
final Set<Class<? extends WebComponentExporter<? extends Component>>> set = Stream.of(exporters).collect(Collectors.toSet());
WebComponentExporter.WebComponentConfigurationFactory factory = new WebComponentExporter.WebComponentConfigurationFactory();
Set<WebComponentConfiguration<? extends Component>> configurations = new HashSet<>();
for (Class<? extends WebComponentExporter<? extends Component>> exporter : exporters) configurations.add(factory.create(new DefaultWebComponentExporterFactory(exporter).create()));
registry.setConfigurations(configurations);
return registry;
}
use of com.vaadin.flow.component.webcomponent.WebComponentConfiguration in project flow by vaadin.
the class WebComponentProvider method synchronizedHandleRequest.
@Override
public boolean synchronizedHandleRequest(VaadinSession session, VaadinRequest request, VaadinResponse response) throws IOException {
String pathInfo = request.getPathInfo();
final ComponentInfo componentInfo = new ComponentInfo(pathInfo);
if (!componentInfo.hasExtension()) {
LoggerFactory.getLogger(WebComponentProvider.class).info("Received web-component request without extension " + "information (.js/.html) with request path {}", pathInfo);
return false;
}
if (componentInfo.getTag() == null) {
LoggerFactory.getLogger(WebComponentProvider.class).info("Received web-component request for non-custom element with request path {}", pathInfo);
return false;
}
if (componentInfo.isHTML()) {
LoggerFactory.getLogger(WebComponentProvider.class).info("Received web-component request for html component in npm" + " mode with request path {}", pathInfo);
return false;
}
WebComponentConfigurationRegistry registry = WebComponentConfigurationRegistry.getInstance(request.getService().getContext());
Optional<WebComponentConfiguration<? extends Component>> optionalWebComponentConfiguration = registry.getConfiguration(componentInfo.tag);
if (optionalWebComponentConfiguration.isPresent()) {
WebComponentConfiguration<? extends Component> webComponentConfiguration = optionalWebComponentConfiguration.get();
String generated;
Supplier<String> responder;
response.setContentType(CONTENT_TYPE_TEXT_JAVASCRIPT_UTF_8);
responder = () -> generateNPMResponse(webComponentConfiguration.getTag(), request, response);
if (cache == null) {
generated = responder.get();
} else {
generated = cache.computeIfAbsent(componentInfo.tag, moduleTag -> responder.get());
}
IOUtils.write(generated, response.getOutputStream(), StandardCharsets.UTF_8);
} else {
response.sendError(HttpServletResponse.SC_NOT_FOUND, "No web component for " + Optional.ofNullable(componentInfo.tag).orElse("<null>"));
}
return true;
}
Aggregations