Java Code Examples for org.apache.commons.vfs2.FileName#getBaseName()

The following examples show how to use org.apache.commons.vfs2.FileName#getBaseName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HopGuiPipelineGraph.java    From hop with Apache License 2.0 6 votes vote down vote up
public String buildTabName() throws HopException {
  String tabName = null;
  String realFilename = pipelineMeta.environmentSubstitute( pipelineMeta.getFilename() );
  if ( StringUtils.isEmpty( realFilename ) ) {
    tabName = pipelineMeta.getName();
  } else {
    try {
      FileObject fileObject = HopVfs.getFileObject( pipelineMeta.getFilename() );
      FileName fileName = fileObject.getName();
      tabName = fileName.getBaseName();
    } catch ( Exception e ) {
      throw new HopException( "Unable to get information from file name '" + pipelineMeta.getFilename() + "'", e );
    }
  }
  return tabName;
}
 
Example 2
Source File: HopGuiWorkflowGraph.java    From hop with Apache License 2.0 6 votes vote down vote up
public String buildTabName() throws HopException {
  String tabName = null;
  String realFilename = workflowMeta.environmentSubstitute( workflowMeta.getFilename() );
  if ( StringUtils.isEmpty( realFilename ) ) {
    tabName = workflowMeta.getName();
  } else {
    try {
      FileObject fileObject = HopVfs.getFileObject( workflowMeta.getFilename() );
      FileName fileName = fileObject.getName();
      tabName = fileName.getBaseName();
    } catch ( Exception e ) {
      throw new HopException( "Unable to get information from file name '" + workflowMeta.getFilename() + "'", e );
    }
  }
  return tabName;
}
 
Example 3
Source File: VFSFileSystem.java    From commons-configuration with Apache License 2.0 6 votes vote down vote up
@Override
public String getFileName(final String path)
{
    if (UriParser.extractScheme(path) == null)
    {
        return super.getFileName(path);
    }
    try
    {
        final FileSystemManager fsManager = VFS.getManager();
        final FileName name = fsManager.resolveURI(path);
        return name.getBaseName();
    }
    catch (final FileSystemException fse)
    {
        fse.printStackTrace();
        return null;
    }
}
 
Example 4
Source File: JCRSolutionDirectFileModel.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void setData( final FileName fullName, final byte[] data ) throws FileSystemException {
  /*
  /api/repo/files/import
  public Response doPostImport(
    @FormDataParam("importDir") String uploadDir,
    @FormDataParam("fileUpload") InputStream fileIS,
    @FormDataParam("overwriteFile") String overwriteFile,
    @FormDataParam("overwriteAclPermissions") String overwriteAclPermissions,
    @FormDataParam("applyAclPermissions") String applyAclPermission,
    @FormDataParam("retainOwnership") String retainOwnership,
    @FormDataParam("charSet") String charSet,
    @FormDataParam("logLevel") String logLevel,
    @FormDataParam("fileUpload") FormDataContentDisposition fileInfo,
    @FormDataParam("fileNameOverried) String fileNameOveride )
  */
  logger.debug( "setData: " + fullName );

  final String name = fullName.getBaseName();
  final String parent = fullName.getParent().getPath();
  final ByteArrayInputStream stream = new ByteArrayInputStream( data );
  final FormDataContentDisposition fd = FormDataContentDisposition
    .name( name )
    .fileName( name )
    .build();
  Response response =
    this.importRes.doPostImport( parent, stream, "true", null, "true", "true", null, "WARN", fd, null );
  throwExceptionOnBadResponse( response );
}
 
Example 5
Source File: XmlSolutionFileModel.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected String[] computeFileNames( FileName file ) {
  final FastStack stack = new FastStack();
  while ( file != null ) {
    final String name = file.getBaseName();
    stack.push( name );
    file = file.getParent();
  }

  final int size = stack.size();
  final String[] result = new String[ size ];
  for ( int i = 0; i < result.length; i++ ) {
    result[ i ] = (String) stack.pop();
  }
  return result;
}
 
Example 6
Source File: KettleFileRepository.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@Override
public RepositoryObject getObjectInformation( ObjectId objectId, RepositoryObjectType objectType ) throws KettleException {
  try {
    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 ( !Utils.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 );
  }
}
 
Example 7
Source File: SpoofaxIgnoresSelector.java    From spoofax with Apache License 2.0 4 votes vote down vote up
@Override public boolean traverseDescendents(FileSelectInfo fileInfo) throws Exception {
    final int depth = fileInfo.getDepth();
    final FileObject resource = fileInfo.getFile();
    final FileName name = resource.getName();
    final String base = name.getBaseName();

    switch(depth) {
        case 1:
            switch(base) {
                case "include": // Spoofax/Stratego
                case ".cache": // Spoofax/Stratego
                case "bin": // Eclipse
                case ".settings": // Eclipse
                case "target": // Maven
                case ".mvn": // Maven
                case "build": // Gradle
                case ".gradle": // Gradle
                case "out": // IntelliJ
                case ".idea": // IntelliJ
                case ".git": // Git
                    return false;
            }
            break;
        case 3:
            switch(base) {
                // Ignore editor/java/trans and src-gen/stratego-java/trans.
                case "trans": {
                    final FileObject parent1 = resource.getParent();
                    if(parent1 != null) {
                        final String parent1base = parent1.getName().getBaseName();
                        if(parent1base.equals("java") || parent1base.equals("stratego-java")) {
                            final FileObject parent2 = parent1.getParent();
                            if(parent2 != null) {
                                final String parent2base = parent2.getName().getBaseName();
                                return !(parent2base.equals("editor") || parent2base.equals("src-gen"));
                            }
                        }
                    }
                    break;
                }
            }
            break;
    }

    return true;
}