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

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

Introduction

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

Prototype

public static String getExtension(String filename) 

Source Link

Document

Gets the extension of a filename.

Usage

From source file:annis.administration.MediaImportHelper.java

public MediaImportHelper(String absolutePath, File dataDir, long corpusRef,
        Map<String, String> mimeTypeMapping) {

    this.fileSource = new File(absolutePath);

    // create a file-name in the form of "filename-UUID.ending", thus we
    // need to split the file name into its components
    String baseName = FilenameUtils.getBaseName(fileSource.getName());
    String extension = FilenameUtils.getExtension(fileSource.getName());
    UUID uuid = UUID.randomUUID();
    fileDestination = new File(dataDir,
            baseName + "_" + uuid.toString() + (extension.isEmpty() ? "" : "." + extension));

    String fileEnding = FilenameUtils.getExtension(absolutePath);
    if (mimeTypeMapping.containsKey(fileEnding)) {
        this.mimeType = mimeTypeMapping.get(fileEnding);
    } else {//from   ww  w . ja v  a 2s  .c om
        this.mimeType = new MimetypesFileTypeMap().getContentType(fileSource);
    }
    this.corpusRef = corpusRef;

}

From source file:FeatureExtraction.FeatureExtractorOOXMLStructuralPaths.java

private void ExtractStructuralFeaturesInMemory(String filePath, Map<String, Integer> structuralPaths) {
    String path;/*from  w  w  w . j a v  a2s .  com*/
    String directoryPath;
    String fileExtension;
    try {
        ZipFile zipFile = new ZipFile(filePath);

        for (Enumeration e = zipFile.entries(); e.hasMoreElements();) {
            ZipEntry entry = (ZipEntry) e.nextElement();
            path = entry.getName();
            directoryPath = FilenameUtils.getFullPath(path);
            fileExtension = FilenameUtils.getExtension(path);

            AddStructuralPath(directoryPath, structuralPaths);
            AddStructuralPath(path, structuralPaths);

            if (fileExtension.equals("rels") || fileExtension.equals("xml")) {
                AddXMLStructuralPaths(zipFile.getInputStream(entry), path, structuralPaths);
            }
        }
    } catch (IOException ex) {
        Console.PrintException(
                String.format("Error extracting OOXML structural features from file: %s", filePath), ex);
    }
}

From source file:com.silverpeas.converter.openoffice.OpenOfficeHTMLConverter.java

@Override
public boolean isDocumentSupported(File document) {
    String fileName = document.getName();
    String extension = FilenameUtils.getExtension(fileName);
    return isDefined(extension) && extension.equalsIgnoreCase("html");
}

From source file:com.silverpeas.converter.openoffice.OpenOfficeODTConverter.java

@Override
public boolean isDocumentSupported(File document) {
    String fileName = document.getName();
    String extension = FilenameUtils.getExtension(fileName);
    return isDefined(extension) && extension.equalsIgnoreCase("odt");
}

From source file:com.liferay.arquillian.maven.importer.LiferayPluginTestCase.java

