Example usage for org.apache.commons.vfs FileName getExtension

List of usage examples for org.apache.commons.vfs FileName getExtension

Introduction

In this page you can find the example usage for org.apache.commons.vfs FileName getExtension.

Prototype

public String getExtension();

Source Link

Document

Returns the extension of this file name.

Usage

From source file:org.pentaho.di.repository.filerep.KettleFileRepository.java

public RepositoryObject getObjectInformation(ObjectId objectId, RepositoryObjectType objectType)
        throws KettleException {
    try {/* w  w w. j  a va  2 s .  c om*/
        String filename = calcDirectoryName(null);
        if (objectId.getId().startsWith("/")) {
            filename += objectId.getId().substring(1);
        } else {
            filename += objectId.getId();
        }
        FileObject fileObject = KettleVFS.getFileObject(filename);
        if (!fileObject.exists()) {
            return null;
        }
        FileName fname = fileObject.getName();
        String name = fname.getBaseName();
        if (!Const.isEmpty(fname.getExtension()) && name.length() > fname.getExtension().length()) {
            name = name.substring(0, name.length() - fname.getExtension().length() - 1);
        }

        String filePath = fileObject.getParent().getName().getPath();
        final FileObject baseDirObject = KettleVFS.getFileObject(repositoryMeta.getBaseDirectory());
        final int baseDirObjectPathLength = baseDirObject.getName().getPath().length();
        final String dirPath = baseDirObjectPathLength <= filePath.length()
                ? filePath.substring(baseDirObjectPathLength)
                : "/";
        RepositoryDirectoryInterface directory = loadRepositoryDirectoryTree().findDirectory(dirPath);
        Date lastModified = new Date(fileObject.getContent().getLastModifiedTime());

        return new RepositoryObject(objectId, name, directory, "-", lastModified, objectType, "", false);

    } catch (Exception e) {
        throw new KettleException("Unable to get object information for object with id=" + objectId, e);
    }
}