@Override protected URL getApplicationUrl(VaadinRequest request) throws MalformedURLException { return getServlet().getApplicationUrl((VaadinServletRequest) request); }
@Override public String getServiceName() { return getServlet().getServletName(); }
@Override public String getMimeType(String resourceName) { return getServlet().getServletContext().getMimeType(resourceName); }
@Override public InputStream getThemeResourceAsStream(UI uI, String themeName, String resource) throws IOException { String filename = "/" + VaadinServlet.THEME_DIR_PATH + '/' + themeName + "/" + resource; URL resourceUrl = getServlet().findResourceURL(filename); if (resourceUrl != null) { // security check: do not permit navigation out of the VAADIN // directory if (!getServlet().isAllowedVAADINResourceUrl(null, resourceUrl)) { throw new IOException(String.format( "Requested resource [{0}] not accessible in the VAADIN directory or access to it is forbidden.", filename)); } return resourceUrl.openStream(); } else { return null; } }
@Override public String getMainDivId(VaadinSession session, VaadinRequest request, Class<? extends UI> uiClass) { String appId = null; try { URL appUrl = getServlet() .getApplicationUrl((VaadinServletRequest) request); appId = appUrl.getPath(); } catch (MalformedURLException e) { // Just ignore problem here } if (appId == null || appId.isEmpty() || "/".equals(appId)) { appId = "ROOT"; } appId = appId.replaceAll("[^a-zA-Z0-9]", ""); // Add hashCode to the end, so that it is still (sort of) // predictable, but indicates that it should not be used in CSS // and // such: int hashCode = appId.hashCode(); if (hashCode < 0) { hashCode = -hashCode; } appId = appId + "-" + hashCode; return appId; }
@Override public File getBaseDirectory() { final String realPath = VaadinServlet .getResourcePath(getServlet().getServletContext(), "/"); if (realPath == null) { return null; } return new File(realPath); }
/** * Gets the currently used Vaadin servlet. The current servlet is * automatically defined when initializing the servlet and when processing * requests to the server (see {@link ThreadLocal}) and in * {@link VaadinSession#access(Runnable)} and {@link UI#access(Runnable)}. * In other cases, (e.g. from background threads), the current servlet is * not automatically defined. * <p> * The current servlet is derived from the current service using * {@link VaadinService#getCurrent()} * * @return the current Vaadin servlet instance if available, otherwise * <code>null</code> * * @since 7.0 */ public static VaadinServlet getCurrent() { VaadinService vaadinService = CurrentInstance.get(VaadinService.class); if (vaadinService instanceof VaadinServletService) { VaadinServletService vss = (VaadinServletService) vaadinService; return vss.getServlet(); } else { return null; } }
final ServletConfig vaadinServletConfig = service.getServlet() .getServletConfig(); getLogger().log(Level.WARNING, "Failed to initialize Atmosphere for " + service.getServlet().getServletName() + ". Push will not work.", e);
@Override public String getServiceName() { return getServlet().getServletName(); }
@Override public String getMimeType(String resourceName) { return getServlet().getServletContext().getMimeType(resourceName); }
@Override public String getMainDivId(VaadinSession session, VaadinRequest request) { String appId = null; try { @SuppressWarnings("deprecation") URL appUrl = getServlet() .getApplicationUrl((VaadinServletRequest) request); appId = appUrl.getPath(); } catch (MalformedURLException e) { // Just ignore problem here } if (appId == null || "".equals(appId) || "/".equals(appId)) { appId = "ROOT"; } appId = appId.replaceAll("[^a-zA-Z0-9]", ""); // Add hashCode to the end, so that it is still (sort of) // predictable, but indicates that it should not be used in CSS // and // such: int hashCode = appId.hashCode(); if (hashCode < 0) { hashCode = -hashCode; } appId = appId + "-" + hashCode; return appId; }
/** * Gets the currently used Vaadin servlet. The current servlet is * automatically defined when initializing the servlet and when processing * requests to the server (see {@link ThreadLocal}) and in * {@link VaadinSession#access(Command)} and {@link UI#access(Command)}. In * other cases, (e.g. from background threads), the current servlet is not * automatically defined. * <p> * The current servlet is derived from the current service using * {@link VaadinService#getCurrent()} * * @return the current Vaadin servlet instance if available, otherwise * <code>null</code> * * @since 7.0 */ public static VaadinServlet getCurrent() { VaadinService vaadinService = CurrentInstance.get(VaadinService.class); if (vaadinService instanceof VaadinServletService) { VaadinServletService vss = (VaadinServletService) vaadinService; return vss.getServlet(); } else { return null; } }
public StubVaadinSession(EventBus eventBus) { this.eventBus = eventBus; final VaadinServlet vaadinServlet = mock(VaadinServlet.class); final ServletConfig servletConfig = mock(ServletConfig.class); this.context = mock(ServletContext.class); doReturn(context).when(servletConfig).getServletContext(); doReturn(servletConfig).when(vaadinServlet).getServletConfig(); doReturn(context).when(vaadinServlet).getServletContext(); this.ui = mock(UI.class); doReturn("foo").when(ui).getEmbedId(); this.vaadinService = mock(VaadinServletService.class); doReturn(vaadinServlet).when(vaadinService).getServlet(); this.vaadinSession = new VaadinSession(vaadinService) { @Override public boolean hasLock() { return true; } }; this.vaadinSession.setAttribute(UI.class, this.ui); this.sessionStore = new SessionStore(vaadinSession, eventBus); this.vaadinSession.setAttribute(SessionStore.class, sessionStore); }
.getServlet(); try { URL autoDetected = servlet.findResourceURL(bundleFileName);
final ServletConfig vaadinServletConfig = service.getServlet() .getServletConfig(); throw new ServiceException( "Failed to initialize Atmosphere for " + service.getServlet().getServletName() + ". Push will not work.", e);
private void setUpUISession() { final VaadinServlet vaadinServlet = mock(VaadinServlet.class); UI ui = mock(UI.class); doReturn("foo").when(ui).getEmbedId(); VaadinServletService vaadinService = mock(VaadinServletService.class); doReturn(vaadinServlet).when(vaadinService).getServlet(); VaadinSession vaadinSession = new VaadinSession(vaadinService) { @Override public boolean hasLock() { return true; } }; vaadinSession.setAttribute(UI.class, ui); SessionStore sessionStore = new SessionStore(vaadinSession, eventBus); vaadinSession.setAttribute(SessionStore.class, sessionStore); UI.setCurrent(ui); VaadinSession.setCurrent(vaadinSession); VaadinService.setCurrent(vaadinService); sessionStore.createBeanStore(UiContextReference.ofCurrentUi()); sessionStore.getBeanStore(UiContextReference.ofCurrentUi()).put(Key.get(AdmincentralFlavour.class), AdmincentralFlavour.ofM5); }