类com.vaadin.server.VaadinRequest源码实例Demo

下面列出了怎么用com.vaadin.server.VaadinRequest的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: vertx-vaadin   文件: VertxVaadinService.java
@Override
public String getStaticFileLocation(VaadinRequest request) {
    String staticFileLocation;
    // if property is defined in configurations, use that
    staticFileLocation = getDeploymentConfiguration().getResourcesPath();
    if (staticFileLocation != null) {
        return staticFileLocation;
    }

    VertxVaadinRequest vertxRequest = (VertxVaadinRequest) request;
    String requestedPath = vertxRequest.getRequest().path()
        .substring(
            Optional.ofNullable(vertxRequest.getRoutingContext().mountPoint())
                .map(String::length).orElse(0)
        );
    return VaadinServletService.getCancelingRelativePath(requestedPath);
}
 
源代码2 项目: vertx-vaadin   文件: VertxVaadinService.java
@Override
public String getMainDivId(VaadinSession session, VaadinRequest request, Class<? extends UI> uiClass) {
    String appId = request.getPathInfo();
    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;
}
 
源代码3 项目: cuba   文件: LinkHandler.java
/**
 * Called to handle the link.
 */
public void handle() {
    try {
        ExternalLinkContext linkContext = new ExternalLinkContext(requestParams, action, app);
        for (LinkHandlerProcessor processor : processors) {
            if (processor.canHandle(linkContext)) {
                processor.handle(linkContext);
                break;
            }
        }
    } finally {
        VaadinRequest request = VaadinService.getCurrentRequest();
        WrappedSession wrappedSession = request.getWrappedSession();
        wrappedSession.removeAttribute(AppUI.LAST_REQUEST_PARAMS_ATTR);
        wrappedSession.removeAttribute(AppUI.LAST_REQUEST_ACTION_ATTR);
    }
}
 
源代码4 项目: framework-spring-tutorial   文件: MyUI.java
@Override
protected void init(VaadinRequest request) {
    final VerticalLayout root = new VerticalLayout();
    root.setSizeFull();
    setContent(root);

    final CssLayout navigationBar = new CssLayout();
    navigationBar.addStyleName(ValoTheme.LAYOUT_COMPONENT_GROUP);
    navigationBar.addComponent(createNavigationButton("UI Scoped View",
            UIScopedView.VIEW_NAME));
    navigationBar.addComponent(createNavigationButton("View Scoped View",
            ViewScopedView.VIEW_NAME));
    root.addComponent(navigationBar);

    springViewDisplay = new Panel();
    springViewDisplay.setSizeFull();
    root.addComponent(springViewDisplay);
    root.setExpandRatio(springViewDisplay, 1.0f);
}
 
源代码5 项目: viritin   文件: Java8LocaleNegotiationStrategy.java
@Override
public Locale negotiate(List<Locale> supportedLocales,
        VaadinRequest vaadinRequest) {
    String languages = vaadinRequest.getHeader("Accept-Language");
    try {
        // Use reflection here, so the code compiles with jdk 1.7
        Class<?> languageRange = Class
                .forName("java.util.Locale$LanguageRange");
        Method parse = languageRange.getMethod("parse", String.class);
        Object priorityList = parse.invoke(null, languages);
        Method lookup = Locale.class.getMethod("lookup", List.class,
                Collection.class);
        return (Locale) lookup.invoke(null, priorityList, supportedLocales);
    } catch (ClassNotFoundException | IllegalAccessException | IllegalArgumentException | NoSuchMethodException | SecurityException | InvocationTargetException e) {
        throw new RuntimeException(
                "Java8LocaleNegotiontionStrategy need java 1.8 or newer.",
                e);
    }

}
 
源代码6 项目: viritin   文件: Issue309PojoForm.java
@Override
protected void init(VaadinRequest request) {
    AbstractForm<Pojo> form = new AbstractForm<Pojo>(Pojo.class) {

        private static final long serialVersionUID = 1251886098275380006L;
        IntegerField myInteger = new IntegerField("My Integer");

        @Override
        protected Component createContent() {
            FormLayout layout = new FormLayout(myInteger, getToolbar());
            return layout;
        }
    };

    form.setResetHandler((Pojo entity) -> {
        form.setEntity(null);
    });

    form.setEntity(new Pojo());
    setContent(form);
}
 
