use of com.vaadin.flow.component.dependency.JsModule in project flow by vaadin.
the class LitTemplateParserImpl method getTemplateContent.
@Override
public TemplateData getTemplateContent(Class<? extends LitTemplate> clazz, String tag, VaadinService service) {
List<Dependency> dependencies = AnnotationReader.getAnnotationsFor(clazz, JsModule.class).stream().map(jsModule -> new Dependency(Dependency.Type.JS_MODULE, jsModule.value(), // load mode doesn't
LoadMode.EAGER)).collect(Collectors.toList());
for (DependencyFilter filter : service.getDependencyFilters()) {
dependencies = filter.filter(new ArrayList<>(dependencies), service);
}
Pair<Dependency, String> chosenDep = null;
for (Dependency dependency : dependencies) {
if (dependency.getType() != Dependency.Type.JS_MODULE) {
continue;
}
String url = dependency.getUrl();
String source = getSourcesFromTemplate(service, tag, url);
if (source == null) {
continue;
}
if (chosenDep == null) {
chosenDep = new Pair<>(dependency, source);
}
if (dependencyHasTagName(dependency, tag)) {
chosenDep = new Pair<>(dependency, source);
break;
}
}
Element templateElement = null;
if (chosenDep != null) {
templateElement = BundleLitParser.parseLitTemplateElement(chosenDep.getFirst().getUrl(), chosenDep.getSecond());
}
if (templateElement != null) {
// Template needs to be wrapped in an element with id, to look
// like a P2 template
Element parent = new Element(tag);
parent.attr("id", tag);
templateElement.appendTo(parent);
return new TemplateData(chosenDep.getFirst().getUrl(), templateElement);
}
getLogger().info("Couldn't find the " + "definition of the element with tag '{}' " + "in any lit template file declared using '@{}' annotations. " + "In a Spring Boot project, please ensure that the template's " + "groupId is added to the vaadin.whitelisted-packages " + "property. Otherwise, please Check the availability of the " + "template files in your WAR file or provide alternative " + "implementation of the method " + "LitTemplateParser.getTemplateContent() which should return " + "an element representing the content of the template file", tag, JsModule.class.getSimpleName());
return null;
}
use of com.vaadin.flow.component.dependency.JsModule in project flow by vaadin.
the class NpmTemplateParser method getTemplateContent.
@Override
public TemplateData getTemplateContent(Class<? extends PolymerTemplate<?>> clazz, String tag, VaadinService service) {
List<Dependency> dependencies = AnnotationReader.getAnnotationsFor(clazz, JsModule.class).stream().map(jsModule -> new Dependency(Dependency.Type.JS_MODULE, jsModule.value(), // load mode doesn't
LoadMode.EAGER)).collect(Collectors.toList());
for (DependencyFilter filter : service.getDependencyFilters()) {
dependencies = filter.filter(new ArrayList<>(dependencies), service);
}
Pair<Dependency, String> chosenDep = null;
for (Dependency dependency : dependencies) {
if (dependency.getType() != Dependency.Type.JS_MODULE) {
continue;
}
String url = dependency.getUrl();
String source = getSourcesFromTemplate(service, tag, url);
if (source == null) {
continue;
}
if (chosenDep == null) {
chosenDep = new Pair<>(dependency, source);
}
if (dependencyHasTagName(dependency, tag)) {
chosenDep = new Pair<>(dependency, source);
break;
}
}
if (chosenDep != null) {
Element templateElement = BundleParser.parseTemplateElement(chosenDep.getFirst().getUrl(), chosenDep.getSecond());
if (!JsoupUtils.getDomModule(templateElement, null).isPresent()) {
// Template needs to be wrapped in an element with id, to look
// like a P2 template
Element parent = new Element(tag);
parent.attr("id", tag);
templateElement.appendTo(parent);
}
return new TemplateData(chosenDep.getFirst().getUrl(), templateElement);
}
throw new IllegalStateException(String.format("Couldn't find the " + "definition of the element with tag '%s' " + "in any template file declared using '@%s' annotations. " + "In a Spring Boot project, please ensure that the template's " + "groupId is added to the vaadin.whitelisted-packages " + "property. Otherwise, please Check the availability of the " + "template files in your WAR file or provide alternative " + "implementation of the method getTemplateContent() which " + "should return an element representing the content of the " + "template file", tag, JsModule.class.getSimpleName()));
}
use of com.vaadin.flow.component.dependency.JsModule in project flow by vaadin.
the class ComponentMetaData method findDependencies.
private static DependencyInfo findDependencies(VaadinService service, Class<? extends Component> componentClass, DependencyInfo dependencyInfo, Set<Class<? extends Component>> scannedClasses) {
assert !scannedClasses.contains(componentClass);
scannedClasses.add(componentClass);
List<JsModule> jsModules = AnnotationReader.getJsModuleAnnotations(componentClass);
dependencyInfo.jsModules.addAll(jsModules);
dependencyInfo.javaScripts.addAll(AnnotationReader.getJavaScriptAnnotations(componentClass));
dependencyInfo.styleSheets.addAll(AnnotationReader.getStyleSheetAnnotations(componentClass));
dependencyInfo.cssImports.addAll(AnnotationReader.getCssImportAnnotations(componentClass));
List<Uses> usesList = AnnotationReader.getAnnotationsFor(componentClass, Uses.class);
for (Uses uses : usesList) {
Class<? extends Component> otherClass = uses.value();
if (!scannedClasses.contains(otherClass)) {
findDependencies(service, otherClass, dependencyInfo, scannedClasses);
}
}
return dependencyInfo;
}
use of com.vaadin.flow.component.dependency.JsModule in project flow by vaadin.
the class UIInternals method addFallbackDependencies.
private void addFallbackDependencies(DependencyInfo dependency) {
if (isFallbackChunkLoaded) {
return;
}
VaadinContext context = ui.getSession().getService().getContext();
FallbackChunk chunk = context.getAttribute(FallbackChunk.class);
if (chunk == null) {
if (getLogger().isDebugEnabled()) {
getLogger().debug("Fallback chunk is not available, skipping fallback dependencies load");
}
return;
}
Set<String> modules = chunk.getModules();
Set<CssImportData> cssImportsData = chunk.getCssImports();
if (modules.isEmpty() && cssImportsData.isEmpty()) {
getLogger().debug("Fallback chunk is empty, skipping fallback dependencies load");
return;
}
List<CssImport> cssImports = dependency.getCssImports();
List<JavaScript> javaScripts = dependency.getJavaScripts();
List<JsModule> jsModules = dependency.getJsModules();
if (jsModules.stream().map(JsModule::value).anyMatch(modules::contains)) {
loadFallbackChunk();
return;
}
if (javaScripts.stream().map(JavaScript::value).anyMatch(modules::contains)) {
loadFallbackChunk();
return;
}
if (cssImports.stream().map(this::buildData).anyMatch(cssImportsData::contains)) {
loadFallbackChunk();
return;
}
}
Aggregations