Example usage for org.springframework.util StringUtils getFilename

List of usage examples for org.springframework.util StringUtils getFilename

Introduction

In this page you can find the example usage for org.springframework.util StringUtils getFilename.

Prototype

@Nullable
public static String getFilename(@Nullable String path) 

Source Link

Document

Extract the filename from the given Java resource path, e.g.

Usage

From source file:de.codecentric.boot.admin.web.servlet.resource.ConcatenatingResourceResolver.java

@Override
protected Resource resolveResourceInternal(HttpServletRequest request, String requestPath,
        List<? extends Resource> locations, ResourceResolverChain chain) {
    String filename = StringUtils.getFilename(requestPath);
    try {/*from   www . j a  v  a 2 s.c o m*/
        return new InMemoryFileResource(filename, buildDescription(locations), getContent(locations),
                getLastModified(locations));
    } catch (IOException ex) {
        throw new ResourceAccessException("Couldn't concatenate resources [" + locations + "]", ex);
    }
}

From source file:com.griddynamics.banshun.DependencySorter.java

private void showContextGraphStructure(Map<String, Location> locationsMap,
        Map<String, BeanReferenceInfo> exports) {
    if (logGraph.isDebugEnabled()) {
        logGraph.debug("digraph G {");

        for (String locationName : locationsMap.keySet()) {
            Map<String, StringBuilder> exportingLocations = new HashMap<>();

            for (BeanReferenceInfo bean : locationsMap.get(locationName).importBeans) {
                String exportingLocation = exports.get(bean.getServiceName()).getLocation();

                if (!exportingLocations.containsKey(exportingLocation)) {
                    exportingLocations.put(exportingLocation, new StringBuilder());
                }/*from www . ja  v a 2 s.  co  m*/
                exportingLocations.get(exportingLocation).append(bean.getServiceName()).append("\\n");
            }
            for (String exportingLocationName : exportingLocations.keySet()) {
                String beans = exportingLocations.get(exportingLocationName).toString();
                logGraph.debug("\"{}\" -> \"{}\" [label = \"{}\"];",
                        new Object[] { StringUtils.getFilename(locationName),
                                StringUtils.getFilename(exportingLocationName), beans });
            }
        }
        logGraph.debug("}");
    }
}

From source file:fr.mby.saml2.sp.opensaml.query.engine.OpenSaml2QueryProcessorFactory.java

protected SamlBindingEnum extractBindingFromRequest(final HttpServletRequest request)
        throws UnsupportedSamlOperation {
    SamlBindingEnum binding = null;/*from  www.j a  v a 2 s  .co  m*/

    final String endpointUri = request.getRequestURI();
    final String bindingPart = StringUtils.getFilename(endpointUri);

    binding = this.bindingConfiguration.get(bindingPart);

    if (binding == null) {
        final String message = String.format("The endpoint URI [%1$s] with binding part "
                + "[%2$s] is not attached to a supported binding !", endpointUri, bindingPart);
        throw new UnsupportedSamlOperation(message);
    }

    return binding;
}

From source file:spring.osgi.io.OsgiBundleResource.java

/**
 * Returns the filename of this resources. This implementation returns the
 * name of the file that this bundle path resource refers to.
 *
 * @return resource filename/*from   w ww . jav  a  2  s  .c  o m*/
 * @see org.springframework.util.StringUtils#getFilename(String)
 */
public String getFilename() {
    return StringUtils.getFilename(this.path);
}

From source file:com.alibaba.citrus.service.velocity.impl.VelocityConfigurationImpl.java

private String getTemplateNameOfPreloadedResource(Resource resource) {
    URL url;/*w  ww.  j a  v  a  2 s.c  om*/

    try {
        url = resource.getURL();
    } catch (IOException e) {
        url = null;
    }

    String templateNameBase;

    if (url != null) {
        templateNameBase = "globalVMs/" + StringUtils.getFilename(url.getPath());
    } else {
        templateNameBase = "globalVMs/globalVM.vm";
    }

    String templateName = templateNameBase;

    // ??resource
    for (int i = 1; preloadedResources.containsKey(templateName)
            && !resource.equals(preloadedResources.get(templateName)); i++) {
        templateName = templateNameBase + i;
    }

    preloadedResources.put(templateName, resource);

    return templateName;
}

