home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1997 May / Pcwk0597.iso / sybase / starbuck / samples.z / DDir_Walker.wxc < prev    next >
Text File  |  1996-12-10  |  7KB  |  248 lines

  1. Save Format v1.3
  2. @begin ClassFile "DDir_Walker"
  3.  Exported 0;
  4.  Abstract 0;
  5.  Interface 0;
  6.  PackageName "";
  7.  Language "Java";
  8.  
  9.  @begin UserFunction "DDir_Walker()"
  10.   Compiler 1;
  11.   GencodeSrcLine 12;
  12.   FunctionName "DDir_Walker::DDir_Walker()";
  13.  @end;
  14.  
  15.  @begin UserFunction "main(String args[])"
  16.   Compiler 1;
  17.   GencodeFunction 1;
  18.   GencodeSrcLine 16;
  19.   FunctionName "DDir_Walker::main(String args[])";
  20.  @end;
  21.  
  22.  @begin UserFunction "CreateMainForm()"
  23.   Compiler 1;
  24.   GencodeFunction 1;
  25.   GencodeSrcLine 23;
  26.   FunctionName "DDir_Walker::CreateMainForm()";
  27.  @end;
  28.  
  29.  @begin UserFunction "StartApp(String args[])"
  30.   Compiler 1;
  31.   GencodeSrcLine 26;
  32.   FunctionName "DDir_Walker::StartApp(String args[])";
  33.  @end;
  34.  
  35.  @begin UserFunction "RunApp(String args[])"
  36.   Compiler 1;
  37.   GencodeSrcLine 39;
  38.   FunctionName "DDir_Walker::RunApp(String args[])";
  39.  @end;
  40.  
  41.  @begin UserFunction "EndApp(String args[])"
  42.   Compiler 1;
  43.   GencodeSrcLine 145;
  44.   FunctionName "DDir_Walker::EndApp(String args[])";
  45.  @end;
  46.  
  47.  @begin HPPPrefixBlock
  48. @begin-code HPPPrefix
  49.  
  50. // add your custom import statements here
  51. import java.io.*;
  52. import java.util.*;
  53.  
  54. @end-code;
  55.   GencodeSrcLine 6;
  56.  @end;
  57.  
  58.  @begin ClassContentsBlock
  59. @begin-code ClassContents
  60.  
  61.     // add your data members here
  62.     DynamoConnection dynamo;
  63.     Document    document;
  64.     DBConnection  connection;
  65.     Session session;
  66.  
  67. @end-code;
  68.   GencodeSrcLine 148;
  69.  @end;
  70.  
  71. @begin-code BaseClassList
  72.  
  73. extends Object
  74.  
  75. @end-code;
  76.  
  77. @begin-code GeneratedClassContents
  78.  
  79.  
  80. @end-code;
  81.  
  82. @begin-code Code "DDir_Walker::DDir_Walker()"
  83.  
  84.     public @CLASSNAME@()
  85.     {
  86.         super();
  87.     }
  88.  
  89. @end-code;
  90.  
  91. @begin-code Code "DDir_Walker::main(String args[])"
  92.  
  93.     public static void main(String args[])
  94.     {
  95.         @@CLASSNAME@ app = new @CLASSNAME@();
  96.         app.StartApp(args);
  97.         app.RunApp(args);
  98.         app.EndApp(args);
  99.     }
  100.  
  101. @end-code;
  102.  
  103. @begin-code Code "DDir_Walker::CreateMainForm()"
  104.  
  105.     public void CreateMainForm()
  106.     {
  107.     }
  108.  
  109. @end-code;
  110.  
  111. @begin-code Code "DDir_Walker::StartApp(String args[])"
  112.  
  113.     public void StartApp(String args[])
  114.     {
  115.         dynamo = new DynamoConnection( args );
  116.         if(! dynamo.getConnected() ) {
  117.             System.err.println( "Connection to NetImpact Dynamo failed" );
  118.             System.exit(2);
  119.         }
  120.         // Define wrapper classes
  121.         document = dynamo.getDocument();
  122.         connection = dynamo.getDBConnection();
  123.         session = dynamo.getSession();
  124.  
  125.     }
  126.  
  127. @end-code;
  128.  
  129. @begin-code Code "DDir_Walker::RunApp(String args[])"
  130.  
  131.     public void RunApp(String args[])
  132.     {
  133.         //CreateMainForm();
  134.         try {       
  135.             document.writeln( "<CENTER><H1>Java Dynamo Directory Walker Sample" ); 
  136.             document.writeln( "<P>\n<BR>\n<HR>\n<BR>" );
  137.         
  138.         
  139.             String directory = args[1];
  140.             Vector dirList = new Vector( 100 );
  141.                                    
  142.             // If no directory specified, print an error message
  143.             if( directory.equals( null ) || directory.equals( new String( "" ) ) ) {
  144.                 document.writeln( "<H2>No directory specified" );
  145.                 return;
  146.             }
  147.                 
  148.             // Create and check if actually is a directory       
  149.             File currentDir = new File( directory );                
  150.             if( !currentDir.isDirectory() ) {
  151.                 document.writeln( "<H2>Directory " + directory + " doesn't exist." );
  152.                 return;
  153.             }    
  154.             
  155.             // Add directory to the list
  156.             dirList.addElement( currentDir );
  157.         
  158.             for( ; dirList.size() > 0 ; ) {            
  159.                 // Get and remove the first dir off the list            
  160.                 File cwd = ( File ) dirList.firstElement(); 
  161.                 dirList.removeElementAt( 0 );
  162.             
  163.                 String[] fileList = cwd.list();
  164.  
  165.                 // Print out the current directory and the table headers
  166.                 document.writeln( "<P>" );
  167.                 document.write( "<CENTER><H2>Directory: " );
  168.                 document.write( cwd.toString() );
  169.                 document.writeln( "</H2></CENTER>" );
  170.         
  171.                 document.writeln( "<CENTER><TABLE BORDER=4 BGCOLOR=WHITE>" );        
  172.                 document.writeln( "<TR>" );
  173.                 document.writeln( "<TH>Name</TH>" );
  174.                 document.writeln( "<TH>Type</TH>" );
  175.                 document.writeln( "<TH>Read</TH>" );
  176.                 document.writeln( "<TH>Write</TH>" );
  177.                 document.writeln( "<TH>Length</TH>" );
  178.                 document.writeln( "<TH>Last Modified</TH>" );
  179.                 document.writeln( "</TR>" );
  180.                     
  181.                 for( int row=0; row<fileList.length; row++ ) {
  182.                     String fileName = fileList[row];                
  183.                     File aFile = new File( cwd, fileName );
  184.             
  185.                     document.writeln( "<TR>" );
  186.  
  187.                     document.write( "<TD>" );
  188.                     document.write( fileName );               
  189.                     document.writeln( "</TD>" );
  190.             
  191.                     // Check if file is a file or a directory
  192.                     // If it's a directory, add to the list
  193.                     if( aFile.isDirectory() ) {
  194.                         document.writeln( "<TD>Directory</TD>" );
  195.                         dirList.addElement( aFile );
  196.                     } else if( aFile.isFile() ) {
  197.                         document.writeln( "<TD>File</TD>" );
  198.                     } else {
  199.                         document.writeln( "<TD>Unknown</TD>" );
  200.                     }
  201.             
  202.                     // Check if file is readable
  203.                     if( aFile.canRead() ) {
  204.                         document.writeln( "<TD>Yes</TD>" );
  205.                     } else {
  206.                         document.writeln( "<TD>No</TD>" );
  207.                     }
  208.             
  209.                     // Check if file is writable
  210.                     if( aFile.canWrite() ) {
  211.                         document.writeln( "<TD>Yes</TD>" );
  212.                     } else {
  213.                         document.writeln( "<TD>No</TD>" );
  214.                     }
  215.             
  216.                     // Get length of file
  217.                     document.write( "<TD>" );
  218.                     document.write( Long.toString( aFile.length() ) );
  219.                     document.writeln( "</TD>" );
  220.             
  221.                     // Get the 'last modified' date and time of file            
  222.                     document.write( "<TD>" );
  223.                     document.write( (new Date( aFile.lastModified() )).toLocaleString() );
  224.                     document.writeln( "</TD>" );
  225.             
  226.                     document.writeln( "</TR>" );                               
  227.                 }
  228.         
  229.                 document.writeln( "</TABLE></CENTER>" );                        
  230.             }
  231.             document.writeln( "<P>\n<BR>\n<HR>\n<BR>" );                
  232.  
  233.         } catch( DynamoException e ) {
  234.         }
  235.  
  236.     }
  237.  
  238. @end-code;
  239.  
  240. @begin-code Code "DDir_Walker::EndApp(String args[])"
  241.  
  242.     public void EndApp(String args[])
  243.     {
  244.     }
  245.  
  246. @end-code;
  247. @end;
  248.