Example usage for com.vaadin.server VaadinRequest getPathInfo

List of usage examples for com.vaadin.server VaadinRequest getPathInfo

Introduction

In this page you can find the example usage for com.vaadin.server VaadinRequest getPathInfo.

Prototype

public String getPathInfo();

Source Link

Document

Gets the path of the requested resource relative to the application.

Usage

From source file:annis.gui.CommonUI.java

License:Apache License

private InstanceConfig getInstanceConfig(VaadinRequest request) {
    String instance = null;/*from   ww  w .  ja  v a 2s  .co m*/
    String pathInfo = request.getPathInfo();

    if (pathInfo != null && pathInfo.startsWith("/")) {
        pathInfo = pathInfo.substring(1);
    }
    if (pathInfo != null && pathInfo.endsWith("/")) {
        pathInfo = pathInfo.substring(0, pathInfo.length() - 1);
    }

    Map<String, InstanceConfig> allConfigs = loadInstanceConfig();

    if (pathInfo != null && !pathInfo.isEmpty()) {
        instance = pathInfo;
    }

    if (instance != null && allConfigs.containsKey(instance)) {
        // return the config that matches the parsed name
        return allConfigs.get(instance);
    } else if (allConfigs.containsKey("default")) {
        // return the default config
        return allConfigs.get("default");
    } else if (allConfigs.size() > 0) {
        // just return any existing config as a fallback
        log.warn("Instance config {} not found or null and default config is not available.", instance);
        return allConfigs.values().iterator().next();
    }

    // default to an empty instance config
    return new InstanceConfig();
}

From source file:annis.gui.EmbeddedVisUI.java

License:Apache License

@Override
protected void init(VaadinRequest request) {
    super.init(request);

    String rawPath = request.getPathInfo();
    List<String> splittedPath = new LinkedList<>();
    if (rawPath != null) {
        rawPath = rawPath.substring(URL_PREFIX.length());
        splittedPath = Splitter.on("/").omitEmptyStrings().trimResults().limit(3).splitToList(rawPath);
    }//  w w  w. j  a  va  2s .c  o  m

    if (splittedPath.size() == 1) {
        // a visualizer definition which get the results from a remote salt file
        String saltUrl = request.getParameter(KEY_SALT);
        if (saltUrl == null) {
            displayGeneralHelp();
        } else {
            generateVisFromRemoteURL(splittedPath.get(0), saltUrl, request.getParameterMap());
        }
    } else if (splittedPath.size() >= 3) {
        // a visualizer definition visname/corpusname/documentname
        if ("htmldoc".equals(splittedPath.get(0))) {
            showHtmlDoc(splittedPath.get(1), splittedPath.get(2), request.getParameterMap());
        } else {
            displayMessage("Unknown visualizer \"" + splittedPath.get(0) + "\"",
                    "Only \"htmldoc\" is supported yet.");
        }
    } else {
        displayGeneralHelp();
    }
    addStyleName("loaded-embedded-vis");
}

From source file:annis.gui.requesthandler.BinaryRequestHandler.java

License:Apache License

@Override
public boolean handleRequest(VaadinSession session, VaadinRequest request, VaadinResponse response)
        throws IOException {
    if (request.getPathInfo() != null && request.getPathInfo().startsWith(prefix)) {
        if ("GET".equalsIgnoreCase(request.getMethod())) {
            sendResponse(session, request, response, true);
            return true;
        } else if ("HEAD".equalsIgnoreCase(request.getMethod())) {
            sendResponse(session, request, response, false);
            return true;
        }//from   w w w . ja v a2 s . com
    }
    return false;
}

From source file:annis.gui.requesthandler.LoginServletRequestHandler.java

License:Apache License

@Override
public boolean handleRequest(VaadinSession session, VaadinRequest request, VaadinResponse response)
        throws IOException {
    if (request.getPathInfo() != null && request.getPathInfo().startsWith(prefix)) {
        if ("GET".equalsIgnoreCase(request.getMethod())) {
            doGet(session, request, response);
            return true;
        } else if ("POST".equalsIgnoreCase(request.getMethod())) {
            doPost(session, request, response);
            return true;
        }//ww  w .  j  a  v  a 2  s. c o m
    }
    return false;
}