From source file:org.eclipse.gemini.blueprint.test.AbstractOnTheFlyBundleCreatorTests.java

private String[] determineImportsFor(Map entries) {
    // get contained packages to do matching on the test hierarchy
    Collection containedPackages = jarCreator.getContainedPackages();
    Set cumulatedPackages = new LinkedHashSet();

    // make sure the collection package is valid
    boolean validPackageCollection = !containedPackages.isEmpty();

    boolean trace = logger.isTraceEnabled();

    for (Iterator iterator = entries.entrySet().iterator(); iterator.hasNext();) {
        Map.Entry entry = (Map.Entry) iterator.next();
        String resourceName = (String) entry.getKey();

        // filter out the test hierarchy
        if (resourceName.endsWith(ClassUtils.CLASS_FILE_SUFFIX)) {
            if (trace)
                logger.trace("Analyze imports for test bundle resource " + resourceName);
            String classFileName = StringUtils.getFilename(resourceName);
            String className = classFileName.substring(0,
                    classFileName.length() - ClassUtils.CLASS_FILE_SUFFIX.length());
            String classPkg = resourceName.substring(0, resourceName.length() - classFileName.length())
                    .replace('/', '.');

            if (classPkg.startsWith("."))
                classPkg = classPkg.substring(1);

            if (classPkg.endsWith("."))
                classPkg = classPkg.substring(0, classPkg.length() - 1);

            // if we don't have the package, add it
            if (validPackageCollection && StringUtils.hasText(classPkg)
                    && !containedPackages.contains(classPkg)) {
                logger.trace(/* w  w w  .j  a va  2  s  .co m*/
                        "Package [" + classPkg + "] is NOT part of the test archive; adding an import for it");
                cumulatedPackages.add(classPkg);
            }

            // otherwise parse the class byte-code
            else {
                if (trace)
                    logger.trace("Package [" + classPkg + "] is part of the test archive; parsing " + className
                            + " bytecode to determine imports...");
                cumulatedPackages.addAll(determineImportsForClass(className, (Resource) entry.getValue()));
            }
        }
    }

    return (String[]) cumulatedPackages.toArray(new String[cumulatedPackages.size()]);
}

From source file:net.solarnetwork.node.setup.obr.OBRProvisionTask.java