protected static void setupPortalMinimal() {
    System.setProperty("liferay.version", LIFERAY_VERSION);

    System.setProperty("liferay.auto.deploy.dir", PORTAL_AUTO_DEPLOY_DIR);

    System.setProperty("liferay.app.server.deploy.dir", PORTAL_SERVER_DEPLOY_DIR);

    System.setProperty("liferay.app.server.lib.global.dir", PORTAL_SERVER_LIB_GLOBAL_DIR);

    System.setProperty("liferay.app.server.portal.dir", SERVER_PORTAL_DIR);

    try {//from   w  w  w  .  j  a  v a 2 s . c  om
        ArchiverManager archiverManager = plexusContainer.lookup(ArchiverManager.class);

        assertNotNull(archiverManager);

        FileUtils.forceMkdir(new File(PORTAL_AUTO_DEPLOY_DIR));
        FileUtils.forceMkdir(new File(PORTAL_SERVER_DEPLOY_DIR));
        FileUtils.forceMkdir(new File(PORTAL_SERVER_LIB_GLOBAL_DIR));
        FileUtils.forceMkdir(new File(SERVER_PORTAL_DIR));

        final MavenResolverSystem mavenResolverSystem = Maven.configureResolver()
                .fromClassloaderResource("settings.xml");

        File[] dependencies = mavenResolverSystem.loadPomFromClassLoaderResource("liferay-setup.xml")
                .importRuntimeAndTestDependencies().resolve().withoutTransitivity().asFile();

        File warFile = null;

        for (File file : dependencies) {
            String fileName = file.getName();
            String fileExtension = FilenameUtils.getExtension(fileName);

            if (fileExtension.equalsIgnoreCase("jar")) {
                FileUtils.copyFile(file, new File(PORTAL_SERVER_LIB_GLOBAL_DIR, file.getName()));
            } else if (fileExtension.equalsIgnoreCase("war") && fileName.contains("portal-web")) {

                warFile = file;
            }
        }

        assertNotNull(warFile);

        // extract portal war

        UnArchiver unArchiver = archiverManager.getUnArchiver(warFile);
        unArchiver.setDestDirectory(new File(SERVER_PORTAL_DIR));
        unArchiver.setSourceFile(warFile);
        unArchiver.setOverwrite(false);
        unArchiver.extract();
        setup = true;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:com.taunova.app.libview.components.ImageHelpers.java

public static File addPrefixToFile(File file, String prefix) {
    String name = FilenameUtils.getBaseName(file.getName());
    String extension = FilenameUtils.getExtension(file.getName());

    StringBuilder builder = new StringBuilder(file.getParent());
    builder.append(File.separator);
    builder.append(name);//from   w ww  .  j  av a2  s . c  o m
    builder.append(prefix);
    builder.append('.');
    builder.append(extension);
    return new File(builder.toString());
}

From source file:bogdanrechi.lansator.properties.ProgramItem.java

public ProgramItem(ProgramItem object) throws StringException {
    this.guid = UUID.randomUUID().toString();
    this.name = object.name;
    this.path = object.path;
    this.runInFolder = object.runInFolder;
    this.asSuperuser = object.asSuperuser;
    this.parameters = object.parameters;
    this.isImageAndText = object.isImageAndText;
    this.isSeparator = object.isSeparator;

    if (object.imageFile.length() > 0 && Files.exists(MainWindow.getImagesPath() + object.imageFile)) {
        String imageCopy = UUID.randomUUID().toString() + "." + FilenameUtils.getExtension(object.imageFile);

        Files.copyFileToFolder(MainWindow.getImagesPath() + object.imageFile, MainWindow.getImagesPath(),
                imageCopy);//  w  w  w .j  ava  2s.  co m

        this.imageFile = imageCopy;
    } else {
        this.imageFile = object.imageFile;
    }
}

From source file:com.bt.download.android.gui.adapters.menu.RenameFileMenuAction.java

@Override
protected void onClick(Context context) {
    String filePath = fd.filePath;

    String name = FilenameUtils.getBaseName(filePath);
    final String ext = FilenameUtils.getExtension(filePath);

    final EditText input = new EditText(context);
    input.setText(name);/*  www.  ja v  a 2 s .c  om*/
    input.selectAll();

    UIUtils.showOkCancelDialog(context, input, R.string.rename, new OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            String newFileName = input.getText().toString() + "." + ext;
            if (isValidFileName(newFileName)) {
                renameFile(newFileName);
                adapter.notifyDataSetChanged();
            } else {
                // FIXME
            }
        }
    });
}

From source file:com.mxhero.plugin.cloudstorage.onedrive.api.command.validators.FileValidator.java

@Override
public void validate(String name) {
    if (name == null || name.isEmpty())
        throw new IllegalArgumentException("Empty file name are not allwed");
    if (PATTERN_EXTENSION_NOT_ALLOWED.matcher(FilenameUtils.getExtension(name)).find())
        throw new IllegalArgumentException(
                "The following extensions are not allowed to upload for Business API. Extensions not allowed: "
                        + EXTENSTIONS_NOT_ALLOWED + " - Name provided: " + name);
    if (PATTERN_GUID_NOT_ALLOWED.matcher(name).find())
        throw new IllegalArgumentException("GUIDs String are not allowed as file name. Name provided: " + name);
    if (FILES_NOT_ALLOWED.contains(name))
        throw new IllegalArgumentException(
                "File name could not be " + FILES_NOT_ALLOWED.toString() + ". Name provided: " + name);
}

From source file:net.dontdrinkandroot.utils.resource.CachedFileResource.java

@Override
public String getContentType() {

    final String extension = FilenameUtils.getExtension(this.file.getName());

    if ("png".equals(extension)) {
        return "image/png";
    }//  w  w w .j a  v  a  2  s .c o m

    return null;
}