private static String getBootstrapJS(JsonValue initialUIDL, BootstrapContext context) { boolean productionMode = context.getSession().getConfiguration() .isProductionMode(); String result = getBootstrapJS(); JsonObject appConfig = context.getApplicationParameters(); result = result.replace("{{APP_ID}}", context.getAppId()); result = result.replace("{{CONFIG_JSON}}", appConfigString);
/** * Returns the specified body size content for the target route chain that * was navigated to, specified with {@link BodySize} on the {@link Route} * annotated class or the {@link ParentLayout} of the route. * * @param context * the bootstrap context * @return the content value string for body size style element */ static String getBodySizeContent( BootstrapHandler.BootstrapContext context) { Optional<BodySize> bodySize = context .getPageConfigurationAnnotation(BodySize.class); // Set full size by default if @BodySize is not used String height = bodySize.map(BodySize::height).orElse("100vh"); String width = bodySize.map(BodySize::width).orElse("100vw"); StringBuilder bodyString = new StringBuilder(); bodyString.append("body {"); if (!height.isEmpty()) { bodyString.append("height:").append(height).append(";"); } if (!width.isEmpty()) { bodyString.append("width:").append(width).append(";"); } bodyString.append("margin:0;"); bodyString.append("}"); return bodyString.toString(); }
BootstrapHandler.BootstrapContext context) { List<Meta> metaAnnotations = context .getPageConfigurationAnnotations(Meta.class); boolean illegalValue = false; Map<String, String> map = new HashMap<>();
private static void setupPwa(Document document, BootstrapContext context) { VaadinService vaadinService = context.getSession().getService(); if (vaadinService == null) { return;
ui.setLocale(session.getLocale()); BootstrapContext context = new BootstrapContext(request, response, session, ui); .getPageConfigurationAnnotation(Push.class); DeploymentConfiguration deploymentConfiguration = context.getSession() .getService().getDeploymentConfiguration(); PushMode pushMode = push.map(Push::value)
document.appendChild(doctype); Element html = document.appendElement("html"); html.attr("lang", context.getUI().getLocale().getLanguage()); Element head = html.appendElement("head"); html.appendElement("body"); if (!context.isProductionMode()) { exportUsageStatistics(document); context.getRequest(), context.getSession(), context.getResponse(), document, context.getUI(), context.getUriResolver()); context.getSession().getService().modifyBootstrapPage(response);
private static void appendWebComponentsPolyfills(Element head, BootstrapContext context) { VaadinSession session = context.getSession(); DeploymentConfiguration config = session.getConfiguration(); createJavaScriptElement(context.getUriResolver() .resolveVaadinUri(es5AdapterUrl), false)); String resolvedUrl = context.getUriResolver() .resolveVaadinUri(webcomponentsLoaderUrl); head.appendChild(createJavaScriptElement(resolvedUrl, false));
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); }
/** * 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; }
/** * Returns the specified viewport content for the target route chain that * was navigated to, specified with {@link Inline} on the {@link Route} * annotated class or the {@link ParentLayout} of the route. * * @param context * the bootstrap context * @return the content value string for viewport meta tag */ static Optional<InlineTargets> getInlineTargets( BootstrapHandler.BootstrapContext context) { List<Inline> inlineAnnotations = context .getPageConfigurationAnnotations(Inline.class); if (inlineAnnotations.isEmpty()) { return Optional.empty(); } else { InlineTargets inlines = new InlineTargets(); inlineAnnotations.forEach(inline -> inlines .addInlineDependency(inline, context.getRequest())); return Optional.of(inlines); } }
private static String getClientEngineUrl(BootstrapContext context) { // use nocache version of client engine if it // has been compiled by SDM or eclipse // In production mode, this should really be loaded by the static block // so emit a warning if we get here (tests will always get here) final boolean productionMode = context.getSession().getConfiguration() .isProductionMode(); boolean resolveNow = !productionMode || getClientEngine() == null; if (resolveNow && ClientResourcesUtils.getResource( "/META-INF/resources/" + CLIENT_ENGINE_NOCACHE_FILE) != null) { return context.getUriResolver().resolveVaadinUri( "context://" + CLIENT_ENGINE_NOCACHE_FILE); } if (getClientEngine() == null) { throw new BootstrapException( "Client engine file name has not been resolved during initialization"); } return context.getUriResolver() .resolveVaadinUri("context://" + getClientEngine()); }
/** * Gets the service URL as a URL relative to the request URI. * * @param context * the bootstrap context * @return the relative service URL */ protected static String getServiceUrl(BootstrapContext context) { String pathInfo = context.getRequest().getPathInfo(); if (pathInfo == null) { return "."; } else { /* * Make a relative URL to the servlet by adding one ../ for each * path segment in pathInfo (i.e. the part of the requested path * that comes after the servlet mapping) */ return ServletHelper.getCancelingRelativePath(pathInfo); } }
private static Element getPushScript(BootstrapContext context) { VaadinRequest request = context.getRequest(); // Parameter appended to JS to bypass caches after version upgrade. String versionQueryParam = "?v=" + Version.getFullVersion(); // Load client-side dependencies for push support String pushJSPath = ServletHelper.getContextRootRelativePath(request) + "/"; if (request.getService().getDeploymentConfiguration() .isProductionMode()) { pushJSPath += ApplicationConstants.VAADIN_PUSH_JS; } else { pushJSPath += ApplicationConstants.VAADIN_PUSH_DEBUG_JS; } pushJSPath += versionQueryParam; return createJavaScriptElement(pushJSPath); }
protected void setupPushConnectionFactory( PushConfiguration pushConfiguration, BootstrapContext context) { VaadinService service = context.getSession().getService(); Iterator<PushConnectionFactory> iter = ServiceLoader .load(PushConnectionFactory.class, service.getClassLoader()) .iterator(); if (iter.hasNext()) { pushConfiguration.setPushConnectionFactory(iter.next()); if (iter.hasNext()) { throw new BootstrapException( "Multiple " + PushConnectionFactory.class.getName() + " implementations found"); } } }
/** * Gets the application id. * * The application id is defined by * {@link VaadinService#getMainDivId(VaadinSession, VaadinRequest)} * * @return the application id */ public String getAppId() { if (appId == null) { appId = getRequest().getService().getMainDivId(getSession(), getRequest()); } return appId; }
/** * Returns the specified viewport content for the target route chain that * was navigated to, specified with {@link Viewport} on the {@link Route} * annotated class or the {@link ParentLayout} of the route. * * @param context * the bootstrap context * @return the content value string for viewport meta tag */ static Optional<String> getViewportContent( BootstrapHandler.BootstrapContext context) { return context.getPageConfigurationAnnotation(Viewport.class) .map(Viewport::value); }
private static void inlineEs6Collections(Element head, BootstrapContext context) { if (!context.getSession().getBrowser().isEs6Supported()) { head.appendChild(createInlineJavaScriptElement(ES6_COLLECTIONS)); } }
static ThemeSettings getThemeSettings( BootstrapHandler.BootstrapContext context) { Optional<ThemeDefinition> themeDefinition = context.getTheme(); if (themeDefinition.isPresent()) { return getThemeSettings(context, themeDefinition.get()); } return null; }
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 void setupFrameworkLibraries(Element head, JsonObject initialUIDL, BootstrapContext context) { inlineEs6Collections(head, context); appendWebComponentsPolyfills(head, context); if (context.getPushMode().isEnabled()) { head.appendChild(getPushScript(context)); } head.appendChild(getBootstrapScript(initialUIDL, context)); head.appendChild(createJavaScriptElement(getClientEngineUrl(context))); }