Java Code Examples for org.apache.commons.vfs2.FileObject#isHidden()

The following examples show how to use org.apache.commons.vfs2.FileObject#isHidden() . 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: BaseFileInputTransform.java    From hop with Apache License 2.0 6 votes vote down vote up
/**
 * Prepare file-dependent data for fill additional fields.
 */
protected void fillFileAdditionalFields( Data data, FileObject file ) throws FileSystemException {
  data.shortFilename = file.getName().getBaseName();
  data.path = HopVfs.getFilename( file.getParent() );
  data.hidden = file.isHidden();
  data.extension = file.getName().getExtension();
  data.uriName = file.getName().getURI();
  data.rootUriName = file.getName().getRootURI();
  if ( file.getType().hasContent() ) {
    data.lastModificationDateTime = new Date( file.getContent().getLastModifiedTime() );
    data.size = file.getContent().getSize();
  } else {
    data.lastModificationDateTime = null;
    data.size = null;
  }
}
 
Example 2
Source File: KettleFileRepository.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
private ObjectId[] getRootObjectIDs( String extension ) throws KettleException {
  try {
    // Get all the files in the root directory with a certain extension...
    //
    List<ObjectId> list = new ArrayList<ObjectId>();

    String folderName = repositoryMeta.getBaseDirectory();
    FileObject folder = KettleVFS.getFileObject( folderName );

    for ( FileObject child : folder.getChildren() ) {
      if ( child.getType().equals( FileType.FILE ) ) {
        if ( !child.isHidden() || !repositoryMeta.isHidingHiddenFiles() ) {
          String name = child.getName().getBaseName();

          if ( name.endsWith( extension ) ) {
            list.add( new StringObjectId( name ) );
          }
        }
      }
    }

    return list.toArray( new ObjectId[list.size()] );
  } catch ( Exception e ) {
    throw new KettleException( "Unable to get root object ids for extension [" + extension + "]", e );
  }
}
 
Example 3
Source File: KettleFileRepository.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
public RepositoryDirectoryInterface loadRepositoryDirectoryTree( RepositoryDirectoryInterface dir ) throws KettleException {
  try {
    String folderName = calcDirectoryName( dir );
    FileObject folder = KettleVFS.getFileObject( folderName );

    for ( FileObject child : folder.getChildren() ) {
      if ( child.getType().equals( FileType.FOLDER ) ) {
        if ( !child.isHidden() || !repositoryMeta.isHidingHiddenFiles() ) {
          if ( !".meta".equals( child.getName().getBaseName() ) ) {
            RepositoryDirectory subDir = new RepositoryDirectory( dir, child.getName().getBaseName() );
            subDir.setObjectId( new StringObjectId( calcObjectId( subDir ) ) );
            dir.addSubdirectory( subDir );

            loadRepositoryDirectoryTree( subDir );
          }
        }
      }
    }

    return dir;
  } catch ( Exception e ) {
    throw new KettleException( "Unable to load the directory tree from this file repository", e );
  }
}
 
Example 4
Source File: BaseFileInputStep.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
/**
 * Prepare file-dependent data for fill additional fields.
 */
protected void fillFileAdditionalFields( D data, FileObject file ) throws FileSystemException {
  data.shortFilename = file.getName().getBaseName();
  data.path = KettleVFS.getFilename( file.getParent() );
  data.hidden = file.isHidden();
  data.extension = file.getName().getExtension();
  data.uriName = file.getName().getURI();
  data.rootUriName = file.getName().getRootURI();
  if ( file.getType().hasContent() ) {
    data.lastModificationDateTime = new Date( file.getContent().getLastModifiedTime() );
    data.size = file.getContent().getSize();
  } else {
    data.lastModificationDateTime = null;
    data.size = null;
  }
}
 
