commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From adammurd...@apache.org
Subject cvs commit: jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/tasks ShowFileTask.java
Date Fri, 01 Nov 2002 03:21:38 GMT
adammurdoch    2002/10/31 19:21:38

  Modified:    vfs/src/java/org/apache/commons/vfs/tasks ShowFileTask.java
  Log:
  Added recursive flag to <showfile> Ant task.
  
  Revision  Changes    Path
  1.5       +57 -23    jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/tasks/ShowFileTask.java
  
  Index: ShowFileTask.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/tasks/ShowFileTask.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ShowFileTask.java	23 Oct 2002 13:09:45 -0000	1.4
  +++ ShowFileTask.java	1 Nov 2002 03:21:38 -0000	1.5
  @@ -75,6 +75,8 @@
   {
       private String url;
       private boolean showContent;
  +    private boolean recursive;
  +    private static final String INDENT = "  ";
   
       /**
        * The URL of the file to display.
  @@ -94,56 +96,88 @@
       }
   
       /**
  +     * Recursively shows the decendents of the file.
  +     */
  +    public void setRecursive( final boolean recursive )
  +    {
  +        this.recursive = recursive;
  +    }
  +
  +    /**
        * Executes the task.
        */
       public void execute() throws BuildException
       {
           try
           {
  -            // Lookup the file
               final FileObject file = resolveFile( url );
  +            log( "Details of " + file.getName().getURI() );
  +            showFile( file, INDENT );
  +        }
  +        catch ( final Exception e )
  +        {
  +            throw new BuildException( e );
  +        }
  +    }
   
  -            // Write details
  -            log( "URI: " + file.getName().getURI() );
  -            log( "Exists: " + file.exists() );
  -            if ( !file.exists() )
  -            {
  -                return;
  -            }
  -            log( "Type: " + file.getType().getName() );
  +    /**
  +     * Logs the details of a file.
  +     */
  +    private void showFile( final FileObject file, final String prefix ) throws Exception
  +    {
  +        // Write details
  +        StringBuffer msg = new StringBuffer( prefix );
  +        msg.append( file.getName().getBaseName() );
  +        if ( file.exists() )
  +        {
  +            msg.append( " (" );
  +            msg.append( file.getType().getName() );
  +            msg.append( ")" );
  +        }
  +        else
  +        {
  +            msg.append( " (unknown)" );
  +        }
  +        log( msg.toString() );
  +
  +        if ( file.exists() )
  +        {
  +            final String newPrefix = prefix + INDENT;
               if ( file.getType() == FileType.FILE )
               {
                   final FileContent content = file.getContent();
  -                log( "Content-Length: " + content.getSize() );
  -                log( "Last-Modified" + new Date( content.getLastModifiedTime() ) );
  +                log( newPrefix + "Content-Length: " + content.getSize() );
  +                log( newPrefix + "Last-Modified" + new Date( content.getLastModifiedTime()
) );
                   if ( showContent )
                   {
  -                    log( "Content:" );
  -                    logContent( file );
  +                    log( newPrefix + "Content:" );
  +                    logContent( file, newPrefix );
                   }
               }
               else
               {
                   final FileObject[] children = file.getChildren();
  -                log( "Child Count: " + children.length );
  -                log( "Children:" );
                   for ( int i = 0; i < children.length; i++ )
                   {
                       FileObject child = children[ i ];
  -                    log( "    " + child.getName().getBaseName() );
  +                    if ( recursive )
  +                    {
  +                        showFile( child, newPrefix );
  +                    }
  +                    else
  +                    {
  +                        log( newPrefix + child.getName().getBaseName() );
  +                    }
                   }
               }
           }
  -        catch ( final Exception e )
  -        {
  -            throw new BuildException( e );
  -        }
       }
   
       /**
        * Writes the content of the file to Ant log.
        */
  -    private void logContent( FileObject file ) throws Exception
  +    private void logContent( final FileObject file, final String prefix )
  +        throws Exception
       {
           final InputStream instr = file.getContent().getInputStream();
           try
  @@ -156,7 +190,7 @@
                   {
                       break;
                   }
  -                log( line );
  +                log( prefix + line );
               }
           }
           finally
  
  
  

--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message