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:fr.amapj.view.engine.ui.AmapUI.java

License:Open Source License

/**
 * Calcul du nom de la base de donnes  partir de l'url saisie
 * @param request//  www. jav  a2s .c  o  m
 * @return
 */
public String getDbName(VaadinRequest request) {
    String dbName = request.getPathInfo();
    if ((dbName == null) || (dbName.length() <= 1)) {
        dbName = "amap1";
    } else {
        dbName = dbName.substring(1);
        // On supprime les eventuels complements dans l'url
        if (dbName.indexOf('/') > 0) {
            dbName = dbName.substring(0, dbName.indexOf('/'));
        }
    }
    return dbName;
}

From source file:org.adho.dhconvalidator.ui.ExternalResourceRequestHandler.java

@Override
public boolean handleRequest(VaadinSession session, VaadinRequest request, VaadinResponse response)
        throws IOException {

    // does the request concern us?
    if (request.getPathInfo().startsWith("/popup" + imagePath)) {
        ZipResult zipResult = (ZipResult) VaadinSession.getCurrent()
                .getAttribute(SessionStorageKey.ZIPRESULT.name());
        // if this is about the example picture we use the example ZipResult
        if (request.getPathInfo().endsWith(examplePictureName)) {
            zipResult = exampleZipResult;
        }//from   w w  w.  j  a  v  a 2 s .  c  om

        if (zipResult != null) {
            byte[] resource = zipResult
                    .getExternalResource(request.getPathInfo().substring(PATH_PREFIX_LENGTH));
            if (resource != null) {
                response.getOutputStream().write(resource);
                return true;
            } else {
                throw new IOException(Messages.getString("ExternalResourceRequestHandler.resourceNotFound",
                        request.getPathInfo().substring(PATH_PREFIX_LENGTH)));
            }
        }
    }
    return false;
}

From source file:org.lucidj.vaadinui.GlobalResourceHandlerEx.java

License:Apache License

@Override
public boolean handleRequest(VaadinSession session, VaadinRequest request, VaadinResponse response)
        throws IOException {
    // We simply filter the resources we want to serve directly
    if (path_to_resource.containsKey(request.getPathInfo())) {
        DownloadStream stream = path_to_resource.get(request.getPathInfo()).getStream();

        if (stream != null) {
            stream.writeResponse(request, response);
            return (true);
        }//from  w ww. j a v a 2 s.  co m
        // Fall back if not found here
    }
    return (super.handleRequest(session, request, response));
}

From source file:org.opencms.ui.dialogs.CmsEmbeddedDialogsUI.java

License:Open Source License

/**
 * @see org.opencms.ui.A_CmsUI#init(com.vaadin.server.VaadinRequest)
 */// ww w  . ja  v  a  2 s. c o m
@Override
protected void init(VaadinRequest request) {

    super.init(request);
    Throwable t = null;
    String errorMessage = null;
    try {
        OpenCms.getRoleManager().checkRole(getCmsObject(), CmsRole.ELEMENT_AUTHOR);
        try {
            String resources = request.getParameter("resources");
            List<CmsResource> resourceList;
            if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(resources)) {
                resourceList = new ArrayList<CmsResource>();
                String[] resIds = resources.split(";");
                for (int i = 0; i < resIds.length; i++) {
                    if (CmsUUID.isValidUUID(resIds[i])) {
                        resourceList.add(getCmsObject().readResource(new CmsUUID(resIds[i]),
                                CmsResourceFilter.IGNORE_EXPIRATION));
                    }

                }
            } else {
                resourceList = Collections.<CmsResource>emptyList();
            }
            String typeParam = request.getParameter("contextType");

            ContextType type;
            String appId = "";
            try {
                type = ContextType.valueOf(typeParam);
                if (ContextType.containerpageToolbar.equals(type)) {
                    appId = CmsPageEditorConfiguration.APP_ID;
                } else if (ContextType.sitemapToolbar.equals(type)) {
                    appId = CmsSitemapEditorConfiguration.APP_ID;
                }
            } catch (Exception e) {
                type = ContextType.appToolbar;
                LOG.error("Could not parse context type parameter " + typeParam);
            }

            m_currentContext = new CmsEmbeddedDialogContext(appId, type, resourceList);
            I_CmsWorkplaceAction action = getAction(request);
            if (action.isActive(m_currentContext)) {
                action.executeAction(m_currentContext);
            } else {
                errorMessage = CmsVaadinUtils.getMessageText(Messages.GUI_WORKPLACE_ACCESS_DENIED_TITLE_0);
            }
        } catch (Throwable e) {
            t = e;
            errorMessage = CmsVaadinUtils.getMessageText(
                    org.opencms.ui.dialogs.Messages.ERR_DAILOG_INSTANTIATION_FAILED_1, request.getPathInfo());
        }
    } catch (CmsRoleViolationException ex) {
        t = ex;
        errorMessage = CmsVaadinUtils.getMessageText(Messages.GUI_WORKPLACE_ACCESS_DENIED_TITLE_0);
    }
    if (errorMessage != null) {
        CmsErrorDialog.showErrorDialog(errorMessage, t, new Runnable() {

            public void run() {

                m_currentContext = new CmsEmbeddedDialogContext("", null, Collections.<CmsResource>emptyList());
                m_currentContext.finish(null);
            }
        });
    }
}