Example 5
Source File: OldVFSNotebookRepo.java    From zeppelin with Apache License 2.0 5 votes vote down vote up
@Override
public List<OldNoteInfo> list(AuthenticationInfo subject) throws IOException {
  FileObject rootDir = getRootDir();

  FileObject[] children = rootDir.getChildren();

  List<OldNoteInfo> infos = new LinkedList<>();
  for (FileObject f : children) {
    String fileName = f.getName().getBaseName();
    if (f.isHidden()
        || fileName.startsWith(".")
        || fileName.startsWith("#")
        || fileName.startsWith("~")) {
      // skip hidden, temporary files
      continue;
    }

    if (!isDirectory(f)) {
      // currently single note is saved like, [NOTE_ID]/note.json.
      // so it must be a directory
      continue;
    }

    OldNoteInfo info = null;

    try {
      info = getNoteInfo(f);
      if (info != null) {
        infos.add(info);
      }
    } catch (Exception e) {
      LOG.error("Can't read note " + f.getName().toString());
    }
  }

  return infos;
}
 
Example 6
Source File: VfsTableModelHiddenFileRowFilter.java    From otroslogviewer with Apache License 2.0 5 votes vote down vote up
protected boolean checkIfInclude(FileObject fileObject) {
  if (!showHidden) {
    try {
      if (fileObject.getName().getBaseName().startsWith(".") || fileObject.isHidden()) {
        return false;
      }
    } catch (FileSystemException e) {

    }
  }
  return true;
}
 
Example 7
Source File: RepositoryTreeModel.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Returns the child of <code>parent</code> at index <code>index</code> in the parent's child array.
 * <code>parent</code> must be a node previously obtained from this data source. This should not return
 * <code>null</code> if <code>index</code> is a valid index for <code>parent</code> (that is <code>index >= 0 && index
 * < getChildCount(parent</code>)).
 *
 * @param parent
 *          a node in the tree, obtained from this data source
 * @return the child of <code>parent</code> at index <code>index</code>
 */
public Object getChild( Object parent, final int index ) {
  if ( parent instanceof RepositoryTreeRoot ) {
    final RepositoryTreeRoot root1 = (RepositoryTreeRoot) parent;
    parent = root1.getRoot();
    if ( parent == null ) {
      return null;
    }
  }

  try {
    final FileObject parElement = (FileObject) parent;
    final FileObject[] children = parElement.getChildren();
    int count = 0;
    for ( int i = 0; i < children.length; i++ ) {
      final FileObject child = children[i];
      if ( isShowFoldersOnly() && child.getType() != FileType.FOLDER ) {
        continue;
      }
      if ( isShowHiddenFiles() == false && child.isHidden() ) {
        continue;
      }
      if ( child.getType() != FileType.FOLDER
          && PublishUtil.acceptFilter( filters, child.getName().getBaseName() ) == false ) {
        continue;
      }

      if ( count == index ) {
        return child;
      }

      count += 1;
    }
    return children[index];
  } catch ( FileSystemException fse ) {
    logger.debug( "Failed", fse );
    return null;
  }
}
 
Example 8
Source File: RepositoryTreeModel.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Returns the number of children of <code>parent</code>. Returns 0 if the node is a leaf or if it has no children.
 * <code>parent</code> must be a node previously obtained from this data source.
 *
 * @param parent
 *          a node in the tree, obtained from this data source
 * @return the number of children of the node <code>parent</code>
 */
public int getChildCount( Object parent ) {
  if ( parent instanceof RepositoryTreeRoot ) {
    final RepositoryTreeRoot root1 = (RepositoryTreeRoot) parent;
    parent = root1.getRoot();
    if ( parent == null ) {
      return 0;
    }
  }
  try {
    final FileObject parElement = (FileObject) parent;
    if ( parElement.getType() != FileType.FOLDER ) {
      return 0;
    }

    final FileObject[] children = parElement.getChildren();
    int count = 0;
    for ( int i = 0; i < children.length; i++ ) {
      final FileObject child = children[i];
      if ( isShowFoldersOnly() && child.getType() != FileType.FOLDER ) {
        continue;
      }
      if ( isShowHiddenFiles() == false && child.isHidden() ) {
        continue;
      }
      if ( child.getType() != FileType.FOLDER
          && PublishUtil.acceptFilter( filters, child.getName().getBaseName() ) == false ) {
        continue;
      }

      count += 1;
    }
    return count;
  } catch ( FileSystemException fse ) {
    logger.debug( "Failed", fse );
    return 0;
  }
}
 
