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.util;
22  
23  import org.millscript.commons.vfs.VFS;
24  import org.millscript.commons.vfs.VFolder;
25  import org.millscript.commons.vfs.VVolume;
26  
27  import java.net.URI;
28  
29  /**
30   * This class implements a Unix style chroot volume, which can have its real
31   * root at any virtual folder.
32   */
33  public class ChrootVolume implements VVolume {
34  
35      /**
36       * The root folder for this volume.
37       */
38      private final ChrootFolder rootFolder;
39  
40      /**
41       * Constructs a new chroot volume with the specified folder as its root.
42       *
43       * @param root  the root folder for the chroot volume
44       */
45      public ChrootVolume( final VFolder root ) {
46          this.rootFolder = this.makeRootVFolder( root );
47      }
48  
49      /**
50       * @see org.millscript.commons.vfs.VVolume#appendBaseURI(java.lang.StringBuffer)
51       */
52      public StringBuffer appendBaseURI( final StringBuffer buffer ) {
53          // chroot doesn't have a scheme, host or port
54          return buffer;
55      }
56  
57      /**
58       * @see org.millscript.commons.vfs.VVolume#getRootVFolder()
59       */
60      public VFolder getRootVFolder() {
61          return this.rootFolder;
62      }
63  
64      /**
65       * @see org.millscript.commons.vfs.VVolume#getURI()
66       */
67      public URI getURI() {
68          // chroot doesn't have a scheme, host or port, it just has a path
69          return URI.create( "/" );
70      }
71  
72      /**
73       * Constructs the root folder for this volume, with the specified parent
74       * folder and returns it.
75       *
76       * @param parent    the virtual folder for the source of this volume
77       * @return  the VFolder for the root of this volume
78       */
79      public ChrootFolder makeRootVFolder( final VFolder parent ) {
80          return new ChrootFolder( this, null, parent );
81      }
82  
83      /**
84       * @see org.millscript.commons.vfs.VVolume#getParentVFS()
85       */
86      public VFS getParentVFS() {
87          return this.rootFolder.getVolume().getParentVFS();
88      }
89  
90      /**
91       * @see java.lang.Object#toString()
92       */
93      @Override
94      public final String toString() {
95          final StringBuffer buff = new StringBuffer( "CHROOT_VOLUME( " );
96          buff.append( this.getURI().toString() );
97          buff.append( " )" );
98          return buff.toString();
99      }
100 
101 }