From source file:org.opencms.ui.dialogs.CmsEmbeddedDialogsUI.java

License:Open Source License

/**
 * Returns the dialog id extracted from the requested path.<p>
 *
 * @param request the request/*www.jav  a  2s.  c  om*/
 *
 * @return the id
 */
private String getDialogId(VaadinRequest request) {

    String path = request.getPathInfo();
    // remove the leading slash
    return path != null ? path.substring(1) : null;
}

From source file:org.opennms.features.pluginmgr.vaadin.config.opennms.PluginManagerAdminApplication.java

License:Open Source License

private void addHeader(VaadinRequest request) {
    if (m_headerProvider != null) {
        try {/*from   w  w w. jav  a 2s  .c om*/
            setHeaderHtml(
                    m_headerProvider.getHeaderHtml(((VaadinServletRequest) request).getHttpServletRequest()));
        } catch (final Exception e) {
            LOG.error("failed to get header HTML for request " + request.getPathInfo(), e.getCause());
        }
    }
    if (m_headerHtml != null) {
        InputStream is = null;
        try {
            is = new ByteArrayInputStream(m_headerHtml.getBytes());
            final CustomLayout headerLayout = new CustomLayout(is);
            headerLayout.setWidth("100%");
            headerLayout.addStyleName("onmsheader");
            m_rootLayout.addComponent(headerLayout);
        } catch (final IOException e) {
            closeQuietly(is);
            LOG.debug("failed to get header layout data", e);
        }
    }
}

From source file:org.opennms.features.topology.app.internal.TopologyUI.java

License:Open Source License

