Merge branch 'master' of github.com:mono/mono
[mono.git] / mcs / class / System.Web / System.Web.Hosting / DefaultVirtualDirectory.cs
1 //
2 // System.Web.Hosting.DefaultVirtualDirectory
3 //
4 // Author:
5 //      Gonzalo Paniagua Javier (gonzalo@ximian.com)
6 //
7
8 //
9 // Copyright (c) 2006 Novell, Inc (http://www.novell.com)
10 //
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
18 // 
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 // 
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30
31 #if NET_2_0
32
33 using System;
34 using System.Collections;
35 using System.IO;
36
37 namespace System.Web.Hosting {
38
39         class DefaultVirtualDirectory : VirtualDirectory
40         {
41                 string phys_dir;
42                 string virtual_dir;
43
44                 internal DefaultVirtualDirectory (string virtualPath)
45                         : base (virtualPath)
46                 {
47                 }
48
49                 void Init ()
50                 {
51                         if (phys_dir == null) {
52                                 string vpath = VirtualPath;
53                                 virtual_dir = VirtualPathUtility.GetDirectory (vpath);
54                                 phys_dir = HostingEnvironment.MapPath (virtual_dir);
55                         }
56                 }
57
58                 ArrayList AddDirectories (ArrayList list, string dir)
59                 {
60                         foreach (string name in Directory.GetDirectories (phys_dir)) {
61                                 string vdir = VirtualPathUtility.Combine (virtual_dir, Path.GetFileName (name));
62                                 list.Add (new DefaultVirtualDirectory (vdir));
63                         }
64                         return list;
65                 }
66
67                 ArrayList AddFiles (ArrayList list, string dir)
68                 {
69                         foreach (string name in Directory.GetFiles (phys_dir)) {
70                                 string vdir = VirtualPathUtility.Combine (virtual_dir, Path.GetFileName (name));
71                                 list.Add (new DefaultVirtualFile (vdir));
72                         }
73                         return list;
74                 }
75
76                 public override IEnumerable Children {
77                         get {
78                                 Init ();
79                                 ArrayList list = new ArrayList ();
80                                 AddDirectories (list, phys_dir);
81                                 return AddFiles (list, phys_dir);
82                         }
83                 }
84
85                 public override IEnumerable Directories {
86                         get {
87                                 Init ();
88                                 ArrayList list = new ArrayList ();
89                                 return AddDirectories (list, phys_dir);
90                         }
91                 }
92                 
93                 public override IEnumerable Files {
94                         get {
95                                 Init ();
96                                 ArrayList list = new ArrayList ();
97                                 return AddFiles (list, phys_dir);
98                         }
99                 }
100         }
101 }
102 #endif
103