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

The following examples show how to use org.apache.commons.vfs2.FileObject#equals() . 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: RepositoryTreeModel.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
public TreePath getTreePathForSelection( FileObject selectedFolder, final String selection )
  throws FileSystemException {
  if ( root.getRoot() == null ) {
    return null;
  }
  if ( root.getRoot().equals( selectedFolder ) ) {
    return new TreePath( root );
  }

  final LinkedList<Object> list = new LinkedList<Object>();
  while ( selectedFolder != null ) {
    list.add( 0, selectedFolder );
    final FileObject parent = selectedFolder.getParent();
    if ( selectedFolder.equals( parent ) ) {
      break;
    }
    if ( root.getRoot().equals( parent ) ) {
      break;
    }
    selectedFolder = parent;
  }
  list.add( 0, root );
  return new TreePath( list.toArray() );
}
 
Example 2
Source File: RepositoryOpenDialog.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Invoked when an action occurs.
 */
public void actionPerformed( final ActionEvent e ) {
  if ( locationCombo.getSelectedItem() instanceof FileObject ) {
    final FileObject selectedItem = (FileObject) locationCombo.getSelectedItem();
    if ( selectedItem.equals( getSelectedView() ) == false ) {
      setSelectedView( selectedItem );
    }
  }
}
 
Example 3
Source File: RepositoryOpenDialog.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
private ComboBoxModel createLocationModel( final FileObject selectedFolder ) {
  if ( fileSystemRoot == null ) {
    return new DefaultComboBoxModel();
  }

  try {
    final ArrayList<FileObject> list = new ArrayList<FileObject>();
    FileObject folder = selectedFolder;
    while ( folder != null ) {
      if ( fileSystemRoot.equals( folder ) ) {
        break;
      }

      if ( folder.getType() != FileType.FILE ) {
        list.add( folder );
      }

      final FileObject parent = folder.getParent();
      if ( folder.equals( parent ) ) {
        // protect yourself against infinite loops ..
        break;
      }
      folder = parent;
    }
    list.add( fileSystemRoot );
    final DefaultComboBoxModel model = new DefaultComboBoxModel( list.toArray() );
    model.setSelectedItem( list.get( 0 ) );
    return model;
  } catch ( FileSystemException e ) {
    return new DefaultComboBoxModel();
  }
}
 
Example 4
Source File: SpoonTabsDelegate.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
/**
 * Finds the tab for the transformation that matches the metadata provided (either the file must be the same or the
 * repository id).
 *
 * @param trans
 *          Transformation metadata to look for
 * @return Tab with transformation open whose metadata matches {@code trans} or {@code null} if no tab exists.
 * @throws KettleFileException
 *           If there is a problem loading the file object for an open transformation with an invalid a filename.
 */
public TabMapEntry findTabForTransformation( TransMeta trans ) throws KettleFileException {
  // File for the transformation we're looking for. It will be loaded upon first request.
  FileObject transFile = null;
  for ( TabMapEntry entry : tabMap ) {
    if ( entry != null && !entry.getTabItem().isDisposed() ) {
      if ( trans.getFilename() != null && entry.getFilename() != null ) {
        // If the entry has a file name it is the same as trans iff. they originated from the same files
        FileObject entryFile = KettleVFS.getFileObject( entry.getFilename() );
        if ( transFile == null ) {
          transFile = KettleVFS.getFileObject( trans.getFilename() );
        }
        if ( entryFile.equals( transFile ) ) {
          return entry;
        }
      } else if ( trans.getObjectId() != null && entry.getObject() != null ) {
        EngineMetaInterface meta = entry.getObject().getMeta();
        if ( meta != null && trans.getObjectId().equals( meta.getObjectId() ) ) {
          // If the transformation has an object id and the entry shares the same id they are the same
          return entry;
        }
      }
    }
  }
  // No tabs for the transformation exist and are not disposed
  return null;
}
 
