Example usage for org.apache.commons.io FilenameUtils removeExtension

List of usage examples for org.apache.commons.io FilenameUtils removeExtension

Introduction

In this page you can find the example usage for org.apache.commons.io FilenameUtils removeExtension.

Prototype

public static String removeExtension(String filename) 

Source Link

Document

Removes the extension from a filename.

Usage

From source file:org.apache.jena.atlas.io.IO.java

/** The filename without any compression extension, or the original filename.
 *  It tests for compression types handled by {@link #openFileEx}.
 *//*from ww  w  . j av  a2s.c om*/
static public String filenameNoCompression(String filename) {
    if (FilenameUtils.isExtension(filename, extensions)) {
        return FilenameUtils.removeExtension(filename);
    }
    return filename;
}

From source file:org.apache.jmeter.report.dashboard.TemplateVisitor.java

@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {

    // Depending on file extension, copy or process file
    String extension = FilenameUtils.getExtension(file.toString());
    if (TEMPLATED_FILE_EXT.equalsIgnoreCase(extension)) {
        // Process template file
        String templatePath = source.relativize(file).toString();
        Template template = configuration.getTemplate(templatePath);
        Path newPath = target.resolve(FilenameUtils.removeExtension(templatePath));
        try (FileOutputStream stream = new FileOutputStream(newPath.toString());
                Writer writer = new OutputStreamWriter(stream, StandardCharsets.UTF_8);
                BufferedWriter bufferedWriter = new BufferedWriter(writer)) {
            template.process(data, bufferedWriter);
        } catch (TemplateException ex) {
            throw new IOException(ex);
        }// w  w  w. j a v  a  2 s.  co  m

    } else {
        // Copy regular file
        Path newFile = target.resolve(source.relativize(file));
        Files.copy(file, newFile, StandardCopyOption.REPLACE_EXISTING);
    }
    return FileVisitResult.CONTINUE;
}

From source file:org.apache.maven.plugin.cxx.CMakeMojo.java

protected String baseNameAsStaticLibrary(String sName, boolean bMavenDependency) {
    if (FilenameUtils.isExtension(sName, FilenameUtils.getExtension(staticLibrarySuffix))) {
        sName = FilenameUtils.removeExtension(sName) + (bMavenDependency ? "${STATIC_LIBRARY_SUFFIX}" : "");
        if (!StringUtils.isEmpty(staticLibraryPrefix)) {
            if (0 == sName.indexOf(staticLibraryPrefix)) {
                sName = sName.replaceFirst(Pattern.quote(staticLibraryPrefix), "");
                sName = (bMavenDependency ? "${STATIC_LIBRARY_PREFIX}" : "") + sName;
            } else {
                sName = "";
            }/*from  www  .j  a  v  a 2 s.c o m*/
        } else {
            sName = (bMavenDependency ? "${STATIC_LIBRARY_PREFIX}" : "") + sName;
        }
    }
    return sName;
}

From source file:org.apache.maven.plugin.cxx.CMakeMojo.java

protected String baseNameAsSharedModule(String sName, boolean bMavenDependency) {
    if (FilenameUtils.isExtension(sName, FilenameUtils.getExtension(sharedModuleSuffix))) {
        sName = FilenameUtils.removeExtension(sName) + (bMavenDependency ? "${SHARED_MODULE_SUFFIX}" : "");
        if (!StringUtils.isEmpty(sharedModulePrefix)) {
            if (0 == sName.indexOf(sharedModulePrefix)) {
                sName = sName.replaceFirst(Pattern.quote(sharedModulePrefix), "");
                sName = (bMavenDependency ? "${SHARED_MODULE_PREFIX}" : "") + sName;
            } else {
                sName = "";
            }/*from   ww w.j  av  a2  s. c o  m*/
        } else {
            sName = (bMavenDependency ? "${SHARED_MODULE_PREFIX}" : "") + sName;
        }
    }
    return sName;
}

From source file:org.apache.maven.plugin.cxx.CMakeMojo.java

protected String baseNameAsSharedLibrary(String sName, boolean bMavenDependency) {
    if (FilenameUtils.isExtension(sName, FilenameUtils.getExtension(sharedLibrarySuffix))) {
        sName = FilenameUtils.removeExtension(sName) + (bMavenDependency ? "${SHARED_LIBRARY_SUFFIX}" : "");
        if (!StringUtils.isEmpty(sharedLibraryPrefix)) {
            if (0 == sName.indexOf(sharedLibraryPrefix)) {
                sName = sName.replaceFirst(Pattern.quote(sharedLibraryPrefix), "");
                sName = (bMavenDependency ? "${SHARED_LIBRARY_PREFIX}" : "") + sName;
            } else {
                sName = "";
            }/*w  w w .ja v  a2s  .c o m*/
        } else {
            sName = (bMavenDependency ? "${SHARED_LIBRARY_PREFIX}" : "") + sName;
        }
    }
    return sName;
}

