@Override public String getMimeType(String resourceName) { return getServlet().getServletContext().getMimeType(resourceName); }
@Override public File getBaseDirectory() { final String realPath = VaadinServlet .getResourcePath(getServlet().getServletContext(), "/"); if (realPath == null) { return null; } return new File(realPath); }
/** * Finds the given resource from the web content folder or using the class * loader. * * @since 7.7 * @param filename * The file to find, starting with a "/" * @return The URL to the given file, or null if the file was not found * @throws IOException * if there was a problem while locating the file */ public URL findResourceURL(String filename) throws IOException { URL resourceUrl = getServletContext().getResource(filename); if (resourceUrl == null) { // try if requested file is found from class loader // strip leading "/" otherwise stream from JAR wont work if (filename.startsWith("/")) { filename = filename.substring(1); } resourceUrl = getService().getClassLoader().getResource(filename); } return resourceUrl; }
throws IOException, ServletException { final ServletContext sc = getServletContext(); URL resourceUrl = findResourceURL(filename);
/** * Create a servlet service instance that allows the use of a custom service * URL. * * @param servlet * @param deploymentConfiguration * @param serviceUrl custom service URL to use (relative to context path, starting * with a slash) or null for default * @throws ServiceException */ public Vaadin4SpringServletService(VaadinServlet servlet, DeploymentConfiguration deploymentConfiguration, String serviceUrl) throws ServiceException { super(servlet, deploymentConfiguration, serviceUrl); logger.info("Using custom Vaadin4Spring servlet service"); applicationContext = WebApplicationContextUtils.getWebApplicationContext(servlet.getServletContext()); }
/** * Create a servlet service instance that allows the use of a custom service * URL. * * @param servlet * @param deploymentConfiguration * @param serviceUrl custom service URL to use (relative to context path, starting * with a slash) or null for default * @throws ServiceException */ public Vaadin4SpringServletService(VaadinServlet servlet, DeploymentConfiguration deploymentConfiguration, String serviceUrl) throws ServiceException { super(servlet, deploymentConfiguration, serviceUrl); logger.info("Using custom Vaadin4Spring servlet service"); applicationContext = WebApplicationContextUtils.getWebApplicationContext(servlet.getServletContext()); }
@Override public String getMimeType(String resourceName) { return getServlet().getServletContext().getMimeType(resourceName); }
/** * Allows the only UI's Guice component provider to be injected. */ @Provides GuiceComponentProvider getUiGuiceComponentProvider() { return (GuiceComponentProvider) VaadinServlet.getCurrent().getServletContext().getAttribute("componentProvider"); }
@Override protected InputStream getApplicationResourceAsStream(Class<?> contextClass, String fileName) { ServletContext servletContext = VaadinServlet.getCurrent().getServletContext(); return servletContext.getResourceAsStream("/VAADIN/" + fileName); } }
private static URL getURL(int nodeId) { final URI currentLocation = Page.getCurrent().getLocation(); final String contextRoot = VaadinServlet.getCurrent().getServletContext().getContextPath(); final String redirectFragment = contextRoot + "/element/node.jsp?node=" + nodeId; try { return new URL(currentLocation.toURL(), redirectFragment); } catch (MalformedURLException e) { throw Throwables.propagate(e); } }
protected String getFullUrl(final String urlFragment) { final URI currentLocation = Page.getCurrent().getLocation(); final String contextRoot = VaadinServlet.getCurrent().getServletContext().getContextPath(); try { return new URL(currentLocation.toURL(), contextRoot + "/" + urlFragment).toString(); } catch (final MalformedURLException e) { throw new RuntimeException("Failed to create full URL from current location: " + currentLocation + ", context root: " + contextRoot + ", url: " + urlFragment); } } }
protected String getFullUrl(final String urlFragment) { final URI currentLocation = Page.getCurrent().getLocation(); final String contextRoot = VaadinServlet.getCurrent().getServletContext().getContextPath(); try { return new URL(currentLocation.toURL(), contextRoot + "/" + urlFragment).toString(); } catch (final MalformedURLException e) { throw new RuntimeException("Failed to create full URL from current location: " + currentLocation + ", context root: " + contextRoot + ", url: " + urlFragment); } } }
protected String getFullUrl(final String urlFragment) { final URI currentLocation = Page.getCurrent().getLocation(); final String contextRoot = VaadinServlet.getCurrent().getServletContext().getContextPath(); try { return new URL(currentLocation.toURL(), contextRoot + "/" + urlFragment).toString(); } catch (final MalformedURLException e) { throw new RuntimeException("Failed to create full URL from current location: " + currentLocation + ", context root: " + contextRoot + ", url: " + urlFragment); } } }
private static URL getURL(int nodeId) { final URI currentLocation = Page.getCurrent().getLocation(); final String contextRoot = VaadinServlet.getCurrent().getServletContext().getContextPath(); final String redirectFragment = contextRoot + "/element/node.jsp?node=" + nodeId; try { return new URL(currentLocation.toURL(), redirectFragment); } catch (MalformedURLException e) { throw Throwables.propagate(e); } }
private void init() { VaadinServlet vaadinServlet = VaadinServlet.getCurrent(); if (vaadinServlet == null) { System.err.println("Couldn't get current instance of VaadinServlet"); return; } context = WebApplicationContextUtils.getRequiredWebApplicationContext(vaadinServlet.getServletContext()); }
public UiContextBoundComponentProvider(UiContextReference uiContextReference) { this(uiContextReference, (GuiceComponentProvider) VaadinServlet.getCurrent().getServletContext().getAttribute("componentProvider"), CurrentUiContextReference.get()); }
@Override public UidlWriter createUidlWriter() { return new CubaUidlWriter(getServlet().getServletContext()); }
@Override public void execute(final List<VertexRef> targets, final OperationContext operationContext) { final Collection<VertexRef> availableNodes = m_geoAssetProvider.getNodesWithCoordinates(); final StringBuilder sb = new StringBuilder(); sb.append(VaadinServlet.getCurrent().getServletContext().getContextPath()); sb.append("/node-maps#search/nodeId%20in%20"); final List<String> nodeIds = new ArrayList<>(); for (final VertexRef ref : targets) { if (availableNodes.contains(ref)) { nodeIds.add(ref.getId()); } } final Iterator<String> i = nodeIds.iterator(); while (i.hasNext()) { sb.append(i.next()); if (i.hasNext()) { sb.append(","); } } final String redirectUrl = sb.toString(); LOG.info("redirecting to: " + redirectUrl); final UI ui = operationContext.getMainWindow(); ui.getPage().getJavaScript().execute("window.location = '" + redirectUrl + "';"); }
@Override public void buttonClick(ClickEvent event) { // try if alarm is there, otherwise show information dialog OnmsAlarm alarm = alarmDao.get(alarmId); if (alarm == null) { new DialogWindow(source.getUI(), "Alarm does not exist!", "The alarm information cannot be shown. \nThe alarm does not exist anymore. \n\nPlease refresh the Alarm Table."); return; } // alarm still exists, show alarm details final URI currentLocation = Page.getCurrent().getLocation(); final String contextRoot = VaadinServlet.getCurrent().getServletContext().getContextPath(); final String redirectFragment = contextRoot + "/alarm/detail.htm?quiet=true&id=" + alarmId; LOG.debug("alarm {} clicked, current location = {}, uri = {}", alarmId, currentLocation, redirectFragment); try { source.getUI().addWindow( new InfoWindow(new URL(currentLocation.toURL(), redirectFragment), new LabelCreator() { @Override public String getLabel() { return "Alarm Info " + alarmId; } })); } catch (MalformedURLException e) { LOG.error(e.getMessage(), e); } } });
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); }