private void downloadPlugins(List<Plugin> plugins) throws InterruptedException {
    assert plugins != null;
    LOG.debug("Starting install of {} plugins", plugins.size());
    if (!directory.exists() && !directory.mkdirs()) {
        throw new RuntimeException("Unable to create plugin directory: " + directory.toString());
    }/*from   ww w.j  av  a2 s . co m*/

    // This method will manually download the bundle for each resolved plugin, 
    // then install it and start it in the running OSGi platform. We don't
    // make use of the OBR RepositoryAdmin to do this because on SolarNode
    // the bundle's runtime area is held only in RAM (not persisted to disk)
    // but we want these downloaded bundles to be persisted to disk. Thus we
    // just do a bit of work here to download and start the bundles ourselves.

    List<Bundle> installedBundles = new ArrayList<Bundle>(plugins.size());

    // iterate backwards, to work our way up through deps to requested plugin
    for (ListIterator<Plugin> itr = plugins.listIterator(plugins.size()); itr.hasPrevious();) {
        Plugin plugin = itr.previous();
        assert plugin instanceof OBRResourcePlugin;
        LOG.debug("Starting install of plugin: {}", plugin.getUID());
        status.setStatusMessage("Starting install of plugin " + plugin.getUID());

        OBRResourcePlugin obrPlugin = (OBRResourcePlugin) plugin;
        Resource resource = obrPlugin.getResource();
        URL resourceURL = resource.getURL();
        String pluginFileName = StringUtils.getFilename(resourceURL.getPath());
        File outputFile = new File(directory, pluginFileName);
        String bundleSymbolicName = resource.getSymbolicName();

        // download to tmp file first, then we'll rename
        File tmpOutputFile = new File(directory, "." + pluginFileName);
        LOG.debug("Downloading plugin {} => {}", resourceURL, tmpOutputFile);
        try {
            FileCopyUtils.copy(resourceURL.openStream(), new FileOutputStream(tmpOutputFile));
        } catch (IOException e) {
            throw new RuntimeException("Unable to download plugin " + bundleSymbolicName, e);
        }

        moveTemporaryDownloadedPluginFile(resource, outputFile, tmpOutputFile);

        installDownloadedPlugin(resource, outputFile, installedBundles);

        LOG.debug("Installed plugin: {}", plugin.getUID());
        status.markPluginInstalled(plugin);
    }
    if (!installedBundles.isEmpty()) {
        Set<Bundle> toRefresh = findFragmentHostsForBundles(installedBundles);
        toRefresh.addAll(installedBundles);
        status.setStatusMessage("Refreshing OSGi framework.");
        FrameworkWiring fw = bundleContext.getBundle(0).adapt(FrameworkWiring.class);
        fw.refreshBundles(toRefresh);

        for (ListIterator<Bundle> itr = installedBundles.listIterator(); itr.hasNext();) {
            Bundle b = itr.next();
            boolean fragment = isFragment(b);
            status.setStatusMessage("Starting plugin: " + b.getSymbolicName());
            try {
                if (!fragment && !(b.getState() == Bundle.ACTIVE || b.getState() == Bundle.STARTING)) {
                    b.start();
                }
                // bundles are in reverse order of plugins
                Plugin p = plugins.get(plugins.size() - itr.nextIndex());
                status.markPluginStarted(p);
            } catch (BundleException e) {
                throw new RuntimeException(
                        "Unable to start plugin " + b.getSymbolicName() + " version " + b.getVersion(), e);
            }
        }
    }
    if (status.isRestartRequired() && systemService == null) {
        LOG.debug("Install of {} plugins complete; manual restart required", plugins.size());
        status.setStatusMessage("Install of " + plugins.size() + " plugins complete; manual restart required");
    } else if (status.isRestartRequired()) {
        LOG.debug("Install of {} plugins complete; restarting now", plugins.size());
        status.setStatusMessage("Install of " + plugins.size() + " plugins complete; restarting now");
        performRestart();
    } else {
        LOG.debug("Install of {} plugins complete", plugins.size());
        status.setStatusMessage("Install of " + plugins.size() + " plugins complete");
    }
}

From source file:org.eclipse.vorto.repository.internal.service.JcrModelRepository.java

private String createUploadHandle(ModelId id, byte[] content, String fileName) {
    try {/*w  w  w . ja  v  a  2s .c  o m*/
        String filePath = fileName.replace("\\", "/");
        File file = File.createTempFile("vorto", StringUtils.getFilename(filePath));
        IOUtils.write(content, new FileOutputStream(file));
        logger.debug("Created temporary file for upload : " + file.getName());
        return file.getName();
    } catch (IOException e) {
        throw new RuntimeException("Could not create temporary file for uploaded model", e);
    }
}

From source file:org.springframework.cloud.config.monitor.PropertyPathEndpoint.java

private Set<String> guessServiceName(String path) {
    Set<String> services = new LinkedHashSet<>();
    if (path != null) {
        String stem = StringUtils.stripFilenameExtension(StringUtils.getFilename(StringUtils.cleanPath(path)));
        // TODO: correlate with service registry
        int index = stem.indexOf("-");
        while (index >= 0) {
            String name = stem.substring(0, index);
            String profile = stem.substring(index + 1);
            if ("application".equals(name)) {
                services.add("*:" + profile);
            } else if (!name.startsWith("application")) {
                services.add(name + ":" + profile);
            }//  w  w w.j  ava 2s .  c om
            index = stem.indexOf("-", index + 1);
        }
        String name = stem;
        if ("application".equals(name)) {
            services.add("*");
        } else if (!name.startsWith("application")) {
            services.add(name);
        }
    }
    return services;
}