Example 9
Source File: RepositoryTableModel.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public int getRowCount() {
  if ( selectedPath == null ) {
    return 0;
  }

  try {
    if ( selectedPath.getType() != FileType.FOLDER ) {
      return 0;
    }

    final FileObject[] children = selectedPath.getChildren();
    int count = 0;
    for ( int i = 0; i < children.length; i++ ) {
      final FileObject child = children[i];
      if ( isShowHiddenFiles() == false && child.isHidden() ) {
        continue;
      }
      if ( child.getType() != FileType.FOLDER ) {
        if ( PublishUtil.acceptFilter( filters, child.getName().getBaseName() ) == false ) {
          continue;
        }
      }

      count += 1;
    }
    return count;
  } catch ( FileSystemException fse ) {
    UncaughtExceptionsModel.getInstance().addException( fse );
    return 0;
  }
}
 
Example 10
Source File: RepositoryTableModel.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public FileObject getElementForRow( final int row ) {
  if ( selectedPath == null ) {
    return null;
  }

  try {
    if ( selectedPath.getType() != FileType.FOLDER ) {
      return null;
    }

    final FileObject[] children = selectedPath.getChildren();
    int count = 0;
    for ( int i = 0; i < children.length; i++ ) {
      final FileObject child = children[i];
      if ( isShowHiddenFiles() == false && child.isHidden() ) {
        continue;
      }
      if ( child.getType() != FileType.FOLDER ) {
        if ( PublishUtil.acceptFilter( filters, child.getName().getBaseName() ) == false ) {
          continue;
        }
      }

      if ( count == row ) {
        return child;
      }
      count += 1;
    }
    return null;
  } catch ( FileSystemException fse ) {
    UncaughtExceptionsModel.getInstance().addException( fse );
    return null;
  }
}
 
Example 11
Source File: KettleFileRepository.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@Override
public String[] getJobNames( ObjectId id_directory, boolean includeDeleted ) throws KettleException {
  try {
    List<String> list = new ArrayList<String>();

    RepositoryDirectoryInterface tree = loadRepositoryDirectoryTree();
    RepositoryDirectoryInterface directory = tree.findDirectory( id_directory );

    String folderName = calcDirectoryName( directory );
    FileObject folder = KettleVFS.getFileObject( folderName );

    for ( FileObject child : folder.getChildren() ) {
      if ( child.getType().equals( FileType.FILE ) ) {
        if ( !child.isHidden() || !repositoryMeta.isHidingHiddenFiles() ) {
          String name = child.getName().getBaseName();

          if ( name.endsWith( EXT_JOB ) ) {

            String jobName = name.substring( 0, name.length() - 4 );
            list.add( jobName );
          }
        }
      }
    }

    return list.toArray( new String[list.size()] );
  } catch ( Exception e ) {
    throw new KettleException(
      "Unable to get list of transformations names in folder with id : " + id_directory, e );
  }
}
 
Example 12
Source File: KettleFileRepository.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@Override
public String[] getTransformationNames( ObjectId id_directory, boolean includeDeleted ) throws KettleException {
  try {
    List<String> list = new ArrayList<String>();

    RepositoryDirectoryInterface tree = loadRepositoryDirectoryTree();
    RepositoryDirectoryInterface directory = tree.findDirectory( id_directory );

    String folderName = calcDirectoryName( directory );
    FileObject folder = KettleVFS.getFileObject( folderName );

    for ( FileObject child : folder.getChildren() ) {
      if ( child.getType().equals( FileType.FILE ) ) {
        if ( !child.isHidden() || !repositoryMeta.isHidingHiddenFiles() ) {
          String name = child.getName().getBaseName();

          if ( name.endsWith( EXT_TRANSFORMATION ) ) {

            String transName = name.substring( 0, name.length() - 4 );
            list.add( transName );
          }
        }
      }
    }

    return list.toArray( new String[list.size()] );
  } catch ( Exception e ) {
    throw new KettleException(
      "Unable to get list of transformations names in folder with id : " + id_directory, e );
  }
}
 