From source file:annis.gui.requesthandler.ResourceRequestHandler.java

License:Apache License

@Override
public boolean handleRequest(VaadinSession session, VaadinRequest request, VaadinResponse response)
        throws IOException {
    if (request.getPathInfo() != null && request.getPathInfo().startsWith(prefix)) {
        String uuidString = StringUtils.removeStart(request.getPathInfo(), prefix);
        UUID uuid = UUID.fromString(uuidString);
        IFrameResourceMap map = VaadinSession.getCurrent().getAttribute(IFrameResourceMap.class);
        if (map == null) {
            response.setStatus(404);/*w  w  w .j  av  a 2 s . co m*/
        } else {
            IFrameResource res = map.get(uuid);
            if (res != null) {
                response.setStatus(200);
                response.setContentType(res.getMimeType());
                response.getOutputStream().write(res.getData());
            }
        }
        return true;
    }
    return false;
}

From source file:annis.gui.SearchUI.java

License:Apache License

@Override
protected void init(VaadinRequest request) {
    super.init(request);

    this.instanceConfig = getInstanceConfig(request);

    getPage().setTitle(instanceConfig.getInstanceDisplayName() + " (ANNIS Corpus Search)");

    queryController = new QueryController(this);

    refresh = new Refresher();
    // deactivate refresher by default
    refresh.setRefreshInterval(-1);//from ww w.  j  a  v a2  s  . c  o  m
    refresh.addListener(queryController);
    addExtension(refresh);

    // always get the resize events directly
    setImmediate(true);

    VerticalLayout mainLayout = new VerticalLayout();
    setContent(mainLayout);

    mainLayout.setSizeFull();
    mainLayout.setMargin(false);

    final ScreenshotMaker screenshot = new ScreenshotMaker(this);
    addExtension(screenshot);

    css = new CSSInject(this);

    HorizontalLayout layoutToolbar = new HorizontalLayout();
    layoutToolbar.setWidth("100%");
    layoutToolbar.setHeight("-1px");

    mainLayout.addComponent(layoutToolbar);
    layoutToolbar.addStyleName("toolbar");
    layoutToolbar.addStyleName("border-layout");

    Button btAboutAnnis = new Button("About ANNIS");
    btAboutAnnis.addStyleName(ChameleonTheme.BUTTON_SMALL);
    btAboutAnnis.setIcon(new ThemeResource("info.gif"));

    btAboutAnnis.addClickListener(new AboutClickListener());

    btBugReport = new Button("Report Bug");
    btBugReport.addStyleName(ChameleonTheme.BUTTON_SMALL);
    btBugReport.setDisableOnClick(true);
    btBugReport.setIcon(new ThemeResource("../runo/icons/16/email.png"));
    btBugReport.addListener(new Button.ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            screenshot.makeScreenshot();
            btBugReport.setCaption("bug report is initialized...");
        }
    });

    String bugmail = (String) VaadinSession.getCurrent().getAttribute("bug-e-mail");
    if (bugmail != null && !bugmail.isEmpty() && !bugmail.startsWith("${")
            && new EmailValidator("").isValid(bugmail)) {
        this.bugEMailAddress = bugmail;
    }
    btBugReport.setVisible(this.bugEMailAddress != null);

    lblUserName = new Label("not logged in");
    lblUserName.setWidth("-1px");
    lblUserName.setHeight("-1px");
    lblUserName.addStyleName("right-aligned-text");

    btLoginLogout = new Button("Login", new Button.ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            if (isLoggedIn()) {
                // logout
                Helper.setUser(null);
                Notification.show("Logged out", Notification.Type.TRAY_NOTIFICATION);
                updateUserInformation();
            } else {
                showLoginWindow();
            }
        }
    });
    btLoginLogout.setSizeUndefined();
    btLoginLogout.setStyleName(ChameleonTheme.BUTTON_SMALL);
    btLoginLogout.setIcon(new ThemeResource("../runo/icons/16/user.png"));

    Button btOpenSource = new Button("Help us to make ANNIS better!");
    btOpenSource.setStyleName(BaseTheme.BUTTON_LINK);
    btOpenSource.addListener(new Button.ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            Window w = new HelpUsWindow();
            w.setCaption("Help us to make ANNIS better!");
            w.setModal(true);
            w.setResizable(true);
            w.setWidth("600px");
            w.setHeight("500px");
            addWindow(w);
            w.center();
        }
    });

    layoutToolbar.addComponent(btAboutAnnis);
    layoutToolbar.addComponent(btBugReport);
    layoutToolbar.addComponent(btOpenSource);
    layoutToolbar.addComponent(lblUserName);
    layoutToolbar.addComponent(btLoginLogout);

    layoutToolbar.setSpacing(true);
    layoutToolbar.setComponentAlignment(btAboutAnnis, Alignment.MIDDLE_LEFT);
    layoutToolbar.setComponentAlignment(btBugReport, Alignment.MIDDLE_LEFT);
    layoutToolbar.setComponentAlignment(btOpenSource, Alignment.MIDDLE_CENTER);
    layoutToolbar.setComponentAlignment(lblUserName, Alignment.MIDDLE_RIGHT);
    layoutToolbar.setComponentAlignment(btLoginLogout, Alignment.MIDDLE_RIGHT);
    layoutToolbar.setExpandRatio(btOpenSource, 1.0f);

    //HorizontalLayout hLayout = new HorizontalLayout();
    final HorizontalSplitPanel hSplit = new HorizontalSplitPanel();
    hSplit.setSizeFull();

    mainLayout.addComponent(hSplit);
    mainLayout.setExpandRatio(hSplit, 1.0f);

    AutoGeneratedQueries autoGenQueries = new AutoGeneratedQueries("example queries", this);

    controlPanel = new ControlPanel(queryController, instanceConfig, autoGenQueries);
    controlPanel.setWidth(100f, Layout.Unit.PERCENTAGE);
    controlPanel.setHeight(100f, Layout.Unit.PERCENTAGE);
    hSplit.setFirstComponent(controlPanel);

    tutorial = new TutorialPanel();
    tutorial.setHeight("99%");

    mainTab = new TabSheet();
    mainTab.setSizeFull();
    mainTab.addTab(autoGenQueries, "example queries");
    mainTab.addTab(tutorial, "Tutorial");

    queryBuilder = new QueryBuilderChooser(queryController, this, instanceConfig);
    mainTab.addTab(queryBuilder, "Query Builder");

    hSplit.setSecondComponent(mainTab);
    hSplit.setSplitPosition(CONTROL_PANEL_WIDTH, Unit.PIXELS);
    hSplit.addSplitterClickListener(new AbstractSplitPanel.SplitterClickListener() {
        @Override
        public void splitterClick(AbstractSplitPanel.SplitterClickEvent event) {
            if (event.isDoubleClick()) {
                if (hSplit.getSplitPosition() == CONTROL_PANEL_WIDTH) {
                    // make small
                    hSplit.setSplitPosition(0.0f, Unit.PIXELS);
                } else {
                    // reset to default width
                    hSplit.setSplitPosition(CONTROL_PANEL_WIDTH, Unit.PIXELS);
                }
            }
        }
    });
    // hLayout.setExpandRatio(mainTab, 1.0f);

    addAction(new ShortcutListener("^Query builder") {
        @Override
        public void handleAction(Object sender, Object target) {
            mainTab.setSelectedTab(queryBuilder);
        }
    });

    addAction(new ShortcutListener("Tutor^eial") {
        @Override
        public void handleAction(Object sender, Object target) {
            mainTab.setSelectedTab(tutorial);
        }
    });

    getPage().addUriFragmentChangedListener(this);

    getSession().addRequestHandler(new RequestHandler() {
        @Override
        public boolean handleRequest(VaadinSession session, VaadinRequest request, VaadinResponse response)
                throws IOException {
            checkCitation(request);

            if (request.getPathInfo() != null && request.getPathInfo().startsWith("/vis-iframe-res/")) {
                String uuidString = StringUtils.removeStart(request.getPathInfo(), "/vis-iframe-res/");
                UUID uuid = UUID.fromString(uuidString);
                IFrameResourceMap map = VaadinSession.getCurrent().getAttribute(IFrameResourceMap.class);
                if (map == null) {
                    response.setStatus(404);
                } else {
                    IFrameResource res = map.get(uuid);
                    if (res != null) {
                        response.setStatus(200);
                        response.setContentType(res.getMimeType());
                        response.getOutputStream().write(res.getData());
                    }
                }
                return true;
            }

            return false;
        }
    });

    getSession().setAttribute(MediaController.class, new MediaControllerImpl());

    getSession().setAttribute(PDFController.class, new PDFControllerImpl());

    loadInstanceFonts();

    checkCitation(request);
    lastQueriedFragment = "";
    evaluateFragment(getPage().getUriFragment());

    updateUserInformation();
}