源代码7 项目: vaadinator   文件: TimesheetUI.java
@Override
protected void init(VaadinRequest request) {
	// TODO: remove test-entry into contet
	context.put(CONTEXT_LOGIN_USER, "sebastian");
	// create
	NavigationManager m = new NavigationManager();
	m.setMaintainBreadcrumb(true);
	TimesheetChangePresenter pres = obtainPresenterFactory(request.getContextPath()).createTimesheetChangePresenter(null);
	// Load the july timesheet into the presenter
	CouchDbTimesheetService tsService = new CouchDbTimesheetService();
	List<Timesheet> tsList = tsService.listAllTimesheet(new HashMap<String, Object>(context));
	for (Timesheet ts : tsList) {
		if (ts.getMonth() == 7 && ts.getYear() == 2014) {
			pres.setTimesheet(ts);
			break;
		}
	}
	// TODO: have list presenter before (instead of one)
	m.setCurrentComponent((Component) pres.getView().getComponent());
	setContent(m);
	// and go
	pres.startPresenting();
}
 
源代码8 项目: gantt   文件: DemoUI.java
@Override
protected void init(VaadinRequest request) {
    ganttListener = null;
    createGantt();

    MenuBar menu = controlsMenuBar();
    Panel controls = createControls();

    Component wrapper = UriFragmentWrapperFactory.wrapByUriFragment(UI.getCurrent().getPage().getUriFragment(),
            gantt);
    if (wrapper instanceof GanttListener) {
        ganttListener = (GanttListener) wrapper;
    }

    final VerticalLayout layout = new VerticalLayout();
    layout.setStyleName("demoContentLayout");
    layout.setMargin(false);
    layout.setSizeFull();
    layout.addComponent(menu);
    layout.addComponent(controls);
    layout.addComponent(wrapper);
    layout.setExpandRatio(wrapper, 1);

    setContent(layout);
}
 
源代码9 项目: gazpachoquest   文件: QuestionnairesUI.java
@Override
public void init(VaadinRequest request) {
    logger.info("New Vaadin UI created");
    String invitation = request.getParameter("invitation");
    logger.info("Invitation: {} of sessions : {}", invitation);
    setSizeFull();
    GazpachoViewDisplay viewDisplay = new GazpachoViewDisplay();
    setContent(viewDisplay);

    navigator = new Navigator(this, (ViewDisplay) viewDisplay);
    navigator.addProvider(viewProvider);
    navigator.setErrorProvider(new GazpachoErrorViewProvider());

    if (isUserSignedIn()) {
        navigator.navigateTo(QuestionnaireView.NAME);
    } else {
        navigator.navigateTo(LoginView.NAME);
    }
}
 
源代码10 项目: boot-examples   文件: Application.java
@Override
protected void init(VaadinRequest vaadinRequest) {
    getPage().setTitle("Root UI");

    Table table = new Table("Customer Table");

    table.addContainerProperty("firstName", String.class, null);
    table.addContainerProperty("lastName", String.class, null);
    table.addContainerProperty("id", Long.class, null);

    for (Customer c : this.customerRepository.findAll())
        table.addItem(new Object[]{c.getFirstName(), c.getLastName(), c.getId()}, c.getId());

    table.setSizeFull();
    table.setColumnHeader("firstName", "First Name");
    table.setColumnHeader("lastName", "First Name");
    setContent(table);
}
 
源代码11 项目: consulo   文件: SchemeRequestHandler.java
@Override
public boolean synchronizedHandleRequest(VaadinSession session, VaadinRequest request, VaadinResponse response) throws IOException {
  response.setContentType("text/css");

  byte[] text = generateCss();

  response.setCacheTime(-1);
  response.setStatus(HttpURLConnection.HTTP_OK);

  try (OutputStream stream = response.getOutputStream()) {
    response.setContentLength(text.length);
    stream.write(text);
  }

  return true;
}
 
源代码12 项目: consulo   文件: SchemeRequestHandler.java
private static boolean hasPathPrefix(VaadinRequest request, String prefix) {
  String pathInfo = request.getPathInfo();

  if (pathInfo == null) {
    return false;
  }

  if (!prefix.startsWith("/")) {
    prefix = '/' + prefix;
  }

  if (pathInfo.startsWith(prefix)) {
    return true;
  }

  return false;
}
 
源代码13 项目: RDFUnit   文件: RDFUnitDemo.java
private String getClientIpAddr(VaadinRequest request) {
    String ip = request.getHeader("X-Forwarded-For");
    if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
        ip = request.getHeader("Proxy-Client-IP");
    }
    if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
        ip = request.getHeader("WL-Proxy-Client-IP");
    }
    if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
        ip = request.getHeader("HTTP_CLIENT_IP");
    }
    if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
        ip = request.getHeader("HTTP_X_FORWARDED_FOR");
    }
    if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
        ip = request.getRemoteAddr();
    }
    return ip;
}
 
源代码14 项目: vertx-vaadin   文件: VertxVaadinService.java
@Override
protected boolean requestCanCreateSession(VaadinRequest request) {
    if (ServletUIInitHandler.isUIInitRequest(request)) {
        // This is the first request if you are embedding by writing the
        // embedding code yourself
        return true;
    } else if (isOtherRequest(request)) {
        /*
         * I.e URIs that are not RPC calls or static (theme) files.
         */
        return true;
    }

    return false;
}
 