@Override
protected void init(final VaadinRequest request) {
    // Register a cleanup
    request.getService().addSessionDestroyListener(
            (SessionDestroyListener) event -> m_widgetManager.removeUpdateListener(TopologyUI.this));

    try {//from   w ww  . ja v  a  2s  .c o  m
        m_headerHtml = getHeader(((VaadinServletRequest) request).getHttpServletRequest());
    } catch (final Exception e) {
        LOG.error("failed to get header HTML for request " + request.getPathInfo(), e.getCause());
    }

    //create VaadinApplicationContext
    m_applicationContext = m_serviceManager.createApplicationContext(new VaadinApplicationContextCreator() {
        @Override
        public VaadinApplicationContext create(OnmsServiceManager manager) {
            VaadinApplicationContextImpl context = new VaadinApplicationContextImpl();
            context.setSessionId(request.getWrappedSession().getId());
            context.setUiId(getUIId());
            context.setUsername(request.getRemoteUser());
            return context;
        }
    });
    m_verticesUpdateManager = new OsgiVerticesUpdateManager(m_serviceManager, m_applicationContext);
    m_serviceManager.getEventRegistry().addPossibleEventConsumer(this, m_applicationContext);

    // Set the algorithm last so that the criteria and SZLs are
    // in place before we run the layout algorithm.
    m_graphContainer.setSessionId(m_applicationContext.getSessionId());
    m_graphContainer.setLayoutAlgorithm(new TopoFRLayoutAlgorithm());

    createLayouts();
    setupErrorHandler(); // Set up an error handler for UI-level exceptions
    setupAutoRefresher(); // Add an auto refresh handler to the GraphContainer

    loadUserSettings();
    // the layout must be created BEFORE loading the hop criteria and the semantic zoom level
    TopologyUIRequestHandler handler = new TopologyUIRequestHandler();
    getSession().addRequestHandler(handler); // Add a request handler that parses incoming focusNode and szl query parameters
    handler.handleRequestParameter(request); // deal with those in init case

    // Add the default criteria if we do not have already a criteria set
    if (getWrappedVertexHopCriteria(m_graphContainer).isEmpty() && noAdditionalFocusCriteria()) {
        m_graphContainer.addCriteria(m_graphContainer.getBaseTopology().getDefaultCriteria()); // set default
    }

    // If no Topology Provider was selected (due to loadUserSettings(), fallback to default
    if (m_graphContainer.getBaseTopology() == null
            || m_graphContainer.getBaseTopology() == MergingGraphProvider.NULL_PROVIDER) {
        TopologySelectorOperation defaultTopologySelectorOperation = createOperationForDefaultGraphProvider(
                m_bundlecontext, "(|(label=Enhanced Linkd)(label=Linkd))");
        Objects.requireNonNull(defaultTopologySelectorOperation, "No default GraphProvider found."); // no default found, abort
        defaultTopologySelectorOperation.execute(m_graphContainer);
    }

    // We set the listeners at the end, to not fire them all the time when initializing the UI
    setupListeners();

    // We force a reload of the topology provider as it may not have been initialized
    m_graphContainer.getBaseTopology().refresh();

    // We force a reload to trigger a fireGraphChanged()
    m_graphContainer.setDirty(true);
    m_graphContainer.redoLayout();

    // Trigger a selectionChanged
    m_selectionManager.selectionChanged(m_selectionManager);
}

From source file:org.panifex.web.vaadin.runtime.PageletAwareUI.java

License:Open Source License

@Override
protected void init(VaadinRequest request) {
    VaadinPagelet pagelet = pageletTracker.matchPathToPagelet(request.getPathInfo());
    if (pagelet != null) {
        try {/* w  w  w.j a  v a 2  s .co m*/
            pagelet.service(request);
        } catch (Exception e) {
            log.error("Unable to service request", e);
            throw new RuntimeException(e);
        }
    } else {
        // pagelet not found - return HTTP 404 - Not found
        VaadinResponse response = CurrentInstance.get(VaadinResponse.class);
        try {
            response.sendError(HttpServletResponse.SC_NOT_FOUND, "Not found");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

From source file:pl.exsio.plupload.PluploadReceiver.java

License:Open Source License

@Override
public boolean handleRequest(VaadinSession session, VaadinRequest request, VaadinResponse response)
        throws IOException {
    if (request.getPathInfo() != null && request.getPathInfo().endsWith(UPLOAD_ACTION_PATH)) {
        if (request instanceof VaadinServletRequest) {
            VaadinServletRequest vsr = (VaadinServletRequest) request;
            HttpServletRequest req = vsr.getHttpServletRequest();
            if (ServletFileUpload.isMultipartContent(req)) {
                try {
                    synchronized (this) {
                        ServletFileUpload upload = new ServletFileUpload();
                        FileItemIterator items = upload.getItemIterator(req);
                        PluploadChunk chunk = PluploadChunkFactory.create(items);
                        PluploadChunkHandler fileHandler = this.getExpectedFileHandler(chunk.getFileId());
                        fileHandler.handleUploadedChunk(chunk);
                        this.writeResponse(chunk, response);
                    }// w ww  . j  a va2 s .c o  m
                } catch (Exception ex) {
                    response.getWriter().append("file upload unsuccessful, because of "
                            + ex.getClass().getName() + ":" + ex.getMessage());
                    throw new IOException(
                            "There was a problem during processing of uploaded chunk. Nested exceptions may have more info.",
                            ex);
                }
                return true;
            }
        }
    }
    return false;

}