From source file:com.ejt.vaadin.loginform.LoginForm.java

License:Apache License

private void init() {
    if (initialized) {
        return;//from  www .j  a v a  2  s. co  m
    }

    LoginFormState state = getState();
    state.userNameFieldConnector = createUserNameField();
    state.passwordFieldConnector = createPasswordField();
    state.loginButtonConnector = createLoginButton();

    String contextPath = VaadinService.getCurrentRequest().getContextPath();
    if (contextPath.endsWith("/")) {
        contextPath = contextPath.substring(0, contextPath.length() - 1);
    }
    state.contextPath = contextPath;

    VaadinSession.getCurrent().addRequestHandler(new RequestHandler() {
        @Override
        public boolean handleRequest(VaadinSession session, VaadinRequest request, VaadinResponse response)
                throws IOException {
            if (LoginFormConnector.LOGIN_URL.equals(request.getPathInfo())) {
                response.setContentType("text/html; charset=utf-8");
                response.setCacheTime(-1);
                PrintWriter writer = response.getWriter();
                writer.append("<html>Success</html>");
                return true;
            } else {
                return false;
            }
        }
    });

    registerRpc(new LoginFormRpc() {
        @Override
        public void submitCompleted() {
            login();
        }
    });

    initialized = true;

    setContent(createContent(getUserNameField(), getPasswordField(), getLoginButton()));
}