源代码15 项目: vertx-vaadin   文件: VertxVaadinService.java
private boolean isOtherRequest(VaadinRequest request) {
    // TODO This should be refactored in some way. It should not be
    // necessary to check all these types.
    return (!ServletPortletHelper.isAppRequest(request)
        && !ServletUIInitHandler.isUIInitRequest(request)
        && !ServletPortletHelper.isFileUploadRequest(request)
        && !ServletPortletHelper.isHeartbeatRequest(request)
        && !ServletPortletHelper.isPublishedFileRequest(request)
        && !ServletPortletHelper.isUIDLRequest(request) && !ServletPortletHelper
        .isPushRequest(request));
}
 
源代码16 项目: vertx-vaadin   文件: VertxVaadinService.java
/**
 * Gets a relative path you can use to refer to the context root.
 *
 * @param request the request for which the location should be determined
 * @return A relative path to the context root. Never ends with a slash (/).
 */
public static String getContextRootRelativePath(VaadinRequest request) {
    VertxVaadinRequest servletRequest = (VertxVaadinRequest) request;
    // Generate location from the request by finding how many "../" should
    // be added to the servlet path before we get to the context root

    String servletPath = "";

    String pathInfo = servletRequest.getPathInfo();
    if (pathInfo != null && !pathInfo.isEmpty()) {
        servletPath += pathInfo;
    }

    return getCancelingRelativePath(servletPath);
}
 
源代码17 项目: vertx-vaadin   文件: SessionStoreAdapterIT.java
@Override
protected void init(VaadinRequest request) {
    request.getService().addSessionDestroyListener(e -> {
        ((SessionTestVerticle) ((VertxVaadinService) e.getService()).getVertx().getOrCreateContext().get("mySelf"))
            .registerSessionEvent("Session destroyed");
    });
}
 
源代码18 项目: vertx-vaadin   文件: VertxVaadinServiceUT.java
private String testLocation(String mountPoint, String pathInfo) {
    VertxVaadinService service = mock(VertxVaadinService.class);
    HttpServerRequest httpServerRequest = mock(HttpServerRequest.class);

    RoutingContext routingContext = mock(RoutingContext.class);
    when(routingContext.mountPoint()).thenReturn(mountPoint);
    when(routingContext.request()).thenReturn(httpServerRequest);

    VaadinRequest req = new VertxVaadinRequest(service, routingContext);

    when(httpServerRequest.path()).thenReturn(Optional.ofNullable(mountPoint).orElse("") + pathInfo);
    return VertxVaadinService.getContextRootRelativePath(req);
}
 
源代码19 项目: anx   文件: MainUI.java
@Override
protected void init(VaadinRequest vaadinRequest) {
	Page.getCurrent().setTitle("Advanced Netconf Explorer");
    addStyleName(ValoTheme.UI_WITH_MENU);
    
    setContent(new RetrieverView(this, vaadinRequest));
    addStyleName("loginview");
}
 
源代码20 项目: piranha   文件: HelloVaadin.java
/**
 * Init the UI.
 * 
 * @param request the request.
 */
@Override
protected void init(VaadinRequest request) {
    final VerticalLayout layout = new VerticalLayout();
    layout.setMargin(true);
    layout.setSpacing(true);
    setContent(layout);
    layout.addComponent(new Label("Hello Vaadin"));
}
 
源代码21 项目: dubbox   文件: HomePageUI.java
/**
 * 首页初始化
 * @param vaadinRequest
 */
@Override
protected void init(VaadinRequest vaadinRequest) {
    VerticalLayout content = new VerticalLayout();
    content.addComponent(createTitle());
    content.addComponent(createTabSheet());
    setContent(content);
}
 
源代码22 项目: cuba   文件: AppUI.java
@Override
protected void refresh(VaadinRequest request) {
    super.refresh(request);

    boolean sessionIsAlive = true;

    Connection connection = app.getConnection();

    if (connection.isAuthenticated()) {
        // Ping middleware session if connected
        log.debug("Ping middleware session");

        try {
            UserSession session = connection.getSession();
            if (session instanceof ClientUserSession
                    && ((ClientUserSession) session).isAuthenticated()) {
                userSessionService.getUserSession(session.getId());

                if (hasAuthenticatedSession()
                        && !Objects.equals(userSession, session)) {
                    setUserSession(session);
                }
            }
        } catch (Exception e) {
            sessionIsAlive = false;

            app.exceptionHandlers.handle(new com.vaadin.server.ErrorEvent(e));
        }

        if (sessionIsAlive) {
            events.publish(new SessionHeartbeatEvent(app));
        }
    }

    urlChangeHandler.restoreState();

    if (sessionIsAlive) {
        events.publish(new UIRefreshEvent(this));
    }
}
 
