View Javadoc

1   ////////////////////////////////////////////////////////////////////////////////
2   // MillScript: an Open Spice interpreter and batch website creation tool
3   // Copyright (C) 2005 Kevin Rogers
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.commons.vfs;
22  
23  import org.millscript.commons.alert.Alert;
24  import org.millscript.commons.alert.AlertDecorator;
25  
26  /**
27   * The class provides a skeletal virtual filesystem volume.
28   */
29  public abstract class AbstractVVolume implements AlertDecorator, VVolume {
30  
31      /**
32       * The VFS that was used to create this volume.
33       */
34      private final VFS vfs;
35  
36      /**
37       * Constructs a new virtual volume, using the specified VFS.
38       *
39       * @param v the VFS that was used to create this volume
40       */
41      protected AbstractVVolume( final VFS v ) {
42          this.vfs = v;
43      }
44  
45      /**
46       * Constructs a new virtual volume, using the VFS from the specified
47       * entry.
48       *
49       * @param e the entry whose VFS to use
50       */
51      protected AbstractVVolume( final VEntry e ) {
52          this.vfs = e.getVolume().getParentVFS();
53      }
54  
55      /**
56       * @see org.millscript.commons.vfs.VVolume#appendBaseURI(java.lang.StringBuffer)
57       */
58      public StringBuffer appendBaseURI( final StringBuffer buffer ) {
59          // Append the URI scheme
60          buffer.append( this.getURI().getScheme() );
61          buffer.append( ':' );
62          // Append the host
63          if ( this.getURI().getHost() != null ) {
64              buffer.append( "//" );
65              buffer.append( this.getURI().getHost() );
66              // Append the port
67              if ( this.getURI().getPort() != -1 ) {
68                  buffer.append( ':' );
69                  buffer.append( this.getURI().getPort() );
70              }
71          }
72          return buffer;
73      }
74  
75      /**
76       * @see org.millscript.commons.alert.AlertDecorator#decorate(org.millscript.commons.alert.Alert)
77       */
78      public Alert decorate( final Alert alert ) {
79          return alert.culprit( "vvolume", this );
80      }
81  
82      /**
83       * @see org.millscript.commons.vfs.VVolume#getParentVFS()
84       */
85      public VFS getParentVFS() {
86          return this.vfs;
87      }
88  
89      /**
90       * @see java.lang.Object#toString()
91       */
92      @Override
93      public final String toString() {
94          final StringBuffer buff = new StringBuffer( "VVOLUME( " );
95          buff.append( this.getURI().toString() );
96          buff.append( " )" );
97          return buff.toString();
98      }
99  
100 }