/** * Get initial page settings if a {@link PageConfigurator} is found for the * current component tree after navigation has resolved. * * @param context * the bootstrap context * @return initial page settings or empty optional if no * {@link PageConfigurator} found */ static Optional<InitialPageSettings> getInitialPageSettings( BootstrapHandler.BootstrapContext context) { UI ui = context.getUI(); Optional<PageConfigurator> pageConfigurator = ui.getChildren() .filter(component -> component instanceof PageConfigurator) .map(component -> (PageConfigurator) component).findFirst(); if (pageConfigurator.isPresent()) { InitialPageSettings settings = createInitialPageSettingsObject( context); pageConfigurator.get().configurePage(settings); return Optional.of(settings); } return Optional.empty(); }
private static InitialPageSettings createInitialPageSettingsObject( BootstrapHandler.BootstrapContext context) { UI ui = context.getUI(); VaadinRequest request = context.getRequest(); WebBrowser browser = context.getSession().getBrowser(); String pathInfo = request.getPathInfo(); if (pathInfo == null) { pathInfo = ""; } else { assert pathInfo.startsWith("/"); pathInfo = pathInfo.substring(1); } Router router = ui.getRouter(); NavigationEvent navigationEvent = new NavigationEvent(router, new Location(pathInfo, QueryParameters.full(request.getParameterMap())), ui, NavigationTrigger.PAGE_LOAD); List<HasElement> components = ui.getChildren() .map(component -> (HasElement) component) .collect(Collectors.toList()); AfterNavigationEvent afterNavigationEvent = new AfterNavigationEvent( new LocationChangeEvent(navigationEvent.getSource(), navigationEvent.getUI(), navigationEvent.getTrigger(), navigationEvent.getLocation(), components)); return new InitialPageSettings(request, ui, afterNavigationEvent, browser); }
/** * Resolves the initial page title for the given bootstrap context and * cancels any pending JS execution for it. * * @param context * the bootstrap context * @return the optional initial page title */ protected static Optional<String> resolvePageTitle( BootstrapContext context) { // check for explicitly set page title, e.g. by PageTitleGenerator or // View level title or page.setTitle String title = context.getUI().getInternals().getTitle(); if (title != null) { // cancel the unnecessary execute javascript context.getUI().getInternals().cancelPendingTitleUpdate(); } return Optional.ofNullable(title); }
document.appendChild(doctype); Element html = document.appendElement("html"); html.attr("lang", context.getUI().getLocale().getLanguage()); Element head = html.appendElement("head"); html.appendElement("body"); context.getResponse(), document, context.getUI(), context.getUriResolver()); context.getSession().getService().modifyBootstrapPage(response);
/** * Gets the push mode to use. * * @return the desired push mode */ public PushMode getPushMode() { if (pushMode == null) { pushMode = getUI().getPushConfiguration().getPushMode(); if (pushMode == null) { pushMode = getRequest().getService() .getDeploymentConfiguration().getPushMode(); } if (pushMode.isEnabled() && !getRequest().getService().ensurePushAvailable()) { /* * Fall back if not supported (ensurePushAvailable will log * information to the developer the first time this happens) */ pushMode = PushMode.DISABLED; } } return pushMode; }
/** * Gets the URI resolver to use for bootstrap resources. * * @return the URI resolver */ public BootstrapUriResolver getUriResolver() { if (uriResolver == null) { uriResolver = new BootstrapUriResolver(getUI()); } return uriResolver; }
protected static JsonObject getApplicationParameters( BootstrapContext context) { JsonObject appConfig = getApplicationParameters(context.getRequest(), context.getSession()); appConfig.put(ApplicationConstants.UI_ID_PARAMETER, context.getUI().getUIId()); return appConfig; }
private static List<Element> setupDocumentHead(Element head, BootstrapContext context) { setupMetaAndTitle(head, context); setupCss(head, context); JsonObject initialUIDL = getInitialUidl(context.getUI()); Map<LoadMode, JsonArray> dependenciesToProcessOnServer = popDependenciesToProcessOnServer( initialUIDL); setupFrameworkLibraries(head, initialUIDL, context); return applyUserDependencies(head, context, dependenciesToProcessOnServer); }