this, request, session, uiClass, new ArrayList<>(), provider); BootstrapContext context = new BootstrapContext(response, bootstrapResponse); bootstrapResponse.setUriResolver(context.getUriResolver()); .getBootstrapResponse(); session.modifyBootstrapResponse(fragmentResponse);
List<Node> fragmentNodes = context.getBootstrapResponse() .getFragmentNodes(); mainDiv.attr("id", context.getAppId()); mainDiv.addClass("v-app"); mainDiv.addClass(context.getThemeName()); mainDiv.addClass( context.getUIClass().getSimpleName().toLowerCase(Locale.ROOT)); if (style != null && !style.isEmpty()) { mainDiv.attr("style", style); fragmentNodes.add(mainDiv); VaadinRequest request = context.getRequest(); if (context.getPushMode().isEnabled()) { if (context.getRequest().getService().getDeploymentConfiguration() .isProductionMode()) { pushJS += ApplicationConstants.VAADIN_PUSH_JS;
protected void appendMainScriptTagContents(BootstrapContext context, StringBuilder builder) throws IOException { JsonObject appConfig = context.getApplicationParameters(); boolean isDebug = !context.getSession().getConfiguration() .isProductionMode(); if (isDebug) { /* * Add tracking needed for getting bootstrap metrics to the client * side Profiler if another implementation hasn't already been * added. */ builder.append( "if (typeof window.__gwtStatsEvent != 'function') {\n"); builder.append("vaadin.gwtStatsEvents = [];\n"); builder.append( "window.__gwtStatsEvent = function(event) {vaadin.gwtStatsEvents.push(event); return true;};\n"); builder.append("}\n"); } builder.append("vaadin.initApplication(\""); builder.append(context.getAppId()); builder.append("\","); appendJsonObject(builder, appConfig, isDebug); builder.append(");\n"); }
protected static JsonObject getApplicationParameters( BootstrapContext context) { VaadinRequest request = context.getRequest(); VaadinSession session = context.getSession(); VaadinService vaadinService = request.getService(); final boolean productionMode = session.getConfiguration() context.getUI().getUIId()); Locale locale = ServletHelper.findLocale(context.getSession(), context.getRequest());
Class<? extends UI> uiClass = context.getUI().getClass(); context.getRequest()); if (viewportContent != null) { head.appendElement(META_TAG).attr("name", "viewport") + "}"); if (context.getSession().getBrowser().isPhantomJS()) { context.getUriResolver() .resolveVaadinUri("context://" + ApplicationConstants.VAADIN_STATIC_FILES_PATH context.getUriResolver() .resolveVaadinUri("context://" + ApplicationConstants.VAADIN_STATIC_FILES_PATH + "server/webcomponents-lite.min.js")); if (context.getPushMode().isEnabled()) { head.appendChild(getPushScript(context)); if (context.getPreRenderMode().includeLiveVersion()) { head.appendChild(getBootstrapScript(initialUIDL, context)); head.appendChild(getClientEngineScript(context));
private static void setupDocumentBody(Document document, BootstrapContext context) { Element body; if (!context.getPreRenderMode().includePreRenderVersion()) { body = document.appendElement("body"); } else { com.vaadin.hummingbird.dom.Element uiElement = context.getUI() .getElement(); if (context.getPreRenderMode() == PreRenderMode.PRE_ONLY && !context.isProductionMode()) { Element preOnlyInfo = body.appendElement("div"); preOnlyInfo.addClass("v-system-error");
private static void includeDependencies(Element head, JsonObject initialUIDL, BootstrapContext context) { // Extract style sheets and load them eagerly JsonArray dependencies = initialUIDL .getArray(DependencyList.DEPENDENCY_KEY); if (dependencies == null || dependencies.length() == 0) { // No dependencies at all return; } Predicate<? super JsonObject> includeStyleSheets = object -> DependencyList.TYPE_STYLESHEET .equals(object.getString(DependencyList.KEY_TYPE)); com.vaadin.hummingbird.util.JsonUtil.objectStream(dependencies) .filter(includeStyleSheets).forEach(stylesheet -> { Element link = head.appendElement("link"); link.attr("rel", "stylesheet"); link.attr("type", "text/css"); String url = stylesheet.getString(DependencyList.KEY_URL); url = context.getUriResolver().resolveVaadinUri(url); link.attr("href", url); }); // Remove from initial UIDL JsonArray otherDependencies = com.vaadin.hummingbird.util.JsonUtil .objectStream(dependencies).filter(includeStyleSheets.negate()) .collect(com.vaadin.hummingbird.util.JsonUtil.asArray()); initialUIDL.put(DependencyList.DEPENDENCY_KEY, otherDependencies); }
private static String getBootstrapJS(JsonValue initialUIDL, BootstrapContext context) { boolean productionMode = context.getSession().getConfiguration() .isProductionMode(); String result = getBootstrapJS(); JsonObject appConfig = context.getApplicationParameters(); int indent = 0; if (!productionMode) { indent = 4; } String appConfigString = JsonUtil.stringify(appConfig, indent); String initialUIDLString = JsonUtil.stringify(initialUIDL, indent); // Browser interpret </script> as end of script no matter if it is // inside a string or not so we must escape it initialUIDLString = scriptEndTagPattern.matcher(initialUIDLString) .replaceAll("<\\\\x2F$1"); if (!productionMode) { // only used in debug mode by profiler result = result.replace("{{GWT_STAT_EVENTS}}", GWT_STAT_EVENTS_JS); } else { result = result.replace("{{GWT_STAT_EVENTS}}", ""); } result = result.replace("{{APP_ID}}", context.getAppId()); result = result.replace("{{INITIAL_UIDL}}", initialUIDLString); result = result.replace("{{CONFIG_JSON}}", appConfigString); return result; }
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 || clientEngineFile == null; if (resolveNow && BootstrapHandler.class.getResource( "/META-INF/resources/" + CLIENT_ENGINE_NOCACHE_FILE) != null) { return context.getUriResolver().resolveVaadinUri( "context://" + CLIENT_ENGINE_NOCACHE_FILE); } if (clientEngineFile == null) { throw new BootstrapException( "Client engine file name has not been resolved during initialization"); } return context.getUriResolver() .resolveVaadinUri("context://" + clientEngineFile); }
/** * 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); } }
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; }
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 pushJS = ServletHelper.getContextRootRelativePath(request) + "/"; if (request.getService().getDeploymentConfiguration() .isProductionMode()) { pushJS += ApplicationConstants.VAADIN_PUSH_JS; } else { pushJS += ApplicationConstants.VAADIN_PUSH_DEBUG_JS; } pushJS += versionQueryParam; return new Element(Tag.valueOf("script"), "") .attr("type", TYPE_TEXT_JAVASCRIPT).attr("src", pushJS); }
@Override public boolean synchronizedHandleRequest(VaadinSession session, VaadinRequest request, VaadinResponse response) throws IOException { // Find UI class Class<? extends UI> uiClass = getUIClass(request); UI ui = createAndInitUI(uiClass, request, session); BootstrapContext context = new BootstrapContext(request, response, session, ui); ServletHelper.setResponseNoCacheHeaders(response::setHeader, response::setDateHeader); Document document = getBootstrapPage(context); writeBootstrapPage(response, document.outerHtml()); return true; }
public String getAppId() { if (appId == null) { appId = getRequest().getService().getMainDivId(getSession(), getRequest()); } return appId; }
@Override protected String getContextRootUrl() { String root = context.getApplicationParameters() .getString(ApplicationConstants.CONTEXT_ROOT_URL); assert root.endsWith("/"); return root; }
.attr("content", "IE=11"); Class<? extends UI> uiClass = context.getUIClass(); viewportContent = ReflectTools .createInstance(viewportGeneratorClass) .getViewport(context.getRequest()); } catch (Exception e) { throw new RuntimeException( new UICreateEvent(context.getRequest(), context.getUIClass())); if (title != null) { head.appendElement("title").appendText(title); String themeName = context.getThemeName(); if (themeName != null) { String themeUri = getThemeUri(context, themeName); context.getSession().getCommunicationManager(), new FilterContext(context.getSession())); for (Dependency dependency : deps) { Type type = dependency.getType(); String url = context.getUriResolver() .resolveVaadinUri(dependency.getUrl()); if (type == Type.HTMLIMPORT) {
protected JsonObject getApplicationParameters(BootstrapContext context) { VaadinRequest request = context.getRequest(); VaadinSession session = context.getSession(); VaadinService vaadinService = request.getService(); String themeName = context.getThemeName(); if (themeName != null) { appConfig.put("theme", themeName); WidgetsetInfo widgetsetInfo = context.getWidgetsetInfo(); appConfig.put("widgetset", VaadinServlet .stripSpecialChars(widgetsetInfo.getWidgetsetName())); context.getSession(), context.getRequest()); appConfig.put(ApplicationConstants.VAADIN_DIR_URL, vaadinDir); appConfig.put(ApplicationConstants.FRONTEND_URL, context.getUriResolver().getFrontendUrl());
private String getBootstrapHtml(BootstrapContext context) { VaadinRequest request = context.getRequest(); VaadinResponse response = context.getResponse(); VaadinService vaadinService = request.getService(); .getBootstrapResponse(); Document document = Document.createShell(""); BootstrapPageResponse pageResponse = new BootstrapPageResponse(this, request, context.getSession(), context.getUIClass(), document, headers, fragmentResponse.getUIProvider()); pageResponse.setUriResolver(context.getUriResolver()); List<Node> fragmentNodes = fragmentResponse.getFragmentNodes(); Element body = document.body(); context.getSession().modifyBootstrapResponse(pageResponse);
/** * Gets the push mode to use. * * @return the desired push mode */ public PushMode getPushMode() { if (pushMode == null) { UICreateEvent event = new UICreateEvent(getRequest(), getUIClass()); pushMode = getBootstrapResponse().getUIProvider() .getPushMode(event); 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; }
@Override protected JsonObject getApplicationParameters(BootstrapContext context) { JsonObject parameters = super.getApplicationParameters(context); VaadinPortletResponse response = (VaadinPortletResponse) context .getResponse(); VaadinPortletRequest request = (VaadinPortletRequest) context .getRequest(); MimeResponse portletResponse = (MimeResponse) response .getPortletResponse(); ResourceURL resourceURL = portletResponse.createResourceURL(); resourceURL.setResourceID("v-browserDetails"); parameters.put("browserDetailsUrl", resourceURL.toString()); String serviceUrlParameterName = ApplicationConstants.V_RESOURCE_PATH; // If we are running in Liferay then we need to prefix all parameters // with the portlet namespace if (request instanceof VaadinLiferayRequest) { serviceUrlParameterName = response.getPortletResponse() .getNamespace() + serviceUrlParameterName; } parameters.put(ApplicationConstants.SERVICE_URL_PARAMETER_NAME, serviceUrlParameterName); return parameters; }