Example 13
Source File: KettleFileRepository.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@Override
public List<RepositoryElementMetaInterface> getTransformationObjects( ObjectId idDirectory,
  boolean includeDeleted ) throws KettleException {

  try {
    List<RepositoryElementMetaInterface> list = new ArrayList<RepositoryElementMetaInterface>();

    RepositoryDirectoryInterface tree = loadRepositoryDirectoryTree();
    RepositoryDirectoryInterface directory = tree.findDirectory( idDirectory );

    String folderName = calcDirectoryName( directory );
    FileObject folder = KettleVFS.getFileObject( folderName );

    for ( FileObject child : folder.getChildren() ) {
      if ( child.getType().equals( FileType.FILE ) ) {
        if ( !child.isHidden() || !repositoryMeta.isHidingHiddenFiles() ) {

          String name = child.getName().getBaseName();

          if ( name.endsWith( EXT_TRANSFORMATION ) ) {

            String transName = name.substring( 0, name.length() - 4 );

            ObjectId id = new StringObjectId( calcObjectId( directory, transName, EXT_TRANSFORMATION ) );
            Date date = new Date( child.getContent().getLastModifiedTime() );
            list.add( new RepositoryObject(
              id, transName, directory, "-", date, RepositoryObjectType.TRANSFORMATION, "", false ) );
          }
        }
      }
    }

    return list;
  } catch ( Exception e ) {
    throw new KettleException( "Unable to get list of transformations in folder with id : " + idDirectory, e );
  }
}
 
Example 14
Source File: KettleFileRepository.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@Override
public List<RepositoryElementMetaInterface> getJobObjects( ObjectId id_directory, boolean includeDeleted ) throws KettleException {

  try {
    List<RepositoryElementMetaInterface> list = new ArrayList<RepositoryElementMetaInterface>();

    RepositoryDirectoryInterface tree = loadRepositoryDirectoryTree();
    RepositoryDirectoryInterface directory = tree.findDirectory( id_directory );

    String folderName = calcDirectoryName( directory );
    FileObject folder = KettleVFS.getFileObject( folderName );

    for ( FileObject child : folder.getChildren() ) {
      if ( child.getType().equals( FileType.FILE ) ) {
        if ( !child.isHidden() || !repositoryMeta.isHidingHiddenFiles() ) {
          String name = child.getName().getBaseName();

          if ( name.endsWith( EXT_JOB ) ) {

            String jobName = name.substring( 0, name.length() - 4 );

            ObjectId id = new StringObjectId( calcObjectId( directory, jobName, EXT_JOB ) );
            Date date = new Date( child.getContent().getLastModifiedTime() );
            list.add( new RepositoryObject(
              id, jobName, directory, "-", date, RepositoryObjectType.JOB, "", false ) );
          }
        }
      }
    }

    return list;
  } catch ( Exception e ) {
    throw new KettleException( "Unable to get list of jobs in folder with id : " + id_directory, e );
  }
}
 
Example 15
Source File: RepositoryTreeModel.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Returns the index of child in parent. If either <code>parent</code> or <code>child</code> is <code>null</code>,
 * returns -1. If either <code>parent</code> or <code>child</code> don't belong to this tree model, returns -1.
 *
 * @param parent
 *          a note in the tree, obtained from this data source
 * @param childNode
 *          the node we are interested in
 * @return the index of the child in the parent, or -1 if either <code>child</code> or <code>parent</code> are
 *         <code>null</code> or don't belong to this tree model
 */
public int getIndexOfChild( Object parent, final Object childNode ) {
  if ( parent instanceof RepositoryTreeRoot ) {
    final RepositoryTreeRoot root1 = (RepositoryTreeRoot) parent;
    parent = root1.getRoot();
    if ( parent == null ) {
      return -1;
    }
  }

  try {
    final FileObject parChild = (FileObject) childNode;
    final FileObject parElement = (FileObject) parent;
    final FileObject[] childs = parElement.getChildren();
    int count = 0;
    for ( int i = 0; i < childs.length; i++ ) {
      final FileObject child = childs[i];
      if ( isShowFoldersOnly() && child.getType() != FileType.FOLDER ) {
        continue;
      }
      if ( isShowHiddenFiles() == false && child.isHidden() ) {
        continue;
      }
      if ( child.getType() != FileType.FOLDER
          && PublishUtil.acceptFilter( filters, child.getName().getBaseName() ) == false ) {
        continue;
      }

      if ( child.getName().equals( parChild.getName() ) ) {
        return count;
      }

      count += 1;
    }

    return -1;
  } catch ( FileSystemException fse ) {
    logger.debug( "Failed", fse );
    return -1;
  }
}