public String getXML( int level ) { String spaces = Const.rightPad( " ", level ); StringBuilder retval = new StringBuilder( 200 ); retval.append( spaces ).append( "<repdir>" ).append( Const.CR ); retval.append( spaces ).append( " " ).append( XMLHandler.addTagValue( "name", getName() ) ); if ( getNrSubdirectories() > 0 ) { retval.append( spaces ).append( " <subdirs>" ).append( Const.CR ); for ( int i = 0; i < getNrSubdirectories(); i++ ) { RepositoryDirectory subdir = getSubdirectory( i ); retval.append( subdir.getXML( level + 1 ) ); } retval.append( spaces ).append( " </subdirs>" ).append( Const.CR ); } retval.append( spaces ).append( "</repdir>" ).append( Const.CR ); return retval.toString(); }
/** * Fill an arraylist with all the ID_DIRECTORY values in the tree below and including this directory. * * @param ids * The arraylist that will contain the directory IDs. */ private void getDirectoryIDs( List<ObjectId> ids ) { if ( getObjectId() != null ) { ids.add( getObjectId() ); } for ( int i = 0; i < getNrSubdirectories(); i++ ) { getSubdirectory( i ).getDirectoryIDs( ids ); } }
/** * Find the sub-directory with a certain ID * * @param id_directory * the directory ID to look for. * @return The RepositoryDirectory if the ID was found, null if nothing could be found. */ @Override public RepositoryDirectory findDirectory( ObjectId id_directory ) { // Check for the root directory... // if ( getObjectId() == null && id_directory == null ) { return this; } if ( getObjectId() != null && getObjectId().equals( id_directory ) ) { return this; } for ( int i = 0; i < getNrSubdirectories(); i++ ) { RepositoryDirectory rd = getSubdirectory( i ).findDirectory( id_directory ); if ( rd != null ) { return rd; } } return null; }
private RepositoryDirectoryInterface initRepositoryDirectoryTree( RepositoryFileTree repoTree ) throws KettleException { RepositoryFile rootFolder = repoTree.getFile(); RepositoryDirectory rootDir = new RepositoryDirectory(); rootDir.setObjectId( new StringObjectId( rootFolder.getId().toString() ) ); fillRepositoryDirectoryFromTree( rootDir, repoTree ); // Example: /etc RepositoryDirectory etcDir = rootDir.findDirectory( ClientRepositoryPaths.getEtcFolderPath() ); RepositoryDirectory newRoot = new RepositoryDirectory(); newRoot.setObjectId( rootDir.getObjectId() ); newRoot.setVisible( false ); for ( int i = 0; i < rootDir.getNrSubdirectories(); i++ ) { RepositoryDirectory childDir = rootDir.getSubdirectory( i ); // Don't show /etc boolean isEtcChild = childDir.equals( etcDir ); if ( isEtcChild ) { continue; } newRoot.addSubdirectory( childDir ); } return newRoot; }