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

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

Introduction

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

Prototype

char EXTENSION_SEPARATOR

To view the source code for org.apache.commons.io FilenameUtils EXTENSION_SEPARATOR.

Click Source Link

Document

The extension separator character.

Usage

From source file:org.dbgl.util.FileUtils.java

public static File[] findFileSequence(File f) {
    List<File> result = new ArrayList<File>();
    result.add(f);/*from   w w  w.ja  va 2 s .  com*/

    int i = 1;
    String name = FilenameUtils.removeExtension(f.getName());
    String ext = FilenameUtils.getExtension(f.getName());

    if (name.endsWith(String.valueOf(i))) {
        File dir = f.getParentFile();
        if (dir != null) {
            File[] files = dir.listFiles(new FileFilter() {
                public boolean accept(File f) {
                    return f.isFile();
                }
            });
            String[] fileNames = getNames(files);
            if (files != null) {
                int index;
                do {
                    i++;
                    String nextFileName = StringUtils.chop(name) + String.valueOf(i)
                            + FilenameUtils.EXTENSION_SEPARATOR + ext;
                    index = ArrayUtils.indexOf(fileNames, nextFileName);
                    if (index >= 0) {
                        result.add(files[index]);
                    }
                } while (index >= 0);
            }
        }
    }

    return result.toArray(new File[0]);
}

From source file:org.eclipse.dirigible.ide.template.ui.common.TemplateGenerator.java

public void generate(HttpServletRequest request) throws Exception {
    TemplateSourceMetadata[] sources = getModel().getTemplate().getTemplateMetadata().getSources();
    for (int i = 0; i < sources.length; i++) {
        String targetLocation = getModel().getTargetLocation();
        String name = sources[i].getName();
        // alternative location check for surrounding template target
        targetLocation = calcTargetLocation(targetLocation, name);
        if ((name != null) && (name.indexOf(IRepository.SEPARATOR) > 1)) {
            name = name.substring(name.indexOf(IRepository.SEPARATOR));
        }//from   w w  w  .java 2 s  .c om
        String renaming = sources[i].getRename();
        if ((renaming != null) && !"".equals(renaming)) {
            // rename the surrounding template target
            String baseFilename = FilenameUtils.getBaseName(getModel().getFileName());
            String originalExtension = FilenameUtils.getExtension(name);
            name = String.format(renaming, baseFilename) + FilenameUtils.EXTENSION_SEPARATOR
                    + originalExtension;
        }

        if (sources[i].isGenerate()) {
            if (i == 0) {
                // leading template
                generateFile(sources[i].getLocation(), targetLocation, getModel().getFileName(), request);
            } else {
                // surrounding templates
                generateFile(sources[i].getLocation(), targetLocation, name, request);
            }
        } else {
            copyFile(name, targetLocation, sources[i].getLocation(), request);
        }
    }

}