Example 5
Source File: PipelineUnitTest.java    From hop with Apache License 2.0 4 votes vote down vote up
public void setRelativeFilename( String referencePipelineFilename ) throws HopException {
  // Build relative path whenever a pipeline is saved
  //
  if ( StringUtils.isEmpty( referencePipelineFilename ) ) {
    return; // nothing we can do
  }

  // Set the filename to be safe
  //
  setPipelineFilename( referencePipelineFilename );

  String base = getBasePath();
  if ( StringUtils.isEmpty( base ) ) {
    base = getVariable( DataSetConst.VARIABLE_UNIT_TESTS_BASE_PATH );
  }
  base = environmentSubstitute( base );
  if ( StringUtils.isNotEmpty( base ) ) {
    // See if the base path is present in the filename
    // Then replace the filename
    //
    try {
      FileObject baseFolder = HopVfs.getFileObject( base );
      FileObject pipelineFile = HopVfs.getFileObject( referencePipelineFilename );
      FileObject parent = pipelineFile.getParent();
      while ( parent != null ) {
        if ( parent.equals( baseFolder ) ) {
          // Here we are, we found the base folder in the pipeline file
          //
          String pipelineFileString = pipelineFile.toString();
          String baseFolderName = parent.toString();

          // Final validation & unit test filename correction
          //
          if ( pipelineFileString.startsWith( baseFolderName ) ) {
            String relativeFile = pipelineFileString.substring( baseFolderName.length() );
            String relativeFilename;
            if ( relativeFile.startsWith( "/" ) ) {
              relativeFilename = "." + relativeFile;
            } else {
              relativeFilename = "./" + relativeFile;
            }
            // Set the pipeline filename to the relative path
            //
            setPipelineFilename( relativeFilename );

            LogChannel.GENERAL.logDetailed( "Unit test '" + getName() + "' : saved relative path to pipeline: " + relativeFilename );
          }
        }
        parent = parent.getParent();
      }
    } catch ( Exception e ) {
      throw new HopException( "Error calculating relative unit test file path", e );
    }
  }

}
 
Example 6
Source File: DataSetHelper.java    From pentaho-pdi-dataset with Apache License 2.0 4 votes vote down vote up
private void saveUnitTest( MetaStoreFactory<TransUnitTest> testFactory, TransUnitTest unitTest, TransMeta transMeta ) throws MetaStoreException {

    // Build relative path whenever a transformation is saved
    //
    if ( StringUtils.isNotEmpty( transMeta.getFilename() ) ) {
      // Set the filename to be safe
      //
      unitTest.setTransFilename( transMeta.getFilename() );

      String basePath = unitTest.getBasePath();
      if ( StringUtils.isEmpty( basePath ) ) {
        basePath = transMeta.getVariable( DataSetConst.VARIABLE_UNIT_TESTS_BASE_PATH );
      }
      basePath = transMeta.environmentSubstitute( basePath );
      if ( StringUtils.isNotEmpty( basePath ) ) {
        // See if the basePath is present in the filename
        // Then replace the filename
        //
        try {
          FileObject baseFolder = KettleVFS.getFileObject( basePath );
          FileObject transFile = KettleVFS.getFileObject( transMeta.getFilename() );
          FileObject parent = transFile.getParent();
          while ( parent != null ) {
            if ( parent.equals( baseFolder ) ) {
              // Here we are, we found the base folder in the transformation file
              //
              String transFilename = transFile.toString();
              String baseFoldername = parent.toString();

              // Final validation & unit test filename correction
              //
              if ( transFilename.startsWith( baseFoldername ) ) {
                String relativeFile = transFilename.substring( baseFoldername.length() );
                String filename;
                if ( relativeFile.startsWith( "/" ) ) {
                  filename = "." + relativeFile;
                } else {
                  filename = "./" + relativeFile;
                }
                // Set the transformation filename to the relative path
                //
                unitTest.setTransFilename( filename );
                LogChannel.GENERAL.logBasic( "Unit test '" + unitTest.getName() + "' : Saved relative path to transformation: " + filename );
              }
            }
            parent = parent.getParent();
          }
        } catch ( Exception e ) {
          throw new MetaStoreException( "Error calculating relative unit test file path", e );
        }
      }
    }

    testFactory.saveElement( unitTest );
  }
 
Example 7
Source File: FilePlayListReplay.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
private void initializeCurrentIfNeeded( FileObject file, String filePart ) throws KettleException {
  if ( !( file.equals( getCurrentProcessingFile() ) && filePart.equals( getCurrentProcessingFilePart() ) ) ) {
    initializeCurrent( file, filePart );
  }
}