源代码23 项目: cuba   文件: AppUI.java
protected void processExternalLink(VaadinRequest request, NavigationState requestedState) {
    if (isLinkHandlerRequest(request)) {
        processLinkHandlerRequest(request);
    } else {
        processRequest(requestedState);
    }
}
 
源代码24 项目: cuba   文件: AppUI.java
protected boolean isLinkHandlerRequest(VaadinRequest request) {
    WrappedSession wrappedSession = request.getWrappedSession();
    if (wrappedSession == null) {
        return false;
    }

    String action = (String) wrappedSession.getAttribute(LAST_REQUEST_ACTION_ATTR);

    return webConfig.getLinkHandlerActions().contains(action);
}
 
源代码25 项目: cuba   文件: ConnectionImpl.java
protected WebBrowser getWebBrowserDetails() {
    // timezone info is passed only on VaadinSession creation
    WebBrowser webBrowser = VaadinSession.getCurrent().getBrowser();
    VaadinRequest currentRequest = VaadinService.getCurrentRequest();
    // update web browser instance if current request is not null
    // it can be null in case of background/async processing of login request
    if (currentRequest != null) {
        webBrowser.updateRequestDetails(currentRequest);
    }
    return webBrowser;
}
 
源代码26 项目: cuba   文件: CubaWebJarsHandler.java
protected boolean browserHasNewestVersion(VaadinRequest request, long resourceLastModifiedTimestamp) {
    if (resourceLastModifiedTimestamp < 1) {
        // We do not know when it was modified so the browser cannot have an
        // up-to-date version
        return false;
    }
    /*
     * The browser can request the resource conditionally using an
     * If-Modified-Since header. Check this against the last modification
     * time.
     */
    try {
        // If-Modified-Since represents the timestamp of the version cached
        // in the browser
        long headerIfModifiedSince = request
                .getDateHeader("If-Modified-Since");

        if (headerIfModifiedSince >= resourceLastModifiedTimestamp) {
            // Browser has this an up-to-date version of the resource
            return true;
        }
    } catch (Exception e) {
        // Failed to parse header. Fail silently - the browser does not have
        // an up-to-date version in its cache.
    }
    return false;
}
 
源代码27 项目: cuba   文件: WebHttpSessionUrlsHolder.java
@Override
public void setUrls(String selectorId, List<String> urls) {
    VaadinRequest vaadinRequest = VaadinService.getCurrentRequest();
    if (vaadinRequest != null)
        vaadinRequest.getWrappedSession().setAttribute(getAttributeName(selectorId), urls);
    else {
        HttpSession httpSession = getHttpSession();
        if (httpSession != null) {
            httpSession.setAttribute(getAttributeName(selectorId), urls);
        }
    }
}
 
源代码28 项目: grpc-by-example-java   文件: ChatUI.java
@Override
protected void init(VaadinRequest vaadinRequest) {

  final UI currentUI = getCurrent();
  final StreamObserver<Chat.ChatMessage> observer = stub.chat(new StreamObserver<Chat.ChatMessageFromServer>() {
    @Override
    public void onNext(Chat.ChatMessageFromServer chatMessageFromServer) {
      currentUI.access(() -> layout.addComponent(new Label(String.format("%s: %s" ,
                                                                         chatMessageFromServer.getMessage().getFrom() ,
                                                                         chatMessageFromServer.getMessage().getMessage()))));
    }

    @Override
    public void onError(Throwable throwable) {
      logger.log(Level.SEVERE , "gRPC Error" , throwable);
    }

    @Override
    public void onCompleted() {
      logger.info("gRPC Call Completed");
    }
  });

  button.addClickListener(e -> {

    final String nameValue = name.getValue();
    final String messageValue = message.getValue();

    observer.onNext(Chat.ChatMessage.newBuilder()
                                    .setFrom(nameValue)
                                    .setMessage(messageValue)
                                    .build());
  });

}
 
源代码29 项目: hawkbit   文件: AbstractHawkbitLoginUI.java
@Override
protected void init(final VaadinRequest request) {
    HawkbitCommonUtil.initLocalization(this, uiProperties.getLocalization(), i18n);
    SpringContextHelper.setContext(context);

    params = UriComponentsBuilder.fromUri(Page.getCurrent().getLocation()).build().getQueryParams();

    setContent(buildContent());

    fillOutUsernameTenantFields();
}
 
源代码30 项目: jpa-invoicer   文件: VaadinUI.java
@Override
protected void init(VaadinRequest request) {
    super.init(request);
    if (!userSession.isLoggedIn()) {
        getContent().setVisible(false);
        addWindow(loginWindow.get());
    }
}