Search in sources :

Example 1 with BootstrapPageResponse

use of com.vaadin.server.BootstrapPageResponse in project opennms by OpenNMS.

the class VaadinOSGiServlet method createServletService.

@Override
protected VaadinServletService createServletService(DeploymentConfiguration deploymentConfiguration) throws ServiceException {
    final VaadinServletService service = super.createServletService(deploymentConfiguration);
    service.addSessionInitListener(new SessionInitListener() {

        @Override
        public void sessionInit(SessionInitEvent event) throws ServiceException {
            final VaadinSession session = event.getSession();
            m_sessions.add(session);
            if (session.getUIProviders().isEmpty() || !session.getUIProviders().contains(m_provider)) {
                session.addUIProvider(m_provider);
            }
        }
    });
    service.addSessionDestroyListener(new SessionDestroyListener() {

        @Override
        public void sessionDestroy(SessionDestroyEvent event) {
            final VaadinSession session = event.getSession();
            m_sessions.remove(session);
            if (session.getUIProviders().contains(m_provider)) {
                session.removeUIProvider(m_provider);
            }
        }
    });
    // Additional listeners
    SessionListenerRepository sessionListenerRepository = SessionListenerRepository.getRepository(m_context);
    if (sessionListenerRepository != null) {
        service.addSessionInitListener(sessionListenerRepository);
        service.addSessionDestroyListener(sessionListenerRepository);
    }
    // The Default location of the favicon is "theme://favicon.ico".
    // However the theme may not provide a favicon. To avoid each theme to host the favicon.ico file, we just use
    // the one defined in /opennms
    service.addSessionInitListener(new SessionInitListener() {

        @Override
        public void sessionInit(SessionInitEvent event) throws ServiceException {
            event.getSession().addBootstrapListener(new BootstrapListener() {

                @Override
                public void modifyBootstrapPage(BootstrapPageResponse response) {
                    response.getDocument().head().getElementsByAttributeValue("rel", "shortcut icon").attr("href", "/opennms/favicon.ico");
                    response.getDocument().head().getElementsByAttributeValue("rel", "icon").attr("href", "/opennms/favicon.ico");
                }

                @Override
                public void modifyBootstrapFragment(BootstrapFragmentResponse response) {
                }
            });
        }
    });
    return service;
}
Also used : SessionInitEvent(com.vaadin.server.SessionInitEvent) ServiceException(com.vaadin.server.ServiceException) VaadinSession(com.vaadin.server.VaadinSession) SessionListenerRepository(org.opennms.vaadin.extender.SessionListenerRepository) SessionInitListener(com.vaadin.server.SessionInitListener) SessionDestroyListener(com.vaadin.server.SessionDestroyListener) BootstrapPageResponse(com.vaadin.server.BootstrapPageResponse) BootstrapListener(com.vaadin.server.BootstrapListener) VaadinServletService(com.vaadin.server.VaadinServletService) BootstrapFragmentResponse(com.vaadin.server.BootstrapFragmentResponse) SessionDestroyEvent(com.vaadin.server.SessionDestroyEvent)

Aggregations

BootstrapFragmentResponse (com.vaadin.server.BootstrapFragmentResponse)1 BootstrapListener (com.vaadin.server.BootstrapListener)1 BootstrapPageResponse (com.vaadin.server.BootstrapPageResponse)1 ServiceException (com.vaadin.server.ServiceException)1 SessionDestroyEvent (com.vaadin.server.SessionDestroyEvent)1 SessionDestroyListener (com.vaadin.server.SessionDestroyListener)1 SessionInitEvent (com.vaadin.server.SessionInitEvent)1 SessionInitListener (com.vaadin.server.SessionInitListener)1 VaadinServletService (com.vaadin.server.VaadinServletService)1 VaadinSession (com.vaadin.server.VaadinSession)1 SessionListenerRepository (org.opennms.vaadin.extender.SessionListenerRepository)1