From source file:org.apache.metron.common.configuration.ConfigurationsUtils.java

public static Map<String, byte[]> readSensorConfigsFromFile(String rootPath, ConfigurationType configType)
        throws IOException {
    Map<String, byte[]> sensorConfigs = new HashMap<>();
    File configPath = new File(rootPath, configType.getDirectory());
    if (configPath.exists()) {
        File[] children = configPath.listFiles();
        if (children != null) {
            for (File file : children) {
                sensorConfigs.put(FilenameUtils.removeExtension(file.getName()),
                        Files.readAllBytes(file.toPath()));
            }//  ww  w . j  a  v a 2s .  co  m
        }
    }
    return sensorConfigs;
}

From source file:org.apache.nutch.protocol.interactiveselenium.BangGoodHandler.java

@Override
public String processDriver(WebDriver driver) {
    StringBuffer buffer = new StringBuffer();

    // Extract content 
    String content = driver.findElement(By.tagName("body")).getText();
    buffer.append(content).append("\n");

    WebElement pages = driver.findElement(By.xpath("//div[@class='page_num']"));
    if (pages == null) {
        return buffer.toString();
    }/* ww w  . j  a  v  a  2s . com*/

    int lastPageNum = 1;
    try {
        lastPageNum = Integer
                .parseInt(pages.findElement(By.xpath("./b[text()='...']/following-sibing::a")).getText());
    } catch (NumberFormatException e) {
        // do nothing
    }

    String baseUrl = FilenameUtils.removeExtension(driver.getCurrentUrl());
    for (int i = 2; i <= lastPageNum; i++) {
        buffer.append("<a href=\"").append(baseUrl).append("-0-1-1-45-0_page").append(i).append(".html\" />\n");
    }

    return buffer.toString();
}

From source file:org.apache.openaz.xacml.admin.components.PolicyWorkspace.java

protected Path getNextFilename(Path parent, String filename) {
    filename = FilenameUtils.removeExtension(filename);
    Path newFile = null;/*w  w w .j  a  v  a  2s. c o  m*/
    int i = 0;
    while (true) {
        newFile = Paths.get(parent.toString(), String.format("%s(%02d)", filename, i++) + ".xml");
        if (Files.notExists(newFile)) {
            return newFile;
        }
        if (i == 100) {
            logger.error("Could not construct a new name for cloned policy.");
            return null;
        }
    }

}

From source file:org.apereo.cas.console.groovy.GroovyShellService.java

private void loadCustomGroovyScriptsIntoClasspath(final Binding binding) {
    final FilenameFilter filter = (dir, name) -> name.endsWith(FILE_EXTENSION);

    final ClassLoader thisClassLoader = this.getClass().getClassLoader();
    try (final GroovyClassLoader loader = new GroovyClassLoader(thisClassLoader)) {
        final File[] files = this.scriptsLocationResource.getFile().listFiles(filter);

        for (final File file : files) {
            try {
                final Class c = loader.parseClass(file);
                final String fileNameWithOutExt = FilenameUtils.removeExtension(file.getName());
                binding.setVariable(fileNameWithOutExt, c.newInstance());
                logger.debug("Add custom groovy script [{}] to the binding", fileNameWithOutExt);
            } catch (final Exception e) {
                logger.error(e.getMessage(), e);
            }/*  w w w. j  ava 2  s.com*/
        }
    } catch (final Exception e) {
        logger.error(e.getMessage(), e);
    }
}

From source file:org.artifactory.repo.RepoBase.java

public boolean accepts(RepoPath repoPath) {
    if (repoPath.isRoot()) {
        return true; // always accepts the root path
    }/*from w  ww .j a  va2s.co  m*/
    String path = repoPath.getPath();
    if (NamingUtils.isSystem(path)) {
        // includes/excludes should not affect system paths
        return true;
    }

    String toCheck = path;
    //For artifactory metadata the pattern apply to the object it represents
    if (NamingUtils.isProperties(path)) {
        toCheck = NamingUtils.getMetadataParentPath(path);
    } else if (NamingUtils.isChecksum(path)) {
        toCheck = FilenameUtils.removeExtension(path);
    }
    return isPathPatternValid(repoPath, toCheck);
}