View Javadoc

1   ////////////////////////////////////////////////////////////////////////////////
2   // MillScript: an Open Spice interpreter and batch website creation tool
3   // Copyright (C) 2001-2005 Open World Ltd
4   //
5   // This file is part of MillScript.
6   //
7   // MillScript is free software; you can redistribute it and/or modify it under
8   // the terms of the GNU General Public License as published by the Free
9   // Software Foundation; either version 2 of the License, or (at your option)
10  // any later version.
11  //
12  // MillScript is distributed in the hope that it will be useful, but WITHOUT
13  // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
15  // more details.
16  //
17  // You should have received a copy of the GNU General Public License along with
18  // MillScript; if not, write to the Free Software Foundation, Inc., 59 Temple
19  // Place, Suite 330, Boston, MA  02111-1307  USA
20  ////////////////////////////////////////////////////////////////////////////////
21  package org.millscript.millscript.apps.website;
22  
23  import org.millscript.commons.vfs.VFS;
24  import org.millscript.commons.vfs.VFolder;
25  import org.millscript.millscript.conf.Configuration;
26  import org.millscript.millscript.conf.WebsiteConf;
27  
28  import java.io.IOException;
29  import java.io.Reader;
30  import java.util.Iterator;
31  
32  import com.townleyenterprises.command.CommandOption;
33  
34  
35  /**
36   * 
37   *
38   */
39  public class StatusCommandOption extends CommandOption {
40  
41      Configuration websiteConf = new WebsiteConf();
42  
43      /**
44       * 
45       */
46      public StatusCommandOption() {
47          super( "status", 's', true, "<dir>", "Show status of websites in <dir>", "." );
48      }
49  
50      /**
51       * @see com.townleyenterprises.command.CommandOption#execute()
52       */
53      @Override
54      public void execute() throws Exception {
55          VFS vfs = new VFS();
56          VFolder cwd = vfs.getCurrentWorkingFolder();
57          // TODO - Need to resolve the specified path against this
58          this.status( cwd );
59      }
60  
61      boolean isAWebsite( final VFolder folder ) {
62          return folder.getVFolder( ".website" ).exists();
63      }
64  
65      void siteStatus( final VFolder folder ) {
66          System.out.print( "Status for " );
67          System.out.println( folder );
68          if ( this.websiteConf.getWebsiteLockFile().exists() ) {
69  //          $self->status_for( $dir, $self->getWebsiteLockFile() );
70          } else if ( this.websiteConf.getWebsiteFailureFile().exists() ) {
71  //          open FILE, $self->getMillScriptFailureFile();
72  //          while ( <FILE> ) {
73  //              print;
74  //          }
75  //          close FILE;
76          } else if ( this.websiteConf.getWebsiteSuccessFile().exists() ) {
77              final Reader r = this.websiteConf.getWebsiteSuccessFile().getReader();
78              int c;
79              try {
80                  while ( ( c = r.read() ) != -1 ) {
81                      System.out.print( (char) c );
82                  }
83                  r.close();
84              } catch ( IOException ex ) {
85                  System.out.println();
86                  System.out.println( "Failed to read information from " );
87              }
88          } else {
89              System.out.println( "No info available" );
90          }
91          System.out.println();
92      }
93  
94      void status( final VFolder folder ) {
95          if ( this.isAWebsite( folder ) ) {
96              this.siteStatus( folder );
97          } else {
98              // We resolved to a folder, so we can just iterate over it's
99              // contents
100             final Iterator it = folder.listFolders().iterator();
101             while ( it.hasNext() ) {
102                 this.status( (VFolder) it.next() );
103             }
104         }
105     }
106 
107 }