From source file:com.foc.vaadin.FocWebApplication.java

License:Apache License

public void initialize(VaadinRequest vaadinRequest, ServletContext servletContext, HttpSession httpSession,
        boolean webServicesOnly) {
    //      setTheme(FocVaadinTheme.THEME_NAME);
    //      Page.getCurrent().setUriFragment("01barmaja");
    Globals.logString("FocWebApplication.init 111");
    setErrorHandler(new DefaultErrorHandler() {
        @Override/*  w w  w  .jav  a2 s .  c o m*/
        public void error(com.vaadin.server.ErrorEvent event) {
            Globals.logString("Error - 1");
            Throwable throwable = event != null ? event.getThrowable() : null;
            Globals.logString("Error - 2");
            if (throwable != null && throwable instanceof Exception) {
                Globals.logString("Error - 3");
                Globals.logException((Exception) throwable);
                Globals.logString("Error - 4");
            }

            // Do the default error handling (optional)
            doDefault(event);
        }
    });

    String userAgent = vaadinRequest != null ? vaadinRequest.getHeader("User-Agent") : null;
    isMobile = Utils.isMobile(userAgent);
    Globals.logString("FocWebApplication.init 2");
    //      isMobile = Globals.isTouchDevice();

    String path = vaadinRequest != null ? vaadinRequest.getPathInfo() : null;
    Globals.logString("FocWebApplication.init 3");
    if (path != null && !path.isEmpty() && path.length() > 1) {
        path = path.substring(1);
        isMobile = path.toLowerCase().trim().equals("m");
    }
    Globals.logString("FocWebApplication.init 4");

    addStyleName("focMainWindow");

    Globals.logString("FocWebApplication.init 5");

    //      FocWebApplication.setInstanceForThread(this);
    setSessionIfEmpty(httpSession);
    Globals.logString("FocWebApplication.init 6");
    startApplicationServer(servletContext, webServicesOnly);
    Globals.logString("FocWebApplication.init 7");
    FocWebServer focWebServer = FocWebServer.getInstance();
    if (focWebServer == null) {
        Globals.logString("FocWebApplication.init 8 - SERVER IS NULL");
    } else {
        Globals.logString("FocWebApplication.init 8 - SERVER OK");
    }
    focWebServer.addApplication(this);
    Globals.logString("FocWebApplication.init 9");
}

