下面列出了怎么用com.vaadin.server.VaadinServlet的API类实例代码及写法,或者点击链接到github查看源代码。
@Override
public InputStream getThemeResourceAsStream(UI uI, String themeName, String resource) {
String filename = VaadinServlet.THEME_DIR_PATH + '/' + themeName
+ "/" + resource;
String normalized = Paths.get(filename).normalize().toString();
if (!normalized.startsWith("VAADIN/")
|| normalized.contains("/../")) {
throw new VertxException(String.format(
"Requested resource [%s] not accessible in the VAADIN directory or access to it is forbidden.",
filename));
}
FileSystem fileSystem = getVertx().fileSystem();
if (fileSystem.existsBlocking(filename)) {
return new ByteArrayInputStream(fileSystem.readFileBlocking(filename).getBytes());
}
return null;
}
@Override
public void start() throws SensorHubException
{
// reset java util logging config so we don't get annoying atmosphere logs
LogManager.getLogManager().reset();//.getLogger("org.atmosphere").setLevel(Level.OFF);
vaadinServlet = new VaadinServlet();
Map<String, String> initParams = new HashMap<String, String>();
initParams.put(SERVLET_PARAM_UI_CLASS, AdminUI.class.getCanonicalName());
initParams.put(SERVLET_PARAM_MODULE_ID, getLocalID());
if (config.widgetSet != null)
initParams.put(WIDGETSET, config.widgetSet);
initParams.put("productionMode", "true"); // set to false to compile theme on-the-fly
HttpServer.getInstance().deployServlet(vaadinServlet, initParams, "/admin/*", "/VAADIN/*");
HttpServer.getInstance().addServletSecurity("/admin/*", "admin");
}
@Override
public String getThemeName(BootstrapContext context) {
String themeName = context.getRequest()
.getParameter(VaadinServlet.URL_PARAMETER_THEME);
if (themeName == null) {
themeName = super.getThemeName(context);
}
return themeName;
}
@Test
public void shouldIgnoreDefaultWidgetsetFromVaadinServletConfiguration(TestContext context) {
WithoutDefaultWidgetSet verticle = new WithoutDefaultWidgetSet();
rule.vertx().deployVerticle(verticle, context.asyncAssertSuccess(event -> {
assertThat(verticle.config.containsKey(VaadinServlet.PARAMETER_WIDGETSET)).isFalse();
}));
}
@Test
public void shouldUseWidgetsetFromVaadinServletConfiguration(TestContext context) {
WithDefaultWidgetSet verticle = new WithDefaultWidgetSet();
rule.vertx().deployVerticle(verticle, context.asyncAssertSuccess(event -> {
assertThat(verticle.config.containsKey(VaadinServlet.PARAMETER_WIDGETSET)).isTrue();
assertThat(verticle.config.getString(VaadinServlet.PARAMETER_WIDGETSET)).isEqualTo(TEST_WIDGETSET);
}));
}
@Bean
public VaadinServlet vaadinServlet(final LocalizedSystemMessagesProvider localizedSystemMessagesProvider) {
return new SpringVaadinServlet() {
@Override
public void servletInitialized() throws ServletException {
super.servletInitialized();
getService().setSystemMessagesProvider(localizedSystemMessagesProvider);
}
};
}
@Override
protected void init(VaadinRequest request) {
// for mobile, set yet another theme
if (VaadinServlet.getCurrent() instanceof TouchKitServlet) {
setTheme("touchkitexex");
}
super.init(request);
}
@Override
public String getConfiguredWidgetset(VaadinRequest request) {
return getDeploymentConfiguration().getWidgetset(VaadinServlet.DEFAULT_WIDGETSET);
}