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

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

Introduction

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

Prototype

public static boolean isExtension(String filename, Collection<String> extensions) 

Source Link

Document

Checks whether the extension of the filename is one of those specified.

Usage

From source file:ch.ifocusit.livingdoc.plugin.utils.AsciidocUtil.java

public static boolean isAdoc(String filename) {
    return FilenameUtils.isExtension(filename, new String[] { Format.adoc.name(), Format.asciidoc.name() });
}

From source file:com.jaxio.celerio.output.OutputResultFactory.java

public OutputResult getOutputResult(String userBaseDirectory, String outputDirectory) {
    if (FilenameUtils.isExtension(outputDirectory, new String[] { "zip", "jar" })) {
        return new ZipOutputResult(outputDirectory);
    } else {/*from  w  w w.j av  a  2 s .co m*/
        return new FolderOutputResult(newUserSource(userBaseDirectory), newGeneratedSource(outputDirectory),
                fileTracker);
    }
}

From source file:neembuu.uploader.zip.generator.utils.NUFileUtils.java

/**
 * Get all the files with the given extension.
 * @param file The directory where there are all the files.
 * @param extension The extension of the files to search for.
 * @return The list of the files./*from w  ww. j  a v  a 2s.  c  o m*/
 */
public static Collection<File> listAllFilesWithExt(File file, final String extension) {
    return FileUtils.listFiles(file, new IOFileFilter() {

        @Override
        public boolean accept(File file) {
            // to prevent old libs compiled by netbeans from getting into.
            // i know since we are using git this should not happen, but when the code
            // was been tweaked for testing, this statement was reqired.
            if (file.getAbsolutePath().replace('/', '\\').contains("\\dist\\"))
                return false;
            return FilenameUtils.isExtension(file.getName(), extension);
        }

        @Override
        public boolean accept(File dir, String name) {
            if (dir.getAbsolutePath().replace('/', '\\').contains("\\dist\\"))
                return false;
            return FilenameUtils.isExtension(name, extension);
        }
    }, TrueFileFilter.INSTANCE);
}

From source file:com.yahoo.rdl.maven.RdlFileFinderImpl.java

@Override
public List<Path> findRdlFiles() throws MojoExecutionException, MojoFailureException {
    List<Path> rdlFiles = new ArrayList<Path>();
    try {/*from  w w w .java 2  s .  com*/
        Files.walkFileTree(rdlDirectory, new SimpleFileVisitor<Path>() {
            @Override
            public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
                if (FilenameUtils.isExtension(file.toString(), "rdl")) {
                    rdlFiles.add(file);
                }
                return super.visitFile(file, attrs);
            }
        });
    } catch (IOException e) {
        throw new MojoExecutionException("Error walking " + rdlDirectory.toAbsolutePath(), e);
    }
    if (rdlFiles.isEmpty()) {
        throw new MojoFailureException("No files ending in .rdl were found in the directory "
                + rdlDirectory.toAbsolutePath()
                + ". Assign <rdlDirectory> in the configuration of rdl-maven-plugin to a folder containing your rdl files.");
    }
    return rdlFiles;
}

From source file:com.viddu.handlebars.HandlebarsFileUtil.java

/**
 * Utility method to load Files in a given directory.
 * /*from   w  ww  .  java 2 s  . c om*/
 * @param outDir
 * @return
 */
public static List<File> loadHandlebarTemplates(File outDir) {
    List<File> fileList = new ArrayList<File>();
    if (outDir.isDirectory()) {
        File[] filesAndDirs = outDir.listFiles();
        for (File file : filesAndDirs) {
            if (file.isDirectory()) {
                fileList.addAll(loadHandlebarTemplates(file));
            } else {
                if (FilenameUtils.isExtension(file.getName(), supportedExt)) {
                    fileList.add(file);
                }
            }
        }
    }
    return fileList;
}

From source file:com.googlecode.bpmn_simulator.gui.dialogs.ModuleFileFilter.java

@Override
public boolean accept(final File file) {
    if (file != null) {
        if (file.isDirectory()) {
            return true;
        }/*from w  ww. j av a  2 s . c o  m*/
        return FilenameUtils.isExtension(file.getName(), module.getFileExtensions());
    }
    return false;
}

From source file:net.shopxx.controller.admin.ThemeController.java

@RequestMapping(value = "/setting", method = RequestMethod.POST)
public String setting(String id, MultipartFile themeFile, RedirectAttributes redirectAttributes) {
    if (themeFile != null && !themeFile.isEmpty()) {
        if (!FilenameUtils.isExtension(themeFile.getOriginalFilename(), "zip")) {
            addFlashMessage(redirectAttributes, Message.error("admin.upload.invalid"));
            return "redirect:setting.jhtml";
        }//from ww  w.  java2 s .c o  m
        if (!themeService.upload(themeFile)) {
            addFlashMessage(redirectAttributes, Message.error("admin.theme.uploadInvalid"));
            return "redirect:setting.jhtml";
        }
    }
    Theme theme = themeService.get(id);
    if (theme == null) {
        return ERROR_VIEW;
    }
    Setting setting = SystemUtils.getSetting();
    setting.setTheme(theme.getId());
    SystemUtils.setSetting(setting);
    cacheService.clear();
    addFlashMessage(redirectAttributes, SUCCESS_MESSAGE);
    return "redirect:setting.jhtml";
}

From source file:com.googlecode.bpmn_simulator.gui.dialogs.ImageExportChooser.java

@Override
public File getSelectedFile() {
    final File file = super.getSelectedFile();
    if (file != null) {
        final String extension = getSelectedImageFormat();
        if (!FilenameUtils.isExtension(file.getName(), extension)) {
            return new File(file.getPath() + FilenameUtils.EXTENSION_SEPARATOR + extension);
        }/*  w w  w.  ja  va2 s  . com*/
    }
    return file;
}

From source file:com.jaeksoft.searchlib.renderer.RendererManager.java

public RendererManager(Config config, File directory) throws SearchLibException, XPathExpressionException,
        ParserConfigurationException, SAXException, IOException {
    array = null;//w w  w .j  av a  2s  .  co  m
    map = new TreeMap<String, Renderer>();
    for (File f : directory.listFiles()) {
        if (f.isFile()) {
            String fname = f.getName();
            if (!FilenameUtils.isExtension(fname, "xml"))
                continue;
            if (fname.endsWith("_old.xml"))
                continue;
            if (fname.endsWith("_tmp.xml"))
                continue;
            if (f.exists())
                add(new Renderer(new XPathParser(f)));
            else
                add(new Renderer());
        }
    }
}

From source file:com.mgmtp.perfload.loadprofiles.ui.util.SwingUtils.java

public static JFileChooser createFileChooser(final File dir, final String description, final String extension) {
    JFileChooser fc = new JFileChooser(dir);
    fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
    fc.setMultiSelectionEnabled(false);/*from www .  ja v  a2s .  c  o m*/
    fc.setAcceptAllFileFilterUsed(false);
    fc.addChoosableFileFilter(new FileFilter() {

        @Override
        public String getDescription() {
            return description;
        }

        @Override
        public boolean accept(final File f) {
            return f.isDirectory() || FilenameUtils.isExtension(f.getName(), extension);
        }
    });
    return fc;
}