From source file:com.foc.vaadin.FocWebApplication.java

License:Apache License

public void initializeGUI(VaadinRequest vaadinRequest, ServletContext servletContext, HttpSession httpSession) {
    String path = vaadinRequest != null ? vaadinRequest.getPathInfo() : null;
    navigationWindow = newWindow();//from ww  w  . j  a v  a  2  s  .  c om

    if (Utils.isStringEmpty(Globals.getApp().getURL())) {
        if (Page.getCurrent() != null) {
            URI url = Page.getCurrent().getLocation();
            Globals.getApp().setURL(url.toString());
        }
    }

    applyUserThemeSelection();
    if (Globals.isValo() && !isPrintUI()) {

        navigationWindow.setHeightUndefined();
        navigationWindow.setHeight("100%");
        FocXMLGuiComponentStatic.setCaptionMargin_Zero(navigationWindow);

        //PANEL
        //         Panel bodyPanel = new Panel();
        //         bodyPanel.setSizeFull();
        //         bodyPanel.setContent(navigationWindow);
        //-----

        footerLayout = new VerticalLayout();
        footerLayout.setHeight("-1px");
        //footerLayout.addComponent(new Label(""));

        VerticalLayout mainVerticalLayout = new VerticalLayout();
        mainVerticalLayout.setSizeFull();// Main Layout is set to size Full so that it fills all the height

        //PANEL
        //         mainVerticalLayout.addComponent(bodyPanel);
        //         mainVerticalLayout.setExpandRatio(bodyPanel, 1);
        //-----

        mainVerticalLayout.addComponent(navigationWindow);
        mainVerticalLayout.setExpandRatio(navigationWindow, 1);
        mainVerticalLayout.addComponent(footerLayout);
        setContent(mainVerticalLayout);
    } else {
        setContent(navigationWindow);
        footerLayout = null;
    }

    initAccountFromDataBase();

    if (getNavigationWindow() != null) {
        INavigationWindow window = getNavigationWindow();

        URI uri = Page.getCurrent().getLocation();

        //Make sure the environment allows unit testing         
        if (ConfigInfo.isUnitAllowed() && uri.getHost().equals("localhost")) {
            //If there are no test indexes already then we need to check the URL for test request
            if (!FocUnitDictionary.getInstance().hasNextTest()) {
                String suiteName = null;
                String testName = null;

                if (path != null && path.toLowerCase().startsWith(URL_PARAMETER_KEY_UNIT_SUITE + ":")) {
                    suiteName = path.substring((URL_PARAMETER_KEY_UNIT_SUITE + ":").length());

                    if (!Utils.isStringEmpty(suiteName)) {
                        int indexOfSuperior = suiteName.indexOf(".");
                        if (indexOfSuperior > 0) {
                            testName = suiteName.substring(indexOfSuperior + 1, suiteName.length());
                            suiteName = suiteName.substring(0, indexOfSuperior);
                        }

                        FocUnitDictionary.getInstance().initializeCurrentSuiteAndTest(suiteName, testName);
                    }
                }
            }

            if (FocUnitDictionary.getInstance().hasNextTest()) {
                try {
                    Globals.getApp().setIsUnitTest(true);
                    FocUnitDictionary.getInstance().runSequence();
                } catch (Exception e) {
                    Globals.logException(e);
                } finally {
                    //                 if(       !FocUnitDictionary.getInstance().isPause()
                    //                       && !FocUnitDictionary.getInstance().isNextTestExist()
                    //                       ){
                    //                    FocUnitDictionary.getInstance().popupLogger(window);
                    //                 }
                    Globals.getApp().setIsUnitTest(false);
                }
            }
        }
    }
    //--------------------------------------------
}

From source file:com.foc.vaadin.FocWebVaadinWindow.java

License:Apache License

public String getPathInfo() {
    VaadinRequest vaadinRequest = VaadinService.getCurrent().getCurrentRequest();
    String path = vaadinRequest != null ? vaadinRequest.getPathInfo() : null;
    return path;/*from   www . j a va2  s .co  m*/
}