1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.millscript.commons.vfs;
22
23 import org.millscript.commons.alert.Alert;
24 import org.millscript.commons.alert.AlertDecorator;
25 import org.millscript.commons.vfs.alerts.VFSAlert;
26 import org.millscript.commons.vfs.protocols.file.LocalFolder;
27 import org.millscript.commons.vfs.util.ChrootVolume;
28 import org.millscript.commons.vfs.util.Resolver;
29 import org.millscript.commons.vfs.util.SimpleVolume;
30
31 /**
32 * This class provides the skeletal implementation of a virtual filesystem
33 * folder,
34 */
35 public abstract class AbstractVFolder< V extends VVolume > extends AbstractVEntry< V > implements AlertDecorator, VFolder {
36
37 /**
38 * Constructs a new virtual filesystem folder with the specified name,
39 * parent folder and volume.
40 *
41 * @param vol the volume this entry is held on
42 * @param parent the parent folder for this folder
43 * @param name the name of the folder
44 */
45 public AbstractVFolder( final V vol, final VFolder parent, final String name ) {
46 super( vol, parent, name );
47 }
48
49 /**
50 * @see org.millscript.commons.vfs.VEntry#appendRelativePath(java.lang.StringBuffer)
51 */
52 public final StringBuffer appendRelativePath( final StringBuffer buff ) {
53
54 if ( this.getParent() == null ) {
55
56 return buff;
57 } else {
58
59
60
61 this.getParent().appendRelativePath( buff );
62
63 return buff.append( this.getName() ).append( '/' );
64 }
65 }
66
67 /**
68 * @see org.millscript.commons.vfs.VEntry#appendRelativePathOnVolume(java.lang.StringBuffer)
69 */
70 public final StringBuffer appendRelativePathOnVolume( final StringBuffer buff ) {
71
72
73
74
75
76
77
78 if ( this.getParent() == null ) {
79
80 return buff;
81 } else if ( this.getParent().getVolume() == this.getVolume() ) {
82
83
84
85 this.getParent().appendRelativePathOnVolume( buff );
86
87 return buff.append( this.getName() ).append( '/' );
88 } else {
89
90 return buff;
91 }
92 }
93
94 /**
95 * @see org.millscript.commons.vfs.VEntry#appendURI(java.lang.StringBuffer)
96 */
97 public final StringBuffer appendURI( final StringBuffer buffer ) {
98
99
100
101 if ( this.getParent() == null ) {
102
103 this.getVolume().appendBaseURI( buffer );
104 } else {
105
106 this.getParent().appendURI( buffer );
107 buffer.append( this.getName() );
108 }
109 return buffer.append( '/' );
110 }
111
112 /**
113 * @see org.millscript.commons.vfs.VFolder#chroot()
114 */
115 public final VVolume chroot() {
116 return new ChrootVolume( this );
117 }
118
119 /**
120 * @see org.millscript.commons.alert.AlertDecorator#decorate(org.millscript.commons.alert.Alert)
121 */
122 public Alert decorate( final Alert alert ) {
123 return alert.culprit( "vfolder", this );
124 }
125
126 /**
127 * @see org.millscript.commons.vfs.VFolder#make(java.lang.String)
128 */
129 public final VFolder make( final String segment ) {
130
131 final VFolder child = this.getVFolder( segment );
132
133 return child.make();
134 }
135
136 /**
137 * @see org.millscript.commons.vfs.VFolder#resolveAsFile(java.lang.String)
138 */
139 public final VFile resolveAsFile( final String path ) {
140 return Resolver.resolveAsFile( this, path );
141 }
142
143 /**
144 * @see org.millscript.commons.vfs.VFolder#resolveAsFolder(java.lang.String)
145 */
146 public final VFolder resolveAsFolder( final String path ) {
147 return Resolver.resolveAsFolder( this, path );
148 }
149
150 /**
151 * @see org.millscript.commons.vfs.VFolder#resolveAsVolume(java.lang.String)
152 */
153 public final VVolume resolveAsVolume( final String path ) {
154 return Resolver.resolveAsVolume( this, path );
155 }
156
157 /**
158 * @see org.millscript.commons.vfs.VFolder#toLocal()
159 */
160 public LocalFolder toLocal() {
161
162 throw new VFSAlert(
163 "Can't make a local copy of a virtual folder yet"
164 ).decorate( this ).mishap();
165 }
166
167 /**
168 * @see java.lang.Object#toString()
169 */
170 @Override
171 public String toString() {
172 final StringBuffer buff = new StringBuffer( "VFOLDER( " );
173 this.appendAbsolutePath( buff );
174 buff.append( " )" );
175 return buff.toString();
176 }
177
178 /**
179 * @see org.millscript.commons.vfs.VFolder#toVolume()
180 */
181 public final VVolume toVolume() {
182 return new SimpleVolume( this );
183 }
184
185 }